Skip to content

Commit

Permalink
Merge PR #49 by @SimonC4 - controller support
Browse files Browse the repository at this point in the history
  • Loading branch information
Cervator committed Jul 26, 2015
2 parents c491d85 + 533369b commit 3045afc
Show file tree
Hide file tree
Showing 14 changed files with 1,833 additions and 21 deletions.
2 changes: 2 additions & 0 deletions desktop/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ dependencies {
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-controllers-desktop:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-controllers-platform:$gdxVersion:natives-desktop"
}

task run(type: JavaExec) {
Expand Down
1 change: 1 addition & 0 deletions main/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ sourceCompatibility = 1.7
dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
}

sourceSets {
Expand Down
14 changes: 14 additions & 0 deletions main/settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,17 @@ keySellMenu=S
keyBuyMenu=B
keyChangeShipMenu=C
keyHireShipMenu=H
controllerAxisShoot=1
controllerAxisShoot2=0
controllerAxisAbility=-1
controllerAxisLeftRight=2
isControllerAxisLeftRightInverted=false
controllerAxisUpDown=5
isControllerAxisUpDownInverted=false
controllerButtonShoot=-1
controllerButtonShoot2=-1
controllerButtonAbility=14
controllerButtonLeft=-1
controllerButtonRight=-1
controllerButtonUp=-1
controllerButtonDown=-1
299 changes: 279 additions & 20 deletions main/src/com/miloshpetrov/sol2/GameOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,40 @@ public class GameOptions {
public static final int CONTROL_KB = 0;
public static final int CONTROL_MIXED = 1;
public static final int CONTROL_MOUSE = 2;
public static final int CONTROL_CONTROLLER = 3;
public static final String DEFAULT_MOUSE_UP = "W";
public static final String DEFAULT_MOUSE_DOWN = "S";
public static final String DEFAULT_UP = "Up";
public static final String DEFAULT_DOWN = "Down";
public static final String DEFAULT_LEFT = "Left";
public static final String DEFAULT_RIGHT = "Right";
public static final String DEFAULT_SHOOT = "Space";
public static final String DEFAULT_SHOOT2 = "L-Ctrl";
public static final String DEFAULT_ABILITY = "L-Shift";
public static final String DEFAULT_ESCAPE = "Escape";
public static final String DEFAULT_MAP = "Tab";
public static final String DEFAULT_INVENTORY = "I";
public static final String DEFAULT_TALK = "T";
public static final String DEFAULT_PAUSE = "P";
public static final String DEFAULT_DROP = "D";
public static final String DEFAULT_SELL = "S";
public static final String DEFAULT_BUY = "B";
public static final String DEFAULT_CHANGE_SHIP = "C";
public static final String DEFAULT_HIRE_SHIP = "H";
public static final int DEFAULT_AXIS_SHOOT = 1;
public static final int DEFAULT_AXIS_SHOOT2 = 0;
public static final int DEFAULT_AXIS_ABILITY = -1;
public static final int DEFAULT_AXIS_LEFT_RIGHT = 2;
public static final boolean DEFAULT_AXIS_LEFT_RIGHT_INVERTED_ = false;
public static final int DEFAULT_AXIS_UP_DOWN = 5;
public static final boolean DEFAULT_AXIS_UP_DOWN_INVERTED_ = false;
public static final int DEFAULT_BUTTON_SHOOT = -1;
public static final int DEFAULT_BUTTON_SHOOT2 = -1;
public static final int DEFAULT_BUTTON_ABILITY = 14;
public static final int DEFAULT_BUTTON_UP = -1;
public static final int DEFAULT_BUTTON_DOWN = -1;
public static final int DEFAULT_BUTTON_LEFT = -1;
public static final int DEFAULT_BUTTON_RIGHT = -1;

public int x;
public int y;
Expand All @@ -38,6 +72,20 @@ public class GameOptions {
private String keyBuyMenuName;
private String keyChangeShipMenuName;
private String keyHireShipMenuName;
private int controllerAxisShoot;
private int controllerAxisShoot2;
private int controllerAxisAbility;
private int controllerAxisLeftRight;
private boolean isControllerAxisLeftRightInverted;
private int controllerAxisUpDown;
private boolean isControllerAxisUpDownInverted;
private int controllerButtonShoot;
private int controllerButtonShoot2;
private int controllerButtonAbility;
private int controllerButtonLeft;
private int controllerButtonRight;
private int controllerButtonUp;
private int controllerButtonDown;

private SortedSet<String> supportedResolutions = new TreeSet<String>();
private Iterator<String> resolutionIterator = null;
Expand All @@ -49,25 +97,39 @@ public GameOptions(boolean mobile, SolFileReader reader) {
fullscreen = r.b("fullscreen", false);
controlType = mobile ? CONTROL_KB : r.i("controlType", CONTROL_MIXED);
volMul = r.f("vol", 1);
keyUpMouseName = r.s("keyUpMouse", "W");
keyDownMouseName = r.s("keyDownMouse", "S");
keyUpName = r.s("keyUp", "Up");
keyDownName = r.s("keyDown", "Down");
keyLeftName = r.s("keyLeft", "Left");
keyRightName = r.s("keyRight", "Right");
keyShootName = r.s("keyShoot", "Space");
keyShoot2Name = r.s("keyShoot2", "L-Ctrl");
keyAbilityName = r.s("keyAbility", "L-Shift");
keyEscapeName = r.s("keyEscape", "Escape");
keyMapName = r.s("keyMap", "Tab");
keyInventoryName = r.s("keyInventory", "I");
keyTalkName = r.s("keyTalk", "T");
keyPauseName = r.s("keyPause", "P");
keyDropName = r.s("keyDrop", "D");
keySellMenuName = r.s("keySellMenu", "S");
keyBuyMenuName = r.s("keyBuyMenu", "B");
keyChangeShipMenuName = r.s("keyChangeShipMenu", "C");
keyHireShipMenuName = r.s("keyHireShipMenu", "H");
keyUpMouseName = r.s("keyUpMouse", DEFAULT_MOUSE_UP);
keyDownMouseName = r.s("keyDownMouse", DEFAULT_MOUSE_DOWN);
keyUpName = r.s("keyUp", DEFAULT_UP);
keyDownName = r.s("keyDown", DEFAULT_DOWN);
keyLeftName = r.s("keyLeft", DEFAULT_LEFT);
keyRightName = r.s("keyRight", DEFAULT_RIGHT);
keyShootName = r.s("keyShoot", DEFAULT_SHOOT);
keyShoot2Name = r.s("keyShoot2", DEFAULT_SHOOT2);
keyAbilityName = r.s("keyAbility", DEFAULT_ABILITY);
keyEscapeName = r.s("keyEscape", DEFAULT_ESCAPE);
keyMapName = r.s("keyMap", DEFAULT_MAP);
keyInventoryName = r.s("keyInventory", DEFAULT_INVENTORY);
keyTalkName = r.s("keyTalk", DEFAULT_TALK);
keyPauseName = r.s("keyPause", DEFAULT_PAUSE);
keyDropName = r.s("keyDrop", DEFAULT_DROP);
keySellMenuName = r.s("keySellMenu", DEFAULT_SELL);
keyBuyMenuName = r.s("keyBuyMenu", DEFAULT_BUY);
keyChangeShipMenuName = r.s("keyChangeShipMenu", DEFAULT_CHANGE_SHIP);
keyHireShipMenuName = r.s("keyHireShipMenu", DEFAULT_HIRE_SHIP);
controllerAxisShoot = r.i("controllerAxisShoot", DEFAULT_AXIS_SHOOT);
controllerAxisShoot2 = r.i("controllerAxisShoot2", DEFAULT_AXIS_SHOOT2);
controllerAxisAbility = r.i("controllerAxisAbility", DEFAULT_AXIS_ABILITY);
controllerAxisLeftRight = r.i("controllerAxisLeftRight", DEFAULT_AXIS_LEFT_RIGHT);
isControllerAxisLeftRightInverted = r.b("isControllerAxisLeftRightInverted", DEFAULT_AXIS_LEFT_RIGHT_INVERTED_);
controllerAxisUpDown = r.i("controllerAxisUpDown", DEFAULT_AXIS_UP_DOWN);
isControllerAxisUpDownInverted = r.b("isControllerAxisUpDownInverted", DEFAULT_AXIS_UP_DOWN_INVERTED_);
controllerButtonShoot = r.i("controllerButtonShoot", DEFAULT_BUTTON_SHOOT);
controllerButtonShoot2 = r.i("controllerButtonShoot2", DEFAULT_BUTTON_SHOOT2);
controllerButtonAbility = r.i("controllerButtonAbility", DEFAULT_BUTTON_ABILITY);
controllerButtonLeft = r.i("controllerButtonLeft", DEFAULT_BUTTON_LEFT);
controllerButtonRight = r.i("controllerButtonRight", DEFAULT_BUTTON_RIGHT);
controllerButtonUp = r.i("controllerButtonUp", DEFAULT_BUTTON_UP);
controllerButtonDown = r.i("controllerButtonDown", DEFAULT_BUTTON_DOWN);
}

public void advanceReso() {
Expand Down Expand Up @@ -101,6 +163,8 @@ public void advanceReso() {
public void advanceControlType(boolean mobile) {
if (controlType == CONTROL_KB) {
controlType = mobile ? CONTROL_MOUSE : CONTROL_MIXED;
} else if (controlType == CONTROL_MIXED) {
controlType = CONTROL_CONTROLLER;
// } else if (controlType == CONTROL_MIXED) {
// controlType = CONTROL_MOUSE;
} else {
Expand Down Expand Up @@ -136,7 +200,14 @@ public void save() {
"keyLeft", keyLeftName, "keyRight", keyRightName, "keyShoot", keyShootName, "keyShoot2", getKeyShoot2Name(),
"keyAbility", getKeyAbilityName(), "keyEscape", getKeyEscapeName(), "keyMap", keyMapName, "keyInventory", keyInventoryName,
"keyTalk", getKeyTalkName(), "keyPause", getKeyPauseName(), "keyDrop", getKeyDropName(), "keySellMenu", getKeySellMenuName(),
"keyBuyMenu", getKeyBuyMenuName(), "keyChangeShipMenu", getKeyChangeShipMenuName(), "keyHireShipMenu", getKeyHireShipMenuName());
"keyBuyMenu", getKeyBuyMenuName(), "keyChangeShipMenu", getKeyChangeShipMenuName(), "keyHireShipMenu", getKeyHireShipMenuName(),
"controllerAxisShoot", getControllerAxisShoot(), "controllerAxisShoot2", getControllerAxisShoot2(),
"controllerAxisAbility", getControllerAxisAbility(), "controllerAxisLeftRight", getControllerAxisLeftRight(),
"isControllerAxisLeftRightInverted", isControllerAxisLeftRightInverted(), "controllerAxisUpDown", getControllerAxisUpDown(),
"isControllerAxisUpDownInverted", isControllerAxisUpDownInverted(), "controllerButtonShoot", getControllerButtonShoot(),
"controllerButtonShoot2", getControllerButtonShoot2(), "controllerButtonAbility", getControllerButtonAbility(),
"controllerButtonLeft", getControllerButtonLeft(), "controllerButtonRight", getControllerButtonRight(),
"controllerButtonUp", getControllerButtonUp(), "controllerButtonDown", getControllerButtonDown());
}

/**
Expand Down Expand Up @@ -574,4 +645,192 @@ public int getKeyHireShipMenu() {
public String getKeyHireShipMenuName() {
return keyHireShipMenuName;
}

public int getControllerAxisShoot() {
return controllerAxisShoot;
}

public int getControllerAxisShoot2() {
return controllerAxisShoot2;
}

public int getControllerAxisAbility() {
return controllerAxisAbility;
}

public int getControllerAxisLeftRight() {
return controllerAxisLeftRight;
}

public int getControllerAxisUpDown() {
return controllerAxisUpDown;
}

public int getControllerButtonShoot() {
return controllerButtonShoot;
}

public int getControllerButtonShoot2() {
return controllerButtonShoot2;
}

public int getControllerButtonAbility() {
return controllerButtonAbility;
}

public int getControllerButtonLeft() {
return controllerButtonLeft;
}

public int getControllerButtonRight() {
return controllerButtonRight;
}

public int getControllerButtonUp() {
return controllerButtonUp;
}

public boolean isControllerAxisLeftRightInverted() {
return isControllerAxisLeftRightInverted;
}

public boolean isControllerAxisUpDownInverted() {
return isControllerAxisUpDownInverted;
}

public void setKeyUpMouseName(String keyUpMouseName) {
this.keyUpMouseName = keyUpMouseName;
}

public void setKeyDownMouseName(String keyDownMouseName) {
this.keyDownMouseName = keyDownMouseName;
}

public void setKeyUpName(String keyUpName) {
this.keyUpName = keyUpName;
}

public void setKeyDownName(String keyDownName) {
this.keyDownName = keyDownName;
}

public void setKeyLeftName(String keyLeftName) {
this.keyLeftName = keyLeftName;
}

public void setKeyRightName(String keyRightName) {
this.keyRightName = keyRightName;
}

public void setKeyShootName(String keyShootName) {
this.keyShootName = keyShootName;
}

public void setKeyShoot2Name(String keyShoot2Name) {
this.keyShoot2Name = keyShoot2Name;
}

public void setKeyAbilityName(String keyAbilityName) {
this.keyAbilityName = keyAbilityName;
}

public void setKeyEscapeName(String keyEscapeName) {
this.keyEscapeName = keyEscapeName;
}

public void setKeyMapName(String keyMapName) {
this.keyMapName = keyMapName;
}

public void setKeyInventoryName(String keyInventoryName) {
this.keyInventoryName = keyInventoryName;
}

public void setKeyTalkName(String keyTalkName) {
this.keyTalkName = keyTalkName;
}

public void setKeyPauseName(String keyPauseName) {
this.keyPauseName = keyPauseName;
}

public void setKeyDropName(String keyDropName) {
this.keyDropName = keyDropName;
}

public void setKeySellMenuName(String keySellMenuName) {
this.keySellMenuName = keySellMenuName;
}

public void setKeyBuyMenuName(String keyBuyMenuName) {
this.keyBuyMenuName = keyBuyMenuName;
}

public void setKeyChangeShipMenuName(String keyChangeShipMenuName) {
this.keyChangeShipMenuName = keyChangeShipMenuName;
}

public void setKeyHireShipMenuName(String keyHireShipMenuName) {
this.keyHireShipMenuName = keyHireShipMenuName;
}

public void setControllerAxisShoot(int controllerAxisShoot) {
this.controllerAxisShoot = controllerAxisShoot;
}

public void setControllerAxisShoot2(int controllerAxisShoot2) {
this.controllerAxisShoot2 = controllerAxisShoot2;
}

public void setControllerAxisAbility(int controllerAxisAbility) {
this.controllerAxisAbility = controllerAxisAbility;
}

public void setControllerAxisLeftRight(int controllerAxisLeftRight) {
this.controllerAxisLeftRight = controllerAxisLeftRight;
}

public void setIsControllerAxisLeftRightInverted(boolean isControllerAxisLeftRightInverted) {
this.isControllerAxisLeftRightInverted = isControllerAxisLeftRightInverted;
}

public void setControllerAxisUpDown(int controllerAxisUpDown) {
this.controllerAxisUpDown = controllerAxisUpDown;
}

public void setIsControllerAxisUpDownInverted(boolean isControllerAxisUpDownInverted) {
this.isControllerAxisUpDownInverted = isControllerAxisUpDownInverted;
}

public void setControllerButtonShoot(int controllerButtonShoot) {
this.controllerButtonShoot = controllerButtonShoot;
}

public void setControllerButtonShoot2(int controllerButtonShoot2) {
this.controllerButtonShoot2 = controllerButtonShoot2;
}

public void setControllerButtonAbility(int controllerButtonAbility) {
this.controllerButtonAbility = controllerButtonAbility;
}

public void setControllerButtonLeft(int controllerButtonLeft) {
this.controllerButtonLeft = controllerButtonLeft;
}

public void setControllerButtonRight(int controllerButtonRight) {
this.controllerButtonRight = controllerButtonRight;
}

public void setControllerButtonUp(int controllerButtonUp) {
this.controllerButtonUp = controllerButtonUp;
}

public int getControllerButtonDown() {
return controllerButtonDown;
}

public void setControllerButtonDown(int controllerButtonDown) {
this.controllerButtonDown = controllerButtonDown;
}
}
4 changes: 3 additions & 1 deletion main/src/com/miloshpetrov/sol2/game/screens/MainScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ public MainScreen(float r, RightPaneLayout rightPaneLayout, SolApplication cmp)
shipControl = new ShipKbControl(cmp, r, myControls);
} else if (ct == GameOptions.CONTROL_MIXED) {
shipControl = new ShipMixedControl(cmp, myControls);
} else {
} else if (ct == GameOptions.CONTROL_MOUSE) {
shipControl = new ShipMouseControl(cmp);
} else {
shipControl = new ShipControllerControl(cmp);
}
boolean mobile = cmp.isMobile();
float lastCol = r - MainScreen.CELL_SZ;
Expand Down
Loading

0 comments on commit 3045afc

Please sign in to comment.