Nifty Gui Help

Hi Guys,

I seem to be strugling my way through trying to workout how to use nifty-gui. It seems really troublesome when there appears no javadoc or full api spec.

Currently I`m trying to workout how to clear the screen after screen transitions.

One screen has a fullscreen backdrop, the other does not.

When I transition between screens (from fullscreen to the other), the fullscreen backdrop still displays.

I have tried the following in the screenController when I click on a particular button.



[java]

nifty.getNifty().fromXml("main.xml", "mainLogin");

nifty.getNifty().render(true);

[/java]



However I get the following exception thrown.



[java]

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.util.ConcurrentModificationException

[/java]



Does anyone happen to know how I can achieve what I am attempting (to clear/flush the screen between transitions)?



Thanks.

How are you setting the background?

I had exactly the opposite problem. I wanted the same background on every screen in my main menu setup but ended up including the background as a layer on every screen.



Edit: also… do you have the stack trace for the concurrent mod exception?

The background is simply set as a panel with length/width = 100% like follows



[xml]

<panel id="backdrop" height="100%" width="100%" backgroundColor="#f60f" childLayout="horizontal" visibleToMouse="true">

[/xml]



The full stacktrace is as follows:

[java]

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.util.ConcurrentModificationException

at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)

at java.util.AbstractList$Itr.next(AbstractList.java:343)

at com.jme3.niftygui.InputSystemJme.forwardEvents(InputSystemJme.java:116)

at de.lessvoid.nifty.Nifty.render(Nifty.java:163)

at com.jme3.niftygui.NiftyJmeDisplay.postQueue(NiftyJmeDisplay.java:136)

at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:660)

at com.jme3.renderer.RenderManager.render(RenderManager.java:687)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:216)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:144)

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:141)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:198)

at java.lang.Thread.run(Thread.java:662)

[/java]

Hello,

I’ve you tried something like that :

[java]

final Nifty nifty = …;

application.enqueue( new Callable<Object>() {

public Object call() {

nifty.exit();

nifty.fromXml(“main.xml”, “mainLogin”);

}

[/java]



I think all structural changes on Nifty screen should be done in the main loop.



In my case I have forfeit to use more than one screen.

I’ve transformed all my previous screen into custom control.



That way, when I want to switch screen, I juste have to hide, or remove the provious control from my screeen and add the new one.

The method Nifty.render() is not meant to be called directly…

I figured, but I couldn’t see any other remotely suitable functions to flush the screen/display for nifty.

I`ll try the method you have outlined didialchichi. :slight_smile: Thanks.

I tried as you had mentioned, but it still did not clear the screen o_0, I think at this stage hiding and showing layers (acting as if they were screens) will be the way I will go.

@Momoko_Fan Do we still need to use xml file for making GUI? wasn’t java supposed to be enough for doing the whole xml stuff after Nifty 1.3 implementation?

@iamcreasy

It’s right that we can now use JAVA to create the screens. But it doesn’t mean that the XML way became deprecated.

In my point of view, XML is still a good option :

People creating the assets and people creating the code can be different and I like the idea of having more than one possible display for a screen. ( depending of the prenferences of the user )

@shanec :

Well, I think its best not to paly with the creation of nifty displays.

Keeping only one screen, and managing its content via layers and panels is a wise decision, in my point of view.

If you still want tp have separate files for your “layers”, transform your current ‘screen’ into ‘controlDefinition’

iamcreasy said:
@Momoko_Fan Do we still need to use xml file for making GUI? wasn't java supposed to be enough for doing the whole xml stuff after Nifty 1.3 implementation?

You can create nifty guis by using the XML or by writing Java code. You can also choose not to use either and do it via jME3 gui node.

Guys, you think too much inside your code. The reason for css on the web is the same as using XML for the GUI. You can design it after the code has been written, without changing anything to the code. Even a designer could improve your UI. So you should lay out the basic blocks of you UI in XML and then modify this basis dynamically using code. Even if it seems easier to you while writing the code to just say “open window here” its not anymore when the game has really grown and the UI is modified/constructed from all ends of code… Thats where you will happily open your XML file to make the right bar just take 10% of the screen… Instead of modifying at least 10 lines of code. So yes, we do need the XML :stuck_out_tongue:

1 Like

I currently use a seperate XML for each screen and it works like a charm. All I do to switch to the new scrreen, in the new xml is this:



nifty.fromXml(CONFIGURATION_NIFTY_ROOT + dsMsg.getScreenName() + XML_EXT, dsMsg.getScreenName());



No call to Nifty.exit(), no call to Nifty.update(). just Nifty.fromXML() and everything works as it should.