mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-04-20 23:30:37 +00:00
Add D-Pad support for 360 controllers. Currently, the 360 D-Pad can only be mapped as D-Pad buttons.
This commit is contained in:
@@ -34,6 +34,7 @@ import com.limelight.input.gamepad.Gamepad;
|
|||||||
import com.limelight.input.gamepad.GamepadHandler;
|
import com.limelight.input.gamepad.GamepadHandler;
|
||||||
import com.limelight.input.gamepad.GamepadMapping;
|
import com.limelight.input.gamepad.GamepadMapping;
|
||||||
import com.limelight.input.gamepad.GamepadMapping.Mapping;
|
import com.limelight.input.gamepad.GamepadMapping.Mapping;
|
||||||
|
import com.limelight.input.gamepad.SourceComponent;
|
||||||
import com.limelight.settings.GamepadSettingsManager;
|
import com.limelight.settings.GamepadSettingsManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -244,10 +245,9 @@ public class GamepadConfigFrame extends JFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
Component newComponent = waitForNewMapping(pad);
|
SourceComponent newComponent = waitForNewMapping(pad);
|
||||||
consumeEvents(pad);
|
consumeEvents(pad);
|
||||||
|
|
||||||
|
|
||||||
if (newComponent != null) {
|
if (newComponent != null) {
|
||||||
Mapping oldConfig = config.get(newComponent);
|
Mapping oldConfig = config.get(newComponent);
|
||||||
if (oldConfig != null) {
|
if (oldConfig != null) {
|
||||||
@@ -256,7 +256,7 @@ public class GamepadConfigFrame extends JFrame {
|
|||||||
|
|
||||||
config.insertMapping(mappingToMap, newComponent);
|
config.insertMapping(mappingToMap, newComponent);
|
||||||
|
|
||||||
buttonPressed.setText(newComponent.getName());
|
buttonPressed.setText(newComponent.getComponent().getName());
|
||||||
configChanged = true;
|
configChanged = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -275,8 +275,8 @@ public class GamepadConfigFrame extends JFrame {
|
|||||||
/*
|
/*
|
||||||
* Waits until the user chooses what to map to the clicked component
|
* Waits until the user chooses what to map to the clicked component
|
||||||
*/
|
*/
|
||||||
private Component waitForNewMapping(Gamepad pad) {
|
private SourceComponent waitForNewMapping(Gamepad pad) {
|
||||||
Component newMapping = null;
|
SourceComponent newMapping = null;
|
||||||
|
|
||||||
while (newMapping == null) {
|
while (newMapping == null) {
|
||||||
if (pad.poll()) {
|
if (pad.poll()) {
|
||||||
@@ -287,8 +287,13 @@ public class GamepadConfigFrame extends JFrame {
|
|||||||
if (!pad.poll()) {
|
if (!pad.poll()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (Math.abs(event.getValue()) > .75F) {
|
|
||||||
newMapping = event.getComponent();
|
if (event.getComponent().getIdentifier() == Component.Identifier.Axis.POV) {
|
||||||
|
newMapping = new SourceComponent(event.getComponent(), ""+event.getValue());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (!event.getComponent().isAnalog() || Math.abs(event.getValue()) > .75F) {
|
||||||
|
newMapping = new SourceComponent(event.getComponent(), "");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,8 +30,6 @@ import javax.swing.JProgressBar;
|
|||||||
import com.limelight.Limelight;
|
import com.limelight.Limelight;
|
||||||
import com.limelight.input.KeyboardHandler;
|
import com.limelight.input.KeyboardHandler;
|
||||||
import com.limelight.input.MouseHandler;
|
import com.limelight.input.MouseHandler;
|
||||||
import com.limelight.input.gamepad.GamepadHandler;
|
|
||||||
import com.limelight.input.gamepad.GamepadListener;
|
|
||||||
import com.limelight.nvstream.NvConnection;
|
import com.limelight.nvstream.NvConnection;
|
||||||
import com.limelight.nvstream.NvConnectionListener.Stage;
|
import com.limelight.nvstream.NvConnectionListener.Stage;
|
||||||
import com.limelight.nvstream.StreamConfiguration;
|
import com.limelight.nvstream.StreamConfiguration;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.limelight.nvstream.NvConnection;
|
|||||||
import com.limelight.nvstream.input.ControllerPacket;
|
import com.limelight.nvstream.input.ControllerPacket;
|
||||||
|
|
||||||
import net.java.games.input.Component;
|
import net.java.games.input.Component;
|
||||||
|
import net.java.games.input.Component.Identifier;
|
||||||
import net.java.games.input.Controller;
|
import net.java.games.input.Controller;
|
||||||
import net.java.games.input.Event;
|
import net.java.games.input.Event;
|
||||||
import net.java.games.input.EventQueue;
|
import net.java.games.input.EventQueue;
|
||||||
@@ -97,8 +98,7 @@ public class Gamepad {
|
|||||||
* Prints out the specified event information for the given gamepad
|
* Prints out the specified event information for the given gamepad
|
||||||
* used for debugging, normally unused.
|
* used for debugging, normally unused.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
public static void printInfo(Controller gamepad, Event event) {
|
||||||
private void printInfo(Controller gamepad, Event event) {
|
|
||||||
Component comp = event.getComponent();
|
Component comp = event.getComponent();
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder(gamepad.getName());
|
StringBuilder builder = new StringBuilder(gamepad.getName());
|
||||||
@@ -108,9 +108,40 @@ public class Gamepad {
|
|||||||
builder.append(comp.getName()).append(" changed to ");
|
builder.append(comp.getName()).append(" changed to ");
|
||||||
|
|
||||||
|
|
||||||
float value = event.getValue();
|
float value = event.getValue();
|
||||||
if(comp.isAnalog()) {
|
if(comp.isAnalog()) {
|
||||||
builder.append(value);
|
builder.append(value);
|
||||||
|
} else if (comp.getIdentifier() == Identifier.Axis.POV) {
|
||||||
|
if (value == Component.POV.DOWN) {
|
||||||
|
builder.append("Down");
|
||||||
|
}
|
||||||
|
else if (value == Component.POV.UP) {
|
||||||
|
builder.append("Up");
|
||||||
|
}
|
||||||
|
else if (value == Component.POV.LEFT) {
|
||||||
|
builder.append("Left");
|
||||||
|
}
|
||||||
|
else if (value == Component.POV.RIGHT) {
|
||||||
|
builder.append("Right");
|
||||||
|
}
|
||||||
|
else if (value == Component.POV.CENTER) {
|
||||||
|
builder.append("Center");
|
||||||
|
}
|
||||||
|
else if (value == Component.POV.DOWN_LEFT) {
|
||||||
|
builder.append("Down-left");
|
||||||
|
}
|
||||||
|
else if (value == Component.POV.DOWN_RIGHT) {
|
||||||
|
builder.append("Down-right");
|
||||||
|
}
|
||||||
|
else if (value == Component.POV.UP_LEFT) {
|
||||||
|
builder.append("Up-left");
|
||||||
|
}
|
||||||
|
else if (value == Component.POV.UP_RIGHT) {
|
||||||
|
builder.append("Up-right");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
builder.append("Unknown");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if(value==1.0f) {
|
if(value==1.0f) {
|
||||||
builder.append("On");
|
builder.append("On");
|
||||||
@@ -140,6 +171,9 @@ public class Gamepad {
|
|||||||
if (mapping != null) {
|
if (mapping != null) {
|
||||||
if (mapping.contComp.isAnalog()) {
|
if (mapping.contComp.isAnalog()) {
|
||||||
handleAnalog(mapping.contComp, sanitizeValue(mapping, value));
|
handleAnalog(mapping.contComp, sanitizeValue(mapping, value));
|
||||||
|
} else if (comp.getIdentifier() == Component.Identifier.Axis.POV) {
|
||||||
|
// The values are directional constants so they cannot be sanitized
|
||||||
|
handlePOV(value);
|
||||||
} else {
|
} else {
|
||||||
handleButtons(mapping.contComp, sanitizeValue(mapping, value));
|
handleButtons(mapping.contComp, sanitizeValue(mapping, value));
|
||||||
}
|
}
|
||||||
@@ -171,6 +205,47 @@ public class Gamepad {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Handles POV component input
|
||||||
|
*/
|
||||||
|
private void handlePOV(float value) {
|
||||||
|
if (value == Component.POV.UP ||
|
||||||
|
value == Component.POV.UP_LEFT ||
|
||||||
|
value == Component.POV.UP_RIGHT) {
|
||||||
|
toggle(ControllerPacket.UP_FLAG, true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
toggle(ControllerPacket.UP_FLAG, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value == Component.POV.DOWN ||
|
||||||
|
value == Component.POV.DOWN_LEFT ||
|
||||||
|
value == Component.POV.DOWN_RIGHT) {
|
||||||
|
toggle(ControllerPacket.DOWN_FLAG, true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
toggle(ControllerPacket.DOWN_FLAG, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value == Component.POV.LEFT ||
|
||||||
|
value == Component.POV.DOWN_LEFT ||
|
||||||
|
value == Component.POV.UP_LEFT) {
|
||||||
|
toggle(ControllerPacket.LEFT_FLAG, true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
toggle(ControllerPacket.LEFT_FLAG, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value == Component.POV.RIGHT ||
|
||||||
|
value == Component.POV.UP_RIGHT ||
|
||||||
|
value == Component.POV.DOWN_RIGHT) {
|
||||||
|
toggle(ControllerPacket.RIGHT_FLAG, true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
toggle(ControllerPacket.RIGHT_FLAG, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Handles analog component input
|
* Handles analog component input
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -28,8 +28,12 @@ public class GamepadMapping implements Serializable {
|
|||||||
* @param toMap a <code>Mapping</code> that will be mapped to the specified gamepad component
|
* @param toMap a <code>Mapping</code> that will be mapped to the specified gamepad component
|
||||||
* @param comp the gamepad component to map to.
|
* @param comp the gamepad component to map to.
|
||||||
*/
|
*/
|
||||||
public void insertMapping(Mapping toMap, Component comp) {
|
public void insertMapping(Mapping toMap, SourceComponent comp) {
|
||||||
mapping.put(comp.getIdentifier().getName(), toMap);
|
// This is the base mapping for components with multiple "buttons"
|
||||||
|
mapping.put(comp.getComponentId(), toMap);
|
||||||
|
|
||||||
|
// This is the more-specific mapping for the specific buttons
|
||||||
|
mapping.put(comp.getFullUniqueId(), toMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,12 +45,31 @@ public class GamepadMapping implements Serializable {
|
|||||||
return mapping.get(comp.getIdentifier().getName());
|
return mapping.get(comp.getIdentifier().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the mapping for the specified source component
|
||||||
|
* @param comp the source component to get a mapping for
|
||||||
|
* @return a mapping for the requested component
|
||||||
|
*/
|
||||||
|
public Mapping get(SourceComponent comp) {
|
||||||
|
return mapping.get(comp.getFullUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the mapping to the specified component
|
* Removes the mapping to the specified component
|
||||||
* @param comp the component to no longer be mapped.
|
* @param comp the component to no longer be mapped.
|
||||||
*/
|
*/
|
||||||
public void remove(Component comp) {
|
public void remove(SourceComponent comp) {
|
||||||
mapping.remove(comp.getIdentifier().getName());
|
// Remove the most specific mapping
|
||||||
|
mapping.remove(comp.getFullUniqueId());
|
||||||
|
|
||||||
|
for (Entry<String, Mapping> entry : mapping.entrySet()) {
|
||||||
|
if (entry.getKey().startsWith(comp.getComponentId())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove the common mapping if no more specific mappings remain
|
||||||
|
mapping.remove(comp.getComponentId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
29
src/com/limelight/input/gamepad/SourceComponent.java
Normal file
29
src/com/limelight/input/gamepad/SourceComponent.java
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package com.limelight.input.gamepad;
|
||||||
|
|
||||||
|
import net.java.games.input.Component;
|
||||||
|
|
||||||
|
public class SourceComponent {
|
||||||
|
private Component component;
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
public SourceComponent(Component component, String id) {
|
||||||
|
this.component = component;
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component getComponent() {
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFullUniqueId() {
|
||||||
|
return getComponentId() + " " + getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getComponentId() {
|
||||||
|
return component.getIdentifier().getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user