[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" |
---|
| 37 | #include "InputEventListener.h" |
---|
| 38 | #include "InputEvent.h" |
---|
[1066] | 39 | #include "InputManager.h" |
---|
[1112] | 40 | #include "core/CommandExecutor.h" |
---|
[971] | 41 | |
---|
| 42 | namespace orxonox |
---|
| 43 | { |
---|
[973] | 44 | // ############################### |
---|
| 45 | // ### InputHandlerGame ### |
---|
| 46 | // ############################### |
---|
| 47 | |
---|
[971] | 48 | /** |
---|
| 49 | @brief standard constructor |
---|
| 50 | */ |
---|
[973] | 51 | InputHandlerGame::InputHandlerGame() |
---|
| 52 | { |
---|
| 53 | } |
---|
[971] | 54 | |
---|
[973] | 55 | /** |
---|
| 56 | @brief Destructor |
---|
| 57 | */ |
---|
| 58 | InputHandlerGame::~InputHandlerGame() |
---|
| 59 | { |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | /** |
---|
[1022] | 63 | @brief Loads the key bindings from the ini file. |
---|
| 64 | Currently, this is just a simple test routine that fills the list with numbers. |
---|
| 65 | */ |
---|
| 66 | bool InputHandlerGame::loadBindings() |
---|
| 67 | { |
---|
| 68 | for (int i = 0; i < numberOfKeys_s; i++) |
---|
| 69 | { |
---|
| 70 | // simply write the key number (i) in the string |
---|
[1112] | 71 | this->bindingsKeyPress_[i] = ""; |
---|
| 72 | this->bindingsKeyRelease_[i] = ""; |
---|
[1022] | 73 | } |
---|
[1112] | 74 | this->bindingsKeyPress_[OIS::KC_NUMPADENTER] = "setInputMode " + getConvertedValue<int, std::string>(IM_KEYBOARD); |
---|
| 75 | this->bindingsKeyPress_[OIS::KC_ESCAPE] = "exit"; |
---|
[1022] | 76 | return true; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | /** |
---|
[973] | 80 | @brief Event handler for the keyPressed Event. |
---|
| 81 | @param e Event information |
---|
| 82 | */ |
---|
| 83 | bool InputHandlerGame::keyPressed(const OIS::KeyEvent &e) |
---|
| 84 | { |
---|
[1112] | 85 | // find the appropriate key binding |
---|
| 86 | std::string cmdStr = bindingsKeyPress_[int(e.key)]; |
---|
| 87 | if (cmdStr != "") |
---|
[1022] | 88 | { |
---|
[1112] | 89 | CommandExecutor::execute(cmdStr); |
---|
| 90 | COUT(3) << "Executing command: " << cmdStr << std::endl; |
---|
[1022] | 91 | } |
---|
[973] | 92 | return true; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | /** |
---|
| 96 | @brief Event handler for the keyReleased Event. |
---|
| 97 | @param e Event information |
---|
| 98 | */ |
---|
| 99 | bool InputHandlerGame::keyReleased(const OIS::KeyEvent &e) |
---|
| 100 | { |
---|
[1022] | 101 | // find the appropriate key binding |
---|
[1112] | 102 | std::string cmdStr = bindingsKeyRelease_[int(e.key)]; |
---|
| 103 | if (cmdStr != "") |
---|
| 104 | { |
---|
| 105 | CommandExecutor::execute(cmdStr); |
---|
| 106 | COUT(3) << "Executing command: " << cmdStr << std::endl; |
---|
| 107 | } |
---|
[973] | 108 | return true; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | /** |
---|
| 112 | @brief Event handler for the mouseMoved Event. |
---|
| 113 | @param e Event information |
---|
| 114 | */ |
---|
| 115 | bool InputHandlerGame::mouseMoved(const OIS::MouseEvent &e) |
---|
| 116 | { |
---|
| 117 | return true; |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | /** |
---|
| 121 | @brief Event handler for the mousePressed Event. |
---|
| 122 | @param e Event information |
---|
| 123 | @param id The ID of the mouse button |
---|
| 124 | */ |
---|
| 125 | bool InputHandlerGame::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id) |
---|
| 126 | { |
---|
| 127 | return true; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | /** |
---|
| 131 | @brief Event handler for the mouseReleased Event. |
---|
| 132 | @param e Event information |
---|
| 133 | @param id The ID of the mouse button |
---|
| 134 | */ |
---|
| 135 | bool InputHandlerGame::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) |
---|
| 136 | { |
---|
| 137 | return true; |
---|
| 138 | } |
---|
| 139 | |
---|
[1022] | 140 | /** |
---|
| 141 | @brief Calls all the objects from classes that derive from InputEventListener. |
---|
| 142 | @param evt The input event that occured. |
---|
| 143 | */ |
---|
| 144 | inline void InputHandlerGame::callListeners(orxonox::InputEvent &evt) |
---|
| 145 | { |
---|
| 146 | for (Iterator<InputEventListener> it = ObjectList<InputEventListener>::start(); it; ) |
---|
| 147 | { |
---|
| 148 | if (it->bActive_) |
---|
| 149 | (it++)->eventOccured(evt); |
---|
| 150 | else |
---|
| 151 | it++; |
---|
| 152 | } |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | |
---|
[973] | 156 | // ############################### |
---|
| 157 | // ### InputHandlerGUI ### |
---|
| 158 | // ############################### |
---|
| 159 | |
---|
| 160 | /** |
---|
| 161 | @brief standard constructor |
---|
| 162 | */ |
---|
| 163 | InputHandlerGUI::InputHandlerGUI() |
---|
| 164 | { |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | /** |
---|
| 168 | @brief Destructor |
---|
| 169 | */ |
---|
| 170 | InputHandlerGUI::~InputHandlerGUI() |
---|
| 171 | { |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | /** |
---|
| 175 | @brief Event handler for the keyPressed Event. |
---|
| 176 | @param e Event information |
---|
| 177 | */ |
---|
| 178 | bool InputHandlerGUI::keyPressed(const OIS::KeyEvent &e) |
---|
| 179 | { |
---|
[1022] | 180 | //CEGUI::System::getSingleton().injectKeyDown( arg.key ); |
---|
| 181 | //CEGUI::System::getSingleton().injectChar( arg.text ); |
---|
[973] | 182 | return true; |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | /** |
---|
| 186 | @brief Event handler for the keyReleased Event. |
---|
| 187 | @param e Event information |
---|
| 188 | */ |
---|
| 189 | bool InputHandlerGUI::keyReleased(const OIS::KeyEvent &e) |
---|
| 190 | { |
---|
[1022] | 191 | //CEGUI::System::getSingleton().injectKeyUp( arg.key ); |
---|
[973] | 192 | return true; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | /** |
---|
| 196 | @brief Event handler for the mouseMoved Event. |
---|
| 197 | @param e Event information |
---|
| 198 | */ |
---|
| 199 | bool InputHandlerGUI::mouseMoved(const OIS::MouseEvent &e) |
---|
| 200 | { |
---|
[1022] | 201 | //CEGUI::System::getSingleton().injectMouseMove( arg.state.X.rel, arg.state.Y.rel ); |
---|
[973] | 202 | return true; |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | /** |
---|
| 206 | @brief Event handler for the mousePressed Event. |
---|
| 207 | @param e Event information |
---|
| 208 | @param id The ID of the mouse button |
---|
| 209 | */ |
---|
| 210 | bool InputHandlerGUI::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id) |
---|
| 211 | { |
---|
[1022] | 212 | //CEGUI::System::getSingleton().injectMouseButtonDown(convertOISMouseButtonToCegui(id)); |
---|
[973] | 213 | return true; |
---|
| 214 | } |
---|
| 215 | |
---|
| 216 | /** |
---|
| 217 | @brief Event handler for the mouseReleased Event. |
---|
| 218 | @param e Event information |
---|
| 219 | @param id The ID of the mouse button |
---|
| 220 | */ |
---|
| 221 | bool InputHandlerGUI::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) |
---|
| 222 | { |
---|
[1022] | 223 | //CEGUI::System::getSingleton().injectMouseButtonUp(convertOISMouseButtonToCegui(id)); |
---|
[973] | 224 | return true; |
---|
| 225 | } |
---|
| 226 | |
---|
[971] | 227 | } |
---|