Changeset 5863 for code/branches
- Timestamp:
- Oct 3, 2009, 5:33:31 PM (15 years ago)
- Location:
- code/branches/core5
- Files:
-
- 2 added
- 1 deleted
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core5/data/defaultConfig/keybindings.ini
r5695 r5863 25 25 KeyEscape="exit" 26 26 KeyF="scale -1 moveUpDown" 27 KeyF1= 27 KeyF1="OverlayGroup toggleVisibility Debug" 28 28 KeyF10= 29 29 KeyF11= … … 41 41 KeyF9= 42 42 KeyG=greet 43 KeyGrave= 43 KeyGrave="openConsole" 44 44 KeyH= 45 45 KeyHome=showGUI … … 126 126 KeyU= 127 127 KeyUP="scale 1 moveFrontBack" 128 KeyUnassigned= 128 KeyUnassigned="openConsole" 129 129 KeyUnderline= 130 130 KeyUnlabeled= -
code/branches/core5/src/libraries/core/Core.cc
r5855 r5863 69 69 #include "TclThreadManager.h" 70 70 #include "input/InputManager.h" 71 #include "input/KeyBinderManager.h" 71 72 72 73 namespace orxonox … … 288 289 inputManager_.reset(new InputManager()); 289 290 291 // Manages KeyBinders and makes them available 292 keyBinderManager_.reset(new KeyBinderManager()); 293 290 294 // load the CEGUI interface 291 295 guiManager_.reset(new GUIManager(graphicsManager_->getRenderWindow(), … … 304 308 this->graphicsScope_.reset(); 305 309 this->guiManager_.reset(); 310 this->keyBinderManager_.reset(); 306 311 this->inputManager_.reset(); 307 312 this->graphicsManager_.reset(); -
code/branches/core5/src/libraries/core/Core.h
r5850 r5863 100 100 scoped_ptr<GraphicsManager> graphicsManager_; //!< Interface to OGRE 101 101 scoped_ptr<InputManager> inputManager_; //!< Interface to OIS 102 scoped_ptr<KeyBinderManager> keyBinderManager_; //!< Manages all KeyBinders 102 103 scoped_ptr<GUIManager> guiManager_; //!< Interface to GUI 103 104 scoped_ptr<Scope<ScopeID::Root> > rootScope_; -
code/branches/core5/src/libraries/core/CorePrereqs.h
r5858 r5863 212 212 class JoyStick; 213 213 class KeyBinder; 214 class KeyBinderManager; 214 215 class Keyboard; 215 216 class KeyDetector; -
code/branches/core5/src/libraries/core/input/CMakeLists.txt
r5738 r5863 9 9 JoyStickQuantityListener.cc 10 10 KeyBinder.cc 11 KeyBinderManager.cc 11 12 Keyboard.cc 12 13 KeyDetector.cc -
code/branches/core5/src/libraries/core/input/InputManager.cc
r5855 r5863 264 264 } 265 265 266 void InputManager::setKeyDetectorCallback(const std::string& command)267 {268 this->keyDetector_->setCallbackCommand(command);269 }270 271 266 // ############################################################ 272 267 // ##### Destruction ##### -
code/branches/core5/src/libraries/core/input/InputManager.h
r5738 r5863 161 161 // Various getters and setters 162 162 //------------------------------- 163 //! Sets the the name of the command used by the KeyDetector as callback.164 void setKeyDetectorCallback(const std::string& command);165 163 //! Returns the number of joy stick that have been created since the c'tor or last call to reload(). 166 164 unsigned int getJoyStickQuantity() const -
code/branches/core5/src/libraries/core/input/KeyBinder.cc
r5738 r5863 27 27 */ 28 28 29 /**30 @file31 @brief Implementation of the different input handlers.32 */33 34 29 #include "KeyBinder.h" 35 30 36 31 #include "util/Convert.h" 37 32 #include "util/Debug.h" 33 #include "util/Exception.h" 38 34 #include "core/ConfigValueIncludes.h" 39 35 #include "core/CoreIncludes.h" … … 48 44 Constructor that does as little as necessary. 49 45 */ 50 KeyBinder::KeyBinder( )46 KeyBinder::KeyBinder(const std::string& filename) 51 47 : deriveTime_(0.0f) 48 , filename_(filename) 52 49 { 53 50 mouseRelative_[0] = 0; … … 103 100 // set them here to use allHalfAxes_ 104 101 setConfigValues(); 102 103 // Load the bindings if filename was given 104 if (!this->filename_.empty()) 105 this->loadBindings(); 105 106 } 106 107 … … 240 241 @brief 241 242 Loads the key and button bindings. 242 @return 243 True if loading succeeded. 244 */ 245 void KeyBinder::loadBindings(const std::string& filename) 243 */ 244 void KeyBinder::loadBindings() 246 245 { 247 246 COUT(3) << "KeyBinder: Loading key bindings..." << std::endl; 248 247 249 if (filename.empty()) 250 return; 251 252 if (this->configFile_ == ConfigFileType::NoType) 253 { 254 // Get a new ConfigFileType from the ConfigFileManager 255 this->configFile_ = ConfigFileManager::getInstance().getNewConfigFileType(); 256 } 257 258 ConfigFileManager::getInstance().setFilename(this->configFile_, filename); 248 // Get a new ConfigFileType from the ConfigFileManager 249 this->configFile_ = ConfigFileManager::getInstance().getNewConfigFileType(); 250 251 ConfigFileManager::getInstance().setFilename(this->configFile_, this->filename_); 259 252 260 253 // Parse bindings and create the ConfigValueContainers if necessary 261 clearBindings();262 254 for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it) 263 255 it->second->readConfigValue(this->configFile_); -
code/branches/core5/src/libraries/core/input/KeyBinder.h
r5738 r5863 26 26 * 27 27 */ 28 29 /**30 @file31 @brief32 Different definitions of input processing.33 */34 28 35 29 #ifndef _KeyBinder_H__ … … 53 47 /** 54 48 @brief 55 Handles mouse, keyboard and joy stick input while in the actual game mode. 56 Manages the key bindings. 49 Maps mouse, keyboard and joy stick input to command strings and executes them. 50 51 The bindings are stored in ini-files (like the one for configValues) in the config Path. 52 @remarks 53 You cannot change the filename because the KeyBinderManager maps these filenames to the 54 KeyBinders. If you need to load other bindings, just create a new one. 57 55 */ 58 56 class _CoreExport KeyBinder : public InputHandler, public JoyStickQuantityListener 59 57 { 60 58 public: 61 KeyBinder ( );59 KeyBinder (const std::string& filename); 62 60 virtual ~KeyBinder(); 63 61 64 void loadBindings(const std::string& filename);65 62 void clearBindings(); 66 63 bool setBinding(const std::string& binding, const std::string& name, bool bTemporary = false); 64 const std::string& getBindingsFilename() 65 { return this->filename_; } 67 66 void setConfigValues(); 68 67 void resetJoyStickAxes(); 69 68 70 69 protected: // functions 70 void loadBindings(); 71 void buttonThresholdChanged(); 72 void initialiseJoyStickBindings(); 73 void compilePointerLists(); 74 // from JoyStickQuantityListener interface 75 virtual void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList); 76 71 77 void allDevicesUpdated(float dt); 72 78 void mouseUpdated(float dt); … … 74 80 // internal 75 81 void tickHalfAxis(HalfAxis& halfAxis); 76 77 void buttonThresholdChanged();78 // from JoyStickQuantityListener interface79 virtual void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList);80 void initialiseJoyStickBindings();81 void compilePointerLists();82 82 83 83 void buttonPressed (const KeyEvent& evt); … … 144 144 float deriveTime_; 145 145 146 //! Name of the file used in this KeyBinder (constant!) 147 const std::string filename_; 146 148 //! Config file used. ConfigFileType::NoType in case of KeyDetector. Also indicates whether we've already loaded. 147 149 ConfigFileType configFile_; … … 171 173 }; 172 174 175 173 176 inline void KeyBinder::buttonPressed (const KeyEvent& evt) 174 177 { assert(!keys_[evt.getKeyCode()].name_.empty()); keys_[evt.getKeyCode()].execute(KeybindMode::OnPress); } -
code/branches/core5/src/orxonox/gamestates/GSGraphics.cc
r5855 r5863 41 41 #include "core/Game.h" 42 42 #include "core/GUIManager.h" 43 #include "core/input/InputManager.h"44 #include "core/input/KeyBinder.h"45 #include "core/input/InputState.h"46 43 #include "core/Loader.h" 47 44 #include "core/XMLFile.h" … … 56 53 GSGraphics::GSGraphics(const GameStateInfo& info) 57 54 : GameState(info) 58 , masterKeyBinder_(0)59 , masterInputState_(0)60 55 , debugOverlay_(0) 61 56 { 62 // load master key bindings63 masterInputState_ = InputManager::getInstance().createInputState("master", true);64 masterKeyBinder_ = new KeyBinder();65 masterInputState_->setKeyHandler(masterKeyBinder_);66 57 } 67 58 68 59 GSGraphics::~GSGraphics() 69 60 { 70 InputManager::getInstance().destroyState("master");71 this->masterKeyBinder_->destroy();72 61 } 73 62 … … 94 83 Loader::open(debugOverlay_); 95 84 96 masterKeyBinder_->loadBindings("masterKeybindings.ini");97 98 85 // add console command to toggle GUI 99 86 this->ccToggleGUI_ = createConsoleCommand(createFunctor(&GSGraphics::toggleGUI, this), "toggleGUI"); 100 87 CommandExecutor::addConsoleCommandShortcut(this->ccToggleGUI_); 101 102 // enable master input103 InputManager::getInstance().enterState("master");104 88 } 105 89 -
code/branches/core5/src/orxonox/gamestates/GSGraphics.h
r5850 r5863 60 60 61 61 private: 62 KeyBinder* masterKeyBinder_; //!< Key binder for master key bindings63 InputState* masterInputState_; //!< Special input state for master input64 62 XMLFile* debugOverlay_; 65 63 ConsoleCommand* ccToggleGUI_; //!< Console command to toggle GUI -
code/branches/core5/src/orxonox/gamestates/GSLevel.cc
r5855 r5863 35 35 #include "core/input/InputManager.h" 36 36 #include "core/input/InputState.h" 37 #include "core/input/KeyBinder .h"37 #include "core/input/KeyBinderManager.h" 38 38 #include "core/ConsoleCommand.h" 39 39 #include "core/ConfigValueIncludes.h" … … 57 57 GSLevel::GSLevel(const GameStateInfo& info) 58 58 : GameState(info) 59 , keyBinder_(0)60 59 , gameInputState_(0) 61 60 , guiMouseOnlyInputState_(0) … … 63 62 { 64 63 RegisterObject(GSLevel); 65 66 this->ccKeybind_ = 0;67 this->ccTkeybind_ = 0;68 64 } 69 65 … … 74 70 void GSLevel::setConfigValues() 75 71 { 76 SetConfigValue(keyDetectorCallbackCode_, "KeybindBindingStringKeyName=");77 72 } 78 73 … … 84 79 { 85 80 gameInputState_ = InputManager::getInstance().createInputState("game"); 86 keyBinder_ = new KeyBinder(); 87 keyBinder_->loadBindings("keybindings.ini"); 88 gameInputState_->setHandler(keyBinder_); 81 gameInputState_->setHandler(KeyBinderManager::getInstance().getDefaultAsHandler()); 82 KeyBinderManager::getInstance().setToDefault(); 89 83 90 84 guiMouseOnlyInputState_ = InputManager::getInstance().createInputState("guiMouseOnly"); … … 102 96 if (GameMode::showsGraphics()) 103 97 { 104 // keybind console command105 ccKeybind_ = createConsoleCommand(createFunctor(&GSLevel::keybind, this), "keybind");106 CommandExecutor::addConsoleCommandShortcut(ccKeybind_);107 ccTkeybind_ = createConsoleCommand(createFunctor(&GSLevel::tkeybind, this), "tkeybind");108 CommandExecutor::addConsoleCommandShortcut(ccTkeybind_);109 // set our console command as callback for the key detector110 InputManager::getInstance().setKeyDetectorCallback(std::string("keybind ") + keyDetectorCallbackCode_);111 112 98 // level is loaded: we can start capturing the input 113 99 InputManager::getInstance().enterState("game"); … … 136 122 void GSLevel::deactivate() 137 123 { 138 /*139 // destroy console commands140 if (this->ccKeybind_)141 {142 delete this->ccKeybind_;143 this->ccKeybind_ = 0;144 }145 if (this->ccTkeybind_)146 {147 delete this->ccTkeybind_;148 this->ccTkeybind_ = 0;149 }150 */151 152 124 if (GameMode::showsGraphics()) 153 125 { … … 181 153 InputManager::getInstance().destroyState("guiKeysOnly"); 182 154 InputManager::getInstance().destroyState("guiMouseOnly"); 183 if (this->keyBinder_)184 {185 this->keyBinder_->destroy();186 this->keyBinder_ = 0;187 }188 155 } 189 156 } … … 211 178 delete startFile_s; 212 179 } 213 214 void GSLevel::keybind(const std::string &command)215 {216 this->keybindInternal(command, false);217 }218 219 void GSLevel::tkeybind(const std::string &command)220 {221 this->keybindInternal(command, true);222 }223 224 /**225 @brief226 Assigns a command string to a key/button/axis. The name is determined via KeyDetector.227 @param command228 Command string that can be executed by the CommandExecutor229 OR: Internal string "KeybindBindingStringKeyName=" used for the second call to identify230 the key/button/axis that has been activated. This is configured above in activate().231 */232 void GSLevel::keybindInternal(const std::string& command, bool bTemporary)233 {234 if (GameMode::showsGraphics())235 {236 static std::string bindingString = "";237 static bool bTemporarySaved = false;238 static bool bound = true;239 // note: We use a long name to make 'sure' that the user doesn't use it accidentally.240 // Howerver there will be no real issue if it happens anyway.241 if (command.find(keyDetectorCallbackCode_) != 0)242 {243 if (bound)244 {245 COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl;246 InputManager::getInstance().enterState("detector");247 bindingString = command;248 bTemporarySaved = bTemporary;249 bound = false;250 }251 //else: We're still in a keybind command. ignore this call.252 }253 else254 {255 if (!bound)256 {257 // user has pressed the key258 std::string name = command.substr(this->keyDetectorCallbackCode_.size());259 COUT(0) << "Binding string \"" << bindingString << "\" on key '" << name << "'" << std::endl;260 this->keyBinder_->setBinding(bindingString, name, bTemporarySaved);261 InputManager::getInstance().leaveState("detector");262 bound = true;263 }264 // else: A key was pressed within the same tick, ignore it.265 }266 }267 }268 180 } -
code/branches/core5/src/orxonox/gamestates/GSLevel.h
r5850 r5863 57 57 void unloadLevel(); 58 58 59 // console commands60 void keybind(const std::string& command);61 void tkeybind(const std::string& command);62 void keybindInternal(const std::string& command, bool bTemporary);63 64 KeyBinder* keyBinder_; //!< tool that loads and manages the input bindings65 59 InputState* gameInputState_; //!< input state for normal ingame playing 66 60 InputState* guiMouseOnlyInputState_; //!< input state if we only need the mouse to use the GUI 67 61 InputState* guiKeysOnlyInputState_; //!< input state if we only need the keys to use the GUI 68 69 //##### ConfigValues #####70 std::string keyDetectorCallbackCode_;71 72 // console commands73 ConsoleCommand* ccKeybind_;74 ConsoleCommand* ccTkeybind_;75 62 }; 76 63 } -
code/branches/core5/src/orxonox/gamestates/GSMainMenu.cc
r5855 r5863 34 34 #include "core/input/InputManager.h" 35 35 #include "core/input/InputState.h" 36 #include "core/input/KeyBinderManager.h" 36 37 #include "core/Game.h" 37 38 #include "core/ConsoleCommand.h" … … 51 52 inputState_ = InputManager::getInstance().createInputState("mainMenu"); 52 53 inputState_->setHandler(GUIManager::getInstancePtr()); 54 inputState_->setKeyHandler(KeyBinderManager::getInstance().getDefaultAsHandler()); 53 55 inputState_->setJoyStickHandler(&InputHandler::EMPTY); 54 56 inputState_->setIsExclusiveMouse(false); … … 86 88 CommandExecutor::addConsoleCommandShortcut(this->ccStartMainMenu_); 87 89 90 KeyBinderManager::getInstance().setToDefault(); 88 91 InputManager::getInstance().enterState("mainMenu"); 89 92
Note: See TracChangeset
for help on using the changeset viewer.