OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
inputmanagerimp.hpp
Go to the documentation of this file.
1 #ifndef MWINPUT_MWINPUTMANAGERIMP_H
2 #define MWINPUT_MWINPUTMANAGERIMP_H
3 
4 #include "../mwgui/mode.hpp"
5 
6 #include <osg/ref_ptr>
7 
8 #include <extern/oics/ICSChannelListener.h>
9 #include <extern/oics/ICSInputControlSystem.h>
10 
14 
15 #include "../mwbase/inputmanager.hpp"
16 
17 
18 namespace MWWorld
19 {
20  class Player;
21 }
22 
23 namespace MWBase
24 {
25  class WindowManager;
26 }
27 
28 namespace ICS
29 {
30  class InputControlSystem;
31 }
32 
33 namespace MyGUI
34 {
35  struct MouseButton;
36 }
37 
38 namespace Files
39 {
40  struct ConfigurationManager;
41 }
42 
43 namespace SDLUtil
44 {
45  class InputWrapper;
46  class VideoWrapper;
47 }
48 
49 namespace osgViewer
50 {
51  class Viewer;
52  class ScreenCaptureHandler;
53 }
54 
55 struct SDL_Window;
56 
57 namespace MWInput
58 {
59 
63  class InputManager :
64  public MWBase::InputManager,
65  public SDLUtil::KeyListener,
69  public ICS::ChannelListener,
70  public ICS::DetectingBindingListener
71  {
72  public:
74  SDL_Window* window,
75  osg::ref_ptr<osgViewer::Viewer> viewer,
76  osg::ref_ptr<osgViewer::ScreenCaptureHandler> screenCaptureHandler,
77  const std::string& userFile, bool userFileExists,
78  const std::string& controllerBindingsFile, bool grab);
79 
80  virtual ~InputManager();
81 
82  virtual bool isWindowVisible();
83 
85  virtual void clear();
86 
87  virtual void update(float dt, bool disableControls=false, bool disableEvents=false);
88 
89  void setPlayer (MWWorld::Player* player) { mPlayer = player; }
90 
91  virtual void changeInputMode(bool guiMode);
92 
93  virtual void processChangedSettings(const Settings::CategorySettingVector& changed);
94 
95  virtual void setDragDrop(bool dragDrop);
96 
97  virtual void toggleControlSwitch (const std::string& sw, bool value);
98  virtual bool getControlSwitch (const std::string& sw);
99 
100  virtual std::string getActionDescription (int action);
101  virtual std::string getActionKeyBindingName (int action);
102  virtual std::string getActionControllerBindingName (int action);
103  virtual int getNumActions() { return A_Last; }
104  virtual std::vector<int> getActionKeySorting();
105  virtual std::vector<int> getActionControllerSorting();
106  virtual void enableDetectingBindingMode (int action, bool keyboard);
107  virtual void resetToDefaultKeyBindings();
108  virtual void resetToDefaultControllerBindings();
109 
110  virtual bool joystickLastUsed() {return mJoystickLastUsed;}
111 
112  public:
113  virtual void keyPressed(const SDL_KeyboardEvent &arg );
114  virtual void keyReleased( const SDL_KeyboardEvent &arg );
115  virtual void textInput (const SDL_TextInputEvent &arg);
116 
117  virtual void mousePressed( const SDL_MouseButtonEvent &arg, Uint8 id );
118  virtual void mouseReleased( const SDL_MouseButtonEvent &arg, Uint8 id );
119  virtual void mouseMoved( const SDLUtil::MouseMotionEvent &arg );
120 
121  virtual void buttonPressed(int deviceID, const SDL_ControllerButtonEvent &arg);
122  virtual void buttonReleased(int deviceID, const SDL_ControllerButtonEvent &arg);
123  virtual void axisMoved(int deviceID, const SDL_ControllerAxisEvent &arg);
124  virtual void controllerAdded(int deviceID, const SDL_ControllerDeviceEvent &arg);
125  virtual void controllerRemoved(const SDL_ControllerDeviceEvent &arg);
126 
127  virtual void windowVisibilityChange( bool visible );
128  virtual void windowFocusChange( bool have_focus );
129  virtual void windowResized (int x, int y);
130  virtual void windowClosed ();
131 
132  virtual void channelChanged(ICS::Channel* channel, float currentValue, float previousValue);
133 
134  virtual void mouseAxisBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
135  , ICS::InputControlSystem::NamedAxis axis, ICS::Control::ControlChangingDirection direction);
136 
137  virtual void keyBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
138  , SDL_Scancode key, ICS::Control::ControlChangingDirection direction);
139 
140  virtual void mouseButtonBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
141  , unsigned int button, ICS::Control::ControlChangingDirection direction);
142 
143  virtual void joystickAxisBindingDetected(ICS::InputControlSystem* ICS, int deviceID, ICS::Control* control
144  , int axis, ICS::Control::ControlChangingDirection direction);
145 
146  virtual void joystickButtonBindingDetected(ICS::InputControlSystem* ICS, int deviceID, ICS::Control* control
147  , unsigned int button, ICS::Control::ControlChangingDirection direction);
148 
149  void clearAllKeyBindings (ICS::Control* control);
150  void clearAllControllerBindings (ICS::Control* control);
151 
152  virtual int countSavedGameRecords() const;
153  virtual void write(ESM::ESMWriter& writer, Loading::Listener& progress);
154  virtual void readRecord(ESM::ESMReader& reader, uint32_t type);
155 
156  private:
157  SDL_Window* mWindow;
159  osg::ref_ptr<osgViewer::Viewer> mViewer;
160  osg::ref_ptr<osgViewer::ScreenCaptureHandler> mScreenCaptureHandler;
161 
164 
165  ICS::InputControlSystem* mInputBinder;
166 
169 
170  std::string mUserFile;
171 
172  bool mDragDrop;
173 
175 
176  bool mInvertY;
177 
179 
183  float mTimeIdle;
184 
187 
189 
191 
192  float mGuiCursorX;
193  float mGuiCursorY;
198  bool mSneaking;
200 
201  std::map<std::string, bool> mControlSwitch;
202 
204 
205  private:
206  void convertMousePosForMyGUI(int& x, int& y);
207 
208  MyGUI::MouseButton sdlButtonToMyGUI(Uint8 button);
209 
210  virtual std::string sdlControllerAxisToString(int axis);
211  virtual std::string sdlControllerButtonToString(int button);
212 
213  void resetIdleTime();
214  void updateIdleTime(float dt);
215 
216  void setPlayerControlsEnabled(bool enabled);
217 
218  void updateCursorMode();
219 
220  bool checkAllowedToUseItems() const;
221 
222  private:
223  void toggleMainMenu();
224  void toggleSpell();
225  void toggleWeapon();
226  void toggleInventory();
227  void toggleConsole();
228  void screenshot();
229  void toggleJournal();
230  void activate();
231  void toggleWalking();
232  void toggleSneaking();
233  void toggleAutoMove();
234  void rest();
235  void quickLoad();
236  void quickSave();
237 
238  void quickKey (int index);
239  void showQuickKeysMenu();
240 
241  bool actionIsActive (int id);
242 
243  void loadKeyDefaults(bool force = false);
244  void loadControllerDefaults(bool force = false);
245 
246  int mFakeDeviceID; //As we only support one controller at a time, use a fake deviceID so we don't lose bindings when switching controllers
247 
248  private:
249  enum Actions
250  {
251  // please add new actions at the bottom, in order to preserve the channel IDs in the key configuration files
252 
254 
256 
257  A_Screenshot, // Take a screenshot
258 
259  A_Inventory, // Toggle inventory screen
260 
261  A_Console, // Toggle console screen
262 
263  A_MoveLeft, // Move player left / right
265  A_MoveForward, // Forward / Backward
267 
269 
270  A_Use, //Use weapon, spell, etc.
272  A_AutoMove, //Toggle Auto-move forward
273  A_Rest, //Rest
274  A_Journal, //Journal
275  A_Weapon, //Draw/Sheath weapon
276  A_Spell, //Ready/Unready Casting
277  A_Run, //Run when held
278  A_CycleSpellLeft, //cycling through spells
280  A_CycleWeaponLeft,//Cycling through weapons
282  A_ToggleSneak, //Toggles Sneak
283  A_AlwaysRun, //Toggle Walking/Running
285 
291 
293 
304 
306 
308 
310 
311  A_LookUpDown, //Joystick look
315 
316  A_Last // Marker for the last item
317  };
318  };
319 }
320 #endif
Definition: inputmanagerimp.hpp:266
bool mAlwaysRunActive
Definition: inputmanagerimp.hpp:196
Definition: inputmanagerimp.hpp:270
void toggleConsole()
Definition: inputmanagerimp.cpp:1000
virtual void resetToDefaultControllerBindings()
Definition: inputmanagerimp.cpp:1623
virtual void keyBindingDetected(ICS::InputControlSystem *ICS, ICS::Control *control, SDL_Scancode key, ICS::Control::ControlChangingDirection direction)
Definition: inputmanagerimp.cpp:1504
osg::ref_ptr< osgViewer::Viewer > mViewer
Definition: inputmanagerimp.hpp:159
Definition: sdlvideowrapper.hpp:18
void rest()
Definition: inputmanagerimp.cpp:955
Interface for input manager (implemented in MWInput)
Definition: inputmanager.hpp:24
virtual void readRecord(ESM::ESMReader &reader, uint32_t type)
Definition: inputmanagerimp.cpp:1601
int mMouseWheel
Definition: inputmanagerimp.hpp:194
virtual void mouseMoved(const SDLUtil::MouseMotionEvent &arg)
Definition: inputmanagerimp.cpp:747
Definition: inputmanagerimp.hpp:301
float mInvUiScalingFactor
Definition: inputmanagerimp.hpp:203
virtual int countSavedGameRecords() const
Definition: inputmanagerimp.cpp:1580
void updateCursorMode()
Definition: inputmanagerimp.cpp:333
Definition: inputmanagerimp.hpp:274
virtual void controllerRemoved(const SDL_ControllerDeviceEvent &arg)
Definition: inputmanagerimp.cpp:863
virtual void windowVisibilityChange(bool visible)
Definition: inputmanagerimp.cpp:872
Definition: inputmanagerimp.hpp:272
float mTimeIdle
Definition: inputmanagerimp.hpp:183
Definition: inputmanagerimp.hpp:263
virtual void keyPressed(const SDL_KeyboardEvent &arg)
Definition: inputmanagerimp.cpp:662
MyGUI::MouseButton sdlButtonToMyGUI(Uint8 button)
Definition: inputmanagerimp.cpp:1628
void quickSave()
Definition: inputmanagerimp.cpp:912
void clearAllControllerBindings(ICS::Control *control)
Definition: inputmanagerimp.cpp:1571
virtual void mouseButtonBindingDetected(ICS::InputControlSystem *ICS, ICS::Control *control, unsigned int button, ICS::Control::ControlChangingDirection direction)
Definition: inputmanagerimp.cpp:1524
Definition: inputmanagerimp.hpp:282
Definition: esmreader.hpp:21
Definition: inputmanagerimp.hpp:316
A wrapper around SDL's event queue, mostly used for handling input-related events.
Definition: sdlinputwrapper.hpp:22
void toggleAutoMove()
Definition: inputmanagerimp.cpp:1073
virtual void buttonReleased(int deviceID, const SDL_ControllerButtonEvent &arg)
Definition: inputmanagerimp.cpp:829
Definition: inputmanagerimp.hpp:257
virtual bool getControlSwitch(const std::string &sw)
Definition: inputmanagerimp.cpp:635
NPC object representing the player and additional player data.
Definition: player.hpp:30
Definition: events.hpp:65
Definition: inputmanagerimp.hpp:281
Definition: inputmanagerimp.hpp:265
Definition: inputmanagerimp.hpp:309
void quickKey(int index)
Definition: inputmanagerimp.cpp:1037
Definition: inputmanagerimp.hpp:312
Definition: events.hpp:15
Definition: inputmanagerimp.hpp:297
void setPlayer(MWWorld::Player *player)
Definition: inputmanagerimp.hpp:89
Definition: inputmanagerimp.hpp:305
virtual void windowFocusChange(bool have_focus)
Definition: inputmanagerimp.cpp:868
int mFakeDeviceID
Definition: inputmanagerimp.hpp:246
Definition: inputmanagerimp.hpp:279
virtual std::string sdlControllerButtonToString(int button)
Definition: inputmanagerimp.cpp:1357
Definition: inputmanagerimp.hpp:295
virtual std::string getActionDescription(int action)
Definition: inputmanagerimp.cpp:1276
virtual void changeInputMode(bool guiMode)
Definition: inputmanagerimp.cpp:585
bool mUserFileExists
Definition: inputmanagerimp.hpp:195
void setPlayerControlsEnabled(bool enabled)
Definition: inputmanagerimp.cpp:167
Definition: loadinglistener.hpp:8
Definition: inputmanagerimp.hpp:299
Definition: inputmanagerimp.hpp:303
Definition: inputmanagerimp.hpp:255
Definition: inputmanagerimp.hpp:311
Actions
Definition: inputmanagerimp.hpp:249
void loadControllerDefaults(bool force=false)
Definition: inputmanagerimp.cpp:1208
virtual void channelChanged(ICS::Channel *channel, float currentValue, float previousValue)
Definition: inputmanagerimp.cpp:182
Definition: inputmanagerimp.hpp:294
std::set< std::pair< std::string, std::string > > CategorySettingVector
Definition: settings.hpp:11
InputManager()
Definition: inputmanager.hpp:34
void showQuickKeysMenu()
Definition: inputmanagerimp.cpp:1048
Definition: inputmanagerimp.hpp:314
std::map< std::string, bool > mControlSwitch
Definition: inputmanagerimp.hpp:201
SDL_Window * mWindow
Definition: inputmanagerimp.hpp:157
Definition: esmwriter.hpp:17
bool mWindowVisible
Definition: inputmanagerimp.hpp:158
MWWorld::Player * mPlayer
Definition: inputmanagerimp.hpp:163
Definition: inputmanagerimp.hpp:278
virtual std::vector< int > getActionControllerSorting()
Actions available for binding to controller buttons.
Definition: inputmanagerimp.cpp:1458
Definition: events.hpp:26
virtual int getNumActions()
Definition: inputmanagerimp.hpp:103
bool mMouseLookEnabled
Definition: inputmanagerimp.hpp:185
bool mDragDrop
Definition: inputmanagerimp.hpp:172
Definition: inputmanagerimp.hpp:307
Definition: inputmanagerimp.hpp:289
Definition: inputmanagerimp.hpp:287
virtual void joystickButtonBindingDetected(ICS::InputControlSystem *ICS, int deviceID, ICS::Control *control, unsigned int button, ICS::Control::ControlChangingDirection direction)
Definition: inputmanagerimp.cpp:1551
Definition: inputmanagerimp.hpp:280
virtual void mousePressed(const SDL_MouseButtonEvent &arg, Uint8 id)
Definition: inputmanagerimp.cpp:703
float mPreviewPOVDelay
Definition: inputmanagerimp.hpp:182
Definition: inputmanagerimp.hpp:298
virtual bool joystickLastUsed()
Definition: inputmanagerimp.hpp:110
Definition: events.hpp:44
std::string mUserFile
Definition: inputmanagerimp.hpp:170
bool mSneakToggles
Definition: inputmanagerimp.hpp:197
virtual void setDragDrop(bool dragDrop)
Definition: inputmanagerimp.cpp:580
void updateIdleTime(float dt)
Definition: inputmanagerimp.cpp:1103
ICS::InputControlSystem * mInputBinder
Definition: inputmanagerimp.hpp:165
void resetIdleTime()
Definition: inputmanagerimp.cpp:1096
void toggleSpell()
Definition: inputmanagerimp.cpp:916
bool mGrabCursor
Definition: inputmanagerimp.hpp:174
virtual void update(float dt, bool disableControls=false, bool disableEvents=false)
Definition: inputmanagerimp.cpp:368
void toggleMainMenu()
Definition: inputmanagerimp.cpp:890
void toggleJournal()
Definition: inputmanagerimp.cpp:1018
bool mControlsDisabled
Definition: inputmanagerimp.hpp:178
virtual void joystickAxisBindingDetected(ICS::InputControlSystem *ICS, int deviceID, ICS::Control *control, int axis, ICS::Control::ControlChangingDirection direction)
Definition: inputmanagerimp.cpp:1535
virtual ~InputManager()
Definition: inputmanagerimp.cpp:151
Class that handles all input and key bindings for OpenMW.
Definition: inputmanagerimp.hpp:63
virtual void clear()
Clear all savegame-specific data.
Definition: inputmanagerimp.cpp:144
Definition: inputmanagerimp.hpp:276
void quickLoad()
Definition: inputmanagerimp.cpp:907
Definition: inputmanagerimp.hpp:261
virtual void keyReleased(const SDL_KeyboardEvent &arg)
Definition: inputmanagerimp.cpp:694
virtual void controllerAdded(int deviceID, const SDL_ControllerDeviceEvent &arg)
Definition: inputmanagerimp.cpp:859
float mCameraSensitivity
Definition: inputmanagerimp.hpp:180
virtual std::string sdlControllerAxisToString(int axis)
Definition: inputmanagerimp.cpp:1395
virtual void resetToDefaultKeyBindings()
Definition: inputmanagerimp.cpp:1618
Definition: inputmanagerimp.hpp:284
virtual std::string getActionKeyBindingName(int action)
Definition: inputmanagerimp.cpp:1325
Definition: inputmanagerimp.hpp:253
Definition: inputmanagerimp.hpp:277
virtual bool isWindowVisible()
Definition: inputmanagerimp.cpp:162
float mGuiCursorY
Definition: inputmanagerimp.hpp:193
Definition: inputmanagerimp.hpp:290
virtual void write(ESM::ESMWriter &writer, Loading::Listener &progress)
Definition: inputmanagerimp.cpp:1585
virtual void mouseReleased(const SDL_MouseButtonEvent &arg, Uint8 id)
Definition: inputmanagerimp.cpp:729
Definition: events.hpp:35
void clearAllKeyBindings(ICS::Control *control)
Definition: inputmanagerimp.cpp:1562
Definition: inputmanagerimp.hpp:302
Definition: inputmanagerimp.hpp:288
bool actionIsActive(int id)
Definition: inputmanagerimp.cpp:1115
bool mAttemptJump
Definition: inputmanagerimp.hpp:199
float mOverencumberedMessageDelay
Definition: inputmanagerimp.hpp:190
void toggleSneaking()
Definition: inputmanagerimp.cpp:1089
virtual void buttonPressed(int deviceID, const SDL_ControllerButtonEvent &arg)
Definition: inputmanagerimp.cpp:795
virtual void windowClosed()
Definition: inputmanagerimp.cpp:885
virtual void toggleControlSwitch(const std::string &sw, bool value)
Definition: inputmanagerimp.cpp:640
Definition: inputmanagerimp.hpp:296
Definition: inputmanagerimp.hpp:300
osg::ref_ptr< osgViewer::ScreenCaptureHandler > mScreenCaptureHandler
Definition: inputmanagerimp.hpp:160
Definition: inputmanagerimp.hpp:273
SDLUtil::InputWrapper * mInputManager
Definition: inputmanagerimp.hpp:167
Definition: inputmanagerimp.hpp:259
virtual void textInput(const SDL_TextInputEvent &arg)
Definition: inputmanagerimp.cpp:686
bool mInvertY
Definition: inputmanagerimp.hpp:176
Definition: inputmanagerimp.hpp:286
Definition: inputmanagerimp.hpp:268
virtual std::string getActionControllerBindingName(int action)
Definition: inputmanagerimp.cpp:1342
void convertMousePosForMyGUI(int &x, int &y)
void loadKeyDefaults(bool force=false)
Definition: inputmanagerimp.cpp:1120
Definition: inputmanagerimp.hpp:313
bool mSneaking
Definition: inputmanagerimp.hpp:198
bool mGuiCursorEnabled
Definition: inputmanagerimp.hpp:186
Definition: inputmanagerimp.hpp:275
virtual void enableDetectingBindingMode(int action, bool keyboard)
If keyboard is true, only pay attention to keyboard events. If false, only pay attention to controlle...
Definition: inputmanagerimp.cpp:1490
virtual void axisMoved(int deviceID, const SDL_ControllerAxisEvent &arg)
Definition: inputmanagerimp.cpp:852
Definition: inputmanagerimp.hpp:271
Definition: inputmanagerimp.hpp:283
void toggleInventory()
Definition: inputmanagerimp.cpp:979
void activate()
Definition: inputmanagerimp.cpp:1067
float mGuiCursorX
Definition: inputmanagerimp.hpp:192
bool mDetectingKeyboard
Definition: inputmanagerimp.hpp:188
virtual void mouseAxisBindingDetected(ICS::InputControlSystem *ICS, ICS::Control *control, ICS::InputControlSystem::NamedAxis axis, ICS::Control::ControlChangingDirection direction)
Definition: inputmanagerimp.cpp:1497
void screenshot()
Definition: inputmanagerimp.cpp:971
virtual std::vector< int > getActionKeySorting()
Actions available for binding to keyboard buttons.
Definition: inputmanagerimp.cpp:1416
virtual void windowResized(int x, int y)
Definition: inputmanagerimp.cpp:877
bool checkAllowedToUseItems() const
Definition: inputmanagerimp.cpp:356
virtual void processChangedSettings(const Settings::CategorySettingVector &changed)
Definition: inputmanagerimp.cpp:595
Definition: inputmanagerimp.hpp:264
float mCameraYMultiplier
Definition: inputmanagerimp.hpp:181
Definition: inputmanagerimp.hpp:292
void toggleWeapon()
Definition: inputmanagerimp.cpp:940
SDLUtil::VideoWrapper * mVideoWrapper
Definition: inputmanagerimp.hpp:168
bool mJoystickLastUsed
Definition: inputmanagerimp.hpp:162
void toggleWalking()
Definition: inputmanagerimp.cpp:1081