Binding from button controller to main app

Hello,

I dont understand why nifty controls are not given the main application variable
what’s the point of clicking a button if it’s action stays in the realm of the gui ???
I need to communicate with game appstates for instance

public class CommandButtonController implements Controller
{
    private Nifty nifty;
    private Element element;
    private Screen screen;

    public void bind(final Nifty nifty,final Screen screenParam,final Element element,final Properties parameter,final ControllerEventListener listener,final Attributes controlDefinitionAttributes) 
    {
        what about app ???
    }

thanks

Nifty isn’t jME specific so it doesn’t use jME-specific classes. You can easily pass anything via a constructor or by implementing AppState as well though.

yes but the problem is that I cant pass it the constructor since the controller is created by nifty itself

 <controlDefinition name="buttonComponent" controller="mygame.gui.CommandButtonController" >

so far i use GameAppState.getInstance().dosomstuff()

But you CAN give nifty preinstantiated versions of your classes so that it doesn’t create empty ones…

really ? how

it is only possible with screencontrollers
nifty.registerScreenController(new OptionsScreenController(randomConstructorArgument));
nifty.addXml(“Interface/Screens/OptionsScreen.xml”);
not with controls AFAIK

you mean a static varialble in the controller class ???

Yeah, it is only screen controllers that you can inject this way. I guess the screen controller could go through all of the elements on bind and inject other stuff.

I don’t know, really, as I stopped using nifty like 3 years ago or more and never looked back.

stopped using nifty, … like there is an alternative ? cos nifty…pfff is not always “that nifty” :stuck_out_tongue:
like this one : Niftygui setVisible seems recursive

I wrote Lemur as my own nifty replacement… though it aims at a slightly different target. There is also JavaFX and tonegodGUI.

If you end up being curious, Lemur related links are here:

It does 3D or 2D guis.

I used it for all of these, for example:

And the HUDs for things like SimArboreal (and most of my other demos, actually):

It tries to be the components to implement other GUIs on top of by having several modular pieces. It still doesn’t implement every GUI control yet (no combo box yet, for example).

JavaFX is probably the most ‘mature’ alternative to nifty right now… but it’s strictly 2D.

still nice, actualy I got an overlay viewport that already displays 3D objects, maybe I could use that :smile:
ok thanks mate