[Orxonox-commit 1330] r6048 - in code/branches/menu: data/defaultConfig data/gui/scripts src/libraries/core src/orxonox/gamestates

scheusso at orxonox.net scheusso at orxonox.net
Thu Nov 12 11:32:41 CET 2009


Author: scheusso
Date: 2009-11-12 11:32:41 +0100 (Thu, 12 Nov 2009)
New Revision: 6048

Modified:
   code/branches/menu/data/defaultConfig/keybindings.ini
   code/branches/menu/data/gui/scripts/InGameMenu.lua
   code/branches/menu/data/gui/scripts/InitialiseGUI.lua
   code/branches/menu/src/libraries/core/GUIManager.cc
   code/branches/menu/src/libraries/core/GUIManager.h
   code/branches/menu/src/libraries/core/Game.cc
   code/branches/menu/src/libraries/core/Game.h
   code/branches/menu/src/orxonox/gamestates/GSLevel.cc
   code/branches/menu/src/orxonox/gamestates/GSLevel.h
Log:
ESC handling in ingame menu: if theres already an opened GUI sheet then hide it, if not open the ingame menu
in mainmenu everything should remain the same


Modified: code/branches/menu/data/defaultConfig/keybindings.ini
===================================================================
--- code/branches/menu/data/defaultConfig/keybindings.ini	2009-11-12 10:23:33 UTC (rev 6047)
+++ code/branches/menu/data/defaultConfig/keybindings.ini	2009-11-12 10:32:41 UTC (rev 6048)
@@ -22,7 +22,7 @@
 KeyE="scale -1 rotateRoll"
 KeyEnd=boost
 KeyEquals=
-KeyEscape="exit"
+KeyEscape="toggleIngameGUI"
 KeyF="scale -1 moveUpDown"
 KeyF1="OverlayGroup toggleVisibility Debug"
 KeyF10=

Modified: code/branches/menu/data/gui/scripts/InGameMenu.lua
===================================================================
--- code/branches/menu/data/gui/scripts/InGameMenu.lua	2009-11-12 10:23:33 UTC (rev 6047)
+++ code/branches/menu/data/gui/scripts/InGameMenu.lua	2009-11-12 10:32:41 UTC (rev 6048)
@@ -17,8 +17,7 @@
 
 -- events for ingamemenu
 function P.button_quit_clicked(e)
-    orxonox.CommandExecutor:execute("hideGUI InGameMenu")
-    orxonox.CommandExecutor:execute("exit")
+    openDecisionPopup( "Do you really want to quit the game?", InGameMenu.callback )
 end
 
 function P.button_mainmenu_clicked(e)
@@ -33,5 +32,12 @@
     orxonox.CommandExecutor:execute("hideGUI InGameMenu")
 end
 
+function P.callback(doExit)
+    if doExit then
+        orxonox.CommandExecutor:execute("hideGUI InGameMenu")
+        orxonox.CommandExecutor:execute("exit")
+    end
+end
+
 return P
 

Modified: code/branches/menu/data/gui/scripts/InitialiseGUI.lua
===================================================================
--- code/branches/menu/data/gui/scripts/InitialiseGUI.lua	2009-11-12 10:23:33 UTC (rev 6047)
+++ code/branches/menu/data/gui/scripts/InitialiseGUI.lua	2009-11-12 10:32:41 UTC (rev 6048)
@@ -20,6 +20,9 @@
 bShowsCursor = false
 bHidePrevious = {}
 
+-- Require all tools
+require("GUITools")
+
 -- loads the GUI with the specified filename
 -- be sure to set the global variable "filename" before calling this function
 function loadGUI(filename)
@@ -27,6 +30,9 @@
     loadedGui = loadedGUIs[filename]
     if loadedGui == nil then
         loadedGuiNS = require(filename)
+        if loadedGuiNS == nil then
+            return
+        end
         loadedGui = loadedGuiNS:load()
         loadedGUIs[filename] = loadedGui
         -- if there has no GUI been loaded yet, set new GUI as current
@@ -146,6 +152,10 @@
     bHidePrevious[filename] = nil
 end
 
+function keyESC()
+    orxonox.CommandExecutor:execute("hideGUI "..activeSheets[nrOfActiveSheets])
+end
+
 function setBackground(filename)
     local newroot
     if root ~= nil then

Modified: code/branches/menu/src/libraries/core/GUIManager.cc
===================================================================
--- code/branches/menu/src/libraries/core/GUIManager.cc	2009-11-12 10:23:33 UTC (rev 6047)
+++ code/branches/menu/src/libraries/core/GUIManager.cc	2009-11-12 10:32:41 UTC (rev 6048)
@@ -107,6 +107,7 @@
         : renderWindow_(renderWindow)
         , resourceProvider_(0)
         , camera_(NULL)
+        , bShowIngameGUI_(false)
     {
         using namespace CEGUI;
 
@@ -250,11 +251,27 @@
             InputManager::getInstance().leaveState("guiMouseOnly");
         }
     }
+
+    void GUIManager::toggleIngameGUI()
+    {
+        if ( this->bShowIngameGUI_==false )
+        {
+            GUIManager::showGUI("InGameMenu");
+            this->bShowIngameGUI_ = true;
+        }
+        else
+        {
+            GUIManager::hideGUI("InGameMenu");
+            this->bShowIngameGUI_ = false;
+        }
+    }
     
-    void GUIManager::setToggleMode(const bool& mode)
+    void GUIManager::keyESC()
     {
-        this->bToggleMode_ = mode;
-        this->executeCode("setToggleMode(" + multi_cast<std::string>(mode) + ")");
+        if( this->showingGUIs_.size() == 0 )
+            this->showGUI("InGameMenu");
+        else
+            this->executeCode("keyESC()");
     }
     
     void GUIManager::setBackground(const std::string& name)

Modified: code/branches/menu/src/libraries/core/GUIManager.h
===================================================================
--- code/branches/menu/src/libraries/core/GUIManager.h	2009-11-12 10:23:33 UTC (rev 6047)
+++ code/branches/menu/src/libraries/core/GUIManager.h	2009-11-12 10:32:41 UTC (rev 6048)
@@ -70,7 +70,8 @@
         static void showGUI(const std::string& name, bool hidePrevious=false, bool showCursor=true);
         void showGUIExtra(const std::string& name, const std::string& ptr, bool hidePrevious=false, bool showCursor=true);
         static void hideGUI(const std::string& name);
-        void setToggleMode(const bool& mode);
+        void toggleIngameGUI();
+        void keyESC();
         void setBackground(const std::string& name);
 
         void setCamera(Ogre::Camera* camera);
@@ -112,7 +113,7 @@
         Ogre::Camera*                        camera_;           //!< Camera used to render the scene with the GUI
 
         static GUIManager*                   singletonPtr_s;    //!< Singleton reference to GUIManager
-        bool                                 bToggleMode_;
+        bool                                 bShowIngameGUI_;
 
     };
 }

Modified: code/branches/menu/src/libraries/core/Game.cc
===================================================================
--- code/branches/menu/src/libraries/core/Game.cc	2009-11-12 10:23:33 UTC (rev 6047)
+++ code/branches/menu/src/libraries/core/Game.cc	2009-11-12 10:32:41 UTC (rev 6048)
@@ -50,12 +50,16 @@
 #include "ConfigValueIncludes.h"
 #include "GameMode.h"
 #include "GameState.h"
+#include "GUIManager.h"
 
 namespace orxonox
 {
     static void stop_game()
         { Game::getInstance().stop(); }
     SetConsoleCommandShortcutExternAlias(stop_game, "exit");
+    static void key_esc()
+        { Game::getInstance().keyESC(); }
+    SetConsoleCommandShortcutExternAlias(key_esc, "keyESC");
     static void printFPS()
         { COUT(0) << Game::getInstance().getAvgFPS() << std::endl; }
     SetConsoleCommandShortcutExternAlias(printFPS, "printFPS");
@@ -353,6 +357,14 @@
             excessSleepTime_ = 50000;
     }
 
+    void Game::keyESC()
+    {
+        if( this->getState("mainMenu") && this->getState("mainMenu")->getActivity().active==true )
+            this->stop();
+        else
+            GUIManager::getInstance().keyESC();
+    }
+
     void Game::stop()
     {
         this->bAbort_ = true;

Modified: code/branches/menu/src/libraries/core/Game.h
===================================================================
--- code/branches/menu/src/libraries/core/Game.h	2009-11-12 10:23:33 UTC (rev 6047)
+++ code/branches/menu/src/libraries/core/Game.h	2009-11-12 10:32:41 UTC (rev 6048)
@@ -97,6 +97,7 @@
 
         void run();
         void stop();
+        void keyESC();
 
         static Game& getInstance(){ return Singleton<Game>::getInstance(); } // tolua_export
 

Modified: code/branches/menu/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- code/branches/menu/src/orxonox/gamestates/GSLevel.cc	2009-11-12 10:23:33 UTC (rev 6047)
+++ code/branches/menu/src/orxonox/gamestates/GSLevel.cc	2009-11-12 10:32:41 UTC (rev 6048)
@@ -55,6 +55,7 @@
         , guiMouseOnlyInputState_(0)
         , guiKeysOnlyInputState_(0)
         , startFile_(0)
+        , bShowIngameGUI_(false)
     {
     }
 
@@ -77,8 +78,6 @@
 
             guiKeysOnlyInputState_ = InputManager::getInstance().createInputState("guiKeysOnly");
             guiKeysOnlyInputState_->setKeyHandler(GUIManager::getInstancePtr());
-
-            CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSLevel::showIngameGUI, this), "showIngameGUI"));
         }
 
         if (GameMode::isMaster())
@@ -96,18 +95,6 @@
         }
     }
 
-    void GSLevel::showIngameGUI(bool show)
-    {
-        if (show)
-        {
-            GUIManager::showGUI("inGameTest");
-        }
-        else
-        {
-            GUIManager::hideGUI("inGameTest");
-        }
-    }
-
     void GSLevel::deactivate()
     {
         if (GameMode::showsGraphics())

Modified: code/branches/menu/src/orxonox/gamestates/GSLevel.h
===================================================================
--- code/branches/menu/src/orxonox/gamestates/GSLevel.h	2009-11-12 10:23:33 UTC (rev 6047)
+++ code/branches/menu/src/orxonox/gamestates/GSLevel.h	2009-11-12 10:32:41 UTC (rev 6048)
@@ -51,7 +51,6 @@
     protected:
         void loadLevel();
         void unloadLevel();
-        void showIngameGUI(bool show);
 
         InputState*              gameInputState_;          //!< input state for normal ingame playing
         InputState*              guiMouseOnlyInputState_;  //!< input state if we only need the mouse to use the GUI
@@ -59,6 +58,7 @@
 
         XMLFile* startFile_;
         std::set<BaseObject*> staticObjects_;
+        bool bShowIngameGUI_;
     };
 }
 




More information about the Orxonox-commit mailing list