Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 28, 2009, 11:10:37 PM (15 years ago)
Author:
rgrieder
Message:

Changed config value handling in the KeyBinder. Doesn't change the interface though.

Location:
code/trunk/src/libraries/core/input
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/libraries/core/input/Button.cc

    r6417 r6428  
    4242#include "core/CommandEvaluation.h"
    4343#include "core/CommandExecutor.h"
    44 #include "core/ConfigValueContainer.h"
    4544
    4645namespace orxonox
     
    5251    */
    5352    Button::Button()
    54         : configContainer_(0)
    55         , bButtonThresholdUser_(false)
     53        : bButtonThresholdUser_(false)
    5654        , paramCommandBuffer_(0)
    5755    {
     
    6462    {
    6563        this->clear();
    66 
    67         if (this->configContainer_)
    68             delete this->configContainer_;
    6964    }
    7065
     
    8378            }
    8479        }
    85     }
    86 
    87     void Button::readConfigValue(ConfigFileType configFile)
    88     {
    89         // create/get ConfigValueContainer
    90         if (!configContainer_)
    91         {
    92             configContainer_ = new ConfigValueContainer(configFile, 0, groupName_, name_, "", name_);
    93             configContainer_->callback(this, &Button::parse);
    94         }
    95         configContainer_->getValue(&bindingString_, this);
    96     }
    97 
    98     void Button::parse()
    99     {
     80        this->bindingString_.clear();
     81    }
     82
     83    void Button::readBinding(ConfigFileType type)
     84    {
     85        const std::string& binding = ConfigFileManager::getInstance().getValue(type, groupName_, name_, "", true);
     86        this->parse(binding);
     87    }
     88
     89    void Button::setBinding(ConfigFileType type, const std::string& binding, bool bTemporary)
     90    {
     91        if (!bTemporary)
     92            ConfigFileManager::getInstance().setValue(type, groupName_, name_, binding, true);
     93        this->parse(binding);
     94    }
     95
     96    void Button::parse(const std::string& binding)
     97    {
     98        if (binding == this->bindingString_)
     99            return;
     100
    100101        // delete all commands
    101102        clear();
     103        this->bindingString_ = binding;
    102104
    103105        if (isEmpty(bindingString_))
  • code/trunk/src/libraries/core/input/Button.h

    r6417 r6428  
    5252        virtual void clear();
    5353        virtual bool addParamCommand(ParamCommand* command) { return false; }
    54         void parse();
    55         void readConfigValue(ConfigFileType configFile);
     54        void parse(const std::string& binding);
     55        void readBinding(ConfigFileType type);
     56        void setBinding(ConfigFileType type, const std::string& binding, bool bTemporary);
    5657        bool execute(KeybindMode::Value mode, float abs = 1.0f, float rel = 1.0f);
    5758
    58         //! Container to allow for better configValue support
    59         ConfigValueContainer* configContainer_;
    6059        //! The configured string value
    6160        std::string bindingString_;
  • code/trunk/src/libraries/core/input/KeyBinder.cc

    r6422 r6428  
    5757        RegisterRootObject(KeyBinder);
    5858
    59         // intialise all buttons and half axes to avoid creating everything with 'new'
     59        // initialise all buttons and half axes to avoid creating everything with 'new'
    6060        // keys
    6161        for (unsigned int i = 0; i < KeyCode::numberOfKeys; i++)
     
    168168            {
    169169                for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; ++i)
    170                     (*joyStickButtons_[iDev])[i].readConfigValue(this->configFile_);
     170                    (*joyStickButtons_[iDev])[i].readBinding(this->configFile_);
    171171                for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; ++i)
    172                     (*joyStickAxes_[iDev])[i].readConfigValue(this->configFile_);
     172                    (*joyStickAxes_[iDev])[i].readBinding(this->configFile_);
    173173            }
    174174        }
     
    257257        for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
    258258        {
    259             it->second->readConfigValue(this->configFile_);
     259            it->second->readBinding(this->configFile_);
    260260            addButtonToCommand(it->second->bindingString_, it->second);
    261261        }
     
    270270        {
    271271            addButtonToCommand(binding, it->second);
    272             if (bTemporary)
    273                 it->second->configContainer_->tset(binding);
    274             else
    275                 it->second->configContainer_->set(binding);
    276             it->second->configContainer_->getValue(&(it->second->bindingString_), it->second);
     272            it->second->setBinding(this->configFile_, binding, bTemporary);
    277273            return true;
    278274        }
  • code/trunk/src/libraries/core/input/KeyBinder.h

    r6417 r6428  
    3838#include <boost/shared_ptr.hpp>
    3939
     40#include "core/ConfigFileManager.h"
    4041#include "InputHandler.h"
    4142#include "Button.h"
  • code/trunk/src/libraries/core/input/KeyDetector.cc

    r6417 r6428  
    6464    {
    6565        // Assign every button/axis the same command, but with its name as argument
    66         clearBindings();
    6766        for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
    68         {
    69             it->second->bindingString_ = callbackCommand_s + ' ' + it->second->groupName_ + "." + it->second->name_;
    70             it->second->parse();
    71         }
     67            it->second->parse(callbackCommand_s + ' ' + it->second->groupName_ + "." + it->second->name_);
    7268    }
    7369
Note: See TracChangeset for help on using the changeset viewer.