Commits

Anonymous committed a1b5c7e

Add generic controller detection as a fallback (will need to promote to 1.1)

  • Participants
  • Parent commits 5276e17

Comments (0)

Files changed (4)

src/com/joshjcarrier/minecontrol/App.java

  */
 public class App {
 
-	public static String VERSION = "1.0.1";
+	public static String VERSION = "1.0.2";
 	
 	/**
 	 * @param args

src/com/joshjcarrier/minecontrol/controller/mapping/GenericControllerPlugin.java

+package com.joshjcarrier.minecontrol.controller.mapping;
+
+import java.net.URL;
+import java.util.HashMap;
+
+import net.java.games.input.Component.Identifier;
+
+import com.joshjcarrier.minecontrol.notch.MinecraftAction;
+
+public class GenericControllerPlugin extends ControllerPlugin {
+
+	private HashMap<String, String> buttonNameMapping;
+	private HashMap<String, MinecraftAction> eventMapping;
+	
+	public GenericControllerPlugin()
+	{
+		buttonNameMapping = new HashMap<String, String>();
+		buttonNameMapping.put(Identifier.Button._0.getName(), "A button");
+		buttonNameMapping.put(Identifier.Button._1.getName(), "B button");
+		buttonNameMapping.put(Identifier.Button._2.getName(), "X button");
+		buttonNameMapping.put(Identifier.Button._3.getName(), "Y button");
+		buttonNameMapping.put(Identifier.Button._4.getName(), "Left shoulder button");
+		buttonNameMapping.put(Identifier.Button._5.getName(), "Right shoulder button");
+		buttonNameMapping.put(Identifier.Button._6.getName(), "Select button");
+		buttonNameMapping.put(Identifier.Button._7.getName(), "Start button");
+		buttonNameMapping.put(Identifier.Button._8.getName(), "Left joystick button");
+		buttonNameMapping.put(Identifier.Button._9.getName(), "Right joystick button");
+		
+		buttonNameMapping.put(Identifier.Axis.Y.getName(), "Left joystick (Y axis)");
+		buttonNameMapping.put(Identifier.Axis.X.getName(), "Left joystick (X axis)");
+		
+		buttonNameMapping.put(Identifier.Axis.RY.getName(), "Right joystick (Y axis)");
+		buttonNameMapping.put(Identifier.Axis.RX.getName(), "Right joystick (X axis)");
+		
+		buttonNameMapping.put(Identifier.Axis.Z.getName(), "Left/right triggers");
+		
+		eventMapping = new HashMap<String, MinecraftAction>();
+		eventMapping.put(Identifier.Button._0.getName(), MinecraftAction.JUMP);
+		eventMapping.put(Identifier.Button._1.getName(), MinecraftAction.INVENTORY);
+		eventMapping.put(Identifier.Button._2.getName(), MinecraftAction.DISCARD_ITEM);
+		eventMapping.put(Identifier.Button._3.getName(), MinecraftAction.CHANGE_PERSPECTIVE);
+		eventMapping.put(Identifier.Button._4.getName(), MinecraftAction.SCROLL_UP);
+		eventMapping.put(Identifier.Button._5.getName(), MinecraftAction.SCROLL_DOWN);
+		eventMapping.put(Identifier.Button._6.getName(), MinecraftAction.SYS_CHANGE_SENSITIVITY);
+		eventMapping.put(Identifier.Button._7.getName(), MinecraftAction.PAUSE);
+		eventMapping.put(Identifier.Button._8.getName(), MinecraftAction.WALK);
+		eventMapping.put(Identifier.Button._9.getName(), MinecraftAction.JUMP);
+		
+		eventMapping.put(Identifier.Axis.Y.getName(), MinecraftAction.MOVE);
+		eventMapping.put(Identifier.Axis.X.getName(), MinecraftAction.STRAFE);
+		
+		eventMapping.put(Identifier.Axis.RY.getName(), MinecraftAction.LOOK_PITCH);
+		eventMapping.put(Identifier.Axis.RX.getName(), MinecraftAction.LOOK_YAW);
+		
+		eventMapping.put(Identifier.Axis.Z.getName(), MinecraftAction.CLICK);
+	}
+	
+	public String getName() {
+		return "Generic controller";
+	}
+
+	public String getInputRegistrationMatching() {
+		return "controller (gamepad)";
+	}
+	
+	public URL getControllerImage()
+	{
+		return this.getClass().getClassLoader().getResource("content/generic.png");
+	}
+	
+	public HashMap<String, String> getButtonNameMapping()
+	{
+		return this.buttonNameMapping;
+	}
+
+	public HashMap<String, MinecraftAction> getActionMapping() {
+		return eventMapping;
+	}
+
+}

src/com/joshjcarrier/minecontrol/ui/ConfigurationManager.java

 import com.joshjcarrier.minecontrol.App;
 import com.joshjcarrier.minecontrol.controller.ControllerManager;
 import com.joshjcarrier.minecontrol.controller.mapping.ControllerPlugin;
+import com.joshjcarrier.minecontrol.controller.mapping.GenericControllerPlugin;
 import com.joshjcarrier.minecontrol.controller.mapping.MsXbox360ControllerPlugin;
 import com.joshjcarrier.minecontrol.notch.MinecraftAction;
 import com.joshjcarrier.minecontrol.notch.MinecraftController;
 	private ConfigurationManager()
 	{
 		currentControllerPlugin = new MsXbox360ControllerPlugin();
+		
+		// just fall back on to a generic one...
+		if(currentControllerPlugin.getControllerConnection() == null)
+		{
+			currentControllerPlugin = new GenericControllerPlugin();
+		}
+		
 		joystickControllerManager = new ControllerManager();
 		joystickControllerManager.setController(currentControllerPlugin);
 		minecraftController = new MinecraftController();
 	{
 		final JPanel creditsPanel = new JPanel(new BorderLayout());
 		
-		JComboBox controllerList = new JComboBox(new Object[]{"Microsoft Xbox 360 controller"});
+		JComboBox controllerList = new JComboBox(new Object[]{currentControllerPlugin.getName()});
 		creditsPanel.add(controllerList, BorderLayout.NORTH);
 		
 		ImageIcon controllerIcon = new ImageIcon(currentControllerPlugin.getControllerImage());

src/content/generic.png

Added
New image