From 9825239e436af201a2b039700072f044466b4776 Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Mon, 7 Jul 2025 06:00:04 +0800 Subject: [PATCH 1/4] fix W and S keys for TextField input --- .../src/forge/adventure/scene/UIScene.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/forge-gui-mobile/src/forge/adventure/scene/UIScene.java b/forge-gui-mobile/src/forge/adventure/scene/UIScene.java index 1651b2e725b..f8d9236188c 100644 --- a/forge-gui-mobile/src/forge/adventure/scene/UIScene.java +++ b/forge-gui-mobile/src/forge/adventure/scene/UIScene.java @@ -1,6 +1,7 @@ package forge.adventure.scene; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Input; import com.badlogic.gdx.controllers.Controller; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.g2d.TextureRegion; @@ -379,10 +380,17 @@ public class UIScene extends Scene { } } if(!textboxOpen){ - if (KeyBinding.Down.isPressed(keycode)) - selectNextDown(); - if (KeyBinding.Up.isPressed(keycode)) - selectNextUp(); + if (stage.getKeyboardFocus() instanceof TextField) { + if (Input.Keys.S != keycode && KeyBinding.Down.isPressed(keycode)) + selectNextDown(); + if (Input.Keys.W != keycode && KeyBinding.Up.isPressed(keycode)) + selectNextUp(); + } else { + if (KeyBinding.Down.isPressed(keycode)) + selectNextDown(); + if (KeyBinding.Up.isPressed(keycode)) + selectNextUp(); + } if (!(stage.getKeyboardFocus() instanceof Selector) && !(stage.getKeyboardFocus() instanceof TextField) && !(stage.getKeyboardFocus() instanceof Slider)) { if (KeyBinding.Right.isPressed(keycode)) selectNextRight(); From 25c59cd5dd0e9ad733c99b325ee3f7a891fa3d07 Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Mon, 7 Jul 2025 09:37:03 +0800 Subject: [PATCH 2/4] add KeyBinding ispressed condition --- .../src/forge/adventure/scene/UIScene.java | 29 ++++++++----------- .../src/forge/adventure/util/KeyBinding.java | 12 ++++++-- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/forge-gui-mobile/src/forge/adventure/scene/UIScene.java b/forge-gui-mobile/src/forge/adventure/scene/UIScene.java index f8d9236188c..8754117b04d 100644 --- a/forge-gui-mobile/src/forge/adventure/scene/UIScene.java +++ b/forge-gui-mobile/src/forge/adventure/scene/UIScene.java @@ -380,23 +380,18 @@ public class UIScene extends Scene { } } if(!textboxOpen){ - if (stage.getKeyboardFocus() instanceof TextField) { - if (Input.Keys.S != keycode && KeyBinding.Down.isPressed(keycode)) - selectNextDown(); - if (Input.Keys.W != keycode && KeyBinding.Up.isPressed(keycode)) - selectNextUp(); - } else { - if (KeyBinding.Down.isPressed(keycode)) - selectNextDown(); - if (KeyBinding.Up.isPressed(keycode)) - selectNextUp(); - } - if (!(stage.getKeyboardFocus() instanceof Selector) && !(stage.getKeyboardFocus() instanceof TextField) && !(stage.getKeyboardFocus() instanceof Slider)) { - if (KeyBinding.Right.isPressed(keycode)) - selectNextRight(); - if (KeyBinding.Left.isPressed(keycode)) - selectNextLeft(); - } + if (KeyBinding.Down.isPressed(keycode, !(stage.getKeyboardFocus() instanceof TextField)) + || KeyBinding.Down.isPressed(keycode,Input.Keys.S != keycode)) + selectNextDown(); + if (KeyBinding.Up.isPressed(keycode, !(stage.getKeyboardFocus() instanceof TextField)) + || KeyBinding.Up.isPressed(keycode,Input.Keys.W != keycode)) + selectNextUp(); + if (KeyBinding.Right.isPressed(keycode, !(stage.getKeyboardFocus() instanceof Selector) + && !(stage.getKeyboardFocus() instanceof TextField) && !(stage.getKeyboardFocus() instanceof Slider))) + selectNextRight(); + if (KeyBinding.Left.isPressed(keycode, !(stage.getKeyboardFocus() instanceof Selector) + && !(stage.getKeyboardFocus() instanceof TextField) && !(stage.getKeyboardFocus() instanceof Slider))) + selectNextLeft(); } if (!dialogShowing()) { Button pressedButton = ui.buttonPressed(keycode); diff --git a/forge-gui-mobile/src/forge/adventure/util/KeyBinding.java b/forge-gui-mobile/src/forge/adventure/util/KeyBinding.java index b58d7c73745..fce1a334136 100644 --- a/forge-gui-mobile/src/forge/adventure/util/KeyBinding.java +++ b/forge-gui-mobile/src/forge/adventure/util/KeyBinding.java @@ -34,9 +34,15 @@ public enum KeyBinding { } public boolean isPressed(int key) { - for (int i = 0; i < bindings.length; i++) { - if (key == bindings[i]) { - return true; + return isPressed(key, null); + } + + public boolean isPressed(int key, Boolean requiredCondition) { + if (requiredCondition == null || requiredCondition) { + for (int i = 0; i < bindings.length; i++) { + if (key == bindings[i]) { + return true; + } } } return false; From 99c6b6d815e3d35fd88468821415880ef4754428 Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Mon, 7 Jul 2025 12:06:35 +0800 Subject: [PATCH 3/4] add comment --- .../src/forge/adventure/scene/UIScene.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/forge-gui-mobile/src/forge/adventure/scene/UIScene.java b/forge-gui-mobile/src/forge/adventure/scene/UIScene.java index 8754117b04d..564d81571d7 100644 --- a/forge-gui-mobile/src/forge/adventure/scene/UIScene.java +++ b/forge-gui-mobile/src/forge/adventure/scene/UIScene.java @@ -243,6 +243,7 @@ public class UIScene extends Scene { public Dialog createGenericDialog(String title, String label, String stringYes, String stringNo, Runnable runnableYes, Runnable runnableNo) { return createGenericDialog(title, label, stringYes, stringNo, runnableYes, runnableNo, false, ""); } + public Dialog createGenericDialog(String title, String label, String stringYes, String stringNo, Runnable runnableYes, Runnable runnableNo, boolean cancelButton, String stringCancel) { Dialog dialog = new Dialog(title == null ? "" : title, Controls.getSkin()); textboxOpen = true; @@ -342,7 +343,7 @@ public class UIScene extends Scene { public boolean keyPressed(int keycode) { ui.pressDown(keycode); - + Selectable selection = getSelected(); if (KeyBinding.Use.isPressed(keycode)) { if (selection != null) { @@ -379,13 +380,16 @@ public class UIScene extends Scene { scroll.setScrollY(scroll.getScrollY() + 20); } } - if(!textboxOpen){ + if (!textboxOpen) { + //Allow letter S for TextField since this is binded on down keys if (KeyBinding.Down.isPressed(keycode, !(stage.getKeyboardFocus() instanceof TextField)) - || KeyBinding.Down.isPressed(keycode,Input.Keys.S != keycode)) + || KeyBinding.Down.isPressed(keycode, Input.Keys.S != keycode)) selectNextDown(); + //Allow letter W for TextField since this is binded on down keys if (KeyBinding.Up.isPressed(keycode, !(stage.getKeyboardFocus() instanceof TextField)) - || KeyBinding.Up.isPressed(keycode,Input.Keys.W != keycode)) + || KeyBinding.Up.isPressed(keycode, Input.Keys.W != keycode)) selectNextUp(); + // Allow Right & Left keybinds if not Selector, Slider or Textfield if (KeyBinding.Right.isPressed(keycode, !(stage.getKeyboardFocus() instanceof Selector) && !(stage.getKeyboardFocus() instanceof TextField) && !(stage.getKeyboardFocus() instanceof Slider))) selectNextRight(); From b76c67f30945ef276cb7b6d6602f534cc45edc8e Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Mon, 7 Jul 2025 12:08:10 +0800 Subject: [PATCH 4/4] fix comment --- forge-gui-mobile/src/forge/adventure/scene/UIScene.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forge-gui-mobile/src/forge/adventure/scene/UIScene.java b/forge-gui-mobile/src/forge/adventure/scene/UIScene.java index 564d81571d7..e0567503e71 100644 --- a/forge-gui-mobile/src/forge/adventure/scene/UIScene.java +++ b/forge-gui-mobile/src/forge/adventure/scene/UIScene.java @@ -385,7 +385,7 @@ public class UIScene extends Scene { if (KeyBinding.Down.isPressed(keycode, !(stage.getKeyboardFocus() instanceof TextField)) || KeyBinding.Down.isPressed(keycode, Input.Keys.S != keycode)) selectNextDown(); - //Allow letter W for TextField since this is binded on down keys + //Allow letter W for TextField since this is binded on up keys if (KeyBinding.Up.isPressed(keycode, !(stage.getKeyboardFocus() instanceof TextField)) || KeyBinding.Up.isPressed(keycode, Input.Keys.W != keycode)) selectNextUp();