Game Development Community

Debug Gui (simple gui example/to use)

by Matthew Langley · in Torque Game Builder · 03/04/2005 (11:22 am) · 10 replies

Just made a quick debug gui... gives you button interfaces to set the debug modes (makes it easier than typing it in each time) plus also put a hide button in there and a text input to change what you want to set debug modes for

here is the code

create a new text file in your T2D client folder and name it "HelperGui.gui"... paste this code in there

//--- OBJECT WRITE BEGIN ---
new GuiControl(HelperGui) {
   profile = "GuiDefaultProfile";
   horizSizing = "right";
   vertSizing = "bottom";
   position = "0 20";
   extent = "800 15";
   minExtent = "8 2";
   visible = "1";

   new GuiControl(DebugControls) {
   profile = "GuiDefaultProfile";
   horizSizing = "right";
   vertSizing = "bottom";
   position = "0 0";
   extent = "800 200";
   minExtent = "8 2";
   visible = "1";

   new GuiButtonCtrl() {
      profile = "GuiButtonProfile";
      horizSizing = "right";
      vertSizing = "bottom";
      position = "0 0";
      extent = "80 15";
      minExtent = "8 2";
      visible = "1";
      text = "Bounding Box";
      groupNum = "1";
      buttonType = "PushButton";
   command = "HelperGui.setMode(BB);";
   };

   new GuiButtonCtrl() {
      profile = "GuiButtonProfile";
      horizSizing = "right";
      vertSizing = "bottom";
      position = "80 0";
      extent = "80 15";
      minExtent = "8 2";
      visible = "1";
      text = "Collision Poly";
      groupNum = "1";
      buttonType = "PushButton";
   command = "HelperGui.setMode(ColPoly);";
   };

   new GuiButtonCtrl() {
      profile = "GuiButtonProfile";
      horizSizing = "right";
      vertSizing = "bottom";
      position = "160 0";
      extent = "80 15";
      minExtent = "8 2";
      visible = "1";
      text = "Mount Nodes";
      groupNum = "1";
      buttonType = "PushButton";
   command = "HelperGui.setMode(MNodes);";
   };

   new GuiButtonCtrl() {
      profile = "GuiButtonProfile";
      horizSizing = "right";
      vertSizing = "bottom";
      position = "240 0";
      extent = "70 15";
      minExtent = "8 2";
      visible = "1";
      text = "Mount Link";
      groupNum = "1";
      buttonType = "PushButton";
   command = "HelperGui.setMode(MLink);";
   };   

   new GuiButtonCtrl() {
      profile = "GuiButtonProfile";
      horizSizing = "right";
      vertSizing = "bottom";
      position = "310 0";
      extent = "70 15";
      minExtent = "8 2";
      visible = "1";
      text = "World Limit";
      groupNum = "1";
      buttonType = "PushButton";
   command = "HelperGui.setMode(WLimit);";
   };

new GuiButtonCtrl() {
profile = "GuiButtonProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "380 0";
extent = "40 15";
minExtent = "8 2";
visible = "1";
text = "ALL";
groupNum = "1";
buttonType = "PushButton";
command = "HelperGui.setMode(ALL);";
};



new GuiMLTextEditCtrl(sceneName) {
profile = "GuiMLTextEditProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "420 0";
extent = "120 18";
minExtent = "8 2";
visible = "1";
lineSpacing = "2";
allowColorChars = "0";
maxChars = "-1";
};
};
new GuiButtonCtrl() {
profile = "GuiButtonProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "540 0";
extent = "40 15";
minExtent = "8 2";
visible = "1";
text = "Hide";
groupNum = "-1";
buttonType = "PushButton";
command = "HelperGui.hide();";
};



};
//--- OBJECT WRITE END ---

About the author

Was a GG Associate and then joined GG in 2005. Lead tool dev for T2D and T3D. In 2011 joined mobile company ngmoco/DeNA and spent about 4 years working game and server tech. 2014 joined startup Merigo Games developing server technology.


#1
03/04/2005 (11:22 am)
(add this to the .gui file also - was too long for one post)
function HelperGui::onWake(%this)
{
	sceneName.setText("t2dSceneGraph");
	%this.hidden = false;
	%this.mode[%this.convertToNum(BB)] = false;
	%this.mode[%this.convertToNum(ColPoly)] = false;
	%this.mode[%this.convertToNum(MNodes)] = false;
	%this.mode[%this.convertToNum(MLink)] = false;
	%this.mode[%this.convertToNum(WLimit)] = false;
	%this.mode[%this.convertToNum(All)] = false;

	DebugControls.setVisible(true);
}

function HelperGui::convertToNum(%this, %char)
{
	switch$(%char)
	{
	case "BB": 
		return 0;
	case "ColPoly":
		return 1;
	case "MNodes":
		return 2;
	case "MLink":
		return 3;
	case "WLimit":		
		return 4;
	case "ALL":
		return 5;
	}
}

function HelperGui::setMode(%this, %mode)
{
	%this.scene = sceneName.getText();

	if(%mode !$= "ALL")
		if(%this.mode[%this.convertToNum(ALL)] $= true)
		{
			%this.mode[%this.convertToNum(ALL)] = false;
			%this.turnDebugOff(ALL);
		}

	if(%this.mode[%this.convertToNum(%mode)] $= true)
	{
		%this.mode[%this.convertToNum(%mode)] = false;
		echo("turning off:" SPC %mode);
		%this.turnDebugOff(%mode);
	} else
	{
		%this.mode[%this.convertToNum(%mode)] = true;
		echo("turning on:" SPC %mode);

		%this.turnDebugOn(%mode);
	}
	



}

function HelperGui::turnDebugOn(%this, %mode)
{
	switch$(%mode)
	{
	case "BB": 
		(%this.scene).setDebugOn(BIT(1));
	case "ColPoly":
		(%this.scene).setDebugOn(BIT(5));
	case "MNodes":
		(%this.scene).setDebugOn(BIT(2));
	case "MLink":
		(%this.scene).setDebugOn(BIT(3));
	case "WLimit":		
		(%this.scene).setDebugOn(BIT(4));
	case "ALL":
		(%this.scene).setDebugOn(0xFFFFFF);
	}
}

function HelperGui::turnDebugOff(%this, %mode)
{
	switch$(%mode)
	{
	case "BB": 
		(%this.scene).setDebugOff(BIT(1));
	case "ColPoly":
		(%this.scene).setDebugOff(BIT(5));
	case "MNodes":
		(%this.scene).setDebugOff(BIT(2));
	case "MLink":
		(%this.scene).setDebugOff(BIT(3));
	case "WLimit":		
		(%this.scene).setDebugOff(BIT(4));
	case "ALL":
		(%this.scene).setDebugOff(0xFFFFFF);
	}
}

function HelperGui::hide(%this)
{
	if(%this.hidden $= false)
	{
			DebugControls.setVisible(false);
		%this.hidden = true;
	} else
	{
		DebugControls.setVisible(true);
		%this.hidden = false;
	}
}


now go to your "client.cs"


find
// Load-up Datablocks.	
	exec("./datablocks.cs");
	// Load-up GUIs.
	exec("./mainScreenGui.gui");

then add this right after it

exec("./HelperGui.gui");

thats how you add a gui so you can load it ... now go down a couple lines and find

// Set GUI.
	Canvas.setContent(mainScreenGui);
	// Set Cursor.
	Canvas.setCursor(DefaultCursor);
	//Canvas.pushDialog(HelperGui);

and add this

mainScreenGui.add(HelperGui);


this will add it to the main gui so you can use it at the same time... note the hide button that i will hide the buttons out of the way... and the text input box is for whatever you want to set debug modes for... leave it as default if you want to change all and haven't changed your sceneGraph name...
#2
03/04/2005 (1:10 pm)
Some pics

www.razedskyz.com/games/torque/tutorials/debugGUI/debugGUI1.JPG
www.razedskyz.com/games/torque/tutorials/debugGUI/debugGUI2.JPG
www.razedskyz.com/games/torque/tutorials/debugGUI/debugGUI3.JPG
www.razedskyz.com/games/torque/tutorials/debugGUI/debugGUI4.JPG
#3
03/04/2005 (4:26 pm)
Awsome, im adding this in.

Ive been spending all my time trying to learn the gui system and not getting any work done on my lil tool. So today im going to stop and work on the real meat of it.

Where are the docs that can tell you every script function and hopefully with a lil description?
#4
03/04/2005 (4:36 pm)
Thanks Matt! You rock. :)

Chris, see this page and look at the "Scripting documentation" section. :)
#5
03/04/2005 (10:59 pm)
Pretty cool. What's the purpose of the text field? It eats all of the key presses so I can't control anything in the game while running.
#6
03/05/2005 (1:15 pm)
Ouch, sorry Seth did this at work so didn't test it too much, to fix that do change this

modified the first post to include these changes :)

new GuiButtonCtrl() {
      profile = "GuiButtonProfile";
      horizSizing = "right";
      vertSizing = "bottom";
      position = "380 0";
      extent = "40 15";
      minExtent = "8 2";
      visible = "1";
      text = "ALL";
      groupNum = "1";
      buttonType = "PushButton";
	command = "HelperGui.setMode(ALL);";
   };
   };

   new GuiButtonCtrl() {
      profile = "GuiButtonProfile";
      horizSizing = "right";
      vertSizing = "bottom";
      position = "420 0";
      extent = "40 15";
      minExtent = "8 2";
      visible = "1";
      text = "Hide";
      groupNum = "-1";
      buttonType = "PushButton";
	command = "HelperGui.hide();";
   };

   new GuiMLTextEditCtrl(sceneName) {
      profile = "GuiMLTextEditProfile";
      horizSizing = "right";
      vertSizing = "bottom";
      position = "465 0";
      extent = "120 18";
      minExtent = "8 2";
      visible = "1";
      lineSpacing = "2";
      allowColorChars = "0";
      maxChars = "-1";
   };


};
//--- OBJECT WRITE END ---

to

new GuiButtonCtrl() {
      profile = "GuiButtonProfile";
      horizSizing = "right";
      vertSizing = "bottom";
      position = "380 0";
      extent = "40 15";
      minExtent = "8 2";
      visible = "1";
      text = "ALL";
      groupNum = "1";
      buttonType = "PushButton";
	command = "HelperGui.setMode(ALL);";
   };
   

  
   new GuiMLTextEditCtrl(sceneName) {
      profile = "GuiMLTextEditProfile";
      horizSizing = "right";
      vertSizing = "bottom";
      position = "420 0";
      extent = "120 18";
      minExtent = "8 2";
      visible = "1";
      lineSpacing = "2";
      allowColorChars = "0";
      maxChars = "-1";
   };
};
 new GuiButtonCtrl() {
      profile = "GuiButtonProfile";
      horizSizing = "right";
      vertSizing = "bottom";
      position = "540 0";
      extent = "40 15";
      minExtent = "8 2";
      visible = "1";
      text = "Hide";
      groupNum = "-1";
      buttonType = "PushButton";
	command = "HelperGui.hide();";
   };



};
//--- OBJECT WRITE END ---


basically you just moved a bracket so the text field is included in "Debug Controls" and swaping the text field's position with the hide button.... that way when you click hide it will hide the text field too...
#7
03/05/2005 (1:34 pm)
Cool. Thanks!
#8
03/05/2005 (2:47 pm)
Btw sorry didn't tell you what the text field was for... when you hit debug buttons it applies that mode to the object in there, by default I have it set to the default scengraph which will set it for all.. if you renamed the scengraph you'd put the new name there... or say when you create the player

$player = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };

if you do

$player = new fxStaticSprite2D(Player) { scenegraph = t2dSceneGraph; };

you then could put "Player" in the text field and apply the debug modes to just that object
#9
03/05/2005 (6:53 pm)
Very nice. I've already found it useful
#10
03/06/2005 (3:18 am)
One of the ideas I had for the T2D debug-info was the ability to pass an expression (such as a variable) and have T2D add it to a special section of the debug-info, sort of like a class "tweaker".

Maybe I'll get around to that one day.

Good work Matthew.

- Melv.