2012-08-11 17:53:39 +02:00
|
|
|
#include "inputmanagerimp.hpp"
|
2010-07-17 19:58:15 +02:00
|
|
|
|
2015-11-14 02:43:24 +01:00
|
|
|
#include <osgViewer/ViewerEventHandlers>
|
|
|
|
|
2015-05-13 16:50:47 +02:00
|
|
|
#include <components/sdlutil/sdlinputwrapper.hpp>
|
2016-10-20 02:12:01 +02:00
|
|
|
#include <components/esm/esmwriter.hpp>
|
|
|
|
#include <components/esm/esmreader.hpp>
|
2015-05-13 16:50:47 +02:00
|
|
|
|
2012-08-12 20:45:02 +02:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2015-11-14 02:43:24 +01:00
|
|
|
#include "../mwbase/environment.hpp"
|
2020-06-27 00:58:33 +02:00
|
|
|
#include "../mwbase/world.hpp"
|
2014-02-23 20:11:05 +01:00
|
|
|
|
|
|
|
#include "../mwworld/esmstore.hpp"
|
|
|
|
|
2020-04-08 19:33:07 +04:00
|
|
|
#include "actionmanager.hpp"
|
2020-04-17 15:21:23 +04:00
|
|
|
#include "bindingsmanager.hpp"
|
2020-04-08 22:02:53 +04:00
|
|
|
#include "controllermanager.hpp"
|
2020-04-16 18:08:55 +04:00
|
|
|
#include "controlswitch.hpp"
|
2020-04-16 11:03:34 +04:00
|
|
|
#include "keyboardmanager.hpp"
|
2020-04-08 14:48:23 +04:00
|
|
|
#include "mousemanager.hpp"
|
2020-04-08 11:43:45 +04:00
|
|
|
#include "sdlmappings.hpp"
|
2020-04-08 10:55:35 +04:00
|
|
|
#include "sensormanager.hpp"
|
|
|
|
|
2010-07-17 19:58:15 +02:00
|
|
|
namespace MWInput
|
|
|
|
{
|
2015-05-03 17:24:35 +02:00
|
|
|
InputManager::InputManager(
|
2015-05-13 16:50:47 +02:00
|
|
|
SDL_Window* window,
|
|
|
|
osg::ref_ptr<osgViewer::Viewer> viewer,
|
2015-11-14 02:43:24 +01:00
|
|
|
osg::ref_ptr<osgViewer::ScreenCaptureHandler> screenCaptureHandler,
|
2017-11-09 18:26:27 +01:00
|
|
|
osgViewer::ScreenCaptureHandler::CaptureOperation *screenCaptureOperation,
|
2020-04-08 19:33:07 +04:00
|
|
|
const std::string& userFile, bool userFileExists, const std::string& userControllerBindingsFile,
|
2015-01-19 18:55:17 -06:00
|
|
|
const std::string& controllerBindingsFile, bool grab)
|
2020-05-26 11:24:47 +04:00
|
|
|
: mControlsDisabled(false)
|
2010-07-17 19:58:15 +02:00
|
|
|
{
|
2020-04-15 12:48:18 +04:00
|
|
|
mInputWrapper = new SDLUtil::InputWrapper(window, viewer, grab);
|
2020-04-16 17:31:20 +04:00
|
|
|
mInputWrapper->setWindowEventCallback(MWBase::Environment::get().getWindowManager());
|
2015-05-14 20:31:16 +02:00
|
|
|
|
2020-04-17 15:21:23 +04:00
|
|
|
mBindingsManager = new BindingsManager(userFile, userFileExists);
|
2011-11-28 16:51:11 +01:00
|
|
|
|
2020-04-16 18:08:55 +04:00
|
|
|
mControlSwitch = new ControlSwitch();
|
2014-12-20 14:46:11 -06:00
|
|
|
|
2020-04-17 15:21:23 +04:00
|
|
|
mActionManager = new ActionManager(mBindingsManager, screenCaptureOperation, viewer, screenCaptureHandler);
|
2014-12-20 14:46:11 -06:00
|
|
|
|
2020-04-17 15:59:37 +04:00
|
|
|
mKeyboardManager = new KeyboardManager(mBindingsManager);
|
2020-04-16 11:03:34 +04:00
|
|
|
mInputWrapper->setKeyboardEventCallback(mKeyboardManager);
|
|
|
|
|
2020-04-17 15:21:23 +04:00
|
|
|
mMouseManager = new MouseManager(mBindingsManager, mInputWrapper, window);
|
2020-04-16 11:03:34 +04:00
|
|
|
mInputWrapper->setMouseEventCallback(mMouseManager);
|
2014-12-20 14:46:11 -06:00
|
|
|
|
2020-04-17 15:21:23 +04:00
|
|
|
mControllerManager = new ControllerManager(mBindingsManager, mActionManager, mMouseManager, userControllerBindingsFile, controllerBindingsFile);
|
2020-04-15 12:48:18 +04:00
|
|
|
mInputWrapper->setControllerEventCallback(mControllerManager);
|
2015-05-15 00:41:21 +02:00
|
|
|
|
2020-04-08 10:55:35 +04:00
|
|
|
mSensorManager = new SensorManager();
|
2020-04-16 11:03:34 +04:00
|
|
|
mInputWrapper->setSensorEventCallback(mSensorManager);
|
2010-08-03 16:26:43 +02:00
|
|
|
}
|
|
|
|
|
2014-03-09 03:34:49 +01:00
|
|
|
void InputManager::clear()
|
|
|
|
{
|
|
|
|
// Enable all controls
|
2020-04-16 18:08:55 +04:00
|
|
|
mControlSwitch->clear();
|
2014-03-09 03:34:49 +01:00
|
|
|
}
|
|
|
|
|
2012-08-12 20:45:02 +02:00
|
|
|
InputManager::~InputManager()
|
2011-01-14 09:52:28 -05:00
|
|
|
{
|
2020-04-08 19:33:07 +04:00
|
|
|
delete mActionManager;
|
2020-04-08 22:02:53 +04:00
|
|
|
delete mControllerManager;
|
2020-04-16 11:03:34 +04:00
|
|
|
delete mKeyboardManager;
|
2020-04-08 19:33:07 +04:00
|
|
|
delete mMouseManager;
|
2020-04-08 10:55:35 +04:00
|
|
|
delete mSensorManager;
|
2020-03-14 22:24:36 +04:00
|
|
|
|
2020-04-16 18:08:55 +04:00
|
|
|
delete mControlSwitch;
|
|
|
|
|
2020-04-17 15:21:23 +04:00
|
|
|
delete mBindingsManager;
|
2011-01-16 10:47:03 -05:00
|
|
|
|
2020-04-15 12:48:18 +04:00
|
|
|
delete mInputWrapper;
|
2015-09-04 03:44:14 +02:00
|
|
|
}
|
|
|
|
|
2020-04-17 15:21:23 +04:00
|
|
|
void InputManager::setAttemptJump(bool jumping)
|
2014-05-31 19:51:21 -04:00
|
|
|
{
|
2020-04-17 15:21:23 +04:00
|
|
|
mActionManager->setAttemptJump(jumping);
|
2012-05-13 10:18:17 +02:00
|
|
|
}
|
|
|
|
|
2015-01-13 04:53:49 +01:00
|
|
|
void InputManager::update(float dt, bool disableControls, bool disableEvents)
|
|
|
|
{
|
2020-05-26 10:58:24 +04:00
|
|
|
mControlsDisabled = disableControls;
|
|
|
|
|
2020-04-15 12:48:18 +04:00
|
|
|
mInputWrapper->setMouseVisible(MWBase::Environment::get().getWindowManager()->getCursorVisible());
|
|
|
|
mInputWrapper->capture(disableEvents);
|
2015-01-13 04:53:49 +01:00
|
|
|
|
2020-04-16 11:03:34 +04:00
|
|
|
if (disableControls)
|
2015-01-13 04:53:49 +01:00
|
|
|
{
|
2020-05-26 11:24:47 +04:00
|
|
|
mMouseManager->updateCursorMode();
|
2015-01-13 04:53:49 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-17 15:21:23 +04:00
|
|
|
mBindingsManager->update(dt);
|
2015-01-13 04:53:49 +01:00
|
|
|
|
2020-05-26 11:24:47 +04:00
|
|
|
mMouseManager->updateCursorMode();
|
2013-01-09 06:10:05 -04:00
|
|
|
|
2020-05-26 10:58:24 +04:00
|
|
|
bool controllerMove = mControllerManager->update(dt);
|
|
|
|
mMouseManager->update(dt);
|
2020-04-17 15:41:52 +04:00
|
|
|
mSensorManager->update(dt);
|
2020-04-16 16:36:32 +04:00
|
|
|
mActionManager->update(dt, controllerMove);
|
2020-06-27 00:58:33 +02:00
|
|
|
|
|
|
|
MWBase::Environment::get().getWorld()->applyDeferredPreviewRotationToPlayer(dt);
|
2012-08-12 20:45:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputManager::setDragDrop(bool dragDrop)
|
|
|
|
{
|
2020-04-17 15:21:23 +04:00
|
|
|
mBindingsManager->setDragDrop(dragDrop);
|
2010-07-17 19:58:15 +02:00
|
|
|
}
|
2010-09-15 14:48:19 +02:00
|
|
|
|
2020-04-08 14:48:23 +04:00
|
|
|
void InputManager::setGamepadGuiCursorEnabled(bool enabled)
|
|
|
|
{
|
2020-04-08 22:02:53 +04:00
|
|
|
mControllerManager->setGamepadGuiCursorEnabled(enabled);
|
2020-04-08 14:48:23 +04:00
|
|
|
}
|
|
|
|
|
2012-08-12 20:45:02 +02:00
|
|
|
void InputManager::changeInputMode(bool guiMode)
|
2010-09-15 14:48:19 +02:00
|
|
|
{
|
2020-04-17 15:41:52 +04:00
|
|
|
mControllerManager->setGuiCursorEnabled(guiMode);
|
|
|
|
mMouseManager->setGuiCursorEnabled(guiMode);
|
|
|
|
mSensorManager->setGuiCursorEnabled(guiMode);
|
|
|
|
mMouseManager->setMouseLookEnabled(!guiMode);
|
2013-03-31 15:50:48 +02:00
|
|
|
if (guiMode)
|
2013-08-27 15:48:13 +02:00
|
|
|
MWBase::Environment::get().getWindowManager()->showCrosshair(false);
|
2020-04-17 16:51:47 +04:00
|
|
|
|
|
|
|
bool isCursorVisible = guiMode && (!mControllerManager->joystickLastUsed() || mControllerManager->gamepadGuiCursorEnabled());
|
|
|
|
MWBase::Environment::get().getWindowManager()->setCursorVisible(isCursorVisible);
|
2013-03-31 15:50:48 +02:00
|
|
|
// if not in gui mode, the camera decides whether to show crosshair or not.
|
2012-08-12 20:45:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputManager::processChangedSettings(const Settings::CategorySettingVector& changed)
|
|
|
|
{
|
2020-04-08 19:33:07 +04:00
|
|
|
mMouseManager->processChangedSettings(changed);
|
2020-04-08 10:55:35 +04:00
|
|
|
mSensorManager->processChangedSettings(changed);
|
2010-09-15 14:48:19 +02:00
|
|
|
}
|
2012-08-04 11:54:42 +04:00
|
|
|
|
2020-04-17 15:21:23 +04:00
|
|
|
bool InputManager::getControlSwitch(const std::string& sw)
|
2012-09-10 18:44:59 +02:00
|
|
|
{
|
2020-04-16 18:08:55 +04:00
|
|
|
return mControlSwitch->get(sw);
|
2012-09-10 18:44:59 +02:00
|
|
|
}
|
|
|
|
|
2020-04-17 15:21:23 +04:00
|
|
|
void InputManager::toggleControlSwitch(const std::string& sw, bool value)
|
2012-08-04 11:54:42 +04:00
|
|
|
{
|
2020-04-16 18:08:55 +04:00
|
|
|
mControlSwitch->set(sw, value);
|
2012-08-04 11:54:42 +04:00
|
|
|
}
|
|
|
|
|
2012-08-18 01:31:57 +04:00
|
|
|
void InputManager::resetIdleTime()
|
|
|
|
{
|
2020-04-16 16:36:32 +04:00
|
|
|
mActionManager->resetIdleTime();
|
2012-08-18 01:31:57 +04:00
|
|
|
}
|
|
|
|
|
2021-06-26 23:10:24 +02:00
|
|
|
bool InputManager::isIdle() const
|
|
|
|
{
|
|
|
|
return mActionManager->getIdleTime() > 0.5;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string InputManager::getActionDescription(int action) const
|
2012-08-12 20:45:02 +02:00
|
|
|
{
|
2020-04-17 15:21:23 +04:00
|
|
|
return mBindingsManager->getActionDescription(action);
|
2012-08-12 20:45:02 +02:00
|
|
|
}
|
|
|
|
|
2021-06-26 23:10:24 +02:00
|
|
|
std::string InputManager::getActionKeyBindingName(int action) const
|
2012-08-12 22:59:58 +02:00
|
|
|
{
|
2020-04-17 15:21:23 +04:00
|
|
|
return mBindingsManager->getActionKeyBindingName(action);
|
2012-08-12 22:59:58 +02:00
|
|
|
}
|
|
|
|
|
2021-06-26 23:10:24 +02:00
|
|
|
std::string InputManager::getActionControllerBindingName(int action) const
|
2012-08-13 01:26:15 +02:00
|
|
|
{
|
2020-04-17 15:21:23 +04:00
|
|
|
return mBindingsManager->getActionControllerBindingName(action);
|
2014-12-08 21:57:32 -06:00
|
|
|
}
|
|
|
|
|
2021-06-26 23:10:24 +02:00
|
|
|
bool InputManager::actionIsActive(int action) const
|
|
|
|
{
|
|
|
|
return mBindingsManager->actionIsActive(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
float InputManager::getActionValue(int action) const
|
|
|
|
{
|
|
|
|
return mBindingsManager->getActionValue(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
float InputManager::getControllerAxisValue(SDL_GameControllerAxis axis) const
|
|
|
|
{
|
|
|
|
return mBindingsManager->getControllerAxisValue(axis);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t InputManager::getMouseButtonsState() const
|
|
|
|
{
|
|
|
|
return mMouseManager->getButtonsState();
|
|
|
|
}
|
|
|
|
|
|
|
|
int InputManager::getMouseMoveX() const
|
|
|
|
{
|
|
|
|
return mMouseManager->getMouseMoveX();
|
|
|
|
}
|
|
|
|
|
|
|
|
int InputManager::getMouseMoveY() const
|
|
|
|
{
|
|
|
|
return mMouseManager->getMouseMoveY();
|
|
|
|
}
|
|
|
|
|
2014-12-08 21:57:32 -06:00
|
|
|
std::vector<int> InputManager::getActionKeySorting()
|
2012-08-13 01:26:15 +02:00
|
|
|
{
|
2020-04-17 15:21:23 +04:00
|
|
|
return mBindingsManager->getActionKeySorting();
|
2012-08-13 01:26:15 +02:00
|
|
|
}
|
|
|
|
|
2020-04-17 15:21:23 +04:00
|
|
|
std::vector<int> InputManager::getActionControllerSorting()
|
2012-08-13 01:26:15 +02:00
|
|
|
{
|
2020-04-17 15:21:23 +04:00
|
|
|
return mBindingsManager->getActionControllerSorting();
|
2014-12-08 21:57:32 -06:00
|
|
|
}
|
2012-08-13 01:26:15 +02:00
|
|
|
|
2020-04-17 15:21:23 +04:00
|
|
|
void InputManager::enableDetectingBindingMode(int action, bool keyboard)
|
2014-12-08 21:57:32 -06:00
|
|
|
{
|
2020-04-17 15:21:23 +04:00
|
|
|
mBindingsManager->enableDetectingBindingMode(action, keyboard);
|
2012-08-13 01:26:15 +02:00
|
|
|
}
|
|
|
|
|
2016-10-20 02:12:01 +02:00
|
|
|
int InputManager::countSavedGameRecords() const
|
|
|
|
{
|
2020-04-24 12:43:17 +04:00
|
|
|
return mControlSwitch->countSavedGameRecords();
|
2016-10-20 02:12:01 +02:00
|
|
|
}
|
|
|
|
|
2020-04-24 12:43:17 +04:00
|
|
|
void InputManager::write(ESM::ESMWriter& writer, Loading::Listener& progress)
|
2016-10-20 02:12:01 +02:00
|
|
|
{
|
2020-04-24 12:43:17 +04:00
|
|
|
mControlSwitch->write(writer, progress);
|
2016-10-20 02:12:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputManager::readRecord(ESM::ESMReader& reader, uint32_t type)
|
|
|
|
{
|
|
|
|
if (type == ESM::REC_INPU)
|
|
|
|
{
|
2020-04-24 12:43:17 +04:00
|
|
|
mControlSwitch->readRecord(reader, type);
|
2016-10-20 02:12:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-08 21:57:32 -06:00
|
|
|
void InputManager::resetToDefaultKeyBindings()
|
2012-08-13 02:55:22 +02:00
|
|
|
{
|
2020-04-17 15:21:23 +04:00
|
|
|
mBindingsManager->loadKeyDefaults(true);
|
2012-08-13 02:55:22 +02:00
|
|
|
}
|
2013-01-08 22:14:30 -04:00
|
|
|
|
2014-12-08 21:57:32 -06:00
|
|
|
void InputManager::resetToDefaultControllerBindings()
|
|
|
|
{
|
2020-04-17 15:21:23 +04:00
|
|
|
mBindingsManager->loadControllerDefaults(true);
|
2014-12-08 21:57:32 -06:00
|
|
|
}
|
2020-04-08 22:02:53 +04:00
|
|
|
|
|
|
|
void InputManager::setJoystickLastUsed(bool enabled)
|
|
|
|
{
|
|
|
|
mControllerManager->setJoystickLastUsed(enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputManager::joystickLastUsed()
|
|
|
|
{
|
|
|
|
return mControllerManager->joystickLastUsed();
|
|
|
|
}
|
2020-04-17 15:21:23 +04:00
|
|
|
|
|
|
|
void InputManager::executeAction(int action)
|
|
|
|
{
|
|
|
|
mActionManager->executeAction(action);
|
|
|
|
}
|
2010-07-17 19:58:15 +02:00
|
|
|
}
|