mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-10 14:51:51 +00:00
- split off the interface part of DHUDMessage into an abstract base class.
The purpose is to allow creating custom message types in ZScript.
This commit is contained in:
parent
711471e9dd
commit
dd893b6a0c
3 changed files with 61 additions and 38 deletions
|
@ -43,12 +43,14 @@
|
|||
|
||||
EXTERN_CVAR(Int, con_scaletext)
|
||||
|
||||
IMPLEMENT_CLASS(DHUDMessage, false, true)
|
||||
|
||||
IMPLEMENT_POINTERS_START(DHUDMessage)
|
||||
IMPLEMENT_POINTER(Next)
|
||||
IMPLEMENT_CLASS(DHUDMessageBase, true, true)
|
||||
IMPLEMENT_POINTERS_START(DHUDMessageBase)
|
||||
IMPLEMENT_POINTER(Next)
|
||||
IMPLEMENT_POINTERS_END
|
||||
|
||||
|
||||
IMPLEMENT_CLASS(DHUDMessage, false, false)
|
||||
|
||||
IMPLEMENT_CLASS(DHUDMessageFadeOut, false, false)
|
||||
IMPLEMENT_CLASS(DHUDMessageFadeInOut, false, false)
|
||||
IMPLEMENT_CLASS(DHUDMessageTypeOnFadeOut, false, false)
|
||||
|
@ -57,6 +59,13 @@ IMPLEMENT_CLASS(DHUDMessageTypeOnFadeOut, false, false)
|
|||
* Basic HUD message. Appears and disappears without any special effects *
|
||||
*************************************************************************/
|
||||
|
||||
void DHUDMessageBase::Serialize(FSerializer &arc)
|
||||
{
|
||||
Super::Serialize(arc);
|
||||
arc("next", Next)
|
||||
("sbarid", SBarID);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
//
|
||||
// DHUDMessage Constructor
|
||||
|
@ -130,7 +139,6 @@ DHUDMessage::DHUDMessage (FFont *font, const char *text, float x, float y, int h
|
|||
WrapWidth = 0;
|
||||
HandleAspect = true;
|
||||
Top = y;
|
||||
Next = NULL;
|
||||
Lines = NULL;
|
||||
HoldTics = (int)(holdTime * TICRATE);
|
||||
Tics = 0;
|
||||
|
@ -184,10 +192,8 @@ void DHUDMessage::Serialize(FSerializer &arc)
|
|||
("tics", Tics)
|
||||
("state", State)
|
||||
.Enum("textcolor", TextColor)
|
||||
("sbarid", SBarID)
|
||||
("sourcetext", SourceText)
|
||||
("font", Font)
|
||||
("next", Next)
|
||||
("hudwidth", HUDWidth)
|
||||
("hudheight", HUDHeight)
|
||||
("nowrap", NoWrap)
|
||||
|
|
|
@ -59,10 +59,30 @@ bool ST_IsLatencyVisible();
|
|||
|
||||
// HUD Message base object --------------------------------------------------
|
||||
|
||||
class DHUDMessage : public DObject
|
||||
// This is a mo-op base class to allow derived ZScript message types that can be managed by the status bar.
|
||||
class DHUDMessageBase : public DObject
|
||||
{
|
||||
DECLARE_CLASS (DHUDMessage, DObject)
|
||||
DECLARE_CLASS(DHUDMessageBase, DObject)
|
||||
HAS_OBJECT_POINTERS
|
||||
|
||||
public:
|
||||
virtual void Serialize(FSerializer &arc);
|
||||
virtual bool Tick() { return true; } // Returns true to indicate time for removal
|
||||
virtual void ScreenSizeChanged() {}
|
||||
virtual void Draw(int bottom, int visibility) {}
|
||||
|
||||
private:
|
||||
TObjPtr<DHUDMessageBase*> Next = nullptr;
|
||||
uint32_t SBarID = 0;
|
||||
friend class DBaseStatusBar;
|
||||
|
||||
};
|
||||
|
||||
// HUD Message --------------------------------------------------
|
||||
|
||||
class DHUDMessage : public DHUDMessageBase
|
||||
{
|
||||
DECLARE_CLASS (DHUDMessage, DHUDMessageBase)
|
||||
public:
|
||||
DHUDMessage (FFont *font, const char *text, float x, float y, int hudwidth, int hudheight,
|
||||
EColorRange textColor, float holdTime);
|
||||
|
@ -70,12 +90,12 @@ public:
|
|||
|
||||
virtual void Serialize(FSerializer &arc);
|
||||
|
||||
void Draw (int bottom, int visibility);
|
||||
virtual void Draw (int bottom, int visibility) override;
|
||||
virtual void ResetText (const char *text);
|
||||
virtual void DrawSetup ();
|
||||
virtual void DoDraw (int linenum, int x, int y, bool clean, int hudheight);
|
||||
virtual bool Tick (); // Returns true to indicate time for removal
|
||||
virtual void ScreenSizeChanged ();
|
||||
virtual bool Tick () override;
|
||||
virtual void ScreenSizeChanged () override;
|
||||
|
||||
void SetVisibility(int vis)
|
||||
{
|
||||
|
@ -130,11 +150,8 @@ protected:
|
|||
DHUDMessage () : SourceText(NULL) {}
|
||||
|
||||
private:
|
||||
TObjPtr<DHUDMessage*> Next;
|
||||
uint32_t SBarID;
|
||||
char *SourceText;
|
||||
|
||||
friend class DBaseStatusBar;
|
||||
};
|
||||
|
||||
// HUD message visibility flags
|
||||
|
@ -360,9 +377,9 @@ public:
|
|||
void SetSize(int reltop = 32, int hres = 320, int vres = 200, int hhres = -1, int hvres = -1);
|
||||
void OnDestroy() override;
|
||||
|
||||
void AttachMessage (DHUDMessage *msg, uint32_t id=0, int layer=HUDMSGLayer_Default);
|
||||
DHUDMessage *DetachMessage (DHUDMessage *msg);
|
||||
DHUDMessage *DetachMessage (uint32_t id);
|
||||
void AttachMessage (DHUDMessageBase *msg, uint32_t id=0, int layer=HUDMSGLayer_Default);
|
||||
DHUDMessageBase *DetachMessage (DHUDMessageBase *msg);
|
||||
DHUDMessageBase *DetachMessage (uint32_t id);
|
||||
void DetachAllMessages ();
|
||||
void ShowPlayerName ();
|
||||
double GetDisplacement() { return Displacement; }
|
||||
|
@ -455,7 +472,7 @@ private:
|
|||
void DrawWaiting () const;
|
||||
void SetDrawSize(int reltop, int hres, int vres);
|
||||
|
||||
TObjPtr<DHUDMessage*> Messages[NUM_HUDMSGLAYERS];
|
||||
TObjPtr<DHUDMessageBase*> Messages[NUM_HUDMSGLAYERS];
|
||||
|
||||
int BaseRelTop;
|
||||
int BaseSBarHorizontalResolution;
|
||||
|
|
|
@ -410,10 +410,10 @@ void DBaseStatusBar::OnDestroy ()
|
|||
{
|
||||
for (size_t i = 0; i < countof(Messages); ++i)
|
||||
{
|
||||
DHUDMessage *msg = Messages[i];
|
||||
DHUDMessageBase *msg = Messages[i];
|
||||
while (msg)
|
||||
{
|
||||
DHUDMessage *next = msg->Next;
|
||||
DHUDMessageBase *next = msg->Next;
|
||||
msg->Destroy();
|
||||
msg = next;
|
||||
}
|
||||
|
@ -594,12 +594,12 @@ void DBaseStatusBar::Tick ()
|
|||
{
|
||||
for (size_t i = 0; i < countof(Messages); ++i)
|
||||
{
|
||||
DHUDMessage *msg = Messages[i];
|
||||
DHUDMessage **prev = &Messages[i];
|
||||
DHUDMessageBase *msg = Messages[i];
|
||||
DHUDMessageBase **prev = &Messages[i];
|
||||
|
||||
while (msg)
|
||||
{
|
||||
DHUDMessage *next = msg->Next;
|
||||
DHUDMessageBase *next = msg->Next;
|
||||
|
||||
if (msg->Tick ())
|
||||
{
|
||||
|
@ -662,10 +662,10 @@ void DBaseStatusBar::CallTick()
|
|||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void DBaseStatusBar::AttachMessage (DHUDMessage *msg, uint32_t id, int layer)
|
||||
void DBaseStatusBar::AttachMessage (DHUDMessageBase *msg, uint32_t id, int layer)
|
||||
{
|
||||
DHUDMessage *old = NULL;
|
||||
DHUDMessage **prev;
|
||||
DHUDMessageBase *old = NULL;
|
||||
DHUDMessageBase **prev;
|
||||
DObject *container = this;
|
||||
|
||||
old = (id == 0 || id == 0xFFFFFFFF) ? NULL : DetachMessage (id);
|
||||
|
@ -703,12 +703,12 @@ void DBaseStatusBar::AttachMessage (DHUDMessage *msg, uint32_t id, int layer)
|
|||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
DHUDMessage *DBaseStatusBar::DetachMessage (DHUDMessage *msg)
|
||||
DHUDMessageBase *DBaseStatusBar::DetachMessage (DHUDMessageBase *msg)
|
||||
{
|
||||
for (size_t i = 0; i < countof(Messages); ++i)
|
||||
{
|
||||
DHUDMessage *probe = Messages[i];
|
||||
DHUDMessage **prev = &Messages[i];
|
||||
DHUDMessageBase *probe = Messages[i];
|
||||
DHUDMessageBase **prev = &Messages[i];
|
||||
|
||||
while (probe && probe != msg)
|
||||
{
|
||||
|
@ -725,12 +725,12 @@ DHUDMessage *DBaseStatusBar::DetachMessage (DHUDMessage *msg)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
DHUDMessage *DBaseStatusBar::DetachMessage (uint32_t id)
|
||||
DHUDMessageBase *DBaseStatusBar::DetachMessage (uint32_t id)
|
||||
{
|
||||
for (size_t i = 0; i < countof(Messages); ++i)
|
||||
{
|
||||
DHUDMessage *probe = Messages[i];
|
||||
DHUDMessage **prev = &Messages[i];
|
||||
DHUDMessageBase *probe = Messages[i];
|
||||
DHUDMessageBase **prev = &Messages[i];
|
||||
|
||||
while (probe && probe->SBarID != id)
|
||||
{
|
||||
|
@ -757,12 +757,12 @@ void DBaseStatusBar::DetachAllMessages ()
|
|||
{
|
||||
for (size_t i = 0; i < countof(Messages); ++i)
|
||||
{
|
||||
DHUDMessage *probe = Messages[i];
|
||||
DHUDMessageBase *probe = Messages[i];
|
||||
|
||||
Messages[i] = NULL;
|
||||
while (probe != NULL)
|
||||
{
|
||||
DHUDMessage *next = probe->Next;
|
||||
DHUDMessageBase *next = probe->Next;
|
||||
probe->Destroy();
|
||||
probe = next;
|
||||
}
|
||||
|
@ -940,7 +940,7 @@ void DBaseStatusBar::FlashCrosshair ()
|
|||
|
||||
void DBaseStatusBar::DrawMessages (int layer, int bottom)
|
||||
{
|
||||
DHUDMessage *msg = Messages[layer];
|
||||
DHUDMessageBase *msg = Messages[layer];
|
||||
int visibility = 0;
|
||||
|
||||
if (viewactive)
|
||||
|
@ -953,7 +953,7 @@ void DBaseStatusBar::DrawMessages (int layer, int bottom)
|
|||
}
|
||||
while (msg)
|
||||
{
|
||||
DHUDMessage *next = msg->Next;
|
||||
DHUDMessageBase *next = msg->Next;
|
||||
msg->Draw (bottom, visibility);
|
||||
msg = next;
|
||||
}
|
||||
|
@ -1307,7 +1307,7 @@ void DBaseStatusBar::ScreenSizeChanged ()
|
|||
|
||||
for (size_t i = 0; i < countof(Messages); ++i)
|
||||
{
|
||||
DHUDMessage *message = Messages[i];
|
||||
DHUDMessageBase *message = Messages[i];
|
||||
while (message != NULL)
|
||||
{
|
||||
message->ScreenSizeChanged ();
|
||||
|
|
Loading…
Reference in a new issue