From 3401d5a43a868a9d538f413143ffa7a3b7049f98 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sat, 12 Jun 2010 19:27:11 +0000 Subject: [PATCH] - added ESC key to exit from main menu --- source/glest_game/menu/menu_state_root.cpp | 62 ++++++++++++++++++++++ source/glest_game/menu/menu_state_root.h | 6 +++ 2 files changed, 68 insertions(+) diff --git a/source/glest_game/menu/menu_state_root.cpp b/source/glest_game/menu/menu_state_root.cpp index 2ef7f653..d867d765 100644 --- a/source/glest_game/menu/menu_state_root.cpp +++ b/source/glest_game/menu/menu_state_root.cpp @@ -59,6 +59,11 @@ MenuStateRoot::MenuStateRoot(Program *program, MainMenu *mainMenu): buttonAbout.setText(lang.get("About")); buttonExit.setText(lang.get("Exit")); labelVersion.setText(glestVersionString); + + //mesage box + mainMessageBox.init(lang.get("Yes"), lang.get("No")); + mainMessageBox.setEnabled(false); + } void MenuStateRoot::mouseClick(int x, int y, MouseButton mouseButton){ @@ -90,6 +95,22 @@ void MenuStateRoot::mouseClick(int x, int y, MouseButton mouseButton){ soundRenderer.playFx(coreData.getClickSoundA()); program->exit(); } + //exit message box, has to be the last thing to do in this function + else if(mainMessageBox.getEnabled()){ + int button= 1; + if(mainMessageBox.mouseClick(x, y, button)) { + if(button==1) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + soundRenderer.playFx(coreData.getClickSoundA()); + program->exit(); + } + else { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //close message box + mainMessageBox.setEnabled(false); + } + } + } } void MenuStateRoot::mouseMove(int x, int y, const MouseState *ms){ @@ -99,6 +120,10 @@ void MenuStateRoot::mouseMove(int x, int y, const MouseState *ms){ buttonOptions.mouseMove(x, y); buttonAbout.mouseMove(x, y); buttonExit.mouseMove(x,y); + if (mainMessageBox.getEnabled()) { + mainMessageBox.mouseMove(x, y); + } + } void MenuStateRoot::render(){ @@ -119,6 +144,12 @@ void MenuStateRoot::render(){ renderer.renderButton(&buttonAbout); renderer.renderButton(&buttonExit); renderer.renderLabel(&labelVersion); + + //exit message box + if(mainMessageBox.getEnabled()){ + renderer.renderMessageBox(&mainMessageBox); + } + } void MenuStateRoot::update(){ @@ -127,4 +158,35 @@ void MenuStateRoot::update(){ } } +void MenuStateRoot::keyDown(char key) { + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,key,key); + + Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); + //exit + if(key == configKeys.getCharKey("ExitKey")) { + Lang &lang= Lang::getInstance(); + showMessageBox(lang.get("ExitGame?"), "", true); + } + else if(mainMessageBox.getEnabled() == true && key == vkReturn) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + program->exit(); + } +} + +void MenuStateRoot::showMessageBox(const string &text, const string &header, bool toggle){ + if(!toggle){ + mainMessageBox.setEnabled(false); + } + + if(!mainMessageBox.getEnabled()){ + mainMessageBox.setText(text); + mainMessageBox.setHeader(header); + mainMessageBox.setEnabled(true); + } + else{ + mainMessageBox.setEnabled(false); + } +} + }}//end namespace diff --git a/source/glest_game/menu/menu_state_root.h b/source/glest_game/menu/menu_state_root.h index 7c672e34..b8396aa7 100644 --- a/source/glest_game/menu/menu_state_root.h +++ b/source/glest_game/menu/menu_state_root.h @@ -20,6 +20,8 @@ namespace Glest{ namespace Game{ // class MenuStateRoot // =============================== +class GraphicMessageBox; + class MenuStateRoot: public MenuState{ private: GraphicButton buttonNewGame; @@ -30,6 +32,8 @@ private: GraphicButton buttonExit; GraphicLabel labelVersion; + GraphicMessageBox mainMessageBox; + public: MenuStateRoot(Program *program, MainMenu *mainMenu); @@ -37,6 +41,8 @@ public: void mouseMove(int x, int y, const MouseState *mouseState); void render(); void update(); + virtual void keyDown(char key); + void showMessageBox(const string &text, const string &header, bool toggle); };