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