Nifty popup fails to register
Posted
by
Snailer
on Game Development
See other posts from Game Development
or by Snailer
Published on 2011-11-07T21:42:40Z
Indexed on
2012/04/04
23:46 UTC
Read the original article
Hit count: 251
gui
|jmonkeyengine
I'm new to Nifty GUI, so I'm following a tutorial here for making popups. For now, I'm just trying to get a very basic "test" popup to show, but I get multiple errors and none of them make much sense. To show a popup, I believe it is necessary to first have a Nifty Screen already showing, which I do. So here is the ScreenController
for the working Nifty Screen:
public class WorkingScreen extends AbstractAppState implements ScreenController {
//Main is my jme SimpleApplication
private Main app;
private Nifty nifty;
private Screen screen;
public WorkingScreen() {}
public void equip(String slotstr) {
int slot = Integer.valueOf(slotstr);
System.out.println("Equipping item in slot "+slot);
//Here's where it STOPS working.
app.getPlayer().registerPopupScreen(nifty);
System.out.println("Registered new popup");
Element ele = nifty.createPopup(app.getPlayer().POPUP);
System.out.println("popup is " +ele);
nifty.showPopup(nifty.getCurrentScreen(), ele.getId(), null);
}
@Override
public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
this.app = (Main)app;
}
@Override
public void update(float tpf) {
/** jME update loop! */
}
public void bind(Nifty nifty, Screen screen) {
this.nifty = nifty;
this.screen = screen;
}
When I call equip(0)
the system prints Equipping item in slot 0
, then a lot of errors and none of the subsequent println()
's. Clearly it botches somewhere in Player.registerPopupScreen(Nifty nifty)
. Here's the method:
public final String POPUP = "Test Popup";
public void registerPopupScreen(Nifty nifty) {
System.out.println("Attempting new popup");
PopupBuilder b = new PopupBuilder(POPUP) {{
childLayoutCenter();
backgroundColor("#000a");
panel(new PanelBuilder() {{
id("List");
childLayoutCenter();
height(percentage(75));
width(percentage(50));
control(new ButtonBuilder("TestButton") {{
label("TestButton");
width("120px");
height("40px");
align(Align.Center);
}});
}});
}};
System.out.println("PopupBuilder success.");
b.registerPopup(nifty);
System.out.println("Registerpopup success.");
}
Because that first println()
doesn't show, it looks like this method isn't even called at all!
Edit
After removing all calls on the Player
object, the popup works. It seems I'm not "allowed" to access the player from the ScreenController
. Unfortunate, since I need information on the player for the popup. Is there a workaround?
© Game Development or respective owner