From 4594d8bd785351b7d1817f33b2366f17b0b49ba9 Mon Sep 17 00:00:00 2001 From: lantzelot-swe <75668734+lantzelot-swe@users.noreply.github.com> Date: Fri, 6 Jan 2023 00:16:02 +0100 Subject: [PATCH] feat: first iteration of gamepad config for mapping buttons --- src/main/java/se/lantz/gui/JoystickPanel.java | 32 ++- .../se/lantz/gui/gamepad/GamePadDialog.java | 40 ++++ .../lantz/gui/gamepad/GamePadImagePanel.java | 149 +++++++++++++ .../lantz/gui/gamepad/GamePadInfoPanel.java | 71 ++++++ .../gui/gamepad/GamePadMappingPanel.java | 207 +++++++++++++++++ .../gui/gamepad/GamepadBackgroundPanel.java | 66 ++++++ .../lantz/gui/gamepad/MappingComponent.java | 208 ++++++++++++++++++ .../java/se/lantz/model/JoystickModel.java | 61 ++--- src/main/resources/se/lantz/joystick-comp.png | Bin 0 -> 28502 bytes src/main/resources/se/lantz/logitech.png | Bin 0 -> 101658 bytes src/main/resources/se/lantz/logitech320.png | Bin 0 -> 115260 bytes 11 files changed, 804 insertions(+), 30 deletions(-) create mode 100644 src/main/java/se/lantz/gui/gamepad/GamePadDialog.java create mode 100644 src/main/java/se/lantz/gui/gamepad/GamePadImagePanel.java create mode 100644 src/main/java/se/lantz/gui/gamepad/GamePadInfoPanel.java create mode 100644 src/main/java/se/lantz/gui/gamepad/GamePadMappingPanel.java create mode 100644 src/main/java/se/lantz/gui/gamepad/GamepadBackgroundPanel.java create mode 100644 src/main/java/se/lantz/gui/gamepad/MappingComponent.java create mode 100644 src/main/resources/se/lantz/joystick-comp.png create mode 100644 src/main/resources/se/lantz/logitech.png create mode 100644 src/main/resources/se/lantz/logitech320.png diff --git a/src/main/java/se/lantz/gui/JoystickPanel.java b/src/main/java/se/lantz/gui/JoystickPanel.java index c5afefb..0f6a486 100644 --- a/src/main/java/se/lantz/gui/JoystickPanel.java +++ b/src/main/java/se/lantz/gui/JoystickPanel.java @@ -17,9 +17,12 @@ import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingConstants; +import se.lantz.gui.exports.ExportGamesDialog; +import se.lantz.gui.gamepad.GamePadDialog; import se.lantz.model.JoystickModel; import se.lantz.util.CustomUndoPlainDocument; import se.lantz.util.TextComponentSupport; +import javax.swing.JButton; public class JoystickPanel extends JPanel { @@ -40,6 +43,7 @@ public class JoystickPanel extends JPanel private JoystickModel model; private JPanel configPanel; private JCheckBox mouseCheckBox; + private JButton gamepadButton; public JoystickPanel(int portnumber, JoystickModel model) { @@ -312,18 +316,24 @@ public class JoystickPanel extends JPanel configPanel.setLayout(gbl_configPanel); GridBagConstraints gbc_configLabel = new GridBagConstraints(); gbc_configLabel.anchor = GridBagConstraints.WEST; - gbc_configLabel.insets = new Insets(4, 5, 0, 5); + gbc_configLabel.insets = new Insets(1, 5, 5, 5); gbc_configLabel.gridx = 0; gbc_configLabel.gridy = 0; configPanel.add(getConfigLabel(), gbc_configLabel); GridBagConstraints gbc_configTextField = new GridBagConstraints(); - gbc_configTextField.insets = new Insets(3, 0, 0, 5); + gbc_configTextField.insets = new Insets(3, 0, 5, 0); gbc_configTextField.fill = GridBagConstraints.HORIZONTAL; gbc_configTextField.weightx = 1.0; gbc_configTextField.anchor = GridBagConstraints.NORTHWEST; gbc_configTextField.gridx = 1; gbc_configTextField.gridy = 0; configPanel.add(getConfigTextField(), gbc_configTextField); + GridBagConstraints gbc_gamepadButton = new GridBagConstraints(); + gbc_gamepadButton.anchor = GridBagConstraints.EAST; + gbc_gamepadButton.insets = new Insets(2, 10, 5, 5); + gbc_gamepadButton.gridx = 2; + gbc_gamepadButton.gridy = 0; + configPanel.add(getGamepadButton(), gbc_gamepadButton); } return configPanel; } @@ -338,4 +348,22 @@ public class JoystickPanel extends JPanel } return mouseCheckBox; } + private JButton getGamepadButton() { + if (gamepadButton == null) { + gamepadButton = new JButton("..."); + gamepadButton.setMargin(new Insets(1, 10, 1, 10)); + gamepadButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + final GamePadDialog gamePadDialog = new GamePadDialog(MainWindow.getInstance(), model); + gamePadDialog.pack(); + gamePadDialog.setLocationRelativeTo(getGamepadButton()); + if (gamePadDialog.showDialog()) + { + model.setConfigString(gamePadDialog.getJoyConfigString()); + } + } + }); + } + return gamepadButton; + } } diff --git a/src/main/java/se/lantz/gui/gamepad/GamePadDialog.java b/src/main/java/se/lantz/gui/gamepad/GamePadDialog.java new file mode 100644 index 0000000..b839a9e --- /dev/null +++ b/src/main/java/se/lantz/gui/gamepad/GamePadDialog.java @@ -0,0 +1,40 @@ +package se.lantz.gui.gamepad; + +import java.awt.Dimension; +import java.awt.Frame; + +import se.lantz.gui.BaseDialog; +import se.lantz.model.JoystickModel; + +public class GamePadDialog extends BaseDialog +{ + private GamepadBackgroundPanel panel; + private JoystickModel model; + + public GamePadDialog(Frame owner, JoystickModel model) + { + super(owner); + //Create a separate model so that changes can be cancelled + this.model = new JoystickModel(model.isPort1()); + setTitle("Edit joystick/gamepad configuration"); + addContent(getGamepadBackgroundPanel()); + this.setPreferredSize(new Dimension(660, 770)); + this.setMinimumSize(new Dimension(660, 770)); + //Set initial values to the model + this.model.setConfigStringFromDb(model.getConfigString()); + } + + private GamepadBackgroundPanel getGamepadBackgroundPanel() + { + if (panel == null) + { + panel = new GamepadBackgroundPanel(model); + } + return panel; + } + + public String getJoyConfigString() + { + return this.model.getConfigString(); + } +} diff --git a/src/main/java/se/lantz/gui/gamepad/GamePadImagePanel.java b/src/main/java/se/lantz/gui/gamepad/GamePadImagePanel.java new file mode 100644 index 0000000..3cad40a --- /dev/null +++ b/src/main/java/se/lantz/gui/gamepad/GamePadImagePanel.java @@ -0,0 +1,149 @@ +package se.lantz.gui.gamepad; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.font.TextLayout; +import java.awt.image.BufferedImage; + +import javax.swing.ImageIcon; +import javax.swing.JLabel; +import javax.swing.JPanel; + +import se.lantz.util.FileManager; + +public class GamePadImagePanel extends JPanel +{ + public enum GamePadButton + { + UP("Up", Character.toString(0x1f815)), DOWN("Down", Character.toString(0x1f817)), + LEFT("Left", Character.toString(0x1f814)), RIGHT("Right", Character.toString(0x1f816)), A("A", "A"), B("B", "B"), + X("X", "TR"), Y("Y", "TL"), LEFT_TRIGGER("Left Trigger", "Left Fire"), RIGHT_TRIGGER("Right Trigger", "Right Fire"), + LEFT_SHOULDER("Left Shoulder", "-"), RIGHT_SHOULDER("Right Shoulder", "-"), BACK_GUIDE("Back/Guide", "C"), + LEFT_STICK("Left stick", "-"), RIGHT_STICK("Right stick", "-"); + + public final String label; + public final String joyMapping; + + private GamePadButton(String label, String joyMapping) + { + this.label = label; + this.joyMapping = joyMapping; + } + } + + ImageIcon gamepadImage = new ImageIcon(getClass().getResource("/se/lantz/logitech320.png")); + private JLabel imageLabel; + + private GamePadButton currentButton = null; + + public GamePadImagePanel() + { + GridBagLayout gridBagLayout = new GridBagLayout(); + setLayout(gridBagLayout); + GridBagConstraints gbc_imageLabel = new GridBagConstraints(); + gbc_imageLabel.insets = new Insets(20, 0, 0, 0); + gbc_imageLabel.weightx = 1.0; + gbc_imageLabel.weighty = 1.0; + gbc_imageLabel.anchor = GridBagConstraints.NORTH; + gbc_imageLabel.gridx = 0; + gbc_imageLabel.gridy = 0; + add(getImageLabel(), gbc_imageLabel); + } + + private JLabel getImageLabel() + { + if (imageLabel == null) + { + imageLabel = new JLabel() + { + + @Override + protected void paintComponent(Graphics g) + { + super.paintComponent(g); + //Draw for currently focused button + drawForButton(g); + } + + }; + imageLabel.setIcon(gamepadImage); + } + return imageLabel; + } + + public void setCurrentButtonAndRepaint(GamePadButton button) + { + this.currentButton = button; + this.repaint(); + } + + private void drawForButton(Graphics g) + { + if (currentButton == null) + { + return; + } + + Graphics2D graphics2D = (Graphics2D) g; + graphics2D.setStroke(new BasicStroke(3.0f)); + graphics2D.setColor(Color.red); + + switch (currentButton) + { + case UP: + //Oval around dpad + graphics2D.drawOval(52, 55, 51, 51); + //up + graphics2D.fillRect(72, 57, 12, 20); + break; + case A: + break; + case B: + break; + case BACK_GUIDE: + break; + case DOWN: + //Oval around dpad + graphics2D.drawOval(52, 55, 51, 51); + //down + graphics2D.fillRect(72, 85, 12, 20); + break; + case LEFT: + //Oval around dpad + graphics2D.drawOval(52, 55, 51, 51); + //Left + graphics2D.fillRect(54, 75, 20, 12); + break; + case LEFT_SHOULDER: + break; + case LEFT_STICK: + break; + case LEFT_TRIGGER: + break; + case RIGHT: + //Oval around dpad + graphics2D.drawOval(52, 55, 51, 51); + //right + graphics2D.fillRect(82, 75, 20, 12); + break; + case RIGHT_SHOULDER: + break; + case RIGHT_STICK: + break; + case RIGHT_TRIGGER: + break; + case X: + break; + case Y: + break; + default: + break; + } + } +} diff --git a/src/main/java/se/lantz/gui/gamepad/GamePadInfoPanel.java b/src/main/java/se/lantz/gui/gamepad/GamePadInfoPanel.java new file mode 100644 index 0000000..b9ccf91 --- /dev/null +++ b/src/main/java/se/lantz/gui/gamepad/GamePadInfoPanel.java @@ -0,0 +1,71 @@ +package se.lantz.gui.gamepad; + +import java.awt.LayoutManager; + +import javax.swing.JPanel; +import java.awt.GridBagLayout; + +import javax.swing.ImageIcon; +import javax.swing.JLabel; +import java.awt.GridBagConstraints; +import java.awt.Insets; +import java.awt.Color; + +public class GamePadInfoPanel extends JPanel +{ + ImageIcon compImage = new ImageIcon(getClass().getResource("/se/lantz/joystick-comp.png")); + + private JLabel infoLabel; + private JLabel compImageLabel; + private JLabel extraButtonsInfoLabel; + + public GamePadInfoPanel() + { + setBackground(Color.WHITE); + GridBagLayout gridBagLayout = new GridBagLayout(); + setLayout(gridBagLayout); + GridBagConstraints gbc_infoLabel = new GridBagConstraints(); + gbc_infoLabel.fill = GridBagConstraints.HORIZONTAL; + gbc_infoLabel.weightx = 1.0; + gbc_infoLabel.insets = new Insets(0, 10, 0, 10); + gbc_infoLabel.gridx = 0; + gbc_infoLabel.gridy = 0; + add(getInfoLabel(), gbc_infoLabel); + GridBagConstraints gbc_compImageLabel = new GridBagConstraints(); + gbc_compImageLabel.insets = new Insets(0, 0, 5, 0); + gbc_compImageLabel.weighty = 1.0; + gbc_compImageLabel.weightx = 1.0; + gbc_compImageLabel.gridx = 0; + gbc_compImageLabel.gridy = 1; + add(getCompImageLabel(), gbc_compImageLabel); + GridBagConstraints gbc_extraButtonsInfoLabel = new GridBagConstraints(); + gbc_extraButtonsInfoLabel.insets = new Insets(0, 10, 10, 10); + gbc_extraButtonsInfoLabel.fill = GridBagConstraints.HORIZONTAL; + gbc_extraButtonsInfoLabel.gridx = 0; + gbc_extraButtonsInfoLabel.gridy = 2; + add(getExtraButtonsInfoLabel(), gbc_extraButtonsInfoLabel); + // TODO Auto-generated constructor stub + } + private JLabel getInfoLabel() { + if (infoLabel == null) { + infoLabel = new JLabel("
THEC64/THEVIC20 is compatible with a wide range of other modern USB controllers, which you use as either the primary or the secondary controller, where applicable. They need to have a minimum of eight buttons to be able to replicate the joystick’s full functionality. Using standard modern USB controller terms, joystick functions translate as follows:");
+ }
+ return infoLabel;
+ }
+ private JLabel getCompImageLabel() {
+ if (compImageLabel == null) {
+ compImageLabel = new JLabel();
+ compImageLabel.setBackground(Color.WHITE);
+ compImageLabel.setIcon(compImage);
+ }
+ return compImageLabel;
+ }
+ private JLabel getExtraButtonsInfoLabel() {
+ if (extraButtonsInfoLabel == null) {
+ extraButtonsInfoLabel = new JLabel("Notice the extra buttons left shoulder, right shoulder, left stick and right stick. \r\n" +
+ "They are not available on the joystick but are common on alternative USB controllers. \r\n" +
+ "The latter two are for controllers with two sticks that press down for additional button functions. It’s up to you what you map to those buttons (if anything).");
+ }
+ return extraButtonsInfoLabel;
+ }
+}
diff --git a/src/main/java/se/lantz/gui/gamepad/GamePadMappingPanel.java b/src/main/java/se/lantz/gui/gamepad/GamePadMappingPanel.java
new file mode 100644
index 0000000..489d610
--- /dev/null
+++ b/src/main/java/se/lantz/gui/gamepad/GamePadMappingPanel.java
@@ -0,0 +1,207 @@
+package se.lantz.gui.gamepad;
+
+import java.awt.GridBagLayout;
+
+import javax.swing.JPanel;
+import se.lantz.gui.gamepad.GamePadImagePanel.GamePadButton;
+import se.lantz.model.JoystickModel;
+import java.awt.GridBagConstraints;
+import java.awt.Insets;
+
+public class GamePadMappingPanel extends JPanel
+{
+ private MappingComponent upComponent;
+ private JoystickModel model;
+ private MappingComponent downComponent;
+ private MappingComponent leftComponent;
+ private MappingComponent rightComponent;
+ private MappingComponent xComponent;
+ private MappingComponent yComponent;
+ private MappingComponent aComponent;
+ private MappingComponent bComponent;
+ private MappingComponent leftTriggerComponent;
+ private MappingComponent rightTriggerComponent;
+ private MappingComponent backGuideComponent;
+ private MappingComponent leftShoulderComponent;
+ private MappingComponent rightShoulderComponent;
+ private MappingComponent leftStickComponent;
+ private MappingComponent rightStickComponent;
+ private GamePadImagePanel imagePanel;
+
+ public GamePadMappingPanel(JoystickModel model, GamePadImagePanel imagePanel)
+ {
+ this.model = model;
+ this.imagePanel = imagePanel;
+ GridBagLayout gridBagLayout = new GridBagLayout();
+ gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0};
+ gridBagLayout.columnWeights = new double[]{1.0, 1.0};
+ setLayout(gridBagLayout);
+ GridBagConstraints gbc_upComponent = new GridBagConstraints();
+ gbc_upComponent.fill = GridBagConstraints.BOTH;
+ gbc_upComponent.gridx = 0;
+ gbc_upComponent.gridy = 0;
+ add(getUpComponent(), gbc_upComponent);
+ GridBagConstraints gbc_downgComponent = new GridBagConstraints();
+ gbc_downgComponent.fill = GridBagConstraints.BOTH;
+ gbc_downgComponent.gridx = 0;
+ gbc_downgComponent.gridy = 1;
+ add(getDowngComponent(), gbc_downgComponent);
+ GridBagConstraints gbc_leftComponent = new GridBagConstraints();
+ gbc_leftComponent.fill = GridBagConstraints.BOTH;
+ gbc_leftComponent.gridx = 0;
+ gbc_leftComponent.gridy = 2;
+ add(getMappingComponent_2(), gbc_leftComponent);
+ GridBagConstraints gbc_rightComponent = new GridBagConstraints();
+ gbc_rightComponent.fill = GridBagConstraints.BOTH;
+ gbc_rightComponent.gridx = 0;
+ gbc_rightComponent.gridy = 3;
+ add(getRightComponent(), gbc_rightComponent);
+ GridBagConstraints gbc_xComponent = new GridBagConstraints();
+ gbc_xComponent.fill = GridBagConstraints.BOTH;
+ gbc_xComponent.gridx = 1;
+ gbc_xComponent.gridy = 2;
+ add(getXComponent(), gbc_xComponent);
+ GridBagConstraints gbc_yComponent = new GridBagConstraints();
+ gbc_yComponent.fill = GridBagConstraints.BOTH;
+ gbc_yComponent.gridx = 1;
+ gbc_yComponent.gridy = 3;
+ add(getYComponent(), gbc_yComponent);
+ GridBagConstraints gbc_aComponent = new GridBagConstraints();
+ gbc_aComponent.fill = GridBagConstraints.BOTH;
+ gbc_aComponent.gridx = 1;
+ gbc_aComponent.gridy = 0;
+ add(getAComponent(), gbc_aComponent);
+ GridBagConstraints gbc_bComponent = new GridBagConstraints();
+ gbc_bComponent.fill = GridBagConstraints.BOTH;
+ gbc_bComponent.gridx = 1;
+ gbc_bComponent.gridy = 1;
+ add(getBComponent(), gbc_bComponent);
+ GridBagConstraints gbc_leftTriggerComponent = new GridBagConstraints();
+ gbc_leftTriggerComponent.fill = GridBagConstraints.BOTH;
+ gbc_leftTriggerComponent.gridx = 0;
+ gbc_leftTriggerComponent.gridy = 4;
+ add(getLeftTriggerComponent(), gbc_leftTriggerComponent);
+ GridBagConstraints gbc_rightTriggerComponent = new GridBagConstraints();
+ gbc_rightTriggerComponent.fill = GridBagConstraints.BOTH;
+ gbc_rightTriggerComponent.gridx = 1;
+ gbc_rightTriggerComponent.gridy = 4;
+ add(getRightTriggerComponent(), gbc_rightTriggerComponent);
+ GridBagConstraints gbc_backGuideComponent = new GridBagConstraints();
+ gbc_backGuideComponent.fill = GridBagConstraints.BOTH;
+ gbc_backGuideComponent.gridx = 0;
+ gbc_backGuideComponent.gridy = 5;
+ add(getBackGuideComponent(), gbc_backGuideComponent);
+ GridBagConstraints gbc_leftStickComponent = new GridBagConstraints();
+ gbc_leftStickComponent.anchor = GridBagConstraints.NORTHWEST;
+ gbc_leftStickComponent.fill = GridBagConstraints.HORIZONTAL;
+ gbc_leftStickComponent.gridx = 0;
+ gbc_leftStickComponent.gridy = 7;
+ add(getLeftStickComponent(), gbc_leftStickComponent);
+ GridBagConstraints gbc_leftShoulderComponent = new GridBagConstraints();
+ gbc_leftShoulderComponent.fill = GridBagConstraints.BOTH;
+ gbc_leftShoulderComponent.gridx = 0;
+ gbc_leftShoulderComponent.gridy = 6;
+ add(getLeftShoulderComponent(), gbc_leftShoulderComponent);
+ GridBagConstraints gbc_rightShoulderComponent = new GridBagConstraints();
+ gbc_rightShoulderComponent.fill = GridBagConstraints.BOTH;
+ gbc_rightShoulderComponent.gridx = 1;
+ gbc_rightShoulderComponent.gridy = 6;
+ add(getRightShoulderComponent(), gbc_rightShoulderComponent);
+ GridBagConstraints gbc_rightStickComponent = new GridBagConstraints();
+ gbc_rightStickComponent.anchor = GridBagConstraints.NORTHWEST;
+ gbc_rightStickComponent.fill = GridBagConstraints.HORIZONTAL;
+ gbc_rightStickComponent.gridx = 1;
+ gbc_rightStickComponent.gridy = 7;
+ add(getRightStickComponent(), gbc_rightStickComponent);
+ }
+ private MappingComponent getUpComponent() {
+ if (upComponent == null) {
+ upComponent = new MappingComponent(GamePadButton.UP, model, imagePanel);
+ }
+ return upComponent;
+ }
+ private MappingComponent getDowngComponent() {
+ if (downComponent == null) {
+ downComponent = new MappingComponent(GamePadButton.DOWN, model, imagePanel);
+ }
+ return downComponent;
+ }
+ private MappingComponent getMappingComponent_2() {
+ if (leftComponent == null) {
+ leftComponent = new MappingComponent(GamePadButton.LEFT, model, imagePanel);
+ }
+ return leftComponent;
+ }
+ private MappingComponent getRightComponent() {
+ if (rightComponent == null) {
+ rightComponent = new MappingComponent(GamePadButton.RIGHT, model, imagePanel);
+ }
+ return rightComponent;
+ }
+ private MappingComponent getXComponent() {
+ if (xComponent == null) {
+ xComponent = new MappingComponent(GamePadButton.X, model, imagePanel);
+ }
+ return xComponent;
+ }
+ private MappingComponent getYComponent() {
+ if (yComponent == null) {
+ yComponent = new MappingComponent(GamePadButton.Y, model, imagePanel);
+ }
+ return yComponent;
+ }
+ private MappingComponent getAComponent() {
+ if (aComponent == null) {
+ aComponent = new MappingComponent(GamePadButton.A, model, imagePanel);
+ }
+ return aComponent;
+ }
+ private MappingComponent getBComponent() {
+ if (bComponent == null) {
+ bComponent = new MappingComponent(GamePadButton.B, model, imagePanel);
+ }
+ return bComponent;
+ }
+ private MappingComponent getLeftTriggerComponent() {
+ if (leftTriggerComponent == null) {
+ leftTriggerComponent = new MappingComponent(GamePadButton.LEFT_TRIGGER, model, imagePanel);
+ }
+ return leftTriggerComponent;
+ }
+ private MappingComponent getRightTriggerComponent() {
+ if (rightTriggerComponent == null) {
+ rightTriggerComponent = new MappingComponent(GamePadButton.RIGHT_TRIGGER, model, imagePanel);
+ }
+ return rightTriggerComponent;
+ }
+ private MappingComponent getBackGuideComponent() {
+ if (backGuideComponent == null) {
+ backGuideComponent = new MappingComponent(GamePadButton.BACK_GUIDE, model, imagePanel);
+ }
+ return backGuideComponent;
+ }
+ private MappingComponent getLeftShoulderComponent() {
+ if (leftShoulderComponent == null) {
+ leftShoulderComponent = new MappingComponent(GamePadButton.LEFT_SHOULDER, model, imagePanel);
+ }
+ return leftShoulderComponent;
+ }
+ private MappingComponent getRightShoulderComponent() {
+ if (rightShoulderComponent == null) {
+ rightShoulderComponent = new MappingComponent(GamePadButton.RIGHT_SHOULDER, model, imagePanel);
+ }
+ return rightShoulderComponent;
+ }
+ private MappingComponent getLeftStickComponent() {
+ if (leftStickComponent == null) {
+ leftStickComponent = new MappingComponent(GamePadButton.LEFT_STICK, model, imagePanel);
+ }
+ return leftStickComponent;
+ }
+ private MappingComponent getRightStickComponent() {
+ if (rightStickComponent == null) {
+ rightStickComponent = new MappingComponent(GamePadButton.RIGHT_STICK, model, imagePanel);
+ }
+ return rightStickComponent;
+ }
+}
diff --git a/src/main/java/se/lantz/gui/gamepad/GamepadBackgroundPanel.java b/src/main/java/se/lantz/gui/gamepad/GamepadBackgroundPanel.java
new file mode 100644
index 0000000..495790a
--- /dev/null
+++ b/src/main/java/se/lantz/gui/gamepad/GamepadBackgroundPanel.java
@@ -0,0 +1,66 @@
+package se.lantz.gui.gamepad;
+
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+
+import javax.swing.JPanel;
+
+import se.lantz.model.JoystickModel;
+
+public class GamepadBackgroundPanel extends JPanel
+{
+ private GamePadInfoPanel gamePadInfoPanel;
+ private GamePadImagePanel gamePadImagePanel;
+ private GamePadMappingPanel gamePadMappingPanel;
+ private JoystickModel model;
+ public GamepadBackgroundPanel(JoystickModel model) {
+ this.model = model;
+ GridBagLayout gridBagLayout = new GridBagLayout();
+ setLayout(gridBagLayout);
+ GridBagConstraints gbc_gamePadInfoPanel = new GridBagConstraints();
+ gbc_gamePadInfoPanel.gridwidth = 2;
+ gbc_gamePadInfoPanel.insets = new Insets(0, 0, 5, 0);
+ gbc_gamePadInfoPanel.anchor = GridBagConstraints.NORTHWEST;
+ gbc_gamePadInfoPanel.weightx = 1.0;
+ gbc_gamePadInfoPanel.fill = GridBagConstraints.BOTH;
+ gbc_gamePadInfoPanel.gridx = 0;
+ gbc_gamePadInfoPanel.gridy = 0;
+ add(getGamePadInfoPanel(), gbc_gamePadInfoPanel);
+ GridBagConstraints gbc_gamePadImagePanel = new GridBagConstraints();
+ gbc_gamePadImagePanel.anchor = GridBagConstraints.NORTHWEST;
+ gbc_gamePadImagePanel.insets = new Insets(0, 0, 5, 10);
+ gbc_gamePadImagePanel.weightx = 1.0;
+ gbc_gamePadImagePanel.fill = GridBagConstraints.BOTH;
+ gbc_gamePadImagePanel.gridx = 1;
+ gbc_gamePadImagePanel.gridy = 1;
+ add(getGamePadImagePanel(), gbc_gamePadImagePanel);
+ GridBagConstraints gbc_gamePadMappingPanel = new GridBagConstraints();
+ gbc_gamePadMappingPanel.insets = new Insets(0, 10, 0, 0);
+ gbc_gamePadMappingPanel.weighty = 1.0;
+ gbc_gamePadMappingPanel.weightx = 1.0;
+ gbc_gamePadMappingPanel.anchor = GridBagConstraints.NORTHWEST;
+ gbc_gamePadMappingPanel.fill = GridBagConstraints.BOTH;
+ gbc_gamePadMappingPanel.gridx = 0;
+ gbc_gamePadMappingPanel.gridy = 1;
+ add(getGamePadMappingPanel(), gbc_gamePadMappingPanel);
+ }
+ private GamePadInfoPanel getGamePadInfoPanel() {
+ if (gamePadInfoPanel == null) {
+ gamePadInfoPanel = new GamePadInfoPanel();
+ }
+ return gamePadInfoPanel;
+ }
+ private GamePadImagePanel getGamePadImagePanel() {
+ if (gamePadImagePanel == null) {
+ gamePadImagePanel = new GamePadImagePanel();
+ }
+ return gamePadImagePanel;
+ }
+ private GamePadMappingPanel getGamePadMappingPanel() {
+ if (gamePadMappingPanel == null) {
+ gamePadMappingPanel = new GamePadMappingPanel(model, getGamePadImagePanel());
+ }
+ return gamePadMappingPanel;
+ }
+}
diff --git a/src/main/java/se/lantz/gui/gamepad/MappingComponent.java b/src/main/java/se/lantz/gui/gamepad/MappingComponent.java
new file mode 100644
index 0000000..dc1bf5b
--- /dev/null
+++ b/src/main/java/se/lantz/gui/gamepad/MappingComponent.java
@@ -0,0 +1,208 @@
+package se.lantz.gui.gamepad;
+
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.beans.Beans;
+
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+import se.lantz.gui.KeySelectionComboBox;
+import se.lantz.gui.gamepad.GamePadImagePanel.GamePadButton;
+import se.lantz.model.JoystickModel;
+
+public class MappingComponent extends JPanel
+{
+ private JLabel buttonTextLabel;
+ private KeySelectionComboBox keySelectionComboBox;
+ private JLabel joyMapLabel;
+ private GamePadButton button;
+ private JoystickModel model;
+ private GamePadImagePanel imagePanel;
+
+ public MappingComponent(GamePadButton button, JoystickModel model, GamePadImagePanel imagePanel)
+ {
+ this.button = button;
+ this.model = model;
+ this.imagePanel = imagePanel;
+ GridBagLayout gridBagLayout = new GridBagLayout();
+ setLayout(gridBagLayout);
+ GridBagConstraints gbc_buttonTextLabel = new GridBagConstraints();
+ gbc_buttonTextLabel.anchor = GridBagConstraints.WEST;
+ gbc_buttonTextLabel.insets = new Insets(5, 5, 0, 5);
+ gbc_buttonTextLabel.gridx = 0;
+ gbc_buttonTextLabel.gridy = 0;
+ add(getButtonTextLabel(), gbc_buttonTextLabel);
+ GridBagConstraints gbc_keySelectionComboBox = new GridBagConstraints();
+ gbc_keySelectionComboBox.weighty = 1.0;
+ gbc_keySelectionComboBox.gridwidth = 2;
+ gbc_keySelectionComboBox.insets = new Insets(0, 4, 5, 5);
+ gbc_keySelectionComboBox.anchor = GridBagConstraints.NORTHWEST;
+ gbc_keySelectionComboBox.gridx = 0;
+ gbc_keySelectionComboBox.gridy = 1;
+ add(getKeySelectionComboBox(), gbc_keySelectionComboBox);
+ GridBagConstraints gbc_joyMapLabel = new GridBagConstraints();
+ gbc_joyMapLabel.anchor = GridBagConstraints.WEST;
+ gbc_joyMapLabel.weightx = 1.0;
+ gbc_joyMapLabel.insets = new Insets(5, 0, 0, 5);
+ gbc_joyMapLabel.gridx = 1;
+ gbc_joyMapLabel.gridy = 0;
+ add(getJoyMapLabel(), gbc_joyMapLabel);
+
+ if (!Beans.isDesignTime())
+ {
+ model.addPropertyChangeListener((e) -> modelChanged());
+ }
+ }
+
+ private void modelChanged()
+ {
+ switch (button)
+ {
+ case UP:
+ getKeySelectionComboBox().setSelectedCode(model.getUp());
+ break;
+ case A:
+ getKeySelectionComboBox().setSelectedCode(model.getA());
+ break;
+ case B:
+ getKeySelectionComboBox().setSelectedCode(model.getB());
+ break;
+ case BACK_GUIDE:
+ getKeySelectionComboBox().setSelectedCode(model.getC());
+ break;
+ case DOWN:
+ getKeySelectionComboBox().setSelectedCode(model.getDown());
+ break;
+ case LEFT:
+ getKeySelectionComboBox().setSelectedCode(model.getLeft());
+ break;
+ case LEFT_SHOULDER:
+ getKeySelectionComboBox().setSelectedCode(model.getLeftShoulder());
+ break;
+ case LEFT_STICK:
+ getKeySelectionComboBox().setSelectedCode(model.getLeftStick());
+ break;
+ case LEFT_TRIGGER:
+ getKeySelectionComboBox().setSelectedCode(model.getLeftFire());
+ break;
+ case RIGHT:
+ getKeySelectionComboBox().setSelectedCode(model.getRight());
+ break;
+ case RIGHT_SHOULDER:
+ getKeySelectionComboBox().setSelectedCode(model.getRightShoulder());
+ break;
+ case RIGHT_STICK:
+ getKeySelectionComboBox().setSelectedCode(model.getRightStick());
+ break;
+ case RIGHT_TRIGGER:
+ getKeySelectionComboBox().setSelectedCode(model.getRightFire());
+ break;
+ case X:
+ getKeySelectionComboBox().setSelectedCode(model.getTr());
+ break;
+ case Y:
+ getKeySelectionComboBox().setSelectedCode(model.getTl());
+ break;
+ default:
+ break;
+ }
+ }
+
+ private JLabel getButtonTextLabel()
+ {
+ if (buttonTextLabel == null)
+ {
+ buttonTextLabel = new JLabel(button.label);
+ }
+ return buttonTextLabel;
+ }
+
+ private KeySelectionComboBox getKeySelectionComboBox()
+ {
+ if (keySelectionComboBox == null)
+ {
+ keySelectionComboBox = new KeySelectionComboBox(model);
+ keySelectionComboBox.addActionListener(e -> {
+ switch (button)
+ {
+ case UP:
+ model.setUp(keySelectionComboBox.getSelectedCode());
+ break;
+ case A:
+ model.setA(keySelectionComboBox.getSelectedCode());
+ break;
+ case B:
+ model.setB(keySelectionComboBox.getSelectedCode());
+ break;
+ case BACK_GUIDE:
+ model.setC(keySelectionComboBox.getSelectedCode());
+ break;
+ case DOWN:
+ model.setDown(keySelectionComboBox.getSelectedCode());
+ break;
+ case LEFT:
+ model.setLeft(keySelectionComboBox.getSelectedCode());
+ break;
+ case LEFT_SHOULDER:
+ model.setLeftShoulder(keySelectionComboBox.getSelectedCode());
+ break;
+ case LEFT_STICK:
+ model.setLeftStick(keySelectionComboBox.getSelectedCode());
+ break;
+ case LEFT_TRIGGER:
+ model.setLeftFire(keySelectionComboBox.getSelectedCode());
+ break;
+ case RIGHT:
+ model.setRight(keySelectionComboBox.getSelectedCode());
+ break;
+ case RIGHT_SHOULDER:
+ model.setRightShoulder(keySelectionComboBox.getSelectedCode());
+ break;
+ case RIGHT_STICK:
+ model.setRightStick(keySelectionComboBox.getSelectedCode());
+ break;
+ case RIGHT_TRIGGER:
+ model.setRightFire(keySelectionComboBox.getSelectedCode());
+ break;
+ case X:
+ model.setTr(keySelectionComboBox.getSelectedCode());
+ break;
+ case Y:
+ model.setTl(keySelectionComboBox.getSelectedCode());
+ break;
+ default:
+ break;
+ }
+ });
+ keySelectionComboBox.addMouseListener(new MouseAdapter()
+ {
+ @Override
+ public void mouseExited(MouseEvent e)
+ {
+ imagePanel.setCurrentButtonAndRepaint(null);
+ }
+
+ @Override
+ public void mouseEntered(MouseEvent me)
+ {
+ imagePanel.setCurrentButtonAndRepaint(button);
+ }
+ });
+ }
+ return keySelectionComboBox;
+ }
+
+ private JLabel getJoyMapLabel()
+ {
+ if (joyMapLabel == null)
+ {
+ joyMapLabel = new JLabel("(" + button.joyMapping + ")");
+ }
+ return joyMapLabel;
+ }
+
+}
diff --git a/src/main/java/se/lantz/model/JoystickModel.java b/src/main/java/se/lantz/model/JoystickModel.java
index cf49fce..685e0d3 100644
--- a/src/main/java/se/lantz/model/JoystickModel.java
+++ b/src/main/java/se/lantz/model/JoystickModel.java
@@ -33,6 +33,11 @@ public class JoystickModel extends AbstractModel
configList.add("");
}
}
+
+ public boolean isPort1()
+ {
+ return this.port1;
+ }
private void setupKeyKodes()
{
@@ -201,13 +206,13 @@ public class JoystickModel extends AbstractModel
setRightFire("");
setTl("");
setTr("");
- setUnused1("");
+ setLeftShoulder("");
setA("");
setB("");
setC("");
- setUnused2("");
- setUnused3("");
- setUnused4("");
+ setRightShoulder("");
+ setLeftStick("");
+ setRightStick("");
this.latestConfigString = configString;
}
else
@@ -244,13 +249,13 @@ public class JoystickModel extends AbstractModel
setRightFire(newConfigList.get(5));
setTl(newConfigList.get(6));
setTr(newConfigList.get(7));
- setUnused1(newConfigList.get(8));
+ setLeftShoulder(newConfigList.get(8));
setA(newConfigList.get(9));
setB(newConfigList.get(10));
setC(newConfigList.get(11));
- setUnused2(newConfigList.get(12));
- setUnused3(newConfigList.get(13));
- setUnused4(newConfigList.get(14));
+ setRightShoulder(newConfigList.get(12));
+ setLeftStick(newConfigList.get(13));
+ setRightStick(newConfigList.get(14));
this.latestConfigString = configString;
}
disableChangeNotification(false);
@@ -377,16 +382,16 @@ public class JoystickModel extends AbstractModel
}
}
- public String getUnused1()
+ public String getLeftShoulder()
{
return configList.get(8);
}
- public void setUnused1(String unused1)
+ public void setLeftShoulder(String leftShoulder)
{
- String old = getUnused1();
- configList.set(8, unused1);
- if (!Objects.equals(old, unused1))
+ String old = getLeftShoulder();
+ configList.set(8, leftShoulder);
+ if (!Objects.equals(old, leftShoulder))
{
notifyChange();
}
@@ -437,46 +442,46 @@ public class JoystickModel extends AbstractModel
}
}
- public String getUnused2()
+ public String getRightShoulder()
{
return configList.get(12);
}
- public void setUnused2(String unused2)
+ public void setRightShoulder(String rightShoulder)
{
- String old = getUnused2();
- configList.set(12, unused2);
- if (!Objects.equals(old, unused2))
+ String old = getRightShoulder();
+ configList.set(12, rightShoulder);
+ if (!Objects.equals(old, rightShoulder))
{
notifyChange();
}
}
- public String getUnused3()
+ public String getLeftStick()
{
return configList.get(13);
}
- public void setUnused3(String unused3)
+ public void setLeftStick(String leftStick)
{
- String old = getUnused3();
- configList.set(13, unused3);
- if (!Objects.equals(old, unused3))
+ String old = getLeftStick();
+ configList.set(13, leftStick);
+ if (!Objects.equals(old, leftStick))
{
notifyChange();
}
}
- public String getUnused4()
+ public String getRightStick()
{
return configList.get(14);
}
- public void setUnused4(String unused4)
+ public void setRightStick(String rightStick)
{
- String old = getUnused4();
- configList.set(14, unused4);
- if (!Objects.equals(old, unused4))
+ String old = getRightStick();
+ configList.set(14, rightStick);
+ if (!Objects.equals(old, rightStick))
{
notifyChange();
}
diff --git a/src/main/resources/se/lantz/joystick-comp.png b/src/main/resources/se/lantz/joystick-comp.png
new file mode 100644
index 0000000000000000000000000000000000000000..7b628cdcf29283d7d150bdc9f2e2214f5b182467
GIT binary patch
literal 28502
zcmZ^qbC4!M)8NOpZQI5^W82n_xx<~AXKe4-wr9t-ZQHhW`+j$E7k6LWAKjgm(GlHQ
zU6on&%g%5m1xZ9WJU9>#5JYJyF%=LH(8qsr4-C}5Ghx_U`@ajQvx=k$Nc9xK>Awbq
z1wbAE0#X+X|6vUIuMO)crR@v?g4F+?19aG-)C>f~{#;rNpypw4xe2Ma@IefHgDgoN
z0sDp7j;RI#0I=4f1C&wV+u!T>iQntMA;eI1S!-F95fI{%lTl82TG~IGH *!?j=rw!BDW8Sg
zy7DU;yMHs&xk#7L)lRR$Rlb4v<&>! AyFZn5gqZzCV
zY;NtGJ9oa>XeW}%7;|*p_={>Th``FzNe?Fnr+a{ s!@lL?HAUWMy-2aq}#iA0l`XfRz~?>0*v
z{qR?Qv2gTwTbz+#(4Hps&}`DFNuvXZhFL%h72CTx_E^U_xU_`XL|0EoNkj#(h7l8b
z5OiR&C?_ei!MN&o4tr>QGC(T9uMQGgDhwe;un}O?@F^aPVfR2x;~$T0KQJ%`v(GLn
z4rGwGZY{s|+Ushl-!JX%5 ~LO%YXSV
z|KeNUg0>Gl_~1YJC;x=#7d2oud+M#XzWn7cPtQzKQN#jV^lnGY9<5(|_g&mE>O=uI
z1e#~Uef|24x6hwPMX@F1)3Y@q>qjC+=o|?jIdb%Y`|nStk~B!{ed^R{v~h895i9K2
zG@0YL#<6O+igv3#=;;YWO$&8TOTSD?Im#gRiFiE3>@|$7k76z=!sA2Z0b8
z*zRJBgApxsQ#u@sgkq6!D3^|9QVI7fGm)9wQ4W?cz>>1l6b>Gn~yMWJB2hsimLbO0do|%q(
zzxFe?qwhP^bZo{vbOAzoqa{PO;ZESX=2m1yG*A8k1O*%$$_cSZj=@8#@;r
pcZY{*n#yL^~8(eDn
z-wG58|F-ph!*;g0O1j7);6nM6_@JAc2@+q=;S^+%&=FDLl$Vw7UG+on1^tqUxTOwk
zD{6&QQBhGUiZ}>GM}biG3=$zN{4G#eTm+B~e`uiy+dxA{&(kYIvn5n;qCFfZMm~FM
z^HkE*44of@*Ms|)U6HZ0r15m&95^Ubt#erw)}sTUXv;-MqoNY|moRU%B;EywpBBnz
z{ioc54hC)EKcyD=0VIppkVbBbDrENpr)EcpDLMjkY;2`^t#^j&*`or;*;e&3^74$g
zU5S5^f@Lr
#Y`KKkv`SUny4ec|$hdj&;M`qIN2
z6ig?q)
#$!dGVe
zgC5+LiXsL5QKQk`DV0`N*M9oq&;Nh_;$NM+aLF;6xXA12vjl$$JRyX;c5CJT_5c3=
zT)ld&kKT+3JH3fJGX!lmKZm@*V3=t;xgli*ebPV~Pvamw7&((;OErzZ`8D7_sg!mp
z6pv#!Bax{7m^NZ!t)KywofY-q!^m}8q0eCgA3`s<3dJmLF;Bn=tQB{CzOC)ufA**U
z{6|0ic`}v4oQj1MU~1