mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-24 21:21:04 +00:00
- 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();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class StatusBarCore native
|
||||
{
|
||||
native static String FormatNumber(int number, int minsize = 0, int maxsize = 0, int format = 0, String prefix = "");
|
||||
}
|
||||
|
||||
struct MugShot
|
||||
|
@ -354,7 +355,6 @@ class BaseStatusBar : StatusBarCore native ui
|
|||
native void DrawString(HUDFont font, String string, Vector2 pos, int flags = 0, int translation = Font.CR_UNTRANSLATED, double Alpha = 1., int wrapwidth = -1, int linespacing = 4, Vector2 scale = (1, 1));
|
||||
native double, double, double, double TransformRect(double x, double y, double w, double h, int flags = 0);
|
||||
native void Fill(Color col, double x, double y, double w, double h, int flags = 0);
|
||||
native static String FormatNumber(int number, int minsize = 0, int maxsize = 0, int format = 0, String prefix = "");
|
||||
native double, double, double, double StatusbarToRealCoords(double x, double y=0, double w=0, double h=0);
|
||||
native int GetTopOfStatusBar();
|
||||
native void SetClipRect(double x, double y, double w, double h, int flags = 0);
|
||||
|
|
Loading…
Reference in a new issue