Save selected tab
authorPerttu Ahola <celeron55@gmail.com>
Thu, 15 Mar 2012 12:17:05 +0000 (14:17 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Thu, 15 Mar 2012 12:17:05 +0000 (14:17 +0200)
src/guiMainMenu.cpp
src/guiMainMenu.h
src/main.cpp

index cb9fe43a650984dd5429e90210cdb15103e78faa..346471337f94508970660a907287e81284c7e012 100644 (file)
@@ -145,8 +145,6 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
        */
        readInput(m_data);
 
-       int active_tab = getTab();
-       
        /*
                Remove stuff
        */
@@ -177,7 +175,7 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
        changeCtype("");
 
        // Version
-       if(active_tab != TAB_CREDITS)
+       if(m_data->selected_tab != TAB_CREDITS)
        {
                core::rect<s32> rect(0, 0, size.X, 40);
                rect += v2s32(4, 0);
@@ -195,7 +193,7 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
        m_topleft_server = c800 + v2s32(90, 70+30+50+290);
        m_size_server = v2s32(620, 140);
        
-       if(active_tab == TAB_ADVANCED)
+       if(m_data->selected_tab == TAB_ADVANCED)
        {
                m_topleft_client = c800 + v2s32(90, 20+50+30);
                m_size_client = v2s32(620, 270);
@@ -215,11 +213,11 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
                e->addTab(L"Multiplayer");
                e->addTab(L"Advanced");
                e->addTab(L"Credits");
-               e->setActiveTab(active_tab);
+               e->setActiveTab(m_data->selected_tab);
        }
 #endif
        
-       if(active_tab == TAB_SINGLEPLAYER)
+       if(m_data->selected_tab == TAB_SINGLEPLAYER)
        {
                // HYBRID
                {
@@ -262,6 +260,7 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
                                e->addItem(narrow_to_wide(i->name+" ["+i->gameid+"]").c_str());
                        }
                        e->setSelected(m_data->selected_world);
+                       Environment->setFocus(e);
                }
                // Delete world button
                {
@@ -351,7 +350,7 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
                }
                changeCtype("C");
        }
-       else if(active_tab == TAB_MULTIPLAYER)
+       else if(m_data->selected_tab == TAB_MULTIPLAYER)
        {
                changeCtype("");
                // CLIENT
@@ -456,7 +455,7 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
                }
                changeCtype("C");
        }
-       else if(active_tab == TAB_ADVANCED)
+       else if(m_data->selected_tab == TAB_ADVANCED)
        {
                changeCtype("");
                // CLIENT
@@ -619,7 +618,7 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
                }
                changeCtype("C");
        }
-       else if(active_tab == TAB_CREDITS)
+       else if(m_data->selected_tab == TAB_CREDITS)
        {
                // CREDITS
                {
@@ -716,6 +715,11 @@ void GUIMainMenu::drawMenu()
 
 void GUIMainMenu::readInput(MainMenuData *dst)
 {
+       {
+               gui::IGUIElement *e = getElementFromId(GUI_ID_TAB_CONTROL);
+               if(e != NULL && e->getType() == gui::EGUIET_TAB_CONTROL)
+                       dst->selected_tab = ((gui::IGUITabControl*)e)->getActiveTab();
+       }
        if(getTab() == TAB_SINGLEPLAYER)
        {
                dst->name = L"singleplayer";
@@ -940,7 +944,6 @@ int GUIMainMenu::getTab()
        gui::IGUIElement *e = getElementFromId(GUI_ID_TAB_CONTROL);
        if(e != NULL && e->getType() == gui::EGUIET_TAB_CONTROL)
                return ((gui::IGUITabControl*)e)->getActiveTab();
-       //return TAB_ADVANCED; // Default
        return TAB_SINGLEPLAYER; // Default
 }
 
index 397c2f7ce13a9494c584f5615cb96c9f49de6848..5cb0f8e2bcf4dda11b439f669f09da5edf091721 100644 (file)
@@ -30,6 +30,8 @@ class IGameCallback;
 struct MainMenuData
 {
        // These are in the native format of the gui elements
+       // Generic
+       int selected_tab;
        // Client options
        std::wstring address;
        std::wstring port;
@@ -52,6 +54,8 @@ struct MainMenuData
        std::vector<SubgameSpec> games;
 
        MainMenuData():
+               // Generic
+               selected_tab(0),
                // Client opts
                fancy_trees(false),
                smooth_lighting(false),
index 38a3b725b828bd0331ec7c0a5cff74e19bd43bb0..2925f048c5ea9dbffa89dfaacccb6614460f3bff 100644 (file)
@@ -1276,6 +1276,8 @@ int main(int argc, char *argv[])
                                
                                // Initialize menu data
                                MainMenuData menudata;
+                               if(g_settings->exists("selected_mainmenu_tab"))
+                                       menudata.selected_tab = g_settings->getS32("selected_mainmenu_tab");
                                menudata.address = narrow_to_wide(address);
                                menudata.name = narrow_to_wide(playername);
                                menudata.port = narrow_to_wide(itos(port));
@@ -1362,15 +1364,41 @@ int main(int argc, char *argv[])
                                                sleep_ms(25);
                                        }
                                        
-                                       // Break out of menu-game loop to shut down cleanly
-                                       if(device->run() == false || kill == true)
-                                               break;
-                                       
                                        infostream<<"Dropping main menu"<<std::endl;
 
                                        menu->drop();
                                }
 
+                               playername = wide_to_narrow(menudata.name);
+                               password = translatePassword(playername, menudata.password);
+                               //infostream<<"Main: password hash: '"<<password<<"'"<<std::endl;
+
+                               address = wide_to_narrow(menudata.address);
+                               int newport = stoi(wide_to_narrow(menudata.port));
+                               if(newport != 0)
+                                       port = newport;
+                               // Save settings
+                               g_settings->setS32("selected_mainmenu_tab", menudata.selected_tab);
+                               g_settings->set("new_style_leaves", itos(menudata.fancy_trees));
+                               g_settings->set("smooth_lighting", itos(menudata.smooth_lighting));
+                               g_settings->set("enable_3d_clouds", itos(menudata.clouds_3d));
+                               g_settings->set("opaque_water", itos(menudata.opaque_water));
+                               g_settings->set("creative_mode", itos(menudata.creative_mode));
+                               g_settings->set("enable_damage", itos(menudata.enable_damage));
+                               g_settings->set("name", playername);
+                               g_settings->set("address", address);
+                               g_settings->set("port", itos(port));
+                               if(menudata.selected_world != -1)
+                                       g_settings->set("selected_world_path",
+                                                       worldspecs[menudata.selected_world].path);
+                               /*// Update configuration file
+                               if(configpath != "")
+                                       g_settings->updateConfigFile(configpath.c_str());*/
+                               
+                               // Break out of menu-game loop to shut down cleanly
+                               if(device->run() == false || kill == true)
+                                       break;
+                               
                                // Set world path to selected one
                                if(menudata.selected_world != -1){
                                        worldspec = worldspecs[menudata.selected_world];
@@ -1406,31 +1434,6 @@ int main(int argc, char *argv[])
                                        continue;
                                }
 
-                               playername = wide_to_narrow(menudata.name);
-                               password = translatePassword(playername, menudata.password);
-                               //infostream<<"Main: password hash: '"<<password<<"'"<<std::endl;
-
-                               address = wide_to_narrow(menudata.address);
-                               int newport = stoi(wide_to_narrow(menudata.port));
-                               if(newport != 0)
-                                       port = newport;
-                               // Save settings
-                               g_settings->set("new_style_leaves", itos(menudata.fancy_trees));
-                               g_settings->set("smooth_lighting", itos(menudata.smooth_lighting));
-                               g_settings->set("enable_3d_clouds", itos(menudata.clouds_3d));
-                               g_settings->set("opaque_water", itos(menudata.opaque_water));
-                               g_settings->set("creative_mode", itos(menudata.creative_mode));
-                               g_settings->set("enable_damage", itos(menudata.enable_damage));
-                               g_settings->set("name", playername);
-                               g_settings->set("address", address);
-                               g_settings->set("port", itos(port));
-                               if(menudata.selected_world != -1)
-                                       g_settings->set("selected_world_path",
-                                                       worldspecs[menudata.selected_world].path);
-                               // Update configuration file
-                               if(configpath != "")
-                                       g_settings->updateConfigFile(configpath.c_str());
-                               
                                // If local game
                                if(address == "")
                                {