Game Development Community

Dynamic GUI's

by Dreamer · in Torque Game Engine · 03/31/2005 (1:40 pm) · 13 replies

I'm working on a skill system ala Everquest and have the following all but functional, Forage, Fishing, Mining, WoodCutting.

I need to create a GUI that can show a dynamic number of pushbuttons depending on whether a player infact has a skill or not.

Here is my code thus far...
new GuiControl(SkillsGUI) {
	profile = "GuiDefaultProfile";
	horizSizing = "right";
	vertSizing = "bottom";
	position = "0 0";
	extent = "100 200";
	minExtent = "8 8";
	visible = "1";
	helpTag = "0";

	new GuiWindowCtrl() {
		profile = "GuiWindowProfile";
		horizSizing = "center";
		vertSizing = "center";
		position = "131 10";
		extent = "120 200";
		minExtent = "8 8";
		visible = "1";
		helpTag = "0";
		text ="Skills";
		maxLength = "255";
		resizeWidth = "0";
		resizeHeight = "0";
		canMove = "1";
		canClose = "1";
		canMinimize = "0";
		canMaximize = "0";
		minSize = "25 25";
		closeCommand = "Canvas.popDialog(SkillsGUI);";
	

};
};

SkillsGUI::OnWake(){
     for(%x = 0; %x <= $Skills.Count; %x++){
         new GuiButtonCtrl($Skills.Name[%x]) {
			profile = "GuiButtonProfile";
			horizSizing = "right";
			vertSizing = "top";
			position = "%x+45 30";
			extent = "45 45";
			minExtent = "8 8";
			visible = "1";
			command = "Canvas.PopDialog(SkillsGUI);CommandToServer($Skills.Name[%x]);";
			text = $Skills.Name[%x];
			groupNum = "3";
			buttonType = "PushButton";
			helpTag = "0";
         };
    }
}
This code however seems to produce gigantic screen filling buttons, I guess I could create individual buttons for each skill, but I would like skills to be completely dynamic and if a player doesn't have or hasn't learned a skill I don't want it to show up in the Skills GUI.

Any Ideas?

#1
04/01/2005 (6:09 am)
You can add new controls dynamically in the .cs files, for example:
new GUIBitmapCtrl(bnFrame)
	{
		 profile = "GuiDefaultProfile";
		 horizSizing = "right";
		 vertSizing = "bottom";
		 position = "0 0";
		 extent = "43 28";
		 minExtent = "8 2";
		 visible = "0";
		 groupNum = "-1";		 
		 text = "Frame";		 
		 bitmap = "starter.RTS/client/ui/combat/unit_frame";
	};
	CombatDisplay.add(bnFrame);

or like this if you want an array of controls:
$unitArray[%i] = new GUIBitmapButtonCtrl(bnUnit)
	{ ... }
	CombatDisplay.add($unitArray[%i]);
#2
04/01/2005 (6:35 am)
I notice your Bitmap points to starter.rts I assume you are using the RTS kit?
Will this work with the basic TGE
#3
04/01/2005 (8:01 am)
Yes, the script language is the same.
#4
04/01/2005 (10:39 am)
Ok, I was under the impression that there had been GUI system changes in RTS.
#5
04/01/2005 (5:09 pm)
There are additional "user input primitives" (drag-select a group of units for example), but the RTS-SK uses the same underlying functionality for just about everything--just optimized (stripped down for the most part), or enhanced (for new cool stuff) as appropriate.

GUI's themselves I don't think were touched at all.
#6
04/01/2005 (5:11 pm)
Might want to check out my GUI Builder. It is specifically designed for creating dynamic guis
#7
04/01/2005 (5:16 pm)
Here is a link to the release of the Toruqe GUI Builder.
#8
04/02/2005 (4:05 pm)
Thanx man, but I don't think I really understand the possible uses for that tool. It seems nice though.
#9
04/02/2005 (4:07 pm)
Quote:I need to create a GUI that can show a dynamic number of pushbuttons depending on whether a player infact has a skill or not

The use is for things like that. Dynamicly generating GUIs at runtime based on factors in the game.
#10
04/03/2005 (1:56 am)
No what I mean is I can't see how your resource could be used for my specific issue. Sorry for the mixup.
#11
04/05/2005 (4:06 pm)
Wow, really? Did you read the resource fully? It really seems from what you were talking about the Torque GUI builder is _exactly_ what you need. You want to do it from scratch? Good luck
#12
07/09/2005 (12:30 am)
Actually I eventually figured it out and ended up with this little tidbit, it's an adjustment to the inventoryGUI I made quite awhile ago, but the same principle applies to any dynamically generated gui. First get data, then add it to the gui, using it's parents .add function, like this :)

//--- OBJECT WRITE BEGIN ---
new GuiControl(InventoryGUI) {
   profile = "GuiDefaultProfile";
   horizSizing = "right";
   vertSizing = "bottom";
   position = "0 0";
   extent = "640 480";
   minExtent = "8 2";
   visible = "1";

   new GuiWindowCtrl(InventoryWindow) {
      profile = "GuiWindowProfile";
      horizSizing = "right";
      vertSizing = "bottom";
      position = "2 -2";
      extent = "640 480";
      minExtent = "8 2";
      visible = "1";
      text = "Inventory";
      maxLength = "255";
      resizeWidth = "1";
      resizeHeight = "1";
      canMove = "1";
      canClose = "1";
      canMinimize = "1";
      canMaximize = "1";
      minSize = "50 50";
      CloseCommand = "Canvas.PopDialog(InventoryGUI);";
   };
};

function InventoryWindow::OnWake(%this){
	InventoryWindow.clear();
	%query = "SELECT * From Inventory";
	%result = $LocalDB.query(%query,0);
	if(%result){
		%x = 10;
		%y = 20;
		while(!$LocalDB.EOF(%result)){
			%Item = $LocalDB.getColumn(%result,"Item");
			%Amount = $LocalDB.getColumn(%result,"Amount");
			$InvImage[%Item] = $LocalDB.getColumn(%result,"Image");
			InventoryListView.addRow(%x,%Item SPC %Amount);
			echo("Added "@%Item@" to GUI");
			echo("InvImage is "@$InvImage[%Item]);
			%pos = %x SPC %y;
			%InventoryItemView = new GuiObjectView() {
				profile = "GuiDefaultProfile";
				horizSizing = "relative";
				vertSizing = "relative";
				position = %pos;
				extent = "50 50";
				minExtent = "8 2";
				visible = "1";
				helpTag = "0";
				cameraZRot = "0";
				forceFOV = "0";
      			};
			InventoryWindow.add(%InventoryItemView);
			%InventoryItemView.setObject(%Item,$InvImage[%Item],"", 0);
			%x = %x + 60;
			if(480 - %x < 10){
				%y += 10;
				%x = 10;
			}
			$LocalDB.nextRow(%result);
		}
	}
}
#13
07/10/2005 (9:29 am)
Dreamer,

How do you handle adding or deleting items for your inventory? Do you have something that deallocates the GuiObjectViews? How do you distinguish one GuiObjectView from another?