diff --git a/src/game.cpp b/src/game.cpp index 465e83ea5..7d6f884e9 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -658,7 +658,8 @@ void the_game( std::wstring &error_message, std::string configpath, ChatBackend &chat_backend, - const SubgameSpec &gamespec // Used for local game + const SubgameSpec &gamespec, // Used for local game, + bool simple_singleplayer_mode ) { video::IVideoDriver* driver = device->getVideoDriver(); @@ -709,7 +710,8 @@ void the_game( if(address == ""){ draw_load_screen(L"Creating server...", driver, font); infostream<<"Creating server"<start(port); } @@ -1357,7 +1359,7 @@ void the_game( <<"Launching pause menu"<drop(); + &g_menumgr, simple_singleplayer_mode))->drop(); // Move mouse cursor on top of the disconnect button input->setMousePos(displaycenter.X, displaycenter.Y+25); diff --git a/src/game.h b/src/game.h index 4ca5a2433..596945e99 100644 --- a/src/game.h +++ b/src/game.h @@ -138,7 +138,8 @@ void the_game( std::wstring &error_message, std::string configpath, ChatBackend &chat_backend, - const SubgameSpec &gamespec // Used for local game + const SubgameSpec &gamespec, // Used for local game + bool simple_singleplayer_mode ); #endif diff --git a/src/guiMainMenu.cpp b/src/guiMainMenu.cpp index 346471337..40f51f97c 100644 --- a/src/guiMainMenu.cpp +++ b/src/guiMainMenu.cpp @@ -720,15 +720,13 @@ void GUIMainMenu::readInput(MainMenuData *dst) if(e != NULL && e->getType() == gui::EGUIET_TAB_CONTROL) dst->selected_tab = ((gui::IGUITabControl*)e)->getActiveTab(); } - if(getTab() == TAB_SINGLEPLAYER) + if(dst->selected_tab == TAB_SINGLEPLAYER) { - dst->name = L"singleplayer"; - dst->password = L""; - dst->address = L""; - dst->port = 30000; + dst->simple_singleplayer_mode = true; } else { + dst->simple_singleplayer_mode = false; { gui::IGUIElement *e = getElementFromId(GUI_ID_NAME_INPUT); if(e != NULL) diff --git a/src/guiMainMenu.h b/src/guiMainMenu.h index 5cb0f8e2b..5f9e73f62 100644 --- a/src/guiMainMenu.h +++ b/src/guiMainMenu.h @@ -45,6 +45,7 @@ struct MainMenuData bool creative_mode; bool enable_damage; int selected_world; + bool simple_singleplayer_mode; // Actions WorldSpec delete_world_spec; std::wstring create_world_name; @@ -62,7 +63,8 @@ struct MainMenuData // Server opts creative_mode(false), enable_damage(false), - selected_world(0) + selected_world(0), + simple_singleplayer_mode(false) {} }; diff --git a/src/guiPauseMenu.cpp b/src/guiPauseMenu.cpp index 3b1861b3d..e542a28e9 100644 --- a/src/guiPauseMenu.cpp +++ b/src/guiPauseMenu.cpp @@ -34,10 +34,12 @@ with this program; if not, write to the Free Software Foundation, Inc., GUIPauseMenu::GUIPauseMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id, IGameCallback *gamecallback, - IMenuManager *menumgr): - GUIModalMenu(env, parent, id, menumgr) + IMenuManager *menumgr, + bool simple_singleplayer_mode): + GUIModalMenu(env, parent, id, menumgr), + m_gamecallback(gamecallback), + m_simple_singleplayer_mode(simple_singleplayer_mode) { - m_gamecallback = gamecallback; } GUIPauseMenu::~GUIPauseMenu() @@ -106,7 +108,7 @@ void GUIPauseMenu::regenerateGui(v2u32 screensize) */ const s32 btn_height = 30; const s32 btn_gap = 20; - const s32 btn_num = 4; + const s32 btn_num = m_simple_singleplayer_mode ? 3 : 4; s32 btn_y = size.Y/2-((btn_num*btn_height+(btn_num-1)*btn_gap))/2; changeCtype(""); { @@ -116,18 +118,21 @@ void GUIPauseMenu::regenerateGui(v2u32 screensize) wgettext("Continue")); } btn_y += btn_height + btn_gap; + if(!m_simple_singleplayer_mode) { - core::rect rect(0, 0, 140, btn_height); - rect = rect + v2s32(size.X/2-140/2, btn_y); - Environment->addButton(rect, this, 261, - wgettext("Change Password")); + { + core::rect rect(0, 0, 140, btn_height); + rect = rect + v2s32(size.X/2-140/2, btn_y); + Environment->addButton(rect, this, 261, + wgettext("Change Password")); + } + btn_y += btn_height + btn_gap; } - btn_y += btn_height + btn_gap; { core::rect rect(0, 0, 140, btn_height); rect = rect + v2s32(size.X/2-140/2, btn_y); Environment->addButton(rect, this, 260, - wgettext("Disconnect")); + wgettext("Exit to Menu")); } btn_y += btn_height + btn_gap; { diff --git a/src/guiPauseMenu.h b/src/guiPauseMenu.h index 64e3c71f1..8514a6f0f 100644 --- a/src/guiPauseMenu.h +++ b/src/guiPauseMenu.h @@ -37,7 +37,8 @@ public: GUIPauseMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id, IGameCallback *gamecallback, - IMenuManager *menumgr); + IMenuManager *menumgr, + bool simple_singleplayer_mode); ~GUIPauseMenu(); void removeChildren(); @@ -52,6 +53,7 @@ public: private: IGameCallback *m_gamecallback; + bool m_simple_singleplayer_mode; }; #endif diff --git a/src/main.cpp b/src/main.cpp index 2925f048c..3e4686134 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1063,7 +1063,7 @@ int main(int argc, char *argv[]) infostream<<"Using gamespec \""<setS32("selected_mainmenu_tab", menudata.selected_tab); g_settings->set("new_style_leaves", itos(menudata.fancy_trees)); @@ -1391,14 +1399,24 @@ int main(int argc, char *argv[]) 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; + current_playername = playername; + current_password = password; + current_address = address; + current_port = port; + + // If using simple singleplayer mode, override + if(simple_singleplayer_mode){ + current_playername = "singleplayer"; + current_password = ""; + current_address = ""; + current_port = 30011; + } + // Set world path to selected one if(menudata.selected_world != -1){ worldspec = worldspecs[menudata.selected_world]; @@ -1435,7 +1453,7 @@ int main(int argc, char *argv[]) } // If local game - if(address == "") + if(current_address == "") { if(menudata.selected_world == -1){ error_message = L"No world selected and no address " @@ -1474,7 +1492,7 @@ int main(int argc, char *argv[]) // Break out of menu-game loop to shut down cleanly if(device->run() == false || kill == true) break; - + /* Run game */ @@ -1485,14 +1503,15 @@ int main(int argc, char *argv[]) device, font, worldspec.path, - playername, - password, - address, - port, + current_playername, + current_password, + current_address, + current_port, error_message, configpath, chat_backend, - gamespec + gamespec, + simple_singleplayer_mode ); } //try diff --git a/src/server.cpp b/src/server.cpp index cb4813ed8..a74a2ee75 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -836,11 +836,13 @@ void PlayerInfo::PrintLine(std::ostream *s) Server::Server( const std::string &path_world, const std::string &path_config, - const SubgameSpec &gamespec + const SubgameSpec &gamespec, + bool simple_singleplayer_mode ): m_path_world(path_world), m_path_config(path_config), m_gamespec(gamespec), + m_simple_singleplayer_mode(simple_singleplayer_mode), m_async_fatal_error(""), m_env(NULL), m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, this), @@ -880,7 +882,11 @@ Server::Server( // share/server m_path_share = porting::path_share + DIR_DELIM + "server"; - infostream<<"Server created for gameid \""< 1){ + infostream<<"Server: Not allowing another client to connect in" + <<" simple singleplayer mode"<getPlayer(peer_id); - if(player != NULL) - name = narrow_to_wide(player->getName()); + // Send information about server to player in chat + SendChatMessage(peer_id, getStatusString()); - std::wstring message; - message += L"*** "; - message += name; - message += L" joined game"; - BroadcastChatMessage(message); + // Send information about joining in chat + { + std::wstring name = L"unknown"; + Player *player = m_env->getPlayer(peer_id); + if(player != NULL) + name = narrow_to_wide(player->getName()); + + std::wstring message; + message += L"*** "; + message += name; + message += L" joined game"; + BroadcastChatMessage(message); + } } // Warnings about protocol version can be issued here diff --git a/src/server.h b/src/server.h index 0b4c67deb..31e3ed176 100644 --- a/src/server.h +++ b/src/server.h @@ -410,7 +410,8 @@ public: Server( const std::string &path_world, const std::string &path_config, - const SubgameSpec &gamespec + const SubgameSpec &gamespec, + bool simple_singleplayer_mode ); ~Server(); void start(unsigned short port); @@ -659,6 +660,9 @@ private: std::string m_path_config; // Subgame specification SubgameSpec m_gamespec; + // If true, do not allow multiple players and hide some multiplayer + // functionality + bool m_simple_singleplayer_mode; // Equivalent of /usr/share/minetest/server std::string m_path_share;