Formatting changes

pull/578/head
Andrei Kortunov 5 years ago
parent 85f91a7de8
commit b575712cb1

@ -218,22 +218,22 @@ namespace MWInput
handleGuiArrowKey(action); handleGuiArrowKey(action);
break; break;
case A_Journal: case A_Journal:
toggleJournal (); toggleJournal();
break; break;
case A_AutoMove: case A_AutoMove:
toggleAutoMove (); toggleAutoMove();
break; break;
case A_AlwaysRun: case A_AlwaysRun:
toggleWalking (); toggleWalking();
break; break;
case A_ToggleWeapon: case A_ToggleWeapon:
toggleWeapon (); toggleWeapon();
break; break;
case A_Rest: case A_Rest:
rest(); rest();
break; break;
case A_ToggleSpell: case A_ToggleSpell:
toggleSpell (); toggleSpell();
break; break;
case A_QuickKey1: case A_QuickKey1:
quickKey(1); quickKey(1);
@ -344,9 +344,9 @@ namespace MWInput
{ {
osg::ref_ptr<osg::Image> screenshot (new osg::Image); osg::ref_ptr<osg::Image> 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 // FIXME: mScreenCaptureHandler->getCaptureOperation() causes crash for some reason
} }
} }
@ -444,10 +444,10 @@ namespace MWInput
if (!MWBase::Environment::get().getInputManager()->getControlSwitch("playercontrols")) if (!MWBase::Environment::get().getInputManager()->getControlSwitch("playercontrols"))
return; return;
if (!MWBase::Environment::get().getWindowManager()->getRestEnabled () || MWBase::Environment::get().getWindowManager()->isGuiMode ()) if (!MWBase::Environment::get().getWindowManager()->getRestEnabled() || MWBase::Environment::get().getWindowManager()->isGuiMode())
return; 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() void ActionManager::toggleInventory()
@ -476,7 +476,7 @@ namespace MWInput
void ActionManager::toggleConsole() void ActionManager::toggleConsole()
{ {
if (MyGUI::InputManager::getInstance ().isModalAny()) if (MyGUI::InputManager::getInstance().isModalAny())
return; return;
MWBase::Environment::get().getWindowManager()->toggleConsole(); MWBase::Environment::get().getWindowManager()->toggleConsole();
@ -489,14 +489,14 @@ namespace MWInput
if (MyGUI::InputManager::getInstance ().isModalAny()) if (MyGUI::InputManager::getInstance ().isModalAny())
return; 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_MainMenu
&& MWBase::Environment::get().getWindowManager()->getMode() != MWGui::GM_Settings && MWBase::Environment::get().getWindowManager()->getMode() != MWGui::GM_Settings
&& MWBase::Environment::get().getWindowManager ()->getJournalAllowed()) && MWBase::Environment::get().getWindowManager ()->getJournalAllowed())
{ {
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Journal); 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); MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Journal);
} }
@ -528,7 +528,7 @@ namespace MWInput
} }
else if (MWBase::Environment::get().getWindowManager()->getMode () == MWGui::GM_QuickKeysMenu) 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 { //Handle any open Modal windows
MWBase::Environment::get().getWindowManager()->exitCurrentModal(); MWBase::Environment::get().getWindowManager()->exitCurrentModal();
} }
@ -579,10 +579,6 @@ namespace MWInput
player.setSneak(mSneaking); player.setSneak(mSneaking);
} }
void ActionManager::clear()
{
}
void ActionManager::handleGuiArrowKey(int action) void ActionManager::handleGuiArrowKey(int action)
{ {
bool joystickUsed = MWBase::Environment::get().getInputManager()->joystickLastUsed(); bool joystickUsed = MWBase::Environment::get().getInputManager()->joystickLastUsed();

@ -23,8 +23,6 @@ namespace MWInput
osg::ref_ptr<osgViewer::Viewer> viewer, osg::ref_ptr<osgViewer::Viewer> viewer,
osg::ref_ptr<osgViewer::ScreenCaptureHandler> screenCaptureHandler); osg::ref_ptr<osgViewer::ScreenCaptureHandler> screenCaptureHandler);
void clear();
void update(float dt, bool triedToMove); void update(float dt, bool triedToMove);
void executeAction(int action); void executeAction(int action);

@ -72,7 +72,7 @@ namespace MWInput
, SDL_Scancode key, ICS::Control::ControlChangingDirection direction) , SDL_Scancode key, ICS::Control::ControlChangingDirection direction)
{ {
//Disallow binding escape key //Disallow binding escape key
if(key==SDL_SCANCODE_ESCAPE) if (key==SDL_SCANCODE_ESCAPE)
{ {
//Stop binding if esc pressed //Stop binding if esc pressed
mInputBinder->cancelDetectingBindingState(); mInputBinder->cancelDetectingBindingState();
@ -90,7 +90,7 @@ namespace MWInput
return; return;
#endif #endif
if(!mDetectingKeyboard) if (!mDetectingKeyboard)
return; return;
clearAllKeyBindings(mInputBinder, control); clearAllKeyBindings(mInputBinder, control);
@ -109,7 +109,7 @@ namespace MWInput
virtual void mouseButtonBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control virtual void mouseButtonBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
, unsigned int button, ICS::Control::ControlChangingDirection direction) , unsigned int button, ICS::Control::ControlChangingDirection direction)
{ {
if(!mDetectingKeyboard) if (!mDetectingKeyboard)
return; return;
clearAllKeyBindings(mInputBinder, control); clearAllKeyBindings(mInputBinder, control);
control->setInitialValue(0.0f); control->setInitialValue(0.0f);
@ -120,7 +120,7 @@ namespace MWInput
virtual void mouseWheelBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control virtual void mouseWheelBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
, ICS::InputControlSystem::MouseWheelClick click, ICS::Control::ControlChangingDirection direction) , ICS::InputControlSystem::MouseWheelClick click, ICS::Control::ControlChangingDirection direction)
{ {
if(!mDetectingKeyboard) if (!mDetectingKeyboard)
return; return;
clearAllKeyBindings(mInputBinder, control); clearAllKeyBindings(mInputBinder, control);
control->setInitialValue(0.0f); control->setInitialValue(0.0f);
@ -132,9 +132,9 @@ namespace MWInput
, int axis, ICS::Control::ControlChangingDirection direction) , int axis, ICS::Control::ControlChangingDirection direction)
{ {
//only allow binding to the trigers //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; return;
if(mDetectingKeyboard) if (mDetectingKeyboard)
return; return;
clearAllControllerBindings(mInputBinder, control); clearAllControllerBindings(mInputBinder, control);
@ -147,7 +147,7 @@ namespace MWInput
virtual void joystickButtonBindingDetected(ICS::InputControlSystem* ICS, int deviceID, ICS::Control* control virtual void joystickButtonBindingDetected(ICS::InputControlSystem* ICS, int deviceID, ICS::Control* control
, unsigned int button, ICS::Control::ControlChangingDirection direction) , unsigned int button, ICS::Control::ControlChangingDirection direction)
{ {
if(mDetectingKeyboard) if (mDetectingKeyboard)
return; return;
clearAllControllerBindings(mInputBinder,control); clearAllControllerBindings(mInputBinder,control);
control->setInitialValue(0.0f); control->setInitialValue(0.0f);
@ -220,8 +220,8 @@ namespace MWInput
A_QuickKey7, A_QuickKey8, A_QuickKey9, A_QuickKey10, A_QuickKey7, A_QuickKey8, A_QuickKey9, A_QuickKey10,
A_Use, A_Journal}; A_Use, A_Journal};
for(size_t i = 0; i < sizeof(playerChannels)/sizeof(playerChannels[0]); i++) { for(int pc : playerChannels)
int pc = playerChannels[i]; {
mInputBinder->getChannel(pc)->setEnabled(enabled); mInputBinder->getChannel(pc)->setEnabled(enabled);
} }
} }
@ -293,7 +293,7 @@ namespace MWInput
for (int i = 0; i < A_Last; ++i) for (int i = 0; i < A_Last; ++i)
{ {
ICS::Control* control; ICS::Control* control;
bool controlExists = mInputBinder->getChannel(i)->getControlsCount () != 0; bool controlExists = mInputBinder->getChannel(i)->getControlsCount() != 0;
if (!controlExists) if (!controlExists)
{ {
control = new ICS::Control(std::to_string(i), false, true, 0, ICS::ICS_MAX, ICS::ICS_MAX); control = new ICS::Control(std::to_string(i), false, true, 0, ICS::ICS_MAX, ICS::ICS_MAX);
@ -302,14 +302,13 @@ namespace MWInput
} }
else else
{ {
control = mInputBinder->getChannel(i)->getAttachedControls ().front().control; control = mInputBinder->getChannel(i)->getAttachedControls().front().control;
} }
if (!controlExists || force || if (!controlExists || force ||
( mInputBinder->getKeyBinding (control, ICS::Control::INCREASE) == SDL_SCANCODE_UNKNOWN (mInputBinder->getKeyBinding(control, ICS::Control::INCREASE) == SDL_SCANCODE_UNKNOWN
&& mInputBinder->getMouseButtonBinding (control, ICS::Control::INCREASE) == ICS_MAX_DEVICE_BUTTONS && mInputBinder->getMouseButtonBinding(control, ICS::Control::INCREASE) == ICS_MAX_DEVICE_BUTTONS
&& mInputBinder->getMouseWheelBinding(control, ICS::Control::INCREASE) == ICS::InputControlSystem::MouseWheelClick::UNASSIGNED && mInputBinder->getMouseWheelBinding(control, ICS::Control::INCREASE) == ICS::InputControlSystem::MouseWheelClick::UNASSIGNED))
))
{ {
clearAllKeyBindings(mInputBinder, control); clearAllKeyBindings(mInputBinder, control);
@ -323,7 +322,7 @@ namespace MWInput
&& (force || !mInputBinder->isMouseButtonBound(defaultMouseButtonBindings[i]))) && (force || !mInputBinder->isMouseButtonBound(defaultMouseButtonBindings[i])))
{ {
control->setInitialValue(0.0f); 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() else if (defaultMouseWheelBindings.find(i) != defaultMouseWheelBindings.end()
&& (force || !mInputBinder->isMouseWheelBound(defaultMouseWheelBindings[i]))) && (force || !mInputBinder->isMouseWheelBound(defaultMouseWheelBindings[i])))
@ -379,7 +378,7 @@ namespace MWInput
for (int i = 0; i < A_Last; i++) for (int i = 0; i < A_Last; i++)
{ {
ICS::Control* control; ICS::Control* control;
bool controlExists = mInputBinder->getChannel(i)->getControlsCount () != 0; bool controlExists = mInputBinder->getChannel(i)->getControlsCount() != 0;
if (!controlExists) if (!controlExists)
{ {
float initial; float initial;
@ -392,10 +391,11 @@ namespace MWInput
} }
else 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); clearAllControllerBindings(mInputBinder, control);
@ -415,7 +415,7 @@ namespace MWInput
} }
} }
std::string BindingsManager::getActionDescription (int action) std::string BindingsManager::getActionDescription(int action)
{ {
std::map<int, std::string> descriptions; std::map<int, std::string> descriptions;
@ -464,24 +464,24 @@ namespace MWInput
descriptions[A_QuickSave] = "sQuickSaveCmd"; descriptions[A_QuickSave] = "sQuickSaveCmd";
descriptions[A_QuickLoad] = "sQuickLoadCmd"; descriptions[A_QuickLoad] = "sQuickLoadCmd";
if (descriptions[action] == "") if (descriptions[action].empty())
return ""; // not configurable return std::string(); // not configurable
return "#{" + descriptions[action] + "}"; 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}"; 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); SDL_Scancode key = mInputBinder->getKeyBinding(c, ICS::Control::INCREASE);
unsigned int mouse = mInputBinder->getMouseButtonBinding (c, ICS::Control::INCREASE); unsigned int mouse = mInputBinder->getMouseButtonBinding(c, ICS::Control::INCREASE);
ICS::InputControlSystem::MouseWheelClick wheel = mInputBinder->getMouseWheelBinding(c, ICS::Control::INCREASE); ICS::InputControlSystem::MouseWheelClick wheel = mInputBinder->getMouseWheelBinding(c, ICS::Control::INCREASE);
if (key != SDL_SCANCODE_UNKNOWN) 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) else if (mouse != ICS_MAX_DEVICE_BUTTONS)
return "#{sMouse} " + std::to_string(mouse); return "#{sMouse} " + std::to_string(mouse);
else if (wheel != ICS::InputControlSystem::MouseWheelClick::UNASSIGNED) else if (wheel != ICS::InputControlSystem::MouseWheelClick::UNASSIGNED)
@ -502,17 +502,17 @@ namespace MWInput
return "#{sNone}"; 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}"; 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) if (mInputBinder->getJoystickAxisBinding(c, sFakeDeviceId, ICS::Control::INCREASE) != ICS::InputControlSystem::UNASSIGNED)
return sdlControllerAxisToString(mInputBinder->getJoystickAxisBinding (c, sFakeDeviceId, ICS::Control::INCREASE)); return sdlControllerAxisToString(mInputBinder->getJoystickAxisBinding(c, sFakeDeviceId, ICS::Control::INCREASE));
else if (mInputBinder->getJoystickButtonBinding (c, sFakeDeviceId, ICS::Control::INCREASE) != ICS_MAX_DEVICE_BUTTONS ) else if (mInputBinder->getJoystickButtonBinding(c, sFakeDeviceId, ICS::Control::INCREASE) != ICS_MAX_DEVICE_BUTTONS)
return sdlControllerButtonToString(mInputBinder->getJoystickButtonBinding (c, sFakeDeviceId, ICS::Control::INCREASE)); return sdlControllerButtonToString(mInputBinder->getJoystickButtonBinding(c, sFakeDeviceId, ICS::Control::INCREASE));
else else
return "#{sNone}"; return "#{sNone}";
} }
@ -680,17 +680,17 @@ namespace MWInput
if (mDragDrop && action != A_GameMenu && action != A_Inventory) if (mDragDrop && action != A_GameMenu && action != A_Inventory)
return; 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 //Is a normal button press, so don't change it at all
} }
//Otherwise only trigger button presses as they go through specific points //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; currentValue = 0.0;
previousValue = 1.0; previousValue = 1.0;
} }
else if(previousValue <= .6 && currentValue > .6) else if (previousValue <= 0.6 && currentValue > 0.6)
{ {
currentValue = 1.0; currentValue = 1.0;
previousValue = 0.0; previousValue = 0.0;
@ -706,7 +706,7 @@ namespace MWInput
bool joystickUsed = MWBase::Environment::get().getInputManager()->joystickLastUsed(); bool joystickUsed = MWBase::Environment::get().getInputManager()->joystickLastUsed();
if (action == A_Use) if (action == A_Use)
{ {
if(joystickUsed && currentValue == 1.0 && actionIsActive(A_ToggleWeapon)) if (joystickUsed && currentValue == 1.0 && actionIsActive(A_ToggleWeapon))
action = A_CycleWeaponRight; action = A_CycleWeaponRight;
else if (joystickUsed && currentValue == 1.0 && actionIsActive(A_ToggleSpell)) else if (joystickUsed && currentValue == 1.0 && actionIsActive(A_ToggleSpell))
@ -721,7 +721,7 @@ namespace MWInput
} }
else if (action == A_Jump) else if (action == A_Jump)
{ {
if(joystickUsed && currentValue == 1.0 && actionIsActive(A_ToggleWeapon)) if (joystickUsed && currentValue == 1.0 && actionIsActive(A_ToggleWeapon))
action = A_CycleWeaponLeft; action = A_CycleWeaponLeft;
else if (joystickUsed && currentValue == 1.0 && actionIsActive(A_ToggleSpell)) else if (joystickUsed && currentValue == 1.0 && actionIsActive(A_ToggleSpell))

@ -41,20 +41,21 @@ namespace MWInput
, mSneakGamepadShortcut(false) , mSneakGamepadShortcut(false)
, mGamepadPreviewMode(false) , mGamepadPreviewMode(false)
{ {
if(!controllerBindingsFile.empty()) if (!controllerBindingsFile.empty())
{ {
SDL_GameControllerAddMappingsFromFile(controllerBindingsFile.c_str()); SDL_GameControllerAddMappingsFromFile(controllerBindingsFile.c_str());
} }
if(!userControllerBindingsFile.empty())
if (!userControllerBindingsFile.empty())
{ {
SDL_GameControllerAddMappingsFromFile(userControllerBindingsFile.c_str()); SDL_GameControllerAddMappingsFromFile(userControllerBindingsFile.c_str());
} }
// Open all presently connected sticks // Open all presently connected sticks
int numSticks = SDL_NumJoysticks(); 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; SDL_ControllerDeviceEvent evt;
evt.which = i; evt.which = i;
@ -73,10 +74,6 @@ namespace MWInput
mInvUiScalingFactor = 1.f / uiScale; mInvUiScalingFactor = 1.f / uiScale;
} }
void ControllerManager::clear()
{
}
void ControllerManager::processChangedSettings(const Settings::CategorySettingVector& changed) void ControllerManager::processChangedSettings(const Settings::CategorySettingVector& changed)
{ {
for (const auto& setting : changed) for (const auto& setting : changed)
@ -131,13 +128,13 @@ namespace MWInput
{ {
float xAxis = mBindingsManager->getActionValue(A_MoveLeftRight); float xAxis = mBindingsManager->getActionValue(A_MoveLeftRight);
float yAxis = mBindingsManager->getActionValue(A_MoveForwardBackward); float yAxis = mBindingsManager->getActionValue(A_MoveForwardBackward);
if (xAxis != .5) if (xAxis != 0.5)
{ {
triedToMove = true; triedToMove = true;
player.setLeftRight((xAxis - 0.5f) * 2); player.setLeftRight((xAxis - 0.5f) * 2);
} }
if (yAxis != .5) if (yAxis != 0.5)
{ {
triedToMove = true; triedToMove = true;
player.setAutoMove (false); player.setAutoMove (false);
@ -153,13 +150,13 @@ namespace MWInput
static const bool isToggleSneak = Settings::Manager::getBool("toggle sneak", "Input"); static const bool isToggleSneak = Settings::Manager::getBool("toggle sneak", "Input");
if (!isToggleSneak) 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; mSneakGamepadShortcut = true;
mActionManager->toggleSneaking(); mActionManager->toggleSneaking();
@ -168,15 +165,15 @@ namespace MWInput
mSneakGamepadShortcut = false; mSneakGamepadShortcut = false;
} }
if(!mActionManager->isSneaking()) if (!mActionManager->isSneaking())
mActionManager->toggleSneaking(); mActionManager->toggleSneaking();
mSneakToggleShortcutTimer = 0.f; mSneakToggleShortcutTimer = 0.f;
} }
else else
{ {
if(!mSneakGamepadShortcut && mActionManager->isSneaking()) if (!mSneakGamepadShortcut && mActionManager->isSneaking())
mActionManager->toggleSneaking(); mActionManager->toggleSneaking();
if(mSneakToggleShortcutTimer <= 0.3f) if (mSneakToggleShortcutTimer <= 0.3f)
mSneakToggleShortcutTimer += dt; mSneakToggleShortcutTimer += dt;
} }
} }
@ -190,7 +187,7 @@ namespace MWInput
if (!mBindingsManager->actionIsActive(A_TogglePOV)) if (!mBindingsManager->actionIsActive(A_TogglePOV))
mGamepadZoom = 0; mGamepadZoom = 0;
if(mGamepadZoom) if (mGamepadZoom)
{ {
MWBase::Environment::get().getWorld()->changeVanityModeScale(mGamepadZoom); MWBase::Environment::get().getWorld()->changeVanityModeScale(mGamepadZoom);
MWBase::Environment::get().getWorld()->setCameraDistance(mGamepadZoom, true, true); MWBase::Environment::get().getWorld()->setCameraDistance(mGamepadZoom, true, true);
@ -210,6 +207,7 @@ namespace MWInput
{ {
if (gamepadToGuiControl(arg)) if (gamepadToGuiControl(arg))
return; return;
if (mGamepadGuiCursorEnabled) if (mGamepadGuiCursorEnabled)
{ {
// Temporary mouse binding until keyboard controls are available: // Temporary mouse binding until keyboard controls are available:
@ -245,6 +243,7 @@ namespace MWInput
mBindingsManager->controllerButtonReleased(deviceID, arg); mBindingsManager->controllerButtonReleased(deviceID, arg);
return; return;
} }
if (!mJoystickEnabled || mControlsDisabled) if (!mJoystickEnabled || mControlsDisabled)
return; return;
@ -276,7 +275,7 @@ namespace MWInput
void ControllerManager::axisMoved(int deviceID, const SDL_ControllerAxisEvent &arg) void ControllerManager::axisMoved(int deviceID, const SDL_ControllerAxisEvent &arg)
{ {
if(!mJoystickEnabled || mControlsDisabled) if (!mJoystickEnabled || mControlsDisabled)
return; return;
mJoystickLastUsed = true; mJoystickLastUsed = true;
@ -286,14 +285,14 @@ namespace MWInput
} }
else 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; mGamepadZoom = arg.value * 0.85f / 1000.f;
return; // Do not propagate event. 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; mGamepadZoom = -arg.value * 0.85f / 1000.f;
return; // Do not propagate event. return; // Do not propagate event.

@ -23,8 +23,6 @@ namespace MWInput
virtual ~ControllerManager() = default; virtual ~ControllerManager() = default;
void clear();
bool update(float dt, bool disableControls); bool update(float dt, bool disableControls);
virtual void buttonPressed(int deviceID, const SDL_ControllerButtonEvent &arg); virtual void buttonPressed(int deviceID, const SDL_ControllerButtonEvent &arg);

@ -58,11 +58,6 @@ namespace MWInput
{ {
// Enable all controls // Enable all controls
mControlSwitch->clear(); mControlSwitch->clear();
mActionManager->clear();
mControllerManager->clear();
mSensorManager->clear();
mMouseManager->clear();
} }
InputManager::~InputManager() InputManager::~InputManager()
@ -90,19 +85,19 @@ namespace MWInput
bool grab = !MWBase::Environment::get().getWindowManager()->containsMode(MWGui::GM_MainMenu) bool grab = !MWBase::Environment::get().getWindowManager()->containsMode(MWGui::GM_MainMenu)
&& !MWBase::Environment::get().getWindowManager()->isConsoleMode(); && !MWBase::Environment::get().getWindowManager()->isConsoleMode();
bool was_relative = mInputWrapper->getMouseRelative(); bool wasRelative = mInputWrapper->getMouseRelative();
bool is_relative = !MWBase::Environment::get().getWindowManager()->isGuiMode(); bool isRelative = !MWBase::Environment::get().getWindowManager()->isGuiMode();
// don't keep the pointer away from the window edge in gui mode // don't keep the pointer away from the window edge in gui mode
// stop using raw mouse motions and switch to system cursor movements // 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 //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 //we switched to non-relative mode, move our cursor to where the in-game
//cursor is //cursor is
if(!is_relative && was_relative != is_relative) if (!isRelative && wasRelative != isRelative)
{ {
mMouseManager->warpMouse(); mMouseManager->warpMouse();
} }
@ -148,7 +143,9 @@ namespace MWInput
mMouseManager->setMouseLookEnabled(!guiMode); mMouseManager->setMouseLookEnabled(!guiMode);
if (guiMode) if (guiMode)
MWBase::Environment::get().getWindowManager()->showCrosshair(false); 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. // if not in gui mode, the camera decides whether to show crosshair or not.
} }

@ -13,17 +13,6 @@
#include "actions.hpp" #include "actions.hpp"
namespace MWInput
{
class ControlSwitch;
class ActionManager;
class BindingsManager;
class ControllerManager;
class KeyboardManager;
class MouseManager;
class SensorManager;
}
namespace MWWorld namespace MWWorld
{ {
class Player; class Player;
@ -43,11 +32,18 @@ struct SDL_Window;
namespace MWInput 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 : class InputManager : public MWBase::InputManager
public MWBase::InputManager
{ {
public: public:
InputManager( InputManager(
@ -99,6 +95,18 @@ namespace MWInput
virtual void executeAction(int action); virtual void executeAction(int action);
private: 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; SDLUtil::InputWrapper* mInputWrapper;
bool mGrabCursor; bool mGrabCursor;
@ -111,18 +119,6 @@ namespace MWInput
KeyboardManager* mKeyboardManager; KeyboardManager* mKeyboardManager;
MouseManager* mMouseManager; MouseManager* mMouseManager;
SensorManager* mSensorManager; 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 #endif

@ -47,11 +47,13 @@ namespace MWInput
consumed = true; consumed = true;
mBindingsManager->setPlayerControlsEnabled(!consumed); mBindingsManager->setPlayerControlsEnabled(!consumed);
} }
if (arg.repeat) if (arg.repeat)
return; return;
if (!mControlsDisabled && !consumed) if (!mControlsDisabled && !consumed)
mBindingsManager->keyPressed(arg); mBindingsManager->keyPressed(arg);
MWBase::Environment::get().getInputManager()->setJoystickLastUsed(false); MWBase::Environment::get().getInputManager()->setJoystickLastUsed(false);
} }

@ -47,10 +47,6 @@ namespace MWInput
mGuiCursorY = mInvUiScalingFactor * h / 2.f; mGuiCursorY = mInvUiScalingFactor * h / 2.f;
} }
void MouseManager::clear()
{
}
void MouseManager::processChangedSettings(const Settings::CategorySettingVector& changed) void MouseManager::processChangedSettings(const Settings::CategorySettingVector& changed)
{ {
for (const auto& setting : changed) for (const auto& setting : changed)
@ -103,7 +99,7 @@ namespace MWInput
rot[2] = -x; rot[2] = -x;
// Only actually turn player when we're not in vanity mode // 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(); MWWorld::Player& player = MWBase::Environment::get().getWorld()->getPlayer();
player.yaw(x); player.yaw(x);
@ -130,7 +126,8 @@ namespace MWInput
bool guiMode = MWBase::Environment::get().getWindowManager()->isGuiMode(); bool guiMode = MWBase::Environment::get().getWindowManager()->isGuiMode();
guiMode = MyGUI::InputManager::getInstance().injectMouseRelease(static_cast<int>(mGuiCursorX), static_cast<int>(mGuiCursorY), sdlButtonToMyGUI(id)) && guiMode; guiMode = MyGUI::InputManager::getInstance().injectMouseRelease(static_cast<int>(mGuiCursorX), static_cast<int>(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->setPlayerControlsEnabled(!guiMode);
mBindingsManager->mouseReleased(arg, id); mBindingsManager->mouseReleased(arg, id);
@ -154,9 +151,9 @@ namespace MWInput
{ {
guiMode = MWBase::Environment::get().getWindowManager()->isGuiMode(); guiMode = MWBase::Environment::get().getWindowManager()->isGuiMode();
guiMode = MyGUI::InputManager::getInstance().injectMousePress(static_cast<int>(mGuiCursorX), static_cast<int>(mGuiCursorY), sdlButtonToMyGUI(id)) && guiMode; guiMode = MyGUI::InputManager::getInstance().injectMousePress(static_cast<int>(mGuiCursorX), static_cast<int>(mGuiCursorY), sdlButtonToMyGUI(id)) && guiMode;
if (MyGUI::InputManager::getInstance ().getMouseFocusWidget () != 0) if (MyGUI::InputManager::getInstance().getMouseFocusWidget () != 0)
{ {
MyGUI::Button* b = MyGUI::InputManager::getInstance ().getMouseFocusWidget ()->castType<MyGUI::Button>(false); MyGUI::Button* b = MyGUI::InputManager::getInstance().getMouseFocusWidget()->castType<MyGUI::Button>(false);
if (b && b->getEnabled() && id == SDL_BUTTON_LEFT) if (b && b->getEnabled() && id == SDL_BUTTON_LEFT)
{ {
MWBase::Environment::get().getWindowManager()->playSound("Menu Click"); MWBase::Environment::get().getWindowManager()->playSound("Menu Click");

@ -20,8 +20,6 @@ namespace MWInput
virtual ~MouseManager() = default; virtual ~MouseManager() = default;
void clear();
void update(float dt, bool disableControls); void update(float dt, bool disableControls);
virtual void mouseMoved(const SDLUtil::MouseMotionEvent &arg); virtual void mouseMoved(const SDLUtil::MouseMotionEvent &arg);

@ -206,14 +206,11 @@ namespace MWInput
{ {
static std::map<SDL_Keycode, MyGUI::KeyCode> keyMap; static std::map<SDL_Keycode, MyGUI::KeyCode> keyMap;
if (keyMap.empty()) if (keyMap.empty())
{
initKeyMap(keyMap); initKeyMap(keyMap);
}
MyGUI::KeyCode kc = MyGUI::KeyCode::None; MyGUI::KeyCode kc = MyGUI::KeyCode::None;
auto foundKey = keyMap.find(code); auto foundKey = keyMap.find(code);
if(foundKey != keyMap.end()) if (foundKey != keyMap.end())
kc = foundKey->second; kc = foundKey->second;
return kc; return kc;

@ -33,13 +33,6 @@ namespace MWInput
updateSensors(); updateSensors();
} }
void SensorManager::clear()
{
mGyroXSpeed = 0.f;
mGyroYSpeed = 0.f;
mGyroUpdateTimer = 0.f;
}
SensorManager::~SensorManager() SensorManager::~SensorManager()
{ {
if (mGyroscope != nullptr) if (mGyroscope != nullptr)
@ -246,7 +239,8 @@ namespace MWInput
// More than half of second passed since the last gyroscope update. // More than half of second passed since the last gyroscope update.
// A device more likely was disconnected or switched to the sleep mode. // A device more likely was disconnected or switched to the sleep mode.
// Reset current rotation speed and wait for update. // Reset current rotation speed and wait for update.
clear(); mGyroXSpeed = 0.f;
mGyroYSpeed = 0.f;
mGyroUpdateTimer = 0.f; mGyroUpdateTimer = 0.f;
return; return;
} }

@ -27,8 +27,6 @@ namespace MWInput
void init(); void init();
void clear();
void update(float dt); void update(float dt);
virtual void sensorUpdated(const SDL_SensorEvent &arg); virtual void sensorUpdated(const SDL_SensorEvent &arg);

Loading…
Cancel
Save