GuiButtonCtrl problems
by James Laker (BurNinG) · in Torque Game Engine · 02/11/2008 (7:43 am) · 3 replies
I dunno if it's just one of those mondays, but I'm struggling with what I believe should be basic GUI knowledge.
I have 8 guiButtonCtrls which you need to click to view the Ship information, before you actually warp into battle.
So as you might have guessed I changed buttonType to RadioButton, and changed their groupNum to 1.
eg.
So my first question is - How would I know which button is selected for a group? (in this case groupNum = 1)
I've read about getSelectedRadio... But that's nowhere to be found in the engine.
Second question... I can add a a dynamic value to the GuiButtonCtrl like i did with:
value = "DroneCarrierShip";
How would I get that value again?
Then I have a "Warp into Battle" button.
Here's what I have currently, to give you an idea what I want to do:
Any help would be appreciated here... But I for some reason cant figure it out. Surely there must be a way without using crappy guiRadiobuttonCtrls.
I have 8 guiButtonCtrls which you need to click to view the Ship information, before you actually warp into battle.
So as you might have guessed I changed buttonType to RadioButton, and changed their groupNum to 1.
eg.
new GuiButtonCtrl() {
canSaveDynamicFields = "0";
Profile = "_GAME_GuiButtonProfile";
HorizSizing = "right";
VertSizing = "bottom";
position = "8 362";
Extent = "100 30";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
Command = "UpdateShipInfo();";
hovertime = "1000";
text = "Drone Carrier";
value = "DroneCarrierShip";
groupNum = "1";
buttonType = "RadioButton";
};So my first question is - How would I know which button is selected for a group? (in this case groupNum = 1)
I've read about getSelectedRadio... But that's nowhere to be found in the engine.
Second question... I can add a a dynamic value to the GuiButtonCtrl like i did with:
value = "DroneCarrierShip";
How would I get that value again?
Then I have a "Warp into Battle" button.
new GuiButtonCtrl() {
canSaveDynamicFields = "0";
Profile = "_GAME_GuiButtonProfile";
HorizSizing = "right";
VertSizing = "bottom";
position = "534 435";
Extent = "100 30";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
Command = "WarpToBattle();";
hovertime = "1000";
text = "Warp to Battle >>";
groupNum = "-1";
buttonType = "PushButton";
};Here's what I have currently, to give you an idea what I want to do:
function WarpToBattle()
{
%selectedShipButton = getSelectedRadio(1);
%shipType = %selectedShipButton.getValue();
echo("%shipType = " @ %shipType);
Canvas.popDialog(guiSelectShip);
commandtoserver('SpawnSelectedShip', %ShipType);
}
function UpdateShipInfo()
{
echo("Update the guiObjectviews in the ShipSelectGui");
//Here i'm going to show a preview of the ship, ship attributes and weapons.
}Any help would be appreciated here... But I for some reason cant figure it out. Surely there must be a way without using crappy guiRadiobuttonCtrls.
#2
To get buttons to act as a radio group you must:
1. set buttontype to radio button
2. set groupNum the same for allthe buttions in the "group"
3. have the same parent container
(With the groupNum and parent container the same, the radio buttons can communicate amongst themselves to coordinate their states properly when one is clicked.)
Maybe you aren't meeting the third condition.
Here is where a little bit more high level written documentation would add a lot. I recall going round and around with some controls trying to do things that simply were hard to do because I was assuming the wrong "paradigm" for the design. A few sentences in the header of each control type explaining the basic "paradigm" of their usage could have saved me a lot of confusion. Without this kind of high level overview, you really need to just review the code briefly to see what methods and call backs are provided, in order to get your head around the way the original designer appears to have imagined the control would be used. Everytime I do this I curse the original author who could have saved 10,000 individual readers this task by writing his two sentences once ;)
If you just need to read the value of your radio set(s) later, then use the "command" for each button to set a logical variable in script to store it. e.g.:
Command = "$screenxxxRadio1Selected=3;";
I agree that it would be nice if the container could retain the last selected radio button. It seems that a simple new subclass of the GuiControl could be done to make a GuiRadioContainer control that did this.
I run into more problems syncing the displayed state of the controls to match (usually saved) defaults each time the screen is entered. To set up a "default" state and sync the logical state with the displayed state of the Gui, I often use control.performClick() in the gui.onWake().
Sometimes this command does a lot of work (e.g.: loads a selected DTS file). Often, it doesn't work correctly unless all of several radio sets of defaults have already been set up before the work is done. To do this, I put an "$enabled" type check in each responding command to NOT do some parts of the normal function when $enabled is off. Then I set $enabled to false, call the .performClick() on the correct default selection within each of several sets of radio buttons, then turn the $enabled back on and then call whatever method that operates on the selections currently set in the several radio groups.
02/11/2008 (10:20 am)
I'm not sure what the issue is from your notes above (so it is probably something basic! :) )To get buttons to act as a radio group you must:
1. set buttontype to radio button
2. set groupNum the same for allthe buttions in the "group"
3. have the same parent container
(With the groupNum and parent container the same, the radio buttons can communicate amongst themselves to coordinate their states properly when one is clicked.)
Maybe you aren't meeting the third condition.
Here is where a little bit more high level written documentation would add a lot. I recall going round and around with some controls trying to do things that simply were hard to do because I was assuming the wrong "paradigm" for the design. A few sentences in the header of each control type explaining the basic "paradigm" of their usage could have saved me a lot of confusion. Without this kind of high level overview, you really need to just review the code briefly to see what methods and call backs are provided, in order to get your head around the way the original designer appears to have imagined the control would be used. Everytime I do this I curse the original author who could have saved 10,000 individual readers this task by writing his two sentences once ;)
If you just need to read the value of your radio set(s) later, then use the "command" for each button to set a logical variable in script to store it. e.g.:
Command = "$screenxxxRadio1Selected=3;";
I agree that it would be nice if the container could retain the last selected radio button. It seems that a simple new subclass of the GuiControl could be done to make a GuiRadioContainer control that did this.
I run into more problems syncing the displayed state of the controls to match (usually saved) defaults each time the screen is entered. To set up a "default" state and sync the logical state with the displayed state of the Gui, I often use control.performClick() in the gui.onWake().
Sometimes this command does a lot of work (e.g.: loads a selected DTS file). Often, it doesn't work correctly unless all of several radio sets of defaults have already been set up before the work is done. To do this, I put an "$enabled" type check in each responding command to NOT do some parts of the normal function when $enabled is off. Then I set $enabled to false, call the .performClick() on the correct default selection within each of several sets of radio buttons, then turn the $enabled back on and then call whatever method that operates on the selections currently set in the several radio groups.
#3
I'm sure it would save ALOT of headaches is the tdn.garagegames.com/wiki/GUI/Profiles/ControlList was just complete. But I'm just gonna blame it on Monday ;)
Thanx again.
02/11/2008 (12:08 pm)
Awesome... Thanx for the input. The getValue was the little bugger... :) All is working good n nice now... yayI'm sure it would save ALOT of headaches is the tdn.garagegames.com/wiki/GUI/Profiles/ControlList was just complete. But I'm just gonna blame it on Monday ;)
Thanx again.
Associate Fyodor "bank" Osokin
Dedicated Logic
When the button "selected", getting %obj.getValue() will return 1 - all other button will give you "0".
Note: all your buttons should be inside single gui control - so engine can "disable" all other buttons inside the same group (groupNum).
Next:
I would recommend you to change:
Command = "UpdateShipInfo();";
To something like:
Command = "UpdateShipInfo(1);";.
Where 1 is the "ship type" (or place "String" value there if not using integers.
Then, inside the function do a simple check - getting the right value:
function UpdateShipInfo(%id) { // do what you need depending of the passed id from button click // Load models, etc $tmp::selectedShip = %id; }Using this is more gives you more clear code - you can mix different gui controls.Or, you can do simply:
for (%i=0;%parentOfButtonsCtrl.getCount();%i++) { %button = %parentOfButtonsCtrl.getObject(%i); if (%button.getValue()) { // Do your stuff here, but then you need to get idea of what kind of ship selected break; } }function WarpToBattle() { echo("%shipType = " @ $tmp::selectedShip); Canvas.popDialog(guiSelectShip); commandtoserver('SpawnSelectedShip', $tmp::selectedShip); }Hope this helps :)
Edit: ohh.. I see.
Command = "UpdateShipInfo(\"DroneCarrierShip\");";.
This is what you need. :)
Then, simply get the %id from called function - and pass it where you need it.