Skip to content

Commit 9a5c49e

Browse files
committed
feat(desktop): Initial translation
1 parent 6dbf61c commit 9a5c49e

16 files changed

+1403
-89
lines changed

gdx-controllers-desktop/build.gradle

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,11 @@ tasks.getByName('processResources') {
4949
dependencies {
5050
api project(":gdx-controllers-core")
5151
implementation "com.badlogicgames.gdx:gdx:$gdxVersion"
52-
api("com.badlogicgames.jamepad:jamepad:$jamepadVersion") {
53-
exclude group: 'com.badlogicgames.gdx', module: 'gdx-jnigen-loader'
54-
}
52+
implementation "org.lwjgl:lwjgl-sdl:3.4.0-SNAPSHOT"
5553
}
5654

57-
targetCompatibility = 1.7
58-
sourceCompatibility = 1.7
55+
targetCompatibility = 1.8
56+
sourceCompatibility = 1.8
5957

6058

6159
ext {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.badlogic.gdx.controllers.desktop;
2+
3+
import com.badlogic.gdx.controllers.ControllerManager;
4+
5+
/**
6+
* Class defining the configuration of a {@link ControllerManager}.
7+
*
8+
* @author Benjamin Schulte
9+
*/
10+
public class Configuration {
11+
/**
12+
* The max number of controllers the ControllerManager should deal with
13+
*/
14+
public int maxNumControllers = 4;
15+
16+
/**
17+
* Use RawInput implementation instead of XInput on Windows, if applicable. Enable this if you
18+
* need to use more than four XInput controllers at once. Comes with drawbacks.
19+
*/
20+
public boolean useRawInput = false;
21+
22+
/**
23+
* Disable this to skip loading of the native library. Can be useful if an application wants
24+
* to use a loader other than {@link com.badlogic.gdx.utils.SharedLibraryLoader}.
25+
*/
26+
public boolean loadNativeLibrary = true;
27+
28+
/**
29+
* Disable this to return to legacy temporary file loading of database file.
30+
*/
31+
public boolean loadDatabaseInMemory = true;
32+
}
33+

gdx-controllers-desktop/src/main/java/com/badlogic/gdx/controllers/desktop/JamepadControllerManager.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77
import com.badlogic.gdx.controllers.desktop.support.CompositeControllerListener;
88
import com.badlogic.gdx.controllers.desktop.support.JamepadControllerMonitor;
99
import com.badlogic.gdx.controllers.desktop.support.JamepadShutdownHook;
10+
import com.badlogic.gdx.controllers.desktop.support.SDLControllerManager;
1011
import com.badlogic.gdx.utils.Array;
1112
import com.badlogic.gdx.utils.Disposable;
1213

1314
import java.io.IOException;
1415

1516
public class JamepadControllerManager extends AbstractControllerManager implements Disposable {
1617
// assign a Jamepad configuration to this field at game startup to override defaults
17-
public static com.studiohartman.jamepad.Configuration jamepadConfiguration;
18+
public static Configuration jamepadConfiguration;
1819

1920
private static boolean nativeLibInitialized = false;
20-
private static com.studiohartman.jamepad.ControllerManager controllerManager;
21+
private static SDLControllerManager controllerManager;
2122

2223
private final CompositeControllerListener compositeListener = new CompositeControllerListener();
2324

@@ -26,10 +27,10 @@ public JamepadControllerManager() {
2627

2728
if (!nativeLibInitialized) {
2829
if (jamepadConfiguration == null) {
29-
jamepadConfiguration = new com.studiohartman.jamepad.Configuration();
30+
jamepadConfiguration = new Configuration();
3031
}
3132

32-
controllerManager = new com.studiohartman.jamepad.ControllerManager(jamepadConfiguration);
33+
controllerManager = new SDLControllerManager(jamepadConfiguration);
3334
controllerManager.initSDLGamepad();
3435

3536
JamepadControllerMonitor monitor = new JamepadControllerMonitor(controllerManager, compositeListener);
@@ -70,7 +71,7 @@ public void dispose() {
7071
}
7172

7273
/**
73-
* @see com.studiohartman.jamepad.ControllerManager#addMappingsFromFile(String)
74+
* @see SDLControllerManager#addMappingsFromFile(String)
7475
*/
7576
public static void addMappingsFromFile(String path) throws IOException, IllegalStateException {
7677
controllerManager.addMappingsFromFile(path);
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.badlogic.gdx.controllers.desktop.support;
2+
3+
import org.lwjgl.sdl.SDLGamepad;
4+
5+
/**
6+
* The list of axes available on a gamepad
7+
*
8+
* Thumbstick axis values range from SDL_JOYSTICK_AXIS_MIN to
9+
* SDL_JOYSTICK_AXIS_MAX, and are centered within ~8000 of zero, though
10+
* advanced UI will allow users to set or autodetect the dead zone, which
11+
* varies between gamepads.
12+
*
13+
* Trigger axis values range from 0 (released) to SDL_JOYSTICK_AXIS_MAX (fully
14+
* pressed) when reported by SDL_GetGamepadAxis(). Note that this is not the
15+
* same range that will be reported by the lower-level SDL_GetJoystickAxis().
16+
*/
17+
public enum ControllerAxis {
18+
INVALID(SDLGamepad.SDL_GAMEPAD_AXIS_INVALID),
19+
LEFTX(SDLGamepad.SDL_GAMEPAD_AXIS_LEFTX),
20+
LEFTY(SDLGamepad.SDL_GAMEPAD_AXIS_LEFTY),
21+
RIGHTX(SDLGamepad.SDL_GAMEPAD_AXIS_RIGHTX),
22+
RIGHTY(SDLGamepad.SDL_GAMEPAD_AXIS_RIGHTY),
23+
LEFT_TRIGGER(SDLGamepad.SDL_GAMEPAD_AXIS_LEFT_TRIGGER),
24+
RIGHT_TRIGGER(SDLGamepad.SDL_GAMEPAD_AXIS_RIGHT_TRIGGER),;
25+
26+
public static final ControllerAxis[] VALUES = values();
27+
28+
private final int id;
29+
30+
ControllerAxis(int id) {
31+
this.id = id;
32+
}
33+
34+
public int getId() {
35+
return id;
36+
}
37+
38+
public static ControllerAxis getById(int id) {
39+
for (ControllerAxis axis : VALUES) {
40+
if (axis.id == id)
41+
return axis;
42+
}
43+
44+
return null;
45+
}
46+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package com.badlogic.gdx.controllers.desktop.support;
2+
3+
import org.lwjgl.sdl.SDLGamepad;
4+
5+
/**
6+
* The list of buttons available on a gamepad
7+
*
8+
* For controllers that use a diamond pattern for the face buttons, the
9+
* south/east/west/north buttons below correspond to the locations in the
10+
* diamond pattern. For Xbox controllers, this would be A/B/X/Y, for Nintendo
11+
* Switch controllers, this would be B/A/Y/X, for GameCube controllers this
12+
* would be A/X/B/Y, for PlayStation controllers this would be
13+
* Cross/Circle/Square/Triangle.
14+
*
15+
* For controllers that don't use a diamond pattern for the face buttons, the
16+
* south/east/west/north buttons indicate the buttons labeled A, B, C, D, or
17+
* 1, 2, 3, 4, or for controllers that aren't labeled, they are the primary,
18+
* secondary, etc. buttons.
19+
*
20+
* The activate action is often the south button and the cancel action is
21+
* often the east button, but in some regions this is reversed, so your game
22+
* should allow remapping actions based on user preferences.
23+
*
24+
* You can query the labels for the face buttons using
25+
* SDL_GetGamepadButtonLabel()
26+
* */
27+
public enum ControllerButton {
28+
29+
INVALID(SDLGamepad.SDL_GAMEPAD_BUTTON_INVALID),
30+
SOUTH(SDLGamepad.SDL_GAMEPAD_BUTTON_SOUTH), /** Bottom face button (e.g. Xbox A button) */
31+
EAST(SDLGamepad.SDL_GAMEPAD_BUTTON_EAST), /** Right face button (e.g. Xbox B button) */
32+
WEST(SDLGamepad.SDL_GAMEPAD_BUTTON_WEST), /** Left face button (e.g. Xbox X button) */
33+
NORTH(SDLGamepad.SDL_GAMEPAD_BUTTON_NORTH), /** Top face button (e.g. Xbox Y button) */
34+
BACK(SDLGamepad.SDL_GAMEPAD_BUTTON_BACK),
35+
GUIDE(SDLGamepad.SDL_GAMEPAD_BUTTON_GUIDE),
36+
START(SDLGamepad.SDL_GAMEPAD_BUTTON_START),
37+
LEFT_STICK(SDLGamepad.SDL_GAMEPAD_BUTTON_LEFT_STICK),
38+
RIGHT_STICK(SDLGamepad.SDL_GAMEPAD_BUTTON_RIGHT_STICK),
39+
LEFT_SHOULDER(SDLGamepad.SDL_GAMEPAD_BUTTON_LEFT_SHOULDER),
40+
RIGHT_SHOULDER(SDLGamepad.SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER),
41+
DPAD_UP(SDLGamepad.SDL_GAMEPAD_BUTTON_DPAD_UP),
42+
DPAD_DOWN(SDLGamepad.SDL_GAMEPAD_BUTTON_DPAD_DOWN),
43+
DPAD_LEFT(SDLGamepad.SDL_GAMEPAD_BUTTON_DPAD_LEFT),
44+
DPAD_RIGHT(SDLGamepad.SDL_GAMEPAD_BUTTON_DPAD_RIGHT),
45+
MISC1(SDLGamepad.SDL_GAMEPAD_BUTTON_MISC1), /** Additional button (e.g. Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button, Amazon Luna microphone button, Google Stadia capture button) */
46+
RIGHT_PADDLE1(SDLGamepad.SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1), /** Upper or primary paddle, under your right hand (e.g. Xbox Elite paddle P1) */
47+
LEFT_PADDLE1(SDLGamepad.SDL_GAMEPAD_BUTTON_LEFT_PADDLE1), /** Upper or primary paddle, under your left hand (e.g. Xbox Elite paddle P3) */
48+
RIGHT_PADDLE2(SDLGamepad.SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2), /** Lower or secondary paddle, under your right hand (e.g. Xbox Elite paddle P2) */
49+
LEFT_PADDLE2(SDLGamepad.SDL_GAMEPAD_BUTTON_LEFT_PADDLE2), /** Lower or secondary paddle, under your left hand (e.g. Xbox Elite paddle P4) */
50+
TOUCHPAD(SDLGamepad.SDL_GAMEPAD_BUTTON_TOUCHPAD), /** PS4/PS5 touchpad button */
51+
MISC2(SDLGamepad.SDL_GAMEPAD_BUTTON_MISC2), /** Additional button */
52+
MISC3(SDLGamepad.SDL_GAMEPAD_BUTTON_MISC3), /** Additional button */
53+
MISC4(SDLGamepad.SDL_GAMEPAD_BUTTON_MISC4), /** Additional button */
54+
MISC5(SDLGamepad.SDL_GAMEPAD_BUTTON_MISC5), /** Additional button */
55+
MISC6(SDLGamepad.SDL_GAMEPAD_BUTTON_MISC6),; /** Additional button */
56+
57+
public static final ControllerButton[] VALUES = values();
58+
59+
private final int id;
60+
61+
ControllerButton(int id) {
62+
this.id = id;
63+
}
64+
65+
public int getId() {
66+
return id;
67+
}
68+
69+
public static ControllerButton getById(int id) {
70+
for (ControllerButton button : VALUES) {
71+
if (button.id == id)
72+
return button;
73+
}
74+
75+
return null;
76+
}
77+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.badlogic.gdx.controllers.desktop.support;
2+
3+
import org.lwjgl.sdl.SDLGamepad;
4+
5+
/**
6+
* The set of gamepad button labels
7+
*
8+
* This isn't a complete set, just the face buttons to make it easy to show
9+
* button prompts.
10+
*
11+
* For a complete set, you should look at the button and gamepad type and have
12+
* a set of symbols that work well with your art style.
13+
*/
14+
public enum ControllerButtonLabel {
15+
UNKNOWN(SDLGamepad.SDL_GAMEPAD_BUTTON_LABEL_UNKNOWN),
16+
A(SDLGamepad.SDL_GAMEPAD_BUTTON_LABEL_A),
17+
B(SDLGamepad.SDL_GAMEPAD_BUTTON_LABEL_B),
18+
X(SDLGamepad.SDL_GAMEPAD_BUTTON_LABEL_X),
19+
Y(SDLGamepad.SDL_GAMEPAD_BUTTON_LABEL_Y),
20+
CROSS(SDLGamepad.SDL_GAMEPAD_BUTTON_LABEL_CROSS),
21+
CIRCLE(SDLGamepad.SDL_GAMEPAD_BUTTON_LABEL_CIRCLE),
22+
SQUARE(SDLGamepad.SDL_GAMEPAD_BUTTON_LABEL_SQUARE),
23+
TRIANGLE(SDLGamepad.SDL_GAMEPAD_BUTTON_LABEL_TRIANGLE),;
24+
25+
public static final ControllerButtonLabel[] VALUES = values();
26+
27+
private final int id;
28+
29+
ControllerButtonLabel(int id) {
30+
this.id = id;
31+
}
32+
33+
public int getId() {
34+
return id;
35+
}
36+
37+
public static ControllerButtonLabel getById(int id) {
38+
for (ControllerButtonLabel label : VALUES) {
39+
if (label.id == id)
40+
return label;
41+
}
42+
43+
return null;
44+
}
45+
}

0 commit comments

Comments
 (0)