From 3a23cc69d6ae36b1f118240c75bf511dce340079 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 8 Jun 2020 23:35:02 +0200 Subject: [PATCH] - since we already got lots of CVAR descriptions from the menu's content, let's use that as CVAR description if none is explicitly provided. This also necessitated localization support for CVAR descriptions because menu content is multi-language. --- src/common/console/c_cvars.h | 4 ++++ src/common/console/c_dispatch.cpp | 3 ++- src/menu/optionmenu.cpp | 14 ++++++++++++++ wadsrc/static/zscript/ui/menu/optionmenuitems.zs | 3 +++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/common/console/c_cvars.h b/src/common/console/c_cvars.h index d1b0e6506..2fc08df7c 100644 --- a/src/common/console/c_cvars.h +++ b/src/common/console/c_cvars.h @@ -143,6 +143,10 @@ public: void SetArchiveBit () { Flags |= CVAR_ARCHIVE; } void MarkUnsafe(); void MarkSafe() { Flags &= ~CVAR_UNSAFECONTEXT; } + void AddDescription(const FString& label) + { + if (Description.IsEmpty()) Description = label; + } int ToInt() { diff --git a/src/common/console/c_dispatch.cpp b/src/common/console/c_dispatch.cpp index 6b4680e35..38ef90831 100644 --- a/src/common/console/c_dispatch.cpp +++ b/src/common/console/c_dispatch.cpp @@ -50,6 +50,7 @@ #include "c_cvars.h" #include "c_buttons.h" #include "findfile.h" +#include "gstrings.h" // MACROS ------------------------------------------------------------------ @@ -300,7 +301,7 @@ void C_DoCommand (const char *cmd, int keynum) } else { // Get the variable's value - if (var->GetDescription().Len()) Printf("%s\n", var->GetDescription().GetChars()); + if (var->GetDescription().Len()) Printf("%s\n", GStrings.localize(var->GetDescription())); Printf ("\"%s\" is \"%s\"\n", var->GetName(), var->GetHumanString()); } } diff --git a/src/menu/optionmenu.cpp b/src/menu/optionmenu.cpp index ebe27800b..0635ee580 100644 --- a/src/menu/optionmenu.cpp +++ b/src/menu/optionmenu.cpp @@ -34,6 +34,7 @@ #include "v_video.h" #include "menu/menu.h" +#include "vm.h" //============================================================================= @@ -52,3 +53,16 @@ DMenuItemBase *DOptionMenuDescriptor::GetItem(FName name) return NULL; } +void SetCVarDescription(FBaseCVar* cvar, const FString* label) +{ + cvar->AddDescription(*label); +} + +DEFINE_ACTION_FUNCTION_NATIVE(_OptionMenuItemOption, SetCVarDescription, SetCVarDescription) +{ + PARAM_PROLOGUE; + PARAM_POINTER(cv, FBaseCVar); + PARAM_STRING(label); + SetCVarDescription(cv, &label); + return 0; +} \ No newline at end of file diff --git a/wadsrc/static/zscript/ui/menu/optionmenuitems.zs b/wadsrc/static/zscript/ui/menu/optionmenuitems.zs index 0b5d4a86b..d36ef3f74 100644 --- a/wadsrc/static/zscript/ui/menu/optionmenuitems.zs +++ b/wadsrc/static/zscript/ui/menu/optionmenuitems.zs @@ -360,10 +360,13 @@ class OptionMenuItemOption : OptionMenuItemOptionBase { CVar mCVar; + private static native void SetCVarDescription(CVar cv, String label); + OptionMenuItemOption Init(String label, Name command, Name values, CVar graycheck = null, int center = 0) { Super.Init(label, command, values, graycheck, center); mCVar = CVar.FindCVar(mAction); + if (mCVar) SetCVarDescription(mCVar, label); return self; }