I want to work with some user inputs, that means user inputs should be visible in my main java class.
I have the following classes:
Main.java (includes main(), simpleInitApp() and simpleUpdate())
InputController.java
controls.xml (Nifty GUI)
I need the user inputs in main.java, so how can I access to the inputs? I already used the NiftyEventSubscriber, but I can access to user inputs only in InputController.java, but I need the inputs in main.java, where I would like to work with.
I need access to the subscriber from the main.java, but I don’t find any solution to do that.
Is your InputController a screenController on the nifty-Screen?
If so you could add a field to your InputController called “Main main”, load this controller from the screen with screen.getScreenController() and set the main-object to the new field.
After that you can direct the input-calls from your controller to the main.
Yes, the InputController is a screenController on the nifty screen. But I don’t understand what you mean with “set the main-object to the new field”
Here is my small test example. In this case I want to recognize if the user has clicked on the logo, but I don’t understand what I should do now.
After you’ve loaded the xml-File with “.fromXml” you can fetch the screenController you’ve implemented above with “inputController = (InputController)nifty.getScreen(“screenId”).getScreenController();”
Than you can set the field main on the controller with your Application-Object (something like: “inputController.setMain(this)”)
Now your InputController is able to call the methods in your Application-Object.
Also it would be a good idea to fetch every input from your screen in your inputController. It’s not a good idea to try to delegate the input-events to other classes than a controller 'cause you will end up confused very fast.
If you follow this pattern you will always know where your input will be handled.
Or better yet register the screen controller with Nifty (either first using the register call or by supplying it to the from/add xml calls) and then you know what the screen controller is already.