v0.8.0: fully implement key bindings window, just need saving now

This commit is contained in:
Evan Debenham
2019-12-18 00:32:53 -05:00
parent 93320fb676
commit 56ad068d23
5 changed files with 318 additions and 85 deletions

View File

@@ -33,16 +33,33 @@ public class KeyBindings {
public static void addKeyBinding(int keyCode, GameAction action){
bindings.put(keyCode, action);
}
public static boolean isKeyBound(int keyCode ){
return bindings.containsKey( keyCode );
public static void clearKeyBindings(){
bindings.clear();
}
public static LinkedHashMap<Integer, GameAction> getAllBindings(){
return new LinkedHashMap<>(bindings);
}
public static void setAllBindings(LinkedHashMap<Integer, GameAction> newBindings){
bindings = new LinkedHashMap<>(newBindings);
}
public static boolean acceptUnbound = false;
public static boolean isKeyBound(int keyCode){
if (keyCode <= 0 || keyCode > 255){
return false;
}
return acceptUnbound || bindings.containsKey( keyCode );
}
public static GameAction getActionForKey(KeyEvent event ){
public static GameAction getActionForKey(KeyEvent event){
return bindings.get( event.code );
}
public static ArrayList<Integer> getKeysForAction(GameAction action ){
public static ArrayList<Integer> getKeysForAction(GameAction action){
ArrayList<Integer> result = new ArrayList<>();
for( int i : bindings.keySet()){
if (bindings.get(i) == action){
@@ -53,12 +70,12 @@ public class KeyBindings {
}
public static String getKeyName( int keyCode ){
String result = Input.Keys.toString(keyCode);
if (result.equals("Plus")){
if (keyCode == Input.Keys.UNKNOWN){
return "None";
} else if (keyCode == Input.Keys.PLUS){
return "+";
} else {
return result;
return Input.Keys.toString(keyCode);
}
}