v1.3.0: added a separate bindings window for controller
This commit is contained in:
@@ -30,8 +30,12 @@ import java.util.LinkedHashMap;
|
||||
// should see about doing some refactoring to clean this up
|
||||
public class KeyBindings {
|
||||
|
||||
//for keyboard keys
|
||||
private static LinkedHashMap<Integer, GameAction> bindings = new LinkedHashMap<>();
|
||||
|
||||
//for controller buttons
|
||||
private static LinkedHashMap<Integer, GameAction> controllerBindings = new LinkedHashMap<>();
|
||||
|
||||
public static LinkedHashMap<Integer, GameAction> getAllBindings(){
|
||||
return new LinkedHashMap<>(bindings);
|
||||
}
|
||||
@@ -40,6 +44,14 @@ public class KeyBindings {
|
||||
bindings = new LinkedHashMap<>(newBindings);
|
||||
}
|
||||
|
||||
public static LinkedHashMap<Integer, GameAction> getAllControllerBindings(){
|
||||
return new LinkedHashMap<>(controllerBindings);
|
||||
}
|
||||
|
||||
public static void setAllControllerBindings(LinkedHashMap<Integer, GameAction> newBindings){
|
||||
controllerBindings = new LinkedHashMap<>(newBindings);
|
||||
}
|
||||
|
||||
//these are special keybinding that are not user-configurable
|
||||
private static LinkedHashMap<Integer, GameAction> hardBindings = new LinkedHashMap<>();
|
||||
|
||||
@@ -53,12 +65,17 @@ public class KeyBindings {
|
||||
if (keyCode < 0 || (keyCode > 255 && keyCode < 1000)){
|
||||
return false;
|
||||
}
|
||||
return bindingKey || bindings.containsKey( keyCode ) || hardBindings.containsKey( keyCode );
|
||||
return bindingKey
|
||||
|| bindings.containsKey( keyCode )
|
||||
|| controllerBindings.containsKey( keyCode )
|
||||
|| hardBindings.containsKey( keyCode );
|
||||
}
|
||||
|
||||
public static GameAction getActionForKey(KeyEvent event){
|
||||
if (bindings.containsKey( event.code )){
|
||||
if (bindings.containsKey( event.code )) {
|
||||
return bindings.get( event.code );
|
||||
} else if (controllerBindings.containsKey( event.code )){
|
||||
return controllerBindings.get( event.code );
|
||||
} else if (hardBindings.containsKey( event.code )) {
|
||||
return hardBindings.get( event.code );
|
||||
}
|
||||
@@ -67,11 +84,36 @@ public class KeyBindings {
|
||||
|
||||
public static ArrayList<Integer> getBoundKeysForAction(GameAction action){
|
||||
ArrayList<Integer> result = new ArrayList<>();
|
||||
for( int i : bindings.keySet()){
|
||||
for( int i : bindings.keySet() ){
|
||||
if (bindings.get(i) == action){
|
||||
result.add(i);
|
||||
}
|
||||
}
|
||||
for( int i : controllerBindings.keySet() ){
|
||||
if (controllerBindings.get(i) == action){
|
||||
result.add(i);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ArrayList<Integer> getKeyboardKeysForAction(GameAction action){
|
||||
ArrayList<Integer> result = new ArrayList<>();
|
||||
for( int i : bindings.keySet() ){
|
||||
if (bindings.get(i) == action){
|
||||
result.add(i);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ArrayList<Integer> getControllerKeysForAction(GameAction action){
|
||||
ArrayList<Integer> result = new ArrayList<>();
|
||||
for( int i : controllerBindings.keySet() ){
|
||||
if (controllerBindings.get(i) == action){
|
||||
result.add(i);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user