devilutionX icon indicating copy to clipboard operation
devilutionX copied to clipboard

Controller Manual Aim Improvements

Open wkdgmr opened this issue 4 months ago • 1 comments

Controller Manual Aim Improvements

Summary

This PR refactors and improves controller aiming and cursor interaction for DevilutionX, enabling precise manual aiming and consistent cursor-based actions with gamepads. The changes unify gamepad aiming logic, ensure cursor persistence, and guarantee that all attack, spell, and interaction actions respect the controller-placed cursor position.


Technical Changes

1. Unified Gamepad Aiming State

  • Introduced GamepadAimActive state to track when the player is actively aiming with the right stick or padmapped D-pad.
  • Ensured the cursor remains visible while aiming and only hides when movement resumes (left stick or D-pad movement).
  • KBM logic remains untouched.

2. Cursor Persistence and Device Switching

  • Patched input detection and device/mode switching logic to respect GamepadAimActive, preventing premature cursor hiding or device swaps during controller aiming.

3. D-pad and Analog Stick Handling

  • Refactored D-pad and stick logic to use button events and padmapper actions, not axis identifiers.
  • Ensured D-pad movement (not padmapper mouse simulation) clears GamepadAimActive and hides the cursor.

4. SecondaryAction Cursor Support

  • Updated PerformSecondaryAction() to explicitly handle all special cursor states (e.g., Telekinesis, Identify, Repair, etc.) using a manual list.
  • Ensured these actions trigger at the cursor position and do not default to walking.

5. Interact and PrimaryAction Patches

  • Patched Interact() and PerformPrimaryAction() to respect controller aiming state.
  • When GamepadAimActive is true, attacks and primary actions are directed at the cursor position, ensuring consistent targeting for controller users.

6. Spell Casting Consistency

  • Patched PerformSpellAction() so that, when controller aiming is active, the player turns and casts spells (e.g., Firewall, Teleport, Town Portal) at the cursor position.
  • Ensured consistent targeting and player facing for all spells when using manual aim.

7. Modifier Hints UI

  • Updated modifier_hints.cpp so gamepad modifier hints (menu navigation, hotspell selection) are hidden while manual aiming is active (IsGamepadAimActive()).
  • Prevents UI clutter and distraction during controller aiming.

8. Controller Motion API

  • Updated controller_motion.h to declare and expose the new gamepad aiming state API (IsGamepadAimActive() and related helpers).
  • Ensures all relevant modules can query and set gamepad aiming state.

9. Minimal Impact on KBM

  • Most changes are gated by controller-specific logic (IsGamepadAimActive()), leaving KBM and general gameplay unaffected.

10. QuickCast Targeting Fixes

  • Updated QuickCast() and related logic to ensure spells cast via quickcast always target the preferred monster when available, even if objects or items are nearby.
  • Ensured that quickcast spells do not accidentally interact with objects/items under the cursor, maintaining monster targeting priority for spells.
  • Secondary actions (e.g., opening chests, picking up items) now correctly interact with objects/items at their actual positions, regardless of monster presence, while spells still prefer monsters.
  • This resolves previous issues where quickcast spells could be misdirected to objects/items instead of monsters when both were present.

Usage

  • Aim with the right stick or padmapped D-pad; the cursor will persist and can be used for all interactions.
  • Attacks, spells, and secondary actions will target the cursor position when controller aiming is active.
  • Movement (left stick or D-pad) will hide the cursor and exit aiming mode.
  • Gamepad modifier hints are hidden while aiming.
  • QuickCast bug fixes and logical adjustments

Files Modified

  • Source/controls/controller_motion.cpp
  • Source/controls/controller_motion.h
  • Source/controls/plrctrls.cpp
  • Source/controls/modifier_hints.cpp

wkdgmr avatar Aug 23 '25 19:08 wkdgmr

Any chance to get some new regression tests for this?

skypher avatar Nov 23 '25 10:11 skypher