diff --git a/src/sig/engine/Action.java b/src/sig/engine/Action.java index 5da89d0..a019a94 100644 --- a/src/sig/engine/Action.java +++ b/src/sig/engine/Action.java @@ -16,6 +16,7 @@ public enum Action { PLAY_GAME(new Key(KeyEvent.VK_F1)),; float val; + Key controllingKey; Action(Component...components) { KeyBind.KEYBINDS.put(this,new ArrayList<>(Arrays.asList(components))); diff --git a/src/sig/engine/Key.java b/src/sig/engine/Key.java index a30e195..9bb5507 100644 --- a/src/sig/engine/Key.java +++ b/src/sig/engine/Key.java @@ -118,6 +118,7 @@ public class Key implements Component{ public static void setKeyHeld(int keycode,boolean pressed) { KEYS.put(KEY_CONVERSION_MAP.get(keycode),pressed); + //System.out.println(KEYS); } public static boolean isKeyHeld(int keycode) { @@ -129,7 +130,7 @@ public class Key implements Component{ } @Override - public Identifier getIdentifier() { + public Identifier.Key getIdentifier() { return KEY_CONVERSION_MAP.get(keycode); } diff --git a/src/sig/engine/KeyBind.java b/src/sig/engine/KeyBind.java index e720c22..996b4ce 100644 --- a/src/sig/engine/KeyBind.java +++ b/src/sig/engine/KeyBind.java @@ -45,19 +45,33 @@ public class KeyBind { public static void poll() { //Polls all KeyBinds based on device. for (Action a : Action.values()) { + boolean held = false; + Component cc = null; for (Component c : KEYBINDS.get(a)) { if (c instanceof Key) { - actionEventCheck(a,((Key)c).isKeyHeld()); + held = ((Key)c).isKeyHeld(); + actionEventCheck(a,held); } else if (c instanceof Identifier.Button) { - actionEventCheck(a,c.getPollData()>0.0f); + held = c.getPollData()>0.0f; + actionEventCheck(a,held); } else if (c.getIdentifier()==Identifier.Axis.POV) { - actionEventCheck(a,a.val==c.getPollData()); + held = a.val==c.getPollData(); + actionEventCheck(a,held); } else if (c.getIdentifier() instanceof Identifier.Axis) { - actionEventCheck(a,c.getPollData()>=c.getDeadZone()&&Math.signum(c.getPollData())==Math.signum(a.val)); + held = c.getPollData()>=c.getDeadZone()&&Math.signum(c.getPollData())==Math.signum(a.val); + actionEventCheck(a,held); } + if (held) { + cc=c; + break; + } + } + if (held) { + KEYBINDS.get(a).remove(cc); + KEYBINDS.get(a).add(0,cc); } } } @@ -73,9 +87,9 @@ public class KeyBind { } private static void emitReleaseEvent(Action a) { - System.out.println("Release for "+a); + //System.out.println("Release for "+a); } private static void emitPressEvent(Action a) { - System.out.println("Press for "+a); + //System.out.println("Press for "+a); } } \ No newline at end of file