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,24 +380,19 @@ public class UIScene extends Scene {
}
}
if(!textboxOpen){
if (stage.getKeyboardFocus() instanceof TextField) {
if (Input.Keys.S != keycode && KeyBinding.Down.isPressed(keycode))
if (KeyBinding.Down.isPressed(keycode, !(stage.getKeyboardFocus() instanceof TextField))
|| KeyBinding.Down.isPressed(keycode,Input.Keys.S != keycode))
selectNextDown();
if (Input.Keys.W != keycode && KeyBinding.Up.isPressed(keycode))
if (KeyBinding.Up.isPressed(keycode, !(stage.getKeyboardFocus() instanceof TextField))
|| KeyBinding.Up.isPressed(keycode,Input.Keys.W != 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))
if (KeyBinding.Right.isPressed(keycode, !(stage.getKeyboardFocus() instanceof Selector)
&& !(stage.getKeyboardFocus() instanceof TextField) && !(stage.getKeyboardFocus() instanceof Slider)))
selectNextRight();
if (KeyBinding.Left.isPressed(keycode))
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);
if (pressedButton != null) {

View File

@@ -34,11 +34,17 @@ public enum KeyBinding {
}
public boolean isPressed(int key) {
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;
}