mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-04-24 00:56:42 +00:00
got rid of some copy pasta
This commit is contained in:
@@ -7,8 +7,6 @@ import java.awt.GridLayout;
|
|||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.ItemEvent;
|
|
||||||
import java.awt.event.ItemListener;
|
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
import java.awt.event.WindowListener;
|
import java.awt.event.WindowListener;
|
||||||
@@ -107,8 +105,8 @@ public class GamepadConfigFrame extends JFrame {
|
|||||||
Box componentBox = Box.createHorizontalBox();
|
Box componentBox = Box.createHorizontalBox();
|
||||||
|
|
||||||
JButton mapButton = new JButton();
|
JButton mapButton = new JButton();
|
||||||
JCheckBox invertBox = new JCheckBox("Invert");
|
JCheckBox invertBox = new GamepadCheckBox("Invert", GamepadCheckBox.Type.INVERT);
|
||||||
JCheckBox triggerBox = new JCheckBox("Trigger");
|
JCheckBox triggerBox = new GamepadCheckBox("Trigger", GamepadCheckBox.Type.TRIGGER);
|
||||||
|
|
||||||
Dimension buttonSize = new Dimension(110, 24);
|
Dimension buttonSize = new Dimension(110, 24);
|
||||||
mapButton.setMaximumSize(buttonSize);
|
mapButton.setMaximumSize(buttonSize);
|
||||||
@@ -119,11 +117,11 @@ public class GamepadConfigFrame extends JFrame {
|
|||||||
setButtonText(mapButton, config.getMapping(mapping.padComp));
|
setButtonText(mapButton, config.getMapping(mapping.padComp));
|
||||||
|
|
||||||
invertBox.setSelected(mapping.invert);
|
invertBox.setSelected(mapping.invert);
|
||||||
invertBox.addActionListener(createInvertListener());
|
invertBox.addActionListener(createCheckboxListener());
|
||||||
invertBox.setName(mapping.padComp.name());
|
invertBox.setName(mapping.padComp.name());
|
||||||
|
|
||||||
triggerBox.setSelected(mapping.trigger);
|
triggerBox.setSelected(mapping.trigger);
|
||||||
triggerBox.addActionListener(createTriggerListener());
|
triggerBox.addActionListener(createCheckboxListener());
|
||||||
triggerBox.setName(mapping.padComp.name());
|
triggerBox.setName(mapping.padComp.name());
|
||||||
triggerBox.setToolTipText("If this component should act as a trigger. (one-way axis)");
|
triggerBox.setToolTipText("If this component should act as a trigger. (one-way axis)");
|
||||||
|
|
||||||
@@ -142,11 +140,10 @@ public class GamepadConfigFrame extends JFrame {
|
|||||||
return componentBox;
|
return componentBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: make createInvertListener() and createTriggerListener() one method. TOO MUCH COPY PASTA!
|
|
||||||
/*
|
/*
|
||||||
* Creates the listener for the invert checkbox
|
* Creates the listener for the checkbox
|
||||||
*/
|
*/
|
||||||
private ActionListener createInvertListener() {
|
private ActionListener createCheckboxListener() {
|
||||||
return new ActionListener() {
|
return new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
@@ -157,35 +154,13 @@ public class GamepadConfigFrame extends JFrame {
|
|||||||
//this makes more semantic sense to me than using !=
|
//this makes more semantic sense to me than using !=
|
||||||
clicked.setSelected(!(clicked.isSelected()));
|
clicked.setSelected(!(clicked.isSelected()));
|
||||||
} else {
|
} else {
|
||||||
currentMapping.invert = (clicked.isSelected());
|
((GamepadCheckBox)clicked).setValue(currentMapping, clicked.isSelected());
|
||||||
configChanged = true;
|
configChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Creates the listener for the trigger checkbox
|
|
||||||
*/
|
|
||||||
private ActionListener createTriggerListener() {
|
|
||||||
return new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
JCheckBox clicked = (JCheckBox)e.getSource();
|
|
||||||
GamepadComponent padComp = GamepadComponent.valueOf(clicked.getName());
|
|
||||||
Mapping currentMapping = config.get(padComp);
|
|
||||||
if (currentMapping == null) {
|
|
||||||
//this makes more semantic sense to me than using !=
|
|
||||||
clicked.setSelected(!(clicked.isSelected()));
|
|
||||||
} else {
|
|
||||||
currentMapping.trigger = (clicked.isSelected());
|
|
||||||
configChanged = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Creates the listener for the window.
|
* Creates the listener for the window.
|
||||||
* It will save configs on exit and restart controller threads
|
* It will save configs on exit and restart controller threads
|
||||||
@@ -338,4 +313,30 @@ public class GamepadConfigFrame extends JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class GamepadCheckBox extends JCheckBox {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private enum Type { TRIGGER, INVERT }
|
||||||
|
private Type type;
|
||||||
|
|
||||||
|
public GamepadCheckBox(String text, Type type) {
|
||||||
|
super(text);
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(Mapping mapping, boolean value) {
|
||||||
|
switch (type) {
|
||||||
|
case TRIGGER:
|
||||||
|
mapping.trigger = value;
|
||||||
|
break;
|
||||||
|
case INVERT:
|
||||||
|
mapping.invert = value;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.out.println("You did something terrible and should feel terrible.");
|
||||||
|
System.out.println("Fix it or the checkbox gods will smite you!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user