void GUIMenu::draw() { if(!IsVisible) { return; } video::IVideoDriver* driver = Environment->getVideoDriver(); v2u32 screensize = driver->getScreenSize(); if(screensize != m_screensize_old /*|| m_force_regenerate_gui*/) { m_screensize_old = screensize; regenerateGui(screensize); //m_force_regenerate_gui = false; } drawMenu(); }
bool GUISettingsMenu::OnEvent(const SEvent& event) { if (event.EventType == EET_KEY_INPUT_EVENT && activeKey >= 0 && event.KeyInput.PressedDown) { KeyPress kp(event.KeyInput); gui::IGUIElement *e = getElementFromId(activeKey); if (e != NULL && e->getType() == gui::EGUIET_BUTTON) { e->setEnabled(true); e->setText(kp.guiName().c_str()); keys[activeKey-GUI_ID_KEYSETTINGS_BASE] = kp; } activeKey = -1; 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_CHECKBOX_CHANGED) { acceptInput(); m_accepted = false; regenerateGui(m_screensize); } if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED) { s32 id = event.GUIEvent.Caller->getID(); if (id >= GUI_ID_KEYSETTINGS_BASE) { resetMenu(); activeKey = id; gui::IGUIElement *e = getElementFromId(id); if (e != NULL && e->getType() == gui::EGUIET_BUTTON) { e->setText(wgettext("press Key")); e->setEnabled(false); return true; } }else{ switch (event.GUIEvent.Caller->getID()) { case GUI_ID_TAB_SETTINGS_CONTROLS: acceptInput(); m_accepted = false; m_data.selected_tab = TAB_SETTINGS_CONTROLS; regenerateGui(m_screensize); return true; case GUI_ID_TAB_SETTINGS_GRAPHICS: acceptInput(); m_accepted = false; m_data.selected_tab = TAB_SETTINGS_GRAPHICS; regenerateGui(m_screensize); return true; case GUI_ID_TAB_SETTINGS_VIDEO: acceptInput(); m_accepted = false; m_data.selected_tab = TAB_SETTINGS_VIDEO; regenerateGui(m_screensize); return true; case GUI_ID_TAB_SETTINGS_SOUND: acceptInput(); m_accepted = false; m_data.selected_tab = TAB_SETTINGS_SOUND; regenerateGui(m_screensize); return true; case GUI_ID_TAB_MAINMENU: //back acceptInput(); save(); quitMenu(); return true; } } } if (event.GUIEvent.EventType == gui::EGET_SCROLL_BAR_CHANGED) { switch (event.GUIEvent.Caller->getID()) { case GUI_ID_VOLUME_SB: gui::IGUIElement *vsb = getElementFromId(GUI_ID_VOLUME_SB); if(vsb != NULL && vsb->getType() == gui::EGUIET_SCROLL_BAR) { m_data.volume = (float)((gui::IGUIScrollBar*)vsb)->getPos(); if (g_sound) g_sound->setListenerGain(m_data.volume/100.0); } return true; } } } return Parent ? Parent->OnEvent(event) : false; }
bool GUIMultiplayerMenu::OnEvent(const SEvent& event) { if (event.EventType==EET_KEY_INPUT_EVENT) { if ( event.KeyInput.PressedDown && ( event.KeyInput.Key == KEY_ESCAPE || event.KeyInput.Key == KEY_RETURN ) ) { 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_CHECKBOX_CHANGED) { acceptInput(); m_accepted = false; regenerateGui(m_screensize); } if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED) { switch (event.GUIEvent.Caller->getID()) { case GUI_ID_START_BUTTON: // Start game acceptInput(); m_accepted = false; m_gamecallback->startGame(); quitMenu(); return true; case GUI_ID_CONNECT_BUTTON: acceptInput(); m_data.selected_tab = TAB_MP_CONNECT; regenerateGui(m_screensize); return true; case GUI_ID_REMFAV_BUTTON: acceptInput(); if (m_data.selected_row > -1) { if (m_data.selected_tab == TAB_MP_LIST) { ServerInfo &info = m_data.servers.at(m_data.selected_row); if (info.is_favourite) { info.is_favourite = false; for ( std::vector<ServerInfo>::iterator i = m_data.favourites.begin(); i != m_data.favourites.end(); i++ ) { if ( i->name == info.name && i->addr == info.addr && i->mode == info.mode ) { m_data.favourites.erase(i); break; } } saveFavourites(); } }else if (m_data.selected_tab == TAB_MP_FAVOURITES) { ServerInfo &info = m_data.favourites.at(m_data.selected_row); if (info.is_favourite) { m_data.favourites.erase(m_data.favourites.begin()+m_data.selected_row); for ( std::vector<ServerInfo>::iterator i = m_data.servers.begin(); i != m_data.servers.end(); i++ ) { if ( i->name == info.name && i->addr == info.addr && i->mode == info.mode ) { i->is_favourite = false; break; } } saveFavourites(); m_data.selected_row = -1; } } } regenerateGui(m_screensize); return true; case GUI_ID_ADDFAV_BUTTON: acceptInput(); if (m_data.selected_tab == TAB_MP_LIST && m_data.selected_row > -1) { ServerInfo &info = m_data.servers.at(m_data.selected_row); if (info.name != L"" && !info.is_favourite) { info.is_favourite = true; m_data.favourites.push_back(info); saveFavourites(); } }else if (m_data.selected_tab == TAB_MP_CUSTOM) { ServerInfo info; info.name = m_data.mmdata->address+L":"+m_data.mmdata->port; info.addr = m_data.mmdata->address+L":"+m_data.mmdata->port; info.mode = L"custom"; info.is_favourite = true; m_data.servers.push_back(info); m_data.favourites.push_back(info); m_data.selected_tab = TAB_MP_FAVOURITES; m_data.selected_row = m_data.favourites.size()-1; } regenerateGui(m_screensize); return true; case GUI_ID_REFRESH_BUTTON: acceptInput(); fetchServers(); if ( ( m_data.selected_tab == TAB_MP_LIST && m_data.selected_row >= (int)m_data.servers.size() ) || ( m_data.selected_tab == TAB_MP_FAVOURITES && m_data.selected_row >= (int)m_data.favourites.size() ) ) { m_data.selected_row = -1; } regenerateGui(m_screensize); return true; case GUI_ID_TAB_MP_LIST: acceptInput(); m_accepted = false; if (m_data.selected_tab != TAB_MP_LIST) { m_data.selected_tab = TAB_MP_LIST; m_data.selected_row = -1; } regenerateGui(m_screensize); return true; case GUI_ID_TAB_MP_FAVOURITES: acceptInput(); m_accepted = false; if (m_data.selected_tab != TAB_MP_FAVOURITES) { m_data.selected_tab = TAB_MP_FAVOURITES; m_data.selected_row = -1; } regenerateGui(m_screensize); return true; case GUI_ID_TAB_MP_CUSTOM: acceptInput(); m_accepted = false; m_data.selected_tab = TAB_MP_CUSTOM; regenerateGui(m_screensize); return true; case GUI_ID_TAB_MP_MAINMENU: //back acceptInput(); 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 GUI_ID_PW_INPUT: m_gamecallback->startGame(); acceptInput(); quitMenu(); return true; } } if ( event.GUIEvent.EventType == gui::EGET_LISTBOX_CHANGED || event.GUIEvent.EventType == gui::EGET_LISTBOX_SELECTED_AGAIN ) { if (event.GUIEvent.Caller->getID() == GUI_ID_SERVER_LIST) { acceptInput(); regenerateGui(m_screensize); 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_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 GUICharDefMenu::OnEvent(const SEvent& event) { if (event.EventType==EET_KEY_INPUT_EVENT) { if (event.KeyInput.Key==KEY_ESCAPE && 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_CD_MALE_BUTTON: { m_parts["gender"] = "M"; m_parts["Yscale"] = "10"; m_parts["XZscale"] = "10"; m_y_scale = 1.0; m_xz_scale = 1.0; m_model->setMaterialTexture(0, getPlayerTexture()); m_model->setScale(v3f(m_xz_scale,m_y_scale,m_xz_scale)); printCharDef(); return true; } case GUI_ID_CD_FEMALE_BUTTON: { m_parts["gender"] = "F"; m_parts["Yscale"] = "10"; m_parts["XZscale"] = "9"; m_y_scale = 1.0; m_xz_scale = 0.9; m_model->setMaterialTexture(0, getPlayerTexture()); m_model->setScale(v3f(m_xz_scale,m_y_scale,m_xz_scale)); printCharDef(); return true; } case GUI_ID_CD_TALLER_BUTTON: { if (m_y_scale >= 1.1) return true; m_y_scale += 0.1; m_parts["Yscale"] = ftos(m_y_scale*10.); m_model->setScale(v3f(m_xz_scale,m_y_scale,m_xz_scale)); printCharDef(); return true; } case GUI_ID_CD_SHORTER_BUTTON: { if (m_y_scale <= 0.8) return true; m_y_scale -= 0.1; m_parts["Yscale"] = ftos(m_y_scale*10.); m_model->setScale(v3f(m_xz_scale,m_y_scale,m_xz_scale)); printCharDef(); return true; } case GUI_ID_CD_WIDER_BUTTON: { if (m_xz_scale >= 1.1) return true; m_xz_scale += 0.1; m_parts["XZscale"] = ftos(m_xz_scale*10.); m_model->setScale(v3f(m_xz_scale,m_y_scale,m_xz_scale)); printCharDef(); return true; } case GUI_ID_CD_THINNER_BUTTON: { if (m_xz_scale <= 0.8) return true; m_xz_scale -= 0.1; m_parts["XZscale"] = ftos(m_xz_scale*10.); m_model->setScale(v3f(m_xz_scale,m_y_scale,m_xz_scale)); printCharDef(); return true; } case GUI_ID_CD_SKINTONE_PREV_BUTTON: { std::map<std::string,std::wstring>::iterator i = m_skintone_types.find(m_parts["skintone"]); if (i == m_skintone_types.begin()) i = m_skintone_types.end(); --i; m_parts["skintone"] = i->first; m_model->setMaterialTexture(0, getPlayerTexture()); regenerateGui(m_screensize); printCharDef(); return true; } case GUI_ID_CD_SKINTONE_NEXT_BUTTON: { std::map<std::string,std::wstring>::iterator i = m_skintone_types.find(m_parts["skintone"]); ++i; if (i == m_skintone_types.end()) i = m_skintone_types.begin(); m_parts["skintone"] = i->first; m_model->setMaterialTexture(0, getPlayerTexture()); regenerateGui(m_screensize); printCharDef(); return true; } case GUI_ID_CD_FACE_PREV_BUTTON: { std::map<std::string,std::wstring>::iterator i = m_face_types.find(m_parts["face"]); if (i == m_face_types.begin()) i = m_face_types.end(); --i; m_parts["face"] = i->first; m_model->setMaterialTexture(0, getPlayerTexture()); regenerateGui(m_screensize); printCharDef(); return true; } case GUI_ID_CD_FACE_NEXT_BUTTON: { std::map<std::string,std::wstring>::iterator i = m_face_types.find(m_parts["face"]); ++i; if (i == m_face_types.end()) i = m_face_types.begin(); m_parts["face"] = i->first; m_model->setMaterialTexture(0, getPlayerTexture()); regenerateGui(m_screensize); printCharDef(); return true; } case GUI_ID_CD_HAIRTONE_PREV_BUTTON: { std::map<std::string,std::wstring>::iterator i = m_hairtone_types.find(m_parts["hairtone"]); if (i == m_hairtone_types.begin()) i = m_hairtone_types.end(); --i; m_parts["hairtone"] = i->first; m_model->setMaterialTexture(0, getPlayerTexture()); regenerateGui(m_screensize); printCharDef(); return true; } case GUI_ID_CD_HAIRTONE_NEXT_BUTTON: { std::map<std::string,std::wstring>::iterator i = m_hairtone_types.find(m_parts["hairtone"]); ++i; if (i == m_hairtone_types.end()) i = m_hairtone_types.begin(); m_parts["hairtone"] = i->first; m_model->setMaterialTexture(0, getPlayerTexture()); regenerateGui(m_screensize); printCharDef(); return true; } case GUI_ID_CD_HAIR_PREV_BUTTON: { std::map<std::string,std::wstring>::iterator i = m_hair_types.find(m_parts["hair"]); if (i == m_hair_types.begin()) i = m_hair_types.end(); --i; m_parts["hair"] = i->first; m_model->setMaterialTexture(0, getPlayerTexture()); regenerateGui(m_screensize); printCharDef(); return true; } case GUI_ID_CD_HAIR_NEXT_BUTTON: { std::map<std::string,std::wstring>::iterator i = m_hair_types.find(m_parts["hair"]); ++i; if (i == m_hair_types.end()) i = m_hair_types.begin(); m_parts["hair"] = i->first; m_model->setMaterialTexture(0, getPlayerTexture()); regenerateGui(m_screensize); printCharDef(); return true; } case GUI_ID_CD_EYES_PREV_BUTTON: { std::map<std::string,std::wstring>::iterator i = m_eyes_types.find(m_parts["eyes"]); if (i == m_eyes_types.begin()) i = m_eyes_types.end(); --i; m_parts["eyes"] = i->first; m_model->setMaterialTexture(0, getPlayerTexture()); regenerateGui(m_screensize); printCharDef(); return true; } case GUI_ID_CD_EYES_NEXT_BUTTON: { std::map<std::string,std::wstring>::iterator i = m_eyes_types.find(m_parts["eyes"]); ++i; if (i == m_eyes_types.end()) i = m_eyes_types.begin(); m_parts["eyes"] = i->first; m_model->setMaterialTexture(0, getPlayerTexture()); regenerateGui(m_screensize); printCharDef(); return true; } case GUI_ID_CD_SHIRT_PREV_BUTTON: { std::map<std::string,std::wstring>::iterator i = m_shirt_types.find(m_parts["shirt"]); if (i == m_shirt_types.begin()) i = m_shirt_types.end(); --i; m_parts["shirt"] = i->first; m_model->setMaterialTexture(0, getPlayerTexture()); regenerateGui(m_screensize); printCharDef(); return true; } case GUI_ID_CD_SHIRT_NEXT_BUTTON: { std::map<std::string,std::wstring>::iterator i = m_shirt_types.find(m_parts["shirt"]); ++i; if (i == m_shirt_types.end()) i = m_shirt_types.begin(); m_parts["shirt"] = i->first; m_model->setMaterialTexture(0, getPlayerTexture()); regenerateGui(m_screensize); printCharDef(); return true; } case GUI_ID_CD_PANTS_PREV_BUTTON: { std::map<std::string,std::wstring>::iterator i = m_pants_types.find(m_parts["pants"]); if (i == m_pants_types.begin()) i = m_pants_types.end(); --i; m_parts["pants"] = i->first; m_model->setMaterialTexture(0, getPlayerTexture()); regenerateGui(m_screensize); printCharDef(); return true; } case GUI_ID_CD_PANTS_NEXT_BUTTON: { std::map<std::string,std::wstring>::iterator i = m_pants_types.find(m_parts["pants"]); ++i; if (i == m_pants_types.end()) i = m_pants_types.begin(); m_parts["pants"] = i->first; m_model->setMaterialTexture(0, getPlayerTexture()); regenerateGui(m_screensize); printCharDef(); return true; } case GUI_ID_CD_SHOES_PREV_BUTTON: { std::map<std::string,std::wstring>::iterator i = m_shoes_types.find(m_parts["shoes"]); if (i == m_shoes_types.begin()) i = m_shoes_types.end(); --i; m_parts["shoes"] = i->first; m_model->setMaterialTexture(0, getPlayerTexture()); regenerateGui(m_screensize); printCharDef(); return true; } case GUI_ID_CD_SHOES_NEXT_BUTTON: { std::map<std::string,std::wstring>::iterator i = m_shoes_types.find(m_parts["shoes"]); ++i; if (i == m_shoes_types.end()) i = m_shoes_types.begin(); m_parts["shoes"] = i->first; m_model->setMaterialTexture(0, getPlayerTexture()); regenerateGui(m_screensize); printCharDef(); return true; } case GUI_ID_CD_SAVE_BUTTON: { savePlayerSkin(); acceptInput(); quitMenu(); return true; } case GUI_ID_CD_QUIT_BUTTON: { acceptInput(); quitMenu(); return true; } } } } return Parent ? Parent->OnEvent(event) : false; }
void GUIFormSpecMenu::drawMenu() { if(m_form_src){ std::string newform = m_form_src->getForm(); if(newform != m_formspec_string){ m_formspec_string = newform; regenerateGui(m_screensize_old); } } updateSelectedItem(); gui::IGUISkin* skin = Environment->getSkin(); if (!skin) return; video::IVideoDriver* driver = Environment->getVideoDriver(); video::SColor bgcolor(140,0,0,0); driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect); m_tooltip_element->setVisible(false); /* Draw items Phase 0: Item slot rectangles Phase 1: Item images; prepare tooltip */ for(int phase=0; phase<=1; phase++) for(u32 i=0; i<m_inventorylists.size(); i++) { drawList(m_inventorylists[i], phase); } for(u32 i=0; i<m_images.size(); i++) { const ImageDrawSpec &spec = m_images[i]; video::ITexture *texture = m_gamedef->tsrc()->getTextureRaw(spec.name); // Image size on screen core::rect<s32> imgrect(0, 0, spec.geom.X, spec.geom.Y); // Image rectangle on screen core::rect<s32> rect = imgrect + spec.pos; const video::SColor color(255,255,255,255); const video::SColor colors[] = {color,color,color,color}; driver->draw2DImage(texture, rect, core::rect<s32>(core::position2d<s32>(0,0), core::dimension2di(texture->getOriginalSize())), NULL/*&AbsoluteClippingRect*/, colors, true); } /* Draw dragged item stack */ drawSelectedItem(); /* Call base class */ gui::IGUIElement::draw(); }
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; }