Menu ID problem [solved]

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Catprog
Posts: 164
Joined: Wed Jan 31, 2007 9:07 am
Contact:

Menu ID problem [solved]

Post by Catprog »

I can't seem to get the id of a menu

it prints MENU SELECTED but the ID is always -1.

event recevier

Code: Select all

              if (event.EventType ==  EET_GUI_EVENT)
        {
 
 
            s32 id = event.GUIEvent.Caller->getID();
 
            switch(event.GUIEvent.EventType)
            {
 
 
            case EGET_MENU_ITEM_SELECTED:
 
                printf("MENU SELECTED\n");
 
 
                menuID = id;
 
                break;
 
 
            }
        }
Enums for menu ids

Code: Select all

 
 
 
enum menuIDs
{
    NEW_MAP_ID=1001,
    OPEN_MAP_ID,
    SAVE_MAP_ID,
    SAVEAS_MAP_ID,
 
    QUIT_ID,
 
    TILE_ID,
    TILE_D_ID,
 
    BGS_ID,
    BGD_ID,
 
    SPEECH_ID,
 
    HIDEC_ID,
    HIDE_ID
 
 
 
 
};
menu creation

Code: Select all

    gui::IGUIContextMenu * MenuBar = guienv->addMenu();
    MenuBar->addItem(L"File", -1, true, true);
    MenuBar->addItem(L"Tiles", -1, true, true);
    MenuBar->addItem(L"Sound", -1, true, true);
    MenuBar->addItem(L"Speech", -1, true, true);
    MenuBar->addItem(L"Hide", -1, true, true);
 
    gui::IGUIContextMenu* subMenuFile = MenuBar->getSubMenu(0);
    subMenuFile->addItem(L"New Map",NEW_MAP_ID);
    subMenuFile->addSeparator();
    subMenuFile->addItem(L"Open Map",OPEN_MAP_ID);
    subMenuFile->addSeparator();
    subMenuFile->addItem(L"Save Map",SAVE_MAP_ID);
    subMenuFile->addItem(L"Save Map as",SAVEAS_MAP_ID);
    subMenuFile->addSeparator();
    subMenuFile->addItem(L"Quit",QUIT_ID);
 
 
    gui::IGUIContextMenu* subMenuTiles = MenuBar->getSubMenu(1);
    subMenuTiles->addItem(L"Tile List",TILE_ID);
    subMenuTiles->addItem(L"Tile Dialog",TILE_D_ID);
 
 
    gui::IGUIContextMenu* subMenuSound = MenuBar->getSubMenu(2);
    subMenuSound->addItem(L"Background Sound List",BGS_ID);
    subMenuSound->addItem(L"Background Sound Dialog",BGD_ID);
 
    gui::IGUIContextMenu* subMenuSpeech = MenuBar->getSubMenu(3);
    subMenuSpeech->addItem(L"Speech Dialog",SPEECH_ID);
 
    gui::IGUIContextMenu* subMenuHide = MenuBar->getSubMenu(4);
 
    subMenuHide->addItem(L"Hide Conditions Dialog",HIDEC_ID);
    subMenuHide->addItem(L"Hide  Dialog",HIDE_ID);
 
 
Last edited by Catprog on Fri Oct 12, 2012 9:07 am, edited 1 time in total.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Menu ID problem

Post by CuteAlien »

The problem is that there is only one id for the whole menu (id's are per gui-element), to get the commands of a menu you have to do something like:

Code: Select all

 
IGUIContextMenu* menu = (IGUIContextMenu*)event.GUIEvent.Caller);
s32 id = menu->getItemCommandId(menu->getSelectedItem());
 
Certainly check if you have menu before doing the cast (for example only cast after you know you have EGET_MENU_ITEM_SELECTED).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Catprog
Posts: 164
Joined: Wed Jan 31, 2007 9:07 am
Contact:

Re: Menu ID problem

Post by Catprog »

Thanks. That was it.
Post Reply