Skip to content

Commit

Permalink
Merge fix for #52 from @SimonC4
Browse files Browse the repository at this point in the history
  • Loading branch information
Cervator committed Jul 26, 2015
2 parents 0cb49b3 + 9c33de8 commit 1cc94e8
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 66 deletions.
140 changes: 74 additions & 66 deletions main/src/com/miloshpetrov/sol2/menu/InputMapControllerScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,15 @@ public void updateCustom(SolApplication cmp, SolInputManager.Ptr[] ptrs, boolean
}

// Keyboard items
if (selectedIndex >= controllerItems) {
Gdx.input.setInputProcessor(new InputAdapter() {
@Override
public boolean keyUp(int keycode) {
InputConfigItem item = itemsList.get(selectedIndex);
item.setInputKey(Input.Keys.toString(keycode));
itemsList.set(selectedIndex, item);
if (selectedIndex >= controllerItems) {
InputConfigItem item = itemsList.get(selectedIndex);
item.setInputKey(Input.Keys.toString(keycode));
itemsList.set(selectedIndex, item);
}

Gdx.input.setInputProcessor(null);
Controllers.clearListeners();

Expand All @@ -197,85 +199,87 @@ public boolean keyUp(int keycode) {
}
});
// Controller items
} else {
// setup the listener that prints events to the console
Controllers.addListener(new ControllerListener() {
public int indexOf(Controller controller) {
return Controllers.getControllers().indexOf(controller, true);
}

@Override
public void connected(Controller controller) {
}

@Override
public void disconnected(Controller controller) {
}

@Override
public boolean buttonDown(Controller controller, int buttonIndex) {
// Do nothing on button down - register the button up event
return true;
}

@Override
public boolean buttonUp(Controller controller, int buttonIndex) {
System.out.println("#" + indexOf(controller) + ", button " + buttonIndex + " up");

// setup the listener that prints events to the console
Controllers.addListener(new ControllerListener() {
public int indexOf(Controller controller) {
return Controllers.getControllers().indexOf(controller, true);
}

@Override
public void connected(Controller controller) {
}

@Override
public void disconnected(Controller controller) {
}

@Override
public boolean buttonDown(Controller controller, int buttonIndex) {
// Do nothing on button down - register the button up event
return true;
}

@Override
public boolean buttonUp(Controller controller, int buttonIndex) {
System.out.println("#" + indexOf(controller) + ", button " + buttonIndex + " up");

if (selectedIndex < controllerItems) {
InputConfigItem item = itemsList.get(selectedIndex);
item.setIsAxis(false);
item.setControllerInput(buttonIndex);
item.setInputKey("Button: " + buttonIndex);
itemsList.set(selectedIndex, item);
}

Gdx.input.setInputProcessor(null);
Controllers.clearListeners();
Gdx.input.setInputProcessor(null);
Controllers.clearListeners();

isEnterNewKey = false;
return true; // return true to indicate the event was handled
}
isEnterNewKey = false;
return true; // return true to indicate the event was handled
}

@Override
public boolean axisMoved(Controller controller, int axisIndex, float value) {
System.out.println("#" + indexOf(controller) + ", axis " + axisIndex + ": " + value);
@Override
public boolean axisMoved(Controller controller, int axisIndex, float value) {
System.out.println("#" + indexOf(controller) + ", axis " + axisIndex + ": " + value);

if (value > 0.5f || value < -0.5f) {
if (value > 0.5f || value < -0.5f) {
if (selectedIndex < controllerItems) {
InputConfigItem item = itemsList.get(selectedIndex);
item.setIsAxis(true);
item.setControllerInput(axisIndex);
item.setInputKey("Axis: " + axisIndex);
itemsList.set(selectedIndex, item);

Gdx.input.setInputProcessor(null);
Controllers.clearListeners();

isEnterNewKey = false;

}
return true;
}

@Override
public boolean povMoved(Controller controller, int povIndex, PovDirection value) {
return false;
}

@Override
public boolean xSliderMoved(Controller controller, int sliderIndex, boolean value) {
return false;
}
Gdx.input.setInputProcessor(null);
Controllers.clearListeners();

@Override
public boolean ySliderMoved(Controller controller, int sliderIndex, boolean value) {
return false;
}
isEnterNewKey = false;

@Override
public boolean accelerometerMoved(Controller controller, int accelerometerIndex, Vector3 value) {
return false;
}
});
}
return true;
}

@Override
public boolean povMoved(Controller controller, int povIndex, PovDirection value) {
return false;
}

@Override
public boolean xSliderMoved(Controller controller, int sliderIndex, boolean value) {
return false;
}

@Override
public boolean ySliderMoved(Controller controller, int sliderIndex, boolean value) {
return false;
}

@Override
public boolean accelerometerMoved(Controller controller, int accelerometerIndex, Vector3 value) {
return false;
}
});
}
}

Expand Down Expand Up @@ -324,9 +328,13 @@ public String getHeader() {
@Override
public String getDisplayDetail() {
if (isEnterNewKey) {
return "Enter New Key";
if (selectedIndex >= controllerItems) {
return "Enter New Key";
} else {
return "Enter New Controller Input";
}
} else {
return "";
return "Only ship controls can use a\ncontroller in this version.\n\nMenu controls need to use\nthe keyboard.";
}
}

Expand Down
6 changes: 6 additions & 0 deletions main/src/com/miloshpetrov/sol2/menu/MainScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public List<SolUiControl> getControls() {

@Override
public void updateCustom(SolApplication cmp, SolInputManager.Ptr[] ptrs, boolean clickedOutside) {
if (cmp.getOptions().controlType == GameOptions.CONTROL_CONTROLLER) {
myTutCtrl.setEnabled(false);
} else {
myTutCtrl.setEnabled(true);
}

if (myTutCtrl.isJustOff()) {
cmp.loadNewGame(true, false);
return;
Expand Down

0 comments on commit 1cc94e8

Please sign in to comment.