For reference, I’m using Lemur. Basically, I’ve gotten the GUI to work in plenty of places, but for some reason it doesn’t show up here. On initialize of the actual game (upon hitting “play”), the function guiSetup
is called, which just builds the gui and attaches it to the guiNode. Just to start, the gui code is exactly the same as the pause gui (though it will become the HUD/controls). I’ve gone through the debugger, and I see the state initialized, the guiNode fetched, the guiSetup function runs, the Lemur Container layout is attached, along with its three buttons, and the game runs. But there is no GUI there. Have I hidden it somehow? No cleanup or enabled(false) calls are being made, as far as I could see, and the location of the container placement works just fine for the pause state. Here’s what I’ve written:
public GamePlayState(int wwidth, int wheight){
width = wwidth;
height = wheight;
}
private boolean loading = false;
@Override
public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
System.out.println("INIT");
// Initializes main variables
this.app = ((SimpleApplication)app);
rootNode = ((SimpleApplication)app).getRootNode();
guiNode = ((SimpleApplication)app).getGuiNode(); // !!!
assetManager = ((SimpleApplication)app).getAssetManager();
inputManager = ((SimpleApplication)app).getInputManager();
flyCam = ((SimpleApplication)app).getFlyByCamera();
cam = ((SimpleApplication)app).getCamera();
bas = stateManager.getState(BulletAppState.class);
// bunch of setup that works fine imo ...
rootNode.attachChild(track);
// Camera setup
camSetup(false);
guiSetup(); // !!!
// other stuff that works fine imo
}
private void guiSetup(){
// guiNode.addControl(new InGameGUIControl(input));
System.out.println(width);
System.out.println(height);
BitmapFont myFont = app.getAssetManager().loadFont("Interface/Fonts/PerfectDark(BRK).fnt");
GuiGlobals.initialize(app);
// Load the 'glass' style
// BaseStyles.loadGlassStyle();
// Set 'glass' as the default style when not specified
// GuiGlobals.getInstance().getStyles().setDefaultStyle("glass");
Styles styles = GuiGlobals.getInstance().getStyles();
Attributes attrs;
// My styles
QuadBackgroundComponent bg = new QuadBackgroundComponent(ColorRGBA.Blue);
// TbtQuadBackgroundComponent realborder = TbtQuadBackgroundComponent.create(assetManager.loadTexture("Textures/test9patchtex.png"), 1, 5,5, 234,234,0,false);
TbtQuadBackgroundComponent realborder = TbtQuadBackgroundComponent.create(app.getAssetManager().loadTexture("Textures/GUI/test_blur_patch.png"), 1, 39,39, 256-39,256-39,1,false);
// TbtQuadBackgroundComponent realborder = TbtQuadBackgroundComponent.create(assetManager.loadTexture("Textures/controls_button.png"), 1,35,35, 342,158,0,false);
// TbtQuadBackgroundComponent realbg = TbtQuadBackgroundComponent.create(assetManager.loadTexture("Textures/inflicted.png"), 1, 10,10, 229,229,0,false);
QuadBackgroundComponent realbg = new QuadBackgroundComponent(ColorRGBA.DarkGray);
QuadBackgroundComponent pink = new QuadBackgroundComponent(ColorRGBA.Pink, 10, 10);
realbg.setMargin(10, 10);
float em = (float)width/100;
attrs = styles.getSelector("container", null);
attrs.set("fontSize", 5 * em);
attrs.set("background", realborder);
attrs.set("font", myFont);
attrs = styles.getSelector("button", null);
attrs.set("fontSize", 5 * em);
attrs.set("border", realborder);
attrs.set("font", myFont);
attrs = styles.getSelector("panel", null);
attrs.set("fontSize", 5 * em);
attrs.set("border", realborder);
attrs.set("font", myFont);
// Actual GUI
Container pauseLayout = new Container();
guiNode.attachChild(pauseLayout);
pauseLayout.setLocalTranslation((float)width * 0.4f, 0.7f * (float)height, -1);
// pauseLayout.setLocalTranslation(10,10, 0);
Button resume = new Button("resume");
resume.addClickCommands(new Command<Button>(){
@Override
public void execute(Button source){
setEnabled(false);
app.getStateManager().detach(app.getStateManager().getState(PauseState.class));
}
});
Button restart = new Button("restart");
restart.addClickCommands(new Command<Button>(){
@Override
public void execute(Button source){
setEnabled(false);
app.getStateManager().detach(app.getStateManager().getState(PauseState.class));
}
});
Button quit = new Button("Quit");
quit.addClickCommands(new Command<Button>(){
@Override
public void execute(Button source){
setEnabled(false);
app.getStateManager().detach(app.getStateManager().getState(PauseState.class));
}
});
pauseLayout.addChild(resume);
pauseLayout.addChild(restart);
pauseLayout.addChild(quit);
pauseLayout.scale(0.8f);
}