For my Nifty GUI, I pretty much followed the “Nifty GUI 1.3 - Usecase Scenarios”: every screen does “extends AbstractAppState implements ScreenController”. I have a tree-structured screen hierarchy, with a “stack” of active screens, so that when a child screen exits, it goes back to the parent screen. Each screen can have an optional “screenNode”, where it put it’s scene. The only thing that goes into the real rootNode is the “screenNode”, so that I can easily switch scene, to match the switching screens. This works well so far.
Now my problem is, that the input-binding is global. I would like to have the input-binding be associated specifically with the currently displayed scene (screen), and be able to switch, just like I do with the rootNode. How could I do this? I think this would mean having multiple InputManager instances, one for each screen, and switching which one is currently active. But the InputManager is created in “private void initInput()” of Application, so I can’t influence this directly. The field is protected, so I could change it’s value, but I think it needs something like an activate/passivate for me to be able to replace it.
The only option I see currently, is to have a registerInput()/deregisterInput() in each screen, and call them when I switch from one to the other. Is that what I should do?