Changeset 1887 for code/trunk/src/core/input/InputManager.cc
- Timestamp:
- Oct 6, 2008, 12:31:32 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/core/input/InputManager.cc
r1881 r1887 56 56 #include "SimpleInputState.h" 57 57 #include "ExtendedInputState.h" 58 #include "JoyStickDeviceNumberListener.h" 58 59 59 60 namespace orxonox 60 61 { 61 SetConsoleCommand(InputManager, keyBind, true);62 SetConsoleCommand(InputManager, storeKeyStroke, true);63 62 SetConsoleCommand(InputManager, calibrate, true); 64 63 SetConsoleCommand(InputManager, reload, false); … … 165 164 if (joyStickSupport) 166 165 _initialiseJoySticks(); 166 // Do this anyway to also inform everyone if a joystick was detached. 167 _configureNumberOfJoySticks(); 167 168 168 169 // Set mouse/joystick region … … 197 198 stateMaster_ = new ExtendedInputState(); 198 199 stateMaster_->setName("master"); 200 stateMaster_->setNumOfJoySticks(joySticksSize_); 199 201 200 202 // KeyDetector to evaluate a pressed key's name 201 203 SimpleInputState* detector = createInputState<SimpleInputState>("detector", 101); 202 204 keyDetector_ = new KeyDetector(); 203 keyDetector_->loadBindings("storeKeyStroke");204 205 detector->setHandler(keyDetector_); 205 206 … … 320 321 //CCOUT(ORX_WARNING) << "Warning: Joy stick support requested, but no joy stick was found" << std::endl; 321 322 } 322 _redimensionLists();323 323 } 324 324 … … 331 331 occupy 2 places in the device number dependent lists. 332 332 */ 333 void InputManager::_ redimensionLists()333 void InputManager::_configureNumberOfJoySticks() 334 334 { 335 335 joySticksSize_ = joySticks_.size(); … … 357 357 for (std::map<int, InputState*>::const_iterator it = inputStatesByPriority_.begin(); 358 358 it != inputStatesByPriority_.end(); ++it) 359 { 359 360 it->second->setNumOfJoySticks(joySticksSize_); 361 } 362 // inform master state 363 if (stateMaster_) 364 this->stateMaster_->setNumOfJoySticks(joySticksSize_); 365 366 // inform all JoyStick Device Number Listeners 367 for (ObjectList<JoyStickDeviceNumberListener>::iterator it = ObjectList<JoyStickDeviceNumberListener>::begin(); it; ++it) 368 it->JoyStickDeviceNumberChanged(joySticksSize_); 369 360 370 } 361 371 … … 385 395 if (!cont) 386 396 { 387 cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), "CoeffPos", coeffPos);397 cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), getIdentifier()->getName(), "CoeffPos", coeffPos); 388 398 getIdentifier()->addConfigValueContainer("CoeffPos", cont); 389 399 } … … 393 403 if (!cont) 394 404 { 395 cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), "CoeffNeg", coeffNeg);405 cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), getIdentifier()->getName(), "CoeffNeg", coeffNeg); 396 406 getIdentifier()->addConfigValueContainer("CoeffNeg", cont); 397 407 } … … 401 411 if (!cont) 402 412 { 403 cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), "Zero", zero);413 cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), getIdentifier()->getName(), "Zero", zero); 404 414 getIdentifier()->addConfigValueContainer("Zero", cont); 405 415 } … … 515 525 516 526 joySticks_.clear(); 517 // don't use _ redimensionLists(), might mess with registered handler if527 // don't use _configureNumberOfJoySticks(), might mess with registered handler if 518 528 // downgrading from 2 to 1 joystick 519 //_ redimensionLists();529 //_configureNumberOfJoySticks(); 520 530 joySticksSize_ = 0; 521 531 } … … 875 885 // check whether the key already is in the list (can happen when focus was lost) 876 886 unsigned int iKey = 0; 877 while (iKey < keysDown_.size() && keysDown_[iKey].key != (KeyCode:: Enum)e.key)887 while (iKey < keysDown_.size() && keysDown_[iKey].key != (KeyCode::ByEnum)e.key) 878 888 iKey++; 879 889 if (iKey == keysDown_.size()) … … 912 922 for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++) 913 923 { 914 if (keysDown_[iKey].key == (KeyCode:: Enum)e.key)924 if (keysDown_[iKey].key == (KeyCode::ByEnum)e.key) 915 925 { 916 926 keysDown_.erase(keysDown_.begin() + iKey); … … 977 987 // check whether the button already is in the list (can happen when focus was lost) 978 988 unsigned int iButton = 0; 979 while (iButton < mouseButtonsDown_.size() && mouseButtonsDown_[iButton] != (MouseButton ::Enum)id)989 while (iButton < mouseButtonsDown_.size() && mouseButtonsDown_[iButton] != (MouseButtonCode::ByEnum)id) 980 990 iButton++; 981 991 if (iButton == mouseButtonsDown_.size()) 982 mouseButtonsDown_.push_back((MouseButton ::Enum)id);983 984 activeStatesTop_[Mouse]->mouseButtonPressed((MouseButton ::Enum)id);985 stateMaster_->mouseButtonPressed((MouseButton ::Enum)id);992 mouseButtonsDown_.push_back((MouseButtonCode::ByEnum)id); 993 994 activeStatesTop_[Mouse]->mouseButtonPressed((MouseButtonCode::ByEnum)id); 995 stateMaster_->mouseButtonPressed((MouseButtonCode::ByEnum)id); 986 996 987 997 return true; … … 1001 1011 for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) 1002 1012 { 1003 if (mouseButtonsDown_[iButton] == (MouseButton ::Enum)id)1013 if (mouseButtonsDown_[iButton] == (MouseButtonCode::ByEnum)id) 1004 1014 { 1005 1015 mouseButtonsDown_.erase(mouseButtonsDown_.begin() + iButton); … … 1008 1018 } 1009 1019 1010 activeStatesTop_[Mouse]->mouseButtonReleased((MouseButton ::Enum)id);1011 stateMaster_->mouseButtonReleased((MouseButton ::Enum)id);1020 activeStatesTop_[Mouse]->mouseButtonReleased((MouseButtonCode::ByEnum)id); 1021 stateMaster_->mouseButtonReleased((MouseButtonCode::ByEnum)id); 1012 1022 1013 1023 return true; … … 1038 1048 1039 1049 // check whether the button already is in the list (can happen when focus was lost) 1040 std::vector<JoyStickButton ::Enum>& buttonsDown = joyStickButtonsDown_[iJoyStick];1050 std::vector<JoyStickButtonCode::ByEnum>& buttonsDown = joyStickButtonsDown_[iJoyStick]; 1041 1051 unsigned int iButton = 0; 1042 1052 while (iButton < buttonsDown.size() && buttonsDown[iButton] != button) 1043 1053 iButton++; 1044 1054 if (iButton == buttonsDown.size()) 1045 buttonsDown.push_back((JoyStickButton ::Enum)button);1046 1047 activeStatesTop_[2 + iJoyStick]->joyStickButtonPressed(iJoyStick, (JoyStickButton ::Enum)button);1048 stateMaster_->joyStickButtonPressed(iJoyStick, (JoyStickButton ::Enum)button);1055 buttonsDown.push_back((JoyStickButtonCode::ByEnum)button); 1056 1057 activeStatesTop_[2 + iJoyStick]->joyStickButtonPressed(iJoyStick, (JoyStickButtonCode::ByEnum)button); 1058 stateMaster_->joyStickButtonPressed(iJoyStick, (JoyStickButtonCode::ByEnum)button); 1049 1059 1050 1060 return true; … … 1056 1066 1057 1067 // remove the button from the joyStickButtonsDown_ list 1058 std::vector<JoyStickButton ::Enum>& buttonsDown = joyStickButtonsDown_[iJoyStick];1068 std::vector<JoyStickButtonCode::ByEnum>& buttonsDown = joyStickButtonsDown_[iJoyStick]; 1059 1069 for (unsigned int iButton = 0; iButton < buttonsDown.size(); iButton++) 1060 1070 { … … 1066 1076 } 1067 1077 1068 activeStatesTop_[2 + iJoyStick]->joyStickButtonReleased(iJoyStick, (JoyStickButton ::Enum)button);1069 stateMaster_->joyStickButtonReleased(iJoyStick, (JoyStickButton ::Enum)button);1078 activeStatesTop_[2 + iJoyStick]->joyStickButtonReleased(iJoyStick, (JoyStickButtonCode::ByEnum)button); 1079 stateMaster_->joyStickButtonReleased(iJoyStick, (JoyStickButtonCode::ByEnum)button); 1070 1080 1071 1081 return true; … … 1177 1187 } 1178 1188 1189 /** 1190 @brief 1191 Sets the the name of the command used by the KeyDetector as callback. 1192 @param command 1193 Command name as string 1194 */ 1195 void InputManager::setKeyDetectorCallback(const std::string& command) 1196 { 1197 this->keyDetector_->setCallbackCommand(command); 1198 } 1179 1199 1180 1200 // ###### InputStates ###### … … 1356 1376 /** 1357 1377 @brief 1358 Method for easily storing a string with the command executor. It is used by the1359 KeyDetector to get assign commands. The KeyDetector simply executes1360 the command 'storeKeyStroke myName' for each button/axis.1361 @remarks1362 This is only a temporary hack until we thourouhgly support multiple KeyBinders.1363 @param name1364 The name of the button/axis.1365 */1366 void InputManager::storeKeyStroke(const std::string& name)1367 {1368 getInstance().requestLeaveState("detector");1369 COUT(0) << "Binding string \"" << bindingCommmandString_s << "\" on key '" << name << "'" << std::endl;1370 CommandExecutor::execute("config KeyBinder " + name + " " + bindingCommmandString_s, false);1371 }1372 1373 /**1374 @brief1375 Assigns a command string to a key/button/axis. The name is determined via KeyDetector1376 and InputManager::storeKeyStroke(.).1377 @param command1378 Command string that can be executed by the CommandExecutor1379 */1380 void InputManager::keyBind(const std::string& command)1381 {1382 bindingCommmandString_s = command;1383 getInstance().requestEnterState("detector");1384 COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl;1385 }1386 1387 /**1388 @brief1389 1378 Starts joy stick calibration. 1390 1379 */
Note: See TracChangeset
for help on using the changeset viewer.