feat: first iteration of gamepad config for mapping buttons
This commit is contained in:
parent
cc8cf8e107
commit
4594d8bd78
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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("<html><h3>Alternative USB controllers</h3><p>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:</html>");
|
||||
}
|
||||
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("<html>Notice the extra buttons <b>left shoulder</b>, <b>right shoulder</b>, <b>left stick</b> and <b>right stick</b>. \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).</html>");
|
||||
}
|
||||
return extraButtonsInfoLabel;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -34,6 +34,11 @@ public class JoystickModel extends AbstractModel
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isPort1()
|
||||
{
|
||||
return this.port1;
|
||||
}
|
||||
|
||||
private void setupKeyKodes()
|
||||
{
|
||||
keyCodeList.add("F1");
|
||||
|
@ -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();
|
||||
}
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
Binary file not shown.
After Width: | Height: | Size: 99 KiB |
Binary file not shown.
After Width: | Height: | Size: 113 KiB |
Loading…
Reference in New Issue