Hi,
I have been using nifty and I have defined it in the initialize() method of one of my AppState(which implements ScreenController) as follow.
[java] niftyDisplay = new NiftyJmeDisplay(app.getAssetManager(), app.getInputManager(), app.getAudioRenderer(), app.getGuiViewPort());
// Create a new nifty GUI object
nifty = niftyDisplay.getNifty();
// Read your XML and initialize your custom ScreenController
nifty.fromXml("Interface/startScreen.xml", "startScreen", this);
nifty.addXml("Interface/moduleScreen.xml");
app.getGuiViewPort().addProcessor(niftyDisplay);
[/java]
However I’m not clear when in which thread nifty’s GUI renders because when I try to do any computations in the same AppState OnClick() methods related to nifty, it simply blocks the GUI rendering.
Say for example, I have the following code
[java] public void onQuit() {
System.out.println(“On Quit!!”);
de.lessvoid.nifty.elements.Element niftyElementButton = nifty.getScreen("endScreen").findElementByName("QuitModuleButton");
de.lessvoid.nifty.elements.Element niftyElement = nifty.getScreen("endScreen").findElementByName("score");
niftyElementButton.disable();
// DOING VERY COMPUTATIONAL PROCESS OR
// DOING NETWORK COMMUNICATION THAT HAS POTENTIAL TO BLOCK OR
// Thread.sleep(10000);
}[/java]
The niftyElementButton.disable(); action does not reflect instantly. I tried doing app.enqueue() and it works well but when I write another app.enqueue() inside the previous again my process blocks.
The functionality that I want is when he clicks OnQuit(), the button should immediately disable so that he can’t press it again. Then I want to do some network communication (which can take time). Mean while nifty should display “Please Wait” in one of the Label elements. Uptill this time all good using app.enqueue(). Then I want if the network communication is successful, there should be a message that “Your communication was successful”. Then after a 10s delay the application should exit automatically. Displaying the “You communcation was …” and making sleep requires anoteher app.enqueue() which will nest in the previous callable. Somehow this don;t work and it again blocks and the message “Your commnicat…” never appears.