Hello people,
I’ve built a small proof-of-concept simulation with jME and I’m having a bit of trouble with the input system.
I’ve been following the tutorial InputSystem and InputHandler guide at http://www.jmonkeyengine.com/wiki/doku.php?id=inputsystem_and_inputhandler_guide.
What I’m trying to achieve is a game state oriented inputsystem. This is, separate input handling for each state (console, spectator, airplane, tank…). I already have different game states (currently GameStateNodes) arranged in a tree, and I would like to associate gamesates and inputhandlers so that I can activate each game state and get the input system to act acordly.
I’m doing the following:
/**
* Switchs the console (on/off)
*/
public void switchConsole() {
logger.info("Opening/closing console");
if (consoleState.isActive()) {
// Deactivate console
input.getConsoleInputHandler().setEnabled(false);
input.getSpectatorInputHandler().getKeyboardLookHandler().setEnabled(true)
consoleState.setActive(false);
} else {
// Activate console
input.getConsoleInputHandler().setEnabled(true);
input.getSpectatorInputHandler().getKeyboardLookHandler().setEnabled(false);
consoleState.setActive(true);
}
}
The problem is that the KeyboardLookHandler contained in my SpectatorInputHandler is correctly disabled with the call to .setEnabled(false). However, when I disable my self-made ConsoleInputHandler it still processes the input events.
The ConsoleInputHandler is really simple but I guess that the problem comes from the way I've implemented the whole thing:
/**
* The ConsoleInputHandler handles console keys.
*/
public class ConsoleInputHandler extends InputHandler {
private final static Logger logger = Logger.getLogger(ConsoleInputHandler.class.toString());
/**
* Console key action code
*/
public class ConsoleKeyAction extends InputAction {
public void performAction(InputActionEvent evt) {
// THIS IS WHAT I'M USING TO WORKAROUND THE PROBLEM:
if (!System.getMainState().getClientState().getConsoleState().isActive()) return;
logger.fine("Key pressed in console mode: triggerIndex=" + evt.getTriggerIndex());
if (evt.getTriggerPressed() == true) {
System.getConsole().processKey(evt.getTriggerCharacter());
}
}
}
/**
* Constructor
*/
public ConsoleInputHandler() {
addAction(new ConsoleKeyAction(), InputHandler.DEVICE_KEYBOARD, InputHandler.BUTTON_ALL, InputHandler.AXIS_ALL, false);
}
}
I've tried debugging inside jME input system (InputHandler, FirstPersonHandler (which is already a composition handler), KeyboardLookHandler...) but I think that maybe I'm misunderstanding the input system.
To avoid ConsoleInputHandler processing all keypresses I'm checking if console is activated by hand, but I think that disabling the InputHandler should work.
Thank you for your suggestions,
J