diff --git a/src/sig/engine/Action.java b/src/sig/engine/Action.java index 9881a74..e68c83f 100644 --- a/src/sig/engine/Action.java +++ b/src/sig/engine/Action.java @@ -7,26 +7,26 @@ import java.util.Arrays; import net.java.games.input.Component; public enum Action { - MOVE_RIGHT(new Key(KeyEvent.VK_RIGHT),new Key(KeyEvent.VK_D)), - MOVE_LEFT(new Key(KeyEvent.VK_LEFT),new Key(KeyEvent.VK_A)), - JUMP(new Key(KeyEvent.VK_SPACE),new Key(KeyEvent.VK_W)), - FALL(new Key(KeyEvent.VK_DOWN),new Key(KeyEvent.VK_S)), - SLIDE(new Key(KeyEvent.VK_CONTROL)), - LEVEL_EDITOR(new Key(KeyEvent.VK_F2)), - PLAY_GAME(new Key(KeyEvent.VK_F1)), - EDITOR_SET_VIEW(new Key(KeyEvent.VK_F3)), - EDITOR_SET_TYPE(new Key(KeyEvent.VK_F4)), - EDITOR_SET_BACKGROUND(new Key(KeyEvent.VK_F5)),; + MOVE_RIGHT(new KeyBind(KeyEvent.VK_RIGHT),new KeyBind(KeyEvent.VK_D)), + MOVE_LEFT(new KeyBind(KeyEvent.VK_LEFT),new KeyBind(KeyEvent.VK_A)), + JUMP(new KeyBind(KeyEvent.VK_SPACE),new KeyBind(KeyEvent.VK_W)), + FALL(new KeyBind(KeyEvent.VK_DOWN),new KeyBind(KeyEvent.VK_S)), + SLIDE(new KeyBind(KeyEvent.VK_CONTROL)), + LEVEL_EDITOR(new KeyBind(KeyEvent.VK_F2)), + PLAY_GAME(new KeyBind(KeyEvent.VK_F1)), + EDITOR_SET_VIEW(new KeyBind(KeyEvent.VK_F3)), + EDITOR_SET_TYPE(new KeyBind(KeyEvent.VK_F4)), + EDITOR_SET_BACKGROUND(new KeyBind(KeyEvent.VK_F5)),; float val; Key controllingKey; - Action(Component...components) { - KeyBind.KEYBINDS.put(this,new ArrayList<>(Arrays.asList(components))); + Action(KeyBind...keybinds) { + KeyBind.KEYBINDS.put(this,new ArrayList<>(Arrays.asList(keybinds))); } Action(Component axis,float val) { - ArrayList comps = new ArrayList(); - comps.add(axis); + ArrayList comps = new ArrayList(); + comps.add(new KeyBind(axis,val)); KeyBind.KEYBINDS.put(this,comps); } } diff --git a/src/sig/engine/KeyBind.java b/src/sig/engine/KeyBind.java index 8fff8e9..6974906 100644 --- a/src/sig/engine/KeyBind.java +++ b/src/sig/engine/KeyBind.java @@ -9,16 +9,20 @@ import net.java.games.input.Component.POV; import sig.RabiClone; public class KeyBind { - public static HashMap> KEYBINDS = new HashMap<>(); + public static HashMap> KEYBINDS = new HashMap<>(); static HashMap KEYS = new HashMap<>(); - Component c; + public Component c; float val; public KeyBind(Component c) { this.c=c; } + public KeyBind(int keycode) { + this(new Key(keycode)); + } + public KeyBind(Component c, float val) { this.c=c; this.val=val; @@ -28,7 +32,7 @@ public class KeyBind { return KEYS.getOrDefault(action,false); } - public static boolean isKeyHeld(Component c) { + public boolean isKeyHeld() { if (c instanceof Key) { return ((Key)c).isKeyHeld(); } else if (c instanceof Identifier.Button) { @@ -54,9 +58,9 @@ public class KeyBind { //Polls all KeyBinds based on device. for (Action a : Action.values()) { boolean held = false; - Component cc = null; - for (Component c : KEYBINDS.get(a)) { - held = isKeyHeld(c); + KeyBind cc = null; + for (KeyBind c : KEYBINDS.get(a)) { + held = c.isKeyHeld(); actionEventCheck(a,held); if (held) { cc=c; diff --git a/src/sig/objects/ConfigureControls.java b/src/sig/objects/ConfigureControls.java index f4cdd05..fe10f90 100644 --- a/src/sig/objects/ConfigureControls.java +++ b/src/sig/objects/ConfigureControls.java @@ -1,11 +1,12 @@ package sig.objects; +import java.util.HashMap; + import net.java.games.input.Component; import sig.RabiClone; import sig.engine.Action; import sig.engine.Alpha; import sig.engine.Font; -import sig.engine.Key; import sig.engine.KeyBind; import sig.engine.Object; import sig.engine.PaletteColor; @@ -13,6 +14,8 @@ import sig.engine.Panel; public class ConfigureControls extends Object{ + HashMap defaultValues = new HashMap<>(); + protected ConfigureControls(Panel panel) { super(panel); RabiClone.BACKGROUND_COLOR = PaletteColor.WHITE; @@ -34,8 +37,8 @@ public class ConfigureControls extends Object{ private StringBuilder DisplayActionKeys(Action a) { StringBuilder sb = new StringBuilder(a.toString()).append(": "); boolean first=true; - for (Component c : KeyBind.KEYBINDS.get(a)) { - sb.append(((Key)c).isKeyHeld()?PaletteColor.YELLOW_GREEN:PaletteColor.MIDNIGHT_BLUE).append(c.getName()).append(!first?",":""); + for (KeyBind c : KeyBind.KEYBINDS.get(a)) { + sb.append(c.isKeyHeld()?PaletteColor.YELLOW_GREEN:PaletteColor.MIDNIGHT_BLUE).append(c.c.getName()).append(!first?",":""); sb.append("\n"); } return sb;