From bd2f028a42b56bfe04b057dec55fa7ef969fa776 Mon Sep 17 00:00:00 2001 From: terencehill Date: Mon, 23 Jan 2023 00:34:54 +0000 Subject: [PATCH] Quickmenu: allow players to make server's custom quickmenu default --- _hud_common.cfg | 2 ++ qcsrc/client/hud/panel/quickmenu.qc | 56 +++++++++++++++++++++-------- qcsrc/client/hud/panel/quickmenu.qh | 1 + xonotic-server.cfg | 2 +- 4 files changed, 46 insertions(+), 15 deletions(-) diff --git a/_hud_common.cfg b/_hud_common.cfg index 0c808dd37..766f89819 100644 --- a/_hud_common.cfg +++ b/_hud_common.cfg @@ -116,6 +116,8 @@ set _hud_panel_quickmenu_file_from_server "" "reserved cvar set by the server wi seta hud_panel_quickmenu_file "" "load the quick menu from this file (empty or 0 to disable)" seta hud_panel_quickmenu_translatecommands 0 "when the game is translated, translate strings inside commands too (useful for chat commands)" seta hud_panel_quickmenu_time 5 "quickmenu expires after this number of seconds in the same page" +// do not remember this setting +set hud_panel_quickmenu_server_is_default 0 "make the server's custom quickmenu the default one" seta hud_panel_infomessages_group0 1 "show group 0 messages (showing keys for non-crucial actions you can do while spectating/observing)" seta hud_panel_infomessages_group_time 6 "number of seconds a message of a group lasts before it gets changed" diff --git a/qcsrc/client/hud/panel/quickmenu.qc b/qcsrc/client/hud/panel/quickmenu.qc index e476e12f0..0f3425203 100644 --- a/qcsrc/client/hud/panel/quickmenu.qc +++ b/qcsrc/client/hud/panel/quickmenu.qc @@ -45,6 +45,20 @@ float QuickMenu_TimeOut; #define QuickMenu_Buffer_Set(tag, string) bufstr_set(QuickMenu_Buffer, QuickMenu_Buffer_Size, strcat(tag, string)) #define QuickMenu_Buffer_Get() bufstr_get(QuickMenu_Buffer, QuickMenu_Buffer_Index) +#define QUICKMENU_ENTRY(title,command) { \ + if(QuickMenu_Buffer_Size + 1 < QUICKMENU_BUFFER_MAXENTRIES) \ + { \ + QuickMenu_Buffer_Set(QM_TAG_TITLE, title); \ + ++QuickMenu_Buffer_Size; \ + QuickMenu_Buffer_Set(QM_TAG_COMMAND, command); \ + } \ + ++QuickMenu_Buffer_Size; \ +} + +// special entries are shown with a different color +#define QUICKMENU_ENTRY_SPECIAL(title, command) QUICKMENU_ENTRY(title, strcat("\n", command)) + + void QuickMenu_TimeOut_Set() { QuickMenu_TimeOut = ((autocvar_hud_panel_quickmenu_time > 0) ? time + autocvar_hud_panel_quickmenu_time : 0); @@ -94,6 +108,15 @@ bool QuickMenu_Open(string mode, string submenu, string file) mode = "file"; } + if(mode == "default") + { + if (autocvar_hud_panel_quickmenu_server_is_default && autocvar__hud_panel_quickmenu_file_from_server != "") + { + mode = "file"; + file = autocvar__hud_panel_quickmenu_file_from_server; + } + } + if(mode == "file") { if(file == "" || file == "0") @@ -171,6 +194,13 @@ bool QuickMenu_Open(string mode, string submenu, string file) ++QuickMenu_Buffer_Size; } fclose(fh); + + // forcedly add this entry + if (autocvar_hud_panel_quickmenu_server_is_default && autocvar__hud_panel_quickmenu_file_from_server != "") + { + string prev_value = cvar_string("hud_panel_quickmenu_server_is_default"); + QUICKMENU_ENTRY_SPECIAL(_("Standard quick menu"), sprintf("hud_panel_quickmenu_server_is_default 0; quickmenu; wait; quickmenu; wait; hud_panel_quickmenu_server_is_default \"%s\"", prev_value)) + } } else { @@ -647,7 +677,10 @@ void HUD_QuickMenu() color = "^4"; else { - color = "^3"; + if (substring(QuickMenu_Page_Command[i], 0, 1) == "\n") + color = "^6"; // special command + else + color = "^3"; if(QuickMenu_Page_Command_Type[i] == 1) // toggle command { int end = strstrofs(QuickMenu_Page_Command[i], ";", 0); @@ -715,16 +748,6 @@ void HUD_QuickMenu() } \ } -#define QUICKMENU_ENTRY(title,command) { \ - if(QuickMenu_Buffer_Size + 1 < QUICKMENU_BUFFER_MAXENTRIES) \ - { \ - QuickMenu_Buffer_Set(QM_TAG_TITLE, title); \ - ++QuickMenu_Buffer_Size; \ - QuickMenu_Buffer_Set(QM_TAG_COMMAND, command); \ - } \ - ++QuickMenu_Buffer_Size; \ -} - #define QUICKMENU_SMENU_PL(submenu,eng_submenu,command,teamplayers,without_me) { \ if(QuickMenu_Buffer_Size + 3 < QUICKMENU_BUFFER_MAXENTRIES) {\ QUICKMENU_SMENU(submenu,eng_submenu) \ @@ -870,10 +893,15 @@ void QuickMenu_Default(string target_submenu) if (autocvar__hud_panel_quickmenu_file_from_server != "") { - string entry_name = _("Server's custom quickmenu"); + string entry_name = _("Server quick menu"); if (autocvar__hud_panel_quickmenu_file_from_server == "wpeditor.txt") - entry_name = _("Waypoint editor quickmenu"); - QUICKMENU_ENTRY(entry_name, "quickmenu; wait; quickmenu \"\" \"\" $_hud_panel_quickmenu_file_from_server") + entry_name = _("Waypoint editor menu"); + QUICKMENU_ENTRY_SPECIAL(entry_name, "quickmenu; wait; quickmenu \"\" \"\" $_hud_panel_quickmenu_file_from_server") + if (autocvar__hud_panel_quickmenu_file_from_server == "wpeditor.txt") + entry_name = _("Waypoint editor menu as default"); + else + entry_name = _("Server quick menu as default"); + QUICKMENU_ENTRY(entry_name, "toggle hud_panel_quickmenu_server_is_default") } if(spectatee_status != 0) diff --git a/qcsrc/client/hud/panel/quickmenu.qh b/qcsrc/client/hud/panel/quickmenu.qh index 249b5121f..3cb6bf014 100644 --- a/qcsrc/client/hud/panel/quickmenu.qh +++ b/qcsrc/client/hud/panel/quickmenu.qh @@ -6,6 +6,7 @@ float autocvar_hud_panel_quickmenu_align; float autocvar_hud_panel_quickmenu_translatecommands; string autocvar_hud_panel_quickmenu_file; float autocvar_hud_panel_quickmenu_time; +bool autocvar_hud_panel_quickmenu_server_is_default; string autocvar__hud_panel_quickmenu_file_from_server; bool QuickMenu_InputEvent(float bInputType, float nPrimary, float nSecondary); diff --git a/xonotic-server.cfg b/xonotic-server.cfg index cf7544a08..cda95f14d 100644 --- a/xonotic-server.cfg +++ b/xonotic-server.cfg @@ -597,4 +597,4 @@ set sv_warpzone_allow_selftarget 0 "do not touch" // don't notify cvar changes in the chat sv_disablenotify 1 -set sv_quickmenu_file "" "filename of the quickmenu that appears in client's default quickmenu, file must be located in a subfolder with an unique name" +set sv_quickmenu_file "" "filename of a custom server's quickmenu that will be selectable from the default client's quickmenu. This file must be sent in a pk3 archive and should have an unique name (e.g. quickmenu-servername.txt) to prevent overriding existing quickmenus" -- 2.39.2