1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 00:35:23 +00:00
OpenMW/apps/openmw/mwinput/inputmanagerimp.hpp

268 lines
8.4 KiB
C++
Raw Normal View History

#ifndef MWINPUT_MWINPUTMANAGERIMP_H
#define MWINPUT_MWINPUTMANAGERIMP_H
#include "../mwgui/mode.hpp"
#include <SDL_sensor.h>
2015-05-13 16:50:47 +02:00
#include <osg/ref_ptr>
2017-11-09 18:26:27 +01:00
#include <osgViewer/ViewerEventHandlers>
2015-05-13 16:50:47 +02:00
#include <extern/oics/ICSChannelListener.h>
#include <extern/oics/ICSInputControlSystem.h>
#include <components/settings/settings.hpp>
2014-12-20 14:46:11 -06:00
#include <components/files/configurationmanager.hpp>
2015-05-13 16:50:47 +02:00
#include <components/sdlutil/events.hpp>
#include "../mwbase/inputmanager.hpp"
2015-05-13 16:50:47 +02:00
#include "actions.hpp"
namespace MWInput
{
class SensorManager;
}
namespace MWWorld
2010-07-17 19:58:15 +02:00
{
2012-08-12 20:45:02 +02:00
class Player;
2010-07-17 19:58:15 +02:00
}
namespace MWBase
2010-07-17 19:58:15 +02:00
{
2012-08-12 20:45:02 +02:00
class WindowManager;
2010-07-17 19:58:15 +02:00
}
2012-08-12 20:45:02 +02:00
namespace ICS
{
class InputControlSystem;
}
2014-12-20 14:46:11 -06:00
namespace Files
{
struct ConfigurationManager;
}
2015-05-13 16:50:47 +02:00
namespace SDLUtil
{
class InputWrapper;
class VideoWrapper;
2015-05-13 16:50:47 +02:00
}
namespace osgViewer
{
class Viewer;
class ScreenCaptureHandler;
2015-05-13 16:50:47 +02:00
}
struct SDL_Window;
2012-08-12 20:45:02 +02:00
namespace MWInput
{
const float ZOOM_SCALE = 120.f; /// Used for scrolling camera in and out
2010-06-22 16:02:58 +02:00
2012-08-12 20:45:02 +02:00
/**
* @brief Class that handles all input and key bindings for OpenMW.
*/
class InputManager :
public MWBase::InputManager,
2015-05-13 16:50:47 +02:00
public SDLUtil::KeyListener,
public SDLUtil::MouseListener,
public SDLUtil::WindowListener,
public SDLUtil::ControllerListener,
public ICS::ChannelListener,
public ICS::DetectingBindingListener
2012-08-12 20:45:02 +02:00
{
public:
2015-05-03 17:24:35 +02:00
InputManager(
2015-05-13 16:50:47 +02:00
SDL_Window* window,
osg::ref_ptr<osgViewer::Viewer> viewer,
osg::ref_ptr<osgViewer::ScreenCaptureHandler> screenCaptureHandler,
2017-11-09 18:26:27 +01:00
osgViewer::ScreenCaptureHandler::CaptureOperation *screenCaptureOperation,
const std::string& userFile, bool userFileExists,
2019-08-03 19:55:58 +00:00
const std::string& userControllerBindingsFile,
const std::string& controllerBindingsFile, bool grab);
2012-08-12 20:45:02 +02:00
virtual ~InputManager();
virtual bool isWindowVisible();
/// Clear all savegame-specific data
virtual void clear();
virtual void update(float dt, bool disableControls=false, bool disableEvents=false);
2012-08-12 20:45:02 +02:00
void setPlayer (MWWorld::Player* player);
2012-08-12 20:45:02 +02:00
virtual void changeInputMode(bool guiMode);
virtual void processChangedSettings(const Settings::CategorySettingVector& changed);
virtual void setDragDrop(bool dragDrop);
virtual void toggleControlSwitch (const std::string& sw, bool value);
virtual bool getControlSwitch (const std::string& sw);
2012-08-12 20:45:02 +02:00
2012-08-13 01:26:15 +02:00
virtual std::string getActionDescription (int action);
2014-12-08 21:57:32 -06:00
virtual std::string getActionKeyBindingName (int action);
virtual std::string getActionControllerBindingName (int action);
2012-08-13 01:26:15 +02:00
virtual int getNumActions() { return A_Last; }
2014-12-08 21:57:32 -06:00
virtual std::vector<int> getActionKeySorting();
virtual std::vector<int> getActionControllerSorting();
virtual void enableDetectingBindingMode (int action, bool keyboard);
virtual void resetToDefaultKeyBindings();
virtual void resetToDefaultControllerBindings();
2012-08-13 01:26:15 +02:00
2014-12-20 14:46:11 -06:00
virtual bool joystickLastUsed() {return mJoystickLastUsed;}
2014-02-13 15:08:40 +01:00
virtual void keyPressed(const SDL_KeyboardEvent &arg );
virtual void keyReleased( const SDL_KeyboardEvent &arg );
2013-06-16 19:43:59 +02:00
virtual void textInput (const SDL_TextInputEvent &arg);
2012-08-12 20:45:02 +02:00
2014-02-13 15:08:40 +01:00
virtual void mousePressed( const SDL_MouseButtonEvent &arg, Uint8 id );
virtual void mouseReleased( const SDL_MouseButtonEvent &arg, Uint8 id );
2015-05-13 16:50:47 +02:00
virtual void mouseMoved( const SDLUtil::MouseMotionEvent &arg );
2012-08-12 20:45:02 +02:00
virtual void mouseWheelMoved( const SDL_MouseWheelEvent &arg);
virtual void buttonPressed(int deviceID, const SDL_ControllerButtonEvent &arg);
virtual void buttonReleased(int deviceID, const SDL_ControllerButtonEvent &arg);
virtual void axisMoved(int deviceID, const SDL_ControllerAxisEvent &arg);
virtual void controllerAdded(int deviceID, const SDL_ControllerDeviceEvent &arg);
virtual void controllerRemoved(const SDL_ControllerDeviceEvent &arg);
2014-12-08 21:57:32 -06:00
2013-07-29 02:32:08 +02:00
virtual void windowVisibilityChange( bool visible );
virtual void windowFocusChange( bool have_focus );
virtual void windowResized (int x, int y);
virtual void windowClosed ();
2012-08-12 20:45:02 +02:00
virtual void channelChanged(ICS::Channel* channel, float currentValue, float previousValue);
2012-08-13 01:26:15 +02:00
virtual void keyBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
2014-09-13 20:39:32 +02:00
, SDL_Scancode key, ICS::Control::ControlChangingDirection direction);
2012-08-13 01:26:15 +02:00
virtual void mouseAxisBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
, ICS::InputControlSystem::NamedAxis axis, ICS::Control::ControlChangingDirection direction);
2012-08-13 01:26:15 +02:00
virtual void mouseButtonBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
, unsigned int button, ICS::Control::ControlChangingDirection direction);
virtual void mouseWheelBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
, ICS::InputControlSystem::MouseWheelClick click, ICS::Control::ControlChangingDirection direction);
virtual void joystickAxisBindingDetected(ICS::InputControlSystem* ICS, int deviceID, ICS::Control* control
2014-12-08 21:57:32 -06:00
, int axis, ICS::Control::ControlChangingDirection direction);
2012-08-13 01:26:15 +02:00
virtual void joystickButtonBindingDetected(ICS::InputControlSystem* ICS, int deviceID, ICS::Control* control
2014-12-08 21:57:32 -06:00
, unsigned int button, ICS::Control::ControlChangingDirection direction);
2012-08-13 01:26:15 +02:00
2014-12-08 21:57:32 -06:00
void clearAllKeyBindings (ICS::Control* control);
void clearAllControllerBindings (ICS::Control* control);
2012-08-13 01:26:15 +02:00
2016-10-20 02:12:01 +02:00
virtual int countSavedGameRecords() const;
virtual void write(ESM::ESMWriter& writer, Loading::Listener& progress);
virtual void readRecord(ESM::ESMReader& reader, uint32_t type);
2012-08-12 20:45:02 +02:00
private:
SDL_Window* mWindow;
bool mWindowVisible;
osg::ref_ptr<osgViewer::Viewer> mViewer;
osg::ref_ptr<osgViewer::ScreenCaptureHandler> mScreenCaptureHandler;
2017-11-09 18:26:27 +01:00
osgViewer::ScreenCaptureHandler::CaptureOperation *mScreenCaptureOperation;
2014-12-08 21:57:32 -06:00
bool mJoystickLastUsed;
MWWorld::Player* mPlayer;
2012-08-12 20:45:02 +02:00
ICS::InputControlSystem* mInputBinder;
2012-08-12 20:45:02 +02:00
2015-05-13 16:50:47 +02:00
SDLUtil::InputWrapper* mInputManager;
SDLUtil::VideoWrapper* mVideoWrapper;
2012-08-12 20:45:02 +02:00
std::string mUserFile;
bool mDragDrop;
bool mGrabCursor;
bool mInvertX;
bool mInvertY;
bool mControlsDisabled;
bool mJoystickEnabled;
2012-08-13 18:48:50 +02:00
float mCameraSensitivity;
float mCameraYMultiplier;
2012-08-17 16:42:42 +04:00
float mPreviewPOVDelay;
2012-08-18 01:31:57 +04:00
float mTimeIdle;
2012-08-13 18:48:50 +02:00
2012-08-12 20:45:02 +02:00
bool mMouseLookEnabled;
bool mGuiCursorEnabled;
bool mGamepadGuiCursorEnabled;
2012-08-12 20:45:02 +02:00
2014-12-08 21:57:32 -06:00
bool mDetectingKeyboard;
float mOverencumberedMessageDelay;
2015-05-15 00:41:21 +02:00
float mGuiCursorX;
float mGuiCursorY;
int mMouseWheel;
2019-02-27 13:29:48 +00:00
float mGamepadZoom;
bool mUserFileExists;
bool mAlwaysRunActive;
bool mSneakToggles;
2019-02-27 14:03:16 -08:00
float mSneakToggleShortcutTimer;
bool mSneakGamepadShortcut;
bool mSneaking;
bool mAttemptJump;
2012-08-12 20:45:02 +02:00
std::map<std::string, bool> mControlSwitch;
2015-05-15 00:41:21 +02:00
float mInvUiScalingFactor;
float mGamepadCursorSpeed;
2015-05-15 00:41:21 +02:00
SensorManager* mSensorManager;
2015-05-15 00:41:21 +02:00
void convertMousePosForMyGUI(int& x, int& y);
2012-08-18 01:31:57 +04:00
void resetIdleTime();
void updateIdleTime(float dt);
void setPlayerControlsEnabled(bool enabled);
void handleGuiArrowKey(int action);
// Return true if GUI consumes input.
bool gamepadToGuiControl(const SDL_ControllerButtonEvent &arg);
bool gamepadToGuiControl(const SDL_ControllerAxisEvent &arg);
void updateCursorMode();
bool checkAllowedToUseItems() const;
2012-08-12 20:45:02 +02:00
void toggleMainMenu();
void toggleSpell();
void toggleWeapon();
void toggleInventory();
void toggleConsole();
void screenshot();
void toggleJournal();
void activate();
void toggleWalking();
void toggleSneaking();
2012-08-12 20:45:02 +02:00
void toggleAutoMove();
2012-09-15 17:12:42 +02:00
void rest();
2014-04-23 21:02:09 -04:00
void quickLoad();
void quickSave();
2012-08-12 20:45:02 +02:00
void quickKey (int index);
void showQuickKeysMenu();
2012-08-12 20:45:02 +02:00
bool actionIsActive (int id);
void loadKeyDefaults(bool force = false);
2014-12-08 21:57:32 -06:00
void loadControllerDefaults(bool force = false);
int mFakeDeviceID; //As we only support one controller at a time, use a fake deviceID so we don't lose bindings when switching controllers
2012-08-12 20:45:02 +02:00
};
}
#endif