[Orxonox-commit 3347] r8035 - in code/branches/usability: data/defaultConfig data/gui/scripts src/libraries/core src/orxonox/gamestates src/orxonox/overlays

dafrick at orxonox.net dafrick at orxonox.net
Sun Mar 6 16:32:06 CET 2011


Author: dafrick
Date: 2011-03-06 16:32:05 +0100 (Sun, 06 Mar 2011)
New Revision: 8035

Modified:
   code/branches/usability/data/defaultConfig/keybindings.ini
   code/branches/usability/data/gui/scripts/GUISheet.lua
   code/branches/usability/data/gui/scripts/GraphicsMenu.lua
   code/branches/usability/data/gui/scripts/MenuSheet.lua
   code/branches/usability/data/gui/scripts/SheetManager.lua
   code/branches/usability/src/libraries/core/GUIManager.cc
   code/branches/usability/src/libraries/core/GUIManager.h
   code/branches/usability/src/orxonox/gamestates/GSMainMenu.cc
   code/branches/usability/src/orxonox/overlays/InGameConsole.cc
Log:
Replacing hard coded keys for the menu navigation with keys specified in the keybindings.ini file (note: You have to delete your keybindings.ini file for it to be regenerated and work correctly).
The upside is, that now we need less hackish, stuff, it's better integrated, toggling of OrxonoxOverlays (e.g. QuestGUI and PickupInventory, among others) is working again. Closing the InGameConsole with ESC no longer requires a workaround to work.
The downside is, that now GUI sheets that require input, e.g. GraphicsMenu or MiscConfigMenu, no longer support menu navigation and ESC doesn't work there.  However, I don't know how to work around that, yet. But since all that ESC business is a hack anyway, I'd rather have the hacks there...


Modified: code/branches/usability/data/defaultConfig/keybindings.ini
===================================================================
--- code/branches/usability/data/defaultConfig/keybindings.ini	2011-03-06 14:29:16 UTC (rev 8034)
+++ code/branches/usability/data/defaultConfig/keybindings.ini	2011-03-06 15:32:05 UTC (rev 8035)
@@ -18,7 +18,7 @@
 KeyD="scale 1 moveRightLeft"
 KeyDelete="scale 1 rotateRoll"
 KeyDivide=
-KeyDown="scale -1 moveFrontBack"
+KeyDown="scale -1 moveFrontBack | navigateGUI down"
 KeyE="scale -1 rotateRoll"
 KeyEnd=boost
 KeyEquals=
@@ -51,7 +51,7 @@
 KeyKana=
 KeyKanji=
 KeyL=
-KeyLeft="scale -1 moveRightLeft"
+KeyLeft="scale -1 moveRightLeft | navigateGUI left"
 KeyLeftAlt=
 KeyLeftBracket=
 KeyLeftControl=mouseLook
@@ -92,7 +92,7 @@
 KeyNumpad9=
 KeyNumpadAdd=
 KeyNumpadComma=
-KeyNumpadEnter=
+KeyNumpadEnter="navigateGUI enter"
 KeyNumpadEquals=
 KeyNumpadPeriod=
 KeyNumpadSubtract=
@@ -107,8 +107,8 @@
 KeyPreviousTrack=
 KeyQ="scale 1 rotateRoll"
 KeyR="scale 1 moveUpDown"
-KeyReturn=
-KeyRight="scale 1 moveRightLeft"
+KeyReturn="navigateGUI enter"
+KeyRight="scale 1 moveRightLeft | navigateGUI right"
 KeyRightAlt=
 KeyRightBracket=
 KeyRightControl="scale -1 moveUpDown"
@@ -125,7 +125,7 @@
 KeyT="onpress fire 3"
 KeyTab="NewHumanController changeMode"
 KeyU=""
-KeyUP="scale 1 moveFrontBack"
+KeyUP="scale 1 moveFrontBack | navigateGUI up"
 KeyUnassigned="InGameConsole openConsole"
 KeyUnderline=
 KeyUnlabeled=

Modified: code/branches/usability/data/gui/scripts/GUISheet.lua
===================================================================
--- code/branches/usability/data/gui/scripts/GUISheet.lua	2011-03-06 14:29:16 UTC (rev 8034)
+++ code/branches/usability/data/gui/scripts/GUISheet.lua	2011-03-06 15:32:05 UTC (rev 8035)
@@ -28,7 +28,7 @@
 end
 
 -- Override this function if you want to react on keystrokes
-function P:onKeyPressed()
+function P:onKeyPressed(mode)
 end
 
 -- Override this function if you want to update the gui after the window was resized
@@ -84,22 +84,22 @@
 end
 
 -- Handles key pressed while the gui sheed is displayed
-function P:keyPressed()
+function P:keyPressed(mode)
     if self.buttons then
-        if code == "208" then     -- key down
+        if mode == "down" then     -- key down
             self:moveSelectionRow(1)
-        elseif code == "200" then -- key up
+        elseif mode == "up" then -- key up
             self:moveSelectionRow(-1)
-        elseif code == "205" then -- key right
+        elseif mode == "right" then -- key right
             self:moveSelectionColumn(1)
-        elseif code == "203" then -- key left
+        elseif mode == "left" then -- key left
             self:moveSelectionColumn(-1)
-        elseif code == "28" or code == "156"  then -- key enter or key numpad enter
+        elseif mode == "enter" then -- key enter or key numpad enter
             self:pressSelectedButton()
         end
     end
 
-    self:onKeyPressed()
+    self:onKeyPressed(mode)
 end
 
 function P:windowResized()

Modified: code/branches/usability/data/gui/scripts/GraphicsMenu.lua
===================================================================
--- code/branches/usability/data/gui/scripts/GraphicsMenu.lua	2011-03-06 14:29:16 UTC (rev 8034)
+++ code/branches/usability/data/gui/scripts/GraphicsMenu.lua	2011-03-06 15:32:05 UTC (rev 8035)
@@ -1,6 +1,6 @@
 -- GraphicsMenu.lua
 
-local P = createMenuSheet("GraphicsMenu")
+local P = createMenuSheet("GraphicsMenu", true, TriBool.True, TriBool.True)
 
 P.resolutionList = {"custom", "640 x 480", "720 x 480", "720 x 576", "800 x 600", "1024 x 600", "1024 x 768", "1152 x 864", "1280 x 720", "1280 x 800", "1280 x 960", "1280 x 1024", "1360 x 768", "1440 x 900", "1600 x 900", "1600 x 1200", "1680 x 1050"}
 P.schemeList = {"TaharezGreen", "Orxonox"}

Modified: code/branches/usability/data/gui/scripts/MenuSheet.lua
===================================================================
--- code/branches/usability/data/gui/scripts/MenuSheet.lua	2011-03-06 14:29:16 UTC (rev 8034)
+++ code/branches/usability/data/gui/scripts/MenuSheet.lua	2011-03-06 15:32:05 UTC (rev 8035)
@@ -15,7 +15,7 @@
     local newSheet = GUISheet.new(_name)
     newSheet.bHidePrevious  = handleDefArg(_bHidePrevious,  true)
     newSheet.tShowCursor    = handleDefArg(_tShowCusor,     TriBool.True)
-    newSheet.tUseKeyboard   = handleDefArg(_tUseKeyboard,   TriBool.True)
+    newSheet.tUseKeyboard   = handleDefArg(_tUseKeyboard,   TriBool.Dontcare)
     newSheet.bBlockJoyStick = handleDefArg(_bBlockJoyStick, false)
 
     setmetatable(newSheet, P)

Modified: code/branches/usability/data/gui/scripts/SheetManager.lua
===================================================================
--- code/branches/usability/data/gui/scripts/SheetManager.lua	2011-03-06 14:29:16 UTC (rev 8034)
+++ code/branches/usability/data/gui/scripts/SheetManager.lua	2011-03-06 15:32:05 UTC (rev 8035)
@@ -4,9 +4,8 @@
 local loadedSheets = {}
 local activeMenuSheets = {size = 0, topSheetTuple = nil}
 local menuSheetsRoot = guiMgr:getMenuRootWindow()
-local bInGameConsoleClosed = false
 local mainMenuLoaded = false
-orxonox.GUIManager:subscribeEventHelper(menuSheetsRoot, "KeyDown", "keyPressed")
+--orxonox.GUIManager:subscribeEventHelper(menuSheetsRoot, "KeyDown", "keyPressed")
 orxonox.GUIManager:subscribeEventHelper(menuSheetsRoot, "Sized", "windowResized")
 
 ------------------------
@@ -133,6 +132,10 @@
         menuSheet:setSelectionNear(1, 1)
     end
 
+    if activeMenuSheets.size > 0 then
+        guiMgr:guisActiveChanged(true)
+    end
+
     return menuSheet
 end
 
@@ -203,6 +206,10 @@
         hideCursor()
     end
 
+    if activeMenuSheets.size == 0 then
+        guiMgr:guisActiveChanged(false)
+    end
+
     sheetTuple.sheet:quit()
 end
 
@@ -216,13 +223,7 @@
 function keyESC()
     -- HUGE, very HUGE hacks!
 
-    -- If the InGameConsole is active, ignore the ESC command.
-    if bInGameConsoleClosed == true then
-        bInGameConsoleClosed = false
-        return
-    end
-
-    -- Count the number of sheets that don't need input till the first that does.
+    -- Count the number of sheets that don't need input until the first that does.
     local counter = noInputSheetIndex()
 
     -- If the first sheet that needs input is the MainMenu.
@@ -236,19 +237,11 @@
     end
 end
 
-function keyPressed(e)
-    local we = tolua.cast(e, "CEGUI::KeyEventArgs")
+-- Function to navigate the GUI, is called by the GUIManager, whenever a relevant key is pressed.
+-- The mode specifies the action to be taken.
+function navigateGUI(mode)
     local sheet = activeMenuSheets[activeMenuSheets.size]
-    code = tostring(we.scancode)
-    -- Some preprocessing
-    if not mainMenuLoaded and not sheet.bNoInput then
-        if code == "1" then
-            keyESC()
-        elseif code == "0"then
-            orxonox.CommandExecutor:execute("InGameConsole openConsole")
-        end
-    end
-    sheet.sheet:keyPressed()
+    sheet.sheet:keyPressed(mode)
 end
 
 function windowResized(e)
@@ -294,10 +287,6 @@
     return counter
 end
 
-function inGameConsoleClosed()
-    bInGameConsoleClosed = not bInGameConsoleClosed;
-end
-
 function getGUIFirstActive(name, bHidePrevious, bNoInput)
     local sheet = activeMenuSheets.topSheetTuple
     -- If the topmost gui sheet has the input name

Modified: code/branches/usability/src/libraries/core/GUIManager.cc
===================================================================
--- code/branches/usability/src/libraries/core/GUIManager.cc	2011-03-06 14:29:16 UTC (rev 8034)
+++ code/branches/usability/src/libraries/core/GUIManager.cc	2011-03-06 15:32:05 UTC (rev 8035)
@@ -102,10 +102,20 @@
     GUIManager* GUIManager::singletonPtr_s = 0;
     /*static*/ const std::string GUIManager::defaultScheme_ = "TaharezGreen";
 
+    static const std::string __CC_navigateGUI_name = "navigateGUI";
+
     SetConsoleCommand("showGUI", &GUIManager::showGUI).defaultValue(1, false).defaultValue(2, false);
     SetConsoleCommand("hideGUI", &GUIManager::hideGUI);
     SetConsoleCommand("toggleGUI", &GUIManager::toggleGUI).defaultValue(1, false).defaultValue(2, false);
+    SetConsoleCommand(__CC_navigateGUI_name, &GUIManager::navigateGUI).deactivate();
 
+    //! Strings that specify modes for the GUI navigation.
+    /*static*/ const std::string GUIManager::NAVIGATE_UP = "up";
+    /*static*/ const std::string GUIManager::NAVIGATE_DOWN = "down";
+    /*static*/ const std::string GUIManager::NAVIGATE_LEFT = "left";
+    /*static*/ const std::string GUIManager::NAVIGATE_RIGHT = "right";
+    /*static*/ const std::string GUIManager::NAVIGATE_ENTER = "enter";
+
     /**
     @brief
         Constructs the GUIManager by starting up CEGUI
@@ -365,6 +375,43 @@
         this->rootWindow_->setProperty("Image", image);
     }
 
+    /**
+    @brief
+        Method to navigate the GUI, by specifying the mode of navigation.
+    @param mode
+        The mode of navigation, at this point can be either 'up', 'down', 'left', 'right' or 'enter'.
+    */
+    /*static*/ void GUIManager::navigateGUI(const std::string& mode)
+    {
+        if(mode == NAVIGATE_UP)
+            GUIManager::getInstance().executeCode("navigateGUI(\"" + NAVIGATE_UP + "\")");
+        else if(mode == NAVIGATE_DOWN)
+            GUIManager::getInstance().executeCode("navigateGUI(\"" + NAVIGATE_DOWN + "\")");
+        else if(mode == NAVIGATE_LEFT)
+            GUIManager::getInstance().executeCode("navigateGUI(\"" + NAVIGATE_LEFT + "\")");
+        else if(mode == NAVIGATE_RIGHT)
+            GUIManager::getInstance().executeCode("navigateGUI(\"" + NAVIGATE_RIGHT + "\")");
+        else if(mode == NAVIGATE_ENTER)
+            GUIManager::getInstance().executeCode("navigateGUI(\"" + NAVIGATE_ENTER + "\")");
+    }
+
+    /**
+    @brief
+        Is called by lua to change whether there are any GUIs active at the moment.
+    @param active
+        Whether GUIs are active.
+    */
+    void GUIManager::guisActiveChanged(bool active)
+    {
+        if(this->GUIsActive_ == active)
+            return;
+        this->GUIsActive_ = active;
+        if(this->GUIsActive_)
+            ModifyConsoleCommand(__CC_navigateGUI_name).activate();
+        else
+            ModifyConsoleCommand(__CC_navigateGUI_name).deactivate();
+    }
+
     void GUIManager::buttonPressed(const KeyEvent& evt)
     {
         this->protectedCall(boost::bind(&CEGUI::System::injectKeyDown, _1, evt.getKeyCode()));

Modified: code/branches/usability/src/libraries/core/GUIManager.h
===================================================================
--- code/branches/usability/src/libraries/core/GUIManager.h	2011-03-06 14:29:16 UTC (rev 8034)
+++ code/branches/usability/src/libraries/core/GUIManager.h	2011-03-06 15:32:05 UTC (rev 8035)
@@ -93,6 +93,9 @@
         void setBackgroundImage(const std::string& imageSet, const std::string imageName); // tolua_export
         void setBackgroundImage(const std::string& image);
 
+        static void navigateGUI(const std::string& mode);
+        void guisActiveChanged(bool active); // tolua_export
+
         //! Creates a new InputState to be used with a GUI Sheet
         const std::string& createInputState(const std::string& name, TriBool::Value showCursor = TriBool::True, TriBool::Value useKeyboard = TriBool::True, bool bBlockJoyStick = false); // tolua_export
         LuaState* getLuaState(void)
@@ -124,6 +127,14 @@
         template <typename FunctionType>
         bool protectedCall(FunctionType function);
 
+        static const std::string NAVIGATE_UP;
+        static const std::string NAVIGATE_DOWN;
+        static const std::string NAVIGATE_LEFT;
+        static const std::string NAVIGATE_RIGHT;
+        static const std::string NAVIGATE_ENTER;
+
+        bool GUIsActive_; //!< Whether there are any GUIs active at a given moment.
+
         // keyHandler functions
         void buttonPressed (const KeyEvent& evt);
         void buttonReleased(const KeyEvent& evt);

Modified: code/branches/usability/src/orxonox/gamestates/GSMainMenu.cc
===================================================================
--- code/branches/usability/src/orxonox/gamestates/GSMainMenu.cc	2011-03-06 14:29:16 UTC (rev 8034)
+++ code/branches/usability/src/orxonox/gamestates/GSMainMenu.cc	2011-03-06 15:32:05 UTC (rev 8035)
@@ -67,7 +67,7 @@
     {
         RegisterRootObject(GSMainMenu);
 
-        InputManager::getInstance().createInputState("MainMenuHackery", true, true)->setKeyHandler(KeyBinderManager::getInstance().getDefaultAsHandler());
+        InputManager::getInstance().createInputState("MainMenuHackery")->setKeyHandler(KeyBinderManager::getInstance().getDefaultAsHandler());
 
         // create an empty Scene
         this->scene_ = new Scene(NULL);

Modified: code/branches/usability/src/orxonox/overlays/InGameConsole.cc
===================================================================
--- code/branches/usability/src/orxonox/overlays/InGameConsole.cc	2011-03-06 14:29:16 UTC (rev 8034)
+++ code/branches/usability/src/orxonox/overlays/InGameConsole.cc	2011-03-06 15:32:05 UTC (rev 8035)
@@ -48,7 +48,6 @@
 #include "core/CoreIncludes.h"
 #include "core/ConfigValueIncludes.h"
 #include "core/command/ConsoleCommand.h"
-#include "core/GUIManager.h"
 #include "core/input/InputManager.h"
 #include "core/input/InputState.h"
 #include "core/input/InputBuffer.h"
@@ -533,7 +532,6 @@
         if (this->bActive_)
         {
             this->bActive_ = false;
-            GUIManager::getInstance().getLuaState()->doString("inGameConsoleClosed()"); // Notify the SheetManager in lua, that the console has been closed.
             InputManager::getInstance().leaveState("console");
             this->shell_->unregisterListener(this);
 
@@ -610,7 +608,6 @@
     */
     /*static*/ void InGameConsole::closeConsole()
     {
-        GUIManager::getInstance().getLuaState()->doString("inGameConsoleClosed()");  // Notify the SheetManager in lua, that the console has been closed, but not by ESC.
         InGameConsole::getInstance().deactivate();
     }
 




More information about the Orxonox-commit mailing list