|
|
|
|
@ -20,7 +20,12 @@
|
|
|
|
|
|
|
|
|
|
namespace devilution { |
|
|
|
|
|
|
|
|
|
bool SimulatingMouseWithPadmapper; |
|
|
|
|
static bool GamepadAimActive = false; |
|
|
|
|
|
|
|
|
|
bool IsGamepadAimActive() |
|
|
|
|
{ |
|
|
|
|
return GamepadAimActive; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
|
|
|
|
|
|
@ -98,15 +103,19 @@ bool IsPressedForMovement(ControllerButton button)
|
|
|
|
|
&& !(SpellSelectFlag && TriggersQuickSpellAction(button)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SetSimulatingMouseWithPadmapper(bool value) |
|
|
|
|
|
|
|
|
|
void SetGamepadAimActive(bool value) |
|
|
|
|
{ |
|
|
|
|
if (SimulatingMouseWithPadmapper == value) |
|
|
|
|
if (GamepadAimActive == value) |
|
|
|
|
return; |
|
|
|
|
SimulatingMouseWithPadmapper = value; |
|
|
|
|
GamepadAimActive = value; |
|
|
|
|
if (value) { |
|
|
|
|
LogVerbose("Control: begin simulating mouse with D-Pad"); |
|
|
|
|
LogVerbose("GamepadAim: begin aiming"); |
|
|
|
|
// Show cursor for aiming (if needed)
|
|
|
|
|
} else { |
|
|
|
|
LogVerbose("Control: end simulating mouse with D-Pad"); |
|
|
|
|
LogVerbose("GamepadAim: end aiming"); |
|
|
|
|
// Hide/reset cursor when movement resumes
|
|
|
|
|
ResetCursor(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -188,14 +197,41 @@ void ProcessControllerMotion(const SDL_Event &event)
|
|
|
|
|
GameController *const controller = GameController::Get(event); |
|
|
|
|
if (controller != nullptr && devilution::GameController::ProcessAxisMotion(event)) { |
|
|
|
|
ScaleJoysticks(); |
|
|
|
|
SetSimulatingMouseWithPadmapper(false); |
|
|
|
|
// End aiming and hide cursor only when left stick axis moved
|
|
|
|
|
if (event.type == SDL_CONTROLLERAXISMOTION) { |
|
|
|
|
if (event.caxis.axis == SDL_CONTROLLER_AXIS_LEFTX || event.caxis.axis == SDL_CONTROLLER_AXIS_LEFTY) { |
|
|
|
|
SetGamepadAimActive(false); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
Joystick *const joystick = Joystick::Get(event); |
|
|
|
|
if (joystick != nullptr && devilution::Joystick::ProcessAxisMotion(event)) { |
|
|
|
|
ScaleJoysticks(); |
|
|
|
|
SetSimulatingMouseWithPadmapper(false); |
|
|
|
|
if (event.type == SDL_JOYAXISMOTION) { |
|
|
|
|
#ifdef JOY_AXIS_LEFTX |
|
|
|
|
if (event.jaxis.axis == JOY_AXIS_LEFTX) |
|
|
|
|
SetGamepadAimActive(false); |
|
|
|
|
#endif |
|
|
|
|
#ifdef JOY_AXIS_LEFTY |
|
|
|
|
if (event.jaxis.axis == JOY_AXIS_LEFTY) |
|
|
|
|
SetGamepadAimActive(false); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// D-pad movement detection (button events, not padmapper mouse simulation)
|
|
|
|
|
StaticVector<ControllerButtonEvent, 4> buttonEvents = ToControllerButtonEvents(event); |
|
|
|
|
for (const auto &ctrlEvent : buttonEvents) { |
|
|
|
|
if (!ctrlEvent.up && IsDPadButton(ctrlEvent.button)) { |
|
|
|
|
// Only clear aim if this is NOT a padmapper mouse simulation combo
|
|
|
|
|
// (i.e., no modifier or not SELECT + D-pad)
|
|
|
|
|
ControllerButtonCombo combo(ctrlEvent.button); |
|
|
|
|
if (combo.modifier == ControllerButton_NONE) { |
|
|
|
|
SetGamepadAimActive(false); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -216,7 +252,7 @@ AxisDirection GetLeftStickOrDpadDirection(bool usePadmapper)
|
|
|
|
|
isDownPressed |= PadmapperIsActionActive("MoveDown"); |
|
|
|
|
isLeftPressed |= PadmapperIsActionActive("MoveLeft"); |
|
|
|
|
isRightPressed |= PadmapperIsActionActive("MoveRight"); |
|
|
|
|
} else if (!SimulatingMouseWithPadmapper) { |
|
|
|
|
} else if (!IsGamepadAimActive()) { |
|
|
|
|
isUpPressed |= IsPressedForMovement(ControllerButton_BUTTON_DPAD_UP); |
|
|
|
|
isDownPressed |= IsPressedForMovement(ControllerButton_BUTTON_DPAD_DOWN); |
|
|
|
|
isLeftPressed |= IsPressedForMovement(ControllerButton_BUTTON_DPAD_LEFT); |
|
|
|
|
@ -259,11 +295,9 @@ void SimulateRightStickWithPadmapper(ControllerButtonEvent ctrlEvent)
|
|
|
|
|
const bool downTriggered = actionName == "MouseDown"; |
|
|
|
|
const bool leftTriggered = actionName == "MouseLeft"; |
|
|
|
|
const bool rightTriggered = actionName == "MouseRight"; |
|
|
|
|
if (!upTriggered && !downTriggered && !leftTriggered && !rightTriggered) { |
|
|
|
|
if (rightStickX == 0 && rightStickY == 0) |
|
|
|
|
SetSimulatingMouseWithPadmapper(false); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (!upTriggered && !downTriggered && !leftTriggered && !rightTriggered) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const bool upActive = (upTriggered && !ctrlEvent.up) || (!upTriggered && PadmapperIsActionActive("MouseUp")); |
|
|
|
|
const bool downActive = (downTriggered && !ctrlEvent.up) || (!downTriggered && PadmapperIsActionActive("MouseDown")); |
|
|
|
|
@ -280,7 +314,8 @@ void SimulateRightStickWithPadmapper(ControllerButtonEvent ctrlEvent)
|
|
|
|
|
rightStickX -= 1.F; |
|
|
|
|
if (rightActive) |
|
|
|
|
rightStickX += 1.F; |
|
|
|
|
SetSimulatingMouseWithPadmapper(true); |
|
|
|
|
// Begin aiming when any direction is active
|
|
|
|
|
SetGamepadAimActive(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} // namespace devilution
|
|
|
|
|
|