From: Des Date: Fri, 6 Sep 2024 12:35:20 +0000 (-0300) Subject: KEEP_OPEN usage example X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=c128126848b247a48be0e616a21af27af326459b;p=xonotic%2Fxonotic-data.pk3dir.git KEEP_OPEN usage example --- diff --git a/qcsrc/client/hud/panel/quickmenu.qc b/qcsrc/client/hud/panel/quickmenu.qc index fde929d53..14ebcc4dd 100644 --- a/qcsrc/client/hud/panel/quickmenu.qc +++ b/qcsrc/client/hud/panel/quickmenu.qc @@ -41,8 +41,14 @@ 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) @@ -168,6 +174,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 +393,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 +414,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 +456,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 +473,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 +705,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) diff --git a/quickmenu_example.txt b/quickmenu_example.txt index 6f97e28ba..de8369fd1 100644 --- a/quickmenu_example.txt +++ b/quickmenu_example.txt @@ -14,6 +14,9 @@ "Sound settings" "Hit sound" "toggle cl_hitsound" "Chat sound" "toggle cl_chatsound" + // KEEP_OPEN menu option to increase/decrease volumes + "+Volume" "rpn /volume volume 0.1 + =" KEEP_OPEN + "-Volume" "rpn /volume volume 0.1 - =" KEEP_OPEN "Sound settings" // A toggle command displays a checkbox showing the current cvar's state