Browse Source

Iron out interactions between simulated mouse movement and character movement

pull/5453/head
staphen 3 years ago committed by Anders Jenbo
parent
commit
198dec9412
  1. 28
      Source/controls/controller_motion.cpp
  2. 15
      Source/options.cpp
  3. 1
      Source/options.h

28
Source/controls/controller_motion.cpp

@ -96,6 +96,9 @@ bool SimulateRightStickWithDpad(ControllerButtonEvent ctrlEvent)
rightStickX = 0;
rightStickY = 0;
// Cannot use PadmapperOptions::IsActive() because this function
// is invoked before PadmapperOptions::ButtonPressed()
if (IsControllerButtonComboPressed(upCombo))
rightStickY += 1.F;
if (IsControllerButtonComboPressed(downCombo))
@ -104,8 +107,17 @@ bool SimulateRightStickWithDpad(ControllerButtonEvent ctrlEvent)
rightStickX -= 1.F;
if (IsControllerButtonComboPressed(rightCombo))
rightStickX += 1.F;
if (rightStickX != 0 || rightStickY != 0)
SetSimulatingMouseWithPadmapper(true);
if (rightStickX == 0 && rightStickY == 0) {
// In this case, PadmapperOptions::IsActive() can be used to anticipate PadmapperOptions::ButtonReleased()
bool upReleased = ctrlEvent.up && ctrlEvent.button == upCombo.button && sgOptions.Padmapper.IsActive("MouseUp");
bool downReleased = ctrlEvent.up && ctrlEvent.button == downCombo.button && sgOptions.Padmapper.IsActive("MouseDown");
bool leftReleased = ctrlEvent.up && ctrlEvent.button == leftCombo.button && sgOptions.Padmapper.IsActive("MouseLeft");
bool rightReleased = ctrlEvent.up && ctrlEvent.button == rightCombo.button && sgOptions.Padmapper.IsActive("MouseRight");
return upReleased || downReleased || leftReleased || rightReleased;
}
SetSimulatingMouseWithPadmapper(true);
return true;
}
@ -178,14 +190,10 @@ AxisDirection GetLeftStickOrDpadDirection(bool usePadmapper)
bool isRightPressed = stickX >= 0.5;
if (usePadmapper) {
ControllerButtonCombo upCombo = sgOptions.Padmapper.ButtonComboForAction("MoveUp");
ControllerButtonCombo downCombo = sgOptions.Padmapper.ButtonComboForAction("MoveDown");
ControllerButtonCombo leftCombo = sgOptions.Padmapper.ButtonComboForAction("MoveLeft");
ControllerButtonCombo rightCombo = sgOptions.Padmapper.ButtonComboForAction("MoveRight");
isUpPressed |= IsControllerButtonComboPressed(upCombo);
isDownPressed |= IsControllerButtonComboPressed(downCombo);
isLeftPressed |= IsControllerButtonComboPressed(leftCombo);
isRightPressed |= IsControllerButtonComboPressed(rightCombo);
isUpPressed |= sgOptions.Padmapper.IsActive("MoveUp");
isDownPressed |= sgOptions.Padmapper.IsActive("MoveDown");
isLeftPressed |= sgOptions.Padmapper.IsActive("MoveLeft");
isRightPressed |= sgOptions.Padmapper.IsActive("MoveRight");
} else {
isUpPressed |= IsControllerButtonPressed(ControllerButton_BUTTON_DPAD_UP);
isDownPressed |= IsControllerButtonPressed(ControllerButton_BUTTON_DPAD_DOWN);

15
Source/options.cpp

@ -1648,6 +1648,21 @@ void PadmapperOptions::ButtonReleased(ControllerButton button, bool invokeAction
buttonToReleaseAction.erase(button);
}
bool PadmapperOptions::IsActive(string_view actionName) const
{
for (const Action &action : actions) {
if (action.key != actionName)
continue;
ControllerButton button = action.boundInput.button;
auto it = buttonToReleaseAction.find(button);
if (it == buttonToReleaseAction.end())
return false;
const Action &releaseAction = it->second.get();
return releaseAction.key == actionName;
}
return false;
}
string_view PadmapperOptions::InputNameForAction(string_view actionName) const
{
for (const Action &action : actions) {

1
Source/options.h

@ -738,6 +738,7 @@ struct PadmapperOptions : OptionCategoryBase {
void CommitActions();
void ButtonPressed(ControllerButton button);
void ButtonReleased(ControllerButton button, bool invokeAction = true);
bool IsActive(string_view actionName) const;
string_view InputNameForAction(string_view actionName) const;
ControllerButtonCombo ButtonComboForAction(string_view actionName) const;

Loading…
Cancel
Save