GuiStatusCtrl - *Updated* Display Field Name, Values, Status Bar for any field or method on any named object. TGEA and (new! TGE 1.52)
by Jaimi McEntire · 02/04/2009 (2:15 pm) · 44 comments
GuiStatusCtrl
Displays Field Name and/or value and/or bar graph for any field or method of any named object, using TorqueML for customization.The GuiStatusCtrl is a control that will monitor a field or method on any named object. This makes it easy to make status screens, etc. Also included is a GuiStatusController - a container that controls GuiStatusCtrls (more later on why this is useful).
The control can display the field name, value and the percentage of value as a progress bar. The field name and value can use TorqueML to customize the font, size, shadows, alignment, etc.
To use the GuiStatusCtrl, add the following files to your TGEA 1.7+ project, and recompile:
For TGEA 1.7+
Download Source Files for TGEA 1.7+
for TGE 1.5.2
Download Source Files for TGE 1.5.2
The GuiStatusCtrl has the following fields:
ObjectName: This is the name of the object that you want to monitor FieldName: This is the field that you want to monitor. New: Can also be a method on the class MaxFieldName: If displaying a status bar, this is the field (or method) that holds the maximum value IgnoreController: If set, this control will be ignored by any GuiStatusController objects FieldNameMLFormat: The TorqueML that is used to display the Field's Name FieldValueMLFormat: The TorqueML that is used to display the Field's Value DisplayFieldName: If true, then the field name is displayed to the left DisplayFieldValue: If true, then the field value is displayed. DisplayBar: If true, then a bar is displayed. The size is proportional to field/maxfield BarColor: The color of the status bar. Label: New: An alternate label to use instead of the FieldName.
The GuiStatusController is a container that is used to control any child GuiStatusCtrl objects. Lets say you have 25 GuiStatusCtrl controls all pointing to "PlayerBob", and you want them to show "PlayerJane" instead. Instead of manually coding the change to all 25 child controls, you instead just set the GuiStatusController ObjectName field, and it will update the child controls for you.
The GuiStatusController has all the fields that a GuiContainer has, with the addition of:
ObjectName: The name of the object to monitor.
If you do not wish for a child control to be changed by the controller, then set the "IgnoreController" field on the child.
Example: Lets create three named objects for our fictional RPG "Supergalactic Megawars" - put this in a test.cs file, and then execute it:
new SimObject("MainPlayer");
new SimObject("PartyPlayer");
new SimObject("GameData");
GameData.GameName = "Supergalactic Megawars";
GameData.LevelName = "Orion Quadrant";
MainPlayer.PlayerName = "Big Bob";
MainPlayer.Strength = 18;
MainPlayer.Vitality = 20;
MainPlayer.Intellect = 30;
MainPlayer.Health = 50;
MainPlayer.MaxHealth = 65;
PartyPlayer.PlayerName = "Sue (female)"; // differentiate from any boys named Sue
PartyPlayer.Strength = 22;
PartyPlayer.Vitality = 18;
PartyPlayer.Intellect = 24;
PartyPlayer.Health = 20;
PartyPlayer.MaxHealth = 65;Now, create a new gui, and put a GuiStatusController on it. Size it to hold 8 GuiStatusCtrl objects, and create and place the status controls in the controller.
Set the ObjectName on the top 2 to "GameData", and the field on the first one to "GameName" and the field on the second one to "LevelName". You should see the status control display the field names and values by default. Set "IgnoreController" to true for both controls. (you can also set the ML properties to apply formatting to the field name and value).
For the remainders, set the ObjectName to "MainPlayer", and the fieldnames to "PlayerName","Strength", "Vitality", "intellect", and "Health". On the Health Control, set "DisplayBar" to true, and set the MaxFieldName to "MaxHealth". You should now see all of the values displayed, and a proportional bar for health. (You can disable the field name and value on health if you don't want them printed).
To see how the controller works, set the Controller.ObjectName parameter to "PartyPlayer". now you are viewing her stats instead.
What's New
You can now use methods as well as field names. For example, to display "Health" on a player, you can add the following method to the Player.cs:
function Player::GetHealth(%this)
{
return %this.dataBlock.MaxDamage - (%this.dataBlock.MaxDamage * %this.getDamagePercent());
}
function Player::GetMaxHealth(%this)
{
return %this.dataBlock.MaxDamage;
}Now, instead of Field Names, use "GetHealth" for the Value and "GetMaxHealth" for the Max Value. Use the new "Label field" to override the display for the field name. (note: your Target object needs to be a "Player" for this to work. Or actually, any ShapeBase descended object)
Update
Here's a slightly more complicated version of the GetHealth function above, that shows how you can manipulate the control as part of the status function - we update the color and label that display based on how hurt the player is:
function Player::GetHealth(%this)
{
%perc = %this.getDamagePercent();
if (%perc < 0.25)
{
%newlabel = "Invincible";
%BarColor = "128 0 0 192";
}
else if (%perc < 0.50)
{
%newlabel = "But a scratch";
%BarColor = "160 0 0 192";
}
else if (%perc < 0.75)
{
%newlabel = "Just a flesh wound";
%BarColor = "192 0 0 192";
}
else
{
// Careful, he'll bite your legs off.
%newlabel = "Calling it a draw";
%BarColor = "255 0 0 192";
}
MyHealthStatus.Label = %newlabel;
MyHealthStatus.BarColor = %BarColor;
return mFloor(0.99 + (%this.dataBlock.MaxDamage - (%this.dataBlock.MaxDamage * %this.getDamagePercent())));
}Sample Pic:

#42
01/03/2010 (1:02 am)
Jaimi do you still have a copy of these files? All your resource files have disappeared and I could really use them now.
#43
01/04/2010 (3:37 pm)
@Michael - the server should be up, have you tried recently? I was just able to pull one of the files, and I'm remote right now.
#44
12/05/2013 (9:29 pm)
Sounds like a really cool Gui Control. Anyone still have a copy lying around? 
Torque Owner Drew Kario