From: ColdSpirit Date: Thu, 30 Dec 2021 11:11:53 +0000 (+0400) Subject: Cvar onChange for qc menu for stable branch X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=bd4f4aadea9be9173b4ab04ab2f98c86a2bc7410;p=xonotic%2Fdarkplaces.git Cvar onChange for qc menu for stable branch Use m_cvar_changed in qc menu to receive all cvar updates --- diff --git a/cvar.c b/cvar.c index 2a0acae8..728f5309 100644 --- a/cvar.c +++ b/cvar.c @@ -21,6 +21,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" +#ifdef CONFIG_MENU + #include "progsvm.h" +#endif + const char *cvar_dummy_description = "custom cvar"; cvar_t *cvar_vars = NULL; @@ -345,6 +349,22 @@ static void Cvar_SetQuick_Internal (cvar_t *var, const char *value) // LordHavoc: don't reallocate when there is no change if (!changed) return; + + // Con_Printf("----> Changing \"%s\" value from \"%s\" to \"%s\"\n", var->name, var->string, value); + +#ifdef CONFIG_MENU + // prepare values to send into QC + prvm_prog_t *prog = MVM_prog; + qboolean qcSubscribed = PRVM_menufunction(m_cvar_changed); + + if (qcSubscribed && prog->loaded) + { + prog->globals.ip[OFS_PARM0] = PRVM_SetTempString(prog, var->name); + prog->globals.ip[OFS_PARM1] = PRVM_SetTempString(prog, var->string); + prog->globals.ip[OFS_PARM2] = PRVM_SetTempString(prog, value); + } +#endif + // LordHavoc: don't reallocate when the buffer is the same size valuelen = strlen(value); @@ -418,6 +438,14 @@ static void Cvar_SetQuick_Internal (cvar_t *var, const char *value) } Cvar_UpdateAutoCvar(var); + +#ifdef CONFIG_MENU + // call "onCvarChanged" like event + if (qcSubscribed && prog->loaded) + { + prog->ExecuteProgram(prog, PRVM_menufunction(m_cvar_changed), "QC function m_cvar_changed is missing"); + } +#endif } void Cvar_SetQuick (cvar_t *var, const char *value) diff --git a/dpdefs/menudefs.qc b/dpdefs/menudefs.qc index 8caab4a9..4eee19ed 100644 --- a/dpdefs/menudefs.qc +++ b/dpdefs/menudefs.qc @@ -15,6 +15,7 @@ void end_sys_fields; void() m_init; void(float keynr, float ascii) m_keydown; +void(string cvarName, string oldValue, string newValue) m_cvar_changed; void(float width, float height) m_draw; void(float mode) m_toggle; void() m_shutdown; diff --git a/prvm_offsets.h b/prvm_offsets.h index 1563a051..306849b7 100644 --- a/prvm_offsets.h +++ b/prvm_offsets.h @@ -443,6 +443,7 @@ PRVM_DECLARE_function(m_newmap) PRVM_DECLARE_function(m_gethostcachecategory) PRVM_DECLARE_function(m_shutdown) PRVM_DECLARE_function(m_toggle) +PRVM_DECLARE_function(m_cvar_changed) PRVM_DECLARE_function(main) PRVM_DECLARE_global(SV_InitCmd) PRVM_DECLARE_global(clientcommandframe) @@ -591,6 +592,7 @@ PRVM_DECLARE_menufunction(m_keyup) PRVM_DECLARE_menufunction(m_newmap) PRVM_DECLARE_menufunction(m_shutdown) PRVM_DECLARE_menufunction(m_toggle) +PRVM_DECLARE_menufunction(m_cvar_changed) PRVM_DECLARE_menuglobaledict(self) PRVM_DECLARE_menuglobalfloat(drawfont) PRVM_DECLARE_menuglobalfloat(require_spawnfunc_prefix)