From d8d27274e6a013b6cc04b15c4d5a9b0e8e22b95b Mon Sep 17 00:00:00 2001 From: darkrose Date: Wed, 16 Dec 2015 03:07:44 +1000 Subject: [PATCH] new multiplayer menu, pt1 --- src/CMakeLists.txt | 1 + src/guiMainMenu.cpp | 143 ++------------ src/guiMainMenu.h | 4 - src/guiMultiplayerMenu.cpp | 369 +++++++++++++++++++++++++++++++++++++ src/guiMultiplayerMenu.h | 112 +++++++++++ src/guiPauseMenu.h | 1 + src/main.cpp | 18 +- src/mainmenumanager.h | 7 + 8 files changed, 515 insertions(+), 140 deletions(-) create mode 100644 src/guiMultiplayerMenu.cpp create mode 100644 src/guiMultiplayerMenu.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 70b0584..514eef1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -250,6 +250,7 @@ set(voxelands_SRCS clientobject.cpp guiMainMenu.cpp guiSettingsMenu.cpp + guiMultiplayerMenu.cpp guiMessageMenu.cpp guiTextInputMenu.cpp guiFormSpecMenu.cpp diff --git a/src/guiMainMenu.cpp b/src/guiMainMenu.cpp index 64cd6f8..4c3ac32 100644 --- a/src/guiMainMenu.cpp +++ b/src/guiMainMenu.cpp @@ -28,6 +28,7 @@ #include "main.h" #include "defaultsettings.h" #include "guiSettingsMenu.h" +#include "guiMultiplayerMenu.h" #include "debug.h" #include "serialization.h" #include @@ -86,9 +87,6 @@ void GUIMainMenu::removeChildren() void GUIMainMenu::regenerateGui(v2u32 screensize) { - std::wstring text_name; - std::wstring text_address; - std::wstring text_port; std::wstring game_mode; std::wstring max_mob_level; @@ -110,32 +108,6 @@ void GUIMainMenu::regenerateGui(v2u32 screensize) m_screensize = screensize; - // Client options - { - gui::IGUIElement *e = getElementFromId(GUI_ID_NAME_INPUT); - if (e != NULL) { - text_name = e->getText(); - }else{ - text_name = m_data->name; - } - if (text_name == L"") - text_name = narrow_to_wide(porting::getUser()); - } - { - gui::IGUIElement *e = getElementFromId(GUI_ID_ADDRESS_INPUT); - if(e != NULL) - text_address = e->getText(); - else - text_address = m_data->address; - } - { - gui::IGUIElement *e = getElementFromId(GUI_ID_PORT_INPUT); - if(e != NULL) - text_port = e->getText(); - else - text_port = m_data->port; - } - // Server options { gui::IGUIElement *e = getElementFromId(GUI_ID_GAME_MODE_COMBO); @@ -403,75 +375,7 @@ void GUIMainMenu::regenerateGui(v2u32 screensize) m_data->selected_tab = TAB_SINGLEPLAYER; } - if (m_data->selected_tab == TAB_MULTIPLAYER) { - { - core::rect rect(0, 0, 550, 20); - rect += topleft_content + v2s32(0, 20); - gui::IGUIStaticText *t = Environment->addStaticText(wgettext("Multi Player"), rect, false, true, this, -1); - t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); - } - - // Nickname + password - { - core::rect rect(0, 0, 110, 20); - rect += topleft_content + v2s32(120, 60); - Environment->addStaticText(wgettext("Name/Password"), rect, false, true, this, -1); - } - { - core::rect rect(0, 0, 230, 30); - rect += topleft_content + v2s32(135, 90); -#if USE_FREETYPE - new gui::intlGUIEditBox(text_name.c_str(), true, Environment, this, GUI_ID_NAME_INPUT, rect); -#else - Environment->addEditBox(text_name.c_str(), rect, false, this, GUI_ID_NAME_INPUT); -#endif - } - { - core::rect rect(0, 0, 230, 30); - rect += topleft_content + v2s32(135, 125); - gui::IGUIEditBox *e; -#if USE_FREETYPE - e = (gui::IGUIEditBox *) new gui::intlGUIEditBox(L"", true, Environment, this, GUI_ID_PW_INPUT, rect); -#else - e = Environment->addEditBox(L"", rect, false, this, GUI_ID_PW_INPUT); -#endif - e->setPasswordBox(true); - Environment->setFocus(e); - - } - // Address + port - { - core::rect rect(0, 0, 110, 20); - rect += topleft_content + v2s32(120, 170); - Environment->addStaticText(wgettext("Address/Port"), rect, false, true, this, -1); - } - { - if (text_address == L"") - text_address = L"servers.voxelands.com"; - core::rect rect(0, 0, 230, 30); - rect += topleft_content + v2s32(135, 200); -#if USE_FREETYPE - new gui::intlGUIEditBox(text_address.c_str(), true, Environment, this, GUI_ID_ADDRESS_INPUT, rect); -#else - Environment->addEditBox(text_address.c_str(), rect, false, this, GUI_ID_ADDRESS_INPUT); -#endif - } - { - core::rect rect(0, 0, 120, 30); - rect += topleft_content + v2s32(245, 240); -#if USE_FREETYPE - new gui::intlGUIEditBox(text_port.c_str(), true, Environment, this, GUI_ID_PORT_INPUT, rect); -#else - Environment->addEditBox(text_port.c_str(), rect, false, this, GUI_ID_PORT_INPUT); -#endif - } - // Start game button - { - core::rect rect(0, 0, 180, 30); - rect += topleft_content + v2s32(160, 290); - Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON, wgettext("Connect")); - } - }else if (m_data->selected_tab == TAB_SINGLEPLAYER) { + if (m_data->selected_tab == TAB_SINGLEPLAYER) { { core::rect rect(0, 0, 550, 20); rect += topleft_content + v2s32(0, 20); @@ -839,29 +743,10 @@ void GUIMainMenu::drawMenu() void GUIMainMenu::acceptInput() { - { - gui::IGUIElement *e = getElementFromId(GUI_ID_NAME_INPUT); - if (e != NULL) { - m_data->name = e->getText(); - }else if (m_data->name == L"") { - m_data->name = std::wstring(L"singleplayer"); - } - } - { - gui::IGUIElement *e = getElementFromId(GUI_ID_PW_INPUT); - if(e != NULL) - m_data->password = e->getText(); - } - { - gui::IGUIElement *e = getElementFromId(GUI_ID_ADDRESS_INPUT); - if (e != NULL) - m_data->address = e->getText(); - } - { - gui::IGUIElement *e = getElementFromId(GUI_ID_PORT_INPUT); - if (e != NULL) - m_data->port = e->getText(); - } + if (m_data->name == L"") + m_data->name = std::wstring(L"singleplayer"); + m_data->password = L""; + m_data->address = L""; std::wstring o_mode = m_data->game_mode; { gui::IGUIElement *e = getElementFromId(GUI_ID_GAME_MODE_COMBO); @@ -1156,13 +1041,7 @@ bool GUIMainMenu::OnEvent(const SEvent& event) switch (event.GUIEvent.Caller->getID()) { case GUI_ID_JOIN_GAME_BUTTON: // Start game acceptInput(); - if ( - m_data->selected_tab == TAB_SINGLEPLAYER - || m_data->selected_tab == TAB_SINGLEPLAYER_ADVANCED - || m_data->selected_tab == TAB_SINGLEPLAYER_MAP - ) - m_data->address = std::wstring(L""); - quitMenu(); + m_gamecallback->startGame(); return true; case GUI_ID_CHARACTER_CREATOR: { @@ -1197,13 +1076,13 @@ bool GUIMainMenu::OnEvent(const SEvent& event) regenerateGui(m_screensize); return true; case GUI_ID_TAB_MULTIPLAYER: + { if (m_data->selected_tab == TAB_SETTINGS) acceptInput(); - m_accepted = false; - m_data->selected_tab = TAB_MULTIPLAYER; - g_settings->set("mainmenu_tab","multiplayer"); - regenerateGui(m_screensize); + GUIMultiplayerMenu *mmenu = new GUIMultiplayerMenu(env, parent, -1,m_data,menumgr,m_gamecallback); + mmenu->drop(); return true; + } case GUI_ID_TAB_SETTINGS: { GUISettingsMenu *smenu = new GUISettingsMenu(env, parent, -1,menumgr, false); diff --git a/src/guiMainMenu.h b/src/guiMainMenu.h index 168faaa..3f00957 100644 --- a/src/guiMainMenu.h +++ b/src/guiMainMenu.h @@ -35,10 +35,6 @@ enum { GUI_ID_QUIT_BUTTON = 101, - GUI_ID_NAME_INPUT, - GUI_ID_PW_INPUT, - GUI_ID_ADDRESS_INPUT, - GUI_ID_PORT_INPUT, GUI_ID_GAME_MODE_COMBO, GUI_ID_GAME_MODE_CREATIVE, GUI_ID_GAME_MODE_ADVENTURE, diff --git a/src/guiMultiplayerMenu.cpp b/src/guiMultiplayerMenu.cpp new file mode 100644 index 0000000..d462ff5 --- /dev/null +++ b/src/guiMultiplayerMenu.cpp @@ -0,0 +1,369 @@ +/************************************************************************ +* guiMultiplayerMenu.cpp +* voxelands - 3d voxel world sandbox game +* Copyright (C) Lisa 'darkrose' Milne 2013-2015 +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +* See the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see +* +* License updated from GPLv2 or later to GPLv3 or later by Lisa Milne +* for Voxelands. +************************************************************************/ + +#include "guiMultiplayerMenu.h" +#include "debug.h" +#include "serialization.h" +#include "main.h" +#include +#include +#include +#include +#include +#include +#include +#include "settings.h" +#include "gui_colours.h" + +GUIMultiplayerMenu::GUIMultiplayerMenu( + gui::IGUIEnvironment* env, + gui::IGUIElement* + parent, + s32 id, + MainMenuData *data, + IMenuManager *menumgr, + IGameCallback *gamecallback +): + GUIModalMenu(env, parent, id, menumgr), + m_accepted(false), + m_gamecallback(gamecallback) +{ + m_data.mmdata = data; +} + +GUIMultiplayerMenu::~GUIMultiplayerMenu() +{ + removeChildren(); +} + +void GUIMultiplayerMenu::removeChildren() +{ + const core::list &children = getChildren(); + core::list children_copy; + for (core::list::ConstIterator i = children.begin(); i != children.end(); i++) { + children_copy.push_back(*i); + } + for (core::list::Iterator i = children_copy.begin(); i != children_copy.end(); i++) { + (*i)->remove(); + } +} + +void GUIMultiplayerMenu::regenerateGui(v2u32 screensize) +{ + std::wstring text_name; + std::wstring text_address; + std::wstring text_port; + + m_screensize = screensize; + + // Client options + { + gui::IGUIElement *e = getElementFromId(GUI_ID_NAME_INPUT); + if (e != NULL) { + text_name = e->getText(); + }else{ + text_name = m_data.mmdata->name; + } + if (text_name == L"") + text_name = narrow_to_wide(porting::getUser()); + } + { + gui::IGUIElement *e = getElementFromId(GUI_ID_ADDRESS_INPUT); + if (e != NULL) { + text_address = e->getText(); + }else{ + text_address = m_data.mmdata->address; + } + } + { + gui::IGUIElement *e = getElementFromId(GUI_ID_PORT_INPUT); + if (e != NULL) { + text_port = e->getText(); + }else{ + text_port = m_data.mmdata->port; + } + } + + /* + Remove stuff + */ + removeChildren(); + + /* + Calculate new sizes and positions + */ + + v2s32 size(800, 500); + + core::rect rect( + screensize.X/2 - size.X/2, + screensize.Y/2 - size.Y/2, + screensize.X/2 + size.X/2, + screensize.Y/2 + size.Y/2 + ); + + DesiredRect = rect; + recalculateAbsolutePosition(false); + + // Main Menu button + { + core::rect rect(0, 0, 200, 40); + rect += v2s32(25, 200); + Environment->addButton(rect, this, GUI_ID_TAB_MP_MAINMENU, wgettext("Main Menu")); + } + + // Dynamic List button + { + core::rect rect(0, 0, 180, 40); + rect += v2s32(35, 260); + Environment->addButton(rect, this, GUI_ID_TAB_MP_LIST, wgettext("All Servers")); + } + // Favourites List button + { + core::rect rect(0, 0, 180, 40); + rect += v2s32(35, 305); + Environment->addButton(rect, this, GUI_ID_TAB_MP_FAVOURITES, wgettext("Favourite Servers")); + } + // Custom Connect button (the old multiplayer menu) + { + core::rect rect(0, 0, 180, 40); + rect += v2s32(35, 350); + Environment->addButton(rect, this, GUI_ID_TAB_MP_CUSTOM, wgettext("Custom Connect")); + } + + v2s32 topleft_content(250, 0); + if (m_data.selected_tab == TAB_MP_CUSTOM) { + { + core::rect rect(0, 0, 550, 20); + rect += topleft_content + v2s32(0, 20); + gui::IGUIStaticText *t = Environment->addStaticText(wgettext("Multi Player"), rect, false, true, this, -1); + t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); + } + + // Nickname + password + { + core::rect rect(0, 0, 110, 20); + rect += topleft_content + v2s32(120, 60); + Environment->addStaticText(wgettext("Name/Password"), rect, false, true, this, -1); + } + { + core::rect rect(0, 0, 230, 30); + rect += topleft_content + v2s32(135, 90); +#if USE_FREETYPE + new gui::intlGUIEditBox(text_name.c_str(), true, Environment, this, GUI_ID_NAME_INPUT, rect); +#else + Environment->addEditBox(text_name.c_str(), rect, false, this, GUI_ID_NAME_INPUT); +#endif + } + { + core::rect rect(0, 0, 230, 30); + rect += topleft_content + v2s32(135, 125); + gui::IGUIEditBox *e; +#if USE_FREETYPE + e = (gui::IGUIEditBox *) new gui::intlGUIEditBox(L"", true, Environment, this, GUI_ID_PW_INPUT, rect); +#else + e = Environment->addEditBox(L"", rect, false, this, GUI_ID_PW_INPUT); +#endif + e->setPasswordBox(true); + Environment->setFocus(e); + + } + // Address + port + { + core::rect rect(0, 0, 110, 20); + rect += topleft_content + v2s32(120, 170); + Environment->addStaticText(wgettext("Address/Port"), rect, false, true, this, -1); + } + { + if (text_address == L"") + text_address = L"servers.voxelands.com"; + core::rect rect(0, 0, 230, 30); + rect += topleft_content + v2s32(135, 200); +#if USE_FREETYPE + new gui::intlGUIEditBox(text_address.c_str(), true, Environment, this, GUI_ID_ADDRESS_INPUT, rect); +#else + Environment->addEditBox(text_address.c_str(), rect, false, this, GUI_ID_ADDRESS_INPUT); +#endif + } + { + core::rect rect(0, 0, 120, 30); + rect += topleft_content + v2s32(245, 240); +#if USE_FREETYPE + new gui::intlGUIEditBox(text_port.c_str(), true, Environment, this, GUI_ID_PORT_INPUT, rect); +#else + Environment->addEditBox(text_port.c_str(), rect, false, this, GUI_ID_PORT_INPUT); +#endif + } + // Start game button + { + core::rect rect(0, 0, 180, 30); + rect += topleft_content + v2s32(160, 290); + Environment->addButton(rect, this, GUI_ID_CONNECT_BUTTON, wgettext("Connect")); + } + }else if (m_data.selected_tab == TAB_MP_FAVOURITES) { + }else{ + } +} + +void GUIMultiplayerMenu::drawMenu() +{ + video::IVideoDriver* driver = Environment->getVideoDriver(); + + { + core::rect left( + AbsoluteRect.UpperLeftCorner.X, + AbsoluteRect.UpperLeftCorner.Y, + AbsoluteRect.LowerRightCorner.X-550, + AbsoluteRect.LowerRightCorner.Y + ); + core::rect right( + AbsoluteRect.UpperLeftCorner.X+250, + AbsoluteRect.UpperLeftCorner.Y, + AbsoluteRect.LowerRightCorner.X, + AbsoluteRect.LowerRightCorner.Y + ); + driver->draw2DRectangle(left, GUI_BG_BTM, GUI_BG_BTM, GUI_BG_BTM, GUI_BG_BTM, &AbsoluteClippingRect); + driver->draw2DRectangle(right, GUI_BG_TOP, GUI_BG_BTM, GUI_BG_TOP, GUI_BG_BTM, &AbsoluteClippingRect); + video::ITexture *texture = driver->getTexture(getTexturePath("menulogo.png").c_str()); + if (texture != 0) { + const core::dimension2d& img_origsize = texture->getOriginalSize(); + core::rect logo( + AbsoluteRect.UpperLeftCorner.X+25, + AbsoluteRect.UpperLeftCorner.Y, + AbsoluteRect.UpperLeftCorner.X+225, + AbsoluteRect.UpperLeftCorner.Y+200 + ); + const video::SColor color(255,255,255,255); + const video::SColor colors[] = {color,color,color,color}; + driver->draw2DImage(texture, logo, core::rect(core::position2d(0,0),img_origsize), NULL, colors, true); + } + } + + gui::IGUIElement::draw(); +} + +bool GUIMultiplayerMenu::acceptInput() +{ + { + gui::IGUIElement *e = getElementFromId(GUI_ID_NAME_INPUT); + if (e != NULL) + m_data.mmdata->name = e->getText(); + if (m_data.mmdata->name == L"") + m_data.mmdata->name = narrow_to_wide(porting::getUser()); + } + { + gui::IGUIElement *e = getElementFromId(GUI_ID_PW_INPUT); + if (e != NULL) + m_data.mmdata->password = e->getText(); + } + { + gui::IGUIElement *e = getElementFromId(GUI_ID_ADDRESS_INPUT); + if (e != NULL) + m_data.mmdata->address = e->getText(); + } + { + gui::IGUIElement *e = getElementFromId(GUI_ID_PORT_INPUT); + if (e != NULL) + m_data.mmdata->port = e->getText(); + } + return true; +} +bool GUIMultiplayerMenu::OnEvent(const SEvent& event) +{ + if (event.EventType==EET_KEY_INPUT_EVENT) { + if ( + event.KeyInput.PressedDown + && ( + event.KeyInput.Key == KEY_ESCAPE + || event.KeyInput.Key == KEY_RETURN + ) + ) { + acceptInput(); + quitMenu(); + return true; + } + } + if (event.EventType == EET_GUI_EVENT) { + if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST && isVisible()) { + if (!canTakeFocus(event.GUIEvent.Element)) { + dstream << "GUIMainMenu: Not allowing focus change." + << std::endl; + // Returning true disables focus change + return true; + } + } + if (event.GUIEvent.EventType==gui::EGET_CHECKBOX_CHANGED) { + acceptInput(); + m_accepted = false; + regenerateGui(m_screensize); + } + if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED) { + switch (event.GUIEvent.Caller->getID()) { + case GUI_ID_CONNECT_BUTTON: // Start game + acceptInput(); + m_gamecallback->startGame(); + quitMenu(); + return true; + case GUI_ID_TAB_MP_LIST: + acceptInput(); + m_accepted = false; + m_data.selected_tab = TAB_MP_LIST; + regenerateGui(m_screensize); + return true; + case GUI_ID_TAB_MP_FAVOURITES: + acceptInput(); + m_accepted = false; + m_data.selected_tab = TAB_MP_FAVOURITES; + regenerateGui(m_screensize); + return true; + case GUI_ID_TAB_MP_CUSTOM: + acceptInput(); + m_accepted = false; + m_data.selected_tab = TAB_MP_CUSTOM; + regenerateGui(m_screensize); + return true; + case GUI_ID_TAB_MP_MAINMENU: //back + acceptInput(); + quitMenu(); + return true; + } + } + if (event.GUIEvent.EventType == gui::EGET_SCROLL_BAR_CHANGED) { + //switch (event.GUIEvent.Caller->getID()) { + //} + } + if (event.GUIEvent.EventType == gui::EGET_EDITBOX_ENTER) { + switch (event.GUIEvent.Caller->getID()) { + case GUI_ID_ADDRESS_INPUT: + case GUI_ID_PORT_INPUT: + case GUI_ID_NAME_INPUT: + case GUI_ID_PW_INPUT: + m_gamecallback->startGame(); + acceptInput(); + quitMenu(); + return true; + } + } + } + return Parent ? Parent->OnEvent(event) : false; +} + diff --git a/src/guiMultiplayerMenu.h b/src/guiMultiplayerMenu.h new file mode 100644 index 0000000..1b79284 --- /dev/null +++ b/src/guiMultiplayerMenu.h @@ -0,0 +1,112 @@ + /************************************************************************ +* guiMultiplayerMenu.h +* voxelands - 3d voxel world sandbox game +* Copyright (C) Lisa 'darkrose' Milne 2013-2015 +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +* See the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see +* +* License updated from GPLv2 or later to GPLv3 or later by Lisa Milne +* for Voxelands. +************************************************************************/ + +#ifndef GUIMULTIPLAYERMENU_HEADER +#define GUIMULTIPLAYERMENU_HEADER + +#include "common_irrlicht.h" +#include "utility.h" +#include "modalMenu.h" +#include "client.h" +#include "intl.h" +#include "keycode.h" +#include +// For IGameCallback +#include "guiPauseMenu.h" +#include "guiMainMenu.h" + +enum +{ + GUI_ID_CONNECT_BUTTON = 101, + // full list + // favourites + // custom connect + GUI_ID_NAME_INPUT, + GUI_ID_PW_INPUT, + GUI_ID_ADDRESS_INPUT, + GUI_ID_PORT_INPUT, + // tabs + GUI_ID_TAB_MP_MAINMENU, + GUI_ID_TAB_MP_LIST, + GUI_ID_TAB_MP_FAVOURITES, + GUI_ID_TAB_MP_CUSTOM +}; + +enum { + TAB_MP_LIST=0, + TAB_MP_FAVOURITES, + TAB_MP_CUSTOM +}; + +struct MultiplayerMenuData +{ + MultiplayerMenuData(): + // Generic + selected_tab(TAB_MP_LIST), + mmdata(NULL) + {} + + // These are in the native format of the gui elements + + // Generic + int selected_tab; + // Options + // server address/port/etc is stored in here + MainMenuData *mmdata; +}; + +class GUIMultiplayerMenu: public GUIModalMenu +{ +public: + GUIMultiplayerMenu( + gui::IGUIEnvironment* env, + gui::IGUIElement* parent, + s32 id, + MainMenuData *data, + IMenuManager *menumgr, + IGameCallback *gamecallback + ); + ~GUIMultiplayerMenu(); + + void removeChildren(); + /* + Remove and re-add (or reposition) stuff + */ + void regenerateGui(v2u32 screensize); + + void drawMenu(); + + bool acceptInput(); + + bool OnEvent(const SEvent& event); + +private: + MultiplayerMenuData m_data; + bool m_accepted; + IGameCallback *m_gamecallback; + v2u32 m_screensize; + + bool resetMenu(); +}; + +#endif + diff --git a/src/guiPauseMenu.h b/src/guiPauseMenu.h index 0877a22..8de6d05 100644 --- a/src/guiPauseMenu.h +++ b/src/guiPauseMenu.h @@ -35,6 +35,7 @@ public: virtual void exitToOS() = 0; virtual void disconnect() = 0; virtual void changePassword() = 0; + virtual void startGame() = 0; }; class GUIPauseMenu : public GUIModalMenu diff --git a/src/main.cpp b/src/main.cpp index 762046c..2ee4fe2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1240,9 +1240,15 @@ int main(int argc, char *argv[]) if (g_settings->exists("mapgen_type")) menudata.map_type = g_settings->get("mapgen_type"); - GUIMainMenu *menu = - new GUIMainMenu(guienv, guiroot, -1, - &g_menumgr, &menudata, g_gamecallback, sound); + GUIMainMenu *menu = new GUIMainMenu( + guienv, + guiroot, + -1, + &g_menumgr, + &menudata, + g_gamecallback, + sound + ); menu->allowFocusRemoval(true); if (error_message != L"") { @@ -1267,8 +1273,12 @@ int main(int argc, char *argv[]) while (device->run() && kill == false) { if (menu->getStatus() == true) break; + if (g_gamecallback->startgame_requested) { + g_gamecallback->startgame_requested = false; + menu->quitMenu(); + break; + } - //driver->beginScene(true, true, video::SColor(255,0,0,0)); driver->beginScene(true, true, video::SColor(255,170,230,255)); drawMenuBackground(driver); diff --git a/src/mainmenumanager.h b/src/mainmenumanager.h index 65481e6..16e15b7 100644 --- a/src/mainmenumanager.h +++ b/src/mainmenumanager.h @@ -89,6 +89,7 @@ public: MainGameCallback(IrrlichtDevice *a_device): disconnect_requested(false), changepassword_requested(false), + startgame_requested(false), device(a_device) { } @@ -108,8 +109,14 @@ public: changepassword_requested = true; } + virtual void startGame() + { + startgame_requested = true; + } + bool disconnect_requested; bool changepassword_requested; + bool startgame_requested; IrrlichtDevice *device; };