Added setting option for automatically activating controller.

This is useful when attaching/detaching controller while running then
client and want to active them anyway.
This commit is contained in:
Maschell 2017-03-27 20:37:22 +02:00
parent e05d96f9b2
commit e7fc629bec
3 changed files with 41 additions and 25 deletions

View File

@ -30,6 +30,7 @@ import java.awt.event.ActionListener;
import javax.swing.Box; import javax.swing.Box;
import javax.swing.BoxLayout; import javax.swing.BoxLayout;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JTextField; import javax.swing.JTextField;
@ -50,9 +51,11 @@ public class GuiInputControls extends JPanel implements ActionListener {
private JButton connectButton; private JButton connectButton;
private JTextField ipTextBox; private JTextField ipTextBox;
private JPanel ipTextBoxWrap; private JPanel ipTextBoxWrap;
private JTextField packetIntervalTextBox;
private JLabel statusLabel; private JLabel statusLabel;
private JPanel autoActivateWrap;
private JCheckBox cbautoActivateController;
public GuiInputControls() throws Exception { public GuiInputControls() throws Exception {
super(); super();
if (instance != null) { if (instance != null) {
@ -77,6 +80,24 @@ public class GuiInputControls extends JPanel implements ActionListener {
statusLabel = new JLabel("Ready."); statusLabel = new JLabel("Ready.");
statusLabel.setAlignmentX(Component.CENTER_ALIGNMENT); statusLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
cbautoActivateController = new JCheckBox();
cbautoActivateController.setSelected(Settings.AUTO_ACTIVATE_CONTROLLER);
cbautoActivateController.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
boolean selected = ((JCheckBox) e.getSource()).isSelected();
Settings.AUTO_ACTIVATE_CONTROLLER = selected;
cbautoActivateController.setSelected(selected);
}
});
autoActivateWrap = new JPanel(new FlowLayout());
autoActivateWrap.add(new JLabel("Auto Activate Controller: "));
autoActivateWrap.add(cbautoActivateController);
autoActivateWrap.setMaximumSize(new Dimension(1000, 20));
add(Box.createVerticalGlue()); add(Box.createVerticalGlue());
add(ipTextBoxWrap); add(ipTextBoxWrap);
@ -86,6 +107,7 @@ public class GuiInputControls extends JPanel implements ActionListener {
add(Box.createRigidArea(new Dimension(1, 8))); add(Box.createRigidArea(new Dimension(1, 8)));
add(statusLabel); add(statusLabel);
add(autoActivateWrap);
add(Box.createVerticalGlue()); add(Box.createVerticalGlue());
@ -113,22 +135,6 @@ public class GuiInputControls extends JPanel implements ActionListener {
return instance; return instance;
} }
public JTextField getPacketIntervalTextBox() {
return packetIntervalTextBox;
}
public JTextField getIpTextBox() {
return ipTextBox;
}
public JButton getConnectButton() {
return connectButton;
}
public JLabel getStatusLabel() {
return statusLabel;
}
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {

View File

@ -99,13 +99,9 @@ public class ControllerManager {
// e.printStackTrace(); // e.printStackTrace();
} }
break; break;
/*
* TODO: Currently the XInput will be set active automatically. But this should move to something for the settings?
*/
case XINPUT14: case XINPUT14:
try { try {
c = new XInput14Controller(deviceIdentifier); c = new XInput14Controller(deviceIdentifier);
c.setActive(true);
} catch (ControllerInitializationFailedException e) { } catch (ControllerInitializationFailedException e) {
// e.printStackTrace(); // e.printStackTrace();
} }
@ -113,7 +109,6 @@ public class ControllerManager {
case XINPUT13: case XINPUT13:
try { try {
c = new XInput13Controller(deviceIdentifier); c = new XInput13Controller(deviceIdentifier);
c.setActive(true);
} catch (ControllerInitializationFailedException e) { } catch (ControllerInitializationFailedException e) {
// e.printStackTrace(); // e.printStackTrace();
} }
@ -122,6 +117,9 @@ public class ControllerManager {
break; break;
} }
if (c != null) { // I don't like that starting the Thread happens here =/ if (c != null) { // I don't like that starting the Thread happens here =/
if(Settings.AUTO_ACTIVATE_CONTROLLER){
c.setActive(true);
}
new Thread(c).start(); new Thread(c).start();
attachedControllers.put(deviceIdentifier, c); attachedControllers.put(deviceIdentifier, c);
} }

View File

@ -50,6 +50,8 @@ public class Settings {
public static final int PING_INTERVAL = 1000; public static final int PING_INTERVAL = 1000;
public static final int PROCESS_CMD_INTERVAL = 10; public static final int PROCESS_CMD_INTERVAL = 10;
public static boolean AUTO_ACTIVATE_CONTROLLER = true;
@Getter @Setter private static String ipAddr = "192.168.0.35"; // @Maschell, you're welcome @Getter @Setter private static String ipAddr = "192.168.0.35"; // @Maschell, you're welcome
private Settings() { private Settings() {
@ -88,6 +90,15 @@ public class Settings {
} }
Settings.ipAddr = prop.getProperty("ipAddr"); Settings.ipAddr = prop.getProperty("ipAddr");
String autoActivatingControllerString = prop.getProperty("autoActivatingController");
if(autoActivatingControllerString != null){ //We don't combine the if statements to keep the default value.
if(autoActivatingControllerString.equals("true")){
Settings.AUTO_ACTIVATE_CONTROLLER = true;
}else{
Settings.AUTO_ACTIVATE_CONTROLLER = false;
}
}
log.info("Loaded config successfully!"); log.info("Loaded config successfully!");
} }
@ -108,6 +119,7 @@ public class Settings {
Properties prop = new Properties(); Properties prop = new Properties();
prop.setProperty("ipAddr", Settings.ipAddr); prop.setProperty("ipAddr", Settings.ipAddr);
prop.setProperty("autoActivatingController", Boolean.toString(Settings.AUTO_ACTIVATE_CONTROLLER));
try { try {
FileOutputStream outStream = new FileOutputStream(configFile); FileOutputStream outStream = new FileOutputStream(configFile);