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