diff options
Diffstat (limited to 'src/guiMainMenu.cpp')
-rw-r--r-- | src/guiMainMenu.cpp | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/src/guiMainMenu.cpp b/src/guiMainMenu.cpp index 6d07fe973..a0d8e93ec 100644 --- a/src/guiMainMenu.cpp +++ b/src/guiMainMenu.cpp @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "guiKeyChangeMenu.h" #include "guiCreateWorld.h" #include "guiMessageMenu.h" +#include "guiConfirmMenu.h" #include "debug.h" #include "serialization.h" #include <string> @@ -47,6 +48,22 @@ struct CreateWorldDestMainMenu : public CreateWorldDest GUIMainMenu *m_menu; }; +struct ConfirmDestDeleteWorld : public ConfirmDest +{ + ConfirmDestDeleteWorld(WorldSpec spec, GUIMainMenu *menu): + m_spec(spec), + m_menu(menu) + {} + void answer(bool answer) + { + if(answer == false) + return; + m_menu->deleteWorld(m_spec); + } + WorldSpec m_spec; + GUIMainMenu *m_menu; +}; + enum { GUI_ID_QUIT_BUTTON = 101, @@ -312,9 +329,9 @@ void GUIMainMenu::regenerateGui(v2u32 screensize) gui::IGUIListBox *e = Environment->addListBox(rect, this, GUI_ID_WORLD_LISTBOX); e->setDrawBackground(true); - for(std::list<std::wstring>::const_iterator i = m_data->worlds.begin(); + for(std::vector<WorldSpec>::const_iterator i = m_data->worlds.begin(); i != m_data->worlds.end(); i++){ - e->addItem(i->c_str()); + e->addItem(narrow_to_wide(i->name+" ["+i->gameid+"]").c_str()); } e->setSelected(m_data->selected_world); } @@ -458,9 +475,21 @@ bool GUIMainMenu::OnEvent(const SEvent& event) return true; } case GUI_ID_DELETE_WORLD_BUTTON: { - acceptInput(); - m_data->delete_world = true; - quitMenu(); + 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: { @@ -516,3 +545,12 @@ void GUIMainMenu::createNewWorld(std::wstring name, std::string gameid) quitMenu(); } +void GUIMainMenu::deleteWorld(WorldSpec spec) +{ + if(!spec.isValid()) + return; + acceptInput(); + m_data->delete_world_spec = spec; + quitMenu(); +} + |