Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 9, 2009, 11:17:14 PM (15 years ago)
Author:
dafrick
Message:

The KeyBindMenu now shows all Keybindings and allows for various manipulations.
For this the bookkeeping in KeyBinder has ben improved.
Also KeyEscape now can't be bound to other commands.

Location:
code/branches/presentation2
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/data/gui/layouts/KeyBindMenu.layout

    r6292 r6311  
    11<?xml version="1.0" encoding="UTF-8"?>
    22
    3 
    43<GUILayout >
    5 
    64    <Window Type="DefaultWindow" Name="orxonox/KeyBindMenu/Background" >
    7 
    85        <Property Name="InheritsAlpha" Value="False" />
    9 
    106        <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
    11 
    127        <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{1,0}}" />
    13 
    148        <Window Type="TaharezLook/StaticText" Name="orxonox/KeyBindWindow" >
    15 
    169            <Property Name="Text" Value="Keybindings" />
    17 
    1810            <Property Name="Alpha" Value="0.8" />
    19 
    2011            <Property Name="InheritsAlpha" Value="False" />
    21 
    2212            <Property Name="HorzFormatting" Value="HorzCentred" />
    23 
    2413            <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
    25 
    2614            <Property Name="VertFormatting" Value="TopAligned" />
    2715            <Property Name="UnifiedAreaRect" Value="{{0.2,0},{0.25,0},{0.8,0},{0.6,0}}" />
    28 
    2916            <Window Type="TaharezLook/StaticText" Name="orxonox/KeyBindText" >
    3017                <Property Name="TextColours" Value="FF4444FF" />
     
    3522                <Property Name="UnifiedAreaRect" Value="{{0.041666,0},{0.15,0},{0.958333,0},{0.92,0}}" />
    3623                <Window Type="TaharezLook/ScrollablePane" Name="orxonox/KeyBindPane" >
    37 
    3824                    <Property Name="ContentArea" Value="l:0 t:0 r:0 b:0" />
    39 
    4025                    <Property Name="HorzStepSize" Value="0.1" />
    41 
    4226                    <Property Name="VertStepSize" Value="0.1" />
    43 
    4427                    <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
    4528                    <Property Name="HorzOverlapSize" Value="0.01" />
    46 
    4729                    <Property Name="UnifiedAreaRect" Value="{{0.04,0},{0.005,0},{0.999,0},{0.99,0}}" />
    48 
    4930                    <Property Name="VertOverlapSize" Value="0.01" />
    50 
    5131                    <Property Name="HorzScrollPosition" Value="0" />
    52 
    5332                    <Property Name="VertScrollPosition" Value="0" />
    54 
    5533                </Window>
    56 
    5734            </Window>
    5835        </Window>
    59 
    6036        <Window Type="TaharezLook/Button" Name="orxonox/KeyBindBackButton" >
    61 
    6237            <Property Name="Text" Value="Back" />
    63 
    6438            <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
    65 
    6639            <Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.625,0},{0.6,0},{0.675,0}}" />
    67 
    6840            <Event Name="Clicked" Function="KeyBindMenu.KeyBindBackButton_clicked"/>
    69 
    7041        </Window>
    71 
    7242    </Window>
    73 
    7443</GUILayout>
  • code/branches/presentation2/data/gui/scripts/GUITools.lua

    r6283 r6311  
    55end
    66
    7 function openInfoPopup(text, functionPtr, closeButton)
     7function openInfoPopup(text, functionPtr, closeButton, arguments)
    88    showGUI("InfoPopup", false, true)
    9     InfoPopup.execute(functionPtr)
     9    InfoPopup.execute(functionPtr, arguments)
    1010    InfoPopup.setText(text)
    1111    InfoPopup.setCloseButton(closeButton)
  • code/branches/presentation2/data/gui/scripts/InfoPopup.lua

    r6283 r6311  
    1515end
    1616
    17 function P.execute(functionPtr)
     17function P.execute(functionPtr, arguments)
    1818    if functionPtr ~= nil then
    19         functionPtr()
     19        if arguments ~= nil then
     20            functionPtr(arguments)
     21        else
     22            functionPtr()
     23        end
    2024    end
    2125end
  • code/branches/presentation2/data/gui/scripts/KeyBindMenu.lua

    r6292 r6311  
    5252    table.insert(nameList, "Look Around")
    5353    table.insert(nameList, "Pause")
     54   
     55    linesList = {}
    5456
    55     local lineHeight = 30
     57    lineHeight = 35
     58    buttonWidth = 170
     59    clearWidth = 20
    5660   
    5761    local window = winMgr:getWindow("orxonox/KeyBindPane")
    5862
    5963    for k,v in pairs(commandList) do
    60         local line = winMgr:createWindow("DefaultWindow", "orxonox/KeyBindPane/Binding" .. k)
    61         local command = winMgr:createWindow("TaharezLook/StaticText", "orxonox/KeyBindPane/Binding" .. k .. "/Command")
    62         local button = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Button")
    63         local clear = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Clear")
    64         local button2 = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Button2")
    65         local clear2 = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Clear2")
    66         local add = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Add")
    67        
    68         line:setSize(CEGUI.UVector2(CEGUI.UDim(1, -13), CEGUI.UDim(0, lineHeight)))
    69         command:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(1, 0)))
    70         button:setSize(CEGUI.UVector2(CEGUI.UDim(0.25, 0), CEGUI.UDim(0.6, 0)))
    71         clear:setSize(CEGUI.UVector2(CEGUI.UDim(0.05, 0), CEGUI.UDim(0.6, 0)))
    72         button2:setSize(CEGUI.UVector2(CEGUI.UDim(0.25, 0), CEGUI.UDim(0.6, 0)))
    73         clear2:setSize(CEGUI.UVector2(CEGUI.UDim(0.05, 0), CEGUI.UDim(0.6, 0)))
    74         add:setSize(CEGUI.UVector2(CEGUI.UDim(0.05, 0), CEGUI.UDim(0.6, 0)))
    75        
    76         line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, lineHeight*(k-1))))       
    77         command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
    78         button:setPosition(CEGUI.UVector2(CEGUI.UDim(0.25, 0), CEGUI.UDim(0.2, 0)))
    79         clear:setPosition(CEGUI.UVector2(CEGUI.UDim(0.5, 0), CEGUI.UDim(0.2, 0)))
    80         button2:setPosition(CEGUI.UVector2(CEGUI.UDim(0.6, 0), CEGUI.UDim(0.2, 0)))
    81         clear2:setPosition(CEGUI.UVector2(CEGUI.UDim(0.85, 0), CEGUI.UDim(0.2, 0)))
    82         add:setPosition(CEGUI.UVector2(CEGUI.UDim(0.925, 0), CEGUI.UDim(0.2, 0)))
    83        
    84         command:setText(nameList[k])
    85         button:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(v))
    86         clear:setText("X")
    87         button2:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(v))
    88         clear2:setText("X")
    89         add:setText("+")
    90 
    91         orxonox.KeyBinderManager:getInstance():subscribeEventHelper(button, "Clicked", P.filename .. ".KeyBindButton_clicked")
    92         orxonox.KeyBinderManager:getInstance():subscribeEventHelper(clear, "Clicked", P.filename .. ".KeyBindClear_clicked")
    93         orxonox.KeyBinderManager:getInstance():subscribeEventHelper(add, "Clicked", P.filename .. ".KeyBindAdd_clicked")
    94         --button:subscribeScriptedEvent("EventClicked", P.filename .. ".KeyBindButton_clicked")
    95        
    96         line:addChildWindow(command)
    97         line:addChildWindow(button)
    98         line:addChildWindow(clear)
    99         line:addChildWindow(button2)
    100         line:addChildWindow(clear2)
    101         line:addChildWindow(add)
     64        local line = P.createLine(k)
     65        table.insert(linesList, line)
    10266        window:addChildWindow(line)
    10367    end
     68   
     69    local funct = luaState:createLuaFunctor("KeyBindMenu.callback()")
     70    orxonox.KeyBinderManager:getInstance():registerKeybindCallback(funct)
     71end
     72
     73function P.createLine(k)
     74    local line = winMgr:createWindow("DefaultWindow", "orxonox/KeyBindPane/Binding" .. k)
     75    line:setHeight(CEGUI.UDim(0, lineHeight))
     76    line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, lineHeight*(k-1))))
     77   
     78    local command = winMgr:createWindow("TaharezLook/StaticText", "orxonox/KeyBindPane/Binding" .. k .. "/Command")
     79    command:setSize(CEGUI.UVector2(CEGUI.UDim(0, 200), CEGUI.UDim(1, 0)))
     80    command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
     81    command:setText(nameList[k])
     82    line:addChildWindow(command)
     83   
     84    local plus = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Plus")
     85    plus:setSize(CEGUI.UVector2(CEGUI.UDim(0, clearWidth), CEGUI.UDim(1, 0)))
     86    plus:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 200), CEGUI.UDim(0, 0)))
     87    plus:setText("+")
     88    orxonox.KeyBinderManager:getInstance():subscribeEventHelper(plus, "Clicked", P.filename .. ".KeyBindPlus_clicked")
     89    line:addChildWindow(plus)
     90   
     91    numButtons = orxonox.KeyBinderManager:getInstance():getCurrent():getNumberOfBindings(commandList[k]);
     92    for i=0,(numButtons-1) do
     93        local button = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Button" .. i)
     94        button:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0.8, 0)))
     95        button:setPosition(CEGUI.UVector2(CEGUI.UDim(0, (i*(buttonWidth+clearWidth))+200+clearWidth), CEGUI.UDim(0.1, 0)))
     96        button:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[k],i))
     97        orxonox.KeyBinderManager:getInstance():subscribeEventHelper(button, "Clicked", P.filename .. ".KeyBindButton_clicked")
     98        --button:subscribeScriptedEvent("EventClicked", P.filename .. ".KeyBindButton_clicked")
     99        line:addChildWindow(button)
     100       
     101        local clear = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Clear" .. i)
     102        clear:setSize(CEGUI.UVector2(CEGUI.UDim(0, clearWidth), CEGUI.UDim(0.8, 0)))
     103        clear:setPosition(CEGUI.UVector2(CEGUI.UDim(0, (i*(buttonWidth+clearWidth)+buttonWidth)+200+clearWidth), CEGUI.UDim(0.1, 0)))
     104        clear:setText("X")
     105        orxonox.KeyBinderManager:getInstance():subscribeEventHelper(clear, "Clicked", P.filename .. ".KeyBindClear_clicked")
     106        line:addChildWindow(clear)
     107    end
     108   
     109    line:setWidth(CEGUI.UDim(0, 200+numButtons*(buttonWidth+clearWidth)+clearWidth))
     110   
     111    return line
    104112end
    105113
     
    107115    local we = CEGUI.toWindowEventArgs(e)
    108116    local name = we.window:getName()
    109     buttonNr = tonumber(string.match(name, "%d+"))
    110     openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind)
     117
     118    local match = string.gmatch(name, "%d+")
     119    local commandNr = tonumber(match())
     120    local buttonNr = tonumber(match())
     121   
     122    local arguments = {}
     123    arguments[1] = commandNr
     124    arguments[2] = buttonNr
     125    openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind, false, arguments)
     126end
     127
     128function P.KeyBindPlus_clicked(e)
     129    local we = CEGUI.toWindowEventArgs(e)
     130    local name = we.window:getName()
     131   
     132    local match = string.gmatch(name, "%d+")
     133    local commandNr = tonumber(match())
     134   
     135    local arguments = {}
     136    arguments[1] = commandNr
     137    openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind, false, arguments)
    111138end
    112139
     
    114141    local we = CEGUI.toWindowEventArgs(e)
    115142    local name = we.window:getName()
    116     clearNr = tonumber(string.match(name, "%d+"))
     143   
     144    local match = string.gmatch(name, "%d+")
     145    local commandNr = tonumber(match())
     146    local buttonNr = tonumber(match())
     147   
     148    orxonox.KeyBinderManager:getInstance():unbind(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[commandNr], buttonNr))
     149   
     150    P.callback()
    117151end
    118152
    119 function P.KeyBindAdd_clicked(e)
    120    
     153function P.keybind(arguments)
     154    local commandNr = arguments[1]
     155    local buttonNr = arguments[2]
     156    if buttonNr ~= nil then
     157        orxonox.KeyBinderManager:getInstance():unbind(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[commandNr], buttonNr))
     158    end
     159    orxonox.KeyBinderManager:getInstance():keybind(commandList[commandNr])
    121160end
    122161
    123 function P.keybind()
    124     local funct = luaState:createLuaFunctor("KeyBindMenu.callback(" .. buttonNr ..")")
    125     orxonox.KeyBinderManager:getInstance():registerKeybindCallback(funct)
    126     orxonox.KeyBinderManager:getInstance():keybind(commandList[buttonNr])
    127 end
     162function P.callback()
     163    while table.getn(linesList) ~= 0 do
     164        if linesList[1] ~= nil then
     165            winMgr:destroyWindow(linesList[1]:getName())
     166        end
     167        table.remove(linesList, 1)
     168    end
     169   
     170    linesList = {}
    128171
    129 function P.callback(number)
    130     orxonox.KeyBinderManager:getInstance():registerKeybindCallback(nil)
    131     local button = winMgr:getWindow("orxonox/KeyBindPane/Binding" .. number .. "/Button")
    132     button:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[number]))
     172    window = winMgr:getWindow("orxonox/KeyBindPane")
     173    for q,w in pairs(commandList) do
     174        local line = P.createLine(q)
     175        table.insert(linesList, line)
     176        window:addChildWindow(line)
     177    end
    133178   
    134     InfoPopup.close()
     179    if(InfoPopup ~= nil) then
     180        InfoPopup.close()
     181    end
    135182end
    136183
  • code/branches/presentation2/src/libraries/core/input/KeyBinder.cc

    r6214 r6311  
    2929#include "KeyBinder.h"
    3030
     31#include <algorithm>
     32#include <sstream>
    3133#include "util/Convert.h"
    3234#include "util/Debug.h"
     
    256258        {
    257259            it->second->readConfigValue(this->configFile_);
    258             this->allCommands_[it->second->bindingString_] = it->second->groupName_ + " " + it->second->name_;
     260            addButtonToCommand(it->second->bindingString_, it->second);
    259261        }
    260262
     
    267269        if (it != allButtons_.end())
    268270        {
     271            addButtonToCommand(binding, it->second);
    269272            if (bTemporary)
    270273                it->second->configContainer_->tset(binding);
     
    272275                it->second->configContainer_->set(binding);
    273276            it->second->configContainer_->getValue(&(it->second->bindingString_), it->second);
    274             this->allCommands_[it->second->bindingString_] = it->second->groupName_ + " " + it->second->name_;
    275277            return true;
    276278        }
     
    282284    }
    283285   
    284     /**
    285     @brief
    286         Return the key name for a specific command
     286     void KeyBinder::addButtonToCommand(std::string command, Button* button)
     287     { 
     288        std::ostringstream stream;
     289        stream << button->groupName_  << "." << button->name_;
     290       
     291        std::vector<std::string>& oldKeynames = this->allCommands_[button->bindingString_];
     292        std::vector<std::string>::iterator it = std::find(oldKeynames.begin(), oldKeynames.end(), stream.str());
     293        if(it != oldKeynames.end())
     294        {
     295            oldKeynames.erase(it);
     296        }
     297       
     298        if(command != "")
     299        {
     300            std::vector<std::string>& keynames = this->allCommands_[command];
     301            if( std::find(keynames.begin(), keynames.end(), stream.str()) == keynames.end())
     302            {
     303                this->allCommands_[command].push_back(stream.str());
     304            }
     305        }
     306     }
     307   
     308    /**
     309    @brief
     310        Return the first key name for a specific command
    287311    */
    288312    std::string KeyBinder::getBinding(std::string commandName)
    289313    {
    290         COUT(0)<< commandName << endl;
    291314        if( this->allCommands_.find(commandName) != this->allCommands_.end())
    292315        {
    293             std::string keyname = this->allCommands_[commandName];
    294 //             while(keyname.find(".")!=keyname.npos)
    295 //                 keyname.replace(1, keyname.find("."), " ");
    296             COUT(0) << keyname << endl;
    297             return keyname;
    298         }
    299         else
     316            std::vector<std::string>& keynames = this->allCommands_[commandName];
     317            return keynames.front();
     318        }
     319       
     320        return "";
     321    }
     322   
     323    /**
     324    @brief
     325        Return the key name for a specific command at a given index.
     326    @param commandName
     327        The command name the key name is returned for.
     328    @param index
     329        The index at which the key name is returned for.
     330    */
     331    std::string KeyBinder::getBinding(std::string commandName, unsigned int index)
     332    {
     333        if( this->allCommands_.find(commandName) != this->allCommands_.end())
     334        {
     335            std::vector<std::string>& keynames = this->allCommands_[commandName];
     336            if(index < keynames.size())
     337            {
     338                return keynames[index];
     339            }
     340               
    300341            return "";
     342        }
     343       
     344        return "";
     345    }
     346   
     347    /**
     348    @brief
     349        Get the number of different key bindings of a specific command.
     350    @param commandName
     351        The command.
     352    */
     353    unsigned int KeyBinder::getNumberOfBindings(std::string commandName)
     354    {
     355        if( this->allCommands_.find(commandName) != this->allCommands_.end())
     356        {
     357            std::vector<std::string>& keynames = this->allCommands_[commandName];
     358            return keynames.size();
     359        }
     360       
     361        return 0;
    301362    }
    302363
  • code/branches/presentation2/src/libraries/core/input/KeyBinder.h

    r6214 r6311  
    3535#include <string>
    3636#include <vector>
     37#include <map>
    3738#include <boost/shared_ptr.hpp>
    3839
     
    6667        bool setBinding(const std::string& binding, const std::string& name, bool bTemporary = false);
    6768        std::string getBinding(std::string commandName); //tolua_export
     69        std::string getBinding(std::string commandName, unsigned int index); //tolua_export
     70        unsigned int getNumberOfBindings(std::string commandName); //tolua_export
     71       
    6872        const std::string& getBindingsFilename()
    6973            { return this->filename_; }
     
    135139        std::vector<HalfAxis*> allHalfAxes_;
    136140        //! Maps input commands to all Button names, including half axes
    137         std::map<std::string, std::string> allCommands_;
     141        std::map< std::string, std::vector<std::string> > allCommands_;
    138142
    139143        /**
     
    156160
    157161    private:
     162        void addButtonToCommand(std::string command, Button* button);
     163       
    158164        //##### ConfigValues #####
    159165        //! Whether to filter small value analog input
  • code/branches/presentation2/src/libraries/core/input/KeyBinderManager.cc

    r6281 r6311  
    5757        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyBinderManager::tkeybind, this), "tkeybind"))
    5858            .defaultValues("");
     59        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyBinderManager::unbind, this), "unbind"))
     60            .defaultValues("");
     61        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyBinderManager::tunbind, this), "tunbind"))
     62            .defaultValues("");
    5963
    6064        // Load default key binder
     
    8993        else
    9094            this->bDefaultFileLoaded_ = false;
     95    }
     96   
     97    inline void KeyBinderManager::unbind(const std::string& binding)
     98    {
     99        this->currentBinder_->setBinding("", binding, false);
     100    }
     101           
     102    inline void KeyBinderManager::tunbind(const std::string& binding)
     103    {
     104        this->currentBinder_->setBinding("", binding, true);
    91105    }
    92106   
     
    163177        if (this->bBinding_)
    164178        {
    165             COUT(0) << "Binding string \"" << command_ << "\" on key '" << keyName << "'" << std::endl;
    166             this->currentBinder_->setBinding(command_, keyName, bTemporary_);
     179            if (keyName == "Keys.KeyEscape")
     180            {
     181                COUT(0) << "Keybinding aborted." << std::endl;
     182            }
     183            else
     184            {
     185                COUT(0) << "Binding string \"" << command_ << "\" on key '" << keyName << "'" << std::endl;
     186                this->currentBinder_->setBinding(command_, keyName, bTemporary_);
     187            }
    167188            InputManager::getInstance().leaveState("detector");
    168189            // inform whatever was calling the command
  • code/branches/presentation2/src/libraries/core/input/KeyBinderManager.h

    r6281 r6311  
    100100        inline void tkeybind(const std::string& command)
    101101            { this->keybindInternal(command, true); }
     102        void unbind(const std::string& binding); //tolua_export
     103        void tunbind(const std::string& binding);
    102104        inline void registerKeybindCallback(Functor* function) { this->callbackFunction_.reset(function); } // tolua_export
    103105
Note: See TracChangeset for help on using the changeset viewer.