ReGameDLL_CS/regamedll/dlls/hintmessage.cpp

61 lines
1.3 KiB
C++
Raw Normal View History

#include "precompiled.h"
CHintMessage::CHintMessage(const char *hintString, bool isHint, CUtlVector<const char *> *args, float duration)
{
2015-06-30 12:46:07 +03:00
m_hintString = hintString;
m_duration = duration;
m_isHint = isHint;
if (args)
{
2017-10-12 17:50:56 +03:00
for (int i = 0; i < args->Count(); i++)
2015-06-30 12:46:07 +03:00
m_args.AddToTail(CloneString((*args)[i]));
}
}
CHintMessage::~CHintMessage()
{
2017-10-12 17:50:56 +03:00
for (int i = 0; i < m_args.Count(); i++)
delete[] m_args[i];
2015-06-30 12:46:07 +03:00
m_args.RemoveAll();
}
void CHintMessage::Send(CBaseEntity *client)
{
UTIL_ShowMessageArgs(m_hintString, client, &m_args, m_isHint);
}
void CHintMessageQueue::Reset()
{
2015-06-30 12:46:07 +03:00
m_tmMessageEnd = 0;
2017-10-12 17:50:56 +03:00
for (int i = 0; i < m_messages.Count(); i++)
2015-06-30 12:46:07 +03:00
delete m_messages[i];
m_messages.RemoveAll();
}
void CHintMessageQueue::Update(CBaseEntity *client)
{
2015-06-30 12:46:07 +03:00
if (gpGlobals->time <= m_tmMessageEnd)
return;
if (!m_messages.Count())
return;
CHintMessage *msg = m_messages[0];
m_tmMessageEnd = gpGlobals->time + msg->GetDuration();
msg->Send(client);
delete msg;
m_messages.Remove(0);
}
bool CHintMessageQueue::AddMessage(const char *message, float duration, bool isHint, CUtlVector<const char *> *args)
{
2015-06-30 12:46:07 +03:00
CHintMessage *msg = new CHintMessage(message, isHint, args, duration);
m_messages.AddToTail(msg);
return true;
}