GUI: Make singleplayer default tab, store selected serverlist, show title of serverlist
authorPilzAdam <pilzadam@minetest.net>
Sat, 30 Mar 2013 17:09:38 +0000 (18:09 +0100)
committerPilzAdam <pilzadam@minetest.net>
Sat, 30 Mar 2013 17:34:36 +0000 (18:34 +0100)
src/guiMainMenu.cpp
src/guiMainMenu.h
src/main.cpp

index 49028fc5bf802aef82a6bb11d144dbe99a85365e..579e6092d911e2269d0105626f14ac6b490ded8f 100644 (file)
@@ -157,6 +157,7 @@ enum
        GUI_ID_SERVERLIST,
        GUI_ID_SERVERLIST_TOGGLE,
        GUI_ID_SERVERLIST_DELETE,
+       GUI_ID_SERVERLIST_TITLE,
 };
 
 enum
@@ -427,16 +428,37 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
                changeCtype("");
                // Server List
                {
-                       core::rect<s32> rect(0, 0, 390, 160);
-                       rect += m_topleft_client + v2s32(50, 10);
+                       core::rect<s32> rect(0, 0, 390, 140);
+                       rect += m_topleft_client + v2s32(50, 30);
                        gui::IGUIListBox *e = Environment->addListBox(rect, this,
                                        GUI_ID_SERVERLIST);
                        e->setDrawBackground(true);
-                       if (m_data->serverlist_show_available == false)
-                               m_data->servers = ServerList::getLocal();
 #if USE_CURL
-                       else
+                       if(m_data->selected_serverlist == SERVERLIST_FAVORITES) {
+                               m_data->servers = ServerList::getLocal();
+                               {
+                                       core::rect<s32> rect(0, 0, 110, 20);
+                                       rect += m_topleft_client + v2s32(50, 10);
+                                       Environment->addStaticText(wgettext("Favorites:"),
+                                               rect, false, true, this, GUI_ID_SERVERLIST_TITLE);
+                               }
+                       } else {
                                m_data->servers = ServerList::getOnline();
+                               {
+                                       core::rect<s32> rect(0, 0, 110, 20);
+                                       rect += m_topleft_client + v2s32(50, 10);
+                                       Environment->addStaticText(wgettext("Public Server List:"),
+                                               rect, false, true, this, GUI_ID_SERVERLIST_TITLE);
+                               }
+                       }
+#else
+                       m_data->servers = ServerList::getLocal();
+                       {
+                               core::rect<s32> rect(0, 0, 110, 20);
+                               rect += m_topleft_client + v2s32(50, 10);
+                               Environment->addStaticText(wgettext("Favorites:"),
+                                       rect, false, true, this, GUI_ID_SERVERLIST_TITLE);
+                       }
 #endif
                        updateGuiServerList();
                        e->setSelected(0);
@@ -474,7 +496,7 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
                        gui::IGUIButton *e = Environment->addButton(rect, this, GUI_ID_SERVERLIST_TOGGLE,
                                wgettext("Show Public"));
                        e->setIsPushButton(true);
-                       if (m_data->serverlist_show_available)
+                       if (m_data->selected_serverlist == SERVERLIST_PUBLIC)
                        {
                                e->setText(wgettext("Show Favorites"));
                                e->setPressed();
@@ -487,7 +509,7 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
                        rect += m_topleft_client + v2s32(50+260+10, 180);
                        gui::IGUIButton *e = Environment->addButton(rect, this, GUI_ID_SERVERLIST_DELETE,
                                wgettext("Delete"));
-                       if (m_data->serverlist_show_available) // Hidden on Show-Online mode
+                       if (m_data->selected_serverlist == SERVERLIST_PUBLIC) // Hidden when on public list
                                e->setVisible(false);
                }
                // Start game button
@@ -1154,25 +1176,28 @@ bool GUIMainMenu::OnEvent(const SEvent& event)
                                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);
-                               if (m_data->serverlist_show_available) // switch to favorite list
+                               gui::IGUIElement *title = getElementFromId(GUI_ID_SERVERLIST_TITLE);
+                               if (m_data->selected_serverlist == SERVERLIST_PUBLIC) // switch to favorite list
                                {
                                        m_data->servers = ServerList::getLocal();
                                        togglebutton->setText(wgettext("Show Public"));
+                                       title->setText(wgettext("Favorites:"));
                                        deletebutton->setVisible(true);
                                        updateGuiServerList();
                                        serverlist->setSelected(0);
+                                       m_data->selected_serverlist = SERVERLIST_FAVORITES;
                                }
                                else // switch to online list
                                {
                                        m_data->servers = ServerList::getOnline();
                                        togglebutton->setText(wgettext("Show Favorites"));
+                                       title->setText(wgettext("Public Server List:"));
                                        deletebutton->setVisible(false);
                                        updateGuiServerList();
                                        serverlist->setSelected(0);
+                                       m_data->selected_serverlist = SERVERLIST_PUBLIC;
                                }
                                serverListOnSelected();
-
-                               m_data->serverlist_show_available = !m_data->serverlist_show_available;
                        }
                        #endif
                        }
index fa5f19defa1b31fdc729db00cf6912a6f4abe2fb..a594ccd418bac8c2b9a052b5740ab6ccc1245440 100644 (file)
@@ -29,6 +29,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 class IGameCallback;
 
+enum {
+       SERVERLIST_FAVORITES,
+       SERVERLIST_PUBLIC,
+};
+
 struct MainMenuData
 {
        // These are in the native format of the gui elements
@@ -64,7 +69,7 @@ struct MainMenuData
        std::string create_world_gameid;
        bool only_refresh;
 
-       bool serverlist_show_available; // if false show local favorites only
+       int selected_serverlist;
 
        std::vector<WorldSpec> worlds;
        std::vector<SubgameSpec> games;
@@ -72,13 +77,7 @@ struct MainMenuData
 
        MainMenuData():
                // Generic
-               selected_tab(
-#if USE_CURL
-                   1
-#else
-                   0
-#endif
-               ),
+               selected_tab(0),
                // Client opts
                fancy_trees(false),
                smooth_lighting(false),
@@ -91,13 +90,7 @@ struct MainMenuData
                // Actions
                only_refresh(false),
 
-               serverlist_show_available(
-#if USE_CURL
-                   true
-#else
-                   false
-#endif
-)
+               selected_serverlist(SERVERLIST_FAVORITES)
        {}
 };
 
index 56c12585921524230ac9355b8335948b1ef49a78..2e57a8c20b2681bc381c8d17cbd5f9b487a94d17 100644 (file)
@@ -1556,6 +1556,8 @@ int main(int argc, char *argv[])
                                MainMenuData menudata;
                                if(g_settings->exists("selected_mainmenu_tab"))
                                        menudata.selected_tab = g_settings->getS32("selected_mainmenu_tab");
+                               if(g_settings->exists("selected_serverlist"))
+                                       menudata.selected_serverlist = g_settings->getS32("selected_serverlist");
                                menudata.address = narrow_to_wide(address);
                                menudata.name = narrow_to_wide(playername);
                                menudata.port = narrow_to_wide(itos(port));
@@ -1752,6 +1754,7 @@ int main(int argc, char *argv[])
                                simple_singleplayer_mode = menudata.simple_singleplayer_mode;
                                // Save settings
                                g_settings->setS32("selected_mainmenu_tab", menudata.selected_tab);
+                               g_settings->setS32("selected_serverlist", menudata.selected_serverlist);
                                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));