From 9b763443fa6c5fcd32fd8de5e6dc57c40a4d798f Mon Sep 17 00:00:00 2001 From: "PSp..om" Date: Thu, 27 Sep 2012 21:33:16 +0000 Subject: [PATCH] Modified the string-based look-ups to use logical ID instead of name. The names may be localized for the local language.... Bouton 0 instead of Button 0, etc. I also changed the compatible layer and the one default mapping to use logical IDs now. Added a few constants to JoystickButton just to make things easier for the standard buttons 0-11. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9782 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../core/com/jme3/input/AbstractJoystick.java | 18 ++++-------------- .../src/core/com/jme3/input/InputManager.java | 4 ++++ engine/src/core/com/jme3/input/Joystick.java | 12 ++++++------ .../src/core/com/jme3/input/JoystickAxis.java | 12 ++++++------ .../core/com/jme3/input/JoystickButton.java | 13 +++++++++++++ .../input/JoystickCompatibilityMappings.java | 16 ++++++++-------- 6 files changed, 41 insertions(+), 34 deletions(-) diff --git a/engine/src/core/com/jme3/input/AbstractJoystick.java b/engine/src/core/com/jme3/input/AbstractJoystick.java index ba7b06b1b..f59b331f6 100644 --- a/engine/src/core/com/jme3/input/AbstractJoystick.java +++ b/engine/src/core/com/jme3/input/AbstractJoystick.java @@ -99,15 +99,10 @@ public abstract class AbstractJoystick implements Joystick { inputManager.addMapping(negativeMapping, new JoyAxisTrigger(joyId, axisId, true)); } - /** - * Returns the JoystickAxis with the specified name. - * - * @param name The name of the axis to search for as returned by JoystickAxis.getName(). - */ @Override - public JoystickAxis getAxis(String name) { + public JoystickAxis getAxis(String logicalId) { for( JoystickAxis axis : axes ) { - if( axis.getName().equals(name) ) + if( axis.getLogicalId().equals(logicalId) ) return axis; } return null; @@ -131,15 +126,10 @@ public abstract class AbstractJoystick implements Joystick { return axes.size(); } - /** - * Returns the JoystickButton with the specified name. - * - * @param name The name of the button to search for as returned by JoystickButton.getName(). - */ @Override - public JoystickButton getButton(String name) { + public JoystickButton getButton(String logicalId) { for( JoystickButton b : buttons ) { - if( b.getName().equals(name) ) + if( b.getLogicalId().equals(logicalId) ) return b; } return null; diff --git a/engine/src/core/com/jme3/input/InputManager.java b/engine/src/core/com/jme3/input/InputManager.java index 8c76c77b6..623f71961 100644 --- a/engine/src/core/com/jme3/input/InputManager.java +++ b/engine/src/core/com/jme3/input/InputManager.java @@ -456,6 +456,10 @@ public class InputManager implements RawInputListener { invokeTimedActions(hash, evt.getTime(), evt.isPressed()); } + public void simulateEvent( InputEvent evt ) { + inputQueue.add(evt); + } + /** * Callback from RawInputListener. Do not use. */ diff --git a/engine/src/core/com/jme3/input/Joystick.java b/engine/src/core/com/jme3/input/Joystick.java index e8a080afd..48bfb5c30 100644 --- a/engine/src/core/com/jme3/input/Joystick.java +++ b/engine/src/core/com/jme3/input/Joystick.java @@ -41,11 +41,11 @@ public interface Joystick { public void assignAxis(String positiveMapping, String negativeMapping, int axisId); /** - * Returns the JoystickAxis with the specified name. + * Returns the JoystickAxis with the specified logical ID. * - * @param name The name of the axis to search for as returned by JoystickAxis.getName(). + * @param logicalId The id of the axis to search for as returned by JoystickAxis.getLogicalId(). */ - public JoystickAxis getAxis(String name); + public JoystickAxis getAxis(String logicalId); /** * Returns a read-only list of all joystick axes for this Joystick. @@ -53,11 +53,11 @@ public interface Joystick { public List getAxes(); /** - * Returns the JoystickButton with the specified name. + * Returns the JoystickButton with the specified logical ID. * - * @param name The name of the button to search for as returned by JoystickButton.getName(). + * @param logicalId The id of the axis to search for as returned by JoystickButton.getLogicalId(). */ - public JoystickButton getButton(String name); + public JoystickButton getButton(String logicalId); /** * Returns a read-only list of all joystick buttons for this Joystick. diff --git a/engine/src/core/com/jme3/input/JoystickAxis.java b/engine/src/core/com/jme3/input/JoystickAxis.java index 371761021..519f0df71 100644 --- a/engine/src/core/com/jme3/input/JoystickAxis.java +++ b/engine/src/core/com/jme3/input/JoystickAxis.java @@ -10,13 +10,13 @@ import com.jme3.input.controls.JoyButtonTrigger; */ public interface JoystickAxis { - public static final String X_AXIS = "X Axis"; - public static final String Y_AXIS = "Y Axis"; - public static final String Z_AXIS = "Z Axis"; - public static final String Z_ROTATION = "Z Rotation"; + public static final String X_AXIS = "x"; + public static final String Y_AXIS = "y"; + public static final String Z_AXIS = "z"; + public static final String Z_ROTATION = "rz"; - public static final String POV_X = "JME:POV_X"; - public static final String POV_Y = "JME:POV_Y"; + public static final String POV_X = "pov_x"; + public static final String POV_Y = "pov_y"; /** * Assign the mappings to receive events from the given joystick axis. diff --git a/engine/src/core/com/jme3/input/JoystickButton.java b/engine/src/core/com/jme3/input/JoystickButton.java index 509a8fee6..bdd283fa1 100644 --- a/engine/src/core/com/jme3/input/JoystickButton.java +++ b/engine/src/core/com/jme3/input/JoystickButton.java @@ -10,6 +10,19 @@ import com.jme3.input.controls.JoyButtonTrigger; */ public interface JoystickButton { + public static final String BUTTON_0 = "0"; + public static final String BUTTON_1 = "1"; + public static final String BUTTON_2 = "2"; + public static final String BUTTON_3 = "3"; + public static final String BUTTON_4 = "4"; + public static final String BUTTON_5 = "5"; + public static final String BUTTON_6 = "6"; + public static final String BUTTON_7 = "7"; + public static final String BUTTON_8 = "8"; + public static final String BUTTON_9 = "9"; + public static final String BUTTON_10 = "10"; + public static final String BUTTON_11 = "11"; + /** * Assign the mapping name to receive events from the given button index * on the joystick. diff --git a/engine/src/core/com/jme3/input/JoystickCompatibilityMappings.java b/engine/src/core/com/jme3/input/JoystickCompatibilityMappings.java index bae00e35d..7dadc3b2e 100644 --- a/engine/src/core/com/jme3/input/JoystickCompatibilityMappings.java +++ b/engine/src/core/com/jme3/input/JoystickCompatibilityMappings.java @@ -81,13 +81,13 @@ public class JoystickCompatibilityMappings { * Returns the remapped version of the axis/button name if there * is a mapping for it otherwise it returns the original name. */ - public static String remapComponent( String joystickName, String componentName ) { + public static String remapComponent( String joystickName, String componentId ) { Map map = getMappings(joystickName.trim(), false); if( map == null ) - return componentName; - if( !map.containsKey(componentName) ) - return componentName; - return map.get(componentName); + return componentId; + if( !map.containsKey(componentId) ) + return componentId; + return map.get(componentId); } /** @@ -106,9 +106,9 @@ public class JoystickCompatibilityMappings { * joystick's name and axis/button name. The "remap" value will be * used instead. */ - public static void addMapping( String stickName, String sourceComponent, String remap ) { - logger.log(Level.INFO, "addMapping(" + stickName + ", " + sourceComponent + ", " + remap + ")" ); - getMappings(stickName, true).put( sourceComponent, remap ); + public static void addMapping( String stickName, String sourceComponentId, String remapId ) { + logger.log(Level.INFO, "addMapping(" + stickName + ", " + sourceComponentId + ", " + remapId + ")" ); + getMappings(stickName, true).put( sourceComponentId, remapId ); } /**