From 084be3599a5ef0acba7c341bfd14a4e9801423a2 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Fri, 15 Feb 2013 21:13:53 +0200 Subject: Get menu background image from selected game --- src/guiMainMenu.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/guiMainMenu.h') diff --git a/src/guiMainMenu.h b/src/guiMainMenu.h index a594ccd41..b0c9ff24b 100644 --- a/src/guiMainMenu.h +++ b/src/guiMainMenu.h @@ -39,6 +39,7 @@ struct MainMenuData // These are in the native format of the gui elements // Generic int selected_tab; + std::string selected_game; // Client options std::string servername; std::string serverdescription; @@ -78,6 +79,7 @@ struct MainMenuData MainMenuData(): // Generic selected_tab(0), + selected_game("minetest"), // Client opts fancy_trees(false), smooth_lighting(false), -- cgit v1.2.3 From 2708482f1bdb163d61193ebb976e9edc66449356 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Fri, 15 Feb 2013 22:06:38 +0200 Subject: Filter worlds by selected game --- src/guiMainMenu.cpp | 23 +++++++++++++++++------ src/guiMainMenu.h | 2 ++ 2 files changed, 19 insertions(+), 6 deletions(-) (limited to 'src/guiMainMenu.h') diff --git a/src/guiMainMenu.cpp b/src/guiMainMenu.cpp index 07efbb62f..2e7fb955d 100644 --- a/src/guiMainMenu.cpp +++ b/src/guiMainMenu.cpp @@ -348,11 +348,17 @@ void GUIMainMenu::regenerateGui(v2u32 screensize) gui::IGUIListBox *e = Environment->addListBox(rect, this, GUI_ID_WORLD_LISTBOX); e->setDrawBackground(true); - for(std::vector::const_iterator i = m_data->worlds.begin(); - i != m_data->worlds.end(); i++){ - e->addItem(narrow_to_wide(i->name+" ["+i->gameid+"]").c_str()); + m_world_indices.clear(); + for(size_t wi = 0; wi < m_data->worlds.size(); wi++){ + const WorldSpec &spec = m_data->worlds[wi]; + if(spec.gameid == m_data->selected_game){ + //e->addItem(narrow_to_wide(spec.name+" ["+spec.gameid+"]").c_str()); + e->addItem(narrow_to_wide(spec.name).c_str()); + m_world_indices.push_back(wi); + if(m_data->selected_world == (int)wi) + e->setSelected(m_world_indices.size()-1); + } } - e->setSelected(m_data->selected_world); Environment->setFocus(e); } // Delete world button @@ -1131,8 +1137,13 @@ void GUIMainMenu::readInput(MainMenuData *dst) { gui::IGUIElement *e = getElementFromId(GUI_ID_WORLD_LISTBOX); - if(e != NULL && e->getType() == gui::EGUIET_LIST_BOX) - dst->selected_world = ((gui::IGUIListBox*)e)->getSelected(); + if(e != NULL && e->getType() == gui::EGUIET_LIST_BOX){ + int list_i = ((gui::IGUIListBox*)e)->getSelected(); + if(list_i == -1) + dst->selected_world = -1; + else + dst->selected_world = m_world_indices[list_i]; + } } { ServerListSpec server = diff --git a/src/guiMainMenu.h b/src/guiMainMenu.h index b0c9ff24b..1c5ca4d37 100644 --- a/src/guiMainMenu.h +++ b/src/guiMainMenu.h @@ -130,6 +130,8 @@ private: s32 id; IMenuManager *menumgr; + std::vector m_world_indices; + bool m_is_regenerating; v2s32 m_topleft_client; v2s32 m_size_client; -- cgit v1.2.3 From b75505e6b2b82d48980ff71649dd4944b04b6f78 Mon Sep 17 00:00:00 2001 From: PilzAdam Date: Thu, 2 May 2013 19:57:03 +0200 Subject: Show game name instead of game ID of selected game --- src/guiMainMenu.cpp | 6 ++++-- src/guiMainMenu.h | 2 ++ src/main.cpp | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'src/guiMainMenu.h') diff --git a/src/guiMainMenu.cpp b/src/guiMainMenu.cpp index c6142d4ce..5d5ae1e90 100644 --- a/src/guiMainMenu.cpp +++ b/src/guiMainMenu.cpp @@ -258,9 +258,9 @@ void GUIMainMenu::regenerateGui(v2u32 screensize) core::rect rect(0, 0, size.X, 40); rect += v2s32(4, 0); std::string t = "Minetest " VERSION_STRING; - if(m_data->selected_game != ""){ + if(m_data->selected_game_name != ""){ t += "/"; - t += m_data->selected_game; + t += m_data->selected_game_name; } Environment->addStaticText(narrow_to_wide(t).c_str(), rect, false, true, this, -1); @@ -1356,6 +1356,8 @@ bool GUIMainMenu::OnEvent(const SEvent& event) 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); } } diff --git a/src/guiMainMenu.h b/src/guiMainMenu.h index 1c5ca4d37..1d09c8baa 100644 --- a/src/guiMainMenu.h +++ b/src/guiMainMenu.h @@ -40,6 +40,7 @@ struct MainMenuData // Generic int selected_tab; std::string selected_game; + std::string selected_game_name; // Client options std::string servername; std::string serverdescription; @@ -80,6 +81,7 @@ struct MainMenuData // Generic selected_tab(0), selected_game("minetest"), + selected_game_name("Minetest"), // Client opts fancy_trees(false), smooth_lighting(false), diff --git a/src/main.cpp b/src/main.cpp index 9a646413d..501e4cdf4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1501,8 +1501,10 @@ int main(int argc, char *argv[]) menudata.selected_tab = g_settings->getS32("selected_mainmenu_tab"); if(g_settings->exists("selected_serverlist")) menudata.selected_serverlist = g_settings->getS32("selected_serverlist"); - if(g_settings->exists("selected_mainmenu_game")) + if(g_settings->exists("selected_mainmenu_game")){ menudata.selected_game = g_settings->get("selected_mainmenu_game"); + menudata.selected_game_name = findSubgame(menudata.selected_game).name; + } menudata.address = narrow_to_wide(address); menudata.name = narrow_to_wide(playername); menudata.port = narrow_to_wide(itos(port)); -- cgit v1.2.3 From efc9329033ece46f04c5aaee3e34c49eb482eaa3 Mon Sep 17 00:00:00 2001 From: PilzAdam Date: Sat, 11 May 2013 16:08:01 +0200 Subject: Only use game filter in singleplayer tab; use menu_{background, overlay, header, footer}.png for other tabs --- src/guiMainMenu.cpp | 53 +++++++++++++++++++------------------------- src/guiMainMenu.h | 9 ++++++++ src/main.cpp | 63 ++++++++++++++++++++++++++++++++++++----------------- 3 files changed, 74 insertions(+), 51 deletions(-) (limited to 'src/guiMainMenu.h') diff --git a/src/guiMainMenu.cpp b/src/guiMainMenu.cpp index 9966b9fa7..36685db84 100644 --- a/src/guiMainMenu.cpp +++ b/src/guiMainMenu.cpp @@ -166,15 +166,6 @@ enum GUI_ID_GAME_BUTTON_MAX = 150, }; -enum -{ - TAB_SINGLEPLAYER=0, - TAB_MULTIPLAYER, - TAB_ADVANCED, - TAB_SETTINGS, - TAB_CREDITS -}; - GUIMainMenu::GUIMainMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id, IMenuManager *menumgr, @@ -258,7 +249,8 @@ void GUIMainMenu::regenerateGui(v2u32 screensize) core::rect rect(0, 0, size.X, 40); rect += v2s32(4, 0); std::string t = "Minetest " VERSION_STRING; - if(m_data->selected_game_name != ""){ + if(m_data->selected_game_name != "" && + m_data->selected_tab == TAB_SINGLEPLAYER){ t += "/"; t += m_data->selected_game_name; } @@ -428,6 +420,26 @@ void GUIMainMenu::regenerateGui(v2u32 screensize) delete[] text; } changeCtype("C"); + + /* Add game selection buttons */ + video::IVideoDriver* driver = Environment->getVideoDriver(); + for(size_t i=0; igames.size(); i++){ + const SubgameSpec *spec = &m_data->games[i]; + v2s32 p(8 + i*(48+8), screensize.Y - (48+8)); + core::rect rect(0, 0, 48, 48); + rect += p; + video::ITexture *bgtexture = NULL; + if(spec->menuicon_path != "") + bgtexture = driver->getTexture(spec->menuicon_path.c_str()); + gui::IGUIButton *b = Environment->addButton(rect, this, + GUI_ID_GAME_BUTTON_FIRST+i, narrow_to_wide(wrap_rows(spec->id, 4)).c_str()); + if(bgtexture){ + b->setImage(bgtexture); + b->setText(L""); + b->setDrawBorder(false); + b->setUseAlphaChannel(true); + } + } } else if(m_data->selected_tab == TAB_MULTIPLAYER) { @@ -920,27 +932,6 @@ void GUIMainMenu::regenerateGui(v2u32 screensize) } } - /* Add game selection buttons */ - - video::IVideoDriver* driver = Environment->getVideoDriver(); - for(size_t i=0; igames.size(); i++){ - const SubgameSpec *spec = &m_data->games[i]; - v2s32 p(8 + i*(48+8), screensize.Y - (48+8)); - core::rect rect(0, 0, 48, 48); - rect += p; - video::ITexture *bgtexture = NULL; - if(spec->menuicon_path != "") - bgtexture = driver->getTexture(spec->menuicon_path.c_str()); - gui::IGUIButton *b = Environment->addButton(rect, this, - GUI_ID_GAME_BUTTON_FIRST+i, narrow_to_wide(wrap_rows(spec->id, 4)).c_str()); - if(bgtexture){ - b->setImage(bgtexture); - b->setText(L""); - b->setDrawBorder(false); - b->setUseAlphaChannel(true); - } - } - m_is_regenerating = false; } diff --git a/src/guiMainMenu.h b/src/guiMainMenu.h index 1d09c8baa..8697344c8 100644 --- a/src/guiMainMenu.h +++ b/src/guiMainMenu.h @@ -34,6 +34,15 @@ enum { SERVERLIST_PUBLIC, }; +enum +{ + TAB_SINGLEPLAYER=0, + TAB_MULTIPLAYER, + TAB_ADVANCED, + TAB_SETTINGS, + TAB_CREDITS +}; + struct MainMenuData { // These are in the native format of the gui elements diff --git a/src/main.cpp b/src/main.cpp index 56cb310ca..7f9ec1ace 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -663,12 +663,14 @@ private: struct MenuTextures { std::string current_gameid; + bool global_textures; video::ITexture *background; video::ITexture *overlay; video::ITexture *header; video::ITexture *footer; MenuTextures(): + global_textures(false), background(NULL), overlay(NULL), header(NULL), @@ -678,28 +680,49 @@ struct MenuTextures static video::ITexture* getMenuTexture(const std::string &tname, video::IVideoDriver* driver, const SubgameSpec *spec) { - std::string path; - // eg. minetest_menu_background.png (for texture packs) - std::string pack_tname = spec->id + "_menu_" + tname + ".png"; - path = getTexturePath(pack_tname); - if(path != "") - return driver->getTexture(path.c_str()); - // eg. games/minetest_game/menu/background.png - path = getImagePath(spec->path + DIR_DELIM + "menu" + DIR_DELIM + tname + ".png"); - if(path != "") - return driver->getTexture(path.c_str()); + if(spec){ + std::string path; + // eg. minetest_menu_background.png (for texture packs) + std::string pack_tname = spec->id + "_menu_" + tname + ".png"; + path = getTexturePath(pack_tname); + if(path != "") + return driver->getTexture(path.c_str()); + // eg. games/minetest_game/menu/background.png + path = getImagePath(spec->path + DIR_DELIM + "menu" + DIR_DELIM + tname + ".png"); + if(path != "") + return driver->getTexture(path.c_str()); + } else { + std::string path; + // eg. menu_background.png + std::string pack_tname = "menu_" + tname + ".png"; + path = getTexturePath(pack_tname); + if(path != "") + return driver->getTexture(path.c_str()); + } return NULL; } - void update(video::IVideoDriver* driver, const SubgameSpec *spec) + void update(video::IVideoDriver* driver, const SubgameSpec *spec, int tab) { - if(spec->id == current_gameid) - return; - current_gameid = spec->id; - background = getMenuTexture("background", driver, spec); - overlay = getMenuTexture("overlay", driver, spec); - header = getMenuTexture("header", driver, spec); - footer = getMenuTexture("footer", driver, spec); + if(tab == TAB_SINGLEPLAYER){ + if(spec->id == current_gameid) + return; + current_gameid = spec->id; + global_textures = false; + background = getMenuTexture("background", driver, spec); + overlay = getMenuTexture("overlay", driver, spec); + header = getMenuTexture("header", driver, spec); + footer = getMenuTexture("footer", driver, spec); + } else { + if(global_textures) + return; + current_gameid = ""; + global_textures = true; + background = getMenuTexture("background", driver, NULL); + overlay = getMenuTexture("overlay", driver, NULL); + header = getMenuTexture("header", driver, NULL); + footer = getMenuTexture("footer", driver, NULL); + } } }; @@ -1778,7 +1801,7 @@ int main(int argc, char *argv[]) const SubgameSpec *menugame = getMenuGame(menudata); MenuTextures menutextures; - menutextures.update(driver, menugame); + menutextures.update(driver, menugame, menudata.selected_tab); if(skip_main_menu == false) { @@ -1839,7 +1862,7 @@ int main(int argc, char *argv[]) // Game can be selected in the menu menugame = getMenuGame(menudata); - menutextures.update(driver, menugame); + menutextures.update(driver, menugame, menu->getTab()); // Clouds for the main menu bool cloud_menu_background = g_settings->getBool("menu_clouds"); if(menugame){ -- cgit v1.2.3