Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 6, 2011, 4:32:05 PM (14 years ago)
Author:
dafrick
Message:

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…

Location:
code/branches/usability
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/usability/data/defaultConfig/keybindings.ini

    r8032 r8035  
    1919KeyDelete="scale 1 rotateRoll"
    2020KeyDivide=
    21 KeyDown="scale -1 moveFrontBack"
     21KeyDown="scale -1 moveFrontBack | navigateGUI down"
    2222KeyE="scale -1 rotateRoll"
    2323KeyEnd=boost
     
    5252KeyKanji=
    5353KeyL=
    54 KeyLeft="scale -1 moveRightLeft"
     54KeyLeft="scale -1 moveRightLeft | navigateGUI left"
    5555KeyLeftAlt=
    5656KeyLeftBracket=
     
    9393KeyNumpadAdd=
    9494KeyNumpadComma=
    95 KeyNumpadEnter=
     95KeyNumpadEnter="navigateGUI enter"
    9696KeyNumpadEquals=
    9797KeyNumpadPeriod=
     
    108108KeyQ="scale 1 rotateRoll"
    109109KeyR="scale 1 moveUpDown"
    110 KeyReturn=
    111 KeyRight="scale 1 moveRightLeft"
     110KeyReturn="navigateGUI enter"
     111KeyRight="scale 1 moveRightLeft | navigateGUI right"
    112112KeyRightAlt=
    113113KeyRightBracket=
     
    126126KeyTab="NewHumanController changeMode"
    127127KeyU=""
    128 KeyUP="scale 1 moveFrontBack"
     128KeyUP="scale 1 moveFrontBack | navigateGUI up"
    129129KeyUnassigned="InGameConsole openConsole"
    130130KeyUnderline=
  • code/branches/usability/data/gui/scripts/GUISheet.lua

    r8028 r8035  
    2929
    3030-- Override this function if you want to react on keystrokes
    31 function P:onKeyPressed()
     31function P:onKeyPressed(mode)
    3232end
    3333
     
    8585
    8686-- Handles key pressed while the gui sheed is displayed
    87 function P:keyPressed()
     87function P:keyPressed(mode)
    8888    if self.buttons then
    89         if code == "208" then     -- key down
     89        if mode == "down" then     -- key down
    9090            self:moveSelectionRow(1)
    91         elseif code == "200" then -- key up
     91        elseif mode == "up" then -- key up
    9292            self:moveSelectionRow(-1)
    93         elseif code == "205" then -- key right
     93        elseif mode == "right" then -- key right
    9494            self:moveSelectionColumn(1)
    95         elseif code == "203" then -- key left
     95        elseif mode == "left" then -- key left
    9696            self:moveSelectionColumn(-1)
    97         elseif code == "28" or code == "156" then -- key enter or key numpad enter
     97        elseif mode == "enter" then -- key enter or key numpad enter
    9898            self:pressSelectedButton()
    9999        end
    100100    end
    101101
    102     self:onKeyPressed()
     102    self:onKeyPressed(mode)
    103103end
    104104
  • code/branches/usability/data/gui/scripts/GraphicsMenu.lua

    r8034 r8035  
    11-- GraphicsMenu.lua
    22
    3 local P = createMenuSheet("GraphicsMenu")
     3local P = createMenuSheet("GraphicsMenu", true, TriBool.True, TriBool.True)
    44
    55P.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"}
  • code/branches/usability/data/gui/scripts/MenuSheet.lua

    r7689 r8035  
    1616    newSheet.bHidePrevious  = handleDefArg(_bHidePrevious,  true)
    1717    newSheet.tShowCursor    = handleDefArg(_tShowCusor,     TriBool.True)
    18     newSheet.tUseKeyboard   = handleDefArg(_tUseKeyboard,   TriBool.True)
     18    newSheet.tUseKeyboard   = handleDefArg(_tUseKeyboard,   TriBool.Dontcare)
    1919    newSheet.bBlockJoyStick = handleDefArg(_bBlockJoyStick, false)
    2020
  • code/branches/usability/data/gui/scripts/SheetManager.lua

    r8033 r8035  
    55local activeMenuSheets = {size = 0, topSheetTuple = nil}
    66local menuSheetsRoot = guiMgr:getMenuRootWindow()
    7 local bInGameConsoleClosed = false
    87local mainMenuLoaded = false
    9 orxonox.GUIManager:subscribeEventHelper(menuSheetsRoot, "KeyDown", "keyPressed")
     8--orxonox.GUIManager:subscribeEventHelper(menuSheetsRoot, "KeyDown", "keyPressed")
    109orxonox.GUIManager:subscribeEventHelper(menuSheetsRoot, "Sized", "windowResized")
    1110
     
    132131    if previous and previous.pressedEnter and menuSheet:hasSelection() == false then
    133132        menuSheet:setSelectionNear(1, 1)
     133    end
     134
     135    if activeMenuSheets.size > 0 then
     136        guiMgr:guisActiveChanged(true)
    134137    end
    135138
     
    204207    end
    205208
     209    if activeMenuSheets.size == 0 then
     210        guiMgr:guisActiveChanged(false)
     211    end
     212
    206213    sheetTuple.sheet:quit()
    207214end
     
    217224    -- HUGE, very HUGE hacks!
    218225
    219     -- If the InGameConsole is active, ignore the ESC command.
    220     if bInGameConsoleClosed == true then
    221         bInGameConsoleClosed = false
    222         return
    223     end
    224 
    225     -- Count the number of sheets that don't need input till the first that does.
     226    -- Count the number of sheets that don't need input until the first that does.
    226227    local counter = noInputSheetIndex()
    227228
     
    237238end
    238239
    239 function keyPressed(e)
    240     local we = tolua.cast(e, "CEGUI::KeyEventArgs")
     240-- Function to navigate the GUI, is called by the GUIManager, whenever a relevant key is pressed.
     241-- The mode specifies the action to be taken.
     242function navigateGUI(mode)
    241243    local sheet = activeMenuSheets[activeMenuSheets.size]
    242     code = tostring(we.scancode)
    243     -- Some preprocessing
    244     if not mainMenuLoaded and not sheet.bNoInput then
    245         if code == "1" then
    246             keyESC()
    247         elseif code == "0"then
    248             orxonox.CommandExecutor:execute("InGameConsole openConsole")
    249         end
    250     end
    251     sheet.sheet:keyPressed()
     244    sheet.sheet:keyPressed(mode)
    252245end
    253246
     
    293286    end
    294287    return counter
    295 end
    296 
    297 function inGameConsoleClosed()
    298     bInGameConsoleClosed = not bInGameConsoleClosed;
    299288end
    300289
  • code/branches/usability/src/libraries/core/GUIManager.cc

    r8033 r8035  
    103103    /*static*/ const std::string GUIManager::defaultScheme_ = "TaharezGreen";
    104104
     105    static const std::string __CC_navigateGUI_name = "navigateGUI";
     106
    105107    SetConsoleCommand("showGUI", &GUIManager::showGUI).defaultValue(1, false).defaultValue(2, false);
    106108    SetConsoleCommand("hideGUI", &GUIManager::hideGUI);
    107109    SetConsoleCommand("toggleGUI", &GUIManager::toggleGUI).defaultValue(1, false).defaultValue(2, false);
     110    SetConsoleCommand(__CC_navigateGUI_name, &GUIManager::navigateGUI).deactivate();
     111
     112    //! Strings that specify modes for the GUI navigation.
     113    /*static*/ const std::string GUIManager::NAVIGATE_UP = "up";
     114    /*static*/ const std::string GUIManager::NAVIGATE_DOWN = "down";
     115    /*static*/ const std::string GUIManager::NAVIGATE_LEFT = "left";
     116    /*static*/ const std::string GUIManager::NAVIGATE_RIGHT = "right";
     117    /*static*/ const std::string GUIManager::NAVIGATE_ENTER = "enter";
    108118
    109119    /**
     
    364374            this->rootWindow_->setProperty("Alpha", "1.0");
    365375        this->rootWindow_->setProperty("Image", image);
     376    }
     377
     378    /**
     379    @brief
     380        Method to navigate the GUI, by specifying the mode of navigation.
     381    @param mode
     382        The mode of navigation, at this point can be either 'up', 'down', 'left', 'right' or 'enter'.
     383    */
     384    /*static*/ void GUIManager::navigateGUI(const std::string& mode)
     385    {
     386        if(mode == NAVIGATE_UP)
     387            GUIManager::getInstance().executeCode("navigateGUI(\"" + NAVIGATE_UP + "\")");
     388        else if(mode == NAVIGATE_DOWN)
     389            GUIManager::getInstance().executeCode("navigateGUI(\"" + NAVIGATE_DOWN + "\")");
     390        else if(mode == NAVIGATE_LEFT)
     391            GUIManager::getInstance().executeCode("navigateGUI(\"" + NAVIGATE_LEFT + "\")");
     392        else if(mode == NAVIGATE_RIGHT)
     393            GUIManager::getInstance().executeCode("navigateGUI(\"" + NAVIGATE_RIGHT + "\")");
     394        else if(mode == NAVIGATE_ENTER)
     395            GUIManager::getInstance().executeCode("navigateGUI(\"" + NAVIGATE_ENTER + "\")");
     396    }
     397
     398    /**
     399    @brief
     400        Is called by lua to change whether there are any GUIs active at the moment.
     401    @param active
     402        Whether GUIs are active.
     403    */
     404    void GUIManager::guisActiveChanged(bool active)
     405    {
     406        if(this->GUIsActive_ == active)
     407            return;
     408        this->GUIsActive_ = active;
     409        if(this->GUIsActive_)
     410            ModifyConsoleCommand(__CC_navigateGUI_name).activate();
     411        else
     412            ModifyConsoleCommand(__CC_navigateGUI_name).deactivate();
    366413    }
    367414
  • code/branches/usability/src/libraries/core/GUIManager.h

    r8033 r8035  
    9494        void setBackgroundImage(const std::string& image);
    9595
     96        static void navigateGUI(const std::string& mode);
     97        void guisActiveChanged(bool active); // tolua_export
     98
    9699        //! Creates a new InputState to be used with a GUI Sheet
    97100        const std::string& createInputState(const std::string& name, TriBool::Value showCursor = TriBool::True, TriBool::Value useKeyboard = TriBool::True, bool bBlockJoyStick = false); // tolua_export
     
    124127        template <typename FunctionType>
    125128        bool protectedCall(FunctionType function);
     129
     130        static const std::string NAVIGATE_UP;
     131        static const std::string NAVIGATE_DOWN;
     132        static const std::string NAVIGATE_LEFT;
     133        static const std::string NAVIGATE_RIGHT;
     134        static const std::string NAVIGATE_ENTER;
     135
     136        bool GUIsActive_; //!< Whether there are any GUIs active at a given moment.
    126137
    127138        // keyHandler functions
  • code/branches/usability/src/orxonox/gamestates/GSMainMenu.cc

    r7978 r8035  
    6868        RegisterRootObject(GSMainMenu);
    6969
    70         InputManager::getInstance().createInputState("MainMenuHackery", true, true)->setKeyHandler(KeyBinderManager::getInstance().getDefaultAsHandler());
     70        InputManager::getInstance().createInputState("MainMenuHackery")->setKeyHandler(KeyBinderManager::getInstance().getDefaultAsHandler());
    7171
    7272        // create an empty Scene
  • code/branches/usability/src/orxonox/overlays/InGameConsole.cc

    r8032 r8035  
    4949#include "core/ConfigValueIncludes.h"
    5050#include "core/command/ConsoleCommand.h"
    51 #include "core/GUIManager.h"
    5251#include "core/input/InputManager.h"
    5352#include "core/input/InputState.h"
     
    534533        {
    535534            this->bActive_ = false;
    536             GUIManager::getInstance().getLuaState()->doString("inGameConsoleClosed()"); // Notify the SheetManager in lua, that the console has been closed.
    537535            InputManager::getInstance().leaveState("console");
    538536            this->shell_->unregisterListener(this);
     
    611609    /*static*/ void InGameConsole::closeConsole()
    612610    {
    613         GUIManager::getInstance().getLuaState()->doString("inGameConsoleClosed()");  // Notify the SheetManager in lua, that the console has been closed, but not by ESC.
    614611        InGameConsole::getInstance().deactivate();
    615612    }
Note: See TracChangeset for help on using the changeset viewer.