[971] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
[1056] | 3 | * > www.orxonox.net < |
---|
[971] | 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Reto Grieder |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
[973] | 28 | |
---|
[971] | 29 | /** |
---|
| 30 | @file |
---|
[973] | 31 | @brief Implementation of the different input handlers. |
---|
[971] | 32 | */ |
---|
| 33 | |
---|
[1062] | 34 | #include "InputHandler.h" |
---|
[1022] | 35 | #include "Debug.h" |
---|
| 36 | #include "util/Convert.h" |
---|
[1182] | 37 | #include "core/CommandExecutor.h" |
---|
[971] | 38 | |
---|
| 39 | namespace orxonox |
---|
| 40 | { |
---|
[973] | 41 | // ############################### |
---|
[1203] | 42 | // ###### KeyBinder ###### |
---|
[973] | 43 | // ############################### |
---|
| 44 | |
---|
[971] | 45 | /** |
---|
[1203] | 46 | @brief Constructor that does as little as necessary. |
---|
[971] | 47 | */ |
---|
[1203] | 48 | KeyBinder::KeyBinder() |
---|
[973] | 49 | { |
---|
[1203] | 50 | clearBindings(); |
---|
[973] | 51 | } |
---|
[971] | 52 | |
---|
[973] | 53 | /** |
---|
| 54 | @brief Destructor |
---|
| 55 | */ |
---|
[1203] | 56 | KeyBinder::~KeyBinder() |
---|
[973] | 57 | { |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | /** |
---|
[1203] | 61 | @brief Overwrites all bindings with "" |
---|
[1022] | 62 | */ |
---|
[1203] | 63 | void KeyBinder::clearBindings() |
---|
[1022] | 64 | { |
---|
| 65 | for (int i = 0; i < numberOfKeys_s; i++) |
---|
| 66 | { |
---|
[1203] | 67 | bindingsKeyPress_ [i] = ""; |
---|
| 68 | bindingsKeyRelease_[i] = ""; |
---|
| 69 | bindingsKeyHold_ [i] = ""; |
---|
[1022] | 70 | } |
---|
[1203] | 71 | for (int i = 0; i < numberOfMouseButtons_s; i++) |
---|
| 72 | { |
---|
| 73 | bindingsMouseButtonPress_ [i] = ""; |
---|
| 74 | bindingsMouseButtonRelease_[i] = ""; |
---|
| 75 | bindingsMouseButtonHold_ [i] = ""; |
---|
| 76 | } |
---|
| 77 | for (int i = 0; i < numberOfJoyStickButtons_s; i++) |
---|
| 78 | { |
---|
| 79 | bindingsJoyStickButtonPress_ [i] = ""; |
---|
| 80 | bindingsJoyStickButtonRelease_[i] = ""; |
---|
| 81 | bindingsJoyStickButtonHold_ [i] = ""; |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | /** |
---|
| 86 | @brief Loads the key and button bindings. |
---|
| 87 | @return True if loading succeeded. |
---|
| 88 | */ |
---|
| 89 | bool KeyBinder::loadBindings() |
---|
| 90 | { |
---|
| 91 | COUT(ORX_DEBUG) << "KeyBinder: Loading key bindings..." << std::endl; |
---|
| 92 | |
---|
| 93 | // clear all the bindings at first. |
---|
| 94 | clearBindings(); |
---|
| 95 | |
---|
| 96 | // TODO: Insert the code to load the bindings from file. |
---|
| 97 | bindingsKeyPress_[OIS::KC_NUMPADENTER] = "activateConsole"; |
---|
| 98 | bindingsKeyPress_[OIS::KC_ESCAPE] = "exit"; |
---|
| 99 | bindingsKeyHold_[OIS::KC_U] = "exec disco.txt"; |
---|
| 100 | |
---|
| 101 | COUT(ORX_DEBUG) << "KeyBinder: Loading key bindings done." << std::endl; |
---|
[1022] | 102 | return true; |
---|
| 103 | } |
---|
| 104 | |
---|
[1203] | 105 | |
---|
[1022] | 106 | /** |
---|
[973] | 107 | @brief Event handler for the keyPressed Event. |
---|
| 108 | @param e Event information |
---|
| 109 | */ |
---|
[1203] | 110 | bool KeyBinder::keyPressed(const OIS::KeyEvent &e) |
---|
[973] | 111 | { |
---|
[1182] | 112 | // find the appropriate key binding |
---|
| 113 | std::string cmdStr = bindingsKeyPress_[int(e.key)]; |
---|
| 114 | if (cmdStr != "") |
---|
[1022] | 115 | { |
---|
[1182] | 116 | CommandExecutor::execute(cmdStr); |
---|
| 117 | COUT(3) << "Executing command: " << cmdStr << std::endl; |
---|
[1022] | 118 | } |
---|
[1203] | 119 | |
---|
[973] | 120 | return true; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | /** |
---|
| 124 | @brief Event handler for the keyReleased Event. |
---|
| 125 | @param e Event information |
---|
| 126 | */ |
---|
[1203] | 127 | bool KeyBinder::keyReleased(const OIS::KeyEvent &e) |
---|
[973] | 128 | { |
---|
[1203] | 129 | // find the appropriate key binding |
---|
| 130 | std::string cmdStr = bindingsKeyRelease_[int(e.key)]; |
---|
| 131 | if (cmdStr != "") |
---|
[1182] | 132 | { |
---|
[1203] | 133 | CommandExecutor::execute(cmdStr); |
---|
| 134 | COUT(3) << "Executing command: " << cmdStr << std::endl; |
---|
[1182] | 135 | } |
---|
| 136 | |
---|
[1203] | 137 | return true; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | /** |
---|
| 141 | @brief Event handler for the keyHeld Event. |
---|
| 142 | @param e Event information |
---|
| 143 | */ |
---|
| 144 | bool KeyBinder::keyHeld(const OIS::KeyEvent &e) |
---|
| 145 | { |
---|
[1022] | 146 | // find the appropriate key binding |
---|
[1203] | 147 | std::string cmdStr = bindingsKeyHold_[int(e.key)]; |
---|
[1182] | 148 | if (cmdStr != "") |
---|
| 149 | { |
---|
| 150 | CommandExecutor::execute(cmdStr); |
---|
| 151 | COUT(3) << "Executing command: " << cmdStr << std::endl; |
---|
| 152 | } |
---|
[1203] | 153 | |
---|
[973] | 154 | return true; |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | /** |
---|
| 158 | @brief Event handler for the mouseMoved Event. |
---|
| 159 | @param e Event information |
---|
| 160 | */ |
---|
[1203] | 161 | bool KeyBinder::mouseMoved(const OIS::MouseEvent &e) |
---|
[973] | 162 | { |
---|
| 163 | return true; |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | /** |
---|
| 167 | @brief Event handler for the mousePressed Event. |
---|
| 168 | @param e Event information |
---|
| 169 | @param id The ID of the mouse button |
---|
| 170 | */ |
---|
[1203] | 171 | bool KeyBinder::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id) |
---|
[973] | 172 | { |
---|
[1203] | 173 | // find the appropriate key binding |
---|
| 174 | std::string cmdStr = bindingsMouseButtonPress_[int(id)]; |
---|
| 175 | if (cmdStr != "") |
---|
| 176 | { |
---|
| 177 | CommandExecutor::execute(cmdStr); |
---|
| 178 | COUT(3) << "Executing command: " << cmdStr << std::endl; |
---|
| 179 | } |
---|
| 180 | |
---|
[973] | 181 | return true; |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | /** |
---|
| 185 | @brief Event handler for the mouseReleased Event. |
---|
| 186 | @param e Event information |
---|
| 187 | @param id The ID of the mouse button |
---|
| 188 | */ |
---|
[1203] | 189 | bool KeyBinder::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) |
---|
[973] | 190 | { |
---|
[1203] | 191 | // find the appropriate key binding |
---|
| 192 | std::string cmdStr = bindingsMouseButtonRelease_[int(id)]; |
---|
| 193 | if (cmdStr != "") |
---|
| 194 | { |
---|
| 195 | CommandExecutor::execute(cmdStr); |
---|
| 196 | COUT(3) << "Executing command: " << cmdStr << std::endl; |
---|
| 197 | } |
---|
| 198 | |
---|
[973] | 199 | return true; |
---|
| 200 | } |
---|
| 201 | |
---|
[1022] | 202 | /** |
---|
[1203] | 203 | @brief Event handler for the mouseHeld Event. |
---|
| 204 | @param e Event information |
---|
| 205 | @param id The ID of the mouse button |
---|
[1182] | 206 | */ |
---|
[1203] | 207 | bool KeyBinder::mouseHeld(const OIS::MouseEvent &e, OIS::MouseButtonID id) |
---|
[1182] | 208 | { |
---|
[1203] | 209 | // find the appropriate key binding |
---|
| 210 | std::string cmdStr = bindingsMouseButtonHold_[int(id)]; |
---|
| 211 | if (cmdStr != "") |
---|
[1182] | 212 | { |
---|
[1203] | 213 | CommandExecutor::execute(cmdStr); |
---|
| 214 | COUT(3) << "Executing command: " << cmdStr << std::endl; |
---|
[1182] | 215 | } |
---|
[1203] | 216 | |
---|
| 217 | return true; |
---|
[1182] | 218 | } |
---|
| 219 | |
---|
[1203] | 220 | bool KeyBinder::buttonPressed(const OIS::JoyStickEvent &arg, int button) |
---|
[1022] | 221 | { |
---|
[1203] | 222 | // find the appropriate key binding |
---|
| 223 | std::string cmdStr = bindingsJoyStickButtonPress_[button]; |
---|
| 224 | if (cmdStr != "") |
---|
[1022] | 225 | { |
---|
[1203] | 226 | CommandExecutor::execute(cmdStr); |
---|
| 227 | COUT(3) << "Executing command: " << cmdStr << std::endl; |
---|
[1022] | 228 | } |
---|
[1203] | 229 | |
---|
| 230 | return true; |
---|
| 231 | } |
---|
| 232 | |
---|
| 233 | bool KeyBinder::buttonReleased(const OIS::JoyStickEvent &arg, int button) |
---|
| 234 | { |
---|
| 235 | // find the appropriate key binding |
---|
| 236 | std::string cmdStr = bindingsJoyStickButtonRelease_[button]; |
---|
| 237 | if (cmdStr != "") |
---|
| 238 | { |
---|
| 239 | CommandExecutor::execute(cmdStr); |
---|
| 240 | COUT(3) << "Executing command: " << cmdStr << std::endl; |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | return true; |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | bool KeyBinder::buttonHeld(const OIS::JoyStickEvent &arg, int button) |
---|
| 247 | { |
---|
| 248 | // find the appropriate key binding |
---|
| 249 | std::string cmdStr = bindingsJoyStickButtonHold_[button]; |
---|
| 250 | if (cmdStr != "") |
---|
| 251 | { |
---|
| 252 | CommandExecutor::execute(cmdStr); |
---|
| 253 | COUT(3) << "Executing command: " << cmdStr << std::endl; |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | return true; |
---|
[1022] | 257 | } |
---|
| 258 | |
---|
[1203] | 259 | bool KeyBinder::axisMoved(const OIS::JoyStickEvent &arg, int axis) |
---|
| 260 | { |
---|
| 261 | return true; |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | bool KeyBinder::sliderMoved(const OIS::JoyStickEvent &arg, int id) |
---|
| 265 | { |
---|
| 266 | return true; |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | bool KeyBinder::povMoved(const OIS::JoyStickEvent &arg, int id) |
---|
| 270 | { |
---|
| 271 | return true; |
---|
| 272 | } |
---|
[1022] | 273 | |
---|
[1203] | 274 | |
---|
| 275 | |
---|
[973] | 276 | // ############################### |
---|
[1203] | 277 | // ### GUIInputHandler ### |
---|
[973] | 278 | // ############################### |
---|
| 279 | |
---|
[1203] | 280 | ///** |
---|
| 281 | // @brief standard constructor |
---|
| 282 | //*/ |
---|
| 283 | //GUIInputHandler::GUIInputHandler() |
---|
| 284 | //{ |
---|
| 285 | //} |
---|
[973] | 286 | |
---|
[1203] | 287 | ///** |
---|
| 288 | // @brief Destructor |
---|
| 289 | //*/ |
---|
| 290 | //GUIInputHandler::~GUIInputHandler() |
---|
| 291 | //{ |
---|
| 292 | //} |
---|
[973] | 293 | |
---|
[1203] | 294 | ///** |
---|
| 295 | // @brief Event handler for the keyPressed Event. |
---|
| 296 | // @param e Event information |
---|
| 297 | //*/ |
---|
| 298 | //bool GUIInputHandler::keyPressed(const OIS::KeyEvent &e) |
---|
| 299 | //{ |
---|
| 300 | ////CEGUI::System::getSingleton().injectKeyDown( arg.key ); |
---|
| 301 | ////CEGUI::System::getSingleton().injectChar( arg.text ); |
---|
| 302 | // return true; |
---|
| 303 | //} |
---|
[973] | 304 | |
---|
[1203] | 305 | ///** |
---|
| 306 | // @brief Event handler for the keyReleased Event. |
---|
| 307 | // @param e Event information |
---|
| 308 | //*/ |
---|
| 309 | //bool GUIInputHandler::keyReleased(const OIS::KeyEvent &e) |
---|
| 310 | //{ |
---|
| 311 | ////CEGUI::System::getSingleton().injectKeyUp( arg.key ); |
---|
| 312 | // return true; |
---|
| 313 | //} |
---|
[973] | 314 | |
---|
[1203] | 315 | ///** |
---|
| 316 | // @brief Event handler for the mouseMoved Event. |
---|
| 317 | // @param e Event information |
---|
| 318 | //*/ |
---|
| 319 | //bool GUIInputHandler::mouseMoved(const OIS::MouseEvent &e) |
---|
| 320 | //{ |
---|
| 321 | ////CEGUI::System::getSingleton().injectMouseMove( arg.state.X.rel, arg.state.Y.rel ); |
---|
| 322 | // return true; |
---|
| 323 | //} |
---|
[973] | 324 | |
---|
[1203] | 325 | ///** |
---|
| 326 | // @brief Event handler for the mousePressed Event. |
---|
| 327 | // @param e Event information |
---|
| 328 | // @param id The ID of the mouse button |
---|
| 329 | //*/ |
---|
| 330 | //bool GUIInputHandler::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id) |
---|
| 331 | //{ |
---|
| 332 | ////CEGUI::System::getSingleton().injectMouseButtonDown(convertOISMouseButtonToCegui(id)); |
---|
| 333 | // return true; |
---|
| 334 | //} |
---|
[973] | 335 | |
---|
[1203] | 336 | ///** |
---|
| 337 | // @brief Event handler for the mouseReleased Event. |
---|
| 338 | // @param e Event information |
---|
| 339 | // @param id The ID of the mouse button |
---|
| 340 | //*/ |
---|
| 341 | //bool GUIInputHandler::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) |
---|
| 342 | //{ |
---|
| 343 | ////CEGUI::System::getSingleton().injectMouseButtonUp(convertOISMouseButtonToCegui(id)); |
---|
| 344 | // return true; |
---|
| 345 | //} |
---|
[973] | 346 | |
---|
[971] | 347 | } |
---|