From 223de3fef837bcf427e88ee046c0b0a3fd70e0fa Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Thu, 28 Jul 2022 19:16:14 -0400 Subject: [PATCH] v1.4.0: reworked danger keybind to cycle target/tabs --- .../messages/windows/windows.properties | 2 +- .../shatteredpixeldungeon/SPDAction.java | 7 ++-- .../ui/DangerIndicator.java | 2 +- .../windows/WndTabbed.java | 33 +++++++++++++++++-- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/core/src/main/assets/messages/windows/windows.properties b/core/src/main/assets/messages/windows/windows.properties index 28bf1b085..62849f868 100644 --- a/core/src/main/assets/messages/windows/windows.properties +++ b/core/src/main/assets/messages/windows/windows.properties @@ -132,10 +132,10 @@ windows.wndkeybindings.bag_3=Container 3 windows.wndkeybindings.bag_4=Container 4 windows.wndkeybindings.bag_5=Container 5 windows.wndkeybindings.tag_attack=Attack Enemy -windows.wndkeybindings.tag_danger=Switch Enemy windows.wndkeybindings.tag_action=Special Action windows.wndkeybindings.tag_loot=Pickup Item windows.wndkeybindings.tag_resume=Resume Motion +windows.wndkeybindings.cycle=Next Target / Next Tab windows.wndkeybindings.zoom_in=Zoom In / Scroll Down windows.wndkeybindings.zoom_out=Zoom Out / Scroll Up windows.wndkeybindings.n=Go North diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDAction.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDAction.java index 0cb8be585..78acd5aaa 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDAction.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDAction.java @@ -77,11 +77,12 @@ public class SPDAction extends GameAction { public static final GameAction REST = new SPDAction("rest"); public static final GameAction TAG_ATTACK = new SPDAction("tag_attack"); - public static final GameAction TAG_DANGER = new SPDAction("tag_danger"); public static final GameAction TAG_ACTION = new SPDAction("tag_action"); public static final GameAction TAG_LOOT = new SPDAction("tag_loot"); public static final GameAction TAG_RESUME = new SPDAction("tag_resume"); + public static final GameAction CYCLE = new SPDAction("cycle"); + public static final GameAction HERO_INFO = new SPDAction("hero_info"); public static final GameAction JOURNAL = new SPDAction("journal"); @@ -133,7 +134,7 @@ public class SPDAction extends GameAction { defaultBindings.put( Input.Keys.Z, SPDAction.REST ); defaultBindings.put( Input.Keys.Q, SPDAction.TAG_ATTACK ); - defaultBindings.put( Input.Keys.TAB, SPDAction.TAG_DANGER ); + defaultBindings.put( Input.Keys.TAB, SPDAction.CYCLE); defaultBindings.put( Input.Keys.X, SPDAction.TAG_ACTION ); defaultBindings.put( Input.Keys.C, SPDAction.TAG_LOOT ); defaultBindings.put( Input.Keys.ENTER, SPDAction.TAG_LOOT ); @@ -161,7 +162,7 @@ public class SPDAction extends GameAction { defaultControllerBindings.put( Input.Keys.BUTTON_SELECT, SPDAction.MIDDLE_CLICK ); defaultControllerBindings.put( Input.Keys.DPAD_UP+1000, SPDAction.TAG_ACTION ); - defaultControllerBindings.put( Input.Keys.DPAD_LEFT+1000, SPDAction.TAG_DANGER ); + defaultControllerBindings.put( Input.Keys.DPAD_LEFT+1000, SPDAction.CYCLE); defaultControllerBindings.put( Input.Keys.DPAD_DOWN+1000, SPDAction.TAG_RESUME ); defaultControllerBindings.put( Input.Keys.DPAD_RIGHT+1000, SPDAction.TAG_LOOT ); 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 3137b4421..b3c73b3ed 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/DangerIndicator.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/DangerIndicator.java @@ -55,7 +55,7 @@ public class DangerIndicator extends Tag { @Override public GameAction keyAction() { - return SPDAction.TAG_DANGER; + return SPDAction.CYCLE; } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndTabbed.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndTabbed.java index 07a41ca16..a1a848dd5 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndTabbed.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndTabbed.java @@ -23,9 +23,12 @@ package com.shatteredpixel.shatteredpixeldungeon.windows; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Chrome; +import com.shatteredpixel.shatteredpixeldungeon.SPDAction; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock; import com.shatteredpixel.shatteredpixeldungeon.ui.Window; +import com.watabou.input.KeyBindings; +import com.watabou.input.KeyEvent; import com.watabou.noosa.Game; import com.watabou.noosa.Image; import com.watabou.noosa.NinePatch; @@ -33,6 +36,7 @@ import com.watabou.noosa.PointerArea; import com.watabou.noosa.audio.Sample; import com.shatteredpixel.shatteredpixeldungeon.ui.Button; import com.watabou.utils.RectF; +import com.watabou.utils.Signal; import java.util.ArrayList; @@ -40,12 +44,37 @@ public class WndTabbed extends Window { protected ArrayList tabs = new ArrayList<>(); protected Tab selected; + + private Signal.Listener tabListener; public WndTabbed() { super( 0, 0, Chrome.get( Chrome.Type.TAB_SET ) ); + + KeyEvent.addKeyListener(tabListener = new Signal.Listener() { + @Override + public boolean onSignal(KeyEvent keyEvent) { + + if (!keyEvent.pressed && KeyBindings.getActionForKey(keyEvent) == SPDAction.CYCLE){ + int idx = tabs.indexOf(selected); + idx++; + if (idx >= tabs.size()) idx = 0; + select(idx); + + return true; + } + + return false; + } + }); } - - protected Tab add( Tab tab ) { + + @Override + public void destroy() { + super.destroy(); + KeyEvent.removeKeyListener(tabListener); + } + + protected Tab add(Tab tab ) { tab.setPos( tabs.size() == 0 ? -chrome.marginLeft() + 1 :