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:
Diego Waxemberg
2013-12-22 11:12:43 -05:00
parent 9f2fa09ef3
commit e7e87825ad
3 changed files with 61 additions and 47 deletions

View File

@@ -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);
} }
}); });

View File

@@ -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();
} }
}); });

View File

@@ -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>();