From 3bc9506eaa01b44e06a7b978a717460fcab1e1da Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Fri, 18 Feb 2022 00:04:32 -0500 Subject: [PATCH] v1.2.0: fixed input spam with new key movement logic --- .../shatteredpixeldungeon/scenes/CellSelector.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/CellSelector.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/CellSelector.java index f518f0376..8001a6530 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/CellSelector.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/CellSelector.java @@ -304,6 +304,7 @@ public class CellSelector extends ScrollArea { } else if (directionFromAction(action) != 0) { + lastCellMoved = -1; if (heldAction1 == SPDAction.NONE){ heldAction1 = action; heldDelay = 0.05f; @@ -332,9 +333,14 @@ public class CellSelector extends ScrollArea { if (heldAction1 != SPDAction.NONE && Dungeon.hero.ready){ processKeyHold(); + } else if (Dungeon.hero.ready) { + lastCellMoved = -1; } } + //prevents repeated inputs when the hero isn't moving + private int lastCellMoved = 0; + private boolean moveFromActions(GameAction... actions){ if (Dungeon.hero == null){ return false; @@ -345,7 +351,8 @@ public class CellSelector extends ScrollArea { cell += directionFromAction(action); } - if (cell != Dungeon.hero.pos){ + if (cell != Dungeon.hero.pos && cell != lastCellMoved){ + lastCellMoved = cell; select(cell, PointerEvent.LEFT); return true; @@ -372,8 +379,9 @@ public class CellSelector extends ScrollArea { && heldDelay <= 0){ enabled = Dungeon.hero.ready = true; Dungeon.observe(); - moveFromActions(heldAction1, heldAction2); - Dungeon.hero.ready = false; + if (moveFromActions(heldAction1, heldAction2)) { + Dungeon.hero.ready = false; + } } }