- added direct native variants to nearly all status bar function.

I skipped ValidateInvFirst because that one will have to be scriptified soon.
This commit is contained in:
Christoph Oelckers 2018-12-01 16:53:54 +01:00
parent 5169a5b119
commit 691652042c
4 changed files with 564 additions and 369 deletions

View File

@ -321,6 +321,31 @@ enum
HUDMSGLayer_Default = HUDMSGLayer_OverHUD, 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 class DBaseStatusBar : public DObject
{ {
friend class DSBarInfo; friend class DSBarInfo;
@ -497,7 +522,7 @@ void ST_Clear();
void ST_CreateStatusBar(bool bTitleLevel); void ST_CreateStatusBar(bool bTitleLevel);
extern FTexture *CrosshairImage; 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 enum DI_Flags

View File

@ -306,7 +306,9 @@ class CommandDrawImage : public SBarInfoCommandFlowControl
protected: protected:
void GetIcon(AInventory *item) void GetIcon(AInventory *item)
{ {
FTextureID icon = GetInventoryIcon(item, flags, &applyscale); int apply;
FTextureID icon = GetInventoryIcon(item, flags, &apply);
applyscale = !!apply;
if (applyscale) if (applyscale)
{ {

View File

@ -63,6 +63,7 @@
#define XHAIRPICKUPSIZE (2+XHAIRSHRINKSIZE) #define XHAIRPICKUPSIZE (2+XHAIRSHRINKSIZE)
#define POWERUPICONSIZE 32 #define POWERUPICONSIZE 32
IMPLEMENT_CLASS(DHUDFont, true, false);
IMPLEMENT_CLASS(DBaseStatusBar, false, true) IMPLEMENT_CLASS(DBaseStatusBar, false, true)
IMPLEMENT_POINTERS_START(DBaseStatusBar) IMPLEMENT_POINTERS_START(DBaseStatusBar)
@ -149,16 +150,6 @@ void ST_FormatMapName(FString &mapname, const char *mapnamecolor)
mapname << mapnamecolor << level.LevelName; 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 // Load crosshair definitions
@ -411,19 +402,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 // PROP Destroy
@ -533,12 +511,6 @@ DVector2 DBaseStatusBar::GetHUDScale() const
return{ double(realscale), double(realscale * (hud_aspectscale ? 1.2 : 1.)) }; 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 // PROC GetHUDScale
@ -552,16 +524,6 @@ void DBaseStatusBar::BeginStatusBar(int resW, int resH, int relTop, bool forceSc
fullscreenOffsets = false; 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 // PROC GetHUDScale
@ -577,24 +539,6 @@ void DBaseStatusBar::BeginHUD(int resW, int resH, double Alpha, bool forcescaled
fullscreenOffsets = true; 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 // PROC AttachToPlayer
@ -675,13 +619,6 @@ void DBaseStatusBar::Tick ()
} }
DEFINE_ACTION_FUNCTION(DBaseStatusBar, Tick)
{
PARAM_SELF_PROLOGUE(DBaseStatusBar);
self->Tick();
return 0;
}
void DBaseStatusBar::CallTick() void DBaseStatusBar::CallTick()
{ {
IFVIRTUAL(DBaseStatusBar, Tick) IFVIRTUAL(DBaseStatusBar, Tick)
@ -732,16 +669,6 @@ void DBaseStatusBar::AttachMessage (DHUDMessageBase *msg, uint32_t id, int layer
GC::WriteBarrier(msg); 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 // PROC DetachMessage
@ -770,14 +697,6 @@ DHUDMessageBase *DBaseStatusBar::DetachMessage (DHUDMessageBase *msg)
return NULL; 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) DHUDMessageBase *DBaseStatusBar::DetachMessage (uint32_t id)
{ {
for (size_t i = 0; i < countof(Messages); ++i) for (size_t i = 0; i < countof(Messages); ++i)
@ -800,13 +719,6 @@ DHUDMessageBase *DBaseStatusBar::DetachMessage (uint32_t id)
return NULL; return NULL;
} }
DEFINE_ACTION_FUNCTION(DBaseStatusBar, DetachMessageID)
{
PARAM_SELF_PROLOGUE(DBaseStatusBar);
PARAM_INT(id);
ACTION_RETURN_OBJECT(self->DetachMessage(id));
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //
// PROC DetachAllMessages // PROC DetachAllMessages
@ -829,14 +741,6 @@ void DBaseStatusBar::DetachAllMessages ()
} }
} }
DEFINE_ACTION_FUNCTION(DBaseStatusBar, DetachAllMessages)
{
PARAM_SELF_PROLOGUE(DBaseStatusBar);
self->DetachAllMessages();
return 0;
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //
// PROC ShowPlayerName // PROC ShowPlayerName
@ -1071,15 +975,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) void DBaseStatusBar::CallDraw(EHudState state, double ticFrac)
{ {
IFVIRTUAL(DBaseStatusBar, Draw) IFVIRTUAL(DBaseStatusBar, Draw)
@ -1153,16 +1048,6 @@ bool DBaseStatusBar::MustDrawLog(EHudState state)
return true; 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) void DBaseStatusBar::SetMugShotState(const char *stateName, bool waitTillDone, bool reset)
{ {
IFVIRTUAL(DBaseStatusBar, SetMugShotState) IFVIRTUAL(DBaseStatusBar, SetMugShotState)
@ -1356,13 +1241,6 @@ void DBaseStatusBar::ScreenSizeChanged ()
} }
} }
DEFINE_ACTION_FUNCTION(DBaseStatusBar, ScreenSizeChanged)
{
PARAM_SELF_PROLOGUE(DBaseStatusBar);
self->ScreenSizeChanged();
return 0;
}
void DBaseStatusBar::CallScreenSizeChanged() void DBaseStatusBar::CallScreenSizeChanged()
{ {
IFVIRTUAL(DBaseStatusBar, ScreenSizeChanged) IFVIRTUAL(DBaseStatusBar, ScreenSizeChanged)
@ -1464,14 +1342,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 uint32_t DBaseStatusBar::GetTranslation() const
{ {
if (gameinfo.gametype & GAME_Raven) if (gameinfo.gametype & GAME_Raven)
@ -1504,28 +1374,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 // draw stuff
@ -1651,78 +1499,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<DHUDFont>(fnt, spac, mono, sy, sy));
}
DEFINE_FIELD(DHUDFont, mFont);
//============================================================================ //============================================================================
// //
// draw a string // draw a string
@ -1853,19 +1629,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); if (font == nullptr) ThrowAbortException(X_READ_NIL, nullptr);
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 (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); 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. // resolve auto-alignment before making any adjustments to the position values.
@ -1890,7 +1656,6 @@ DEFINE_ACTION_FUNCTION(DBaseStatusBar, DrawString)
{ {
self->DrawString(font->mFont, string, x, y, flags, alpha, trans, font->mSpacing, font->mMonospaced, font->mShadowX, font->mShadowY); self->DrawString(font->mFont, string, x, y, flags, alpha, trans, font->mSpacing, font->mMonospaced, font->mShadowX, font->mShadowY);
} }
return 0;
} }
@ -1951,22 +1716,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 // draw stuff
@ -1989,20 +1738,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 // draw stuff
@ -2020,18 +1755,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 // CCMD showpop
@ -2057,27 +1780,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) static DObject *InitObject(PClass *type, int paramnum, VM_ARGS)
{ {
auto obj = type->CreateNew(); auto obj = type->CreateNew();
@ -2086,35 +1788,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 enum ENumFlags
{ {
@ -2122,43 +1795,23 @@ enum ENumFlags
FNF_FILLZEROS = 0x2, 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 }; 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) if (maxsize > 0 && maxsize < 10)
{ {
number = clamp(number, -maxvals[maxsize - 1], maxvals[maxsize]); number = clamp(number, -maxvals[maxsize - 1], maxvals[maxsize]);
} }
FString fmt; FString &fmt = *result;
if (minsize <= 1) fmt.Format("%s%d", prefix.GetChars(), number); 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 if (flags & FNF_FILLZEROS) fmt.Format("%s%0*d", prefix.GetChars(), minsize, number);
else fmt.Format("%s%*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);
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -2166,7 +1819,8 @@ DEFINE_ACTION_FUNCTION(DBaseStatusBar, GetMugshot)
// Weapons List // Weapons List
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
FTextureID GetInventoryIcon(AInventory *item, uint32_t flags, bool *applyscale)
FTextureID GetInventoryIcon(AInventory *item, uint32_t flags, int *applyscale)
{ {
if (applyscale != NULL) if (applyscale != NULL)
{ {
@ -2221,15 +1875,10 @@ FTextureID GetInventoryIcon(AInventory *item, uint32_t flags, bool *applyscale)
return picnum; return picnum;
} }
DEFINE_ACTION_FUNCTION(DBaseStatusBar, GetInventoryIcon) DEFINE_ACTION_FUNCTION(DBaseStatusBar, ValidateInvFirst)
{ {
PARAM_PROLOGUE; PARAM_SELF_PROLOGUE(DBaseStatusBar);
PARAM_OBJECT(item, AInventory); PARAM_INT(num);
PARAM_INT(flags); ACTION_RETURN_POINTER(self->ValidateInvFirst(num));
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);
} }

View File

@ -36,6 +36,10 @@
#include "v_font.h" #include "v_font.h"
#include "gstrings.h" #include "gstrings.h"
#include "a_keys.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)); 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<DHUDFont>(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<DHUDFont>(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, floorplane)
DEFINE_FIELD_X(Sector, sector_t, ceilingplane) DEFINE_FIELD_X(Sector, sector_t, ceilingplane)
DEFINE_FIELD_X(Sector, sector_t, Colormap) 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(Secplane, secplane_t, negiC)
DEFINE_FIELD_X(Vertex, vertex_t, p) 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);