mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-04-13 11:26:25 +00:00
more gamepad stuff
- now have settings files - now read/write gamepad settings to file - now map button/axis for gamepads
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package com.limelight.input;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTextField;
|
||||
import java.io.Serializable;
|
||||
|
||||
public enum ControllerComponent {
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
public enum ControllerComponent implements Serializable {
|
||||
BTN_A("Button 1 (A)", false), BTN_X("Button 2 (X)", false), BTN_Y("Button 3 (Y)", false), BTN_B("Button 4 (B)", false),
|
||||
DPAD_UP("D-pad Up", false), DPAD_DOWN("D-pad Down", false), DPAD_LEFT("D-pad Left", false), DPAD_RIGHT("D-pad Right", false),
|
||||
LS_X("Left Stick X", true), LS_Y("Left Stick X", true), RS_X("Right Stick X", true), RS_Y("Left Stick Y", true),
|
||||
@@ -12,14 +14,13 @@ public enum ControllerComponent {
|
||||
BTN_START("Start Button", false), BTN_BACK("Back Button", false), BTN_SPECIAL("Special Button", false);
|
||||
|
||||
private JLabel label;
|
||||
private JTextField textBox;
|
||||
private JButton mapButton;
|
||||
private boolean analog;
|
||||
|
||||
private ControllerComponent(String name, boolean analog) {
|
||||
this.label = new JLabel(name);
|
||||
this.textBox = new JTextField();
|
||||
this.textBox.setEditable(false);
|
||||
this.textBox.setName(this.name());
|
||||
this.mapButton = new JButton();
|
||||
this.mapButton.setName(this.name());
|
||||
this.analog = analog;
|
||||
}
|
||||
|
||||
@@ -27,8 +28,8 @@ public enum ControllerComponent {
|
||||
return label;
|
||||
}
|
||||
|
||||
public JTextField getTextField() {
|
||||
return textBox;
|
||||
public JButton getMapButton() {
|
||||
return mapButton;
|
||||
}
|
||||
|
||||
public boolean isAnalog() {
|
||||
|
||||
@@ -18,6 +18,7 @@ public class ControllerListener {
|
||||
*/
|
||||
public static boolean startUp() {
|
||||
if (listenerThread == null || !listenerThread.isAlive()) {
|
||||
System.out.println("Controller Listener thread starting up");
|
||||
listenerThread = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -36,13 +37,14 @@ public class ControllerListener {
|
||||
Class<? extends ControllerEnvironment> defEnv = ControllerEnvironment.getDefaultEnvironment().getClass();
|
||||
construct = defEnv.getDeclaredConstructor();
|
||||
construct.setAccessible(true);
|
||||
|
||||
ControllerEnvironment defaultEnv = null;
|
||||
|
||||
//TODO: allow "rescanning" to work again
|
||||
defaultEnv = (ControllerEnvironment)construct.newInstance();
|
||||
|
||||
while(!isInterrupted()) {
|
||||
|
||||
ControllerEnvironment defaultEnv = null;
|
||||
|
||||
defaultEnv = (ControllerEnvironment)construct.newInstance();
|
||||
|
||||
Controller[] ca = defaultEnv.getControllers();
|
||||
LinkedList<Controller> gamepads = new LinkedList<Controller>();
|
||||
|
||||
@@ -60,9 +62,7 @@ public class ControllerListener {
|
||||
}
|
||||
|
||||
GamepadHandler.addGamepads(gamepads);
|
||||
if (conn != null) {
|
||||
GamepadHandler.setConnection(conn);
|
||||
}
|
||||
GamepadHandler.setConnection(conn);
|
||||
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
@@ -83,12 +83,19 @@ public class ControllerListener {
|
||||
|
||||
public static void stopListening() {
|
||||
if (listenerThread != null && listenerThread.isAlive()) {
|
||||
System.out.println("Stopping Controller Listener thread");
|
||||
listenerThread.interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
public static void startSendingInput(NvConnection connection) {
|
||||
System.out.println("Starting to send controller input");
|
||||
conn = connection;
|
||||
}
|
||||
|
||||
public static void stopSendingInput() {
|
||||
System.out.println("Stopping sending controller input");
|
||||
conn = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -104,11 +104,13 @@ public class Gamepad {
|
||||
}
|
||||
|
||||
private void handleComponent(Component comp, float value) {
|
||||
ControllerComponent contComp = config.getControllerComponent(comp);
|
||||
if (contComp.isAnalog()) {
|
||||
handleAnalog(contComp, value);
|
||||
} else {
|
||||
handleButtons(contComp, value);
|
||||
if (config != null) {
|
||||
ControllerComponent contComp = config.getControllerComponent(comp);
|
||||
if (contComp.isAnalog()) {
|
||||
handleAnalog(contComp, value);
|
||||
} else {
|
||||
handleButtons(contComp, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,14 +149,14 @@ public class Gamepad {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void handleButtons(ControllerComponent contComp, float value) {
|
||||
boolean press = false;
|
||||
|
||||
if (value > 0.5F) {
|
||||
press = true;
|
||||
}
|
||||
|
||||
|
||||
switch (contComp) {
|
||||
case BTN_A:
|
||||
toggle(ControllerPacket.A_FLAG, press);
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import com.limelight.nvstream.NvConnection;
|
||||
import com.limelight.settings.GamepadSettingsManager;
|
||||
|
||||
import net.java.games.input.Controller;
|
||||
|
||||
@@ -18,9 +19,11 @@ public class GamepadHandler {
|
||||
|
||||
gamepads.clear();
|
||||
|
||||
|
||||
GamepadSettings settings = GamepadSettingsManager.getSettings();
|
||||
for (Controller pad : pads) {
|
||||
|
||||
gamepads.add(new Gamepad(pad, null)); //TODO: need to create/get the settings for this controller
|
||||
gamepads.add(new Gamepad(pad, settings));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +37,7 @@ public class GamepadHandler {
|
||||
|
||||
public static void startUp() {
|
||||
if (handler == null || !handler.isAlive()) {
|
||||
System.out.println("Gamepad Handler thread starting up");
|
||||
handler = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -42,6 +46,7 @@ public class GamepadHandler {
|
||||
if (!gamepad.poll()) {
|
||||
break;
|
||||
}
|
||||
|
||||
gamepad.handleEvents(conn);
|
||||
}
|
||||
try {
|
||||
@@ -56,6 +61,7 @@ public class GamepadHandler {
|
||||
|
||||
public static void stopHandler() {
|
||||
if (handler != null && handler.isAlive()) {
|
||||
System.out.println("Stopping Gamepad Handler thread");
|
||||
handler.interrupt();
|
||||
conn = null;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.limelight.input;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.java.games.input.Component;
|
||||
|
||||
public class GamepadSettings {
|
||||
public class GamepadSettings implements Serializable {
|
||||
private static final long serialVersionUID = -185035113915743149L;
|
||||
|
||||
private HashMap<ControllerComponent, Component> mapping;
|
||||
private HashMap<Component, ControllerComponent> inverseMapping;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user