Unexpected menu behavior
by Jon Mitchell · in Torque Game Builder · 03/19/2007 (1:09 pm) · 2 replies
I am working on a menu based on this tutorial:
http://tdn.garagegames.com/wiki/TGB/MiniTuturials/GUIOptionsMenu
I have added a second option menu that opens a new menu over the main menu, however if I hit delete, the binded key to open and close the main menu the main menu will close and re-open over the current menu, however the original option menu this will not happen. I was thinking it has something to do with the else if statements so I removed the else if for the optionsMenuGui however the main menu still could be closed, but would not re-open over the levelChooseGui menu
The only difference I see between the two menus is that the options menu gets the initialize function called as the menu is opened.
It is not a huge deal that the main menu can close under one sub-menu window and not another, it is mostly me being picky :-)
Anyone have any thoughts on the issue I have run into?
oops, too much code not enough space, looks like I have to paste it in a reply. :-p
http://tdn.garagegames.com/wiki/TGB/MiniTuturials/GUIOptionsMenu
I have added a second option menu that opens a new menu over the main menu, however if I hit delete, the binded key to open and close the main menu the main menu will close and re-open over the current menu, however the original option menu this will not happen. I was thinking it has something to do with the else if statements so I removed the else if for the optionsMenuGui however the main menu still could be closed, but would not re-open over the levelChooseGui menu
The only difference I see between the two menus is that the options menu gets the initialize function called as the menu is opened.
It is not a huge deal that the main menu can close under one sub-menu window and not another, it is mostly me being picky :-)
Anyone have any thoughts on the issue I have run into?
oops, too much code not enough space, looks like I have to paste it in a reply. :-p
#2
to this:
and the menus work normally now.
03/19/2007 (5:37 pm)
Huh, I guess it was an else if issue, I changed this:// this check ensures the main window won't close if the options menu is open!
else if(optionsMenuGui.isAwake())
{
Canvas.popDialog(%this);
}
// this check ensures the main window won't close if the level menu is open!
else if (levelChooseGui.isAwake())
{
Canvas.popDialog(%this);
}to this:
// this check ensures the main window won't close if other menus are open!
else if(!optionsMenuGui.isAwake() && !levelChooseGui.isAwake())
{
Canvas.popDialog(%this);
}and the menus work normally now.
Torque Owner Jon Mitchell
Studio with out a name
//************************************main menu keybinding and setup**************************************** // bind key moveMap.bindCmd(keyboard, "delete", mainmenu @ ".toggleMenu();", ""); // toggle the main menu function mainmenu::toggleMenu(%this) { if(!%this.isAwake()) { Canvas.pushDialog(%this); } // this check ensures the main window won't close if the options menu is open! else if(!optionsMenuGui.isAwake()) { Canvas.popDialog(%this); } // this check ensures the main window won't close if the level menu is open! else if (!levelChooseGui.isAwake()) { Canvas.popDialog(%this); } } //************************************main menu items**************************************** //The close menu button is not listed here because it uses the same function as the keybind to open the menu function mainmenu::chooseLevel(%this) { // open the level menu up! if(!levelChooseGui.isAwake()) { // display the level menu Canvas.pushDialog(levelChooseGui); } } //This opens options window function mainmenu::playOptions(%this) { // open the options menu up! if(!optionsMenuGui.isAwake()) { // tell the options menu to get ready optionsMenuGui.initialize(); // display the options menu Canvas.pushDialog(optionsMenuGui); } } // exit the game function mainmenu::exit(%this) { // exit T2D quit(); } //************************************option menu items**************************************** // initialize various options menu controls function optionsMenuGui::initialize(%this) { // get the window's child elements by internal name %pointsField = %this.findObjectByInternalName("pointsField", true); %bouncyOff = %this.findObjectByInternalName("off", true); %bouncyOn = %this.findObjectByInternalName("on", true); %bouncyRandom = %this.findObjectByInternalName("random", true); %shotNormal = %this.findObjectByInternalName("normal", true); %shotFast = %this.findObjectByInternalName("fast", true); %shotBlazing = %this.findObjectByInternalName("blazing", true); // set all the default values of the controls from file %pointsField.setValue($options::pointsField); %bouncyOff.setValue($options::bouncyOff); %bouncyOn.setValue($options::bouncyOn); %bouncyRandom.setValue($options::bouncyRandom); %shotNormal.setValue($options::shotNormal); %shotFast.setValue($options::shotFast); %shotBlazing.setValue($options::shotBlazing); } // cancel the changes and close the options menu function optionsMenuGui::cancelChanges(%this) { // just close the options menu and forget the changes Canvas.popDialog(%this); } // apply the changes and close the options menu function optionsMenuGui::applyChanges(%this) { // get the window's child elements by internal name %pointsField = %this.findObjectByInternalName("pointsField", true); %bouncyOff = %this.findObjectByInternalName("off", true); %bouncyOn = %this.findObjectByInternalName("on", true); %bouncyRandom = %this.findObjectByInternalName("random", true); %shotNormal = %this.findObjectByInternalName("normal", true); %shotFast = %this.findObjectByInternalName("fast", true); %shotBlazing = %this.findObjectByInternalName("blazing", true); // assign the variables to a sub-section of a prefs global $options::pointsField = %pointsField.getValue(); $options::bouncyOff = %bouncyOff.getValue(); $options::bouncyOn = %bouncyOn.getValue(); $options::bouncyRandom = %bouncyRandom.getValue(); $options::shotNormal = %shotNormal.getValue(); $options::shotFast = %shotFast.getValue(); $options::shotBlazing = %shotBlazing.getValue(); // export these prefs to our optionsMenu prefs file export("$options::*", "~/data/gameprefs.cs"); // close the options menu Canvas.popDialog(%this); } //************************************level menu items**************************************** //command for buttons on the menu to go in the command field: mainmenu.newGame1(); // start a new game function levelChooseGui::newGame1(%this) { sceneWindow2D.loadLevel("tank_mp_test/data/levels/level1.t2d"); Canvas.popDialog(%this); mainMenu.toggleMenu(); } function levelChooseGui::newGame2(%this) { sceneWindow2D.loadLevel("tank_mp_test/data/levels/level2.t2d"); Canvas.popDialog(%this); mainMenu.toggleMenu(); } function levelChooseGui::newGame3(%this) { sceneWindow2D.loadLevel("tank_mp_test/data/levels/level3.t2d"); Canvas.popDialog(%this); mainMenu.toggleMenu(); } function levelChooseGui::newGame4(%this) { sceneWindow2D.loadLevel("tank_mp_test/data/levels/level4.t2d"); Canvas.popDialog(%this); mainMenu.toggleMenu(); } // cancel and close the level menu function levelChooseGui::cancel(%this) { Canvas.popDialog(%this); }