From 0696bf1f361d1cefde96a8448a481ca4309d04d2 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Wed, 30 Oct 2019 15:49:09 -0400 Subject: [PATCH] v0.8.0: added all other key actions from old desktop build, no remapping yet --- .../java/com/watabou/input/KeyAction.java | 25 +++++++++- .../java/com/watabou/input/KeyBindings.java | 29 +++++++++-- .../java/com/watabou/noosa/ui/Button.java | 30 +++++++++++- .../scenes/CellSelector.java | 48 ++++++++++++------- .../ui/ActionIndicator.java | 8 +++- .../ui/AttackIndicator.java | 6 +++ .../ui/DangerIndicator.java | 6 +++ .../ui/LootIndicator.java | 6 +++ .../ui/QuickSlotButton.java | 22 +++++++++ .../ui/ResumeIndicator.java | 6 +++ .../shatteredpixeldungeon/ui/StatusPane.java | 23 ++++++--- .../shatteredpixeldungeon/ui/Toolbar.java | 20 +++++++- 12 files changed, 196 insertions(+), 33 deletions(-) diff --git a/SPD-classes/src/main/java/com/watabou/input/KeyAction.java b/SPD-classes/src/main/java/com/watabou/input/KeyAction.java index 8e6c9979b..289e06258 100644 --- a/SPD-classes/src/main/java/com/watabou/input/KeyAction.java +++ b/SPD-classes/src/main/java/com/watabou/input/KeyAction.java @@ -21,11 +21,32 @@ package com.watabou.input; +//FIXME this is describing actions defined in the core module, it should probably be moved there. public enum KeyAction { BACK, MENU, - N, NE, E, SE, S, SW, W, NW, + HERO_INFO, + JOURNAL, - UNKNOWN + WAIT, + SEARCH, + + INVENTORY, + QUICKSLOT_1, + QUICKSLOT_2, + QUICKSLOT_3, + QUICKSLOT_4, + + TAG_ATTACK, + TAG_DANGER, + TAG_ACTION, + TAG_LOOT, + TAG_RESUME, + + ZOOM_IN, + ZOOM_OUT, + ZOOM_DEFAULT, + + N, NE, E, SE, S, SW, W, NW } diff --git a/SPD-classes/src/main/java/com/watabou/input/KeyBindings.java b/SPD-classes/src/main/java/com/watabou/input/KeyBindings.java index 3586c0ffa..cd1d030b6 100644 --- a/SPD-classes/src/main/java/com/watabou/input/KeyBindings.java +++ b/SPD-classes/src/main/java/com/watabou/input/KeyBindings.java @@ -32,14 +32,37 @@ public class KeyBindings { static { bindings = new HashMap<>(); - bindings.put( Input.Keys.BACK, KeyAction.BACK ); - bindings.put( Input.Keys.MENU, KeyAction.MENU ); + bindings.put( Input.Keys.BACK, KeyAction.BACK ); + bindings.put( Input.Keys.MENU, KeyAction.MENU ); + + bindings.put( Input.Keys.H, KeyAction.HERO_INFO ); + bindings.put( Input.Keys.J, KeyAction.JOURNAL ); + + bindings.put( Input.Keys.NUMPAD_5, KeyAction.WAIT ); + bindings.put( Input.Keys.SPACE, KeyAction.WAIT ); + bindings.put( Input.Keys.S, KeyAction.SEARCH ); + + bindings.put( Input.Keys.I, KeyAction.INVENTORY ); + bindings.put( Input.Keys.Q, KeyAction.QUICKSLOT_1 ); + bindings.put( Input.Keys.W, KeyAction.QUICKSLOT_2 ); + bindings.put( Input.Keys.E, KeyAction.QUICKSLOT_3 ); + bindings.put( Input.Keys.R, KeyAction.QUICKSLOT_4 ); + + bindings.put( Input.Keys.A, KeyAction.TAG_ATTACK ); + bindings.put( Input.Keys.TAB, KeyAction.TAG_DANGER ); + bindings.put( Input.Keys.D, KeyAction.TAG_ACTION ); + bindings.put( Input.Keys.ENTER, KeyAction.TAG_LOOT ); + bindings.put( Input.Keys.T, KeyAction.TAG_RESUME ); + + bindings.put( Input.Keys.PLUS, KeyAction.ZOOM_IN ); + bindings.put( Input.Keys.EQUALS, KeyAction.ZOOM_IN ); + bindings.put( Input.Keys.MINUS, KeyAction.ZOOM_OUT ); + bindings.put( Input.Keys.SLASH, KeyAction.ZOOM_DEFAULT ); bindings.put( Input.Keys.UP, KeyAction.N ); bindings.put( Input.Keys.RIGHT, KeyAction.E ); bindings.put( Input.Keys.DOWN, KeyAction.S ); bindings.put( Input.Keys.LEFT, KeyAction.W ); - bindings.put( Input.Keys.NUMPAD_8, KeyAction.N ); bindings.put( Input.Keys.NUMPAD_9, KeyAction.NE ); bindings.put( Input.Keys.NUMPAD_6, KeyAction.E ); diff --git a/SPD-classes/src/main/java/com/watabou/noosa/ui/Button.java b/SPD-classes/src/main/java/com/watabou/noosa/ui/Button.java index 3bfe47f5d..538dcec65 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/ui/Button.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/ui/Button.java @@ -21,9 +21,13 @@ package com.watabou.noosa.ui; +import com.watabou.input.KeyAction; +import com.watabou.input.KeyBindings; +import com.watabou.input.KeyEvent; import com.watabou.input.PointerEvent; import com.watabou.noosa.Game; import com.watabou.noosa.PointerArea; +import com.watabou.utils.Signal; public class Button extends Component { @@ -33,7 +37,6 @@ public class Button extends Component { protected boolean pressed; protected float pressTime; - protected boolean processed; @Override @@ -59,6 +62,24 @@ public class Button extends Component { } }; add( hotArea ); + + KeyEvent.addKeyListener( keyListener = new Signal.Listener() { + @Override + public boolean onSignal ( KeyEvent event ) { + if ( active && !event.pressed && KeyBindings.getBinding( event ) != null + && KeyBindings.getBinding( event ) == keyAction()){ + onClick(); + return true; + } + return false; + } + }); + } + + private Signal.Listener keyListener; + + public KeyAction keyAction(){ + return null; } @Override @@ -96,4 +117,11 @@ public class Button extends Component { hotArea.width = width; hotArea.height = height; } + + @Override + public synchronized void destroy () { + super.destroy(); + KeyEvent.removeKeyListener( keyListener ); + } + } 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 ceb21524e..5a41da4cf 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/CellSelector.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/CellSelector.java @@ -21,7 +21,6 @@ package com.shatteredpixel.shatteredpixeldungeon.scenes; -import com.badlogic.gdx.Input; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; @@ -30,6 +29,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; import com.shatteredpixel.shatteredpixeldungeon.items.Heap; import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite; import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap; +import com.watabou.input.KeyAction; import com.watabou.input.KeyBindings; import com.watabou.input.KeyEvent; import com.watabou.input.PointerEvent; @@ -55,7 +55,7 @@ public class CellSelector extends ScrollArea { dragThreshold = PixelScene.defaultZoom * DungeonTilemap.SIZE / 2; mouseZoom = camera.zoom; - KeyEvent.addKeyListener(movementListener); + KeyEvent.addKeyListener( keyListener ); } private float mouseZoom; @@ -208,19 +208,33 @@ public class CellSelector extends ScrollArea { } - private KeyEvent heldKey = null; - private int heldKeyTurns = 0; + private KeyAction heldAction = null; + private int heldTurns = 0; - private Signal.Listener movementListener = new Signal.Listener() { + private Signal.Listener keyListener = new Signal.Listener() { @Override public boolean onSignal(KeyEvent event) { + KeyAction action = KeyBindings.getBinding( event ); if (!event.pressed){ - if (heldKey != null && heldKey.code == event.code) { + + if (heldAction != null && heldAction == action) { resetKeyHold(); return true; + } else { + switch (action){ + case ZOOM_IN: + zoom( camera.zoom+1 ); + return true; + case ZOOM_OUT: + zoom( camera.zoom-1 ); + return true; + case ZOOM_DEFAULT: + zoom( PixelScene.defaultZoom ); + return true; + } } - } else if (moveFromKey(event)) { - heldKey = event; + } else if (moveFromKey(action)) { + heldAction = action; return true; } @@ -228,11 +242,11 @@ public class CellSelector extends ScrollArea { } }; - private boolean moveFromKey(KeyEvent event){ + private boolean moveFromKey(KeyAction event){ boolean moved = true; int cell = Dungeon.hero.pos; //TODO implement game actions, instead of using keys directly - switch (KeyBindings.getBinding( event )){ + switch (event){ case N: cell += -Dungeon.level.width(); break; @@ -265,7 +279,7 @@ public class CellSelector extends ScrollArea { //each step when keyboard moving takes 0.15s, 0.125s, 0.1s, 0.1s, ... // this is to make it easier to move 1 or 2 steps without overshooting CharSprite.setMoveInterval( CharSprite.DEFAULT_MOVE_INTERVAL + - Math.max(0, 0.05f - heldKeyTurns*0.025f)); + Math.max(0, 0.05f - heldTurns *0.025f)); select(cell); } @@ -273,16 +287,16 @@ public class CellSelector extends ScrollArea { } public void processKeyHold(){ - if (heldKey != null){ + if (heldAction != null){ enabled = true; - heldKeyTurns++; - moveFromKey(heldKey); + heldTurns++; + moveFromKey(heldAction); } } public void resetKeyHold(){ - heldKey = null; - heldKeyTurns = 0; + heldAction = null; + heldTurns = 0; CharSprite.setMoveInterval( CharSprite.DEFAULT_MOVE_INTERVAL ); } @@ -315,7 +329,7 @@ public class CellSelector extends ScrollArea { @Override public void destroy() { super.destroy(); - KeyEvent.removeKeyListener(movementListener); + KeyEvent.removeKeyListener( keyListener ); } public interface Listener { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/ActionIndicator.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/ActionIndicator.java index e7cd6caae..efb2c2d4d 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/ActionIndicator.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/ActionIndicator.java @@ -23,6 +23,7 @@ package com.shatteredpixel.shatteredpixeldungeon.ui; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; +import com.watabou.input.KeyAction; import com.watabou.noosa.Image; public class ActionIndicator extends Tag { @@ -40,7 +41,12 @@ public class ActionIndicator extends Tag { setSize( 24, 24 ); visible = false; } - + + @Override + public KeyAction keyAction() { + return KeyAction.TAG_ACTION; + } + @Override public void destroy() { super.destroy(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/AttackIndicator.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/AttackIndicator.java index 980dafb70..8b1e20f83 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/AttackIndicator.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/AttackIndicator.java @@ -26,6 +26,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite; +import com.watabou.input.KeyAction; import com.watabou.noosa.Game; import com.watabou.utils.Random; import com.watabou.utils.Reflection; @@ -57,6 +58,11 @@ public class AttackIndicator extends Tag { enable( false ); } + @Override + public KeyAction keyAction() { + return KeyAction.TAG_ATTACK; + } + @Override protected void createChildren() { super.createChildren(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/DangerIndicator.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/DangerIndicator.java index 9f5b61ba5..95f20b90d 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/DangerIndicator.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/DangerIndicator.java @@ -24,6 +24,7 @@ package com.shatteredpixel.shatteredpixeldungeon.ui; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; +import com.watabou.input.KeyAction; import com.watabou.noosa.BitmapText; import com.watabou.noosa.Camera; import com.watabou.noosa.Image; @@ -47,6 +48,11 @@ public class DangerIndicator extends Tag { visible = false; } + @Override + public KeyAction keyAction() { + return KeyAction.TAG_DANGER; + } + @Override protected void createChildren() { super.createChildren(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/LootIndicator.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/LootIndicator.java index d18ee99fa..5a8b134a1 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/LootIndicator.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/LootIndicator.java @@ -24,6 +24,7 @@ package com.shatteredpixel.shatteredpixeldungeon.ui; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.items.Heap; import com.shatteredpixel.shatteredpixeldungeon.items.Item; +import com.watabou.input.KeyAction; public class LootIndicator extends Tag { @@ -40,6 +41,11 @@ public class LootIndicator extends Tag { visible = false; } + @Override + public KeyAction keyAction() { + return KeyAction.TAG_LOOT; + } + @Override protected void createChildren() { super.createChildren(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java index 66f48662a..f1dfba76f 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java @@ -31,6 +31,7 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite; import com.shatteredpixel.shatteredpixeldungeon.utils.BArray; import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag; +import com.watabou.input.KeyAction; import com.watabou.noosa.Image; import com.watabou.noosa.ui.Button; import com.watabou.utils.PathFinder; @@ -92,6 +93,11 @@ public class QuickSlotButton extends Button implements WndBag.Listener { item.execute( Dungeon.hero ); } } + + @Override + public KeyAction keyAction() { + return QuickSlotButton.this.keyAction(); + } @Override protected boolean onLongClick() { return QuickSlotButton.this.onLongClick(); @@ -127,6 +133,22 @@ public class QuickSlotButton extends Button implements WndBag.Listener { PixelScene.align(crossB); } + @Override + public KeyAction keyAction() { + switch (slotNum){ + case 0: + return KeyAction.QUICKSLOT_1; + case 1: + return KeyAction.QUICKSLOT_2; + case 2: + return KeyAction.QUICKSLOT_3; + case 3: + return KeyAction.QUICKSLOT_4; + default: + return super.keyAction(); + } + } + @Override protected void onClick() { GameScene.selectItem( this, WndBag.Mode.QUICKSLOT, Messages.get(this, "select_item") ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/ResumeIndicator.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/ResumeIndicator.java index 5a68a055e..76f646cb7 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/ResumeIndicator.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/ResumeIndicator.java @@ -23,6 +23,7 @@ package com.shatteredpixel.shatteredpixeldungeon.ui; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; +import com.watabou.input.KeyAction; import com.watabou.noosa.Image; public class ResumeIndicator extends Tag { @@ -37,6 +38,11 @@ public class ResumeIndicator extends Tag { visible = false; } + + @Override + public KeyAction keyAction() { + return KeyAction.TAG_RESUME; + } @Override protected void createChildren() { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java index b3242224b..ad0aa3877 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java @@ -32,7 +32,7 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite; import com.shatteredpixel.shatteredpixeldungeon.windows.WndGame; import com.shatteredpixel.shatteredpixeldungeon.windows.WndHero; import com.shatteredpixel.shatteredpixeldungeon.windows.WndJournal; -import com.watabou.input.PointerEvent; +import com.watabou.input.KeyAction; import com.watabou.noosa.BitmapText; import com.watabou.noosa.Camera; import com.watabou.noosa.Game; @@ -82,14 +82,18 @@ public class StatusPane extends Component { bg = new NinePatch( Assets.STATUS, 0, 0, 128, 36, 85, 0, 45, 0 ); add( bg ); - add( new PointerArea( 0, 1, 31, 31 ) { + add( new Button(){ @Override - protected void onClick( PointerEvent event ) { - Image sprite = Dungeon.hero.sprite; - Camera.main.panTo( sprite.center(), 5f ); + protected void onClick () { + Camera.main.panTo( Dungeon.hero.sprite.center(), 5f ); GameScene.show( new WndHero() ); } - } ); + + @Override + public KeyAction keyAction() { + return KeyAction.HERO_INFO; + } + }.setRect( 0, 1, 30, 30 )); btnJournal = new JournalButton(); add( btnJournal ); @@ -259,7 +263,12 @@ public class StatusPane extends Component { width = bg.width + 13; //includes the depth display to the left height = bg.height + 4; } - + + @Override + public KeyAction keyAction() { + return KeyAction.JOURNAL; + } + @Override protected void createChildren() { super.createChildren(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java index cf984d823..a706f11c4 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java @@ -32,6 +32,7 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite; import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTerrainTilemap; import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag; import com.shatteredpixel.shatteredpixeldungeon.windows.WndJournal; +import com.watabou.input.KeyAction; import com.watabou.noosa.Camera; import com.watabou.noosa.Game; import com.watabou.noosa.Gizmo; @@ -78,7 +79,12 @@ public class Toolbar extends Component { examining = false; Dungeon.hero.rest(false); } - + + @Override + public KeyAction keyAction() { + return KeyAction.WAIT; + } + protected boolean onLongClick() { examining = false; Dungeon.hero.rest(true); @@ -97,7 +103,12 @@ public class Toolbar extends Component { Dungeon.hero.search(true); } } - + + @Override + public KeyAction keyAction() { + return KeyAction.SEARCH; + } + @Override protected boolean onLongClick() { Dungeon.hero.search(true); @@ -123,6 +134,11 @@ public class Toolbar extends Component { GameScene.show(new WndBag(Dungeon.hero.belongings.backpack, null, WndBag.Mode.ALL, null)); } + @Override + public KeyAction keyAction() { + return KeyAction.INVENTORY; + } + @Override protected boolean onLongClick() { WndJournal.last_index = 3; //catalog page