| 1 | /* |
|---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
|---|
| 3 | * |
|---|
| 4 | * |
|---|
| 5 | * License notice: |
|---|
| 6 | * |
|---|
| 7 | * This program is free software; you can redistribute it and/or |
|---|
| 8 | * modify it under the terms of the GNU General Public License |
|---|
| 9 | * as published by the Free Software Foundation; either version 2 |
|---|
| 10 | * of the License, or (at your option) any later version. |
|---|
| 11 | * |
|---|
| 12 | * This program is distributed in the hope that it will be useful, |
|---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | * GNU General Public License for more details. |
|---|
| 16 | * |
|---|
| 17 | * You should have received a copy of the GNU General Public License |
|---|
| 18 | * along with this program; if not, write to the Free Software |
|---|
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|---|
| 20 | * |
|---|
| 21 | * Author: |
|---|
| 22 | * Reto Grieder |
|---|
| 23 | * Co-authors: |
|---|
| 24 | * ... |
|---|
| 25 | * |
|---|
| 26 | */ |
|---|
| 27 | |
|---|
| 28 | /** |
|---|
| 29 | @file |
|---|
| 30 | @brief Implementation of the different input handlers. |
|---|
| 31 | */ |
|---|
| 32 | |
|---|
| 33 | #include "Debug.h" |
|---|
| 34 | #include "util/Convert.h" |
|---|
| 35 | #include "InputEventListener.h" |
|---|
| 36 | #include "InputEvent.h" |
|---|
| 37 | #include "InputHandler.h" |
|---|
| 38 | |
|---|
| 39 | namespace orxonox |
|---|
| 40 | { |
|---|
| 41 | // ############################### |
|---|
| 42 | // ### InputHandlerGame ### |
|---|
| 43 | // ############################### |
|---|
| 44 | |
|---|
| 45 | /** |
|---|
| 46 | @brief standard constructor |
|---|
| 47 | */ |
|---|
| 48 | InputHandlerGame::InputHandlerGame() |
|---|
| 49 | { |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | /** |
|---|
| 53 | @brief Destructor |
|---|
| 54 | */ |
|---|
| 55 | InputHandlerGame::~InputHandlerGame() |
|---|
| 56 | { |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | /** |
|---|
| 60 | @brief Loads the key bindings from the ini file. |
|---|
| 61 | Currently, this is just a simple test routine that fills the list with numbers. |
|---|
| 62 | */ |
|---|
| 63 | bool InputHandlerGame::loadBindings() |
|---|
| 64 | { |
|---|
| 65 | for (int i = 0; i < numberOfKeys_s; i++) |
|---|
| 66 | { |
|---|
| 67 | // simply write the key number (i) in the string |
|---|
| 68 | this->bindingsKeyPressed_[i] = ConvertValueAndReturn<int, std::string>(i); |
|---|
| 69 | this->bindingsKeyReleased_[i] = ConvertValueAndReturn<int, std::string>(i); |
|---|
| 70 | } |
|---|
| 71 | return true; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | /** |
|---|
| 75 | @brief Event handler for the keyPressed Event. |
|---|
| 76 | @param e Event information |
|---|
| 77 | */ |
|---|
| 78 | bool InputHandlerGame::keyPressed(const OIS::KeyEvent &e) |
|---|
| 79 | { |
|---|
| 80 | if (e.key == OIS::KC_ESCAPE) |
|---|
| 81 | { |
|---|
| 82 | InputEvent e = {1, true, 0, 0, 0}; |
|---|
| 83 | InputHandlerGame::callListeners(e); |
|---|
| 84 | } |
|---|
| 85 | else |
|---|
| 86 | { |
|---|
| 87 | // find the appropriate key binding |
|---|
| 88 | std::string cmdStr = bindingsKeyPressed_[int(e.key)]; |
|---|
| 89 | //COUT(3) << cmdStr << " pressed" << std::endl; |
|---|
| 90 | } |
|---|
| 91 | return true; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | /** |
|---|
| 95 | @brief Event handler for the keyReleased Event. |
|---|
| 96 | @param e Event information |
|---|
| 97 | */ |
|---|
| 98 | bool InputHandlerGame::keyReleased(const OIS::KeyEvent &e) |
|---|
| 99 | { |
|---|
| 100 | // find the appropriate key binding |
|---|
| 101 | std::string cmdStr = bindingsKeyReleased_[int(e.key)]; |
|---|
| 102 | //COUT(3) << cmdStr << " released" << std::endl; |
|---|
| 103 | return true; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | /** |
|---|
| 107 | @brief Event handler for the mouseMoved Event. |
|---|
| 108 | @param e Event information |
|---|
| 109 | */ |
|---|
| 110 | bool InputHandlerGame::mouseMoved(const OIS::MouseEvent &e) |
|---|
| 111 | { |
|---|
| 112 | return true; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | /** |
|---|
| 116 | @brief Event handler for the mousePressed Event. |
|---|
| 117 | @param e Event information |
|---|
| 118 | @param id The ID of the mouse button |
|---|
| 119 | */ |
|---|
| 120 | bool InputHandlerGame::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id) |
|---|
| 121 | { |
|---|
| 122 | return true; |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | /** |
|---|
| 126 | @brief Event handler for the mouseReleased Event. |
|---|
| 127 | @param e Event information |
|---|
| 128 | @param id The ID of the mouse button |
|---|
| 129 | */ |
|---|
| 130 | bool InputHandlerGame::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) |
|---|
| 131 | { |
|---|
| 132 | return true; |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | /** |
|---|
| 136 | @brief Calls all the objects from classes that derive from InputEventListener. |
|---|
| 137 | @param evt The input event that occured. |
|---|
| 138 | */ |
|---|
| 139 | inline void InputHandlerGame::callListeners(orxonox::InputEvent &evt) |
|---|
| 140 | { |
|---|
| 141 | for (Iterator<InputEventListener> it = ObjectList<InputEventListener>::start(); it; ) |
|---|
| 142 | { |
|---|
| 143 | if (it->bActive_) |
|---|
| 144 | (it++)->eventOccured(evt); |
|---|
| 145 | else |
|---|
| 146 | it++; |
|---|
| 147 | } |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | // ############################### |
|---|
| 152 | // ### InputHandlerGUI ### |
|---|
| 153 | // ############################### |
|---|
| 154 | |
|---|
| 155 | /** |
|---|
| 156 | @brief standard constructor |
|---|
| 157 | */ |
|---|
| 158 | InputHandlerGUI::InputHandlerGUI() |
|---|
| 159 | { |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | /** |
|---|
| 163 | @brief Destructor |
|---|
| 164 | */ |
|---|
| 165 | InputHandlerGUI::~InputHandlerGUI() |
|---|
| 166 | { |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | /** |
|---|
| 170 | @brief Event handler for the keyPressed Event. |
|---|
| 171 | @param e Event information |
|---|
| 172 | */ |
|---|
| 173 | bool InputHandlerGUI::keyPressed(const OIS::KeyEvent &e) |
|---|
| 174 | { |
|---|
| 175 | //CEGUI::System::getSingleton().injectKeyDown( arg.key ); |
|---|
| 176 | //CEGUI::System::getSingleton().injectChar( arg.text ); |
|---|
| 177 | return true; |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | /** |
|---|
| 181 | @brief Event handler for the keyReleased Event. |
|---|
| 182 | @param e Event information |
|---|
| 183 | */ |
|---|
| 184 | bool InputHandlerGUI::keyReleased(const OIS::KeyEvent &e) |
|---|
| 185 | { |
|---|
| 186 | //CEGUI::System::getSingleton().injectKeyUp( arg.key ); |
|---|
| 187 | return true; |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | /** |
|---|
| 191 | @brief Event handler for the mouseMoved Event. |
|---|
| 192 | @param e Event information |
|---|
| 193 | */ |
|---|
| 194 | bool InputHandlerGUI::mouseMoved(const OIS::MouseEvent &e) |
|---|
| 195 | { |
|---|
| 196 | //CEGUI::System::getSingleton().injectMouseMove( arg.state.X.rel, arg.state.Y.rel ); |
|---|
| 197 | return true; |
|---|
| 198 | } |
|---|
| 199 | |
|---|
| 200 | /** |
|---|
| 201 | @brief Event handler for the mousePressed Event. |
|---|
| 202 | @param e Event information |
|---|
| 203 | @param id The ID of the mouse button |
|---|
| 204 | */ |
|---|
| 205 | bool InputHandlerGUI::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id) |
|---|
| 206 | { |
|---|
| 207 | //CEGUI::System::getSingleton().injectMouseButtonDown(convertOISMouseButtonToCegui(id)); |
|---|
| 208 | return true; |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | /** |
|---|
| 212 | @brief Event handler for the mouseReleased Event. |
|---|
| 213 | @param e Event information |
|---|
| 214 | @param id The ID of the mouse button |
|---|
| 215 | */ |
|---|
| 216 | bool InputHandlerGUI::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) |
|---|
| 217 | { |
|---|
| 218 | //CEGUI::System::getSingleton().injectMouseButtonUp(convertOISMouseButtonToCegui(id)); |
|---|
| 219 | return true; |
|---|
| 220 | } |
|---|
| 221 | |
|---|
| 222 | } |
|---|