mirror of
https://github.com/Maschell/HIDtoVPADNetworkClient.git
synced 2024-11-22 05:59:16 +01:00
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:
parent
e05d96f9b2
commit
e7fc629bec
@ -30,6 +30,7 @@ import java.awt.event.ActionListener;
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
@ -50,8 +51,10 @@ public class GuiInputControls extends JPanel implements ActionListener {
|
||||
private JButton connectButton;
|
||||
private JTextField ipTextBox;
|
||||
private JPanel ipTextBoxWrap;
|
||||
private JTextField packetIntervalTextBox;
|
||||
private JLabel statusLabel;
|
||||
|
||||
private JPanel autoActivateWrap;
|
||||
private JCheckBox cbautoActivateController;
|
||||
|
||||
public GuiInputControls() throws Exception {
|
||||
super();
|
||||
@ -76,7 +79,25 @@ public class GuiInputControls extends JPanel implements ActionListener {
|
||||
|
||||
statusLabel = new JLabel("Ready.");
|
||||
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(ipTextBoxWrap);
|
||||
@ -86,6 +107,7 @@ public class GuiInputControls extends JPanel implements ActionListener {
|
||||
add(Box.createRigidArea(new Dimension(1, 8)));
|
||||
|
||||
add(statusLabel);
|
||||
add(autoActivateWrap);
|
||||
|
||||
add(Box.createVerticalGlue());
|
||||
|
||||
@ -113,22 +135,6 @@ public class GuiInputControls extends JPanel implements ActionListener {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public JTextField getPacketIntervalTextBox() {
|
||||
return packetIntervalTextBox;
|
||||
}
|
||||
|
||||
public JTextField getIpTextBox() {
|
||||
return ipTextBox;
|
||||
}
|
||||
|
||||
public JButton getConnectButton() {
|
||||
return connectButton;
|
||||
}
|
||||
|
||||
public JLabel getStatusLabel() {
|
||||
return statusLabel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
|
@ -98,22 +98,17 @@ public class ControllerManager {
|
||||
} catch (ControllerInitializationFailedException e) {
|
||||
// e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
/*
|
||||
* TODO: Currently the XInput will be set active automatically. But this should move to something for the settings?
|
||||
*/
|
||||
break;
|
||||
case XINPUT14:
|
||||
try {
|
||||
c = new XInput14Controller(deviceIdentifier);
|
||||
c.setActive(true);
|
||||
} catch (ControllerInitializationFailedException e) {
|
||||
// e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
case XINPUT13:
|
||||
try {
|
||||
c = new XInput13Controller(deviceIdentifier);
|
||||
c.setActive(true);
|
||||
c = new XInput13Controller(deviceIdentifier);
|
||||
} catch (ControllerInitializationFailedException e) {
|
||||
// e.printStackTrace();
|
||||
}
|
||||
@ -122,6 +117,9 @@ public class ControllerManager {
|
||||
break;
|
||||
}
|
||||
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();
|
||||
attachedControllers.put(deviceIdentifier, c);
|
||||
}
|
||||
|
@ -50,6 +50,8 @@ public class Settings {
|
||||
public static final int PING_INTERVAL = 1000;
|
||||
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
|
||||
|
||||
private Settings() {
|
||||
@ -88,6 +90,15 @@ public class Settings {
|
||||
}
|
||||
|
||||
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!");
|
||||
}
|
||||
@ -108,6 +119,7 @@ public class Settings {
|
||||
Properties prop = new Properties();
|
||||
|
||||
prop.setProperty("ipAddr", Settings.ipAddr);
|
||||
prop.setProperty("autoActivatingController", Boolean.toString(Settings.AUTO_ACTIVATE_CONTROLLER));
|
||||
|
||||
try {
|
||||
FileOutputStream outStream = new FileOutputStream(configFile);
|
||||
|
Loading…
Reference in New Issue
Block a user