From: terencehill Date: Fri, 28 Feb 2025 18:27:32 +0000 (+0100) Subject: Menu: fix potential bug if a stand-alone non-root dialog were opened via menu_cmd... X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=40e6770bae2cf5908861b7d2a4cc19b11a9261e6;p=xonotic%2Fxonotic-data.pk3dir.git Menu: fix potential bug if a stand-alone non-root dialog were opened via menu_cmd directmenu 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 This new behaviour is not applied for dialogs opened via menu_cmd --- diff --git a/qcsrc/menu/command/menu_cmd.qc b/qcsrc/menu/command/menu_cmd.qc index 9c1b9d0c6f..2554f2946e 100644 --- a/qcsrc/menu/command/menu_cmd.qc +++ b/qcsrc/menu/command/menu_cmd.qc @@ -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") diff --git a/qcsrc/menu/item/dialog.qc b/qcsrc/menu/item/dialog.qc index 9e0ea95eba..d6df13719d 100644 --- a/qcsrc/menu/item/dialog.qc +++ b/qcsrc/menu/item/dialog.qc @@ -103,17 +103,21 @@ 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) diff --git a/qcsrc/menu/item/dialog.qh b/qcsrc/menu/item/dialog.qh index 1a9a60849a..34ea86084f 100644 --- a/qcsrc/menu/item/dialog.qh +++ b/qcsrc/menu/item/dialog.qh @@ -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; diff --git a/qcsrc/menu/menu.qc b/qcsrc/menu/menu.qc index 2e941e6148..fc990facdb 100644 --- a/qcsrc/menu/menu.qc +++ b/qcsrc/menu/menu.qc @@ -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; + } } } } diff --git a/qcsrc/menu/menu.qh b/qcsrc/menu/menu.qh index 2df3319508..ed01018c7f 100644 --- a/qcsrc/menu/menu.qh +++ b/qcsrc/menu/menu.qh @@ -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; diff --git a/qcsrc/menu/xonotic/nexposee.qc b/qcsrc/menu/xonotic/nexposee.qc index 7c2bcacd9f..2afb040297 100644 --- a/qcsrc/menu/xonotic/nexposee.qc +++ b/qcsrc/menu/xonotic/nexposee.qc @@ -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 } diff --git a/qcsrc/menu/xonotic/rootdialog.qc b/qcsrc/menu/xonotic/rootdialog.qc index 31a96e4918..9a6c14626b 100644 --- a/qcsrc/menu/xonotic/rootdialog.qc +++ b/qcsrc/menu/xonotic/rootdialog.qc @@ -8,5 +8,5 @@ void XonoticRootDialog_showNotify(entity me) void XonoticRootDialog_close(entity me) { - m_goto(string_null); + m_goto(string_null, true); }