Only use game filter in singleplayer tab; use menu_{background, overlay, header,...
authorPilzAdam <pilzadam@minetest.net>
Sat, 11 May 2013 14:08:01 +0000 (16:08 +0200)
committerPilzAdam <pilzadam@minetest.net>
Mon, 13 May 2013 15:06:08 +0000 (17:06 +0200)
src/guiMainMenu.cpp
src/guiMainMenu.h
src/main.cpp

index 9966b9fa77a36fd5fd3810aabc9321c81478a7d0..36685db847acc0ed8a2efcd1e34d1a19ed200b43 100644 (file)
@@ -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<s32> 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; i<m_data->games.size(); i++){
+                       const SubgameSpec *spec = &m_data->games[i];
+                       v2s32 p(8 + i*(48+8), screensize.Y - (48+8));
+                       core::rect<s32> 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; i<m_data->games.size(); i++){
-               const SubgameSpec *spec = &m_data->games[i];
-               v2s32 p(8 + i*(48+8), screensize.Y - (48+8));
-               core::rect<s32> 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;
 }
 
index 1d09c8baad2c802d9f8bb30bdc0b6e3a160348ee..8697344c84e763b493daa0b76e4a50951981a36b 100644 (file)
@@ -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
index 56cb310ca9864ce5bde4e2e37638b2f3c447fc82..7f9ec1ace13385a808787888e3946e559207d493 100644 (file)
@@ -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){