Menu with SubMenues do not close correctly on clicking not into the menue

Hello folks,

i have this issue which i ignored for a long time where i hope that someone could help me with. So basically i have a menu with 3 or 5 items where 2 of them are submenues and these submenues contain ~5 elements. When i navigate to one of thes subMenues the only choice to get this subMenue closed is to get the focus on it and go back with the mouse to the parentMenue or click an item of it.

Here my example:
This is the menue with submenues:

after click to somewhere:

what it should look like:

This is the Menu class:

 private class MainMenue extends Menu {
     MainMenue(Screen screen, Vector2f position, boolean isScrollable) {
     Menu menuActions = new ActionsMenue(screen, Vector2f.ZERO, false);
                menuSettings.addMenuItem("Lock Gui", null, null, true, true);
                menuSettings.addMenuItem("ChatBox", null, null, true, false);
                // Add a menu item
                addMenuItem("Pause", null, null);
                addMenuItem("Actions", null, menuActions);
                addMenuItem("Settings", null, menuSettings);
                addMenuItem("Exit", null, null);
    }

 public void onMenuItemClicked(int index, Object value, boolean isToggled) {
            switch (index) {
                case 0:
                    application.stop();
                    break;
            }
        }
    }

This is how i create and pop up the menu:

menu = new MainMenue(screen, Vector2f.ZERO, false);
screen.addElement(menu);
 ButtonAdapter buttonOptions = new ButtonAdapter(screen, new Vector2f(panelBorders.y, panelBorders.x)) {
            @Override
            public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
                menu.showMenu(null, getAbsoluteX(), getAbsoluteY() - menu.getHeight() * 0.5f);
            }
        };
        buttonOptions.setWidth(2 * labelWidth);
        buttonOptions.setText("Menue");

[EDIT] See below for answers as this one is wrong (keept for records sake)

Hi,
it is fixed but it run under jme3.1, i’ve ended doing a build :

On the other hand you can fix it by-yourself by Overriding the “hide” methode of you menu and make a call to “hideAllSubmenus(false)”, here is my test case :

public class MenuDebug extends Menu {

    MenuDebug(Screen screen, Vector2f position, boolean isScrollable) {
        super(screen, position, isScrollable);

        // Action menu item
        Menu menuActions = new Menu(screen, Vector2f.ZERO, false) {
            @Override
            public void onMenuItemClicked(int index, Object value, boolean isToggled) {
                System.err.println("Hello Action : " + value);
            }
        };
        menuActions.addMenuItem("Lock Gui", null, null, true, true);
        menuActions.addMenuItem("ChatBox", null, null, true, false);

        // Settings menu item
        Menu menuSettings = new Menu(screen, Vector2f.ZERO, false) {
            @Override
            public void onMenuItemClicked(int index, Object value, boolean isToggled) {
                System.err.println("Hello Settings : " + value);
            }
        };
        menuSettings.addMenuItem("Screen Size", null, null, true, true);
        menuSettings.addMenuItem("Shaker", null, null, true, false);

        // Add a menu item
        addMenuItem("Pause", null, null);
        addMenuItem("Actions", null, menuActions);
        addMenuItem("Settings", null, menuSettings);
        addMenuItem("Exit", null, null);
    }

    @Override
    public void onMenuItemClicked(int index, Object value, boolean isToggled) {
        switch (index) {
            case 0:
                System.err.println("Stop App");
                break;
        }
    }
    
    @Override
    public void hide() {
        super.hide();
        hideAllSubmenus(false);
    }
}
2 Likes

i tried a lot of things to get this problem fixed… but such an easy fix ^^. Thank you very much

Hi, thanks for trying to maintain tonegodgui. In your git, you have two branches, 3.1 and master. Is master just maintained for 3.0 and 3.1 just for 3.1? Are there any major differences besides the 3.1 branch working on jme 3.1?

3.0 and 3.1 are the same, no difference as currently as i got no plan for api improvement, just want to take care of some stuff with the little i can.
Concerning API improvement and new feature you might check this thread with the @atomix fork he planned some nice stuff.
link : Tonegodgui now gradlefied and moved to GitHub
hope it help.

Oh i have to refuse the fix :(. After applying it, the elements of submenue wheren’t clickable anymore.

I’m dumb as hell…
There is no bug in fact it is just that you need to add the menu Item to the screen also to let the screen know about the item and update it properly.
Template :

public class MenuDebug extends Menu {

    MenuDebug(Screen screen, Vector2f position, boolean isScrollable) {
        super(screen, position, isScrollable);

        // Action menu item
        Menu menuActions = new Menu(screen, Vector2f.ZERO, false) {
            @Override
            public void onMenuItemClicked(int index, Object value, boolean isToggled) {
                System.err.println("Hello Action : " + value);
            }
        };
        menuActions.addMenuItem("Lock Gui", null, null, true, true);
        menuActions.addMenuItem("ChatBox", null, null, true, false);
        screen.addElement(menuActions); // add this

        // Settings menu item
        Menu menuSettings = new Menu(screen, Vector2f.ZERO, false) {
            @Override
            public void onMenuItemClicked(int index, Object value, boolean isToggled) {
                System.err.println("Hello Settings : " + value);
            }
        };
        menuSettings.addMenuItem("Screen Size", null, null, true, true);
        menuSettings.addMenuItem("Shaker", null, null, true, false);
        screen.addElement(menuSettings);  // add this

        // Add a menu item
        addMenuItem("Pause", null, null);
        addMenuItem("Actions", null, menuActions);
        addMenuItem("Settings", null, menuSettings);
        addMenuItem("Exit", null, null);
    }

    @Override
    public void onMenuItemClicked(int index, Object value, boolean isToggled) {
        switch (index) {
            case 0:
                System.err.println("Stop App");
                break;
        }
    }
}
1 Like

Thanks this worked :).