How to toggle GUI on/off screen
by Richard Jernejcic · in Game Design and Creative Issues · 03/13/2005 (4:00 pm) · 12 replies
Hi, yall! Trying to set up a GUI to toggle on and off with a push of a button. I created a simple GUI (GUI Window Control type) with a button that closes it. I tested it with the "canvas.push" command in the console, and it works correctly. Then I went to default.bind.cs and added the following function definition right under the optionsDlg function, in order to test that I could bring it up with a push of the "g" button:
------------------------------------------------------------
function bringUpGI(%val)
{
if (%val)
Canvas.pushDialog(GalacticInterface);
}
moveMap.bind(keyboard, "ctrl g", bringUpGI);
------------------------------------------------------------
I don't get any errors when I run the demo, but when I enter the mission and push the "g" key, nothing happens. Furthermore, I'm not sure how to go to the next step to make it so it toggles on and off with the push of the "g" button. I'm still a noob, and though I tried different ways (following some of the other example functions in the default.bind.cs file), no luck. Little help would be appreciated. Thanks.
------------------------------------------------------------
function bringUpGI(%val)
{
if (%val)
Canvas.pushDialog(GalacticInterface);
}
moveMap.bind(keyboard, "ctrl g", bringUpGI);
------------------------------------------------------------
I don't get any errors when I run the demo, but when I enter the mission and push the "g" key, nothing happens. Furthermore, I'm not sure how to go to the next step to make it so it toggles on and off with the push of the "g" button. I'm still a noob, and though I tried different ways (following some of the other example functions in the default.bind.cs file), no luck. Little help would be appreciated. Thanks.
About the author
#2
If I may, I'd like to ask a few follow-up GUI question regarding how the GUI's look. First, how do you change the color of the standard GUI dialog boxes?
Second, is there any way to add features, like the ability to drag and resize, to GUI elements that don't have them by default? For example: I want to design a GUIbitmapCtrl that has a bitmap shape, but that is "drag-able" and "resize-able like the GUIWindowCtrl (or vice-versus, if you get my meaning).
Finally, is there a consolidated list somewhere of all these special functions like ".isAwake"?
Thanks again for the great suggestion above. I'll try it this evening, and let you know if it works out.
03/14/2005 (10:22 am)
Jacob: Thanks a heap! I'll give that a try. I hadn't come across the .isAwake() bit yet in my reading.If I may, I'd like to ask a few follow-up GUI question regarding how the GUI's look. First, how do you change the color of the standard GUI dialog boxes?
Second, is there any way to add features, like the ability to drag and resize, to GUI elements that don't have them by default? For example: I want to design a GUIbitmapCtrl that has a bitmap shape, but that is "drag-able" and "resize-able like the GUIWindowCtrl (or vice-versus, if you get my meaning).
Finally, is there a consolidated list somewhere of all these special functions like ".isAwake"?
Thanks again for the great suggestion above. I'll try it this evening, and let you know if it works out.
#3
Regarding changing color; if you want to change the fill color of a GUI control, find the profile it is using in defaultProfiles.cs and see if it has a "fillColor" field. If so, just change it there. If not, "fillColor" either doesn't apply to that particular GUI Control or it is using the value from the "parent" Control - "GuiDefaultProfile" itself...also found in defaultProfiles.cs. You can change it there but if you do, it will affect any other profile that takes the value from it.
I haven't had a need to implement Controls that are move-able, so my suggestion would be to search the resources for that :)
To get a list of all registered console methods in your build, type dumpConsoleClasses(); from the console. It will just list them right there. When you exit the game you can save the console.log file for later use.
You can do a search in your console.log for any class like "GuiTextListCtrl" and any of its methods will be right there. Have fun!
03/14/2005 (4:59 pm)
Happy to help!Regarding changing color; if you want to change the fill color of a GUI control, find the profile it is using in defaultProfiles.cs and see if it has a "fillColor" field. If so, just change it there. If not, "fillColor" either doesn't apply to that particular GUI Control or it is using the value from the "parent" Control - "GuiDefaultProfile" itself...also found in defaultProfiles.cs. You can change it there but if you do, it will affect any other profile that takes the value from it.
I haven't had a need to implement Controls that are move-able, so my suggestion would be to search the resources for that :)
To get a list of all registered console methods in your build, type dumpConsoleClasses(); from the console. It will just list them right there. When you exit the game you can save the console.log file for later use.
You can do a search in your console.log for any class like "GuiTextListCtrl" and any of its methods will be right there. Have fun!
#4
Any ideas?
03/15/2005 (8:40 am)
Jacob: Thanks for the additional info. Now for the bad news: The script snippet you provided gives no errors when I start up Torgue, but I still get nothing when I hit the "g" key to attempt to pup up the GUI. I can canvas.pushDialog from the console and get the GUI to appear, but the function call is not working. :( Is there some attribute I need to have selected in the GUI itself? I compared my GUI to the standard OptionsDlg.gui, and the only difference I saw was the parent GUI had a check box labeled "setHelp" (or something like that) with a value of zero. I'm using the same gui profile for mine, but it doesn't even have that checkbox available. I'm stumped. This should be a really simple thing, but nothing I've done seems to work. I've even tried replacing my GUI's name in the function call that pushes the OptionsDlg GUI to the screen...nothing!Any ideas?
#5
FYI: I believe that starter.fps/client/scripts/default.bind.cs gets executed first and than any "custom" binds in starter.fps/client/config.cs. This gives you a way to over-ride any default binds if you wish. Anyway, my directory and script structure is completely different from the demo (starter.fps) so I hope all the above info is correct :)
03/15/2005 (9:33 am)
Try putting your binding command in starter.fps/client/config.cs (substitute your mod name for "starter.fps" if you have changed the name). As you can see, the first thing that happens in config.cs is that anything that was bound under MoveMap gets deleted - your command included if it was executed before config.cs. So, just insert it somewhere in that file and you should be good to go.FYI: I believe that starter.fps/client/scripts/default.bind.cs gets executed first and than any "custom" binds in starter.fps/client/config.cs. This gives you a way to over-ride any default binds if you wish. Anyway, my directory and script structure is completely different from the demo (starter.fps) so I hope all the above info is correct :)
#6
03/15/2005 (11:48 am)
Ah, that might explain it. So just the binding command should go in config.cs, and not the function itself? Our mod started with the starter.fps, so it sounds like that may be what's happening. I'll check out the config.cs script file when I get home. Thanks again, and I'll let you know how it turns out.
#7
03/15/2005 (11:54 am)
Yes, just put the binding command in config.cs and the function can go anywhere. A common place to put GUI specific functions is either at the end of the YouGui.gui file or make a YourGui.cs file which can contain all functionality pertaining to YourGui. Keeps it nice and organized that way. :)
#8
--------------------------------------------
moveMap.bindCmd(keyboard, "escape", "", "myfunction();");
--------------------------------------------
Yes, the escape key is used for the exit-game function normally; I made sure to comment out the original moveMap line in both the default.bind.cs and config.cs files. Anyway, the game loaded up okay, with no errors reported, but hitting escape key did nothing. I also had the "g" key bound to myfunction(), which still worked okay. On a hunch, I commented out the moveMap.bind line for the "g" mapping, thinking that perhaps I couldn't have the same function mapped to more than one key, but this didn't make the "escape" key mapping work. Is there some restriction or formatting trick with the moveMap.bindCmd method?
03/16/2005 (7:58 am)
Jacob: Got it working now; thanks. Okay, next step: how do I make it non-remap-able? I think I'm supposed to use the moveMap.bindCmd. I tried this:--------------------------------------------
moveMap.bindCmd(keyboard, "escape", "", "myfunction();");
--------------------------------------------
Yes, the escape key is used for the exit-game function normally; I made sure to comment out the original moveMap line in both the default.bind.cs and config.cs files. Anyway, the game loaded up okay, with no errors reported, but hitting escape key did nothing. I also had the "g" key bound to myfunction(), which still worked okay. On a hunch, I commented out the moveMap.bind line for the "g" mapping, thinking that perhaps I couldn't have the same function mapped to more than one key, but this didn't make the "escape" key mapping work. Is there some restriction or formatting trick with the moveMap.bindCmd method?
#9
03/16/2005 (7:50 pm)
What you have there should work. You are correct, the bindCmd is for non-remappable keys. The args for bindCmd are: device, action, makeCmd, breakCmd. Not exactly sure what the make/break do at this time... Anyhow, I tried your bindCmd, inserting "myFunction();" as the 3rd and than 4th arg and it worked both ways. Also, you CAN have the same function bound to more than one key - no restrictions on that. So, check spelling and run with console trace "on" to try and track it down.
#10
03/17/2005 (7:32 am)
Okay, thanks for checking it. I'll have to check things again. Not sure how to turn console trace on, as you suggest. Up to now, I just open console after attempting to execute it to see if any errors are reported.
#11
To turn on Trace use trace(true), to turn it off use trace(false). Trace will dump function calls and their parameters as well as return values to the log.
03/17/2005 (8:05 am)
@RichardTo turn on Trace use trace(true), to turn it off use trace(false). Trace will dump function calls and their parameters as well as return values to the log.
#12
03/18/2005 (6:30 am)
Todd: Thanks. I will type trace(true) into the console and see how it functions. Really appreciate all the help available to the noobs like myself. Making real progress would be much more difficult without the willing support from people like you and Jacob.
Torque 3D Owner Jacob
Try this:
function ToggleGui(%val) { if(%val) { if(YourGui.isAwake()) canvas.popDialog(YourGui); else canvas.pushDialog(YourGui); } } moveMap.bind(keyboard, "ctrl g", ToggleGui);This will toggle "YourGui" on and off. "1" gets passed into the function as %val whenever the key is pressed and "0" gets passed when it is released. Thus, you want to test for %val so that your "toggle" only executes when the key is pressed...and not again when it is released. Have fun! :)
Edit: since you mentioned that you want to use the "g" key, just put:
...otherwise you need to press ctrl+g to get it to work.