Changeset 1887 for code/trunk/src/orxonox/gamestates/GSLevel.cc
- Timestamp:
- Oct 6, 2008, 12:31:32 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/gamestates/GSLevel.cc
r1826 r1887 36 36 #include "core/input/KeyBinder.h" 37 37 #include "core/Loader.h" 38 #include "core/CommandExecutor.h" 39 #include "core/ConsoleCommand.h" 40 #include "core/ConfigValueIncludes.h" 41 #include "core/CoreIncludes.h" 38 42 #include "objects/Backlight.h" 39 43 #include "objects/Tickable.h" … … 55 59 , hud_(0) 56 60 { 61 RegisterObject(GSLevel); 62 setConfigValues(); 57 63 } 58 64 59 65 GSLevel::~GSLevel() 60 66 { 67 } 68 69 void GSLevel::setConfigValues() 70 { 71 SetConfigValue(keyDetectorCallbackCode_, "KeybindBindingStringKeyName="); 61 72 } 62 73 … … 65 76 inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game", 20); 66 77 keyBinder_ = new KeyBinder(); 67 keyBinder_->loadBindings( );78 keyBinder_->loadBindings("keybindings.ini"); 68 79 inputState_->setHandler(keyBinder_); 69 80 … … 88 99 // TODO: insert slomo console command with 89 100 // .accessLevel(AccessLevel::Offline).defaultValue(0, 1.0).axisParamIndex(0).isAxisRelative(false); 101 102 // keybind console command 103 FunctorMember<GSLevel>* functor1 = createFunctor(&GSLevel::keybind); 104 functor1->setObject(this); 105 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "keybind")); 106 FunctorMember<GSLevel>* functor2 = createFunctor(&GSLevel::tkeybind); 107 functor2->setObject(this); 108 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "tkeybind")); 109 // set our console command as callback for the key detector 110 InputManager::getInstance().setKeyDetectorCallback(std::string("keybind ") + keyDetectorCallbackCode_); 90 111 } 91 112 … … 145 166 delete this->startLevel_; 146 167 } 168 169 void GSLevel::keybind(const std::string &command) 170 { 171 this->keybindInternal(command, false); 172 } 173 174 void GSLevel::tkeybind(const std::string &command) 175 { 176 this->keybindInternal(command, true); 177 } 178 179 /** 180 @brief 181 Assigns a command string to a key/button/axis. The name is determined via KeyDetector. 182 @param command 183 Command string that can be executed by the CommandExecutor 184 OR: Internal string "KeybindBindingStringKeyName=" used for the second call to identify 185 the key/button/axis that has been activated. This is configured above in enter(). 186 */ 187 void GSLevel::keybindInternal(const std::string& command, bool bTemporary) 188 { 189 static std::string bindingString = ""; 190 static bool bTemporarySaved = false; 191 static bool bound = true; 192 // note: We use a long name to make 'sure' that the user doesn't use it accidentally. 193 // Howerver there will be no real issue if it happens anyway. 194 if (command.find(keyDetectorCallbackCode_) != 0) 195 { 196 if (bound) 197 { 198 COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl; 199 InputManager::getInstance().requestEnterState("detector"); 200 bindingString = command; 201 bTemporarySaved = bTemporary; 202 bound = false; 203 } 204 //else: We're still in a keybind command. ignore this call. 205 } 206 else 207 { 208 if (!bound) 209 { 210 // user has pressed the key 211 std::string name = command.substr(this->keyDetectorCallbackCode_.size()); 212 COUT(0) << "Binding string \"" << bindingString << "\" on key '" << name << "'" << std::endl; 213 this->keyBinder_->setBinding(bindingString, name, bTemporarySaved); 214 InputManager::getInstance().requestLeaveState("detector"); 215 bound = true; 216 } 217 // else: A key was pressed within the same tick, ignore it. 218 } 219 } 147 220 }
Note: See TracChangeset
for help on using the changeset viewer.