1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 21:49:56 +00:00
openmw-tes3mp/apps/openmw/mwinput/inputmanagerimp.cpp

227 lines
6.7 KiB
C++
Raw Normal View History

#include "inputmanagerimp.hpp"
2010-07-17 17:58:15 +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"
#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"
#include "actionmanager.hpp"
#include "bindingsmanager.hpp"
#include "controllermanager.hpp"
#include "controlswitch.hpp"
#include "keyboardmanager.hpp"
#include "mousemanager.hpp"
2020-04-08 07:43:45 +00:00
#include "sdlmappings.hpp"
#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,
osg::ref_ptr<osgViewer::ScreenCaptureHandler> screenCaptureHandler,
2017-11-09 17:26:27 +00:00
osgViewer::ScreenCaptureHandler::CaptureOperation *screenCaptureOperation,
const std::string& userFile, bool userFileExists, const std::string& userControllerBindingsFile,
const std::string& controllerBindingsFile, bool grab)
2020-05-26 07:24:47 +00:00
: mControlsDisabled(false)
2010-07-17 17:58:15 +00:00
{
mInputWrapper = new SDLUtil::InputWrapper(window, viewer, grab);
mInputWrapper->setWindowEventCallback(MWBase::Environment::get().getWindowManager());
mBindingsManager = new BindingsManager(userFile, userFileExists);
2014-12-20 20:46:11 +00:00
mControlSwitch = new ControlSwitch();
2014-12-20 20:46:11 +00:00
mActionManager = new ActionManager(mBindingsManager, screenCaptureOperation, viewer, screenCaptureHandler);
2015-05-14 22:41:21 +00:00
2020-04-17 11:59:37 +00:00
mKeyboardManager = new KeyboardManager(mBindingsManager);
mInputWrapper->setKeyboardEventCallback(mKeyboardManager);
mMouseManager = new MouseManager(mBindingsManager, mInputWrapper, window);
mInputWrapper->setMouseEventCallback(mMouseManager);
2015-05-14 22:41:21 +00:00
mControllerManager = new ControllerManager(mBindingsManager, mActionManager, mMouseManager, userControllerBindingsFile, controllerBindingsFile);
mInputWrapper->setControllerEventCallback(mControllerManager);
2015-05-14 22:41:21 +00:00
mSensorManager = new SensorManager();
mInputWrapper->setSensorEventCallback(mSensorManager);
}
void InputManager::clear()
{
// Enable all controls
mControlSwitch->clear();
}
2012-08-12 18:45:02 +00:00
InputManager::~InputManager()
{
delete mActionManager;
delete mControllerManager;
delete mKeyboardManager;
delete mMouseManager;
delete mSensorManager;
delete mControlSwitch;
delete mBindingsManager;
delete mInputWrapper;
}
void InputManager::setAttemptJump(bool jumping)
2010-07-20 19:10:51 +00:00
{
mActionManager->setAttemptJump(jumping);
}
void InputManager::update(float dt, bool disableControls, bool disableEvents)
{
2020-05-26 06:58:24 +00:00
mControlsDisabled = disableControls;
mInputWrapper->setMouseVisible(MWBase::Environment::get().getWindowManager()->getCursorVisible());
mInputWrapper->capture(disableEvents);
if (disableControls)
{
2020-05-26 07:24:47 +00:00
mMouseManager->updateCursorMode();
return;
}
mBindingsManager->update(dt);
2020-05-26 07:24:47 +00:00
mMouseManager->updateCursorMode();
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)
{
mBindingsManager->setDragDrop(dragDrop);
2010-07-17 17:58:15 +00:00
}
void InputManager::setGamepadGuiCursorEnabled(bool enabled)
{
mControllerManager->setGamepadGuiCursorEnabled(enabled);
2010-07-17 17:58:15 +00:00
}
2012-08-12 18:45:02 +00:00
void InputManager::changeInputMode(bool guiMode)
{
2020-04-17 11:41:52 +00:00
mControllerManager->setGuiCursorEnabled(guiMode);
mMouseManager->setGuiCursorEnabled(guiMode);
mSensorManager->setGuiCursorEnabled(guiMode);
mMouseManager->setMouseLookEnabled(!guiMode);
if (guiMode)
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);
// 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)
{
mMouseManager->processChangedSettings(changed);
mSensorManager->processChangedSettings(changed);
}
bool InputManager::getControlSwitch(const std::string& sw)
2012-08-12 18:45:02 +00:00
{
return mControlSwitch->get(sw);
2012-08-12 18:45:02 +00:00
}
void InputManager::toggleControlSwitch(const std::string& sw, bool value)
2013-06-16 17:43:59 +00:00
{
mControlSwitch->set(sw, value);
2013-06-16 17:43:59 +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-12 18:45:02 +00:00
std::string InputManager::getActionDescription(int action)
2012-08-12 18:45:02 +00:00
{
return mBindingsManager->getActionDescription(action);
2012-08-12 18:45:02 +00:00
}
std::string InputManager::getActionKeyBindingName(int action)
2014-12-09 03:57:32 +00:00
{
return mBindingsManager->getActionKeyBindingName(action);
2012-08-12 18:45:02 +00:00
}
std::string InputManager::getActionControllerBindingName(int action)
{
return mBindingsManager->getActionControllerBindingName(action);
}
2014-12-09 03:57:32 +00:00
std::vector<int> InputManager::getActionKeySorting()
{
return mBindingsManager->getActionKeySorting();
}
std::vector<int> InputManager::getActionControllerSorting()
{
return mBindingsManager->getActionControllerSorting();
}
void InputManager::enableDetectingBindingMode(int action, bool keyboard)
{
mBindingsManager->enableDetectingBindingMode(action, keyboard);
}
2016-10-20 00:12:01 +00:00
int InputManager::countSavedGameRecords() const
2012-08-12 18:45:02 +00:00
{
return mControlSwitch->countSavedGameRecords();
2012-08-12 18:45:02 +00:00
}
void InputManager::write(ESM::ESMWriter& writer, Loading::Listener& progress)
2014-12-09 03:57:32 +00:00
{
mControlSwitch->write(writer, progress);
2014-12-09 03:57:32 +00:00
}
2016-10-20 00:12:01 +00:00
void InputManager::readRecord(ESM::ESMReader& reader, uint32_t type)
2014-12-09 03:57:32 +00:00
{
2016-10-20 00:12:01 +00:00
if (type == ESM::REC_INPU)
2014-12-09 03:57:32 +00:00
{
mControlSwitch->readRecord(reader, type);
2014-12-09 03:57:32 +00:00
}
}
void InputManager::resetToDefaultKeyBindings()
{
mBindingsManager->loadKeyDefaults(true);
2014-12-09 03:57:32 +00:00
}
void InputManager::resetToDefaultControllerBindings()
{
mBindingsManager->loadControllerDefaults(true);
2014-12-09 03:57:32 +00:00
}
void InputManager::setJoystickLastUsed(bool enabled)
{
mControllerManager->setJoystickLastUsed(enabled);
}
bool InputManager::joystickLastUsed()
{
return mControllerManager->joystickLastUsed();
2013-07-29 00:32:08 +00:00
}
void InputManager::executeAction(int action)
2013-07-29 00:32:08 +00:00
{
mActionManager->executeAction(action);
}
2010-07-17 17:58:15 +00:00
}