Skip to content

Commit 533369b

Browse files
committed
Controller inputs can now be changed. Remove some debug information being written to the console. Left some in there on the input mapping screen for diagnostics. Changed the input control back to keyboard in settings.ini as not every developer will have a controller.
1 parent d6af8bb commit 533369b

File tree

3 files changed

+104
-32
lines changed

3 files changed

+104
-32
lines changed

main/settings.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
x=1366
22
y=768
33
fullscreen=false
4-
controlType=3
4+
controlType=0
55
vol=0.66
66
keyUpMouse=W
77
keyDownMouse=S

main/src/com/miloshpetrov/sol2/game/screens/ShipControllerControl.java

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,14 @@ public int indexOf (Controller controller) {
6464

6565
@Override
6666
public void connected (Controller controller) {
67-
System.out.println("connected " + controller.getName());
68-
int i = 0;
69-
for (Controller c : Controllers.getControllers()) {
70-
System.out.println("#" + i++ + ": " + c.getName());
71-
}
7267
}
7368

7469
@Override
7570
public void disconnected (Controller controller) {
76-
System.out.println("disconnected " + controller.getName());
77-
int i = 0;
78-
for (Controller c : Controllers.getControllers()) {
79-
System.out.println("#" + i++ + ": " + c.getName());
80-
}
81-
if (Controllers.getControllers().size == 0) System.out.println("No controllers attached");
8271
}
8372

8473
@Override
8574
public boolean buttonDown (Controller controller, int buttonIndex) {
86-
System.out.println("#" + indexOf(controller) + ", button " + buttonIndex + " down");
87-
8875
if (buttonIndex == gameOptions.getControllerButtonShoot()){
8976
controllerShoot = true;
9077
} else if (buttonIndex == gameOptions.getControllerButtonShoot2()){
@@ -99,13 +86,11 @@ public boolean buttonDown (Controller controller, int buttonIndex) {
9986
controllerUp = true;
10087
}
10188

102-
return false;
89+
return true;
10390
}
10491

10592
@Override
10693
public boolean buttonUp (Controller controller, int buttonIndex) {
107-
System.out.println("#" + indexOf(controller) + ", button " + buttonIndex + " up");
108-
10994
if (buttonIndex == gameOptions.getControllerButtonShoot()){
11095
controllerShoot = false;
11196
} else if (buttonIndex == gameOptions.getControllerButtonShoot2()){
@@ -120,13 +105,11 @@ public boolean buttonUp (Controller controller, int buttonIndex) {
120105
controllerUp = false;
121106
}
122107

123-
return false;
108+
return true;
124109
}
125110

126111
@Override
127112
public boolean axisMoved (Controller controller, int axisIndex, float value) {
128-
System.out.println("#" + indexOf(controller) + ", axis " + axisIndex + ": " + value);
129-
130113
if (axisIndex == gameOptions.getControllerAxisShoot()){
131114
if (value > 0.5f) {
132115
controllerShoot = true;
@@ -179,7 +162,7 @@ else if (axisIndex == gameOptions.getControllerAxisUpDown()){
179162
}
180163
}
181164

182-
return false;
165+
return true;
183166
}
184167

185168
@Override

main/src/com/miloshpetrov/sol2/menu/InputMapControllerScreen.java

Lines changed: 100 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
import com.badlogic.gdx.Gdx;
55
import com.badlogic.gdx.Input;
66
import com.badlogic.gdx.InputAdapter;
7+
import com.badlogic.gdx.controllers.Controller;
8+
import com.badlogic.gdx.controllers.ControllerListener;
9+
import com.badlogic.gdx.controllers.Controllers;
10+
import com.badlogic.gdx.controllers.PovDirection;
11+
import com.badlogic.gdx.math.Vector3;
712
import com.miloshpetrov.sol2.GameOptions;
813
import com.miloshpetrov.sol2.SolApplication;
914
import com.miloshpetrov.sol2.ui.SolInputManager;
@@ -21,6 +26,7 @@ public class InputMapControllerScreen implements InputMapOperations {
2126
private boolean isEnterNewKey;
2227
private List<InputConfigItem> itemsList = new ArrayList<InputConfigItem>();
2328
private int selectedIndex;
29+
private int controllerItems;
2430

2531
public InputMapControllerScreen(InputMapScreen inputMapScreen, GameOptions gameOptions) {
2632
controls = new ArrayList<SolUiControl>();
@@ -49,6 +55,8 @@ private void InitialiseList(GameOptions gameOptions) {
4955
itemsList.add(InitItem(gameOptions.getControllerAxisShoot2(), gameOptions.getControllerButtonShoot2(), "Shoot Secondary"));
5056
itemsList.add(InitItem(gameOptions.getControllerAxisAbility(), gameOptions.getControllerButtonAbility(), "Ability"));
5157

58+
controllerItems = itemsList.size();
59+
5260
// Menu and Interface Keys
5361
itemsList.add(new InputConfigItem("Pause", gameOptions.getKeyPauseName()));
5462
itemsList.add(new InputConfigItem("Map", gameOptions.getKeyMapName()));
@@ -166,28 +174,108 @@ public void updateCustom(SolApplication cmp, SolInputManager.Ptr[] ptrs, boolean
166174
if (changeCtrl.isJustOff()) {
167175
isEnterNewKey = !isEnterNewKey;
168176

169-
// TODO: Capture Controller Inputs
170-
171177
// Can cancel the key entering by clicking this button a second time
172178
if (!isEnterNewKey) {
173179
Gdx.input.setInputProcessor(null);
180+
Controllers.clearListeners();
174181
return;
175182
}
176183

177-
Gdx.input.setInputProcessor(new InputAdapter() {
178-
@Override
179-
public boolean keyUp (int keycode) {
180-
if (selectedIndex >= 7) {
184+
// Keyboard items
185+
if (selectedIndex >= controllerItems) {
186+
Gdx.input.setInputProcessor(new InputAdapter() {
187+
@Override
188+
public boolean keyUp(int keycode) {
181189
InputConfigItem item = itemsList.get(selectedIndex);
182190
item.setInputKey(Input.Keys.toString(keycode));
183191
itemsList.set(selectedIndex, item);
192+
Gdx.input.setInputProcessor(null);
193+
Controllers.clearListeners();
194+
195+
isEnterNewKey = false;
196+
return true; // return true to indicate the event was handled
197+
}
198+
});
199+
// Controller items
200+
} else {
201+
// setup the listener that prints events to the console
202+
Controllers.addListener(new ControllerListener() {
203+
public int indexOf(Controller controller) {
204+
return Controllers.getControllers().indexOf(controller, true);
205+
}
206+
207+
@Override
208+
public void connected(Controller controller) {
209+
}
210+
211+
@Override
212+
public void disconnected(Controller controller) {
213+
}
214+
215+
@Override
216+
public boolean buttonDown(Controller controller, int buttonIndex) {
217+
// Do nothing on button down - register the button up event
218+
return true;
219+
}
220+
221+
@Override
222+
public boolean buttonUp(Controller controller, int buttonIndex) {
223+
System.out.println("#" + indexOf(controller) + ", button " + buttonIndex + " up");
224+
225+
InputConfigItem item = itemsList.get(selectedIndex);
226+
item.setIsAxis(false);
227+
item.setControllerInput(buttonIndex);
228+
item.setInputKey("Button: " + buttonIndex);
229+
itemsList.set(selectedIndex, item);
230+
231+
Gdx.input.setInputProcessor(null);
232+
Controllers.clearListeners();
233+
234+
isEnterNewKey = false;
235+
return true; // return true to indicate the event was handled
236+
}
237+
238+
@Override
239+
public boolean axisMoved(Controller controller, int axisIndex, float value) {
240+
System.out.println("#" + indexOf(controller) + ", axis " + axisIndex + ": " + value);
241+
242+
if (value > 0.5f || value < -0.5f) {
243+
InputConfigItem item = itemsList.get(selectedIndex);
244+
item.setIsAxis(true);
245+
item.setControllerInput(axisIndex);
246+
item.setInputKey("Axis: " + axisIndex);
247+
itemsList.set(selectedIndex, item);
248+
249+
Gdx.input.setInputProcessor(null);
250+
Controllers.clearListeners();
251+
252+
isEnterNewKey = false;
253+
254+
}
255+
return true;
184256
}
185-
Gdx.input.setInputProcessor(null);
186257

187-
isEnterNewKey = false;
188-
return true; // return true to indicate the event was handled
189-
}
190-
});
258+
@Override
259+
public boolean povMoved(Controller controller, int povIndex, PovDirection value) {
260+
return false;
261+
}
262+
263+
@Override
264+
public boolean xSliderMoved(Controller controller, int sliderIndex, boolean value) {
265+
return false;
266+
}
267+
268+
@Override
269+
public boolean ySliderMoved(Controller controller, int sliderIndex, boolean value) {
270+
return false;
271+
}
272+
273+
@Override
274+
public boolean accelerometerMoved(Controller controller, int accelerometerIndex, Vector3 value) {
275+
return false;
276+
}
277+
});
278+
}
191279
}
192280
}
193281

@@ -218,6 +306,7 @@ public boolean isCursorOnBg(SolInputManager.Ptr ptr) {
218306
@Override
219307
public void onAdd(SolApplication cmp) {
220308
InitialiseList(cmp.getOptions());
309+
Controllers.clearListeners();
221310
isEnterNewKey = false;
222311
selectedIndex = 0;
223312
}

0 commit comments

Comments
 (0)