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