switch (event.GUIEvent.EventType)
{
case EGET_MENU_ITEM_SELECTED: // main menu events
{
IGUIContextMenu* menu = (IGUIContextMenu*)event.GUIEvent.Caller;
s32 id = menu->getItemCommandId(menu->getSelectedItem());
if (id == GUI_CREATEWORLD)
createWorld();
if (id == GUI_LOADWORLD)
{
openDialog = GUI->addFileOpenDialog(L"Please select a map file to load");
hexMap->loadFromFile( stringc( openDialog->getFileName()).c_str());
cout << "load world\n";
}
if (id == GUI_SAVEWORLD)
{
openDialog = GUI->addFileOpenDialog(L"Please select a map file to save");
hexMap->saveAsFile( stringc( openDialog->getFileName()).c_str());
cout << "save world\n";
}
if (id == GUI_GENERATEWORLD)
generateWorld();
if (id == GUI_TUTORIAL)
tutorial();
if (id == GUI_INFO)
info();
}
break;
}
Dialog runs a while so you can't just start and immediately get result. User has to click something first. So you start it - then react later to event to do next thing. Event is usually gui event EGET_FILE_SELECTED.
It's used in a few examples like 22.MaterialViewer or 09.Meshviewer so check those if you need some code.
Why not? If keys don't do anything you probably catch the key-events. Like returning true by default in event-handler (which means event handled so it's no longer passed on to Irrlicht).
case EGET_MENU_ITEM_SELECTED: // main menu events
{
IGUIContextMenu* menu = (IGUIContextMenu*)event.GUIEvent.Caller;
s32 id = menu->getItemCommandId(menu->getSelectedItem());
switch (id)
{
case GUI_CREATEWORLD:
if (hexMap != nullptr)
hexMap->destroy();
hexMap->createEmpty(40, 40);
std::cout << "created new Empty world" << std::endl;
break;
case GUI_LOADWORLD:
openDialog = GUI->addFileOpenDialog(L"Please select a map file to open");
openDialogState = openDialogStates::load;
break;
case GUI_SAVEWORLD:
openDialog = GUI->addFileOpenDialog(L"Please select a map file to save");
openDialogState = openDialogStates::save;
break;
case GUI_GENERATEWORLD:
generateWorld();
break;
case GUI_TUTORIAL:
tutorial();
break;
case GUI_INFO:
info();
break;
} // switch(id)
}