From: Des - Date: Sat, 21 Sep 2024 14:09:39 +0000 (+0000) Subject: Implement KEEP_OPEN flag for quickmenu, and make holding CTRL coherent with it X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=00bcf2815443ed07f9964c72808225766328872e;p=xonotic%2Fxonotic-data.pk3dir.git Implement KEEP_OPEN flag for quickmenu, and make holding CTRL coherent with it --- diff --git a/qcsrc/client/hud/panel/quickmenu.qc b/qcsrc/client/hud/panel/quickmenu.qc index fde929d53..710245445 100644 --- a/qcsrc/client/hud/panel/quickmenu.qc +++ b/qcsrc/client/hud/panel/quickmenu.qc @@ -41,21 +41,29 @@ float QuickMenu_TimeOut; #define QM_TAG_TITLE "T" #define QM_TAG_SUBMENU "S" #define QM_TAG_COMMAND "C" +#define QM_TAG_KCOMMAND "K" #define QM_TAG_PLCOMMAND "P" +// QuickMenu_Page_Command_Type +#define QM_PCT_NONE 0 +#define QM_PCT_TOGGLE 1 +#define QM_PCT_KEEP 2 + #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) { \ +#define QUICKMENU_ENTRY_TAG(title, command, tag) { \ 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_Set(tag, command); \ } \ ++QuickMenu_Buffer_Size; \ } +#define QUICKMENU_ENTRY(title, command) QUICKMENU_ENTRY_TAG(title, command, QM_TAG_COMMAND) + // special entries are shown with a different color #define QUICKMENU_ENTRY_SPECIAL(title, command) QUICKMENU_ENTRY(title, strcat("\n", command)) @@ -168,6 +176,14 @@ bool QuickMenu_Open(string mode, string submenu, string file) ++QuickMenu_Buffer_Size; QuickMenu_Buffer_Set(QM_TAG_COMMAND, argv(1)); } + else if(argc == 3 && argv(2) == "KEEP_OPEN") + { + if(argv(1) == "") + continue; + QuickMenu_Buffer_Set(QM_TAG_TITLE, argv(0)); + ++QuickMenu_Buffer_Size; + QuickMenu_Buffer_Set(QM_TAG_KCOMMAND, argv(1)); + } else if(argc == 3) { // check for special keywords @@ -379,7 +395,15 @@ bool QuickMenu_Page_Load(string target_submenu, bool new_page) cmd = QuickMenu_Buffer_Get(); string command_code = substring(cmd, 0, 1); if(command_code == QM_TAG_COMMAND) + { cmd = substring(cmd, 1, -1); + QuickMenu_Page_Command_Type[QuickMenu_Page_Entries] = QM_PCT_NONE; + } + else if(command_code == QM_TAG_KCOMMAND) + { + cmd = substring(cmd, 1, -1); + QuickMenu_Page_Command_Type[QuickMenu_Page_Entries] = QM_PCT_KEEP; + } else if(command_code == QM_TAG_PLCOMMAND) { // throw away the current quickmenu buffer and load a new one @@ -392,7 +416,8 @@ bool QuickMenu_Page_Load(string target_submenu, bool new_page) } tokenize_console(cmd); - QuickMenu_Page_Command_Type[QuickMenu_Page_Entries] = (argv(1) && argv(0) == "toggle"); + if(argv(1) && argv(0) == "toggle") + QuickMenu_Page_Command_Type[QuickMenu_Page_Entries] = QM_PCT_TOGGLE; QuickMenu_Page_LoadEntry(QuickMenu_Page_Entries, substring(s, 1, -1), cmd); } @@ -433,7 +458,10 @@ bool QuickMenu_ActionForNumber(int num) QuickMenu_Page_ActivatedEntry_Time = time + 0.1; localcmd(strcat("\n", QuickMenu_Page_Command[num], "\n")); QuickMenu_TimeOut_Set(); - return true; + if(QuickMenu_Page_Command_Type[num] == QM_PCT_TOGGLE || QuickMenu_Page_Command_Type[num] == QM_PCT_KEEP) + return false; + else + return true; } if (QuickMenu_Page_Description[num] != "") QuickMenu_Page_Load(QuickMenu_Page_Description[num], 0); @@ -447,11 +475,7 @@ void QuickMenu_Page_ActiveEntry(int entry_num) if(QuickMenu_Page_Command[QuickMenu_Page_ActivatedEntry]) { bool f = QuickMenu_ActionForNumber(QuickMenu_Page_ActivatedEntry); - // toggle commands don't close the quickmenu - if(QuickMenu_Page_Command_Type[QuickMenu_Page_ActivatedEntry] == 1) - QuickMenu_Page_ActivatedEntry_Close = false; - else - QuickMenu_Page_ActivatedEntry_Close = (f && !(hudShiftState & S_CTRL)); + QuickMenu_Page_ActivatedEntry_Close = (hudShiftState & S_CTRL) ? !f : f; } else QuickMenu_Page_ActivatedEntry_Close = (!(hudShiftState & S_CTRL)); @@ -683,7 +707,7 @@ void HUD_QuickMenu() color = "^6"; // special command else color = "^3"; - if(QuickMenu_Page_Command_Type[i] == 1) // toggle command + if(QuickMenu_Page_Command_Type[i] == QM_PCT_TOGGLE) // toggle command { int end = strstrofs(QuickMenu_Page_Command[i], ";", 0); if(end < 0) @@ -866,14 +890,14 @@ void QuickMenu_Default(string target_submenu) if(spectatee_status > 0) { - QUICKMENU_ENTRY(CTX(_("QMCMD^Change spectator camera")), "dropweapon") + QUICKMENU_ENTRY_TAG(CTX(_("QMCMD^Change spectator camera")), "dropweapon", QM_TAG_KCOMMAND) } if(spectatee_status == -1) { QUICKMENU_SMENU(CTX(_("QMCMD^Observer camera")), "Observer camera") - QUICKMENU_ENTRY(CTX(_("QMCMD^Increase speed")), "weapnext") - QUICKMENU_ENTRY(CTX(_("QMCMD^Decrease speed")), "weapprev") + QUICKMENU_ENTRY_TAG(CTX(_("QMCMD^Increase speed")), "weapnext", QM_TAG_KCOMMAND) + QUICKMENU_ENTRY_TAG(CTX(_("QMCMD^Decrease speed")), "weapprev", QM_TAG_KCOMMAND) QUICKMENU_ENTRY(CTX(_("QMCMD^Wall collision")), "toggle cl_clippedspectating") QUICKMENU_SMENU(CTX(_("QMCMD^Observer camera")), "Observer camera") } diff --git a/quickmenu_example.txt b/quickmenu_example.txt index 6f97e28ba..595624025 100644 --- a/quickmenu_example.txt +++ b/quickmenu_example.txt @@ -14,6 +14,12 @@ "Sound settings" "Hit sound" "toggle cl_hitsound" "Chat sound" "toggle cl_chatsound" + // KEEP_OPEN menu option to increase/decrease volumes and stay + // the same menu + // Holding CTRL while selecting the number inverts the default + // keep behavior for an entry + "+Volume" "rpn /mastervolume mastervolume 0.1 + =" KEEP_OPEN + "-Volume" "rpn /mastervolume mastervolume 0.1 - =" KEEP_OPEN "Sound settings" // A toggle command displays a checkbox showing the current cvar's state