I've been working on a GUI however i'm definitly no were near completed but i've been working off of the example from New Integrating FengGUI with jME - by Unfair however i'm using gamestates. I usually create a seperate class and then in the same class create a public static class however i've been having slight issues attaching the rootnode to attachChild i'm unsure of what i should return in the class i do know i have to call a spatial but not sure how i should go about it.
here is the portion of the code before i attempted to create the gamestate from also i want to impliment a single boolean i can call in order to change a couple values around however i could properly figure that out. Can anyone assist
...
FengJMEInputHandler input;
org.fenggui.Display disp; // FengGUI's display
// Create the GUI
disp = new org.fenggui.Display(new org.fenggui.binding.render.lwjgl.LWJGLBinding());
input = new FengJMEInputHandler(disp);
//LabelExample GUI = new LabelExample();
//GUI.buildGUI(disp);
//display.getRenderer().setBackgroundColor(ColorRGBA.red);
initGUI(disp, false);
}
///////////////////////////////////////////////////////////////GUI STARTS////////////////////////////////////
/**
* Create our GUI. FengGUI init code goes in here
*
*@param Display display, boolean GameStarted(adds functionality and scaling if game started)
*/
protected void initGUI(Display display, boolean GameStarted)
{
// Grab a display using an LWJGL binding
// (obviously, since jME uses LWJGL)
input = new FengJMEInputHandler(disp);
//Initialize the window
final Container mainMenuContainer = new Container();
mainMenuContainer.getAppearance().add(new PlainBackground(Color.RED));
//mainMenuContainer.getAppearance().setPadding(new Spacing(90, 90));
mainMenuContainer.setLayoutManager(new RowLayout(true));
//Initialize the menu and set up appearences
Menu mainMenu = new Menu();
//random colors to see what each one does
mainMenu.getAppearance().setHoverColor(Color.BLUE);
mainMenu.getAppearance().setColor(Color.BLACK);
mainMenu.getAppearance().setSelectionColor(Color.GREEN);
//mainMenu.getAppearance().setHoverUnderlay()
//Initialize menu components
mainMenu.addItem(gameMenu(disp, "Game"));
mainMenu.addItem(multiplayerMenu(disp,"Multiplayer"));
mainMenu.addItem(optionsMenu(disp,"Options"));
//Shows end game Menu if game is active
if (GameStarted!=false) {mainMenu.addItem(endGameMenu(disp,"End Game"));}
mainMenu.addItem(endProgram(disp,"End Program"));
mainMenuContainer.addWidget(mainMenu);
mainMenuContainer.pack();
disp.addWidget(mainMenuContainer);
// Update the display with the newly added components
disp.pack();
}
private MenuItem gameMenu(final Display d, final String s){
MenuItem gameItem = new MenuItem(s);
//Initialzie GameWindow
gameItem.addMenuItemPressedListener(new IMenuItemPressedListener(){
public void menuItemPressed(MenuItemPressedEvent menuItemPressedEvent)
{
//Sets up the Window
Window mainMenu = FengGUI.createWindow(d, false, false, false, true);
mainMenu.removeAllWidgets();
mainMenu.addWidget(mainMenu.getTitleBar());
mainMenu.setTitle(s);
mainMenu.setPosition(new Point(d.getWidth()/2,d.getHeight()/2));
mainMenu.setMovable(false);
mainMenu.setResizable(false);
mainMenu.setLayoutManager(new RowLayout(false));
//Sets up the Menu
Menu gameMenu = new Menu();
MenuItem Continue = new MenuItem("Continue");
MenuItem newGame = new MenuItem("New game");
gameMenu.getAppearance().add(new PlainBackground(Color.WHITE_HALF_TRANSPARENT));
gameMenu.addItem(Continue);
gameMenu.addItem(newGame);
//Attach the Menu to the window
mainMenu.addWidget(gameMenu);
mainMenu.pack();
// Update the display with the newly added components
d.pack();
}});
return gameItem;
}
private MenuItem multiplayerMenu(Display d, String s){
MenuItem multiplayerMenu = new MenuItem(s);
return multiplayerMenu;
}
private MenuItem optionsMenu(Display d, String s){
MenuItem optionsMenu = new MenuItem(s);
// need to figure a way to set up a container
return optionsMenu;
}
private MenuItem endGameMenu(Display d, String s){
MenuItem endGameMenu = new MenuItem(s);
return endGameMenu;
}
private MenuItem endProgram(final Display d, final String s){
MenuItem endProgram = new MenuItem(s);
//initializes End Program Window;
endProgram.addMenuItemPressedListener(new IMenuItemPressedListener(){
public void menuItemPressed(MenuItemPressedEvent menuItemPressedEvent)
{
//remember to change how this exits when implimented
try {
gameWindow(d, s);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}});
return endProgram;
}
private Window gameWindow(Display d, String s)throws java.lang.InterruptedException {
//Sets up the Window
Window mainMenu = FengGUI.createWindow(disp, false, false, false, true);
mainMenu.removeAllWidgets();
mainMenu.addWidget(mainMenu.getTitleBar());
mainMenu.setTitle(s);
mainMenu.setPosition(new Point(disp.getWidth()/2,disp.getHeight()/2));
mainMenu.setMovable(false);
mainMenu.setResizable(false);
mainMenu.setLayoutManager(new RowLayout(false));
//Sets up the exit Label
Label endProgramLabel = FengGUI.createLabel("Program will end in ");
//initialize count down
CountDown endGameCounter = new CountDown(15, mainMenu);
rootNode.addController(endGameCounter);
//endGameCounter.update(12);
Label second = FengGUI.createLabel(Float.toString(endGameCounter.countDownValue));
//Attach the Label to the window
mainMenu.addWidget(endProgramLabel);
mainMenu.addWidget(second);
mainMenu.pack();
// Update the display with the newly added components
disp.pack();
return mainMenu;
}
///////////////counter//////////////////
class CountDown extends Controller {
private float elapsedTime = 0.0f;
private float totalTime;
private Container fengContainer;
private Widget lastLabel = null;
public CountDown(float totalTime, Container fengContainer) {
this.totalTime = totalTime;
this.fengContainer = fengContainer;
}
public float countDownValue = totalTime - elapsedTime;
public void update(float tpf) {
elapsedTime += tpf;
if(countDownValue < 0.0f)
countDownValue = 0.0f;
// Ideally you would update update the text of the label instead of creating a new one as done below.
// Without code in front of me I couldn't do it for you, but I know you can.
if(lastLabel != null)
fengContainer.removeWidget(lastLabel);
lastLabel = FengGUI.createLabel(Integer.toString((int)countDownValue));
fengContainer.addWidget(lastLabel);
if(countDownValue == 0.0f)
setActive(false);
}
}
////////////////////////////////////////////////////GUI ENDS//
/*
FengGUI
I have added FengGui game state to my project and it works fine, but renders under the other game state. I have tried adding the FengGui gamestate first and last, and it doesn't matter?
It doesn't render 'after' because you need to flush the queue, call Renderer.renderQueue(), after the first pass finishes. If you have an InGameState and a GUIGameState, you need to put the statement after all your code in the InGameState render method:
DisplaySystem.getDisplaySystem().getRenderer().renderQueue();
You need to flush the queue at the end of your IngameGameState render method. The FengGUI GameState needs to be added after the IngameGameState. If this doesn't work, try clearing the Zbuffer after rendering (in IngameGameState.render) with Renderer.clearZBuffer, then it SHOULD work if the GameStates are rendered in the correct order.
///////////////////////////////////////