int ModApiMainMenu::l_show_keys_menu(lua_State *L) { GUIEngine* engine = getGuiEngine(L); assert(engine != 0); GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu( engine->m_device->getGUIEnvironment(), engine->m_parent, -1, engine->m_menumanager); kmenu->drop(); return 0; }
bool GUIMainMenu::OnEvent(const SEvent& event) { if(event.EventType==EET_KEY_INPUT_EVENT) { if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown) { m_gamecallback->exitToOS(); quitMenu(); return true; } if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown) { acceptInput(); quitMenu(); return true; } } if(event.EventType==EET_GUI_EVENT) { if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST && isVisible()) { if(!canTakeFocus(event.GUIEvent.Element)) { dstream<<"GUIMainMenu: Not allowing focus change." <<std::endl; // Returning true disables focus change return true; } } if(event.GUIEvent.EventType==gui::EGET_TAB_CHANGED) { if(!m_is_regenerating) regenerateGui(m_screensize_old); return true; } if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED) { switch(event.GUIEvent.Caller->getID()) { case GUI_ID_JOIN_GAME_BUTTON: { MainMenuData cur; readInput(&cur); if(cur.address == L"" && getTab() == TAB_MULTIPLAYER){ (new GUIMessageMenu(env, parent, -1, menumgr, wgettext("Address required.")) )->drop(); return true; } acceptInput(); quitMenu(); return true; } case GUI_ID_CHANGE_KEYS_BUTTON: { GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(env, parent, -1,menumgr); kmenu->drop(); return true; } case GUI_ID_DELETE_WORLD_BUTTON: { MainMenuData cur; readInput(&cur); if(cur.selected_world == -1){ (new GUIMessageMenu(env, parent, -1, menumgr, wgettext("Cannot delete world: Nothing selected")) )->drop(); } else { WorldSpec spec = m_data->worlds[cur.selected_world]; ConfirmDestDeleteWorld *dest = new ConfirmDestDeleteWorld(spec, this); (new GUIConfirmMenu(env, parent, -1, menumgr, dest, (std::wstring(wgettext("Delete world ")) +L"\""+narrow_to_wide(spec.name)+L"\"?").c_str() ))->drop(); } return true; } case GUI_ID_CREATE_WORLD_BUTTON: { std::vector<SubgameSpec> games = getAvailableGames(); if(games.size() == 0){ GUIMessageMenu *menu = new GUIMessageMenu(env, parent, -1, menumgr, wgettext("Cannot create world: No games found")); menu->drop(); } else { CreateWorldDest *dest = new CreateWorldDestMainMenu(this); GUICreateWorld *menu = new GUICreateWorld(env, parent, -1, menumgr, dest, games); menu->drop(); } return true; } case GUI_ID_CONFIGURE_WORLD_BUTTON: { GUIMessageMenu *menu = new GUIMessageMenu(env, parent, -1, menumgr, wgettext("Nothing here")); menu->drop(); return true; } } } if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER) { switch(event.GUIEvent.Caller->getID()) { case GUI_ID_ADDRESS_INPUT: case GUI_ID_PORT_INPUT: case GUI_ID_NAME_INPUT: case 264: acceptInput(); quitMenu(); return true; } } if(event.GUIEvent.EventType==gui::EGET_LISTBOX_SELECTED_AGAIN) { switch(event.GUIEvent.Caller->getID()) { case GUI_ID_WORLD_LISTBOX: acceptInput(); if(getTab() != TAB_SINGLEPLAYER) m_data->address = L""; // Force local game quitMenu(); return true; } } } return Parent ? Parent->OnEvent(event) : false; }
bool GUIMainMenu::OnEvent(const SEvent& event) { if(event.EventType==EET_KEY_INPUT_EVENT) { if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown) { m_gamecallback->exitToOS(); quitMenu(); return true; } if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown) { acceptInput(); quitMenu(); return true; } } if(event.EventType==EET_GUI_EVENT) { if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST && isVisible()) { if(!canTakeFocus(event.GUIEvent.Element)) { dstream<<"GUIMainMenu: Not allowing focus change." <<std::endl; // Returning true disables focus change return true; } } if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED) { switch(event.GUIEvent.Caller->getID()) { case GUI_ID_JOIN_GAME_BUTTON: // Start game acceptInput(); quitMenu(); return true; case GUI_ID_CHANGE_KEYS_BUTTON: { GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(env, parent, -1,menumgr); kmenu->drop(); return true; } case GUI_ID_DELETE_MAP_BUTTON: // Delete map // Don't accept input data, just set deletion request m_data->delete_map = true; m_accepted = true; quitMenu(); return true; } } if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER) { switch(event.GUIEvent.Caller->getID()) { case GUI_ID_ADDRESS_INPUT: case GUI_ID_PORT_INPUT: case GUI_ID_NAME_INPUT: case 264: acceptInput(); quitMenu(); return true; } } } return Parent ? Parent->OnEvent(event) : false; }
bool GUIMainMenu::OnEvent(const SEvent& event) { if(event.EventType==EET_KEY_INPUT_EVENT) { if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown) { m_gamecallback->exitToOS(); quitMenu(); return true; } if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown) { acceptInput(); quitMenu(); return true; } } if(event.EventType==EET_GUI_EVENT) { if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST && isVisible()) { if(!canTakeFocus(event.GUIEvent.Element)) { dstream<<"GUIMainMenu: Not allowing focus change." <<std::endl; // Returning true disables focus change return true; } } if(event.GUIEvent.EventType==gui::EGET_TAB_CHANGED) { if(!m_is_regenerating) regenerateGui(m_screensize_old); return true; } if(event.GUIEvent.EventType==gui::EGET_LISTBOX_CHANGED && event.GUIEvent.Caller->getID() == GUI_ID_SERVERLIST) { serverListOnSelected(); return true; } if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED) { switch(event.GUIEvent.Caller->getID()) { case GUI_ID_JOIN_GAME_BUTTON: { MainMenuData cur; readInput(&cur); if (getTab() == TAB_MULTIPLAYER && cur.address == L"") { wchar_t* text = wgettext("Address required."); (new GUIMessageMenu(env, parent, -1, menumgr, text) )->drop(); delete[] text; return true; } acceptInput(); quitMenu(); return true; } case GUI_ID_CHANGE_KEYS_BUTTON: { GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(env, parent, -1,menumgr); kmenu->drop(); return true; } case GUI_ID_DELETE_WORLD_BUTTON: { MainMenuData cur; readInput(&cur); if(cur.selected_world == -1){ wchar_t* text = wgettext("Cannot delete world: Nothing selected"); (new GUIMessageMenu(env, parent, -1, menumgr, text) )->drop(); delete[] text; } else { WorldSpec spec = m_data->worlds[cur.selected_world]; // Get files and directories involved std::vector<std::string> paths; paths.push_back(spec.path); fs::GetRecursiveSubPaths(spec.path, paths); // Launch confirmation dialog ConfirmDestDeleteWorld *dest = new ConfirmDestDeleteWorld(spec, this, paths); wchar_t* text1 = wgettext("Delete world"); wchar_t* text2 = wgettext("Files to be deleted"); std::wstring text = text1; text += L" \""; text += narrow_to_wide(spec.name); text += L"\"?\n\n"; text += text2; text += L":\n"; delete[] text1; delete[] text2; for(u32 i=0; i<paths.size(); i++){ if(i == 3){ text += L"..."; break; } text += narrow_to_wide(paths[i]) + L"\n"; } (new GUIConfirmMenu(env, parent, -1, menumgr, dest, text.c_str()))->drop(); } return true; } case GUI_ID_CREATE_WORLD_BUTTON: { const std::vector<SubgameSpec> &games = m_data->games; if(games.size() == 0){ wchar_t* text = wgettext("Cannot create world: No games found"); GUIMessageMenu *menu = new GUIMessageMenu(env, parent, -1, menumgr, text); menu->drop(); delete[] text; } else { CreateWorldDest *dest = new CreateWorldDestMainMenu(this); GUICreateWorld *menu = new GUICreateWorld(env, parent, -1, menumgr, dest, games, m_data->selected_game); menu->drop(); } return true; } case GUI_ID_CONFIGURE_WORLD_BUTTON: { MainMenuData cur; readInput(&cur); if(cur.selected_world == -1) { wchar_t* text = wgettext("Cannot configure world: Nothing selected"); (new GUIMessageMenu(env, parent, -1, menumgr, text) )->drop(); delete[] text; } else { WorldSpec wspec = m_data->worlds[cur.selected_world]; GUIConfigureWorld *menu = new GUIConfigureWorld(env, parent, -1, menumgr, wspec); menu->drop(); } return true; } case GUI_ID_SERVERLIST_DELETE: { gui::IGUIListBox *serverlist = (gui::IGUIListBox*)getElementFromId(GUI_ID_SERVERLIST); s32 selected = ((gui::IGUIListBox*)serverlist)->getSelected(); if (selected == -1) return true; ServerList::deleteEntry(m_data->servers[selected]); m_data->servers = ServerList::getLocal(); updateGuiServerList(); if (selected > 0) selected -= 1; serverlist->setSelected(selected); serverListOnSelected(); return true; } #if USE_CURL case GUI_ID_SERVERLIST_TOGGLE: { gui::IGUIElement *togglebutton = getElementFromId(GUI_ID_SERVERLIST_TOGGLE); gui::IGUIElement *deletebutton = getElementFromId(GUI_ID_SERVERLIST_DELETE); gui::IGUIListBox *serverlist = (gui::IGUIListBox*)getElementFromId(GUI_ID_SERVERLIST); gui::IGUIElement *title = getElementFromId(GUI_ID_SERVERLIST_TITLE); if (m_data->selected_serverlist == SERVERLIST_PUBLIC) // switch to favorite list { m_data->servers = ServerList::getLocal(); wchar_t* text1 = wgettext("Show Public"); wchar_t* text2 = wgettext("Favorites:"); togglebutton->setText(text1); title->setText(text2); delete[] text1; delete[] text2; deletebutton->setVisible(true); updateGuiServerList(); serverlist->setSelected(0); m_data->selected_serverlist = SERVERLIST_FAVORITES; } else // switch to online list { m_data->servers = ServerList::getOnline(); wchar_t* text1 = wgettext("Show Favorites"); wchar_t* text2 = wgettext("Public Server List:"); togglebutton->setText(text1); title->setText(text2); delete[] text1; delete[] text2; deletebutton->setVisible(false); updateGuiServerList(); serverlist->setSelected(0); m_data->selected_serverlist = SERVERLIST_PUBLIC; } serverListOnSelected(); } #endif } /* Game buttons */ int eid = event.GUIEvent.Caller->getID(); if(eid >= GUI_ID_GAME_BUTTON_FIRST && eid <= GUI_ID_GAME_BUTTON_MAX){ m_data->selected_game = m_data->games[eid - GUI_ID_GAME_BUTTON_FIRST].id; m_data->selected_game_name = m_data->games[eid - GUI_ID_GAME_BUTTON_FIRST].name; regenerateGui(m_screensize_old); } } if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER) { switch(event.GUIEvent.Caller->getID()) { case GUI_ID_ADDRESS_INPUT: case GUI_ID_PORT_INPUT: case GUI_ID_NAME_INPUT: case 264: MainMenuData cur; readInput(&cur); if (getTab() == TAB_MULTIPLAYER && cur.address == L"") { wchar_t* text = wgettext("Address required."); (new GUIMessageMenu(env, parent, -1, menumgr, text) )->drop(); delete[] text; return true; } acceptInput(); quitMenu(); return true; } } if(event.GUIEvent.EventType==gui::EGET_LISTBOX_CHANGED) { readInput(m_data); } if(event.GUIEvent.EventType==gui::EGET_LISTBOX_SELECTED_AGAIN) { switch(event.GUIEvent.Caller->getID()) { case GUI_ID_WORLD_LISTBOX: acceptInput(); if(getTab() != TAB_SINGLEPLAYER) m_data->address = L""; // Force local game quitMenu(); return true; case GUI_ID_SERVERLIST: gui::IGUIListBox *serverlist = (gui::IGUIListBox*)getElementFromId(GUI_ID_SERVERLIST); if (serverlist->getSelected() > -1) { acceptInput(); quitMenu(); return true; } } } } return Parent ? Parent->OnEvent(event) : false; }