Customize the health-status-bar?
by Heath Rezabek · in RTS Starter Kit · 12/01/2004 (12:11 pm) · 9 replies
Hi! i'm excited to get going with RTSTorque. i have a question right off the bat.
i want to create a custom health read-out [you know, the blocky green bar above the units?]. i've looked around, and cannot find the asset to edit to change this visual element. where should i be looking?
thanks,
- aqaraza
i want to create a custom health read-out [you know, the blocky green bar above the units?]. i've looked around, and cannot find the asset to edit to change this visual element. where should i be looking?
thanks,
- aqaraza
#2
- aqaraza
12/01/2004 (2:15 pm)
Alright; found it! now. don't tell anyone cool that i'm about to ask this; i know it will sound very stupid if you already know the answer, but i am not an experienced coder, & spend more time with music and textures. do i need to recompile the engine in order to see the changes i made and saved [keeping a backup!] take effect? if so, that'd explain why my commenting out the black box and decreasing the size of the green bar is not working...- aqaraza
#3
12/01/2004 (2:25 pm)
Yes any changes to the C requires a recompile to take effect
#4
12/05/2004 (4:43 pm)
Related question, now that i've been able to do that: where in the code would the variable setting the distance above the unit the bar is drawn at be? i glanced around nearby in the code but cld not decipher. thanks for any info, -aq
#5
RectI rect(offset, Point2I(width, mDamageRectSize.y));
this RectI reuires two 2d points (only x and y) to define it. It uses offset, which is defined a few lines above then makes the other out of width and mDamageRectSize.y. My best guess is it would be the second element of the offset Point2I.
12/05/2004 (7:06 pm)
The short answer is it's on line 453:RectI rect(offset, Point2I(width, mDamageRectSize.y));
this RectI reuires two 2d points (only x and y) to define it. It uses offset, which is defined a few lines above then makes the other out of width and mDamageRectSize.y. My best guess is it would be the second element of the offset Point2I.
#6
-----------------
I wanted to add more status bars.
So I added a mana bar, and a second mana bar that shifts color as mana decreases.
For now, I have connected the mana bar to the health attribute. Now I need to figure out how to add a mana attribute to a character, unless someone wants to get me started.
I added the following code to game/rts/guiRTSTSctrl.cc, just after
This requires adding mManaRectSize, mManaFrameColor, and mManaFillColor to game/rts/guiRTSTSctrl.h where the mDamageRectSize stuff is defined.
Also, these variables are all set to values at the top of game/rts/guiRTSTSctrl.cc, around line 79. The additional variables must be added there as well.
Also, it should be noted that mDamageRectSize does not actually control the size of the damage rectangle. It appears that this was the original intention, but was abandoned in an effort to make the box size scale when zooming the camera.
04/07/2005 (2:00 pm)
MANA BAR added above damage bar, and also a COLOR SHIFTING STATUS BAR-----------------
I wanted to add more status bars.
So I added a mana bar, and a second mana bar that shifts color as mana decreases.
For now, I have connected the mana bar to the health attribute. Now I need to figure out how to add a mana attribute to a character, unless someone wants to get me started.
I added the following code to game/rts/guiRTSTSctrl.cc, just after
if (rect.extent.x > 0)
dglDrawRectFill(rect, mDamageFillColor);[b]//ADDING A 'MANA' BAR -----------------------------------[/b]
//temporarily setting mana = health until I know how to use mana
F32 mana = mClampF(1 - object->getDamageValue(), 0, 1);
int spaceBetween = 4;
//move the top left corner, offset, up by the height of the mana box,
//plus spaceBetween for the space in between boxes.
offset.y -= (mManaRectSize.y + spaceBetween);
// Center the bar
RectI manaRect(offset, Point2I(width, mManaRectSize.y));
// Draw the border
dglDrawRect(manaRect, mManaFrameColor);
// Draw the damage % fill
manaRect.point += Point2I(1, 1);
manaRect.extent -= Point2I(1, 1);
manaRect.extent.x = (S32)(manaRect.extent.x * mana);
if (manaRect.extent.x == 1)
manaRect.extent.x = 2;
if (manaRect.extent.x > 0)
dglDrawRectFill(manaRect, mManaFillColor);
[b]//END OF ADDING A 'MANA' BAR -----------------------------------[/b]
[b]//ADDING A COLOR SHIFTING 'MANA' BAR -----------------------[/b]
//temporarily setting mana = to health
//F32 mana = mClampF(1 - object->getDamageValue(), 0, 1);
//move the top left corner, offset, up by the height of the mana box,
//plus spaceBetween for the space in between boxes.
//make this status bar taller, just for fun
float colorShiftheight = 10;
offset.y -= (colorShiftheight + spaceBetween);
// Center the bar
RectI colorManaRect(offset, Point2I(width, colorShiftheight));
// Draw the border
dglDrawRect(colorManaRect, mManaFrameColor);
// Draw the damage % fill
colorManaRect.point += Point2I(1, 1);
colorManaRect.extent -= Point2I(1, 1);
//commented out this line so that the box is always filled
//colorManaRect.extent.x = (S32)(colorManaRect.extent.x * mana);
if (mana < 1)
Con::printf("mana color = (%f,0,%f,1)",mana,1-mana);
//setting the color to shift from red to blue as mana decreases
[b]ColorF colorManaFillColor;
colorManaFillColor.set(mana, 0, 1-mana, 1 );[/b]
if (colorManaRect.extent.x == 1)
colorManaRect.extent.x = 2;
if (colorManaRect.extent.x > 0)
dglDrawRectFill(colorManaRect, colorManaFillColor);
[b]//END OF ADDING A COLOR SHIFTING 'MANA' BAR -------[/b]This requires adding mManaRectSize, mManaFrameColor, and mManaFillColor to game/rts/guiRTSTSctrl.h where the mDamageRectSize stuff is defined.
ColorF mDamageFillColor;
ColorF mDamageFrameColor;
Point2I mDamageRectSize;
ColorF mManaFillColor;
ColorF mManaFrameColor;
Point2I mManaRectSize;Also, these variables are all set to values at the top of game/rts/guiRTSTSctrl.cc, around line 79. The additional variables must be added there as well.
Also, it should be noted that mDamageRectSize does not actually control the size of the damage rectangle. It appears that this was the original intention, but was abandoned in an effort to make the box size scale when zooming the camera.
#7
Tell you what, if I can get over this cold at all, I'll throw together a quick "adding mana to the RTS-SK" example this weekend and post it here. Unless of course someone beats me to it!
04/08/2005 (6:38 am)
Very nice!Tell you what, if I can get over this cold at all, I'll throw together a quick "adding mana to the RTS-SK" example this weekend and post it here. Unless of course someone beats me to it!
#8
04/08/2005 (12:08 pm)
That would be great! That's next on my todo list.
#9
===============
Rather than comment out the black box in the following in
Torque/Engine/game/RTS/guiRTSTSCtrl.cc:
Of course, since this is a modification of a .cc file, it requires a recompile.
04/09/2005 (10:02 am)
IMPROVING THE BLACK BOX UNDER THE DAMAGE or HEALTH BAR===============
Rather than comment out the black box in the following in
Torque/Engine/game/RTS/guiRTSTSCtrl.cc:
// Draw the border
dglDrawRect(rect, mDamageFrameColor);I recommend changing to dglDrawRectFill rather than dglDrawRect. Somethings just not right about the dglDrawRect box. It is creating a filled box with the corners kinda cut off. I thought it might be shadows, so I tried changing the box to green. I also removed the red filled damage bar. Then you can really see the dglDrawRect. I couldn't really figure whats going on there. So the quick fix is to change to the filled box version as follows: // Draw the border
dglDrawRectFill(rect, mDamageFrameColor);I also chose to do subtract 2 from the "extent" point, instead of just one, which causes the red bar to have a nice even border around it. // Draw the damage % fill
rect.point += Point2I(1, 1);
rect.extent -= Point2I(2, 2);Of course, since this is a modification of a .cc file, it requires a recompile.
Torque 3D Owner Martin "Founder" Hoover