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/src/libraries/core/input
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • 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.