mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-04-03 14:36:09 +00:00
Removed deprecated method and renamed some classes. Created a new package to separate gamepad classes from keyboard/mouse classes
This commit is contained in:
@@ -12,7 +12,7 @@ import javax.swing.UIManager;
|
||||
import com.limelight.binding.PlatformBinding;
|
||||
import com.limelight.gui.MainFrame;
|
||||
import com.limelight.gui.StreamFrame;
|
||||
import com.limelight.input.ControllerListener;
|
||||
import com.limelight.input.gamepad.GamepadListener;
|
||||
import com.limelight.nvstream.NvConnection;
|
||||
import com.limelight.nvstream.NvConnectionListener;
|
||||
import com.limelight.nvstream.StreamConfiguration;
|
||||
@@ -94,7 +94,7 @@ public class Limelight implements NvConnectionListener {
|
||||
PlatformBinding.getAudioRenderer(),
|
||||
PlatformBinding.getVideoDecoderRenderer());
|
||||
|
||||
ControllerListener.startSendingInput(conn);
|
||||
GamepadListener.startSendingInput(conn);
|
||||
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public class Limelight implements NvConnectionListener {
|
||||
}
|
||||
|
||||
private static void startControllerListener() {
|
||||
ControllerListener.startUp();
|
||||
GamepadListener.startUp();
|
||||
}
|
||||
|
||||
private static void createFrame() {
|
||||
@@ -178,7 +178,7 @@ public class Limelight implements NvConnectionListener {
|
||||
@Override
|
||||
public void connectionStarted() {
|
||||
streamFrame.hideSpinner();
|
||||
ControllerListener.startSendingInput(conn);
|
||||
GamepadListener.startSendingInput(conn);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,19 +22,18 @@ import javax.swing.JCheckBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.LineBorder;
|
||||
|
||||
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.ControllerListener;
|
||||
import com.limelight.input.Gamepad;
|
||||
import com.limelight.input.GamepadHandler;
|
||||
import com.limelight.input.GamepadMapping;
|
||||
import com.limelight.input.GamepadMapping.Mapping;
|
||||
import com.limelight.input.gamepad.GamepadComponent;
|
||||
import com.limelight.input.gamepad.GamepadListener;
|
||||
import com.limelight.input.gamepad.Gamepad;
|
||||
import com.limelight.input.gamepad.GamepadHandler;
|
||||
import com.limelight.input.gamepad.GamepadMapping;
|
||||
import com.limelight.input.gamepad.GamepadMapping.Mapping;
|
||||
import com.limelight.settings.GamepadSettingsManager;
|
||||
|
||||
public class GamepadConfigFrame extends JFrame {
|
||||
@@ -60,12 +59,12 @@ public class GamepadConfigFrame extends JFrame {
|
||||
public void build() {
|
||||
componentMap = new HashMap<Box, Mapping>();
|
||||
|
||||
GridLayout layout = new GridLayout(ControllerComponent.values().length/2 + 1, 2);
|
||||
GridLayout layout = new GridLayout(GamepadComponent.values().length/2 + 1, 2);
|
||||
layout.setHgap(60);
|
||||
layout.setVgap(3);
|
||||
JPanel mainPanel = new JPanel(layout);
|
||||
|
||||
ControllerComponent[] components = ControllerComponent.values();
|
||||
GamepadComponent[] components = GamepadComponent.values();
|
||||
|
||||
for (int i = 0; i < components.length; i++) {
|
||||
|
||||
@@ -102,7 +101,7 @@ public class GamepadConfigFrame extends JFrame {
|
||||
mapButton.setMaximumSize(buttonSize);
|
||||
mapButton.setMinimumSize(buttonSize);
|
||||
mapButton.setPreferredSize(buttonSize);
|
||||
mapButton.addActionListener(createListener());
|
||||
mapButton.addActionListener(createMapListener());
|
||||
mapButton.setText(config.getMapping(mapping.contComp));
|
||||
|
||||
invertBox.setSelected(mapping.invert);
|
||||
@@ -110,7 +109,7 @@ public class GamepadConfigFrame extends JFrame {
|
||||
|
||||
triggerBox.setSelected(mapping.trigger);
|
||||
triggerBox.addItemListener(createTriggerListener());
|
||||
triggerBox.setToolTipText("If this component should act as a trigger.");
|
||||
triggerBox.setToolTipText("If this component should act as a trigger. (one-way axis)");
|
||||
|
||||
componentBox.add(Box.createHorizontalStrut(5));
|
||||
componentBox.add(mapping.contComp.getLabel());
|
||||
@@ -120,23 +119,20 @@ public class GamepadConfigFrame extends JFrame {
|
||||
componentBox.add(triggerBox);
|
||||
componentBox.add(Box.createHorizontalStrut(5));
|
||||
|
||||
componentBox.setBorder(createBorder());
|
||||
componentBox.setBorder(new LineBorder(Color.GRAY, 1, true));
|
||||
|
||||
componentMap.put(componentBox, mapping);
|
||||
|
||||
return componentBox;
|
||||
}
|
||||
|
||||
private Border createBorder() {
|
||||
return new LineBorder(Color.GRAY, 1, true);
|
||||
}
|
||||
//TODO: make createInvertListener() and createTriggerListener() one method. TOO MUCH COPY PASTA!
|
||||
private ItemListener createInvertListener() {
|
||||
return new ItemListener() {
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
JCheckBox clicked = (JCheckBox)e.getItem();
|
||||
ControllerComponent contComp = ControllerComponent.valueOf(clicked.getName());
|
||||
GamepadComponent contComp = GamepadComponent.valueOf(clicked.getName());
|
||||
config.get(contComp).invert = (e.getStateChange() == ItemEvent.SELECTED);
|
||||
configChanged = true;
|
||||
}
|
||||
@@ -148,7 +144,7 @@ public class GamepadConfigFrame extends JFrame {
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
JCheckBox clicked = (JCheckBox)e.getItem();
|
||||
ControllerComponent contComp = ControllerComponent.valueOf(clicked.getName());
|
||||
GamepadComponent contComp = GamepadComponent.valueOf(clicked.getName());
|
||||
config.get(contComp).trigger = (e.getStateChange() == ItemEvent.SELECTED);
|
||||
configChanged = true;
|
||||
}
|
||||
@@ -165,7 +161,7 @@ public class GamepadConfigFrame extends JFrame {
|
||||
}
|
||||
if (configChanged) {
|
||||
updateConfigs();
|
||||
ControllerListener.startUp();
|
||||
GamepadListener.startUp();
|
||||
}
|
||||
if (shouldStartHandler) {
|
||||
GamepadHandler.startUp();
|
||||
@@ -175,7 +171,7 @@ public class GamepadConfigFrame extends JFrame {
|
||||
};
|
||||
}
|
||||
|
||||
private ActionListener createListener() {
|
||||
private ActionListener createMapListener() {
|
||||
return new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
@@ -202,7 +198,7 @@ public class GamepadConfigFrame extends JFrame {
|
||||
|
||||
buttonPressed.setSelected(true);
|
||||
|
||||
ControllerListener.stopListening();
|
||||
GamepadListener.stopListening();
|
||||
|
||||
if (GamepadHandler.isRunning()) {
|
||||
GamepadHandler.stopHandler();
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import com.limelight.Limelight;
|
||||
import com.limelight.binding.PlatformBinding;
|
||||
import com.limelight.input.ControllerListener;
|
||||
import com.limelight.input.gamepad.GamepadListener;
|
||||
import com.limelight.nvstream.NvConnection;
|
||||
import com.limelight.nvstream.http.NvHTTP;
|
||||
import com.limelight.settings.PreferencesManager;
|
||||
@@ -51,7 +51,7 @@ public class MainFrame {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
super.windowClosing(e);
|
||||
ControllerListener.stopListening();
|
||||
GamepadListener.stopListening();
|
||||
}
|
||||
});
|
||||
Container mainPane = limeFrame.getContentPane();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.limelight.input;
|
||||
package com.limelight.input.gamepad;
|
||||
|
||||
import com.limelight.input.GamepadMapping.Mapping;
|
||||
import com.limelight.input.gamepad.GamepadMapping.Mapping;
|
||||
import com.limelight.nvstream.NvConnection;
|
||||
import com.limelight.nvstream.input.ControllerPacket;
|
||||
|
||||
@@ -134,7 +134,7 @@ public class Gamepad {
|
||||
}
|
||||
}
|
||||
|
||||
private void handleAnalog(ControllerComponent contComp, float value) {
|
||||
private void handleAnalog(GamepadComponent contComp, float value) {
|
||||
switch (contComp) {
|
||||
case LS_X:
|
||||
leftStickX = (short)Math.round(value * 0x7FFF);
|
||||
@@ -160,7 +160,7 @@ public class Gamepad {
|
||||
}
|
||||
}
|
||||
|
||||
private void handleButtons(ControllerComponent contComp, float value) {
|
||||
private void handleButtons(GamepadComponent contComp, float value) {
|
||||
boolean press = false;
|
||||
|
||||
if (value > 0.5F) {
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.limelight.input;
|
||||
package com.limelight.input.gamepad;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
|
||||
public enum ControllerComponent implements Serializable {
|
||||
public enum GamepadComponent implements Serializable {
|
||||
BTN_A("Button 1 (A)", false), BTN_X("Button 2 (X)", false), BTN_Y("Button 3 (Y)", false), BTN_B("Button 4 (B)", false),
|
||||
DPAD_UP("D-pad Up", false), DPAD_DOWN("D-pad Down", false), DPAD_LEFT("D-pad Left", false), DPAD_RIGHT("D-pad Right", false),
|
||||
LS_X("Left Stick X", true), LS_Y("Left Stick Y", true), RS_X("Right Stick X", true), RS_Y("Right Stick Y", true),
|
||||
@@ -15,7 +15,7 @@ public enum ControllerComponent implements Serializable {
|
||||
private JLabel label;
|
||||
private boolean analog;
|
||||
|
||||
private ControllerComponent(String name, boolean analog) {
|
||||
private GamepadComponent(String name, boolean analog) {
|
||||
this.label = new JLabel(name);
|
||||
this.analog = analog;
|
||||
}
|
||||
@@ -27,9 +27,4 @@ public enum ControllerComponent implements Serializable {
|
||||
public boolean isAnalog() {
|
||||
return analog;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean sameAs(ControllerComponent other) {
|
||||
return this.name().equals(other.name());
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.limelight.input;
|
||||
package com.limelight.input.gamepad;
|
||||
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.limelight.input;
|
||||
package com.limelight.input.gamepad;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.LinkedList;
|
||||
@@ -8,7 +8,7 @@ import com.limelight.nvstream.NvConnection;
|
||||
import net.java.games.input.Controller;
|
||||
import net.java.games.input.ControllerEnvironment;
|
||||
|
||||
public class ControllerListener {
|
||||
public class GamepadListener {
|
||||
private static Thread listenerThread;
|
||||
private static NvConnection conn;
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.limelight.input;
|
||||
package com.limelight.input.gamepad;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
|
||||
import net.java.games.input.Component;
|
||||
|
||||
public class GamepadMapping implements Serializable {
|
||||
@@ -32,10 +33,10 @@ public class GamepadMapping implements Serializable {
|
||||
* @param contComp the component to get a mapping for
|
||||
* @return a mapping or an null if there is none
|
||||
*/
|
||||
public Mapping get(ControllerComponent contComp) {
|
||||
public Mapping get(GamepadComponent contComp) {
|
||||
//#allTheJank
|
||||
for (Entry<String, Mapping> entry : mapping.entrySet()) {
|
||||
if (entry.getValue().contComp.sameAs(contComp)) {
|
||||
if (entry.getValue().contComp == contComp) {
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
@@ -47,9 +48,9 @@ public class GamepadMapping implements Serializable {
|
||||
* @param contComp the component to get a mapping for
|
||||
* @return a mapping or an empty string if there is none
|
||||
*/
|
||||
public String getMapping(ControllerComponent contComp) {
|
||||
public String getMapping(GamepadComponent contComp) {
|
||||
for (Entry<String, Mapping> entry : mapping.entrySet()) {
|
||||
if (entry.getValue().contComp.sameAs(contComp)) {
|
||||
if (entry.getValue().contComp == contComp) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
@@ -59,11 +60,11 @@ public class GamepadMapping implements Serializable {
|
||||
public class Mapping implements Serializable {
|
||||
private static final long serialVersionUID = -8407172977953214242L;
|
||||
|
||||
public ControllerComponent contComp;
|
||||
public GamepadComponent contComp;
|
||||
public boolean invert;
|
||||
public boolean trigger;
|
||||
|
||||
public Mapping(ControllerComponent contComp, boolean invert, boolean trigger) {
|
||||
public Mapping(GamepadComponent contComp, boolean invert, boolean trigger) {
|
||||
this.contComp = contComp;
|
||||
this.invert = invert;
|
||||
this.trigger = trigger;
|
||||
@@ -2,7 +2,7 @@ package com.limelight.settings;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.limelight.input.GamepadMapping;
|
||||
import com.limelight.input.gamepad.GamepadMapping;
|
||||
|
||||
public abstract class GamepadSettingsManager {
|
||||
private static GamepadMapping cachedSettings;
|
||||
|
||||
Reference in New Issue
Block a user