]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Menu: fix potential bug if a stand-alone non-root dialog were opened via menu_cmd...
authorterencehill <piuntn@gmail.com>
Fri, 28 Feb 2025 18:27:32 +0000 (19:27 +0100)
committerterencehill <piuntn@gmail.com>
Fri, 28 Feb 2025 18:45:12 +0000 (19:45 +0100)
Currently none of such dialogs can be opened in that way because they don't have the name field
set but if e.g. the Mutators dialog had it, then an empty menu would be displayed after closing
the Mutators dialog if opened via menu_cmd directmenu Mutators

Now the menu will be always hidden when closing a dialog that was opened via
menu_cmd directmenu <dialog_name>

This new behaviour is not applied for dialogs opened via
menu_cmd <dialog_name>

qcsrc/menu/command/menu_cmd.qc
qcsrc/menu/item/dialog.qc
qcsrc/menu/item/dialog.qh
qcsrc/menu/menu.qc
qcsrc/menu/menu.qh
qcsrc/menu/xonotic/nexposee.qc
qcsrc/menu/xonotic/rootdialog.qc

index 9c1b9d0c6f7280a0e2deed526302f3bb204d8902..2554f2946ef97e828f0d9cdbc51242dffa36b56f 100644 (file)
@@ -114,7 +114,7 @@ void GameCommand(string theCommand)
                else if (argc == 2 && !close_mode && (!isdemo() || argv(1) == "Welcome")) // don't allow this command in demos
                {
                        m_play_click_sound(MENU_SOUND_OPEN);
-                       m_goto(strcat(filter, argv(1))); // switch to a menu item
+                       m_goto(strcat(filter, argv(1)), true); // switch to a menu item
                }
                else if(argc > 2 && (!isdemo() || argv(1) == "Welcome"))
                {
@@ -132,7 +132,7 @@ void GameCommand(string theCommand)
                                                        bufstr_add(argsbuf, argv(i), 1);
                                                e.readInputArgs(e, argsbuf);
                                                if (!close_mode)
-                                                       m_goto(strcat(filter, s));
+                                                       m_goto(strcat(filter, s), true);
                                        }
                                        if(argsbuf >= 0)
                                                buf_del(argsbuf);
@@ -148,52 +148,17 @@ void GameCommand(string theCommand)
                return;
        }
 
-       if (argv(0) == "nexposee")
+       switch (argv(0))
        {
-               m_goto("nexposee");
-               return;
-       }
-
-       if (argv(0) == "servers")
-       {
-               m_goto("servers");
-               return;
-       }
-
-       if (argv(0) == "profile")
-       {
-               m_goto("profile");
-               return;
-       }
-
-       if (argv(0) == "skinselect")
-       {
-               m_goto("skinselector");
-               return;
-       }
-
-       if (argv(0) == "languageselect")
-       {
-               m_goto("languageselector");
-               return;
-       }
-
-       if (argv(0) == "settings")
-       {
-               m_goto("settings");
-               return;
-       }
-
-       if (argv(0) == "inputsettings")
-       {
-               m_goto("inputsettings");
-               return;
-       }
-
-       if (argv(0) == "videosettings")
-       {
-               m_goto("videosettings");
-               return;
+               // unlike menu_cmd directmenu, the menu won't be closed when these menu items will be closed
+               case "nexposee":         m_goto("nexposee", false); return;
+               case "servers":          m_goto("servers", false); return;
+               case "profile":          m_goto("profile", false); return;
+               case "skinselect":       m_goto("skinselector", false); return;
+               case "languageselect":   m_goto("languageselector", false); return;
+               case "settings":         m_goto("settings", false); return;
+               case "inputsettings":    m_goto("inputsettings", false); return;
+               case "videosettings":    m_goto("videosettings", false); return;
        }
 
        if (argv(0) == "dumptree")
index 9e0ea95ebad6dc9555357c310f01a0c9ac9ad793..d6df13719de56d49158bb3c0d32401c573713855 100644 (file)
 
        void Dialog_close(entity me)
        {
+               bool closed = false;
                if (me.parent.instanceOfNexposee)
                {
                        ExposeeCloseButton_Click(me, me.parent);
-                       if(me.hideMenuOnClose)
-                       {
-                               me.hideMenuOnClose = false;
-                               m_hide();
-                       }
+                       closed = true;
                }
                else if (me.parent.instanceOfModalController)
+               {
                        DialogCloseButton_Click(me, me);
+                       closed = true;
+               }
+
+               if (closed && me.hideMenuOnClose)
+                       m_goto(string_null, false);
+               me.hideMenuOnClose = false; // reset it regardless
        }
 
        float Dialog_keyDown(entity me, float key, float ascii, float shift)
index 1a9a60849ac1dc9506be055566d1e8fa28ae1efe..34ea86084f755b222d5b5b059feb687aa9e8d483 100644 (file)
@@ -67,9 +67,9 @@ CLASS(Dialog, InputContainer)
        ATTRIB(Dialog, borderLines, float, 1);
        ATTRIB(Dialog, closeButtonImage, string);
 
-       ATTRIB(Dialog, hideMenuOnClose, bool, false);
-
        ATTRIB(Dialog, frame, entity);
 ENDCLASS(Dialog)
 
 void Dialog_Close(entity button, entity me);
+
+.bool hideMenuOnClose;
index 2e941e614809880ceb856aad654f5eedac2cc913..fc990facdb965e74051c54f335ad6aeec18e8beb 100644 (file)
@@ -216,7 +216,7 @@ void m_init_delayed()
 
        if (m_goto_buffer)
        {
-               m_goto(m_goto_buffer);
+               m_goto(m_goto_buffer, false);
                strfree(m_goto_buffer);
        }
 
@@ -1038,7 +1038,7 @@ void m_setpointerfocus(entity wnd)
        if (wnd.focused) m_focus_item_chain(wnd, focus);
 }
 
-void m_goto(string itemname)
+void m_goto(string itemname, bool hide_menu_on_close)
 {
        if (!menuInitialized)
        {
@@ -1069,12 +1069,17 @@ void m_goto(string itemname)
 
                if ((e) && (!e.requiresConnection || (gamestatus & (GAME_ISSERVER | GAME_CONNECTED))))
                {
-                       if(!Menu_Active)
-                               e.hideMenuOnClose = true;
                        m_hide();
                        m_activate_window(e);
                        m_setpointerfocus(e);
                        m_display();
+                       if (hide_menu_on_close)
+                       {
+                               while(e.parent && !(e.instanceOfDialog && e.isTabRoot))
+                                       e = e.parent;
+                               if (e.instanceOfDialog)
+                                       e.hideMenuOnClose = true;
+                       }
                }
        }
 }
index 2df331950848c1dcdab9c53b63d9ebd553a3cb9a..ed01018c7fd98d65ff689419d0523ed236353628 100644 (file)
@@ -26,7 +26,7 @@ entity anim;
 entity main;
 void m_hide();
 void m_display();
-void m_goto(string name);
+void m_goto(string name, bool hide_menu_on_close);
 .string name;
 
 entity keyGrabber;
index 7c2bcacd9f9fcd25d5714db7a774571e1f1c4d8f..2afb0402978a7acc67cc29b8b22300b505b8d983 100644 (file)
@@ -14,5 +14,5 @@ void XonoticNexposee_configureXonoticNexposee(entity me)
 
 void XonoticNexposee_close(entity me)
 {
-       m_goto(string_null); // hide
+       m_goto(string_null, true); // hide
 }
index 31a96e4918b712b900c39e36d8b25dffc1f8a682..9a6c14626b673467ca7775b56d69a40f1a1f4079 100644 (file)
@@ -8,5 +8,5 @@ void XonoticRootDialog_showNotify(entity me)
 
 void XonoticRootDialog_close(entity me)
 {
-       m_goto(string_null);
+       m_goto(string_null, true);
 }