Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 16, 2010, 11:22:36 AM (15 years ago)
Author:
rgrieder
Message:

Merged revisions 6430-6440 from the gamestate branch to the trunk.
This adds keybindings merging functionality.

(from log of r6437)
When running development builds, the keybinder will merge the local file and the one from the data folder.
Catch: if you want to remove a binding, you'll have to write "NoBinding" (not case sensitive) to override the default command

The keybind command already does that for you though.

Location:
code/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/input/Button.cc

    r6428 r6536  
    4242#include "core/CommandEvaluation.h"
    4343#include "core/CommandExecutor.h"
     44#include "core/ConfigFileManager.h"
    4445
    4546namespace orxonox
     
    8182    }
    8283
    83     void Button::readBinding(ConfigFileType type)
    84     {
    85         const std::string& binding = ConfigFileManager::getInstance().getValue(type, groupName_, name_, "", true);
     84    void Button::readBinding(ConfigFile* configFile, ConfigFile* fallbackFile)
     85    {
     86        std::string binding = configFile->getOrCreateValue(groupName_, name_, "", true);
     87        if (binding.empty() && fallbackFile)
     88            binding = fallbackFile->getValue(groupName_, name_, true);
    8689        this->parse(binding);
    8790    }
    8891
    89     void Button::setBinding(ConfigFileType type, const std::string& binding, bool bTemporary)
     92    void Button::setBinding(ConfigFile* configFile, ConfigFile* fallbackFile, const std::string& binding, bool bTemporary)
    9093    {
    9194        if (!bTemporary)
    92             ConfigFileManager::getInstance().setValue(type, groupName_, name_, binding, true);
     95            configFile->setValue(groupName_, name_, binding, true);
    9396        this->parse(binding);
    9497    }
     
    103106        this->bindingString_ = binding;
    104107
    105         if (isEmpty(bindingString_))
     108        if (isEmpty(bindingString_) || removeTrailingWhitespaces(getLowercase(binding)) == "nobinding")
    106109            return;
    107110
  • code/trunk/src/libraries/core/input/Button.h

    r6428 r6536  
    4141#include <vector>
    4242#include "InputCommands.h"
    43 #include "core/ConfigFileManager.h"
    4443
    4544namespace orxonox
     
    5352        virtual bool addParamCommand(ParamCommand* command) { return false; }
    5453        void parse(const std::string& binding);
    55         void readBinding(ConfigFileType type);
    56         void setBinding(ConfigFileType type, const std::string& binding, bool bTemporary);
     54        void readBinding(ConfigFile* configFile, ConfigFile* fallbackFile);
     55        void setBinding(ConfigFile* configFile, ConfigFile* fallbackFile, const std::string& binding, bool bTemporary);
    5756        bool execute(KeybindMode::Value mode, float abs = 1.0f, float rel = 1.0f);
    5857
  • code/trunk/src/libraries/core/input/JoyStick.cc

    r6417 r6536  
    106106    {
    107107        list.resize(size);
    108         unsigned int configValueVectorSize = ConfigFileManager::getInstance().getVectorSize(ConfigFileType::JoyStickCalibration, sectionName, valueName);
     108        unsigned int configValueVectorSize = ConfigFileManager::getInstance().getConfigFile(ConfigFileType::JoyStickCalibration)->getVectorSize(sectionName, valueName);
    109109        if (configValueVectorSize > size)
    110110            configValueVectorSize = size;
     
    112112        for (unsigned int i = 0; i < configValueVectorSize; ++i)
    113113        {
    114             list[i] = multi_cast<int>(ConfigFileManager::getInstance().getValue(
    115                 ConfigFileType::JoyStickCalibration, sectionName, valueName, i, multi_cast<std::string>(defaultValue), false));
     114            list[i] = multi_cast<int>(ConfigFileManager::getInstance().getConfigFile(ConfigFileType::JoyStickCalibration)
     115                ->getOrCreateValue(sectionName, valueName, i, multi_cast<std::string>(defaultValue), false));
    116116        }
    117117
     
    153153            if (configMinValues_[i] == INT_MAX)
    154154                configMinValues_[i] = -32768;
    155             ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration,
    156                 deviceName_, "MinValue", i, multi_cast<std::string>(configMinValues_[i]), false);
     155            ConfigFileManager::getInstance().getConfigFile(ConfigFileType::JoyStickCalibration)
     156                ->getOrCreateValue(deviceName_, "MinValue", i, multi_cast<std::string>(configMinValues_[i]), false);
    157157
    158158            // Maximum values
    159159            if (configMaxValues_[i] == INT_MIN)
    160160                configMaxValues_[i] = 32767;
    161             ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration,
    162                 deviceName_, "MaxValue", i, multi_cast<std::string>(configMaxValues_[i]), false);
     161            ConfigFileManager::getInstance().getConfigFile(ConfigFileType::JoyStickCalibration)
     162                ->getOrCreateValue(deviceName_, "MaxValue", i, multi_cast<std::string>(configMaxValues_[i]), false);
    163163
    164164            // Middle values
    165             ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration,
    166                 deviceName_, "ZeroValue", i, multi_cast<std::string>(configZeroValues_[i]), false);
     165            ConfigFileManager::getInstance().getConfigFile(ConfigFileType::JoyStickCalibration)
     166                ->getOrCreateValue(deviceName_, "ZeroValue", i, multi_cast<std::string>(configZeroValues_[i]), false);
    167167        }
    168168
  • code/trunk/src/libraries/core/input/KeyBinder.cc

    r6428 r6536  
    3737#include "core/CoreIncludes.h"
    3838#include "core/ConfigFileManager.h"
     39#include "core/PathConfig.h"
    3940#include "InputCommands.h"
    4041#include "JoyStick.h"
     
    4950        : deriveTime_(0.0f)
    5051        , filename_(filename)
     52        , configFile_(NULL)
     53        , fallbackConfigFile_(NULL)
    5154    {
    5255        mouseRelative_[0] = 0;
     
    9497        }
    9598
    96         // We might not even load any bindings at all (KeyDetector for instance)
    97         this->configFile_ = ConfigFileType::NoType;
    98 
    9999        // initialise joy sticks separatly to allow for reloading
    100100        this->JoyStickQuantityChanged(this->getJoyStickList());
     
    116116        // almost no destructors required because most of the arrays are static.
    117117        clearBindings(); // does some destruction work
     118        if (this->configFile_)
     119            delete this->configFile_;
     120        if (this->fallbackConfigFile_)
     121            delete this->fallbackConfigFile_;
    118122    }
    119123
     
    163167
    164168        // load the bindings if required
    165         if (configFile_ != ConfigFileType::NoType)
     169        if (configFile_ != NULL)
    166170        {
    167171            for (unsigned int iDev = oldValue; iDev < joySticks_.size(); ++iDev)
    168172            {
    169173                for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; ++i)
    170                     (*joyStickButtons_[iDev])[i].readBinding(this->configFile_);
     174                    (*joyStickButtons_[iDev])[i].readBinding(this->configFile_, this->fallbackConfigFile_);
    171175                for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; ++i)
    172                     (*joyStickAxes_[iDev])[i].readBinding(this->configFile_);
     176                    (*joyStickAxes_[iDev])[i].readBinding(this->configFile_, this->fallbackConfigFile_);
    173177            }
    174178        }
     
    249253        COUT(3) << "KeyBinder: Loading key bindings..." << std::endl;
    250254
    251         // Get a new ConfigFileType from the ConfigFileManager
    252         this->configFile_ = ConfigFileManager::getInstance().getNewConfigFileType();
    253 
    254         ConfigFileManager::getInstance().setFilename(this->configFile_, this->filename_);
     255        this->configFile_ = new ConfigFile(this->filename_, !PathConfig::isDevelopmentRun());
     256        this->configFile_->load();
     257
     258        if (PathConfig::isDevelopmentRun())
     259        {
     260            // Dev users should have combined key bindings files
     261            std::string defaultFilepath(PathConfig::getDataPathString() + ConfigFile::DEFAULT_CONFIG_FOLDER + '/' + this->filename_);
     262            std::ifstream file(defaultFilepath.c_str());
     263            if (file.is_open())
     264            {
     265                file.close();
     266                // Open the default file for later use (use absolute path!)
     267                this->fallbackConfigFile_ = new ConfigFile(defaultFilepath, false);
     268                this->fallbackConfigFile_->load();
     269            }
     270        }
    255271
    256272        // Parse bindings and create the ConfigValueContainers if necessary
    257273        for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
    258274        {
    259             it->second->readBinding(this->configFile_);
     275            it->second->readBinding(this->configFile_, this->fallbackConfigFile_);
    260276            addButtonToCommand(it->second->bindingString_, it->second);
    261277        }
     
    270286        {
    271287            addButtonToCommand(binding, it->second);
    272             it->second->setBinding(this->configFile_, binding, bTemporary);
     288            std::string str = binding;
     289            if (PathConfig::isDevelopmentRun() && binding.empty())
     290                str = "NoBinding";
     291            it->second->setBinding(this->configFile_, this->fallbackConfigFile_, binding, bTemporary);
    273292            return true;
    274293        }
  • code/trunk/src/libraries/core/input/KeyBinder.h

    r6428 r6536  
    3838#include <boost/shared_ptr.hpp>
    3939
    40 #include "core/ConfigFileManager.h"
    4140#include "InputHandler.h"
    4241#include "Button.h"
     
    157156        //! Name of the file used in this KeyBinder (constant!)
    158157        const std::string filename_;
    159         //! Config file used. ConfigFileType::NoType in case of KeyDetector. Also indicates whether we've already loaded.
    160         ConfigFileType configFile_;
     158        //! Config file used. NULL in case of KeyDetector. Also indicates whether we've already loaded.
     159        ConfigFile* configFile_;
     160        //! Config file from the data directory that only serves as fallback
     161        ConfigFile* fallbackConfigFile_;
    161162
    162163    private:
Note: See TracChangeset for help on using the changeset viewer.