From 833237eab8d89f5ea578699635d39bb40af8ae3c Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Thu, 2 Jun 2022 16:12:23 -0400 Subject: [PATCH] v1.3.0: fixed errors with left click assignment in WndKeyBindings --- .../messages/windows/windows.properties | 1 + .../windows/WndKeyBindings.java | 22 ++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/core/src/main/assets/messages/windows/windows.properties b/core/src/main/assets/messages/windows/windows.properties index 5202ccdc0..f74815306 100644 --- a/core/src/main/assets/messages/windows/windows.properties +++ b/core/src/main/assets/messages/windows/windows.properties @@ -144,6 +144,7 @@ windows.wndkeybindings$wndchangebinding.changed_bind=New binding: _%s_ windows.wndkeybindings$wndchangebinding.warning=This key will be unbound from _%s_. windows.wndkeybindings$wndchangebinding.error=This key is already bound to this action. windows.wndkeybindings$wndchangebinding.unbind=Unbind Key +windows.wndkeybindings$wndchangebinding.cant_unbind=You must have at least one key bound to this action. windows.wndkeybindings$wndchangebinding.confirm=Confirm windows.wndkeybindings$wndchangebinding.cancel=Cancel diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndKeyBindings.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndKeyBindings.java index 967fba48d..eef4836e5 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndKeyBindings.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndKeyBindings.java @@ -33,8 +33,10 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.Window; import com.watabou.input.GameAction; import com.watabou.input.KeyBindings; import com.watabou.input.KeyEvent; +import com.watabou.input.PointerEvent; import com.watabou.noosa.ColorBlock; import com.watabou.noosa.ui.Component; +import com.watabou.utils.PointF; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -344,7 +346,9 @@ public class WndKeyBindings extends Window { private RenderedTextBlock changedKey; private RenderedTextBlock warnErr; + private RedButton btnUnbind; private RedButton btnConfirm; + private RedButton btnCancel; public WndChangeBinding(GameAction action, BindingItem listItem, int keyAssigning, int curKeyCode, int otherBoundKey1, int otherBoundKey2 ){ @@ -379,10 +383,14 @@ public class WndKeyBindings extends Window { warnErr.setRect(0, changedKey.bottom() + 10, WIDTH, warnErr.height()); add(warnErr); - RedButton btnUnbind = new RedButton(Messages.get(this, "unbind"), 9){ + btnUnbind = new RedButton(Messages.get(this, "unbind"), 9){ @Override protected void onClick() { - onSignal(new KeyEvent(0, true)); + if (action == GameAction.LEFT_CLICK && listItem.key2 == 0 && listItem.key3 == 0){ + ShatteredPixelDungeon.scene().addToFront(new WndMessage(Messages.get(WndChangeBinding.class, "cant_unbind"))); + } else { + onSignal(new KeyEvent(0, true)); + } } }; btnUnbind.setRect(0, warnErr.bottom() + 6, WIDTH, BTN_HEIGHT); @@ -433,7 +441,7 @@ public class WndKeyBindings extends Window { btnConfirm.enable(false); add(btnConfirm); - RedButton btnCancel = new RedButton(Messages.get(this, "cancel"), 9){ + btnCancel = new RedButton(Messages.get(this, "cancel"), 9){ @Override protected void onClick() { hide(); @@ -449,6 +457,14 @@ public class WndKeyBindings extends Window { @Override public boolean onSignal(KeyEvent event) { + //ignore left clicks if we are pressing a button + if (KeyBindings.getActionForKey(event) == GameAction.LEFT_CLICK){ + PointF hoverPos = camera().screenToCamera((int)PointerEvent.currentHoverPos().x, (int)PointerEvent.currentHoverPos().y); + if (btnUnbind.inside(hoverPos.x, hoverPos.y)) return true; + if (btnConfirm.inside(hoverPos.x, hoverPos.y)) return true; + if (btnCancel.inside(hoverPos.x, hoverPos.y)) return true; + } + if (event.pressed){ changedKey.text(Messages.get(this, "changed_bind", KeyBindings.getKeyName(event.code))); changedKey.setPos((WIDTH - changedKey.width())/2, changedKey.top());