mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-26 22:11:43 +00:00
- exposed the HUD message interface to ZScript.
Note that this is just the bare abstract interface. It is up to content makers to define usable HUD message classes and optionally contribute them to the engine.
This commit is contained in:
parent
dd893b6a0c
commit
bb16e34bf4
4 changed files with 106 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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<DHUDMessageBase*> Next = nullptr;
|
||||
uint32_t SBarID = 0;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue