mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-06-15 21:31:12 +00:00
Work in progress: fixing gamepad to work on all OSs and be customizable
This commit is contained in:
@@ -0,0 +1,113 @@
|
|||||||
|
package com.limelight.gui;
|
||||||
|
|
||||||
|
import java.awt.Container;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Toolkit;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
import javax.swing.Box;
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
|
||||||
|
import net.java.games.input.Component;
|
||||||
|
import net.java.games.input.Event;
|
||||||
|
import net.java.games.input.EventQueue;
|
||||||
|
|
||||||
|
import com.limelight.input.ControllerComponent;
|
||||||
|
import com.limelight.input.Gamepad;
|
||||||
|
import com.limelight.input.GamepadHandler;
|
||||||
|
import com.limelight.input.GamepadSettings;
|
||||||
|
|
||||||
|
public class SettingsFrame extends JFrame {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public SettingsFrame() {
|
||||||
|
super("Limelight Settings");
|
||||||
|
this.setSize(800, 500);
|
||||||
|
this.setResizable(false);
|
||||||
|
this.setAlwaysOnTop(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void build() {
|
||||||
|
Container c = this.getContentPane();
|
||||||
|
JPanel mainPanel = new JPanel();
|
||||||
|
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.X_AXIS));
|
||||||
|
|
||||||
|
Box leftColumn = Box.createVerticalBox();
|
||||||
|
Box rightColumn = Box.createVerticalBox();
|
||||||
|
|
||||||
|
leftColumn.add(Box.createVerticalStrut(10));
|
||||||
|
rightColumn.add(Box.createVerticalStrut(10));
|
||||||
|
|
||||||
|
|
||||||
|
ControllerComponent[] components = ControllerComponent.values();
|
||||||
|
for (int i = 0; i < components.length; i++) {
|
||||||
|
Box componentBox = Box.createHorizontalBox();
|
||||||
|
|
||||||
|
componentBox.add(Box.createHorizontalStrut(10));
|
||||||
|
componentBox.add(components[i].getLabel());
|
||||||
|
componentBox.add(Box.createHorizontalGlue());
|
||||||
|
componentBox.add(components[i].getTextField());
|
||||||
|
componentBox.add(Box.createHorizontalStrut(10));
|
||||||
|
components[i].getTextField().setColumns(10);
|
||||||
|
components[i].getTextField().setMaximumSize(new Dimension(50, 30));
|
||||||
|
components[i].getTextField().addActionListener(createListener());
|
||||||
|
if (i > components.length / 2) {
|
||||||
|
rightColumn.add(componentBox);
|
||||||
|
if (i < components.length - 1) {
|
||||||
|
rightColumn.add(Box.createVerticalStrut(5));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
leftColumn.add(componentBox);
|
||||||
|
if (i < components.length / 2 - 1) {
|
||||||
|
leftColumn.add(Box.createVerticalStrut(5));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rightColumn.add(Box.createVerticalGlue());
|
||||||
|
leftColumn.add(Box.createVerticalGlue());
|
||||||
|
|
||||||
|
mainPanel.add(Box.createHorizontalStrut(20));
|
||||||
|
mainPanel.add(leftColumn);
|
||||||
|
mainPanel.add(Box.createHorizontalGlue());
|
||||||
|
mainPanel.add(rightColumn);
|
||||||
|
|
||||||
|
mainPanel.add(Box.createHorizontalStrut(20));
|
||||||
|
|
||||||
|
c.add(mainPanel);
|
||||||
|
|
||||||
|
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
|
||||||
|
this.setLocation(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2);
|
||||||
|
this.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ActionListener createListener() {
|
||||||
|
return new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
//#allthejank
|
||||||
|
ControllerComponent contComp = ControllerComponent.valueOf(((JTextField)e.getSource()).getName());
|
||||||
|
|
||||||
|
contComp.getTextField().setText("Select Input");
|
||||||
|
|
||||||
|
Gamepad listenPad = GamepadHandler.getGamepads().get(0);
|
||||||
|
listenPad.poll();
|
||||||
|
EventQueue queue = listenPad.getEvents();
|
||||||
|
Event event = new Event();
|
||||||
|
queue.getNextEvent(event);
|
||||||
|
Component comp = event.getComponent();
|
||||||
|
contComp.getTextField().setText(comp.getName());
|
||||||
|
|
||||||
|
GamepadSettings config = listenPad.getConfiguration();
|
||||||
|
|
||||||
|
config.insertSetting(contComp, comp);
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.limelight.input;
|
||||||
|
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
|
||||||
|
public enum ControllerComponent {
|
||||||
|
BTN_A("Button 1 (A)"), BTN_X("Button 2 (X)"), BTN_Y("Button 3 (Y)"), BTN_B("Button 4 (B)"),
|
||||||
|
DPAD_UP("D-pad Up"), DPAD_DOWN("D-pad Down"), DPAD_LEFT("D-pad Left"), DPAD_RIGHT("D-pad Right"),
|
||||||
|
LS_X("Left Stick X"), LS_Y("Left Stick X"), RS_X("Right Stick X"), RS_Y("Left Stick Y"),
|
||||||
|
LS_THUMB("Left Stick Button"), RS_THUMB("Right Stick Button"),
|
||||||
|
LT("Left Trigger"), RT("Right Trigger"), LB("Left Bumper"), RB("Right Bumper"),
|
||||||
|
BTN_START("Start Button"), BTN_BACK("Back Button"), BTN_SPECIAL("Special Button");
|
||||||
|
|
||||||
|
private JLabel label;
|
||||||
|
private JTextField textBox;
|
||||||
|
|
||||||
|
private ControllerComponent(String name) {
|
||||||
|
this.label = new JLabel(name);
|
||||||
|
this.textBox = new JTextField();
|
||||||
|
this.textBox.setEditable(false);
|
||||||
|
this.textBox.setName(this.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
public JLabel getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JTextField getTextField() {
|
||||||
|
return textBox;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,6 +19,8 @@ public abstract class Gamepad {
|
|||||||
protected short leftStickX = 0x0000;
|
protected short leftStickX = 0x0000;
|
||||||
protected short leftStickY = 0x0000;
|
protected short leftStickY = 0x0000;
|
||||||
|
|
||||||
|
protected GamepadSettings configuration;
|
||||||
|
|
||||||
public enum ControllerType { XBOX, PS3 };
|
public enum ControllerType { XBOX, PS3 };
|
||||||
|
|
||||||
|
|
||||||
@@ -37,12 +39,18 @@ public abstract class Gamepad {
|
|||||||
this.conn = conn;
|
this.conn = conn;
|
||||||
this.pad = pad;
|
this.pad = pad;
|
||||||
|
|
||||||
|
configuration = new GamepadSettings();
|
||||||
|
|
||||||
for (Component comp : pad.getComponents()) {
|
for (Component comp : pad.getComponents()) {
|
||||||
initValue(comp);
|
initValue(comp);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GamepadSettings getConfiguration() {
|
||||||
|
return configuration;
|
||||||
|
}
|
||||||
|
|
||||||
private void initValue(Component comp) {
|
private void initValue(Component comp) {
|
||||||
handleComponent(comp, comp.getPollData());
|
handleComponent(comp, comp.getPollData());
|
||||||
}
|
}
|
||||||
@@ -56,6 +64,10 @@ public abstract class Gamepad {
|
|||||||
leftStickX, leftStickY, rightStickX, rightStickY);
|
leftStickX, leftStickY, rightStickX, rightStickY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EventQueue getEvents() {
|
||||||
|
return pad.getEventQueue();
|
||||||
|
}
|
||||||
|
|
||||||
public void handleEvents() {
|
public void handleEvents() {
|
||||||
EventQueue queue = pad.getEventQueue();
|
EventQueue queue = pad.getEventQueue();
|
||||||
Event event = new Event();
|
Event event = new Event();
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
package com.limelight.input;
|
package com.limelight.input;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.swing.event.ListSelectionEvent;
|
||||||
|
|
||||||
import com.limelight.input.Gamepad.ControllerType;
|
import com.limelight.input.Gamepad.ControllerType;
|
||||||
import com.limelight.nvstream.NvConnection;
|
import com.limelight.nvstream.NvConnection;
|
||||||
|
|
||||||
@@ -37,6 +40,10 @@ public class GamepadHandler {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<Gamepad> getGamepads() {
|
||||||
|
return Collections.unmodifiableList(gamepads);
|
||||||
|
}
|
||||||
|
|
||||||
private void startUp() {
|
private void startUp() {
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.limelight.input;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import net.java.games.input.Component;
|
||||||
|
|
||||||
|
public class GamepadSettings {
|
||||||
|
private HashMap<ControllerComponent, Component> mapping;
|
||||||
|
|
||||||
|
public void insertSetting(ControllerComponent contComp, Component comp) {
|
||||||
|
mapping.put(contComp, comp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component getComponent(ControllerComponent contComp) {
|
||||||
|
return mapping.get(contComp);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user