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