[Nifty] Redirecting first screen under certain condition - Solved

Hi!



Now I’m able to creae some simple gui with Nifty!



But there is one thing I don’t understand how I have to implement it :



Context :

I’m creating a toolbar who loads other UI when you give it the xml file name.



Here is how it works ( or how I think it works ) :



[java]

#GameApplication:init# loadGUI( fileName )

#GameApplication:loadGUI# Nifty nifty = new Nifty()

#GameApplication:loadGUI# nifty.fromXml( fileName, DEFAULT_STARTSCREEN )



#MyGUIController:bind# MyToolbar.registerController(this)

#MyToolbar:registerController# store Controller and create an icon in the toolbar corresponding to it



#GameApplication:loadGUI# guiViewPort().addProcessor(niftyDisplay);

[/java]



The DEFAULT_STARTSCREEN is in fact a screen with nothing with the only purpose to register itself to the toolbar when opened.

This way, when adding a GUI, it starts hidden.

When you want it to appears, you just have to click on the corresponding icon in the toolbar.



It works fine but …



I want some GUI to starts not hidden.

So I change the code for those controllers :

[java]

#GameApplication:init# loadGUI( fileName )

#GameApplication:loadGUI# Nifty nifty = new Nifty()

#GameApplication:loadGUI# nifty.fromXml( fileName, DEFAULT_STARTSCREEN )



#MyGUIController:bind# MyToolbar.registerController(this)

#MyToolbar:registerController# store Controller and create an icon in the toolbar corresponding to it



#MyGUIController:bind# nifty.gotoScreen( “realStartScreen” )



#GameApplication:loadGUI# guiViewPort().addProcessor(niftyDisplay);

[/java]



But nifty.gotoScreen( “realStartScreen” ) doesn’t seem to work inside the bind method.



I tried to add it inside the onStartScreen method :

[java]

@Override

public void onStartScreen() {

this.nifty.gotoScreen( STARTSCREEN );

}

[/java]

That time it work but … each time I want to come back to the DEFAULT_STARTSCREEN, it redirects me on the STARTSCREEN :frowning:



I think I can come up with a tip like

[java]

@Override

public void onStartScreen() {

if( firstTime )

this.nifty.gotoScreen( STARTSCREEN );

}

[/java]

But it’s not really clean.



Is there an other way to do it?



Thanks in advance.

Finally, this solution will satisfy me :

[java]

@Override

public void onStartScreen() {



if( !sheetInitialized && ! startHidden() )

{

this.nifty.gotoScreen( STARTSCREEN );

}

sheetInitialized = true;

}

[/java]