diff --git a/apps/openmw/mwinput/actionmanager.cpp b/apps/openmw/mwinput/actionmanager.cpp index e90a4ddaf..f2af3089d 100644 --- a/apps/openmw/mwinput/actionmanager.cpp +++ b/apps/openmw/mwinput/actionmanager.cpp @@ -218,22 +218,22 @@ namespace MWInput handleGuiArrowKey(action); break; case A_Journal: - toggleJournal (); + toggleJournal(); break; case A_AutoMove: - toggleAutoMove (); + toggleAutoMove(); break; case A_AlwaysRun: - toggleWalking (); + toggleWalking(); break; case A_ToggleWeapon: - toggleWeapon (); + toggleWeapon(); break; case A_Rest: rest(); break; case A_ToggleSpell: - toggleSpell (); + toggleSpell(); break; case A_QuickKey1: quickKey(1); @@ -344,9 +344,9 @@ namespace MWInput { osg::ref_ptr screenshot (new osg::Image); - if (MWBase::Environment::get().getWorld()->screenshot360(screenshot.get(),settingStr)) + if (MWBase::Environment::get().getWorld()->screenshot360(screenshot.get(), settingStr)) { - (*mScreenCaptureOperation) (*(screenshot.get()),0); + (*mScreenCaptureOperation) (*(screenshot.get()), 0); // FIXME: mScreenCaptureHandler->getCaptureOperation() causes crash for some reason } } @@ -444,10 +444,10 @@ namespace MWInput if (!MWBase::Environment::get().getInputManager()->getControlSwitch("playercontrols")) return; - if (!MWBase::Environment::get().getWindowManager()->getRestEnabled () || MWBase::Environment::get().getWindowManager()->isGuiMode ()) + if (!MWBase::Environment::get().getWindowManager()->getRestEnabled() || MWBase::Environment::get().getWindowManager()->isGuiMode()) return; - MWBase::Environment::get().getWindowManager()->pushGuiMode (MWGui::GM_Rest); //Open rest GUI + MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Rest); //Open rest GUI } void ActionManager::toggleInventory() @@ -476,7 +476,7 @@ namespace MWInput void ActionManager::toggleConsole() { - if (MyGUI::InputManager::getInstance ().isModalAny()) + if (MyGUI::InputManager::getInstance().isModalAny()) return; MWBase::Environment::get().getWindowManager()->toggleConsole(); @@ -489,14 +489,14 @@ namespace MWInput if (MyGUI::InputManager::getInstance ().isModalAny()) return; - if(MWBase::Environment::get().getWindowManager()->getMode() != MWGui::GM_Journal + if (MWBase::Environment::get().getWindowManager()->getMode() != MWGui::GM_Journal && MWBase::Environment::get().getWindowManager()->getMode() != MWGui::GM_MainMenu && MWBase::Environment::get().getWindowManager()->getMode() != MWGui::GM_Settings && MWBase::Environment::get().getWindowManager ()->getJournalAllowed()) { MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Journal); } - else if(MWBase::Environment::get().getWindowManager()->containsMode(MWGui::GM_Journal)) + else if (MWBase::Environment::get().getWindowManager()->containsMode(MWGui::GM_Journal)) { MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Journal); } @@ -528,7 +528,7 @@ namespace MWInput } else if (MWBase::Environment::get().getWindowManager()->getMode () == MWGui::GM_QuickKeysMenu) { - while(MyGUI::InputManager::getInstance().isModalAny()) + while (MyGUI::InputManager::getInstance().isModalAny()) { //Handle any open Modal windows MWBase::Environment::get().getWindowManager()->exitCurrentModal(); } @@ -579,10 +579,6 @@ namespace MWInput player.setSneak(mSneaking); } - void ActionManager::clear() - { - } - void ActionManager::handleGuiArrowKey(int action) { bool joystickUsed = MWBase::Environment::get().getInputManager()->joystickLastUsed(); diff --git a/apps/openmw/mwinput/actionmanager.hpp b/apps/openmw/mwinput/actionmanager.hpp index 31fd993c9..7aa73f520 100644 --- a/apps/openmw/mwinput/actionmanager.hpp +++ b/apps/openmw/mwinput/actionmanager.hpp @@ -23,8 +23,6 @@ namespace MWInput osg::ref_ptr viewer, osg::ref_ptr screenCaptureHandler); - void clear(); - void update(float dt, bool triedToMove); void executeAction(int action); diff --git a/apps/openmw/mwinput/bindingsmanager.cpp b/apps/openmw/mwinput/bindingsmanager.cpp index f871f0c51..f21e184b7 100644 --- a/apps/openmw/mwinput/bindingsmanager.cpp +++ b/apps/openmw/mwinput/bindingsmanager.cpp @@ -72,7 +72,7 @@ namespace MWInput , SDL_Scancode key, ICS::Control::ControlChangingDirection direction) { //Disallow binding escape key - if(key==SDL_SCANCODE_ESCAPE) + if (key==SDL_SCANCODE_ESCAPE) { //Stop binding if esc pressed mInputBinder->cancelDetectingBindingState(); @@ -90,7 +90,7 @@ namespace MWInput return; #endif - if(!mDetectingKeyboard) + if (!mDetectingKeyboard) return; clearAllKeyBindings(mInputBinder, control); @@ -109,7 +109,7 @@ namespace MWInput virtual void mouseButtonBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control , unsigned int button, ICS::Control::ControlChangingDirection direction) { - if(!mDetectingKeyboard) + if (!mDetectingKeyboard) return; clearAllKeyBindings(mInputBinder, control); control->setInitialValue(0.0f); @@ -120,7 +120,7 @@ namespace MWInput virtual void mouseWheelBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control , ICS::InputControlSystem::MouseWheelClick click, ICS::Control::ControlChangingDirection direction) { - if(!mDetectingKeyboard) + if (!mDetectingKeyboard) return; clearAllKeyBindings(mInputBinder, control); control->setInitialValue(0.0f); @@ -132,9 +132,9 @@ namespace MWInput , int axis, ICS::Control::ControlChangingDirection direction) { //only allow binding to the trigers - if(axis != SDL_CONTROLLER_AXIS_TRIGGERLEFT && axis != SDL_CONTROLLER_AXIS_TRIGGERRIGHT) + if (axis != SDL_CONTROLLER_AXIS_TRIGGERLEFT && axis != SDL_CONTROLLER_AXIS_TRIGGERRIGHT) return; - if(mDetectingKeyboard) + if (mDetectingKeyboard) return; clearAllControllerBindings(mInputBinder, control); @@ -147,7 +147,7 @@ namespace MWInput virtual void joystickButtonBindingDetected(ICS::InputControlSystem* ICS, int deviceID, ICS::Control* control , unsigned int button, ICS::Control::ControlChangingDirection direction) { - if(mDetectingKeyboard) + if (mDetectingKeyboard) return; clearAllControllerBindings(mInputBinder,control); control->setInitialValue(0.0f); @@ -220,8 +220,8 @@ namespace MWInput A_QuickKey7, A_QuickKey8, A_QuickKey9, A_QuickKey10, A_Use, A_Journal}; - for(size_t i = 0; i < sizeof(playerChannels)/sizeof(playerChannels[0]); i++) { - int pc = playerChannels[i]; + for(int pc : playerChannels) + { mInputBinder->getChannel(pc)->setEnabled(enabled); } } @@ -293,7 +293,7 @@ namespace MWInput for (int i = 0; i < A_Last; ++i) { ICS::Control* control; - bool controlExists = mInputBinder->getChannel(i)->getControlsCount () != 0; + bool controlExists = mInputBinder->getChannel(i)->getControlsCount() != 0; if (!controlExists) { control = new ICS::Control(std::to_string(i), false, true, 0, ICS::ICS_MAX, ICS::ICS_MAX); @@ -302,14 +302,13 @@ namespace MWInput } else { - control = mInputBinder->getChannel(i)->getAttachedControls ().front().control; + control = mInputBinder->getChannel(i)->getAttachedControls().front().control; } if (!controlExists || force || - ( mInputBinder->getKeyBinding (control, ICS::Control::INCREASE) == SDL_SCANCODE_UNKNOWN - && mInputBinder->getMouseButtonBinding (control, ICS::Control::INCREASE) == ICS_MAX_DEVICE_BUTTONS - && mInputBinder->getMouseWheelBinding(control, ICS::Control::INCREASE) == ICS::InputControlSystem::MouseWheelClick::UNASSIGNED - )) + (mInputBinder->getKeyBinding(control, ICS::Control::INCREASE) == SDL_SCANCODE_UNKNOWN + && mInputBinder->getMouseButtonBinding(control, ICS::Control::INCREASE) == ICS_MAX_DEVICE_BUTTONS + && mInputBinder->getMouseWheelBinding(control, ICS::Control::INCREASE) == ICS::InputControlSystem::MouseWheelClick::UNASSIGNED)) { clearAllKeyBindings(mInputBinder, control); @@ -323,7 +322,7 @@ namespace MWInput && (force || !mInputBinder->isMouseButtonBound(defaultMouseButtonBindings[i]))) { control->setInitialValue(0.0f); - mInputBinder->addMouseButtonBinding (control, defaultMouseButtonBindings[i], ICS::Control::INCREASE); + mInputBinder->addMouseButtonBinding(control, defaultMouseButtonBindings[i], ICS::Control::INCREASE); } else if (defaultMouseWheelBindings.find(i) != defaultMouseWheelBindings.end() && (force || !mInputBinder->isMouseWheelBound(defaultMouseWheelBindings[i]))) @@ -379,7 +378,7 @@ namespace MWInput for (int i = 0; i < A_Last; i++) { ICS::Control* control; - bool controlExists = mInputBinder->getChannel(i)->getControlsCount () != 0; + bool controlExists = mInputBinder->getChannel(i)->getControlsCount() != 0; if (!controlExists) { float initial; @@ -392,10 +391,11 @@ namespace MWInput } else { - control = mInputBinder->getChannel(i)->getAttachedControls ().front().control; + control = mInputBinder->getChannel(i)->getAttachedControls().front().control; } - if (!controlExists || force || ( mInputBinder->getJoystickAxisBinding (control, sFakeDeviceId, ICS::Control::INCREASE) == ICS::InputControlSystem::UNASSIGNED && mInputBinder->getJoystickButtonBinding (control, sFakeDeviceId, ICS::Control::INCREASE) == ICS_MAX_DEVICE_BUTTONS )) + if (!controlExists || force || (mInputBinder->getJoystickAxisBinding(control, sFakeDeviceId, ICS::Control::INCREASE) == ICS::InputControlSystem::UNASSIGNED && + mInputBinder->getJoystickButtonBinding(control, sFakeDeviceId, ICS::Control::INCREASE) == ICS_MAX_DEVICE_BUTTONS)) { clearAllControllerBindings(mInputBinder, control); @@ -415,7 +415,7 @@ namespace MWInput } } - std::string BindingsManager::getActionDescription (int action) + std::string BindingsManager::getActionDescription(int action) { std::map descriptions; @@ -464,24 +464,24 @@ namespace MWInput descriptions[A_QuickSave] = "sQuickSaveCmd"; descriptions[A_QuickLoad] = "sQuickLoadCmd"; - if (descriptions[action] == "") - return ""; // not configurable + if (descriptions[action].empty()) + return std::string(); // not configurable return "#{" + descriptions[action] + "}"; } - std::string BindingsManager::getActionKeyBindingName (int action) + std::string BindingsManager::getActionKeyBindingName(int action) { - if (mInputBinder->getChannel (action)->getControlsCount () == 0) + if (mInputBinder->getChannel(action)->getControlsCount() == 0) return "#{sNone}"; - ICS::Control* c = mInputBinder->getChannel (action)->getAttachedControls ().front().control; + ICS::Control* c = mInputBinder->getChannel(action)->getAttachedControls().front().control; - SDL_Scancode key = mInputBinder->getKeyBinding (c, ICS::Control::INCREASE); - unsigned int mouse = mInputBinder->getMouseButtonBinding (c, ICS::Control::INCREASE); + SDL_Scancode key = mInputBinder->getKeyBinding(c, ICS::Control::INCREASE); + unsigned int mouse = mInputBinder->getMouseButtonBinding(c, ICS::Control::INCREASE); ICS::InputControlSystem::MouseWheelClick wheel = mInputBinder->getMouseWheelBinding(c, ICS::Control::INCREASE); if (key != SDL_SCANCODE_UNKNOWN) - return MyGUI::TextIterator::toTagsString(mInputBinder->scancodeToString (key)); + return MyGUI::TextIterator::toTagsString(mInputBinder->scancodeToString(key)); else if (mouse != ICS_MAX_DEVICE_BUTTONS) return "#{sMouse} " + std::to_string(mouse); else if (wheel != ICS::InputControlSystem::MouseWheelClick::UNASSIGNED) @@ -502,17 +502,17 @@ namespace MWInput return "#{sNone}"; } - std::string BindingsManager::getActionControllerBindingName (int action) + std::string BindingsManager::getActionControllerBindingName(int action) { - if (mInputBinder->getChannel (action)->getControlsCount () == 0) + if (mInputBinder->getChannel(action)->getControlsCount() == 0) return "#{sNone}"; - ICS::Control* c = mInputBinder->getChannel (action)->getAttachedControls ().front().control; + ICS::Control* c = mInputBinder->getChannel(action)->getAttachedControls().front().control; - if (mInputBinder->getJoystickAxisBinding (c, sFakeDeviceId, ICS::Control::INCREASE) != ICS::InputControlSystem::UNASSIGNED) - return sdlControllerAxisToString(mInputBinder->getJoystickAxisBinding (c, sFakeDeviceId, ICS::Control::INCREASE)); - else if (mInputBinder->getJoystickButtonBinding (c, sFakeDeviceId, ICS::Control::INCREASE) != ICS_MAX_DEVICE_BUTTONS ) - return sdlControllerButtonToString(mInputBinder->getJoystickButtonBinding (c, sFakeDeviceId, ICS::Control::INCREASE)); + if (mInputBinder->getJoystickAxisBinding(c, sFakeDeviceId, ICS::Control::INCREASE) != ICS::InputControlSystem::UNASSIGNED) + return sdlControllerAxisToString(mInputBinder->getJoystickAxisBinding(c, sFakeDeviceId, ICS::Control::INCREASE)); + else if (mInputBinder->getJoystickButtonBinding(c, sFakeDeviceId, ICS::Control::INCREASE) != ICS_MAX_DEVICE_BUTTONS) + return sdlControllerButtonToString(mInputBinder->getJoystickButtonBinding(c, sFakeDeviceId, ICS::Control::INCREASE)); else return "#{sNone}"; } @@ -680,17 +680,17 @@ namespace MWInput if (mDragDrop && action != A_GameMenu && action != A_Inventory) return; - if((previousValue == 1 || previousValue == 0) && (currentValue==1 || currentValue==0)) + if ((previousValue == 1 || previousValue == 0) && (currentValue==1 || currentValue==0)) { //Is a normal button press, so don't change it at all } //Otherwise only trigger button presses as they go through specific points - else if(previousValue >= .8 && currentValue < .8) + else if (previousValue >= 0.8 && currentValue < 0.8) { currentValue = 0.0; previousValue = 1.0; } - else if(previousValue <= .6 && currentValue > .6) + else if (previousValue <= 0.6 && currentValue > 0.6) { currentValue = 1.0; previousValue = 0.0; @@ -706,7 +706,7 @@ namespace MWInput bool joystickUsed = MWBase::Environment::get().getInputManager()->joystickLastUsed(); if (action == A_Use) { - if(joystickUsed && currentValue == 1.0 && actionIsActive(A_ToggleWeapon)) + if (joystickUsed && currentValue == 1.0 && actionIsActive(A_ToggleWeapon)) action = A_CycleWeaponRight; else if (joystickUsed && currentValue == 1.0 && actionIsActive(A_ToggleSpell)) @@ -721,7 +721,7 @@ namespace MWInput } else if (action == A_Jump) { - if(joystickUsed && currentValue == 1.0 && actionIsActive(A_ToggleWeapon)) + if (joystickUsed && currentValue == 1.0 && actionIsActive(A_ToggleWeapon)) action = A_CycleWeaponLeft; else if (joystickUsed && currentValue == 1.0 && actionIsActive(A_ToggleSpell)) diff --git a/apps/openmw/mwinput/controllermanager.cpp b/apps/openmw/mwinput/controllermanager.cpp index b8fc0ca74..5c5246caf 100644 --- a/apps/openmw/mwinput/controllermanager.cpp +++ b/apps/openmw/mwinput/controllermanager.cpp @@ -41,20 +41,21 @@ namespace MWInput , mSneakGamepadShortcut(false) , mGamepadPreviewMode(false) { - if(!controllerBindingsFile.empty()) + if (!controllerBindingsFile.empty()) { SDL_GameControllerAddMappingsFromFile(controllerBindingsFile.c_str()); } - if(!userControllerBindingsFile.empty()) + + if (!userControllerBindingsFile.empty()) { SDL_GameControllerAddMappingsFromFile(userControllerBindingsFile.c_str()); } // Open all presently connected sticks int numSticks = SDL_NumJoysticks(); - for(int i = 0; i < numSticks; i++) + for (int i = 0; i < numSticks; i++) { - if(SDL_IsGameController(i)) + if (SDL_IsGameController(i)) { SDL_ControllerDeviceEvent evt; evt.which = i; @@ -73,10 +74,6 @@ namespace MWInput mInvUiScalingFactor = 1.f / uiScale; } - void ControllerManager::clear() - { - } - void ControllerManager::processChangedSettings(const Settings::CategorySettingVector& changed) { for (const auto& setting : changed) @@ -131,13 +128,13 @@ namespace MWInput { float xAxis = mBindingsManager->getActionValue(A_MoveLeftRight); float yAxis = mBindingsManager->getActionValue(A_MoveForwardBackward); - if (xAxis != .5) + if (xAxis != 0.5) { triedToMove = true; player.setLeftRight((xAxis - 0.5f) * 2); } - if (yAxis != .5) + if (yAxis != 0.5) { triedToMove = true; player.setAutoMove (false); @@ -153,13 +150,13 @@ namespace MWInput static const bool isToggleSneak = Settings::Manager::getBool("toggle sneak", "Input"); if (!isToggleSneak) { - if(mJoystickLastUsed) + if (mJoystickLastUsed) { - if(mBindingsManager->actionIsActive(A_Sneak)) + if (mBindingsManager->actionIsActive(A_Sneak)) { - if(mSneakToggleShortcutTimer) // New Sneak Button Press + if (mSneakToggleShortcutTimer) // New Sneak Button Press { - if(mSneakToggleShortcutTimer <= 0.3f) + if (mSneakToggleShortcutTimer <= 0.3f) { mSneakGamepadShortcut = true; mActionManager->toggleSneaking(); @@ -168,15 +165,15 @@ namespace MWInput mSneakGamepadShortcut = false; } - if(!mActionManager->isSneaking()) + if (!mActionManager->isSneaking()) mActionManager->toggleSneaking(); mSneakToggleShortcutTimer = 0.f; } else { - if(!mSneakGamepadShortcut && mActionManager->isSneaking()) + if (!mSneakGamepadShortcut && mActionManager->isSneaking()) mActionManager->toggleSneaking(); - if(mSneakToggleShortcutTimer <= 0.3f) + if (mSneakToggleShortcutTimer <= 0.3f) mSneakToggleShortcutTimer += dt; } } @@ -190,7 +187,7 @@ namespace MWInput if (!mBindingsManager->actionIsActive(A_TogglePOV)) mGamepadZoom = 0; - if(mGamepadZoom) + if (mGamepadZoom) { MWBase::Environment::get().getWorld()->changeVanityModeScale(mGamepadZoom); MWBase::Environment::get().getWorld()->setCameraDistance(mGamepadZoom, true, true); @@ -210,6 +207,7 @@ namespace MWInput { if (gamepadToGuiControl(arg)) return; + if (mGamepadGuiCursorEnabled) { // Temporary mouse binding until keyboard controls are available: @@ -245,6 +243,7 @@ namespace MWInput mBindingsManager->controllerButtonReleased(deviceID, arg); return; } + if (!mJoystickEnabled || mControlsDisabled) return; @@ -276,7 +275,7 @@ namespace MWInput void ControllerManager::axisMoved(int deviceID, const SDL_ControllerAxisEvent &arg) { - if(!mJoystickEnabled || mControlsDisabled) + if (!mJoystickEnabled || mControlsDisabled) return; mJoystickLastUsed = true; @@ -286,14 +285,14 @@ namespace MWInput } else { - if(mGamepadPreviewMode && arg.value) // Preview Mode Gamepad Zooming + if (mGamepadPreviewMode && arg.value) // Preview Mode Gamepad Zooming { - if(arg.axis == SDL_CONTROLLER_AXIS_TRIGGERRIGHT) + if (arg.axis == SDL_CONTROLLER_AXIS_TRIGGERRIGHT) { mGamepadZoom = arg.value * 0.85f / 1000.f; return; // Do not propagate event. } - else if(arg.axis == SDL_CONTROLLER_AXIS_TRIGGERLEFT) + else if (arg.axis == SDL_CONTROLLER_AXIS_TRIGGERLEFT) { mGamepadZoom = -arg.value * 0.85f / 1000.f; return; // Do not propagate event. diff --git a/apps/openmw/mwinput/controllermanager.hpp b/apps/openmw/mwinput/controllermanager.hpp index f1be50ee6..6b9546b0c 100644 --- a/apps/openmw/mwinput/controllermanager.hpp +++ b/apps/openmw/mwinput/controllermanager.hpp @@ -23,8 +23,6 @@ namespace MWInput virtual ~ControllerManager() = default; - void clear(); - bool update(float dt, bool disableControls); virtual void buttonPressed(int deviceID, const SDL_ControllerButtonEvent &arg); diff --git a/apps/openmw/mwinput/inputmanagerimp.cpp b/apps/openmw/mwinput/inputmanagerimp.cpp index fb49ff464..4f1ee7855 100644 --- a/apps/openmw/mwinput/inputmanagerimp.cpp +++ b/apps/openmw/mwinput/inputmanagerimp.cpp @@ -58,11 +58,6 @@ namespace MWInput { // Enable all controls mControlSwitch->clear(); - - mActionManager->clear(); - mControllerManager->clear(); - mSensorManager->clear(); - mMouseManager->clear(); } InputManager::~InputManager() @@ -90,19 +85,19 @@ namespace MWInput bool grab = !MWBase::Environment::get().getWindowManager()->containsMode(MWGui::GM_MainMenu) && !MWBase::Environment::get().getWindowManager()->isConsoleMode(); - bool was_relative = mInputWrapper->getMouseRelative(); - bool is_relative = !MWBase::Environment::get().getWindowManager()->isGuiMode(); + bool wasRelative = mInputWrapper->getMouseRelative(); + bool isRelative = !MWBase::Environment::get().getWindowManager()->isGuiMode(); // don't keep the pointer away from the window edge in gui mode // stop using raw mouse motions and switch to system cursor movements - mInputWrapper->setMouseRelative(is_relative); + mInputWrapper->setMouseRelative(isRelative); //we let the mouse escape in the main menu - mInputWrapper->setGrabPointer(grab && (mGrabCursor || is_relative)); + mInputWrapper->setGrabPointer(grab && (mGrabCursor || isRelative)); //we switched to non-relative mode, move our cursor to where the in-game //cursor is - if(!is_relative && was_relative != is_relative) + if (!isRelative && wasRelative != isRelative) { mMouseManager->warpMouse(); } @@ -148,7 +143,9 @@ namespace MWInput mMouseManager->setMouseLookEnabled(!guiMode); if (guiMode) MWBase::Environment::get().getWindowManager()->showCrosshair(false); - MWBase::Environment::get().getWindowManager()->setCursorVisible(guiMode && (!mControllerManager->joystickLastUsed() || mControllerManager->gamepadGuiCursorEnabled())); + + 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. } diff --git a/apps/openmw/mwinput/inputmanagerimp.hpp b/apps/openmw/mwinput/inputmanagerimp.hpp index 211a09583..4ecb6a82d 100644 --- a/apps/openmw/mwinput/inputmanagerimp.hpp +++ b/apps/openmw/mwinput/inputmanagerimp.hpp @@ -13,17 +13,6 @@ #include "actions.hpp" -namespace MWInput -{ - class ControlSwitch; - class ActionManager; - class BindingsManager; - class ControllerManager; - class KeyboardManager; - class MouseManager; - class SensorManager; -} - namespace MWWorld { class Player; @@ -43,11 +32,18 @@ struct SDL_Window; namespace MWInput { + class ControlSwitch; + class ActionManager; + class BindingsManager; + class ControllerManager; + class KeyboardManager; + class MouseManager; + class SensorManager; + /** - * @brief Class that handles all input and key bindings for OpenMW. + * @brief Class that provides a high-level API for game input */ - class InputManager : - public MWBase::InputManager + class InputManager : public MWBase::InputManager { public: InputManager( @@ -99,6 +95,18 @@ namespace MWInput virtual void executeAction(int action); private: + void convertMousePosForMyGUI(int& x, int& y); + + void handleGuiArrowKey(int action); + + void updateCursorMode(); + + void quickKey(int index); + void showQuickKeysMenu(); + + void loadKeyDefaults(bool force = false); + void loadControllerDefaults(bool force = false); + SDLUtil::InputWrapper* mInputWrapper; bool mGrabCursor; @@ -111,18 +119,6 @@ namespace MWInput KeyboardManager* mKeyboardManager; MouseManager* mMouseManager; SensorManager* mSensorManager; - - void convertMousePosForMyGUI(int& x, int& y); - - void handleGuiArrowKey(int action); - - void updateCursorMode(); - - void quickKey(int index); - void showQuickKeysMenu(); - - void loadKeyDefaults(bool force = false); - void loadControllerDefaults(bool force = false); }; } #endif diff --git a/apps/openmw/mwinput/keyboardmanager.cpp b/apps/openmw/mwinput/keyboardmanager.cpp index 159ea388f..afeef632f 100644 --- a/apps/openmw/mwinput/keyboardmanager.cpp +++ b/apps/openmw/mwinput/keyboardmanager.cpp @@ -47,11 +47,13 @@ namespace MWInput consumed = true; mBindingsManager->setPlayerControlsEnabled(!consumed); } + if (arg.repeat) return; if (!mControlsDisabled && !consumed) mBindingsManager->keyPressed(arg); + MWBase::Environment::get().getInputManager()->setJoystickLastUsed(false); } diff --git a/apps/openmw/mwinput/mousemanager.cpp b/apps/openmw/mwinput/mousemanager.cpp index 30e32bef8..cc20cc1ef 100644 --- a/apps/openmw/mwinput/mousemanager.cpp +++ b/apps/openmw/mwinput/mousemanager.cpp @@ -47,10 +47,6 @@ namespace MWInput mGuiCursorY = mInvUiScalingFactor * h / 2.f; } - void MouseManager::clear() - { - } - void MouseManager::processChangedSettings(const Settings::CategorySettingVector& changed) { for (const auto& setting : changed) @@ -103,7 +99,7 @@ namespace MWInput rot[2] = -x; // Only actually turn player when we're not in vanity mode - if(!MWBase::Environment::get().getWorld()->vanityRotateCamera(rot) && input->getControlSwitch("playerlooking")) + if (!MWBase::Environment::get().getWorld()->vanityRotateCamera(rot) && input->getControlSwitch("playerlooking")) { MWWorld::Player& player = MWBase::Environment::get().getWorld()->getPlayer(); player.yaw(x); @@ -130,7 +126,8 @@ namespace MWInput bool guiMode = MWBase::Environment::get().getWindowManager()->isGuiMode(); guiMode = MyGUI::InputManager::getInstance().injectMouseRelease(static_cast(mGuiCursorX), static_cast(mGuiCursorY), sdlButtonToMyGUI(id)) && guiMode; - if(mBindingsManager->isDetectingBindingState()) return; // don't allow same mouseup to bind as initiated bind + if (mBindingsManager->isDetectingBindingState()) + return; // don't allow same mouseup to bind as initiated bind mBindingsManager->setPlayerControlsEnabled(!guiMode); mBindingsManager->mouseReleased(arg, id); @@ -154,9 +151,9 @@ namespace MWInput { guiMode = MWBase::Environment::get().getWindowManager()->isGuiMode(); guiMode = MyGUI::InputManager::getInstance().injectMousePress(static_cast(mGuiCursorX), static_cast(mGuiCursorY), sdlButtonToMyGUI(id)) && guiMode; - if (MyGUI::InputManager::getInstance ().getMouseFocusWidget () != 0) + if (MyGUI::InputManager::getInstance().getMouseFocusWidget () != 0) { - MyGUI::Button* b = MyGUI::InputManager::getInstance ().getMouseFocusWidget ()->castType(false); + MyGUI::Button* b = MyGUI::InputManager::getInstance().getMouseFocusWidget()->castType(false); if (b && b->getEnabled() && id == SDL_BUTTON_LEFT) { MWBase::Environment::get().getWindowManager()->playSound("Menu Click"); diff --git a/apps/openmw/mwinput/mousemanager.hpp b/apps/openmw/mwinput/mousemanager.hpp index 2686c59b7..58d97f6e5 100644 --- a/apps/openmw/mwinput/mousemanager.hpp +++ b/apps/openmw/mwinput/mousemanager.hpp @@ -20,8 +20,6 @@ namespace MWInput virtual ~MouseManager() = default; - void clear(); - void update(float dt, bool disableControls); virtual void mouseMoved(const SDLUtil::MouseMotionEvent &arg); diff --git a/apps/openmw/mwinput/sdlmappings.cpp b/apps/openmw/mwinput/sdlmappings.cpp index 8a9ccf4e7..0c3f5c5d8 100644 --- a/apps/openmw/mwinput/sdlmappings.cpp +++ b/apps/openmw/mwinput/sdlmappings.cpp @@ -206,14 +206,11 @@ namespace MWInput { static std::map keyMap; if (keyMap.empty()) - { initKeyMap(keyMap); - } MyGUI::KeyCode kc = MyGUI::KeyCode::None; - auto foundKey = keyMap.find(code); - if(foundKey != keyMap.end()) + if (foundKey != keyMap.end()) kc = foundKey->second; return kc; diff --git a/apps/openmw/mwinput/sensormanager.cpp b/apps/openmw/mwinput/sensormanager.cpp index 02669798c..d70662f6a 100644 --- a/apps/openmw/mwinput/sensormanager.cpp +++ b/apps/openmw/mwinput/sensormanager.cpp @@ -33,13 +33,6 @@ namespace MWInput updateSensors(); } - void SensorManager::clear() - { - mGyroXSpeed = 0.f; - mGyroYSpeed = 0.f; - mGyroUpdateTimer = 0.f; - } - SensorManager::~SensorManager() { if (mGyroscope != nullptr) @@ -246,7 +239,8 @@ namespace MWInput // More than half of second passed since the last gyroscope update. // A device more likely was disconnected or switched to the sleep mode. // Reset current rotation speed and wait for update. - clear(); + mGyroXSpeed = 0.f; + mGyroYSpeed = 0.f; mGyroUpdateTimer = 0.f; return; } diff --git a/apps/openmw/mwinput/sensormanager.hpp b/apps/openmw/mwinput/sensormanager.hpp index 9b24328f7..8f333ad31 100644 --- a/apps/openmw/mwinput/sensormanager.hpp +++ b/apps/openmw/mwinput/sensormanager.hpp @@ -27,8 +27,6 @@ namespace MWInput void init(); - void clear(); - void update(float dt); virtual void sensorUpdated(const SDL_SensorEvent &arg);