Game Development Community

Make multiple gui controls go invisible at once

by Richard Preziosi · in Torque Game Engine · 04/25/2008 (1:26 am) · 5 replies

First off let me appologize for the horrendus amount of questions i've asked in the past few days. But I have actually learned a lot by asking, and don't think I'll learn as much by not asking. Plus I've spent a few hundred dollars on all of this, so I'm not gonna be afraid to ask a million questions, so here we go.

Ok I'm making my own sort of tabbed window that consists of 5 buttons. Each button sets visible an invisible gui control below it. But i need to make sure that when the button is pressed that it sets any other gui control that should not be visible, invisible. For instance if i press inventory, it should make sure quests, map, tradeskills, etc are all invisible and only the inventory window is visible. I have wrote a function that should do this, but I cannot for the life of me get it to work. So I figured I'd see what the community could suggest.

Here is my function for changing the window, this is located at the bottom of my gui file, which i will post after this, it wouldn't let me post it all at once.

function changeWindow(){

   if( inventorywindow ){

      inventorywindow.setVisible(true);
      abilitieswindow.setVisible(false);
      tradeskillswindow.setVisible(false);
      questswindow.setVisible(false);
      worldmapwindow.setVisible(false);

}
   else if( abilitieswindow ){
     
      inventorywindow.setVisible(false);
      abilitieswindow.setVisible(true);
      tradeskillswindow.setVisible(false);
      questswindow.setVisible(false);
      worldmapwindow.setVisible(false);

}
   else if( tradeskillswindow ){
      
      inventorywindow.setVisible(false);
      abilitieswindow.setVisible(false);
      tradeskillswindow.setVisible(true);
      questswindow.setVisible(false);
      worldmapwindow.setVisible(false);


}
   else if( questswindow ){
      
   inventorywindow.setVisible(false);
      abilitieswindow.setVisible(false);
      tradeskillswindow.setVisible(false);
      questswindow.setVisible(true);
      worldmapwindow.setVisible(false);


}
   else if( worldmapwindow ){
      
   inventorywindow.setVisible(false);
      abilitieswindow.setVisible(false);
      tradeskillswindow.setVisible(false);
      questswindow.setVisible(false);
      worldmapwindow.setVisible(true);


}
}

#1
04/25/2008 (1:26 am)
Here is the top of my gui file
//--- OBJECT WRITE BEGIN ---
new GuiChunkedBitmapCtrl(GameMenu) {
   canSaveDynamicFields = "1";
   Profile = "GuiDefaultProfile";
   HorizSizing = "center";
   VertSizing = "center";
   position = "0 0";
   Extent = "640 480";
   MinExtent = "8 2";
   canSave = "1";
   Visible = "1";
   Command = "showGameMenu();";
   hovertime = "1000";
   bitmap = "./gamemenubackground.png";
   useVariable = "0";
   tile = "1";

   new GuiBitmapCtrl() {
      canSaveDynamicFields = "1";
      Profile = "GuiDefaultProfile";
      HorizSizing = "center";
      VertSizing = "center";
      position = "70 -10";
      Extent = "500 500";
      MinExtent = "8 2";
      canSave = "1";
      Visible = "1";
      hovertime = "1000";
      bitmap = "./gamemenuwindow.png";
      wrap = "0";

      new GuiBitmapButtonCtrl(tradeskillsbtn) {
         canSaveDynamicFields = "0";
         Profile = "GuiDefaultProfile";
         HorizSizing = "relative";
         VertSizing = "relative";
         position = "201 13";
         Extent = "94 19";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         Command = "changeWindow(tradeskillswindow);";
         hovertime = "1000";
         groupNum = "-1";
         buttonType = "PushButton";
         bitmap = "./buttons/tradeskills";
      };
      new GuiBitmapButtonCtrl(abilitiesbtn) {
         canSaveDynamicFields = "0";
         Profile = "GuiDefaultProfile";
         HorizSizing = "relative";
         VertSizing = "relative";
         position = "115 13";
         Extent = "71 19";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         Command = "changeWindow(abilitieswindow);";
         hovertime = "1000";
         groupNum = "-1";
         buttonType = "PushButton";
         bitmap = "./buttons/abilities";
      };
      new GuiBitmapButtonCtrl(worldmapbtn) {
         canSaveDynamicFields = "0";
         Profile = "GuiDefaultProfile";
         HorizSizing = "relative";
         VertSizing = "relative";
         position = "383 13";
         Extent = "96 22";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         Command = "changeWindow(wordmapwindow);";
         hovertime = "1000";
         groupNum = "-1";
         buttonType = "PushButton";
         bitmap = "./buttons/worldmap";
      };
      new GuiBitmapButtonCtrl(inventorybtn) {
         canSaveDynamicFields = "1";
         Profile = "GuiDefaultProfile";
         HorizSizing = "relative";
         VertSizing = "relative";
         position = "13 13";
         Extent = "96 22";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         Command = "changeWindow(inventorywindow);";
         hovertime = "1000";
         groupNum = "-1";
         buttonType = "PushButton";
         bitmap = "./buttons/inventory";
            NewDynamicField = "worldmapwindow.setvisible(false);";
      };
      new GuiBitmapButtonTextCtrl(questsbtn) {
         canSaveDynamicFields = "1";
         Profile = "GuiDefaultProfile";
         HorizSizing = "relative";
         VertSizing = "relative";
         position = "310 13";
         Extent = "59 23";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         Command = "changeWindow(questswindow);";
         hovertime = "1000";
         groupNum = "-1";
         buttonType = "PushButton";
         bitmap = "./buttons/quests";
      };
   };
   new GuiControl(worldmapwindow) {
      canSaveDynamicFields = "1";
      Profile = "GuiDefaultProfile";
      HorizSizing = "center";
      VertSizing = "center";
      position = "70 34";
      Extent = "500 412";
      MinExtent = "8 2";
      canSave = "1";
      Visible = "0";
      hovertime = "1000";

      new GuiBitmapCtrl() {
         canSaveDynamicFields = "1";
         Profile = "GuiDefaultProfile";
         HorizSizing = "center";
         VertSizing = "center";
         position = "35 55";
         Extent = "429 302";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         hovertime = "1000";
         bitmap = "./worldmapbg.png";
         wrap = "0";
      };
   };
   new GuiControl(inventorywindow) {
      canSaveDynamicFields = "0";
      Profile = "GuiDefaultProfile";
      HorizSizing = "right";
      VertSizing = "bottom";
      position = "70 34";
      Extent = "500 412";
      MinExtent = "8 2";
      canSave = "1";
      Visible = "0";
      hovertime = "1000";

      new GuiBitmapCtrl() {
         canSaveDynamicFields = "0";
         Profile = "GuiDefaultProfile";
         HorizSizing = "center";
         VertSizing = "center";
         position = "50 6";
         Extent = "400 400";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         hovertime = "1000";
         bitmap = "./inventorywindow.png";
         wrap = "0";
      };
   };
   new GuiControl(questswindow) {
      canSaveDynamicFields = "0";
      Profile = "GuiDefaultProfile";
      HorizSizing = "right";
      VertSizing = "bottom";
      position = "0 0";
      Extent = "64 64";
      MinExtent = "8 2";
      canSave = "1";
      Visible = "1";
      hovertime = "1000";
   };
   new GuiControl(tradeskillswindow) {
      canSaveDynamicFields = "0";
      Profile = "GuiDefaultProfile";
      HorizSizing = "right";
      VertSizing = "bottom";
      position = "0 0";
      Extent = "64 64";
      MinExtent = "8 2";
      canSave = "1";
      Visible = "1";
      hovertime = "1000";
   };
   new GuiControl(abilitieswindow) {
      canSaveDynamicFields = "0";
      Profile = "GuiDefaultProfile";
      HorizSizing = "right";
      VertSizing = "bottom";
      position = "0 0";
      Extent = "64 64";
      MinExtent = "8 2";
      canSave = "1";
      Visible = "1";
      hovertime = "1000";
   };
};
//--- OBJECT WRITE END ---

function toggleGameMenu(%val)
{
	if(%val)
              GameMenu.toggle();
}

function GameMenu::toggle(%this)
{
    if (%this.isAwake())
      Canvas.popDialog(%this);
    else
      Canvas.pushDialog(%this);
}
#2
04/25/2008 (2:00 am)
Again I've managed to answer my own question after I've posted it on the forums. So I will post my resolution as always incase someone else ends up having the same issue or want.

I had to simply make each "else if" statement it's own function. for instance:

function showinventorywindow(){

      inventorywindow.setVisible(true);
      abilitieswindow.setVisible(false);
      tradeskillswindow.setVisible(false);
      questswindow.setVisible(false);
      worldmapwindow.setVisible(false);

}

I had to do that for each window and then just called it by the function name, still curious though as to why my original method would not work.
#3
04/25/2008 (7:37 am)
My guess is your original if statements were returning false so the actual block wasn't getting executed. You could have probably done something like if( inventorywindow.IsAwake() ), which would return true if that control is awake.
#4
04/25/2008 (9:05 am)
It may reduce clutter to group gui controls inside a wrapper control: (The guicontrol base class is often used for this kind of organization.)

This allows you to move them around easily in the gui editor at the same time by moving the parent.

If you give the wrapper control a name, it will let you call that object to change the visibility of it and all its children with one step.

(It isn't clear with a quick glance if your xxxxWindow objects are other gui screens. If they are, then this isn't applicable. It is useful if you are turning on and off sets of gui controls on a single screen that are always acted on at the same time.)
#5
04/25/2008 (9:25 am)
Matt's advice is worth its weight in unleavened bread: add a container GuiControl which does nothing but contain the sub-controls you want to act on as a group.

Also, a general tip when posting on GG or any coding forum: before posting, always reduce your problem to the simplest possible example which demonstrates the problem. This has two big advantages: First, in the process of reducing it to the simplest example, you're quite likely to solve the problem yourself; Second, people reading your post are way more likely to tackle a problem which fits in eight inches of screen real-estate versus one which spans multiple pages.