[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 |
---|
[1022] | 31 | @brief Different definitions of input processing. |
---|
[971] | 32 | */ |
---|
[973] | 33 | |
---|
| 34 | #ifndef _InputHandler_H__ |
---|
| 35 | #define _InputHandler_H__ |
---|
| 36 | |
---|
[1062] | 37 | #include "CorePrereqs.h" |
---|
| 38 | |
---|
[1022] | 39 | #include <string> |
---|
[1219] | 40 | #include "ois/OIS.h" |
---|
| 41 | #include "OrxonoxClass.h" |
---|
| 42 | #include "CommandExecutor.h" |
---|
[973] | 43 | |
---|
| 44 | namespace orxonox |
---|
| 45 | { |
---|
[1219] | 46 | namespace KeybindSetting |
---|
| 47 | { |
---|
| 48 | enum KeybindSetting |
---|
| 49 | { |
---|
| 50 | None, |
---|
| 51 | OnPress, |
---|
| 52 | OnRelease, |
---|
| 53 | Continuous, |
---|
| 54 | }; |
---|
| 55 | } |
---|
| 56 | |
---|
[973] | 57 | /** |
---|
[1219] | 58 | @brief Interface class used for key input listeners. |
---|
[973] | 59 | */ |
---|
[1219] | 60 | class _CoreExport KeyHandler : public OIS::KeyListener |
---|
[973] | 61 | { |
---|
| 62 | public: |
---|
[1219] | 63 | virtual ~KeyHandler() { } |
---|
| 64 | virtual bool keyHeld(const OIS::KeyEvent &arg) = 0; |
---|
| 65 | }; |
---|
[973] | 66 | |
---|
[1219] | 67 | /** |
---|
| 68 | @brief Interface class used for mouse input listeners. |
---|
| 69 | */ |
---|
| 70 | class _CoreExport MouseHandler : public OIS::MouseListener |
---|
| 71 | { |
---|
| 72 | public: |
---|
| 73 | virtual ~MouseHandler() { } |
---|
| 74 | virtual bool mouseHeld(const OIS::MouseEvent &arg, OIS::MouseButtonID id) = 0; |
---|
| 75 | }; |
---|
| 76 | |
---|
| 77 | /** |
---|
| 78 | @brief Interface class used for joy stick input listeners. |
---|
| 79 | */ |
---|
| 80 | class _CoreExport JoyStickHandler |
---|
| 81 | { |
---|
| 82 | public: |
---|
| 83 | virtual ~JoyStickHandler() { } |
---|
| 84 | virtual bool buttonPressed (int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0; |
---|
| 85 | virtual bool buttonReleased(int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0; |
---|
| 86 | virtual bool buttonHeld (int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0; |
---|
| 87 | virtual bool axisMoved (int joyStickID, const OIS::JoyStickEvent &arg, int axis) = 0; |
---|
| 88 | virtual bool sliderMoved (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;} |
---|
| 89 | virtual bool povMoved (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;} |
---|
| 90 | virtual bool vector3Moved (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;} |
---|
| 91 | }; |
---|
| 92 | |
---|
| 93 | struct _CoreExport KeyBinding |
---|
| 94 | { |
---|
| 95 | std::string commandStr; |
---|
| 96 | CommandEvaluation evaluation; |
---|
| 97 | }; |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | /** |
---|
| 101 | @brief Captures mouse, keyboard and joy stick input while in the actual game mode. |
---|
| 102 | Manages the key bindings. |
---|
| 103 | */ |
---|
| 104 | class _CoreExport KeyBinder : public KeyHandler, public MouseHandler, public JoyStickHandler, public OrxonoxClass |
---|
| 105 | { |
---|
| 106 | public: |
---|
| 107 | KeyBinder (); |
---|
| 108 | ~KeyBinder(); |
---|
| 109 | |
---|
[1022] | 110 | bool loadBindings(); |
---|
[1219] | 111 | void clearBindings(); |
---|
| 112 | |
---|
| 113 | void setConfigValues(); |
---|
| 114 | |
---|
| 115 | std::string testtest; |
---|
[1022] | 116 | |
---|
[1219] | 117 | private: // functions |
---|
| 118 | |
---|
| 119 | bool executeBinding(KeyBinding &binding); |
---|
| 120 | |
---|
[973] | 121 | bool keyPressed (const OIS::KeyEvent &arg); |
---|
| 122 | bool keyReleased (const OIS::KeyEvent &arg); |
---|
[1219] | 123 | bool keyHeld (const OIS::KeyEvent &arg); |
---|
[1022] | 124 | |
---|
[1219] | 125 | bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id); |
---|
| 126 | bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id); |
---|
| 127 | bool mouseHeld (const OIS::MouseEvent &arg, OIS::MouseButtonID id); |
---|
| 128 | bool mouseMoved (const OIS::MouseEvent &arg); |
---|
[1022] | 129 | |
---|
[1219] | 130 | bool buttonPressed (int joyStickID, const OIS::JoyStickEvent &arg, int button); |
---|
| 131 | bool buttonReleased(int joyStickID, const OIS::JoyStickEvent &arg, int button); |
---|
| 132 | bool buttonHeld (int joyStickID, const OIS::JoyStickEvent &arg, int button); |
---|
| 133 | bool axisMoved (int joyStickID, const OIS::JoyStickEvent &arg, int axis); |
---|
| 134 | bool sliderMoved (int joyStickID, const OIS::JoyStickEvent &arg, int id); |
---|
| 135 | bool povMoved (int joyStickID, const OIS::JoyStickEvent &arg, int id); |
---|
| 136 | bool vector3Moved (int joyStickID, const OIS::JoyStickEvent &arg, int id); |
---|
[1022] | 137 | |
---|
[1219] | 138 | private: // variables |
---|
| 139 | |
---|
| 140 | //! denotes the number of different keys there are in OIS. |
---|
| 141 | static const int numberOfKeys_s = 0xEE; |
---|
[1022] | 142 | //! Array of input events for every pressed key |
---|
[1219] | 143 | KeyBinding bindingsKeyPress_ [numberOfKeys_s]; |
---|
[1022] | 144 | //! Array of input events for every released key |
---|
[1219] | 145 | KeyBinding bindingsKeyRelease_[numberOfKeys_s]; |
---|
| 146 | //! Array of input events for every held key |
---|
| 147 | KeyBinding bindingsKeyHold_ [numberOfKeys_s]; |
---|
| 148 | //! Names of the keys as strings |
---|
| 149 | std::string keyNames_[numberOfKeys_s]; |
---|
[1022] | 150 | |
---|
[1219] | 151 | //! denotes the number of different mouse buttons there are in OIS. |
---|
| 152 | static const int numberOfMouseButtons_s = 8; |
---|
| 153 | //! Array of input events for every pressed mouse button |
---|
| 154 | std::string bindingsMouseButtonPress_ [numberOfMouseButtons_s]; |
---|
| 155 | //! Array of input events for every released mouse button |
---|
| 156 | std::string bindingsMouseButtonRelease_[numberOfMouseButtons_s]; |
---|
| 157 | //! Array of input events for every held mouse button |
---|
| 158 | std::string bindingsMouseButtonHold_ [numberOfMouseButtons_s]; |
---|
| 159 | //! Names of the mouse buttons as strings |
---|
| 160 | std::string mouseButtonNames_[numberOfMouseButtons_s]; |
---|
| 161 | |
---|
| 162 | //! denotes the number of different joy stick buttons there are in OIS. |
---|
| 163 | static const int numberOfJoyStickButtons_s = 32; |
---|
| 164 | //! Array of input events for every pressed joy stick button |
---|
| 165 | std::string bindingsJoyStickButtonPress_ [numberOfJoyStickButtons_s]; |
---|
| 166 | //! Array of input events for every released joy stick button |
---|
| 167 | std::string bindingsJoyStickButtonRelease_[numberOfJoyStickButtons_s]; |
---|
| 168 | //! Array of input events for every held joy stick button |
---|
| 169 | std::string bindingsJoyStickButtonHold_ [numberOfJoyStickButtons_s]; |
---|
| 170 | //! Names of the joy stick buttons as strings |
---|
| 171 | std::string joyStickButtonNames_[numberOfJoyStickButtons_s]; |
---|
| 172 | |
---|
[973] | 173 | }; |
---|
| 174 | |
---|
| 175 | |
---|
| 176 | /** |
---|
[1022] | 177 | @brief Captures mouse and keyboard input and distributes it to the |
---|
| 178 | GUI. |
---|
[973] | 179 | */ |
---|
[1219] | 180 | //class _CoreExport GUIInputHandler : public KeyHandler, public MouseHandler, public JoyStickHandler |
---|
| 181 | //{ |
---|
| 182 | //public: |
---|
| 183 | // GUIInputHandler (); |
---|
| 184 | // ~GUIInputHandler(); |
---|
[973] | 185 | |
---|
[1219] | 186 | //private: |
---|
| 187 | // // input events |
---|
| 188 | //bool keyPressed (const OIS::KeyEvent &arg); |
---|
| 189 | //bool keyReleased (const OIS::KeyEvent &arg); |
---|
| 190 | //bool keyHeld (const OIS::KeyEvent &arg); |
---|
[973] | 191 | |
---|
[1219] | 192 | // bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id); |
---|
| 193 | //bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id); |
---|
| 194 | //bool mouseHeld (const OIS::MouseEvent &arg, OIS::MouseButtonID id); |
---|
| 195 | // bool mouseMoved (const OIS::MouseEvent &arg); |
---|
| 196 | |
---|
| 197 | //bool buttonPressed (const OIS::JoyStickEvent &arg, int button); |
---|
| 198 | //bool buttonReleased(const OIS::JoyStickEvent &arg, int button); |
---|
| 199 | //bool buttonHeld (const OIS::JoyStickEvent &arg, int button); |
---|
| 200 | //bool axisMoved (const OIS::JoyStickEvent &arg, int axis); |
---|
| 201 | //bool sliderMoved (const OIS::JoyStickEvent &arg, int id); |
---|
| 202 | //bool povMoved (const OIS::JoyStickEvent &arg, int id); |
---|
| 203 | //}; |
---|
| 204 | |
---|
[973] | 205 | } |
---|
| 206 | |
---|
| 207 | #endif /* _InputHandler_H__ */ |
---|