(GBUI) Menu not working

Hi,



i made this menu (taking a look at aTechnique). Yet, when i start the game and the menu should appear, nothing except the mouse is being displayed. There's no error in the console.

If i click with my mouse anywhere on the screen, the game (application) freezes.





Is this because aTechnique has some problems, or did i forgot something in my code?

Any advice would be great :slight_smile:





import java.util.concurrent.Callable;

import com.jme.input.MouseInput;
import com.jme.renderer.Renderer;
import com.jme.system.DisplaySystem;
import com.jme.util.GameTaskQueueManager;
import com.jme.util.Timer;
import com.jmex.bui.BButton;
import com.jmex.bui.BComponent;
import com.jmex.bui.BDecoratedWindow;
import com.jmex.bui.BImage;
import com.jmex.bui.BWindow;
import com.jmex.bui.BuiSystem;
import com.jmex.bui.PolledRootNode;
import com.jmex.bui.background.ImageBackground;
import com.jmex.bui.enumeratedConstants.ImageBackgroundMode;
import com.jmex.bui.layout.TableLayout;
import com.jmex.bui.util.Point;
import com.jmex.game.state.BasicGameState;

public class GBuiMenu extends BasicGameState {

   private BWindow window;

   public GBuiMenu() {
      super("Menu");
      MouseInput.get().setCursorVisible(true);

      // init GBUI
      BuiSystem.init(new PolledRootNode(Timer.getTimer()), "/data/rsrc/style2.bss");

      // init the window-container
      window = new BDecoratedWindow(BuiSystem.getStyle(), "Menu");
      TableLayout layout = new TableLayout(1, 10, 0);
      layout.setEqualRows(true);
      layout.setHorizontalAlignment(TableLayout.CENTER);
      window.setLayoutManager(layout);
      window.setSize(DisplaySystem.getDisplaySystem().getWidth() / 2, DisplaySystem.getDisplaySystem()
            .getHeight());

      // background image for the menu
      try {
         GameTaskQueueManager.getManager().update(new Callable<Object>() {
            public Object call() throws Exception {
               BImage image = new BImage(getClass().getClassLoader().getResource(
                     "data/images/menu_background.png"));
               window.setBackground(BComponent.DEFAULT, new ImageBackground(
                     ImageBackgroundMode.SCALE_XY, image));
               return null;
            }
         }).get();
      } catch (Exception e) {
         e.printStackTrace();
      }

      // init the main menu
      buildMainMenu();
      
      rootNode.attachChild(BuiSystem.getRootNode());
      rootNode.setRenderQueueMode(Renderer.QUEUE_ORTHO);
      rootNode.updateRenderState();
   }

   private void buildMainMenu() {
      // buttons
      BButton btnResumeGame = new BButton("Resume Game");
      BButton btnSingleplayer = new BButton("Singleplayer");
      BButton btnMultiplayer = new BButton("Multiplayer");
      BButton btnOptions = new BButton("Options");
      BButton btnRules = new BButton("Rules");
      BButton btnHighscore = new BButton("Highscore");
      BButton btnExit = new BButton("Exit");

      // button actions (not done yet)
      
      
      // x,y of component are the lower-left corner
        int startPosY = window.getHeight() - 100;
        int buttonCount = 7;
        int buttonHeight = (int) (startPosY / (1.5f * buttonCount));
        int stepPosY = (int) (buttonHeight * 1.5f);
        int buttonWidth = (int) (window.getWidth() * 0.6f);
        int posX = (window.getWidth() - buttonWidth) / 2;
        int counter = 0;

      window.removeAll();
      window.add(btnResumeGame, new Point(posX, startPosY - stepPosY * counter++));
      window.add(btnSingleplayer, new Point(posX, startPosY - stepPosY * counter++));
      window.add(btnMultiplayer, new Point(posX, startPosY - stepPosY * counter++));
      window.add(btnOptions, new Point(posX, startPosY - stepPosY * counter++));
      window.add(btnRules, new Point(posX, startPosY - stepPosY * counter++));
      window.add(btnHighscore, new Point(posX, startPosY - stepPosY * counter++));
      window.add(btnExit, new Point(posX, startPosY - stepPosY * counter++));
      window.center();
   }

   public void setActive(boolean active) {
      if (active) {
         GameTaskQueueManager.getManager().update(new Callable<Object>() {
            public Object call() throws Exception {
               BuiSystem.addWindow(window);
               window.center();
               BuiSystem.getRootNode().updateRenderState();
               rootNode.attachChild(BuiSystem.getRootNode());
               return null;
            }
         });
      } else {
         // If still active, hide the GBUI portion
         if (window.getRootNode() != null) {
            window.dismiss();
         }
         rootNode.detachChild(BuiSystem.getRootNode());
      }
      super.setActive(active);
   }

}

Senor Simpson fixed the issue with aTechnique late last week, but that doesn't mean there's not something wrong with your code :wink:



What code are you using to call the code you posted?

Im using BaseGame as the main Class:



public class myGame extends BaseGame {

...
...
...

protected final void initGame() {

      instance = this;
      display.setTitle("myGame");

      // Creates the GameStateManager. Only needs to be called once.
      GameStateManager.create();
      
      GameState menu = new GBuiMenu();
      menu.setActive(true);
      GameStateManager.getInstance().attachChild(menu);
   }
}

This was what you resolved via PM, correct @papercut?