Changeset 7861
- Timestamp:
- Feb 12, 2011, 11:54:07 AM (14 years ago)
- Location:
- code/trunk/src/libraries/core
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/libraries/core/command/ConsoleCommand.cc
r7401 r7861 38 38 #include "core/Language.h" 39 39 #include "core/GameMode.h" 40 #include "core/input/KeyBinder.h" 41 #include "core/input/KeyBinderManager.h" 40 42 41 43 namespace orxonox … … 575 577 576 578 /** 579 @brief Changes the keybind mode. 580 */ 581 ConsoleCommand& ConsoleCommand::changeKeybindMode(KeybindMode::Value mode) 582 { 583 KeyBinderManager::getInstance().getCurrent()->changeMode(this, mode); 584 585 this->keybindMode(mode); 586 return *this; 587 } 588 589 /** 577 590 @brief Returns the command with given group an name. 578 591 @param group The group of the requested command -
code/trunk/src/libraries/core/command/ConsoleCommand.h
r7401 r7861 510 510 /// Changes the keybind mode of the command. 511 511 inline ConsoleCommandManipulator& keybindMode(KeybindMode::Value mode) 512 { if (this->command_) { this->command_-> keybindMode(mode); } return *this; }512 { if (this->command_) { this->command_->changeKeybindMode(mode); } return *this; } 513 513 /// Sets the input configured param to the given index. 514 514 inline ConsoleCommandManipulator& inputConfiguredParam(int index) … … 598 598 } 599 599 600 /// Changes the keybindmode.600 /// Sets the keybind mode. Note: use changeKeybindMode if you intend to change the mode. 601 601 inline ConsoleCommand& keybindMode(KeybindMode::Value mode) 602 602 { this->keybindMode_ = mode; return *this; } … … 604 604 inline KeybindMode::Value getKeybindMode() const 605 605 { return this->keybindMode_; } 606 607 ConsoleCommand& changeKeybindMode(KeybindMode::Value mode); 606 608 607 609 /// Changes the input configured param to the given index. -
code/trunk/src/libraries/core/input/InputCommands.h
r7284 r7861 58 58 virtual ~BaseCommand() { } 59 59 virtual bool execute(float abs = 1.0f, float rel = 1.0f) = 0; 60 virtual CommandEvaluation* getEvaluation() = 0; 60 61 }; 61 62 … … 64 65 public: 65 66 bool execute(float abs = 1.0f, float rel = 1.0f); 67 CommandEvaluation* getEvaluation(); 66 68 67 69 CommandEvaluation evaluation_; … … 79 81 } 80 82 83 /// Returns a pointer to the encapsuled evaluation. 84 inline CommandEvaluation* SimpleCommand::getEvaluation() 85 { 86 return &this->evaluation_; 87 } 88 81 89 class _CoreExport ParamCommand : public BaseCommand 82 90 { … … 84 92 ParamCommand() : scale_(1.0f), paramCommand_(0) { } 85 93 bool execute(float abs = 1.0f, float rel = 1.0f); 94 CommandEvaluation* getEvaluation(); 86 95 87 96 float scale_; 88 97 BufferedParamCommand* paramCommand_; 89 98 }; 99 100 /// Returns a pointer to the encapsuled evaluation. 101 inline CommandEvaluation* ParamCommand::getEvaluation() 102 { 103 if (this->paramCommand_) 104 return &this->paramCommand_->evaluation_; 105 else 106 return 0; 107 } 90 108 } 91 109 -
code/trunk/src/libraries/core/input/KeyBinder.cc
r7859 r7861 385 385 } 386 386 387 /** 388 @brief Changes the keybind mode of a given console command. 389 */ 390 void KeyBinder::changeMode(ConsoleCommand* command, KeybindMode::Value new_mode) 391 { 392 // iterate over all buttons 393 for (std::map<std::string, Button*>::iterator it = this->allButtons_.begin(); it != this->allButtons_.end(); ++it) 394 { 395 Button* button = it->second; 396 397 // iterate over all modes 398 for (size_t mode_index = 0; mode_index < 3; ++mode_index) 399 { 400 if (mode_index == new_mode) // skip commands that are already in the desired mode 401 continue; 402 403 // iterate over all commands of the given mode at the given button 404 for (size_t command_index = 0; command_index < button->nCommands_[mode_index]; ++command_index) 405 { 406 CommandEvaluation* evaluation = button->commands_[mode_index][command_index]->getEvaluation(); 407 408 // compare the command 409 if (evaluation && evaluation->getConsoleCommand() == command) 410 { 411 // increase array of new mode 412 BaseCommand** array_new_mode = new BaseCommand*[button->nCommands_[new_mode] + 1]; 413 // copy array content 414 for (size_t c = 0; c < button->nCommands_[new_mode]; ++c) 415 array_new_mode[c] = button->commands_[new_mode][c]; 416 // insert changed command at the end 417 array_new_mode[button->nCommands_[new_mode]] = button->commands_[mode_index][command_index]; 418 // delete old array 419 delete[] button->commands_[new_mode]; 420 // assign new array 421 button->commands_[new_mode] = array_new_mode; 422 // increase counter 423 button->nCommands_[new_mode]++; 424 425 // erase command from old array 426 for (size_t c = command_index; c < button->nCommands_[mode_index] - 1; ++c) 427 button->commands_[mode_index][c] = button->commands_[mode_index][c + 1]; 428 // decrease counter 429 button->nCommands_[mode_index]--; 430 // note: we don't replace the old array - it's not one element too large, but no one cares since nCommands_ defines the size 431 432 // decrement the index since we shifted the array and continue searching for more occurrences of the command 433 command_index--; 434 } 435 } 436 } 437 } 438 } 439 387 440 void KeyBinder::resetJoyStickAxes() 388 441 { -
code/trunk/src/libraries/core/input/KeyBinder.h
r7859 r7861 75 75 void resetJoyStickAxes(); 76 76 void resetMouseAxes(); 77 78 void changeMode(ConsoleCommand* command, KeybindMode::Value mode); 77 79 78 80 protected: // functions
Note: See TracChangeset
for help on using the changeset viewer.