mirror of
https://github.com/minetest/minetest.git
synced 2024-12-03 13:03:45 +01:00
Save selected tab
This commit is contained in:
parent
2b200d481f
commit
899004207d
@ -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
|
||||
}
|
||||
|
||||
|
@ -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),
|
||||
|
61
src/main.cpp
61
src/main.cpp
@ -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 == "")
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user