Changeset 6437 for code/branches/gamestate/src/libraries/core/input
- Timestamp:
- Jan 1, 2010, 10:05:56 PM (15 years ago)
- Location:
- code/branches/gamestate/src/libraries/core/input
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gamestate/src/libraries/core/input/Button.cc
r6432 r6437 82 82 } 83 83 84 void Button::readBinding(ConfigFile* configFile) 85 { 86 const std::string& binding = configFile->getOrCreateValue(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); 87 89 this->parse(binding); 88 90 } 89 91 90 void Button::setBinding(ConfigFile* configFile, const std::string& binding, bool bTemporary)92 void Button::setBinding(ConfigFile* configFile, ConfigFile* fallbackFile, const std::string& binding, bool bTemporary) 91 93 { 92 94 if (!bTemporary) … … 104 106 this->bindingString_ = binding; 105 107 106 if (isEmpty(bindingString_) )108 if (isEmpty(bindingString_) || removeTrailingWhitespaces(getLowercase(binding)) == "nobinding") 107 109 return; 108 110 -
code/branches/gamestate/src/libraries/core/input/Button.h
r6432 r6437 52 52 virtual bool addParamCommand(ParamCommand* command) { return false; } 53 53 void parse(const std::string& binding); 54 void readBinding(ConfigFile* configFile );55 void setBinding(ConfigFile* configFile, 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); 56 56 bool execute(KeybindMode::Value mode, float abs = 1.0f, float rel = 1.0f); 57 57 -
code/branches/gamestate/src/libraries/core/input/KeyBinder.cc
r6432 r6437 37 37 #include "core/CoreIncludes.h" 38 38 #include "core/ConfigFileManager.h" 39 #include "core/PathConfig.h" 39 40 #include "InputCommands.h" 40 41 #include "JoyStick.h" … … 50 51 , filename_(filename) 51 52 , configFile_(NULL) 53 , fallbackConfigFile_(NULL) 52 54 { 53 55 mouseRelative_[0] = 0; … … 114 116 // almost no destructors required because most of the arrays are static. 115 117 clearBindings(); // does some destruction work 118 if (this->configFile_) 119 delete this->configFile_; 120 if (this->fallbackConfigFile_) 121 delete this->fallbackConfigFile_; 116 122 } 117 123 … … 166 172 { 167 173 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_); 169 175 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_); 171 177 } 172 178 } … … 247 253 COUT(3) << "KeyBinder: Loading key bindings..." << std::endl; 248 254 249 this->configFile_ = new ConfigFile(this->filename_ );255 this->configFile_ = new ConfigFile(this->filename_, !PathConfig::isDevelopmentRun()); 250 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 } 251 271 252 272 // Parse bindings and create the ConfigValueContainers if necessary 253 273 for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it) 254 274 { 255 it->second->readBinding(this->configFile_ );275 it->second->readBinding(this->configFile_, this->fallbackConfigFile_); 256 276 addButtonToCommand(it->second->bindingString_, it->second); 257 277 } … … 266 286 { 267 287 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); 269 292 return true; 270 293 } -
code/branches/gamestate/src/libraries/core/input/KeyBinder.h
r6432 r6437 158 158 //! Config file used. NULL in case of KeyDetector. Also indicates whether we've already loaded. 159 159 ConfigFile* configFile_; 160 //! Config file from the data directory that only serves as fallback 161 ConfigFile* fallbackConfigFile_; 160 162 161 163 private:
Note: See TracChangeset
for help on using the changeset viewer.