Game Development Community

Drop Down GUI

by Jerald Reichstein · in Technical Issues · 05/13/2005 (9:50 am) · 3 replies

Hello everyone. I'm trying to implement the drop down GUI for our project and I'm having trouble trying to get started. I've kindof figured out how to implement an energy meter and using the GUI editor but I can't seem to find anything related to using drop down menus (specifically how to use and add items to list). So if anyone could point me to the right direction on what files or whatever I would appreciate it. Thanks

#1
05/13/2005 (10:39 am)
You could use a popUp Control (used in the file browsers, like the gui editor)

if you named it myPopUp

myPopUp.add("Option 1", 0);
myPopUp.add("Option 2", 1);
myPopUp.add("Option 3", 2);

that will populate it,
and this would be the code to make it respond when selected

function myPopUp::onSelect(%this, %id)
{
   echo("ID = " @ %id);
   if(%id != -1)
   {
      if(%id == 0)
      {
         echo("you chose option 1");
      } else if(%id == 1)
      {
         echo("you chose option 2");
      } else if(%id == 3)
      {
         echo("you chose option 3");
      }
   }
}

or you could use a GuiMenuBar (the top bar in the editors)
#2
05/13/2005 (10:41 am)
If you named it myGuiMenu you would populate it like this

myGuiMenu.clearMenus();

myGuiMenu.addMenu("File, 0);
myGuiMenu.addMenuItem("File", "Do Something", 0);
myGuiMenu.addMenuItem("File", "Quit", 1);
// File Menu Commands
myGuiMenu.scriptCommand["File", 0] = "Do Something();";
myGuiMenu.scriptCommand["File", 1] = "quit();";

this would make a File drop down, when you click it you would get two option texts "Do Something" and "Quit"...
#3
05/13/2005 (10:42 am)
Be sure to add this
//-----------------------------------------------------------------------------
// Menu Item Select Command Processing.
//-----------------------------------------------------------------------------
function myGuiMenu::onMenuItemSelect(%this, %menuId, %menu, %itemId, %item)
{
   // Script-Command Available?
   if(%this.scriptCommand[%menu, %itemId] !$= "")
      // Yes, so execute it.
      eval(%this.scriptCommand[%menu, %itemId]);
   else
      // No, so error!
      error("No script command defined for menu " @ %menu  @ " item " @ %item);
}
this will make sure scriptCommand executes (grabbed from the editors)