From: ColdSpirit Date: Thu, 30 Dec 2021 10:44:01 +0000 (+0400) Subject: Cvar onChange for qc menu X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=8e50ec7a85adbcb9b9256cc2c8357a9f13a442aa;p=xonotic%2Fdarkplaces.git Cvar onChange for qc menu Use m_cvar_changed in qc menu to receive all cvar updates --- diff --git a/cvar.c b/cvar.c index 7936c923..6abf324c 100644 --- a/cvar.c +++ b/cvar.c @@ -22,6 +22,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"; static const char *cvar_null_string = ""; @@ -393,6 +397,21 @@ static void Cvar_SetQuick_Internal (cvar_t *var, const char *value) // LadyHavoc: 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; + bool 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 // LadyHavoc: don't reallocate when the buffer is the same size valuelen = strlen(value); @@ -427,6 +446,14 @@ static void Cvar_SetQuick_Internal (cvar_t *var, const char *value) // Call the function stored in the cvar for bounds checking, cleanup, etc Cvar_Callback(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 63d2c638..5aa7f3f7 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 97a2defb..dd4caa1e 100644 --- a/prvm_offsets.h +++ b/prvm_offsets.h @@ -446,6 +446,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) @@ -594,6 +595,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)