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