mirror of
https://github.com/ZDoom/qzdoom.git
synced 2025-02-07 08:21:04 +00:00
- Added a prefix option to drawnumber.
- Added a flag to remove the cap on drawnumber (this means on the lower length numbers will be drawn). SVN r3165 (trunk)
This commit is contained in:
parent
f96dd8ff8a
commit
c8e8edb1c5
1 changed files with 106 additions and 71 deletions
|
@ -552,58 +552,7 @@ class CommandDrawString : public SBarInfoCommand
|
||||||
sc.MustGetToken(',');
|
sc.MustGetToken(',');
|
||||||
translation = GetTranslation(sc);
|
translation = GetTranslation(sc);
|
||||||
sc.MustGetToken(',');
|
sc.MustGetToken(',');
|
||||||
if(sc.CheckToken(TK_Identifier))
|
ParseStringValue(sc);
|
||||||
{
|
|
||||||
if(sc.Compare("levelname"))
|
|
||||||
strValue = LEVELNAME;
|
|
||||||
else if(sc.Compare("levellump"))
|
|
||||||
strValue = LEVELLUMP;
|
|
||||||
else if(sc.Compare("skillname"))
|
|
||||||
strValue = SKILLNAME;
|
|
||||||
else if(sc.Compare("playerclass"))
|
|
||||||
strValue = PLAYERCLASS;
|
|
||||||
else if(sc.Compare("playername"))
|
|
||||||
strValue = PLAYERNAME;
|
|
||||||
else if(sc.Compare("ammo1tag"))
|
|
||||||
strValue = AMMO1TAG;
|
|
||||||
else if(sc.Compare("ammo2tag"))
|
|
||||||
strValue = AMMO2TAG;
|
|
||||||
else if(sc.Compare("weapontag"))
|
|
||||||
strValue = WEAPONTAG;
|
|
||||||
else if(sc.Compare("inventorytag"))
|
|
||||||
strValue = INVENTORYTAG;
|
|
||||||
else if(sc.Compare("time"))
|
|
||||||
strValue = TIME;
|
|
||||||
else if(sc.Compare("logtext"))
|
|
||||||
strValue = LOGTEXT;
|
|
||||||
else if(sc.Compare("globalvar"))
|
|
||||||
{
|
|
||||||
strValue = GLOBALVAR;
|
|
||||||
sc.MustGetToken(TK_IntConst);
|
|
||||||
if(sc.Number < 0 || sc.Number >= NUM_GLOBALVARS)
|
|
||||||
sc.ScriptError("Global variable number out of range: %d", sc.Number);
|
|
||||||
valueArgument = sc.Number;
|
|
||||||
}
|
|
||||||
else if(sc.Compare("globalarray"))
|
|
||||||
{
|
|
||||||
strValue = GLOBALARRAY;
|
|
||||||
sc.MustGetToken(TK_IntConst);
|
|
||||||
if(sc.Number < 0 || sc.Number >= NUM_GLOBALVARS)
|
|
||||||
sc.ScriptError("Global variable number out of range: %d", sc.Number);
|
|
||||||
valueArgument = sc.Number;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
sc.ScriptError("Unknown string '%s'.", sc.String);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
strValue = CONSTANT;
|
|
||||||
sc.MustGetToken(TK_StringConst);
|
|
||||||
if(sc.String[0] == '$')
|
|
||||||
str = GStrings[sc.String+1];
|
|
||||||
else
|
|
||||||
str = sc.String;
|
|
||||||
}
|
|
||||||
sc.MustGetToken(',');
|
sc.MustGetToken(',');
|
||||||
GetCoordinates(sc, fullScreenOffsets, startX, y);
|
GetCoordinates(sc, fullScreenOffsets, startX, y);
|
||||||
if(sc.CheckToken(',')) //spacing
|
if(sc.CheckToken(',')) //spacing
|
||||||
|
@ -659,6 +608,61 @@ class CommandDrawString : public SBarInfoCommand
|
||||||
|
|
||||||
RealignString();
|
RealignString();
|
||||||
}
|
}
|
||||||
|
void ParseStringValue(FScanner &sc)
|
||||||
|
{
|
||||||
|
if(sc.CheckToken(TK_Identifier))
|
||||||
|
{
|
||||||
|
if(sc.Compare("levelname"))
|
||||||
|
strValue = LEVELNAME;
|
||||||
|
else if(sc.Compare("levellump"))
|
||||||
|
strValue = LEVELLUMP;
|
||||||
|
else if(sc.Compare("skillname"))
|
||||||
|
strValue = SKILLNAME;
|
||||||
|
else if(sc.Compare("playerclass"))
|
||||||
|
strValue = PLAYERCLASS;
|
||||||
|
else if(sc.Compare("playername"))
|
||||||
|
strValue = PLAYERNAME;
|
||||||
|
else if(sc.Compare("ammo1tag"))
|
||||||
|
strValue = AMMO1TAG;
|
||||||
|
else if(sc.Compare("ammo2tag"))
|
||||||
|
strValue = AMMO2TAG;
|
||||||
|
else if(sc.Compare("weapontag"))
|
||||||
|
strValue = WEAPONTAG;
|
||||||
|
else if(sc.Compare("inventorytag"))
|
||||||
|
strValue = INVENTORYTAG;
|
||||||
|
else if(sc.Compare("time"))
|
||||||
|
strValue = TIME;
|
||||||
|
else if(sc.Compare("logtext"))
|
||||||
|
strValue = LOGTEXT;
|
||||||
|
else if(sc.Compare("globalvar"))
|
||||||
|
{
|
||||||
|
strValue = GLOBALVAR;
|
||||||
|
sc.MustGetToken(TK_IntConst);
|
||||||
|
if(sc.Number < 0 || sc.Number >= NUM_GLOBALVARS)
|
||||||
|
sc.ScriptError("Global variable number out of range: %d", sc.Number);
|
||||||
|
valueArgument = sc.Number;
|
||||||
|
}
|
||||||
|
else if(sc.Compare("globalarray"))
|
||||||
|
{
|
||||||
|
strValue = GLOBALARRAY;
|
||||||
|
sc.MustGetToken(TK_IntConst);
|
||||||
|
if(sc.Number < 0 || sc.Number >= NUM_GLOBALVARS)
|
||||||
|
sc.ScriptError("Global variable number out of range: %d", sc.Number);
|
||||||
|
valueArgument = sc.Number;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
sc.ScriptError("Unknown string '%s'.", sc.String);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strValue = CONSTANT;
|
||||||
|
sc.MustGetToken(TK_StringConst);
|
||||||
|
if(sc.String[0] == '$')
|
||||||
|
str = GStrings[sc.String+1];
|
||||||
|
else
|
||||||
|
str = sc.String;
|
||||||
|
}
|
||||||
|
}
|
||||||
void Reset()
|
void Reset()
|
||||||
{
|
{
|
||||||
switch(strValue)
|
switch(strValue)
|
||||||
|
@ -846,8 +850,9 @@ class CommandDrawNumber : public CommandDrawString
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CommandDrawNumber(SBarInfo *script) : CommandDrawString(script),
|
CommandDrawNumber(SBarInfo *script) : CommandDrawString(script),
|
||||||
fillZeros(false), whenNotZero(false), interpolationSpeed(0), drawValue(0),
|
fillZeros(false), whenNotZero(false), dontCap(false),
|
||||||
length(3), lowValue(-1), lowTranslation(CR_UNTRANSLATED), highValue(-1),
|
usePrefix(false), interpolationSpeed(0), drawValue(0), length(3),
|
||||||
|
lowValue(-1), lowTranslation(CR_UNTRANSLATED), highValue(-1),
|
||||||
highTranslation(CR_UNTRANSLATED), value(CONSTANT),
|
highTranslation(CR_UNTRANSLATED), value(CONSTANT),
|
||||||
inventoryItem(NULL)
|
inventoryItem(NULL)
|
||||||
{
|
{
|
||||||
|
@ -980,6 +985,8 @@ class CommandDrawNumber : public CommandDrawString
|
||||||
fillZeros = true;
|
fillZeros = true;
|
||||||
else if(sc.Compare("whennotzero"))
|
else if(sc.Compare("whennotzero"))
|
||||||
whenNotZero = true;
|
whenNotZero = true;
|
||||||
|
else if(sc.Compare("dontcap"))
|
||||||
|
dontCap = true;
|
||||||
else if(sc.Compare("drawshadow"))
|
else if(sc.Compare("drawshadow"))
|
||||||
{
|
{
|
||||||
if(sc.CheckToken('('))
|
if(sc.CheckToken('('))
|
||||||
|
@ -1014,6 +1021,21 @@ class CommandDrawNumber : public CommandDrawString
|
||||||
sc.ScriptError("Unknown alignment '%s'.", sc.String);
|
sc.ScriptError("Unknown alignment '%s'.", sc.String);
|
||||||
sc.MustGetToken(')');
|
sc.MustGetToken(')');
|
||||||
}
|
}
|
||||||
|
else if(sc.Compare("prefix"))
|
||||||
|
{
|
||||||
|
usePrefix = true;
|
||||||
|
sc.MustGetToken('(');
|
||||||
|
ParseStringValue(sc);
|
||||||
|
sc.MustGetToken(',');
|
||||||
|
sc.MustGetToken(TK_StringConst);
|
||||||
|
prefixPadding = sc.String;
|
||||||
|
if(strValue == CommandDrawString::CONSTANT)
|
||||||
|
{
|
||||||
|
usePrefix = false; // Use prefix just determines if we tick the string.
|
||||||
|
prefixPadding = str + prefixPadding;
|
||||||
|
}
|
||||||
|
sc.MustGetToken(')');
|
||||||
|
}
|
||||||
else
|
else
|
||||||
sc.ScriptError("Unknown flag '%s'.", sc.String);
|
sc.ScriptError("Unknown flag '%s'.", sc.String);
|
||||||
if(!sc.CheckToken('|'))
|
if(!sc.CheckToken('|'))
|
||||||
|
@ -1056,6 +1078,12 @@ class CommandDrawNumber : public CommandDrawString
|
||||||
}
|
}
|
||||||
void Tick(const SBarInfoMainBlock *block, const DSBarInfo *statusBar, bool hudChanged)
|
void Tick(const SBarInfoMainBlock *block, const DSBarInfo *statusBar, bool hudChanged)
|
||||||
{
|
{
|
||||||
|
if(usePrefix)
|
||||||
|
{
|
||||||
|
cache = -1; // Disable the cache since we are using the same variables.
|
||||||
|
CommandDrawString::Tick(block, statusBar, hudChanged);
|
||||||
|
}
|
||||||
|
|
||||||
int num = valueArgument;
|
int num = valueArgument;
|
||||||
switch(value)
|
switch(value)
|
||||||
{
|
{
|
||||||
|
@ -1222,25 +1250,28 @@ class CommandDrawNumber : public CommandDrawString
|
||||||
else if(highValue != -1 && drawValue >= highValue) //high
|
else if(highValue != -1 && drawValue >= highValue) //high
|
||||||
translation = highTranslation;
|
translation = highTranslation;
|
||||||
|
|
||||||
// 10^9 is a largest we can hold in a 32-bit int. So if we go any larger we have to toss out the positions limit.
|
bool useFillZeros = fillZeros;
|
||||||
int maxval = length <= 9 ? (int) ceil(pow(10., length))-1 : INT_MAX;
|
if(!dontCap)
|
||||||
if(!fillZeros || length == 1)
|
|
||||||
drawValue = clamp(drawValue, -maxval, maxval);
|
|
||||||
else //The community wanted negatives to take the last digit, but we can only do this if there is room
|
|
||||||
drawValue = clamp(drawValue, length <= 9 ? (int) -(ceil(pow(10., length-1))-1) : INT_MIN, maxval);
|
|
||||||
str.Format("%d", drawValue);
|
|
||||||
if(fillZeros)
|
|
||||||
{
|
{
|
||||||
if(drawValue < 0) //We don't want the negative just yet
|
// 10^9 is a largest we can hold in a 32-bit int. So if we go any larger we have to toss out the positions limit.
|
||||||
str.Format("%d", -drawValue);
|
int maxval = length <= 9 ? (int) ceil(pow(10., length))-1 : INT_MAX;
|
||||||
while(str.Len() < (unsigned int) length)
|
if(!fillZeros || length == 1)
|
||||||
{
|
drawValue = clamp(drawValue, -maxval, maxval);
|
||||||
if(drawValue < 0 && str.Len() == (unsigned int) (length-1))
|
else //The community wanted negatives to take the last digit, but we can only do this if there is room
|
||||||
str.Insert(0, "-");
|
drawValue = clamp(drawValue, length <= 9 ? (int) -(ceil(pow(10., length-1))-1) : INT_MIN, maxval);
|
||||||
else
|
|
||||||
str.Insert(0, "0");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else if(length <= 9)
|
||||||
|
{
|
||||||
|
int limit = (int) ceil(pow(10., length > 1 && drawValue < 0 ? length - 1 : length));
|
||||||
|
if(drawValue >= limit)
|
||||||
|
useFillZeros = true;
|
||||||
|
drawValue = drawValue%limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(useFillZeros)
|
||||||
|
str.Format("%s%s%0*d", usePrefix ? str.GetChars() : "", prefixPadding.GetChars(), drawValue < 0 ? length - 1 : length, drawValue);
|
||||||
|
else
|
||||||
|
str.Format("%s%s%d", usePrefix ? str.GetChars() : "", prefixPadding.GetChars(), drawValue);
|
||||||
|
|
||||||
RealignString();
|
RealignString();
|
||||||
}
|
}
|
||||||
|
@ -1278,6 +1309,8 @@ class CommandDrawNumber : public CommandDrawString
|
||||||
|
|
||||||
bool fillZeros;
|
bool fillZeros;
|
||||||
bool whenNotZero;
|
bool whenNotZero;
|
||||||
|
bool dontCap;
|
||||||
|
bool usePrefix;
|
||||||
|
|
||||||
int interpolationSpeed;
|
int interpolationSpeed;
|
||||||
int drawValue;
|
int drawValue;
|
||||||
|
@ -1291,6 +1324,8 @@ class CommandDrawNumber : public CommandDrawString
|
||||||
ValueType value;
|
ValueType value;
|
||||||
const PClass *inventoryItem;
|
const PClass *inventoryItem;
|
||||||
|
|
||||||
|
FString prefixPadding;
|
||||||
|
|
||||||
friend class CommandDrawInventoryBar;
|
friend class CommandDrawInventoryBar;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue