Add FBaseCVar::GetHumanString()

- For most cvars, this is equivalent to calling GetGenericRep() to get a
  string.
- For float cvars, it uses %g instead of %H, because %H is generally more
  information than is needed.
This commit is contained in:
Randy Heit 2016-04-23 22:30:08 -05:00
parent fc54dd1ff0
commit e96ed6bf8d
5 changed files with 24 additions and 9 deletions

View File

@ -132,6 +132,11 @@ FBaseCVar::~FBaseCVar ()
}
}
const char *FBaseCVar::GetHumanString(int precision) const
{
return GetGenericRep(CVAR_String).String;
}
void FBaseCVar::ForceSet (UCVarValue value, ECVarType type, bool nouserinfosend)
{
DoSet (value, type);
@ -750,6 +755,16 @@ ECVarType FFloatCVar::GetRealType () const
return CVAR_Float;
}
const char *FFloatCVar::GetHumanString(int precision) const
{
if (precision < 0)
{
precision = 6;
}
mysnprintf(cstrbuf, countof(cstrbuf), "%.*g", precision, Value);
return cstrbuf;
}
UCVarValue FFloatCVar::GetGenericRep (ECVarType type) const
{
return FromFloat (Value, type);
@ -1675,7 +1690,7 @@ void FBaseCVar::ListVars (const char *filter, bool plain)
if (!(flags & CVAR_UNSETTABLE))
{
++count;
Printf ("%s : %s\n", var->GetName(), var->GetGenericRep(CVAR_String).String);
Printf ("%s : %s\n", var->GetName(), var->GetHumanString());
}
}
else
@ -1692,7 +1707,7 @@ void FBaseCVar::ListVars (const char *filter, bool plain)
flags & CVAR_MOD ? 'M' : ' ',
flags & CVAR_IGNORE ? 'X' : ' ',
var->GetName(),
var->GetGenericRep(CVAR_String).String);
var->GetHumanString());
}
}
var = var->m_Next;

View File

@ -108,6 +108,7 @@ public:
virtual ECVarType GetRealType () const = 0;
virtual const char *GetHumanString(int precision=-1) const;
virtual UCVarValue GetGenericRep (ECVarType type) const = 0;
virtual UCVarValue GetFavoriteRep (ECVarType *type) const = 0;
@ -268,6 +269,7 @@ public:
virtual UCVarValue GetGenericRepDefault (ECVarType type) const;
virtual UCVarValue GetFavoriteRepDefault (ECVarType *type) const;
virtual void SetGenericRepDefault (UCVarValue value, ECVarType type);
const char *GetHumanString(int precision) const override;
float operator= (float floatval)
{ UCVarValue val; val.Float = floatval; SetGenericRep (val, CVAR_Float); return floatval; }

View File

@ -651,8 +651,7 @@ void C_DoCommand (const char *cmd, int keynum)
}
else
{ // Get the variable's value
UCVarValue val = var->GetGenericRep (CVAR_String);
Printf ("\"%s\" is \"%s\"\n", var->GetName(), val.String);
Printf ("\"%s\" is \"%s\"\n", var->GetName(), var->GetHumanString());
}
}
else

View File

@ -993,8 +993,7 @@ CCMD (playerinfo)
if (pair->Key != NAME_Name && pair->Key != NAME_Team && pair->Key != NAME_Skin &&
pair->Key != NAME_Gender && pair->Key != NAME_PlayerClass)
{
UCVarValue val = pair->Value->GetGenericRep(CVAR_String);
Printf("%20s: %s\n", pair->Key.GetChars(), val.String);
Printf("%20s: %s\n", pair->Key.GetChars(), pair->Value->GetHumanString());
}
}
if (argv.argc() > 2)

View File

@ -295,10 +295,10 @@ public:
}
else
{
UCVarValue cv = mCVar->GetGenericRep(CVAR_String);
const char *cv = mCVar->GetHumanString();
for(unsigned i = 0; i < (*opt)->mValues.Size(); i++)
{
if ((*opt)->mValues[i].TextValue.CompareNoCase(cv.String) == 0)
if ((*opt)->mValues[i].TextValue.CompareNoCase(cv) == 0)
{
Selection = i;
break;
@ -995,7 +995,7 @@ public:
if ( mCVar == NULL )
return "";
return mCVar->GetGenericRep( CVAR_String ).String;
return mCVar->GetHumanString();
}
virtual FString Represent()