Skip to content

Commit 120993c

Browse files
authored
Fix Automap movement being hardcoded to right stick on gamepad (diasurgical#7921)
1 parent 2d71017 commit 120993c

11 files changed

Lines changed: 115 additions & 82 deletions

File tree

Source/controls/game_controls.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrlEvent, Game
166166
|| (!VirtualGamepadState.secondaryActionButton.isHeld && ControllerActionHeld == GameActionType_SECONDARY_ACTION)
167167
|| (!VirtualGamepadState.spellActionButton.isHeld && ControllerActionHeld == GameActionType_CAST_SPELL)) {
168168
ControllerActionHeld = GameActionType_NONE;
169-
LastMouseButtonAction = MouseActionType::None;
169+
LastPlayerAction = PlayerActionType::None;
170170
}
171171
}
172172
}
@@ -265,7 +265,7 @@ void PressControllerButton(ControllerButton button)
265265
switch (button) {
266266
case devilution::ControllerButton_BUTTON_DPAD_UP:
267267
PressEscKey();
268-
LastMouseButtonAction = MouseActionType::None;
268+
LastPlayerAction = PlayerActionType::None;
269269
PadHotspellMenuActive = false;
270270
PadMenuNavigatorActive = false;
271271
gamemenu_on();

Source/controls/plrctrls.cpp

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ void Interact()
516516
}
517517

518518
NetSendCmdLoc(MyPlayerId, true, myPlayer.UsesRangedWeapon() ? CMD_RATTACKXY : CMD_SATTACKXY, position);
519-
LastMouseButtonAction = MouseActionType::Attack;
519+
LastPlayerAction = PlayerActionType::Attack;
520520
return;
521521
}
522522

@@ -526,19 +526,19 @@ void Interact()
526526
} else {
527527
NetSendCmdParam1(true, CMD_RATTACKID, pcursmonst);
528528
}
529-
LastMouseButtonAction = MouseActionType::AttackMonsterTarget;
529+
LastPlayerAction = PlayerActionType::AttackMonsterTarget;
530530
return;
531531
}
532532

533533
if (leveltype != DTYPE_TOWN && PlayerUnderCursor != nullptr && !myPlayer.friendlyMode) {
534534
NetSendCmdParam1(true, myPlayer.UsesRangedWeapon() ? CMD_RATTACKPID : CMD_ATTACKPID, PlayerUnderCursor->getId());
535-
LastMouseButtonAction = MouseActionType::AttackPlayerTarget;
535+
LastPlayerAction = PlayerActionType::AttackPlayerTarget;
536536
return;
537537
}
538538

539539
if (ObjectUnderCursor != nullptr) {
540540
NetSendCmdLoc(MyPlayerId, true, CMD_OPOBJXY, cursPosition);
541-
LastMouseButtonAction = MouseActionType::OperateObject;
541+
LastPlayerAction = PlayerActionType::OperateObject;
542542
return;
543543
}
544544
}
@@ -1521,6 +1521,23 @@ void ProcessLeftStickOrDPadGameUI()
15211521
handler(GetLeftStickOrDpadDirection(false));
15221522
}
15231523

1524+
void ProcessAutomapMovementGamepad()
1525+
{
1526+
if (!AutomapActive)
1527+
return;
1528+
1529+
const auto &padmapper = GetOptions().Padmapper;
1530+
1531+
if (IsControllerButtonComboPressed(padmapper.ButtonComboForAction("AutomapMoveUp")))
1532+
AutomapUp();
1533+
if (IsControllerButtonComboPressed(padmapper.ButtonComboForAction("AutomapMoveDown")))
1534+
AutomapDown();
1535+
if (IsControllerButtonComboPressed(padmapper.ButtonComboForAction("AutomapMoveLeft")))
1536+
AutomapLeft();
1537+
if (IsControllerButtonComboPressed(padmapper.ButtonComboForAction("AutomapMoveRight")))
1538+
AutomapRight();
1539+
}
1540+
15241541
void Movement(Player &player)
15251542
{
15261543
if (PadMenuNavigatorActive || PadHotspellMenuActive || InGameMenu())
@@ -1827,15 +1844,6 @@ void HandleRightStickMotion()
18271844
return;
18281845
}
18291846

1830-
if (AutomapActive) { // move map
1831-
int dx = 0;
1832-
int dy = 0;
1833-
acc.Pool(&dx, &dy, 32);
1834-
AutomapOffset.deltaX += dy + dx;
1835-
AutomapOffset.deltaY += dy - dx;
1836-
return;
1837-
}
1838-
18391847
{ // move cursor
18401848
InvalidateInventorySlot();
18411849
int x = MousePosition.x;
@@ -1900,7 +1908,7 @@ void plrctrls_after_check_curs_move()
19001908
}
19011909

19021910
// While holding the button down we should retain target (but potentially lose it if it dies, goes out of view, etc)
1903-
if (ControllerActionHeld != GameActionType_NONE && IsNoneOf(LastMouseButtonAction, MouseActionType::None, MouseActionType::Attack, MouseActionType::Spell)) {
1911+
if (ControllerActionHeld != GameActionType_NONE && IsNoneOf(LastPlayerAction, PlayerActionType::None, PlayerActionType::Attack, PlayerActionType::Spell)) {
19041912
InvalidateTargets();
19051913

19061914
if (pcursmonst == -1 && ObjectUnderCursor == nullptr && pcursitem == -1 && pcursinvitem == -1 && pcursstashitem == StashStruct::EmptyCell && PlayerUnderCursor == nullptr) {
@@ -1937,6 +1945,7 @@ void plrctrls_every_frame()
19371945
{
19381946
ProcessLeftStickOrDPadGameUI();
19391947
HandleRightStickMotion();
1948+
ProcessAutomapMovementGamepad();
19401949
}
19411950

19421951
void plrctrls_after_game_logic()
@@ -2101,11 +2110,11 @@ void PerformSpellAction()
21012110
UpdateSpellTarget(myPlayer._pRSpell);
21022111
CheckPlrSpell(false);
21032112
if (PlayerUnderCursor != nullptr)
2104-
LastMouseButtonAction = MouseActionType::SpellPlayerTarget;
2113+
LastPlayerAction = PlayerActionType::SpellPlayerTarget;
21052114
else if (pcursmonst != -1)
2106-
LastMouseButtonAction = MouseActionType::SpellMonsterTarget;
2115+
LastPlayerAction = PlayerActionType::SpellMonsterTarget;
21072116
else
2108-
LastMouseButtonAction = MouseActionType::Spell;
2117+
LastPlayerAction = PlayerActionType::Spell;
21092118
}
21102119

21112120
void CtrlUseInvItem()
@@ -2188,7 +2197,7 @@ void PerformSecondaryAction()
21882197
NetSendCmdLocParam1(true, CMD_GOTOAGETITEM, cursPosition, pcursitem);
21892198
} else if (ObjectUnderCursor != nullptr) {
21902199
NetSendCmdLoc(MyPlayerId, true, CMD_OPOBJXY, cursPosition);
2191-
LastMouseButtonAction = MouseActionType::OperateObject;
2200+
LastPlayerAction = PlayerActionType::OperateObject;
21922201
} else {
21932202
if (pcursmissile != nullptr) {
21942203
MakePlrPath(myPlayer, pcursmissile->position.tile, true);
@@ -2205,7 +2214,7 @@ void PerformSecondaryAction()
22052214

22062215
void QuickCast(size_t slot)
22072216
{
2208-
MouseActionType prevMouseButtonAction = LastMouseButtonAction;
2217+
PlayerActionType prevMouseButtonAction = LastPlayerAction;
22092218
Player &myPlayer = *MyPlayer;
22102219
SpellID spell = myPlayer._pSplHotKey[slot];
22112220
SpellType spellType = myPlayer._pSplTHotKey[slot];
@@ -2215,7 +2224,7 @@ void QuickCast(size_t slot)
22152224
}
22162225

22172226
CheckPlrSpell(false, spell, spellType);
2218-
LastMouseButtonAction = prevMouseButtonAction;
2227+
LastPlayerAction = prevMouseButtonAction;
22192228
}
22202229

22212230
} // namespace devilution

Source/cursor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ void ShiftToDiamondGridAlignment(Point screenPosition, Point &tile, bool &flipfl
771771
*/
772772
bool CheckMouseHold(const Point currentTile)
773773
{
774-
if ((sgbMouseDown != CLICK_NONE || ControllerActionHeld != GameActionType_NONE) && IsNoneOf(LastMouseButtonAction, MouseActionType::None, MouseActionType::Attack, MouseActionType::Spell)) {
774+
if ((sgbMouseDown != CLICK_NONE || ControllerActionHeld != GameActionType_NONE) && IsNoneOf(LastPlayerAction, PlayerActionType::None, PlayerActionType::Attack, PlayerActionType::Spell)) {
775775
InvalidateTargets();
776776

777777
if (pcursmonst == -1 && ObjectUnderCursor == nullptr && pcursitem == -1 && pcursinvitem == -1 && pcursstashitem == StashStruct::EmptyCell && PlayerUnderCursor == nullptr) {

0 commit comments

Comments
 (0)