Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- add new ccmd cvarsearch allows searching cvar by name, languageid… #2294

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 51 additions & 6 deletions src/common/console/c_cvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "printf.h"
#include "palutil.h"
#include "i_interface.h"
#include "gstrings.h"

#include "dobject.h"
#include "dobjtype.h"
Expand Down Expand Up @@ -1695,16 +1696,37 @@ CCMD (toggle)
}
}

void FBaseCVar::ListVars (const char *filter, bool plain)
void FBaseCVar::ListVars (const char *filter, int listtype)
{
int count = 0;

bool plain = listtype == LCT_Plain;
bool includedesc = listtype == LCT_FullSearch;

decltype(cvarMap)::Iterator it(cvarMap);
decltype(cvarMap)::Pair *pair;
while (it.NextPair(pair))
{
auto var = pair->Value;
if (CheckWildcards (filter, var->GetName()))

bool ismatch;

if (filter && includedesc)
{
// search always allow partial matches
// also allow matching to cvar name, localised description, and description language-id

FString SearchString = FString("*") + filter + "*";
ismatch = CheckWildcards (SearchString.GetChars(), var->GetName()) ||
CheckWildcards (SearchString.GetChars(), var->GetDescription().GetChars()) ||
CheckWildcards (SearchString.GetChars(), GStrings.localize(var->GetDescription().GetChars()));
}
else
{
ismatch = CheckWildcards (filter, var->GetName());
}

if (ismatch)
{
uint32_t flags = var->GetFlags();
if (plain)
Expand All @@ -1718,7 +1740,8 @@ void FBaseCVar::ListVars (const char *filter, bool plain)
else
{
++count;
Printf ("%c%c%c%c%c %s = %s\n",

Printf ("%c%c%c%c%c %s = %s",
flags & CVAR_ARCHIVE ? 'A' : ' ',
flags & CVAR_USERINFO ? 'U' :
flags & CVAR_SERVERINFO ? 'S' :
Expand All @@ -1730,6 +1753,16 @@ void FBaseCVar::ListVars (const char *filter, bool plain)
flags & CVAR_IGNORE ? 'X' : ' ',
var->GetName(),
var->GetHumanString());

if (includedesc)
if (var->GetDescription().Len())
Printf(" // \"%s\"\n", GStrings.localize(var->GetDescription().GetChars()));
else
Printf("\n");
else
Printf("\n");


}
}
}
Expand All @@ -1740,17 +1773,29 @@ CCMD (cvarlist)
{
if (argv.argc() == 1)
{
FBaseCVar::ListVars (NULL, false);
FBaseCVar::ListVars (NULL, LCT_Default);
}
else
{
FBaseCVar::ListVars (argv[1], false);
FBaseCVar::ListVars (argv[1], LCT_Default);
}
}

CCMD (cvarlistplain)
{
FBaseCVar::ListVars (NULL, true);
FBaseCVar::ListVars (NULL, LCT_Plain);
}

CCMD (cvarsearch)
{
if (argv.argc() == 1)
{
FBaseCVar::ListVars (NULL, LCT_FullSearch);
}
else
{
FBaseCVar::ListVars (argv[1], LCT_FullSearch);
}
}

CCMD (archivecvar)
Expand Down
9 changes: 8 additions & 1 deletion src/common/console/c_cvars.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ enum ECVarType
CVAR_Dummy, // Unknown
};

enum ListCCMDType
{
LCT_Default,
LCT_Plain,
LCT_FullSearch,
};


class FIntCVarRef;
union UCVarValue
Expand Down Expand Up @@ -201,7 +208,7 @@ class FBaseCVar
static void MarkZSCallbacks ();
static void ResetColors (); // recalc color cvars' indices after screen change

static void ListVars (const char *filter, bool plain);
static void ListVars (const char *filter, int listtype);

const FString &GetDescription() const { return Description; };
const FString& GetToggleMessage(int which) { return ToggleMessages[which]; }
Expand Down
Loading