How to use Lemur’s support for multiple controllers.
As well I tried to figure out how to get the controller name so I could implement a customized key name as on my nacon controller it is a “1” where it is “B” on the Nintendo controller and an “X” on the PS4 controller.
At the moment I just map Keys and joystick buttons to “something” I don’t see the joystick… But I might be just blind and it is directly in front of me.
here is an example (my current game does read it from a file and is a bit less straight forward so I took an older game, but the same principle). I can not see in this code where it knows which gamepad, it looks to me that this is only for one and if there are two it just picks one of the two…
package ch.artificials.bg.view.states.player;
import com.jme3.input.KeyInput;
import com.simsilica.lemur.input.Axis;
import com.simsilica.lemur.input.Button;
import com.simsilica.lemur.input.FunctionId;
import com.simsilica.lemur.input.InputMapper;
import com.simsilica.lemur.input.InputState;
public class PlayerMovementFunctions {
public static final String G_MOVEMENT = "Movement";
public static final String G_ACTION = "Action";
public static final FunctionId F_X_ROTATE_MOUSE = new FunctionId(G_MOVEMENT, "RotateMouse");
public static final FunctionId F_X_ROTATE_KEYBOARD = new FunctionId(G_MOVEMENT, "RotateKeyboard");
public static final FunctionId F_X_ROTATE_CONTROLER = new FunctionId(G_MOVEMENT, "RotateControler");
public static final FunctionId F_THRUST = new FunctionId(G_MOVEMENT, "Thrust");
public static final FunctionId F_STRAFE = new FunctionId(G_MOVEMENT, "Strafe");
public static final FunctionId F_BOOST = new FunctionId(G_MOVEMENT, "Boost");
public static final FunctionId F_SHOOT = new FunctionId(G_ACTION, "Shoot");
public static final FunctionId F_LAUNCH = new FunctionId(G_ACTION, "Launch");
public static final FunctionId F_TAKE_SCREENSHOT = new FunctionId(G_ACTION, "Take Screenshot");
public static void initializeDefaultMappings(InputMapper inputMapper) {
if (!inputMapper.hasMappings(F_THRUST)) {
inputMapper.map(F_THRUST, InputState.Negative, Axis.JOYSTICK_LEFT_Y);
inputMapper.map(F_THRUST, KeyInput.KEY_W);
inputMapper.map(F_THRUST, InputState.Negative, KeyInput.KEY_S);
}
if (!inputMapper.hasMappings(F_STRAFE)) {
// Strafing is setup similar to move.
inputMapper.map(F_STRAFE, Axis.JOYSTICK_LEFT_X);
inputMapper.map(F_STRAFE, KeyInput.KEY_D);
inputMapper.map(F_STRAFE, InputState.Negative, KeyInput.KEY_A);
}
if (!inputMapper.hasMappings(F_X_ROTATE_MOUSE)) {
inputMapper.map(F_X_ROTATE_MOUSE, Axis.MOUSE_X);
}
if (!inputMapper.hasMappings(F_X_ROTATE_KEYBOARD)) {
inputMapper.map(F_X_ROTATE_KEYBOARD, KeyInput.KEY_RIGHT);
inputMapper.map(F_X_ROTATE_KEYBOARD, InputState.Negative, KeyInput.KEY_LEFT);
}
if (!inputMapper.hasMappings(F_X_ROTATE_CONTROLER)) {
inputMapper.map(F_X_ROTATE_CONTROLER, Axis.JOYSTICK_RIGHT_X);
}
if (!inputMapper.hasMappings(F_SHOOT)) {
inputMapper.map(F_SHOOT, Button.JOYSTICK_RIGHT2);
inputMapper.map(F_SHOOT, KeyInput.KEY_SPACE);
inputMapper.map(F_SHOOT, Button.MOUSE_BUTTON1);
}
if (!inputMapper.hasMappings(F_LAUNCH)) {
inputMapper.map(F_LAUNCH, Button.JOYSTICK_LEFT2);
inputMapper.map(F_LAUNCH, KeyInput.KEY_UP);
inputMapper.map(F_LAUNCH, Button.MOUSE_BUTTON2);
}
if (!inputMapper.hasMappings(F_TAKE_SCREENSHOT)) {
inputMapper.map(F_TAKE_SCREENSHOT, KeyInput.KEY_P);
}
}
}
And I ask because the testers for my demo stuck mainly because of issues with the gamepad. For example, if I run my gamepad with XInput instead DirectInput8 the R1,2,3 and L1,2,3 are not functional (they probably are axis there). And the player has not a clue what a jostick_button1 is he wants to read X or B or 1 depending on the controller.
I guess it just listens to all joysticks and looks if there is a mapping. But how can I for example detect which one is in use (games I know to do this by letting the player press start to connect) and get the type of the controller? If I know the type I could provide a proper translation of the button…
Additional Note:
I found the Lemur mapping which maps all the buttons to more straight forward names on a gamepad. And I saw Lemur does this for all possible joystick. But let’s say I have plugged in two controller, which one will Lemur / Jme take? I cant see that. Both together? One of them?
And is there a better way to handle different kind of gamepads and is it even possible to know which type of controller is connected with Lemur?