mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-25 15:35:23 +00:00
229 lines
7.3 KiB
C++
229 lines
7.3 KiB
C++
#ifndef MWINPUT_MWINPUTMANAGERIMP_H
|
|
#define MWINPUT_MWINPUTMANAGERIMP_H
|
|
|
|
#include "../mwgui/mode.hpp"
|
|
|
|
#include <SDL_sensor.h>
|
|
|
|
#include <osg/ref_ptr>
|
|
#include <osgViewer/ViewerEventHandlers>
|
|
|
|
#include <extern/oics/ICSChannelListener.h>
|
|
#include <extern/oics/ICSInputControlSystem.h>
|
|
|
|
#include <components/settings/settings.hpp>
|
|
#include <components/files/configurationmanager.hpp>
|
|
#include <components/sdlutil/events.hpp>
|
|
|
|
#include "../mwbase/inputmanager.hpp"
|
|
|
|
#include "actions.hpp"
|
|
|
|
namespace MWInput
|
|
{
|
|
class ActionManager;
|
|
class MouseManager;
|
|
class SensorManager;
|
|
}
|
|
|
|
namespace MWWorld
|
|
{
|
|
class Player;
|
|
}
|
|
|
|
namespace MWBase
|
|
{
|
|
class WindowManager;
|
|
}
|
|
|
|
namespace ICS
|
|
{
|
|
class InputControlSystem;
|
|
}
|
|
|
|
namespace Files
|
|
{
|
|
struct ConfigurationManager;
|
|
}
|
|
|
|
namespace SDLUtil
|
|
{
|
|
class InputWrapper;
|
|
class VideoWrapper;
|
|
}
|
|
|
|
struct SDL_Window;
|
|
|
|
namespace MWInput
|
|
{
|
|
/**
|
|
* @brief Class that handles all input and key bindings for OpenMW.
|
|
*/
|
|
class InputManager :
|
|
public MWBase::InputManager,
|
|
public SDLUtil::KeyListener,
|
|
public SDLUtil::WindowListener,
|
|
public SDLUtil::ControllerListener,
|
|
public ICS::ChannelListener,
|
|
public ICS::DetectingBindingListener
|
|
{
|
|
public:
|
|
InputManager(
|
|
SDL_Window* window,
|
|
osg::ref_ptr<osgViewer::Viewer> viewer,
|
|
osg::ref_ptr<osgViewer::ScreenCaptureHandler> screenCaptureHandler,
|
|
osgViewer::ScreenCaptureHandler::CaptureOperation *screenCaptureOperation,
|
|
const std::string& userFile, bool userFileExists,
|
|
const std::string& userControllerBindingsFile,
|
|
const std::string& controllerBindingsFile, bool grab);
|
|
|
|
virtual ~InputManager();
|
|
|
|
virtual bool isWindowVisible();
|
|
|
|
/// Clear all savegame-specific data
|
|
virtual void clear();
|
|
|
|
virtual void update(float dt, bool disableControls=false, bool disableEvents=false);
|
|
|
|
void setPlayer (MWWorld::Player* player);
|
|
|
|
virtual void changeInputMode(bool guiMode);
|
|
|
|
virtual void processChangedSettings(const Settings::CategorySettingVector& changed);
|
|
|
|
virtual void setDragDrop(bool dragDrop);
|
|
virtual void setGamepadGuiCursorEnabled(bool enabled);
|
|
|
|
virtual void toggleControlSwitch (const std::string& sw, bool value);
|
|
virtual bool getControlSwitch (const std::string& sw);
|
|
|
|
virtual std::string getActionDescription (int action);
|
|
virtual std::string getActionKeyBindingName (int action);
|
|
virtual std::string getActionControllerBindingName (int action);
|
|
virtual int getNumActions() { return A_Last; }
|
|
virtual std::vector<int> getActionKeySorting();
|
|
virtual std::vector<int> getActionControllerSorting();
|
|
virtual void enableDetectingBindingMode (int action, bool keyboard);
|
|
virtual void resetToDefaultKeyBindings();
|
|
virtual void resetToDefaultControllerBindings();
|
|
|
|
virtual void setJoystickLastUsed(bool enabled) { mJoystickLastUsed = enabled; }
|
|
virtual bool joystickLastUsed() {return mJoystickLastUsed;}
|
|
|
|
virtual void keyPressed(const SDL_KeyboardEvent &arg );
|
|
virtual void keyReleased( const SDL_KeyboardEvent &arg );
|
|
virtual void textInput (const SDL_TextInputEvent &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);
|
|
|
|
virtual void windowVisibilityChange( bool visible );
|
|
virtual void windowFocusChange( bool have_focus );
|
|
virtual void windowResized (int x, int y);
|
|
virtual void windowClosed ();
|
|
|
|
virtual void channelChanged(ICS::Channel* channel, float currentValue, float previousValue);
|
|
|
|
virtual void keyBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
|
|
, SDL_Scancode key, ICS::Control::ControlChangingDirection direction);
|
|
|
|
virtual void mouseAxisBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
|
|
, ICS::InputControlSystem::NamedAxis axis, ICS::Control::ControlChangingDirection direction);
|
|
|
|
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
|
|
, int axis, ICS::Control::ControlChangingDirection direction);
|
|
|
|
virtual void joystickButtonBindingDetected(ICS::InputControlSystem* ICS, int deviceID, ICS::Control* control
|
|
, unsigned int button, ICS::Control::ControlChangingDirection direction);
|
|
|
|
void clearAllKeyBindings (ICS::Control* control);
|
|
void clearAllControllerBindings (ICS::Control* control);
|
|
|
|
virtual int countSavedGameRecords() const;
|
|
virtual void write(ESM::ESMWriter& writer, Loading::Listener& progress);
|
|
virtual void readRecord(ESM::ESMReader& reader, uint32_t type);
|
|
|
|
virtual void setPlayerControlsEnabled(bool enabled);
|
|
|
|
virtual void resetIdleTime();
|
|
|
|
private:
|
|
SDL_Window* mWindow;
|
|
bool mWindowVisible;
|
|
|
|
bool mJoystickLastUsed;
|
|
MWWorld::Player* mPlayer;
|
|
|
|
ICS::InputControlSystem* mInputBinder;
|
|
|
|
SDLUtil::InputWrapper* mInputManager;
|
|
SDLUtil::VideoWrapper* mVideoWrapper;
|
|
|
|
std::string mUserFile;
|
|
|
|
bool mDragDrop;
|
|
|
|
bool mGrabCursor;
|
|
|
|
bool mControlsDisabled;
|
|
bool mJoystickEnabled;
|
|
|
|
float mPreviewPOVDelay;
|
|
float mTimeIdle;
|
|
|
|
bool mGuiCursorEnabled;
|
|
bool mGamepadGuiCursorEnabled;
|
|
|
|
bool mDetectingKeyboard;
|
|
|
|
float mOverencumberedMessageDelay;
|
|
|
|
float mGamepadZoom;
|
|
bool mSneakToggles;
|
|
float mSneakToggleShortcutTimer;
|
|
bool mSneakGamepadShortcut;
|
|
bool mAttemptJump;
|
|
|
|
std::map<std::string, bool> mControlSwitch;
|
|
|
|
float mInvUiScalingFactor;
|
|
float mGamepadCursorSpeed;
|
|
|
|
ActionManager* mActionManager;
|
|
MouseManager* mMouseManager;
|
|
SensorManager* mSensorManager;
|
|
|
|
void convertMousePosForMyGUI(int& x, int& y);
|
|
|
|
void updateIdleTime(float dt);
|
|
|
|
void handleGuiArrowKey(int action);
|
|
// Return true if GUI consumes input.
|
|
bool gamepadToGuiControl(const SDL_ControllerButtonEvent &arg);
|
|
bool gamepadToGuiControl(const SDL_ControllerAxisEvent &arg);
|
|
|
|
void updateCursorMode();
|
|
|
|
void quickKey (int index);
|
|
void showQuickKeysMenu();
|
|
|
|
bool actionIsActive (int id);
|
|
|
|
void loadKeyDefaults(bool force = false);
|
|
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
|
|
};
|
|
}
|
|
#endif
|