Problems with GBUI and Gamestates

Hello,



I'm afraid I'm going mad here and could use some help. Inspired by the tutorials here http://code.google.com/p/gbui/wiki/CreatingYourJmeInterfaceUsingGbui5 I tried to setup a MenuGamestate and … well it doesn't work… :frowning:



Here is the part where i create my gamestates:


        MainMenuView mainMenu = new MainMenuView();
        MainMenuPresenter mainMenuPresenter = new MainMenuPresenter();
        mainMenu.setListener(mainMenuPresenter);
        gsManager.attachChild(mainMenu);

        InGame inGame = inGameProvider.get();
        gsManager.attachChild(inGame);

        stateManager.start(mainMenuPresenter);



The method call of  stateManager.start(mainMenuPresenter); gets propagated through to a this.setActive(true) in MainMenuView, however the Gamestate does not appear as active when queried with:


logger.info("MainMenu isActive: " + GameStateManager.getInstance().getChild("MainMenuView").isActive());



This is of course at the moment only a minor hindrance because when i set the state to active manually, it does appear as active. However the most pressing problem is: Nothing gets rendered to the screen. Here is my gamestate:


public class MainMenuView extends BasicGameState implements IMainMenuView {

    private final Logger logger = Logger.getLogger(this.getClass().getName());
    private DisplaySystem display;
    private InputHandler input;
    private BWindow buiWindow;
    private IMainMenuListener listener;

    public MainMenuView() {
        super("MainMenuView");
        display = DisplaySystem.getDisplaySystem();
        input = new InputHandler();
        defineControls();
        BuiSystem.init(new PolledRootNode(Timer.getTimer(), input), "/gui/appearence.bss");
        getRootNode().attachChild(BuiSystem.getRootNode());
        GameTaskQueueManager.getManager().update(new Callable() {

            @Override
            public Object call() {
                setupWindow();
                return null;
            }
        });
        rootNode.setLightCombineMode(LightCombineMode.Off);
        rootNode.setRenderQueueMode(Renderer.QUEUE_ORTHO);
        rootNode.updateRenderState();
        rootNode.updateGeometricState(0, true);
    }



The method setupWindows ends with:


    BuiSystem.addWindow(buiWindow);



I am really very desperate and could use any Help. I made probably a very simple mistake.

Thank You,
    ---Florian

Can you show us a little more code, maybe enough to run you app? That would help alot.

Hi,



after telling this forum of my problem and despair I found the mistake I made. I use Guice for dependency injection and attached two instances of the same GameState to the GameStateManager. It didn't work out of course. So after scoping my GameStates as singletons everything works like a charm. Thank You all for listening! :slight_smile:



A happy new Year,

— Florian 

Glad your up and running again.

I don't know how I missed this topic, could've been vacation… but your Singleton approach is correct.  I've used GBUI in many GameState works without a problem.



Glad to see that you got it working.



timo

Hello



I’m using StandardGame. i have two game states - Menu (with gbui, i started working on it  ) ang Game (with the rest). At start i’m creating only a menu state and it shows corectly (look here for screen shot http://img25.imageshack.us/img25/4288/200908301836041280x800s.png ).

Then if i press “Start game” button, it creates the second GameState “Game” and activates only that GameState. It’s also work ok.

But then if i try to switch back to my menu, it’s look not correctly (look here http://img337.imageshack.us/img337/9941/200908301830411280x800s.png ). Where i’m making errors?? Here is code for Menu





public class Menu extends BasicGameState {



   private BWindow window;



   public Menu() {

      super(“Menu”);

      // show mouse cursor

      MouseInput.get().setCursorVisible(true);



      // init GBUI

      BuiSystem.init(new PolledRootNode(Timer.getTimer()),

            “/rsrc/style2.bss”);

      

      // create the GUI

      createGUI();

   }



   private void createGUI() {

      window = new BDecoratedWindow(BuiSystem.getStyle(), “Menu”);

      TableLayout layout = new TableLayout(1, 10, 0);

      layout.setEqualRows(true);

      layout.setHorizontalAlignment(TableLayout.STRETCH);

      window.setLayoutManager(layout);

      window.setSize(DisplaySystem.getDisplaySystem().getWidth()/2,

            DisplaySystem.getDisplaySystem().getHeight());



      final BButton btnNewGame = new BButton(“New game”);

      final BButton btnResumeGame = new BButton(“Continue game”);

      final BButton btnExit = new BButton(“Exit”);



      btnNewGame.addListener(new ActionListener() {

         @Override

         public void actionPerformed(ActionEvent event) {

            if (GameStateManager.getInstance().getChild(“Game”) != null) {

               // check if we don’t have a game already running

               GameStateManager.getInstance().detachChild(“Game”);

            }

            btnResumeGame.setEnabled(true);

            GameStateManager.getInstance().attachChild(new Game());

            GameStateManager.getInstance().deactivateAllChildren();

            GameStateManager.getInstance().activateChildNamed(“Game”);

         }

      });



      btnResumeGame.setEnabled(false);

      btnResumeGame.addListener(new ActionListener() {

         @Override

         public void actionPerformed(ActionEvent event) {

            GameStateManager.getInstance().deactivateAllChildren();

            GameStateManager.getInstance().activateChildNamed(“Game”);

         }

      });



      btnExit.addListener(new ActionListener() {

         @Override

         public void actionPerformed(ActionEvent event) {

            System.exit(0);

         }

      });



      try {

         GameTaskQueueManager.getManager().update(new Callable<Object>() {

            public Object call() throws Exception {

               window.add(btnNewGame);

               window.add(btnResumeGame);

               window.add(btnExit);

               window.center();

               BuiSystem.addWindow(window);

               return null;

            }

         });

      } catch (Exception e) {

         e.printStackTrace();

      }

      rootNode.attachChild(BuiSystem.getRootNode());

   }



   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);

   }

}



I’ll be glad for help :slight_smile:



PS:

Sorry for my english

Pablo,

    Did you write the code or pull it from the atechnique source?  (not accusatory, just asking)  There's a bug that I've not identified where yet and it's highly prevalent in aTechnique as well with GameState.  I'll look at your code today and see if I can debug to figure out what's going on…I'm pretty sure it's not going to be with your code, but an existing bug in GBUI that I've been looking at.  Well, actually, I've been out of town and net-less for 3 weeks, but before I left I was looking at it.



I'll put this on my priority list for today.



timo

standtrooper said:

Pablo,
     Did you write the code or pull it from the atechnique source?  (not accusatory, just asking)...
I looked at SimpleGBUITest from jme-demos and made some changes (GBUI has so nice and easy to learn API ;)).

Thanks for help  :)