add KeyBinding ispressed condition

This commit is contained in:
Anthony Calosa
2025-07-07 09:37:03 +08:00
parent 9825239e43
commit 25c59cd5dd
2 changed files with 21 additions and 20 deletions

View File

@@ -380,23 +380,18 @@ public class UIScene extends Scene {
} }
} }
if(!textboxOpen){ if(!textboxOpen){
if (stage.getKeyboardFocus() instanceof TextField) { if (KeyBinding.Down.isPressed(keycode, !(stage.getKeyboardFocus() instanceof TextField))
if (Input.Keys.S != keycode && KeyBinding.Down.isPressed(keycode)) || KeyBinding.Down.isPressed(keycode,Input.Keys.S != keycode))
selectNextDown(); selectNextDown();
if (Input.Keys.W != keycode && KeyBinding.Up.isPressed(keycode)) if (KeyBinding.Up.isPressed(keycode, !(stage.getKeyboardFocus() instanceof TextField))
selectNextUp(); || KeyBinding.Up.isPressed(keycode,Input.Keys.W != keycode))
} else { selectNextUp();
if (KeyBinding.Down.isPressed(keycode)) if (KeyBinding.Right.isPressed(keycode, !(stage.getKeyboardFocus() instanceof Selector)
selectNextDown(); && !(stage.getKeyboardFocus() instanceof TextField) && !(stage.getKeyboardFocus() instanceof Slider)))
if (KeyBinding.Up.isPressed(keycode)) selectNextRight();
selectNextUp(); if (KeyBinding.Left.isPressed(keycode, !(stage.getKeyboardFocus() instanceof Selector)
} && !(stage.getKeyboardFocus() instanceof TextField) && !(stage.getKeyboardFocus() instanceof Slider)))
if (!(stage.getKeyboardFocus() instanceof Selector) && !(stage.getKeyboardFocus() instanceof TextField) && !(stage.getKeyboardFocus() instanceof Slider)) { selectNextLeft();
if (KeyBinding.Right.isPressed(keycode))
selectNextRight();
if (KeyBinding.Left.isPressed(keycode))
selectNextLeft();
}
} }
if (!dialogShowing()) { if (!dialogShowing()) {
Button pressedButton = ui.buttonPressed(keycode); Button pressedButton = ui.buttonPressed(keycode);

View File

@@ -34,9 +34,15 @@ public enum KeyBinding {
} }
public boolean isPressed(int key) { public boolean isPressed(int key) {
for (int i = 0; i < bindings.length; i++) { return isPressed(key, null);
if (key == bindings[i]) { }
return true;
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; return false;