- moved FormatNumber to the generic base class.
This commit is contained in:
parent
fd6b7f9274
commit
3f61ab7fbf
4 changed files with 46 additions and 45 deletions
|
|
@ -42,6 +42,7 @@
|
|||
#include "cmdlib.h"
|
||||
#include "texturemanager.h"
|
||||
#include "c_cvars.h"
|
||||
#include "vm.h"
|
||||
|
||||
FGameTexture* CrosshairImage;
|
||||
static int CrosshairNum;
|
||||
|
|
@ -196,3 +197,47 @@ void ST_DrawCrosshair(int phealth, double xpos, double ypos, double scale)
|
|||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
enum ENumFlags
|
||||
{
|
||||
FNF_WHENNOTZERO = 0x1,
|
||||
FNF_FILLZEROS = 0x2,
|
||||
};
|
||||
|
||||
void FormatNumber(int number, int minsize, int maxsize, int flags, const FString& prefix, FString* result)
|
||||
{
|
||||
static int maxvals[] = { 1, 9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999 };
|
||||
|
||||
if (number == 0 && (flags & FNF_WHENNOTZERO))
|
||||
{
|
||||
*result = "";
|
||||
return;
|
||||
}
|
||||
if (maxsize > 0 && maxsize < 10)
|
||||
{
|
||||
number = clamp(number, -maxvals[maxsize - 1], maxvals[maxsize]);
|
||||
}
|
||||
FString& fmt = *result;
|
||||
if (minsize <= 1) fmt.Format("%s%d", prefix.GetChars(), number);
|
||||
else if (flags & FNF_FILLZEROS) fmt.Format("%s%0*d", prefix.GetChars(), minsize, number);
|
||||
else fmt.Format("%s%*d", prefix.GetChars(), minsize, number);
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(DStatusBarCore, FormatNumber, FormatNumber)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
PARAM_INT(number);
|
||||
PARAM_INT(minsize);
|
||||
PARAM_INT(maxsize);
|
||||
PARAM_INT(flags);
|
||||
PARAM_STRING(prefix);
|
||||
FString fmt;
|
||||
FormatNumber(number, minsize, maxsize, flags, prefix, &fmt);
|
||||
ACTION_RETURN_STRING(fmt);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1092,10 +1092,6 @@ void DBaseStatusBar::RefreshBackground () const
|
|||
|
||||
void DBaseStatusBar::DrawCrosshair ()
|
||||
{
|
||||
uint32_t color;
|
||||
double size;
|
||||
int w, h;
|
||||
|
||||
if (!crosshairon)
|
||||
{
|
||||
return;
|
||||
|
|
@ -1950,31 +1946,6 @@ static DObject *InitObject(PClass *type, int paramnum, VM_ARGS)
|
|||
|
||||
|
||||
|
||||
enum ENumFlags
|
||||
{
|
||||
FNF_WHENNOTZERO = 0x1,
|
||||
FNF_FILLZEROS = 0x2,
|
||||
};
|
||||
|
||||
void FormatNumber(int number, int minsize, int maxsize, int flags, const FString &prefix, FString *result)
|
||||
{
|
||||
static int maxvals[] = { 1, 9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999 };
|
||||
|
||||
if (number == 0 && (flags & FNF_WHENNOTZERO))
|
||||
{
|
||||
*result = "";
|
||||
return;
|
||||
}
|
||||
if (maxsize > 0 && maxsize < 10)
|
||||
{
|
||||
number = clamp(number, -maxvals[maxsize - 1], maxvals[maxsize]);
|
||||
}
|
||||
FString &fmt = *result;
|
||||
if (minsize <= 1) fmt.Format("%s%d", prefix.GetChars(), number);
|
||||
else if (flags & FNF_FILLZEROS) fmt.Format("%s%0*d", prefix.GetChars(), minsize, number);
|
||||
else fmt.Format("%s%*d", prefix.GetChars(), minsize, number);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Weapons List
|
||||
|
|
|
|||
|
|
@ -2295,21 +2295,6 @@ DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, GetGlobalACSArrayValue, GetGlobalA
|
|||
ACTION_RETURN_INT(ACS_GlobalArrays[arrayno][index]);
|
||||
}
|
||||
|
||||
void FormatNumber(int number, int minsize, int maxsize, int flags, const FString &prefix, FString *result);
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, FormatNumber, FormatNumber)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
PARAM_INT(number);
|
||||
PARAM_INT(minsize);
|
||||
PARAM_INT(maxsize);
|
||||
PARAM_INT(flags);
|
||||
PARAM_STRING(prefix);
|
||||
FString fmt;
|
||||
FormatNumber(number, minsize, maxsize, flags, prefix, &fmt);
|
||||
ACTION_RETURN_STRING(fmt);
|
||||
}
|
||||
|
||||
static void ReceivedWeapon(DBaseStatusBar *self)
|
||||
{
|
||||
self->mugshot.Grin();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue