[SOLVED] GUI Problem with Lemur and AbstractAppStates

Hey guys,

so the Problem is the following:
I am in the MainMenu of my game which is a 3D Menu. It looks something like this.


When pressing the Start Button i switch into my GameState. It then looks like this.

Now initally shooting was bound to the Spacebar, right now the following problem occurs:
If i press spacebar event which is bound to the Start button from the main menu gets executed again. This leads to the problem that the complete GameState gets called again and also my CostomInput class.
This idea behind this was to seperate the MainMenu control from the ingame controls. The MainMenu control only uses the standard input from Lemur i guess, atleast thats how i understand it for now. The ingame controls are however seperated and are organized in an extra class which is being initialized when switching into the GameState.

It sounds like the start button is focused by lemur since it was the last button you clicked before starting the game, and then pressing spacebar will execute a click action on whatever is the current focus.

If that is the case, then you should be able to clear the focused button when the game starts with some code like this

GuiGlobals.getInstance().getFocusManagerState().setFocus(null);

So in your game you want the menu and cursor to still work but also for the space bar to do things in the game?

Normally games go from “menu open, mouse + keys interact with menu” to “playing game, menu no longer open, mouse and keys not longer interact with menu”. In that scenario, this would all be automatic.

If you have the clickable menus open at the same time the game is played then it might be best to just disable menu navigation completely.
GuiGlobals.getInstance().getFocusNavigationState().setEnabled(false);

Note: if you really are extending AbstractAppState then you are using old code and should be extending BaseAppState instead. Else you will have to keep track of and manage all of the lifecycle details yourself and are bound to get some of it wrong sometimes. Extending BaseAppState is the recommended way.

…and then you also could have used (from your app state):
getState(FocusNavigationState.class).setEnabled(false);

That is not available using the old (should probably be deprecated) AbstractAppState.

Note 2: it’s also possible to just unmap the space bar from FocusNavigationFunctions.F_ACTIVATE

1 Like

Thanks for the help guys it finally worked, appreaciate the help. :+1:

1 Like