diff --git a/src/g_statusbar/base_sbar.cpp b/src/g_statusbar/base_sbar.cpp index 0e50fc806..fc00d107a 100644 --- a/src/g_statusbar/base_sbar.cpp +++ b/src/g_statusbar/base_sbar.cpp @@ -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); +} + diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index 2593eaf24..4ca762448 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -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 diff --git a/src/scripting/vmthunks.cpp b/src/scripting/vmthunks.cpp index cbcc2dc72..b28c06de4 100644 --- a/src/scripting/vmthunks.cpp +++ b/src/scripting/vmthunks.cpp @@ -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(); diff --git a/wadsrc/static/zscript/ui/statusbar/statusbar.zs b/wadsrc/static/zscript/ui/statusbar/statusbar.zs index 7164e7628..c0ec25218 100644 --- a/wadsrc/static/zscript/ui/statusbar/statusbar.zs +++ b/wadsrc/static/zscript/ui/statusbar/statusbar.zs @@ -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);