Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 1, 2010, 10:05:56 PM (14 years ago)
Author:
rgrieder
Message:

Added support for keybindings.ini merging:
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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gamestate/src/libraries/core/input/KeyBinder.cc

    r6432 r6437  
    3737#include "core/CoreIncludes.h"
    3838#include "core/ConfigFileManager.h"
     39#include "core/PathConfig.h"
    3940#include "InputCommands.h"
    4041#include "JoyStick.h"
     
    5051        , filename_(filename)
    5152        , configFile_(NULL)
     53        , fallbackConfigFile_(NULL)
    5254    {
    5355        mouseRelative_[0] = 0;
     
    114116        // almost no destructors required because most of the arrays are static.
    115117        clearBindings(); // does some destruction work
     118        if (this->configFile_)
     119            delete this->configFile_;
     120        if (this->fallbackConfigFile_)
     121            delete this->fallbackConfigFile_;
    116122    }
    117123
     
    166172            {
    167173                for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; ++i)
    168                     (*joyStickButtons_[iDev])[i].readBinding(this->configFile_);
     174                    (*joyStickButtons_[iDev])[i].readBinding(this->configFile_, this->fallbackConfigFile_);
    169175                for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; ++i)
    170                     (*joyStickAxes_[iDev])[i].readBinding(this->configFile_);
     176                    (*joyStickAxes_[iDev])[i].readBinding(this->configFile_, this->fallbackConfigFile_);
    171177            }
    172178        }
     
    247253        COUT(3) << "KeyBinder: Loading key bindings..." << std::endl;
    248254
    249         this->configFile_ = new ConfigFile(this->filename_);
     255        this->configFile_ = new ConfigFile(this->filename_, !PathConfig::isDevelopmentRun());
    250256        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        }
    251271
    252272        // Parse bindings and create the ConfigValueContainers if necessary
    253273        for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
    254274        {
    255             it->second->readBinding(this->configFile_);
     275            it->second->readBinding(this->configFile_, this->fallbackConfigFile_);
    256276            addButtonToCommand(it->second->bindingString_, it->second);
    257277        }
     
    266286        {
    267287            addButtonToCommand(binding, it->second);
    268             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);
    269292            return true;
    270293        }
Note: See TracChangeset for help on using the changeset viewer.