Nifty gui popups

I can’t get nifty gui popups to work.



This is the xml code of the popup:[java] <popup id=“popup” width=“50%” height=“50%”>

<layer id=“layer” backgroundcolor="#0000" childlayout=“center”>

<panel width=“50%” height=“50%” childLayout=“vertical” backgroundColor="#00FF">

<control name=“label” text=“test” />

</panel>

</layer>

</popup>[/java]This is between the and tags.



and when I use this code, AFTER nifty is initialized and when a screen is displayed, nothing happens:[java]nifty.showPopup(nifty.getCurrentScreen(), “popup”, null);[/java]I have already put a System.out.printline right behind that to see if it was getting called, which does happen.

Are you defining the popup inside the screen tags? It needs to be inside the screen definition.



Be aware if using popups that trying to change screen with a popup open does nasty things at the moment.

now I have this popup xml code, inside the screen that should have the popup. And now as soon as I switch to that screen, nifty.getcurrentscreen() becomes 0, which trows a nullpointerexception in the simpleupdate method because I check that. And that is before opening the popup.

I finally got the popup to work, and I tried converting one of my screens into a popup, but this gives a nullpointerException:[java] nifty.createPopup("Winkel");

nifty.findPopupByName("Winkel").findControl("geld", LabelControl.class).setText("Geld: " + app.geld);

lbc = nifty.findPopupByName("Winkel").findControl("Voorwerpen", ListBoxControl.class);[/java]This is in the MenuController.bind method, and this gets executed right after the screen the popup should overlay is initialized.



This is the code for the popup:[java]<popup id="Winkel" controller="mygame.MenuController" childLayout="center">

<panel width="100%" height="100%" backgroundColor="#0000" childLayout="center">

<control name="window" title="Winkel" width="500px" height="300px" align="center" valign="center" closeable="false">

<panel width="100%" height="100%" childLayout="vertical" backgroundColor="#00FF">

<control name="label" text="Geld: ###################################" id="geld" />

<control id="Voorwerpen" name="listBox" vertical="optional" horizontal="optional" displayItems="4" selection="Single" ForceSelection="true" />

<control name="label" text="Prijs: (selecteer een item)" id="prijs" width="100%" align="left" textHAlign="left" />

<control name="label" text="Beschrijving: (selecteer een item)" id="beschrijving" width="100%" align="left" textHAlign="left" textVAlign="top" height="80px" />

<control name="button" label="Koop item" align="left" visibleToMouse="true">

<interact onClick="koop()" />

</control>

<control name="button" label="Terug" align="left" visibleToMouse="true">

<interact onClick="closeShop()" />

</control>

</panel>

</control>

</panel>

</popup>[/java]



What am I doing wrong?

[java]nifty.createPopup(“Winkel”);[/java] … will create a new element with a new generated id! The findPopupByName() call will not find this popup instance. A better approach would be to simply keep the return value of the nifty.createPopup() call:



[java]Element popup = nifty.createPopup(“Winkel”);

popup.findControl …[/java]



The manual covers that in the chapter “POPUP LAYERS” on page 41-43. And yeah, I know that this is a bit weird but it is what it is (at the moment at least).