mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-04-24 00:56:42 +00:00
renamed gamepad config page, No longer shit bricks if the gamepad disconnects while trying to map. Now rescans for gamepads
This commit is contained in:
@@ -31,7 +31,7 @@ import com.limelight.input.GamepadMapping;
|
|||||||
import com.limelight.input.GamepadMapping.Mapping;
|
import com.limelight.input.GamepadMapping.Mapping;
|
||||||
import com.limelight.settings.GamepadSettingsManager;
|
import com.limelight.settings.GamepadSettingsManager;
|
||||||
|
|
||||||
public class SettingsFrame extends JFrame {
|
public class GamepadConfigFrame extends JFrame {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private boolean configChanged = false;
|
private boolean configChanged = false;
|
||||||
@@ -40,7 +40,7 @@ public class SettingsFrame extends JFrame {
|
|||||||
private Thread mappingThread;
|
private Thread mappingThread;
|
||||||
private GamepadMapping config;
|
private GamepadMapping config;
|
||||||
|
|
||||||
public SettingsFrame() {
|
public GamepadConfigFrame() {
|
||||||
super("Gamepad Settings");
|
super("Gamepad Settings");
|
||||||
System.out.println("Creating Settings Frame");
|
System.out.println("Creating Settings Frame");
|
||||||
this.setSize(900, 500);
|
this.setSize(900, 500);
|
||||||
@@ -87,6 +87,9 @@ public class SettingsFrame extends JFrame {
|
|||||||
comp.getMapButton().setMinimumSize(buttonSize);
|
comp.getMapButton().setMinimumSize(buttonSize);
|
||||||
comp.getMapButton().setPreferredSize(buttonSize);
|
comp.getMapButton().setPreferredSize(buttonSize);
|
||||||
|
|
||||||
|
for (ActionListener l : comp.getMapButton().getActionListeners()) {
|
||||||
|
comp.getMapButton().removeActionListener(l);
|
||||||
|
}
|
||||||
comp.getMapButton().addActionListener(createListener());
|
comp.getMapButton().addActionListener(createListener());
|
||||||
comp.getMapButton().setText(config.getMapping(comp));
|
comp.getMapButton().setText(config.getMapping(comp));
|
||||||
|
|
||||||
@@ -172,7 +175,7 @@ public class SettingsFrame extends JFrame {
|
|||||||
List<Gamepad> gamepads = GamepadHandler.getGamepads();
|
List<Gamepad> gamepads = GamepadHandler.getGamepads();
|
||||||
|
|
||||||
if (gamepads.isEmpty()) {
|
if (gamepads.isEmpty()) {
|
||||||
JOptionPane.showMessageDialog(SettingsFrame.this, "No Gamepad Detected");
|
JOptionPane.showMessageDialog(GamepadConfigFrame.this, "No Gamepad Detected");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
map(contComp, gamepads.get(0));
|
map(contComp, gamepads.get(0));
|
||||||
@@ -198,17 +201,22 @@ public class SettingsFrame extends JFrame {
|
|||||||
Component newMapping = null;
|
Component newMapping = null;
|
||||||
|
|
||||||
while (newMapping == null) {
|
while (newMapping == null) {
|
||||||
pad.poll();
|
if (pad.poll()) {
|
||||||
EventQueue queue = pad.getEvents();
|
EventQueue queue = pad.getEvents();
|
||||||
Event event = new Event();
|
Event event = new Event();
|
||||||
|
|
||||||
while (queue.getNextEvent(event)) {
|
while (queue.getNextEvent(event)) {
|
||||||
if (Math.abs(event.getValue()) > .75F) {
|
if (!pad.poll()) {
|
||||||
newMapping = event.getComponent();
|
break;
|
||||||
break;
|
}
|
||||||
|
if (Math.abs(event.getValue()) > .75F) {
|
||||||
|
newMapping = event.getComponent();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
@@ -218,30 +226,38 @@ public class SettingsFrame extends JFrame {
|
|||||||
Thread consumeEvents = new Thread(new Runnable() {
|
Thread consumeEvents = new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
pad.poll();
|
if (pad.poll()) {
|
||||||
EventQueue queue = pad.getEvents();
|
EventQueue queue = pad.getEvents();
|
||||||
Event event = new Event();
|
Event event = new Event();
|
||||||
|
|
||||||
while (queue.getNextEvent(event)) {
|
while (queue.getNextEvent(event)) {
|
||||||
|
if (!pad.poll()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
consumeEvents.setName("Consume Events Thread");
|
consumeEvents.setName("Consume Events Thread");
|
||||||
consumeEvents.start();
|
consumeEvents.start();
|
||||||
|
|
||||||
Mapping oldConfig = config.getMapping(newMapping);
|
if (newMapping != null) {
|
||||||
if (oldConfig != null) {
|
Mapping oldConfig = config.getMapping(newMapping);
|
||||||
config.removeMapping(newMapping);
|
if (oldConfig != null) {
|
||||||
oldConfig.contComp.getMapButton().setText("");
|
config.removeMapping(newMapping);
|
||||||
}
|
oldConfig.contComp.getMapButton().setText("");
|
||||||
|
}
|
||||||
|
|
||||||
Mapping newConfig = config.getMappedComponent(contComp);
|
Mapping newConfig = config.getMappedComponent(contComp);
|
||||||
if (newConfig == null) {
|
if (newConfig == null) {
|
||||||
newConfig = config.new Mapping(contComp, false, false);
|
newConfig = config.new Mapping(contComp, false, false);
|
||||||
|
}
|
||||||
|
config.insertMapping(newConfig, newMapping);
|
||||||
|
contComp.getMapButton().setText(newMapping.getName());
|
||||||
|
configChanged = true;
|
||||||
|
} else {
|
||||||
|
contComp.getMapButton().setText(config.getMapping(contComp));
|
||||||
}
|
}
|
||||||
config.insertMapping(newConfig, newMapping);
|
|
||||||
contComp.getMapButton().setText(newMapping.getName());
|
|
||||||
configChanged = true;
|
|
||||||
contComp.getMapButton().setSelected(false);
|
contComp.getMapButton().setSelected(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -125,7 +125,7 @@ public class MainFrame {
|
|||||||
gamepadSettings.addActionListener(new ActionListener() {
|
gamepadSettings.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
new SettingsFrame().build();
|
new GamepadConfigFrame().build();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -40,11 +40,9 @@ public class ControllerListener {
|
|||||||
|
|
||||||
ControllerEnvironment defaultEnv = null;
|
ControllerEnvironment defaultEnv = null;
|
||||||
|
|
||||||
//TODO: allow "rescanning" to work again
|
|
||||||
defaultEnv = (ControllerEnvironment)construct.newInstance();
|
|
||||||
|
|
||||||
while(!isInterrupted()) {
|
while(!isInterrupted()) {
|
||||||
|
|
||||||
|
defaultEnv = (ControllerEnvironment)construct.newInstance();
|
||||||
Controller[] ca = defaultEnv.getControllers();
|
Controller[] ca = defaultEnv.getControllers();
|
||||||
LinkedList<Controller> gamepads = new LinkedList<Controller>();
|
LinkedList<Controller> gamepads = new LinkedList<Controller>();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user