So I have my screen, which is something similar to an RTS screen (buttons on the bottom right corner that moves, attacks and do stuff). Now, what I wanted to do is when the user press, let’s say, S, I wanted to call a method actionStop(), which would stop the current unit’s order. I see that Nifty allow us to add KeyInputHandler. The problem is, that it only reads actions converted by NiftyInputMapping, which in this case, converts KeyboardInputEvent to NiftyInputEvent, an enumeration. I can’t add functionality to an enumeration, so I can’t add an ActionStop on that enum, so that my KeyInputHandler knows what to do when the user pressed S. To overcome this, I could set as Character, and put a value there that would mean the order Stop (doesn’t even need to be S). My question is, couldn’t NiftyInputEvent be an Interface and the current enumeration be an implementation of that Interface? That way, we could add our custom enumerations (or anything else)?
Excellent description of the problem (as well as the workaround).
The answer is: YES! It’s not done yet but this will definitely change into an interface. This shortcoming has already been mentioned and I’m aware of the problem. This will be an interface soon.
Great news! As I knew this was a new implementation, I thought it might need some adjustments like this! ^^
Edit: And that Manual is really, really helpful! It’s great! Helped me so much, so many dumb questions answered there!
Added as a new issue to the Nifty github tracker https://github.com/void256/nifty-gui/issues/38 so that I can’t forget it ^^
This commit might be of interest
Unfortunately this commit changed the way NiftyInputEvent is used a bit. Therefore this change will not be part of Nifty 1.3.2. Instead I’ve commited it to Nifty 1.4 (which already contains all the changes of 1.3.x but is allowed to introduce features that would break backward compatibility with Nifty 1.3.x).
Oh, too bad I won’t see this change soon. Glad to know you worked hard to do this ^^ If in the future, when I need this, the 1.4 isn’t out yet, I’ll just build from the source and use it.
Why dont you use JMEs InputManager?