diff --git a/src/g_shared/hudmessages.cpp b/src/g_shared/hudmessages.cpp index 073a02c68..32465f7b1 100644 --- a/src/g_shared/hudmessages.cpp +++ b/src/g_shared/hudmessages.cpp @@ -40,6 +40,7 @@ #include "cmdlib.h" #include "doomstat.h" #include "serializer.h" +#include "vm.h" EXTERN_CVAR(Int, con_scaletext) @@ -66,6 +67,61 @@ void DHUDMessageBase::Serialize(FSerializer &arc) ("sbarid", SBarID); } +DEFINE_ACTION_FUNCTION(DHUDMessageBase, Tick) +{ + PARAM_SELF_PROLOGUE(DHUDMessageBase); + ACTION_RETURN_BOOL(self->Tick()); +} + +DEFINE_ACTION_FUNCTION(DHUDMessageBase, ScreenSizeChanged) +{ + PARAM_SELF_PROLOGUE(DHUDMessageBase); + self->ScreenSizeChanged(); + return 0; +} + +DEFINE_ACTION_FUNCTION(DHUDMessageBase, Draw) +{ + PARAM_SELF_PROLOGUE(DHUDMessageBase); + PARAM_INT(bottom); + PARAM_INT(visibility); + self->Draw(bottom, visibility); + return 0; +} + +bool DHUDMessageBase::CallTick() +{ + IFVIRTUAL(DHUDMessageBase, Tick) + { + VMValue params[] = { (DObject*)this }; + int retval; + VMReturn ret; ret.IntAt(&retval); + VMCall(func, params, countof(params), &ret, 1); + return !!retval; + } + return Tick(); +} + +void DHUDMessageBase::CallScreenSizeChanged() +{ + IFVIRTUAL(DHUDMessageBase, ScreenSizeChanged) + { + VMValue params[] = { (DObject*)this }; + VMCall(func, params, countof(params), nullptr, 0); + } + else ScreenSizeChanged(); +} + +void DHUDMessageBase::CallDraw(int bottom, int visibility) +{ + IFVIRTUAL(DHUDMessageBase, Draw) + { + VMValue params[] = { (DObject*)this, bottom, visibility }; + VMCall(func, params, countof(params), nullptr, 0); + } + else Draw(bottom, visibility); +} + //============================================================================ // // DHUDMessage Constructor diff --git a/src/g_statusbar/sbar.h b/src/g_statusbar/sbar.h index 13e051c6d..ba3d379b8 100644 --- a/src/g_statusbar/sbar.h +++ b/src/g_statusbar/sbar.h @@ -71,6 +71,10 @@ public: virtual void ScreenSizeChanged() {} virtual void Draw(int bottom, int visibility) {} + bool CallTick(); // Returns true to indicate time for removal + void CallScreenSizeChanged(); + void CallDraw(int bottom, int visibility); + private: TObjPtr Next = nullptr; uint32_t SBarID = 0; diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index b097002fe..d9fa88cc2 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -601,7 +601,7 @@ void DBaseStatusBar::Tick () { DHUDMessageBase *next = msg->Next; - if (msg->Tick ()) + if (msg->CallTick ()) { *prev = next; msg->Destroy(); @@ -697,6 +697,16 @@ void DBaseStatusBar::AttachMessage (DHUDMessageBase *msg, uint32_t id, int layer GC::WriteBarrier(container, 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 @@ -725,6 +735,14 @@ 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) @@ -747,6 +765,13 @@ 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 @@ -769,6 +794,14 @@ void DBaseStatusBar::DetachAllMessages () } } +DEFINE_ACTION_FUNCTION(DBaseStatusBar, DetachAllMessages) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + self->DetachAllMessages(); + return 0; +} + + //--------------------------------------------------------------------------- // // PROC ShowPlayerName @@ -954,7 +987,7 @@ void DBaseStatusBar::DrawMessages (int layer, int bottom) while (msg) { DHUDMessageBase *next = msg->Next; - msg->Draw (bottom, visibility); + msg->CallDraw (bottom, visibility); msg = next; } } @@ -1310,7 +1343,7 @@ void DBaseStatusBar::ScreenSizeChanged () DHUDMessageBase *message = Messages[i]; while (message != NULL) { - message->ScreenSizeChanged (); + message->CallScreenSizeChanged (); message = message->Next; } } diff --git a/wadsrc/static/zscript/statusbar/statusbar.txt b/wadsrc/static/zscript/statusbar/statusbar.txt index 56e831f97..29f9d01b0 100644 --- a/wadsrc/static/zscript/statusbar/statusbar.txt +++ b/wadsrc/static/zscript/statusbar/statusbar.txt @@ -101,6 +101,12 @@ class InventoryBarState ui } +class HUDMessageBase native ui +{ + virtual native bool Tick(); + virtual native void ScreenSizeChanged(); + virtual native void Draw(int bottom, int visibility); +} class BaseStatusBar native ui { @@ -291,6 +297,10 @@ class BaseStatusBar native ui private HUDFont mSmallFont; + native void AttachMessage(HUDMessageBase msg); + native HUDMessageBase DetachMessage(HUDMessageBase msg); + native HUDMessageBase DetachMessageID(uint msgid); + native void DetachAllMessages(); native void SetSize(int height, int vwidth, int vheight, int hwidth = -1, int hheight = -1); native Vector2 GetHUDScale();