Skip to content

Commit

Permalink
Merge pull request OpenMW#2578 from akortunov/mouse
Browse files Browse the repository at this point in the history
Implement mouse wheel bindings (bug OpenMW#2679)
  • Loading branch information
psi29a committed Oct 31, 2019
2 parents f944c5b + e4bec88 commit ec9a593
Show file tree
Hide file tree
Showing 14 changed files with 386 additions and 59 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Bug #1515: Opening console masks dialogue, inventory menu
Bug #1933: Actors can have few stocks of the same item
Bug #2395: Duplicated plugins in the launcher when multiple data directories provide the same plugin
Bug #2679: Unable to map mouse wheel under control settings
Bug #2969: Scripted items can stack
Bug #2976: Data lines in global openmw.cfg take priority over user openmw.cfg
Bug #2987: Editor: some chance and AI data fields can overflow
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG_PR.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ New Editor Features:
- Land heightmap/shape editing and vertex selection (#5170)

Bug Fixes:
- The Mouse Wheel can now be used for key bindings (#2679)
- Scripted Items cannot be stacked anymore to avoid multiple script execution (#2969)
- Stray text after an "else" statement is now ignored, like in the original engine, to handle mods which erroneously use "else if" statements (#3006)
- "SetPos" and "SetPosition" commands now more closely replicate the original engine's behaviour (#3109)
Expand Down
2 changes: 0 additions & 2 deletions apps/launcher/advancedpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ bool Launcher::AdvancedPage::loadSettings()
loadSettingBool(normaliseRaceSpeedCheckBox, "normalise race speed", "Game");

// Input Settings
loadSettingBool(allowThirdPersonZoomCheckBox, "allow third person zoom", "Input");
loadSettingBool(grabCursorCheckBox, "grab cursor", "Input");
loadSettingBool(toggleSneakCheckBox, "toggle sneak", "Input");

Expand Down Expand Up @@ -145,7 +144,6 @@ void Launcher::AdvancedPage::saveSettings()
saveSettingBool(normaliseRaceSpeedCheckBox, "normalise race speed", "Game");

// Input Settings
saveSettingBool(allowThirdPersonZoomCheckBox, "allow third person zoom", "Input");
saveSettingBool(grabCursorCheckBox, "grab cursor", "Input");
saveSettingBool(toggleSneakCheckBox, "toggle sneak", "Input");

Expand Down
3 changes: 3 additions & 0 deletions apps/openmw/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,11 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
if(boost::filesystem::exists(input2)) {
boost::filesystem::copy_file(input2, keybinderUser);
keybinderUserExists = boost::filesystem::exists(keybinderUser);
Log(Debug::Info) << "Loading keybindings file: " << keybinderUser;
}
}
else
Log(Debug::Info) << "Loading keybindings file: " << keybinderUser;

// find correct path to the game controller bindings
// File format for controller mappings is different for SDL <= 2.0.4, 2.0.5, and >= 2.0.6
Expand Down
84 changes: 73 additions & 11 deletions apps/openmw/mwinput/inputmanagerimp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,14 @@ namespace MWInput
case A_ToggleDebug:
MWBase::Environment::get().getWindowManager()->toggleDebugWindow();
break;
case A_ZoomIn:
if (mControlSwitch["playerviewswitch"] && mControlSwitch["playercontrols"] && !MWBase::Environment::get().getWindowManager()->isGuiMode())
MWBase::Environment::get().getWorld()->setCameraDistance(ZOOM_SCALE, true, true);
break;
case A_ZoomOut:
if (mControlSwitch["playerviewswitch"] && mControlSwitch["playercontrols"] && !MWBase::Environment::get().getWindowManager()->isGuiMode())
MWBase::Environment::get().getWorld()->setCameraDistance(-ZOOM_SCALE, true, true);
break;
case A_QuickSave:
quickSave();
break;
Expand Down Expand Up @@ -750,7 +758,9 @@ namespace MWInput
actionIsActive(A_MoveRight) ||
actionIsActive(A_Jump) ||
actionIsActive(A_Sneak) ||
actionIsActive(A_TogglePOV))
actionIsActive(A_TogglePOV) ||
actionIsActive(A_ZoomIn) ||
actionIsActive(A_ZoomOut) )
{
resetIdleTime();
} else {
Expand Down Expand Up @@ -938,6 +948,14 @@ namespace MWInput
}
}

void InputManager::mouseWheelMoved(const SDL_MouseWheelEvent &arg)
{
if (mInputBinder->detectingBindingState() || !mControlsDisabled)
mInputBinder->mouseWheelMoved(arg);

mJoystickLastUsed = false;
}

void InputManager::mouseMoved(const SDLUtil::MouseMotionEvent &arg )
{
mInputBinder->mouseMoved (arg);
Expand Down Expand Up @@ -985,9 +1003,6 @@ namespace MWInput
if (arg.zrel && mControlSwitch["playerviewswitch"] && mControlSwitch["playercontrols"]) //Check to make sure you are allowed to zoomout and there is a change
{
MWBase::Environment::get().getWorld()->changeVanityModeScale(static_cast<float>(arg.zrel));

if (Settings::Manager::getBool("allow third person zoom", "Input"))
MWBase::Environment::get().getWorld()->setCameraDistance(static_cast<float>(arg.zrel), true, true);
}
}
}
Expand Down Expand Up @@ -1447,6 +1462,10 @@ namespace MWInput
defaultMouseButtonBindings[A_Inventory] = SDL_BUTTON_RIGHT;
defaultMouseButtonBindings[A_Use] = SDL_BUTTON_LEFT;

std::map<int, ICS::InputControlSystem::MouseWheelClick> defaultMouseWheelBindings;
defaultMouseWheelBindings[A_ZoomIn] = ICS::InputControlSystem::MouseWheelClick::UP;
defaultMouseWheelBindings[A_ZoomOut] = ICS::InputControlSystem::MouseWheelClick::DOWN;

for (int i = 0; i < A_Last; ++i)
{
ICS::Control* control;
Expand All @@ -1465,6 +1484,7 @@ namespace MWInput
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
))
{
clearAllKeyBindings(control);
Expand All @@ -1481,6 +1501,12 @@ namespace MWInput
control->setInitialValue(0.0f);
mInputBinder->addMouseButtonBinding (control, defaultMouseButtonBindings[i], ICS::Control::INCREASE);
}
else if (defaultMouseWheelBindings.find(i) != defaultMouseWheelBindings.end()
&& (force || !mInputBinder->isMouseWheelBound(defaultMouseWheelBindings[i])))
{
control->setInitialValue(0.f);
mInputBinder->addMouseWheelBinding(control, defaultMouseWheelBindings[i], ICS::Control::INCREASE);
}

if (i == A_LookLeftRight && !mInputBinder->isKeyBound(SDL_SCANCODE_KP_4) && !mInputBinder->isKeyBound(SDL_SCANCODE_KP_6))
{
Expand Down Expand Up @@ -1571,6 +1597,10 @@ namespace MWInput

if (action == A_Screenshot)
return "Screenshot";
else if (action == A_ZoomIn)
return "Zoom In";
else if (action == A_ZoomOut)
return "Zoom Out";

descriptions[A_Use] = "sUse";
descriptions[A_Activate] = "sActivate";
Expand Down Expand Up @@ -1623,10 +1653,25 @@ namespace MWInput

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));
else if (mouse != ICS_MAX_DEVICE_BUTTONS)
return "#{sMouse} " + std::to_string(mouse);
else if (wheel != ICS::InputControlSystem::MouseWheelClick::UNASSIGNED)
switch (wheel)
{
case ICS::InputControlSystem::MouseWheelClick::UP:
return "Mouse Wheel Up";
case ICS::InputControlSystem::MouseWheelClick::DOWN:
return "Mouse Wheel Down";
case ICS::InputControlSystem::MouseWheelClick::RIGHT:
return "Mouse Wheel Right";
case ICS::InputControlSystem::MouseWheelClick::LEFT:
return "Mouse Wheel Left";
default:
return "#{sNone}";
}
else
return "#{sNone}";
}
Expand Down Expand Up @@ -1713,6 +1758,8 @@ namespace MWInput
ret.push_back(A_MoveLeft);
ret.push_back(A_MoveRight);
ret.push_back(A_TogglePOV);
ret.push_back(A_ZoomIn);
ret.push_back(A_ZoomOut);
ret.push_back(A_Run);
ret.push_back(A_AlwaysRun);
ret.push_back(A_Sneak);
Expand Down Expand Up @@ -1751,6 +1798,8 @@ namespace MWInput
{
std::vector<int> ret;
ret.push_back(A_TogglePOV);
ret.push_back(A_ZoomIn);
ret.push_back(A_ZoomOut);
ret.push_back(A_Sneak);
ret.push_back(A_Activate);
ret.push_back(A_Use);
Expand Down Expand Up @@ -1790,13 +1839,6 @@ namespace MWInput
mInputBinder->enableDetectingBindingState (c, ICS::Control::INCREASE);
}

void InputManager::mouseAxisBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
, ICS::InputControlSystem::NamedAxis axis, ICS::Control::ControlChangingDirection direction)
{
// we don't want mouse movement bindings
return;
}

void InputManager::keyBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
, SDL_Scancode key, ICS::Control::ControlChangingDirection direction)
{
Expand Down Expand Up @@ -1828,6 +1870,13 @@ namespace MWInput
MWBase::Environment::get().getWindowManager ()->notifyInputActionBound ();
}

void InputManager::mouseAxisBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
, ICS::InputControlSystem::NamedAxis axis, ICS::Control::ControlChangingDirection direction)
{
// we don't want mouse movement bindings
return;
}

void InputManager::mouseButtonBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
, unsigned int button, ICS::Control::ControlChangingDirection direction)
{
Expand All @@ -1839,6 +1888,17 @@ namespace MWInput
MWBase::Environment::get().getWindowManager ()->notifyInputActionBound ();
}

void InputManager::mouseWheelBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
, ICS::InputControlSystem::MouseWheelClick click, ICS::Control::ControlChangingDirection direction)
{
if(!mDetectingKeyboard)
return;
clearAllKeyBindings(control);
control->setInitialValue(0.0f);
ICS::DetectingBindingListener::mouseWheelBindingDetected(ICS, control, click, direction);
MWBase::Environment::get().getWindowManager()->notifyInputActionBound();
}

void InputManager::joystickAxisBindingDetected(ICS::InputControlSystem* ICS, int deviceID, ICS::Control* control
, int axis, ICS::Control::ControlChangingDirection direction)
{
Expand Down Expand Up @@ -1873,6 +1933,8 @@ namespace MWInput
mInputBinder->removeKeyBinding (mInputBinder->getKeyBinding (control, ICS::Control::INCREASE));
if (mInputBinder->getMouseButtonBinding (control, ICS::Control::INCREASE) != ICS_MAX_DEVICE_BUTTONS)
mInputBinder->removeMouseButtonBinding (mInputBinder->getMouseButtonBinding (control, ICS::Control::INCREASE));
if (mInputBinder->getMouseWheelBinding (control, ICS::Control::INCREASE) != ICS::InputControlSystem::MouseWheelClick::UNASSIGNED)
mInputBinder->removeMouseWheelBinding (mInputBinder->getMouseWheelBinding(control, ICS::Control::INCREASE));
}

void InputManager::clearAllControllerBindings (ICS::Control* control)
Expand Down
51 changes: 30 additions & 21 deletions apps/openmw/mwinput/inputmanagerimp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct SDL_Window;

namespace MWInput
{
const float ZOOM_SCALE = 120.f; /// Used for scrolling camera in and out

/**
* @brief Class that handles all input and key bindings for OpenMW.
Expand Down Expand Up @@ -120,6 +121,8 @@ namespace MWInput
virtual void mouseReleased( const SDL_MouseButtonEvent &arg, Uint8 id );
virtual void mouseMoved( const SDLUtil::MouseMotionEvent &arg );

virtual void mouseWheelMoved( const SDL_MouseWheelEvent &arg);

virtual void buttonPressed(int deviceID, const SDL_ControllerButtonEvent &arg);
virtual void buttonReleased(int deviceID, const SDL_ControllerButtonEvent &arg);
virtual void axisMoved(int deviceID, const SDL_ControllerAxisEvent &arg);
Expand All @@ -133,15 +136,18 @@ namespace MWInput

virtual void channelChanged(ICS::Channel* channel, float currentValue, float previousValue);

virtual void mouseAxisBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
, ICS::InputControlSystem::NamedAxis axis, ICS::Control::ControlChangingDirection direction);

virtual void keyBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
, SDL_Scancode key, ICS::Control::ControlChangingDirection direction);

virtual void mouseAxisBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
, ICS::InputControlSystem::NamedAxis axis, ICS::Control::ControlChangingDirection direction);

virtual void mouseButtonBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
, unsigned int button, ICS::Control::ControlChangingDirection direction);

virtual void mouseWheelBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
, ICS::InputControlSystem::MouseWheelClick click, ICS::Control::ControlChangingDirection direction);

virtual void joystickAxisBindingDetected(ICS::InputControlSystem* ICS, int deviceID, ICS::Control* control
, int axis, ICS::Control::ControlChangingDirection direction);

Expand Down Expand Up @@ -268,33 +274,33 @@ namespace MWInput

A_Unused,

A_Screenshot, // Take a screenshot
A_Screenshot, // Take a screenshot

A_Inventory, // Toggle inventory screen
A_Inventory, // Toggle inventory screen

A_Console, // Toggle console screen
A_Console, // Toggle console screen

A_MoveLeft, // Move player left / right
A_MoveLeft, // Move player left / right
A_MoveRight,
A_MoveForward, // Forward / Backward
A_MoveForward, // Forward / Backward
A_MoveBackward,

A_Activate,

A_Use, //Use weapon, spell, etc.
A_Use, //Use weapon, spell, etc.
A_Jump,
A_AutoMove, //Toggle Auto-move forward
A_Rest, //Rest
A_Journal, //Journal
A_Weapon, //Draw/Sheath weapon
A_Spell, //Ready/Unready Casting
A_Run, //Run when held
A_CycleSpellLeft, //cycling through spells
A_AutoMove, //Toggle Auto-move forward
A_Rest, //Rest
A_Journal, //Journal
A_Weapon, //Draw/Sheath weapon
A_Spell, //Ready/Unready Casting
A_Run, //Run when held
A_CycleSpellLeft, //cycling through spells
A_CycleSpellRight,
A_CycleWeaponLeft,//Cycling through weapons
A_CycleWeaponLeft, //Cycling through weapons
A_CycleWeaponRight,
A_ToggleSneak, //Toggles Sneak
A_AlwaysRun, //Toggle Walking/Running
A_ToggleSneak, //Toggles Sneak
A_AlwaysRun, //Toggle Walking/Running
A_Sneak,

A_QuickSave,
Expand Down Expand Up @@ -322,12 +328,15 @@ namespace MWInput

A_ToggleDebug,

A_LookUpDown, //Joystick look
A_LookUpDown, //Joystick look
A_LookLeftRight,
A_MoveForwardBackward,
A_MoveLeftRight,

A_Last // Marker for the last item
A_ZoomIn,
A_ZoomOut,

A_Last // Marker for the last item
};
};
}
Expand Down
1 change: 1 addition & 0 deletions components/sdlutil/events.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class MouseListener
virtual void mouseMoved( const MouseMotionEvent &arg ) = 0;
virtual void mousePressed( const SDL_MouseButtonEvent &arg, Uint8 id ) = 0;
virtual void mouseReleased( const SDL_MouseButtonEvent &arg, Uint8 id ) = 0;
virtual void mouseWheelMoved( const SDL_MouseWheelEvent &arg) = 0;
};

class KeyListener
Expand Down
1 change: 1 addition & 0 deletions components/sdlutil/sdlinputwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ InputWrapper::InputWrapper(SDL_Window* window, osg::ref_ptr<osgViewer::Viewer> v
break;
case SDL_MOUSEWHEEL:
mMouseListener->mouseMoved(_packageMouseMotion(evt));
mMouseListener->mouseWheelMoved(evt.wheel);
break;
case SDL_MOUSEBUTTONDOWN:
mMouseListener->mousePressed(evt.button, evt.button.button);
Expand Down
12 changes: 0 additions & 12 deletions docs/source/reference/modding/settings/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,6 @@ based on whether the caps lock key was on or off at the time you exited.

This settings can be toggled in game by pressing the CapsLock key and exiting.

allow third person zoom
-----------------------

:Type: boolean
:Range: True/False
:Default: False

Allow zooming in and out using the middle mouse wheel in third person view.
This feature may not work correctly if the mouse wheel is bound to other actions,
and may be triggered accidentally in some cases, so is disabled by default.
This setting can only be configured by editing the settings configuration file.

camera sensitivity
------------------

Expand Down
Loading

0 comments on commit ec9a593

Please sign in to comment.