From 057604a7b1b6ab4e57c06d1517346568741ad148 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 1 Dec 2018 16:53:54 +0100 Subject: [PATCH] - added direct native variants to nearly all status bar function. I skipped ValidateInvFirst because that one will have to be scriptified soon. --- src/g_statusbar/sbar.h | 27 +- src/g_statusbar/sbarinfo_commands.cpp | 4 +- src/g_statusbar/shared_sbar.cpp | 383 +------------------ src/scripting/vmthunks.cpp | 519 ++++++++++++++++++++++++++ 4 files changed, 564 insertions(+), 369 deletions(-) diff --git a/src/g_statusbar/sbar.h b/src/g_statusbar/sbar.h index 326a36028..9085b2f09 100644 --- a/src/g_statusbar/sbar.h +++ b/src/g_statusbar/sbar.h @@ -321,6 +321,31 @@ enum HUDMSGLayer_Default = HUDMSGLayer_OverHUD, }; + +//============================================================================ +// +// encapsulates all settings a HUD font may need +// +//============================================================================ + +class DHUDFont : public DObject +{ + // this blocks CreateNew on this class which is the intent here. + DECLARE_ABSTRACT_CLASS(DHUDFont, DObject); + +public: + FFont *mFont; + int mSpacing; + bool mMonospaced; + int mShadowX; + int mShadowY; + + DHUDFont(FFont *f, int sp, bool ms, int sx, int sy) + : mFont(f), mSpacing(sp), mMonospaced(ms), mShadowX(sx), mShadowY(sy) + {} +}; + + class DBaseStatusBar : public DObject { friend class DSBarInfo; @@ -498,7 +523,7 @@ void ST_Clear(); void ST_CreateStatusBar(bool bTitleLevel); extern FTexture *CrosshairImage; -FTextureID GetInventoryIcon(AInventory *item, uint32_t flags, bool *applyscale = nullptr); +FTextureID GetInventoryIcon(AInventory *item, uint32_t flags, int *applyscale = nullptr); enum DI_Flags diff --git a/src/g_statusbar/sbarinfo_commands.cpp b/src/g_statusbar/sbarinfo_commands.cpp index 38373f328..e859d728e 100644 --- a/src/g_statusbar/sbarinfo_commands.cpp +++ b/src/g_statusbar/sbarinfo_commands.cpp @@ -306,7 +306,9 @@ class CommandDrawImage : public SBarInfoCommandFlowControl protected: void GetIcon(AInventory *item) { - FTextureID icon = GetInventoryIcon(item, flags, &applyscale); + int apply; + FTextureID icon = GetInventoryIcon(item, flags, &apply); + applyscale = !!apply; if (applyscale) { diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index c8bd2ecc3..1b106dcd0 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -69,6 +69,7 @@ #define XHAIRPICKUPSIZE (2+XHAIRSHRINKSIZE) #define POWERUPICONSIZE 32 +IMPLEMENT_CLASS(DHUDFont, true, false); IMPLEMENT_CLASS(DBaseStatusBar, false, true) IMPLEMENT_POINTERS_START(DBaseStatusBar) @@ -160,16 +161,6 @@ void ST_FormatMapName(FString &mapname, const char *mapnamecolor) mapname << mapnamecolor << level.LevelName; } -DEFINE_ACTION_FUNCTION(FLevelLocals, FormatMapName) -{ - PARAM_SELF_STRUCT_PROLOGUE(FLevelLocals); - PARAM_INT(cr); - char mapnamecolor[3] = { '\34', char(cr + 'A'), 0 }; - FString rets; - ST_FormatMapName(rets, mapnamecolor); - ACTION_RETURN_STRING(rets); -} - //--------------------------------------------------------------------------- // // Load crosshair definitions @@ -426,19 +417,6 @@ void DBaseStatusBar::SetDrawSize(int reltop, int hres, int vres) } -DEFINE_ACTION_FUNCTION(DBaseStatusBar, SetSize) -{ - PARAM_SELF_PROLOGUE(DBaseStatusBar); - PARAM_INT(rt); - PARAM_INT(vw); - PARAM_INT(vh); - PARAM_INT(hvw); - PARAM_INT(hvh); - self->SetSize(rt, vw, vh, hvw, hvh); - return 0; -} - - //--------------------------------------------------------------------------- // // PROP Destroy @@ -548,12 +526,6 @@ DVector2 DBaseStatusBar::GetHUDScale() const return{ double(realscale), double(realscale * (hud_aspectscale ? 1.2 : 1.)) }; } -DEFINE_ACTION_FUNCTION(DBaseStatusBar, GetHUDScale) -{ - PARAM_SELF_PROLOGUE(DBaseStatusBar); - ACTION_RETURN_VEC2(self->GetHUDScale()); -} - //--------------------------------------------------------------------------- // // PROC GetHUDScale @@ -567,16 +539,6 @@ void DBaseStatusBar::BeginStatusBar(int resW, int resH, int relTop, bool forceSc fullscreenOffsets = false; } -DEFINE_ACTION_FUNCTION(DBaseStatusBar, BeginStatusBar) -{ - PARAM_SELF_PROLOGUE(DBaseStatusBar); - PARAM_BOOL(fs); - PARAM_INT(w); - PARAM_INT(h); - PARAM_INT(r); - self->BeginStatusBar(w, h, r, fs); - return 0; -} //--------------------------------------------------------------------------- // // PROC GetHUDScale @@ -592,24 +554,6 @@ void DBaseStatusBar::BeginHUD(int resW, int resH, double Alpha, bool forcescaled fullscreenOffsets = true; } -DEFINE_ACTION_FUNCTION(DBaseStatusBar, BeginHUD) -{ - PARAM_SELF_PROLOGUE(DBaseStatusBar); - PARAM_FLOAT(a); - PARAM_BOOL(fs); - PARAM_INT(w); - PARAM_INT(h); - self->BeginHUD(w, h, a, fs); - return 0; -} - -DEFINE_ACTION_FUNCTION(DBaseStatusBar, UpdateScreenGeometry) -{ - PARAM_SELF_PROLOGUE(DBaseStatusBar); - setsizeneeded = true; - return 0; -} - //--------------------------------------------------------------------------- // // PROC AttachToPlayer @@ -690,13 +634,6 @@ void DBaseStatusBar::Tick () } -DEFINE_ACTION_FUNCTION(DBaseStatusBar, Tick) -{ - PARAM_SELF_PROLOGUE(DBaseStatusBar); - self->Tick(); - return 0; -} - void DBaseStatusBar::CallTick() { IFVIRTUAL(DBaseStatusBar, Tick) @@ -747,16 +684,6 @@ void DBaseStatusBar::AttachMessage (DHUDMessageBase *msg, uint32_t id, int layer GC::WriteBarrier(msg); } -DEFINE_ACTION_FUNCTION(DBaseStatusBar, AttachMessage) -{ - PARAM_SELF_PROLOGUE(DBaseStatusBar); - PARAM_OBJECT(msg, DHUDMessageBase); - PARAM_UINT(id); - PARAM_INT(layer); - self->AttachMessage(msg, id, layer); - return 0; -} - //--------------------------------------------------------------------------- // // PROC DetachMessage @@ -785,14 +712,6 @@ DHUDMessageBase *DBaseStatusBar::DetachMessage (DHUDMessageBase *msg) return NULL; } -DEFINE_ACTION_FUNCTION(DBaseStatusBar, DetachMessage) -{ - PARAM_SELF_PROLOGUE(DBaseStatusBar); - PARAM_OBJECT(msg, DHUDMessageBase); - ACTION_RETURN_OBJECT(self->DetachMessage(msg)); -} - - DHUDMessageBase *DBaseStatusBar::DetachMessage (uint32_t id) { for (size_t i = 0; i < countof(Messages); ++i) @@ -815,13 +734,6 @@ DHUDMessageBase *DBaseStatusBar::DetachMessage (uint32_t id) return NULL; } -DEFINE_ACTION_FUNCTION(DBaseStatusBar, DetachMessageID) -{ - PARAM_SELF_PROLOGUE(DBaseStatusBar); - PARAM_INT(id); - ACTION_RETURN_OBJECT(self->DetachMessage(id)); -} - //--------------------------------------------------------------------------- // // PROC DetachAllMessages @@ -844,14 +756,6 @@ void DBaseStatusBar::DetachAllMessages () } } -DEFINE_ACTION_FUNCTION(DBaseStatusBar, DetachAllMessages) -{ - PARAM_SELF_PROLOGUE(DBaseStatusBar); - self->DetachAllMessages(); - return 0; -} - - //--------------------------------------------------------------------------- // // PROC ShowPlayerName @@ -1087,15 +991,6 @@ void DBaseStatusBar::Draw (EHudState state, double ticFrac) } } -DEFINE_ACTION_FUNCTION(DBaseStatusBar, Draw) -{ - PARAM_SELF_PROLOGUE(DBaseStatusBar); - PARAM_INT(state); - PARAM_FLOAT(ticFrac); - self->Draw((EHudState)state, ticFrac); - return 0; -} - void DBaseStatusBar::CallDraw(EHudState state, double ticFrac) { IFVIRTUAL(DBaseStatusBar, Draw) @@ -1169,16 +1064,6 @@ bool DBaseStatusBar::MustDrawLog(EHudState state) return true; } -DEFINE_ACTION_FUNCTION(DBaseStatusBar, SetMugshotState) -{ - PARAM_SELF_PROLOGUE(DBaseStatusBar); - PARAM_STRING(statename); - PARAM_BOOL(wait); - PARAM_BOOL(reset); - self->mugshot.SetState(statename, wait, reset); - return 0; -} - void DBaseStatusBar::SetMugShotState(const char *stateName, bool waitTillDone, bool reset) { IFVIRTUAL(DBaseStatusBar, SetMugShotState) @@ -1397,13 +1282,6 @@ void DBaseStatusBar::ScreenSizeChanged () } } -DEFINE_ACTION_FUNCTION(DBaseStatusBar, ScreenSizeChanged) -{ - PARAM_SELF_PROLOGUE(DBaseStatusBar); - self->ScreenSizeChanged(); - return 0; -} - void DBaseStatusBar::CallScreenSizeChanged() { IFVIRTUAL(DBaseStatusBar, ScreenSizeChanged) @@ -1505,14 +1383,6 @@ AInventory *DBaseStatusBar::ValidateInvFirst (int numVisible) const } } -DEFINE_ACTION_FUNCTION(DBaseStatusBar, ValidateInvFirst) -{ - PARAM_SELF_PROLOGUE(DBaseStatusBar); - PARAM_INT(num); - ACTION_RETURN_POINTER(self->ValidateInvFirst(num)); -} - - uint32_t DBaseStatusBar::GetTranslation() const { if (gameinfo.gametype & GAME_Raven) @@ -1545,28 +1415,6 @@ void DBaseStatusBar::StatusbarToRealCoords(double &x, double &y, double &w, doub } } -DEFINE_ACTION_FUNCTION(DBaseStatusBar, StatusbarToRealCoords) -{ - PARAM_SELF_PROLOGUE(DBaseStatusBar); - PARAM_FLOAT(x); - PARAM_FLOAT(y); - PARAM_FLOAT(w); - PARAM_FLOAT(h); - self->StatusbarToRealCoords(x, y, w, h); - if (numret > 0) ret[0].SetFloat(x); - if (numret > 1) ret[1].SetFloat(y); - if (numret > 2) ret[2].SetFloat(w); - if (numret > 3) ret[3].SetFloat(h); - return MIN(4, numret); -} - - -DEFINE_ACTION_FUNCTION(DBaseStatusBar, GetTopOfStatusbar) -{ - PARAM_SELF_PROLOGUE(DBaseStatusBar); - ACTION_RETURN_INT(self->GetTopOfStatusbar()); -} - //============================================================================ // // draw stuff @@ -1692,78 +1540,6 @@ void DBaseStatusBar::DrawGraphic(FTextureID texture, double x, double y, int fla } -DEFINE_ACTION_FUNCTION(DBaseStatusBar, DrawTexture) -{ - PARAM_SELF_PROLOGUE(DBaseStatusBar); - PARAM_INT(texid); - PARAM_FLOAT(x); - PARAM_FLOAT(y); - PARAM_INT(flags); - PARAM_FLOAT(alpha); - PARAM_FLOAT(w); - PARAM_FLOAT(h); - PARAM_FLOAT(scaleX); - PARAM_FLOAT(scaleY); - if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); - self->DrawGraphic(FSetTextureID(texid), x, y, flags, alpha, w, h, scaleX, scaleY); - return 0; -} - -DEFINE_ACTION_FUNCTION(DBaseStatusBar, DrawImage) -{ - PARAM_SELF_PROLOGUE(DBaseStatusBar); - PARAM_STRING(texid); - PARAM_FLOAT(x); - PARAM_FLOAT(y); - PARAM_INT(flags); - PARAM_FLOAT(alpha); - PARAM_FLOAT(w); - PARAM_FLOAT(h); - PARAM_FLOAT(scaleX); - PARAM_FLOAT(scaleY); - if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); - self->DrawGraphic(TexMan.CheckForTexture(texid, ETextureType::Any), x, y, flags, alpha, w, h, scaleX, scaleY); - return 0; -} - -//============================================================================ -// -// encapsulates all settings a HUD font may need -// -//============================================================================ - -class DHUDFont : public DObject -{ - // this blocks CreateNew on this class which is the intent here. - DECLARE_ABSTRACT_CLASS(DHUDFont, DObject); - -public: - FFont *mFont; - int mSpacing; - bool mMonospaced; - int mShadowX; - int mShadowY; - - DHUDFont(FFont *f, int sp, bool ms, int sx, int sy) - : mFont(f), mSpacing(sp), mMonospaced(ms), mShadowX(sx), mShadowY(sy) - {} -}; - -IMPLEMENT_CLASS(DHUDFont, true, false); - -DEFINE_ACTION_FUNCTION(DHUDFont, Create) -{ - PARAM_PROLOGUE; - PARAM_POINTER(fnt, FFont); - PARAM_INT(spac); - PARAM_BOOL(mono); - PARAM_INT(sx); - PARAM_INT(sy); - ACTION_RETURN_POINTER(Create(fnt, spac, mono, sy, sy)); -} - -DEFINE_FIELD(DHUDFont, mFont); - //============================================================================ // // draw a string @@ -1894,19 +1670,9 @@ void DBaseStatusBar::DrawString(FFont *font, const FString &cstring, double x, d } -DEFINE_ACTION_FUNCTION(DBaseStatusBar, DrawString) +void SBar_DrawString(DBaseStatusBar *self, DHUDFont *font, const FString &string, double x, double y, int flags, int trans, double alpha, int wrapwidth, int linespacing) { - PARAM_SELF_PROLOGUE(DBaseStatusBar); - PARAM_POINTER_NOT_NULL(font, DHUDFont); - PARAM_STRING(string); - PARAM_FLOAT(x); - PARAM_FLOAT(y); - PARAM_INT(flags); - PARAM_INT(trans); - PARAM_FLOAT(alpha); - PARAM_INT(wrapwidth); - PARAM_INT(linespacing); - + if (font == nullptr) ThrowAbortException(X_READ_NIL, nullptr); if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); // resolve auto-alignment before making any adjustments to the position values. @@ -1931,7 +1697,6 @@ DEFINE_ACTION_FUNCTION(DBaseStatusBar, DrawString) { self->DrawString(font->mFont, string, x, y, flags, alpha, trans, font->mSpacing, font->mMonospaced, font->mShadowX, font->mShadowY); } - return 0; } @@ -1992,22 +1757,6 @@ void DBaseStatusBar::TransformRect(double &x, double &y, double &w, double &h, i } -DEFINE_ACTION_FUNCTION(DBaseStatusBar, TransformRect) -{ - PARAM_SELF_PROLOGUE(DBaseStatusBar); - PARAM_FLOAT(x); - PARAM_FLOAT(y); - PARAM_FLOAT(w); - PARAM_FLOAT(h); - PARAM_INT(flags); - self->TransformRect(x, y, w, h, flags); - if (numret > 0) ret[0].SetFloat(x); - if (numret > 1) ret[1].SetFloat(y); - if (numret > 2) ret[2].SetFloat(w); - if (numret > 3) ret[3].SetFloat(h); - return MIN(4, numret); -} - //============================================================================ // // draw stuff @@ -2030,20 +1779,6 @@ void DBaseStatusBar::Fill(PalEntry color, double x, double y, double w, double h } -DEFINE_ACTION_FUNCTION(DBaseStatusBar, Fill) -{ - PARAM_SELF_PROLOGUE(DBaseStatusBar); - PARAM_COLOR(color); - PARAM_FLOAT(x); - PARAM_FLOAT(y); - PARAM_FLOAT(w); - PARAM_FLOAT(h); - PARAM_INT(flags); - if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); - self->Fill(color, x, y, w, h, flags); - return 0; -} - //============================================================================ // // draw stuff @@ -2061,18 +1796,6 @@ void DBaseStatusBar::SetClipRect(double x, double y, double w, double h, int fla } -DEFINE_ACTION_FUNCTION(DBaseStatusBar, SetClipRect) -{ - PARAM_SELF_PROLOGUE(DBaseStatusBar); - PARAM_FLOAT(x); - PARAM_FLOAT(y); - PARAM_FLOAT(w); - PARAM_FLOAT(h); - PARAM_INT(flags); - self->SetClipRect(x, y, w, h, flags); - return 0; -} - //============================================================================ // // CCMD showpop @@ -2098,27 +1821,6 @@ CCMD (showpop) } } -DEFINE_FIELD(DBaseStatusBar, RelTop); -DEFINE_FIELD(DBaseStatusBar, HorizontalResolution); -DEFINE_FIELD(DBaseStatusBar, VerticalResolution); -DEFINE_FIELD(DBaseStatusBar, Centering); -DEFINE_FIELD(DBaseStatusBar, FixedOrigin); -DEFINE_FIELD(DBaseStatusBar, CompleteBorder); -DEFINE_FIELD(DBaseStatusBar, CrosshairSize); -DEFINE_FIELD(DBaseStatusBar, Displacement); -DEFINE_FIELD(DBaseStatusBar, CPlayer); -DEFINE_FIELD(DBaseStatusBar, ShowLog); -DEFINE_FIELD(DBaseStatusBar, Alpha); -DEFINE_FIELD(DBaseStatusBar, drawOffset); -DEFINE_FIELD(DBaseStatusBar, drawClip); -DEFINE_FIELD(DBaseStatusBar, fullscreenOffsets); -DEFINE_FIELD(DBaseStatusBar, defaultScale); -DEFINE_FIELD(DBaseStatusBar, artiflashTick); -DEFINE_FIELD(DBaseStatusBar, itemflashFade); - -DEFINE_GLOBAL(StatusBar); - - static DObject *InitObject(PClass *type, int paramnum, VM_ARGS) { auto obj = type->CreateNew(); @@ -2127,35 +1829,6 @@ static DObject *InitObject(PClass *type, int paramnum, VM_ARGS) } -DEFINE_ACTION_FUNCTION(DBaseStatusBar, GetGlobalACSString) -{ - PARAM_PROLOGUE; - PARAM_INT(index); - ACTION_RETURN_STRING(FBehavior::StaticLookupString(ACS_GlobalVars[index])); -} - -DEFINE_ACTION_FUNCTION(DBaseStatusBar, GetGlobalACSArrayString) -{ - PARAM_PROLOGUE; - PARAM_INT(arrayno); - PARAM_INT(index); - ACTION_RETURN_STRING(FBehavior::StaticLookupString(ACS_GlobalArrays[arrayno][index])); -} - -DEFINE_ACTION_FUNCTION(DBaseStatusBar, GetGlobalACSValue) -{ - PARAM_PROLOGUE; - PARAM_INT(index); - ACTION_RETURN_INT(ACS_GlobalVars[index]); -} - -DEFINE_ACTION_FUNCTION(DBaseStatusBar, GetGlobalACSArrayValue) -{ - PARAM_PROLOGUE; - PARAM_INT(arrayno); - PARAM_INT(index); - ACTION_RETURN_INT(ACS_GlobalArrays[arrayno][index]); -} enum ENumFlags { @@ -2163,43 +1836,23 @@ enum ENumFlags FNF_FILLZEROS = 0x2, }; -DEFINE_ACTION_FUNCTION(DBaseStatusBar, FormatNumber) +void FormatNumber(int number, int minsize, int maxsize, int flags, const FString &prefix, FString *result) { - PARAM_PROLOGUE; - PARAM_INT(number); - PARAM_INT(minsize); - PARAM_INT(maxsize); - PARAM_INT(flags); - PARAM_STRING(prefix); static int maxvals[] = { 1, 9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999 }; - if (number == 0 && (flags & FNF_WHENNOTZERO)) ACTION_RETURN_STRING(""); + if (number == 0 && (flags & FNF_WHENNOTZERO)) + { + *result = ""; + return; + } if (maxsize > 0 && maxsize < 10) { number = clamp(number, -maxvals[maxsize - 1], maxvals[maxsize]); } - FString fmt; + 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); - ACTION_RETURN_STRING(fmt); -} - -DEFINE_ACTION_FUNCTION(DBaseStatusBar, ReceivedWeapon) -{ - PARAM_SELF_PROLOGUE(DBaseStatusBar); - self->mugshot.Grin(); - return 0; -} - -DEFINE_ACTION_FUNCTION(DBaseStatusBar, GetMugshot) -{ - PARAM_SELF_PROLOGUE(DBaseStatusBar); - PARAM_INT(accuracy); - PARAM_INT(stateflags); - PARAM_STRING(def_face); - auto tex = self->mugshot.GetFace(self->CPlayer, def_face, accuracy, (FMugShot::StateFlags)stateflags); - ACTION_RETURN_INT(tex ? tex->id.GetIndex() : -1); } //--------------------------------------------------------------------------- @@ -2207,7 +1860,8 @@ DEFINE_ACTION_FUNCTION(DBaseStatusBar, GetMugshot) // Weapons List // //--------------------------------------------------------------------------- -FTextureID GetInventoryIcon(AInventory *item, uint32_t flags, bool *applyscale) + +FTextureID GetInventoryIcon(AInventory *item, uint32_t flags, int *applyscale) { if (applyscale != NULL) { @@ -2262,15 +1916,10 @@ FTextureID GetInventoryIcon(AInventory *item, uint32_t flags, bool *applyscale) return picnum; } -DEFINE_ACTION_FUNCTION(DBaseStatusBar, GetInventoryIcon) +DEFINE_ACTION_FUNCTION(DBaseStatusBar, ValidateInvFirst) { - PARAM_PROLOGUE; - PARAM_OBJECT(item, AInventory); - PARAM_INT(flags); - bool applyscale; - FTextureID icon = GetInventoryIcon(item, flags, &applyscale); - if (numret >= 1) ret[0].SetInt(icon.GetIndex()); - if (numret >= 2) ret[1].SetInt(applyscale); - return MIN(numret, 2); + PARAM_SELF_PROLOGUE(DBaseStatusBar); + PARAM_INT(num); + ACTION_RETURN_POINTER(self->ValidateInvFirst(num)); } diff --git a/src/scripting/vmthunks.cpp b/src/scripting/vmthunks.cpp index 83353ff52..0e63f1fcd 100644 --- a/src/scripting/vmthunks.cpp +++ b/src/scripting/vmthunks.cpp @@ -36,6 +36,10 @@ #include "v_font.h" #include "gstrings.h" #include "a_keys.h" +#include "sbar.h" +#include "doomstat.h" +#include "p_acs.h" +#include "a_pickups.h" //===================================================================================== // @@ -1613,6 +1617,499 @@ DEFINE_ACTION_FUNCTION_NATIVE(AKey, GetKeyType, P_GetKeyType) ACTION_RETURN_POINTER(P_GetKeyType(num)); } + +//===================================================================================== +// +// Statusbar exports +// +//===================================================================================== + +static void SBar_SetSize(DBaseStatusBar *self, int rt, int vw, int vh, int hvw, int hvh) +{ + self->SetSize(rt, vw, vh, hvw, hvh); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, SetSize, SBar_SetSize) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + PARAM_INT(rt); + PARAM_INT(vw); + PARAM_INT(vh); + PARAM_INT(hvw); + PARAM_INT(hvh); + self->SetSize(rt, vw, vh, hvw, hvh); + return 0; +} + +static void SBar_GetHUDScale(DBaseStatusBar *self, DVector2 *result) +{ + *result = self->GetHUDScale(); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, GetHUDScale, SBar_GetHUDScale) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + ACTION_RETURN_VEC2(self->GetHUDScale()); +} + +static void BeginStatusBar(DBaseStatusBar *self, bool fs, int w, int h, int r) +{ + self->BeginStatusBar(w, h, r, fs); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, BeginStatusBar, BeginStatusBar) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + PARAM_BOOL(fs); + PARAM_INT(w); + PARAM_INT(h); + PARAM_INT(r); + self->BeginStatusBar(w, h, r, fs); + return 0; +} + +static void BeginHUD(DBaseStatusBar *self, double a, bool fs, int w, int h) +{ + self->BeginHUD(w, h, a, fs); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, BeginHUD, BeginHUD) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + PARAM_FLOAT(a); + PARAM_BOOL(fs); + PARAM_INT(w); + PARAM_INT(h); + self->BeginHUD(w, h, a, fs); + return 0; +} + +static void UpdateScreenGeometry(DBaseStatusBar *) +{ + setsizeneeded = true; +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, UpdateScreenGeometry, UpdateScreenGeometry) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + setsizeneeded = true; + return 0; +} + +static void SBar_Tick(DBaseStatusBar *self) +{ + self->Tick(); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, Tick, SBar_Tick) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + self->Tick(); + return 0; +} + +static void SBar_AttachMessage(DBaseStatusBar *self, DHUDMessageBase *msg, unsigned id, int layer) +{ + self->AttachMessage(msg, id, layer); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, AttachMessage, SBar_AttachMessage) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + PARAM_OBJECT(msg, DHUDMessageBase); + PARAM_UINT(id); + PARAM_INT(layer); + self->AttachMessage(msg, id, layer); + return 0; +} + +static void SBar_DetachMessage(DBaseStatusBar *self, DHUDMessageBase *msg) +{ + self->DetachMessage(msg); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, DetachMessage, SBar_DetachMessage) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + PARAM_OBJECT(msg, DHUDMessageBase); + ACTION_RETURN_OBJECT(self->DetachMessage(msg)); +} + +static void SBar_DetachMessageID(DBaseStatusBar *self, unsigned id) +{ + self->DetachMessage(id); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, DetachMessageID, SBar_DetachMessageID) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + PARAM_INT(id); + ACTION_RETURN_OBJECT(self->DetachMessage(id)); +} + +static void SBar_DetachAllMessages(DBaseStatusBar *self) +{ + self->DetachAllMessages(); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, DetachAllMessages, SBar_DetachAllMessages) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + self->DetachAllMessages(); + return 0; +} + +static void SBar_Draw(DBaseStatusBar *self, int state, double ticFrac) +{ + self->Draw((EHudState)state, ticFrac); +} + + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, Draw, SBar_Draw) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + PARAM_INT(state); + PARAM_FLOAT(ticFrac); + self->Draw((EHudState)state, ticFrac); + return 0; +} + +static void SetMugshotState(DBaseStatusBar *self, const FString &statename, bool wait, bool reset) +{ + self->mugshot.SetState(statename, wait, reset); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, SetMugshotState, SetMugshotState) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + PARAM_STRING(statename); + PARAM_BOOL(wait); + PARAM_BOOL(reset); + self->mugshot.SetState(statename, wait, reset); + return 0; +} + +static void SBar_ScreenSizeChanged(DBaseStatusBar *self) +{ + self->ScreenSizeChanged(); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, ScreenSizeChanged, SBar_ScreenSizeChanged) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + self->ScreenSizeChanged(); + return 0; +} + +static double StatusbarToRealCoords(DBaseStatusBar *self, double x, double y, double w, double h, double *py, double *pw, double *ph) +{ + self->StatusbarToRealCoords(x, y, w, h); + *py = y; + *pw = w; + *ph = h; + return x; +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, StatusbarToRealCoords, StatusbarToRealCoords) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + PARAM_FLOAT(x); + PARAM_FLOAT(y); + PARAM_FLOAT(w); + PARAM_FLOAT(h); + self->StatusbarToRealCoords(x, y, w, h); + if (numret > 0) ret[0].SetFloat(x); + if (numret > 1) ret[1].SetFloat(y); + if (numret > 2) ret[2].SetFloat(w); + if (numret > 3) ret[3].SetFloat(h); + return MIN(4, numret); +} + +static int GetTopOfStatusbar(DBaseStatusBar *self) +{ + return self->GetTopOfStatusbar(); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, GetTopOfStatusbar, GetTopOfStatusbar) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + ACTION_RETURN_INT(self->GetTopOfStatusbar()); +} + +void SBar_DrawTexture(DBaseStatusBar *self, int texid, double x, double y, int flags, double alpha, double w, double h, double scaleX, double scaleY) +{ + if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); + self->DrawGraphic(FSetTextureID(texid), x, y, flags, alpha, w, h, scaleX, scaleY); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, DrawTexture, SBar_DrawTexture) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + PARAM_INT(texid); + PARAM_FLOAT(x); + PARAM_FLOAT(y); + PARAM_INT(flags); + PARAM_FLOAT(alpha); + PARAM_FLOAT(w); + PARAM_FLOAT(h); + PARAM_FLOAT(scaleX); + PARAM_FLOAT(scaleY); + SBar_DrawTexture(self, texid, x, y, flags, alpha, w, h, scaleX, scaleY); + return 0; +} + +void SBar_DrawImage(DBaseStatusBar *self, const FString &texid, double x, double y, int flags, double alpha, double w, double h, double scaleX, double scaleY) +{ + if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); + self->DrawGraphic(TexMan.CheckForTexture(texid, ETextureType::Any), x, y, flags, alpha, w, h, scaleX, scaleY); +} + +DEFINE_ACTION_FUNCTION(DBaseStatusBar, DrawImage) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + PARAM_STRING(texid); + PARAM_FLOAT(x); + PARAM_FLOAT(y); + PARAM_INT(flags); + PARAM_FLOAT(alpha); + PARAM_FLOAT(w); + PARAM_FLOAT(h); + PARAM_FLOAT(scaleX); + PARAM_FLOAT(scaleY); + SBar_DrawImage(self, texid, x, y, flags, alpha, w, h, scaleX, scaleY); + return 0; +} + +void SBar_DrawString(DBaseStatusBar *self, DHUDFont *font, const FString &string, double x, double y, int flags, int trans, double alpha, int wrapwidth, int linespacing); + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, DrawString, SBar_DrawString) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + PARAM_POINTER_NOT_NULL(font, DHUDFont); + PARAM_STRING(string); + PARAM_FLOAT(x); + PARAM_FLOAT(y); + PARAM_INT(flags); + PARAM_INT(trans); + PARAM_FLOAT(alpha); + PARAM_INT(wrapwidth); + PARAM_INT(linespacing); + SBar_DrawString(self, font, string, x, y, flags, trans, alpha, wrapwidth, linespacing); + return 0; +} + +static double SBar_TransformRect(DBaseStatusBar *self, double x, double y, double w, double h, int flags, double *py, double *pw, double *ph) +{ + self->TransformRect(x, y, w, h, flags); + *py = y; + *pw = w; + *ph = h; + return x; +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, TransformRect, SBar_TransformRect) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + PARAM_FLOAT(x); + PARAM_FLOAT(y); + PARAM_FLOAT(w); + PARAM_FLOAT(h); + PARAM_INT(flags); + self->TransformRect(x, y, w, h, flags); + if (numret > 0) ret[0].SetFloat(x); + if (numret > 1) ret[1].SetFloat(y); + if (numret > 2) ret[2].SetFloat(w); + if (numret > 3) ret[3].SetFloat(h); + return MIN(4, numret); +} + +static void SBar_Fill(DBaseStatusBar *self, int color, double x, double y, double w, double h, int flags) +{ + if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); + self->Fill(color, x, y, w, h, flags); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, Fill, SBar_Fill) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + PARAM_COLOR(color); + PARAM_FLOAT(x); + PARAM_FLOAT(y); + PARAM_FLOAT(w); + PARAM_FLOAT(h); + PARAM_INT(flags); + SBar_Fill(self, color, x, y, w, h, flags); + return 0; +} + +static void SBar_SetClipRect(DBaseStatusBar *self, int color, double x, double y, double w, double h, int flags) +{ + self->SetClipRect(x, y, w, h, flags); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, SetClipRect, SBar_SetClipRect) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + PARAM_FLOAT(x); + PARAM_FLOAT(y); + PARAM_FLOAT(w); + PARAM_FLOAT(h); + PARAM_INT(flags); + self->SetClipRect(x, y, w, h, flags); + return 0; +} + +static void GetGlobalACSString(int index, FString *result) +{ + *result = FBehavior::StaticLookupString(ACS_GlobalVars[index]); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, GetGlobalACSString, GetGlobalACSString) +{ + PARAM_PROLOGUE; + PARAM_INT(index); + ACTION_RETURN_STRING(FBehavior::StaticLookupString(ACS_GlobalVars[index])); +} + +static void GetGlobalACSArrayString(int arrayno, int index, FString *result) +{ + *result = FBehavior::StaticLookupString(ACS_GlobalVars[index]); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, GetGlobalACSArrayString, GetGlobalACSArrayString) +{ + PARAM_PROLOGUE; + PARAM_INT(arrayno); + PARAM_INT(index); + ACTION_RETURN_STRING(FBehavior::StaticLookupString(ACS_GlobalArrays[arrayno][index])); +} + +static int GetGlobalACSValue(int index) +{ + return (ACS_GlobalVars[index]); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, GetGlobalACSValue, GetGlobalACSValue) +{ + PARAM_PROLOGUE; + PARAM_INT(index); + ACTION_RETURN_INT(ACS_GlobalVars[index]); +} + +static int GetGlobalACSArrayValue(int arrayno, int index) +{ + return (ACS_GlobalArrays[arrayno][index]); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, GetGlobalACSArrayValue, GetGlobalACSArrayValue) +{ + PARAM_PROLOGUE; + PARAM_INT(arrayno); + PARAM_INT(index); + 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(); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, ReceivedWeapon, ReceivedWeapon) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + ReceivedWeapon(self); + return 0; +} + +static int GetMugshot(DBaseStatusBar *self, int accuracy, int stateflags, const FString &def_face) +{ + auto tex = self->mugshot.GetFace(self->CPlayer, def_face, accuracy, (FMugShot::StateFlags)stateflags); + return (tex ? tex->id.GetIndex() : -1); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, GetMugshot, GetMugshot) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + PARAM_INT(accuracy); + PARAM_INT(stateflags); + PARAM_STRING(def_face); + ACTION_RETURN_INT(GetMugshot(self, accuracy, stateflags, def_face)); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, GetInventoryIcon, GetInventoryIcon) +{ + PARAM_PROLOGUE; + PARAM_OBJECT(item, AInventory); + PARAM_INT(flags); + int applyscale; + FTextureID icon = GetInventoryIcon(item, flags, &applyscale); + if (numret >= 1) ret[0].SetInt(icon.GetIndex()); + if (numret >= 2) ret[1].SetInt(applyscale); + return MIN(numret, 2); +} + +//===================================================================================== +// +// +// +//===================================================================================== + +DHUDFont *CreateHudFont(FFont *fnt, int spac, bool mono, int sx, int sy) +{ + return (Create(fnt, spac, mono, sy, sy)); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DHUDFont, Create, CreateHudFont) +{ + PARAM_PROLOGUE; + PARAM_POINTER(fnt, FFont); + PARAM_INT(spac); + PARAM_BOOL(mono); + PARAM_INT(sx); + PARAM_INT(sy); + ACTION_RETURN_POINTER(Create(fnt, spac, mono, sy, sy)); +} + + +//===================================================================================== +// +// +// +//===================================================================================== + +void FormatMapName(FLevelLocals *self, int cr, FString *result) +{ + char mapnamecolor[3] = { '\34', char(cr + 'A'), 0 }; + ST_FormatMapName(*result, mapnamecolor); +} + + +DEFINE_ACTION_FUNCTION(FLevelLocals, FormatMapName) +{ + PARAM_SELF_STRUCT_PROLOGUE(FLevelLocals); + PARAM_INT(cr); + FString rets; + FormatMapName(self, cr, &rets); + ACTION_RETURN_STRING(rets); +} + + + DEFINE_FIELD_X(Sector, sector_t, floorplane) DEFINE_FIELD_X(Sector, sector_t, ceilingplane) DEFINE_FIELD_X(Sector, sector_t, Colormap) @@ -1690,3 +2187,25 @@ DEFINE_FIELD_X(Secplane, secplane_t, D) DEFINE_FIELD_X(Secplane, secplane_t, negiC) DEFINE_FIELD_X(Vertex, vertex_t, p) + +DEFINE_FIELD(DBaseStatusBar, RelTop); +DEFINE_FIELD(DBaseStatusBar, HorizontalResolution); +DEFINE_FIELD(DBaseStatusBar, VerticalResolution); +DEFINE_FIELD(DBaseStatusBar, Centering); +DEFINE_FIELD(DBaseStatusBar, FixedOrigin); +DEFINE_FIELD(DBaseStatusBar, CompleteBorder); +DEFINE_FIELD(DBaseStatusBar, CrosshairSize); +DEFINE_FIELD(DBaseStatusBar, Displacement); +DEFINE_FIELD(DBaseStatusBar, CPlayer); +DEFINE_FIELD(DBaseStatusBar, ShowLog); +DEFINE_FIELD(DBaseStatusBar, Alpha); +DEFINE_FIELD(DBaseStatusBar, drawOffset); +DEFINE_FIELD(DBaseStatusBar, drawClip); +DEFINE_FIELD(DBaseStatusBar, fullscreenOffsets); +DEFINE_FIELD(DBaseStatusBar, defaultScale); +DEFINE_FIELD(DBaseStatusBar, artiflashTick); +DEFINE_FIELD(DBaseStatusBar, itemflashFade); + +DEFINE_FIELD(DHUDFont, mFont); + +DEFINE_GLOBAL(StatusBar);