Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 3, 2009, 5:33:31 PM (15 years ago)
Author:
rgrieder
Message:

New class: KeyBinderManager (yes, it really was necessary, I'm not such a Fan of zillions of classes as well) and moved the keybind command to it from GSLevel.
This new Singleton simply maps the keybind command to the right KeyBinder, selected by KeyBinderManager::setCurrent().
There is also a default KeyBinder (with keybindings.ini as file), which should do the Trick for now. Other Keybinders should only server special purposes (like in mini games or so).

DELETE YOUR keybindings.ini FILE! =
Location:
code/branches/core5/src/libraries/core
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/src/libraries/core/Core.cc

    r5855 r5863  
    6969#include "TclThreadManager.h"
    7070#include "input/InputManager.h"
     71#include "input/KeyBinderManager.h"
    7172
    7273namespace orxonox
     
    288289        inputManager_.reset(new InputManager());
    289290
     291        // Manages KeyBinders and makes them available
     292        keyBinderManager_.reset(new KeyBinderManager());
     293
    290294        // load the CEGUI interface
    291295        guiManager_.reset(new GUIManager(graphicsManager_->getRenderWindow(),
     
    304308        this->graphicsScope_.reset();
    305309        this->guiManager_.reset();
     310        this->keyBinderManager_.reset();
    306311        this->inputManager_.reset();
    307312        this->graphicsManager_.reset();
  • code/branches/core5/src/libraries/core/Core.h

    r5850 r5863  
    100100            scoped_ptr<GraphicsManager>   graphicsManager_;     //!< Interface to OGRE
    101101            scoped_ptr<InputManager>      inputManager_;        //!< Interface to OIS
     102            scoped_ptr<KeyBinderManager>  keyBinderManager_;    //!< Manages all KeyBinders
    102103            scoped_ptr<GUIManager>        guiManager_;          //!< Interface to GUI
    103104            scoped_ptr<Scope<ScopeID::Root> >     rootScope_;
  • code/branches/core5/src/libraries/core/CorePrereqs.h

    r5858 r5863  
    212212    class JoyStick;
    213213    class KeyBinder;
     214    class KeyBinderManager;
    214215    class Keyboard;
    215216    class KeyDetector;
  • code/branches/core5/src/libraries/core/input/CMakeLists.txt

    r5738 r5863  
    99  JoyStickQuantityListener.cc
    1010  KeyBinder.cc
     11  KeyBinderManager.cc
    1112  Keyboard.cc
    1213  KeyDetector.cc
  • code/branches/core5/src/libraries/core/input/InputManager.cc

    r5855 r5863  
    264264    }
    265265
    266     void InputManager::setKeyDetectorCallback(const std::string& command)
    267     {
    268         this->keyDetector_->setCallbackCommand(command);
    269     }
    270 
    271266    // ############################################################
    272267    // #####                    Destruction                   #####
  • code/branches/core5/src/libraries/core/input/InputManager.h

    r5738 r5863  
    161161        // Various getters and setters
    162162        //-------------------------------
    163         //! Sets the the name of the command used by the KeyDetector as callback.
    164         void setKeyDetectorCallback(const std::string& command);
    165163        //! Returns the number of joy stick that have been created since the c'tor or last call to reload().
    166164        unsigned int getJoyStickQuantity() const
  • code/branches/core5/src/libraries/core/input/KeyBinder.cc

    r5738 r5863  
    2727 */
    2828
    29 /**
    30  @file
    31  @brief Implementation of the different input handlers.
    32  */
    33 
    3429#include "KeyBinder.h"
    3530
    3631#include "util/Convert.h"
    3732#include "util/Debug.h"
     33#include "util/Exception.h"
    3834#include "core/ConfigValueIncludes.h"
    3935#include "core/CoreIncludes.h"
     
    4844        Constructor that does as little as necessary.
    4945    */
    50     KeyBinder::KeyBinder()
     46    KeyBinder::KeyBinder(const std::string& filename)
    5147        : deriveTime_(0.0f)
     48        , filename_(filename)
    5249    {
    5350        mouseRelative_[0] = 0;
     
    103100        // set them here to use allHalfAxes_
    104101        setConfigValues();
     102
     103        // Load the bindings if filename was given
     104        if (!this->filename_.empty())
     105            this->loadBindings();
    105106    }
    106107
     
    240241    @brief
    241242        Loads the key and button bindings.
    242     @return
    243         True if loading succeeded.
    244     */
    245     void KeyBinder::loadBindings(const std::string& filename)
     243    */
     244    void KeyBinder::loadBindings()
    246245    {
    247246        COUT(3) << "KeyBinder: Loading key bindings..." << std::endl;
    248247
    249         if (filename.empty())
    250             return;
    251 
    252         if (this->configFile_ == ConfigFileType::NoType)
    253         {
    254             // Get a new ConfigFileType from the ConfigFileManager
    255             this->configFile_ = ConfigFileManager::getInstance().getNewConfigFileType();
    256         }
    257 
    258         ConfigFileManager::getInstance().setFilename(this->configFile_, filename);
     248        // Get a new ConfigFileType from the ConfigFileManager
     249        this->configFile_ = ConfigFileManager::getInstance().getNewConfigFileType();
     250
     251        ConfigFileManager::getInstance().setFilename(this->configFile_, this->filename_);
    259252
    260253        // Parse bindings and create the ConfigValueContainers if necessary
    261         clearBindings();
    262254        for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
    263255            it->second->readConfigValue(this->configFile_);
  • code/branches/core5/src/libraries/core/input/KeyBinder.h

    r5738 r5863  
    2626 *
    2727 */
    28 
    29 /**
    30 @file
    31 @brief
    32     Different definitions of input processing.
    33 */
    3428
    3529#ifndef _KeyBinder_H__
     
    5347    /**
    5448    @brief
    55         Handles mouse, keyboard and joy stick input while in the actual game mode.
    56         Manages the key bindings.
     49        Maps mouse, keyboard and joy stick input to command strings and executes them.
     50
     51        The bindings are stored in ini-files (like the one for configValues) in the config Path.
     52    @remarks
     53        You cannot change the filename because the KeyBinderManager maps these filenames to the
     54        KeyBinders. If you need to load other bindings, just create a new one.
    5755    */
    5856    class _CoreExport KeyBinder : public InputHandler, public JoyStickQuantityListener
    5957    {
    6058    public:
    61         KeyBinder ();
     59        KeyBinder (const std::string& filename);
    6260        virtual ~KeyBinder();
    6361
    64         void loadBindings(const std::string& filename);
    6562        void clearBindings();
    6663        bool setBinding(const std::string& binding, const std::string& name, bool bTemporary = false);
     64        const std::string& getBindingsFilename()
     65            { return this->filename_; }
    6766        void setConfigValues();
    6867        void resetJoyStickAxes();
    6968
    7069    protected: // functions
     70        void loadBindings();
     71        void buttonThresholdChanged();
     72        void initialiseJoyStickBindings();
     73        void compilePointerLists();
     74        // from JoyStickQuantityListener interface
     75        virtual void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList);
     76
    7177        void allDevicesUpdated(float dt);
    7278        void mouseUpdated(float dt);
     
    7480        // internal
    7581        void tickHalfAxis(HalfAxis& halfAxis);
    76 
    77         void buttonThresholdChanged();
    78         // from JoyStickQuantityListener interface
    79         virtual void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList);
    80         void initialiseJoyStickBindings();
    81         void compilePointerLists();
    8282
    8383        void buttonPressed (const KeyEvent& evt);
     
    144144        float deriveTime_;
    145145
     146        //! Name of the file used in this KeyBinder (constant!)
     147        const std::string filename_;
    146148        //! Config file used. ConfigFileType::NoType in case of KeyDetector. Also indicates whether we've already loaded.
    147149        ConfigFileType configFile_;
     
    171173    };
    172174
     175
    173176    inline void KeyBinder::buttonPressed (const KeyEvent& evt)
    174177    { assert(!keys_[evt.getKeyCode()].name_.empty()); keys_[evt.getKeyCode()].execute(KeybindMode::OnPress); }
Note: See TracChangeset for help on using the changeset viewer.