Skip to content

Commit 7203027

Browse files
committed
Move hud priority to an enum
1 parent b8c21b7 commit 7203027

4 files changed

Lines changed: 21 additions & 15 deletions

File tree

src/adminsystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ CON_COMMAND_CHAT_FLAGS(hsay, "<message> - Say something as a hud hint", ADMFLAG_
562562
}
563563

564564
SendHudMessageAll(
565-
10, 99, "<span class='fontSize-l'><span color='#FFFFFF'>ADMIN: </span><span color='#D11313'>%s</span></span>",
565+
10, EHudPriority::AdminHSay, "<span class='fontSize-l'><span color='#FFFFFF'>ADMIN: </span><span color='#D11313'>%s</span></span>",
566566
EscapeHTMLSpecialCharacters(args.ArgS()).c_str());
567567
}
568568

src/utils/hud_manager.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ extern CGlobalVars* GetGlobals();
3434
CConVar<bool> g_cvarFixHudFlashing("cs2f_fix_hud_flashing", FCVAR_NONE, "Whether to fix hud flashing using a workaround, this BREAKS warmup so pick one or the other", false);
3535
static std::vector<std::shared_ptr<CHudMessage>> g_vecHudMessages;
3636

37-
bool ShouldDisplayForPlayer(ZEPlayerHandle hPlayer, int iPriority)
37+
bool ShouldDisplayForPlayer(ZEPlayerHandle hPlayer, EHudPriority ePriority)
3838
{
3939
for (std::shared_ptr<CHudMessage> pHudMessage : g_vecHudMessages)
4040
{
4141
// Require higher priority to block, so if priority matches most recent message takes precedence
42-
if (pHudMessage->HasRecipient(hPlayer) && pHudMessage->GetPriority() > iPriority)
42+
if (pHudMessage->HasRecipient(hPlayer) && pHudMessage->GetPriority() > ePriority)
4343
return false;
4444
}
4545

@@ -88,7 +88,7 @@ void CreateHudMessage(std::shared_ptr<CHudMessage> pHudMessage)
8888
g_gameEventManager->FreeEvent(pEvent);
8989
}
9090

91-
void SendHudMessage(ZEPlayer* pPlayer, int iDuration, int iPriority, const char* pszMessage, ...)
91+
void SendHudMessage(ZEPlayer* pPlayer, int iDuration, EHudPriority ePriority, const char* pszMessage, ...)
9292
{
9393
va_list args;
9494
va_start(args, pszMessage);
@@ -98,13 +98,13 @@ void SendHudMessage(ZEPlayer* pPlayer, int iDuration, int iPriority, const char*
9898

9999
va_end(args);
100100

101-
std::shared_ptr<CHudMessage> pHudMessage = std::make_shared<CHudMessage>(buf, iDuration, iPriority);
101+
std::shared_ptr<CHudMessage> pHudMessage = std::make_shared<CHudMessage>(buf, iDuration, ePriority);
102102

103103
pHudMessage->AddRecipient(pPlayer->GetHandle());
104104
CreateHudMessage(pHudMessage);
105105
}
106106

107-
void SendHudMessageAll(int iDuration, int iPriority, const char* pszMessage, ...)
107+
void SendHudMessageAll(int iDuration, EHudPriority ePriority, const char* pszMessage, ...)
108108
{
109109
if (!GetGlobals())
110110
return;
@@ -117,7 +117,7 @@ void SendHudMessageAll(int iDuration, int iPriority, const char* pszMessage, ...
117117

118118
va_end(args);
119119

120-
std::shared_ptr<CHudMessage> pHudMessage = std::make_shared<CHudMessage>(buf, iDuration, iPriority);
120+
std::shared_ptr<CHudMessage> pHudMessage = std::make_shared<CHudMessage>(buf, iDuration, ePriority);
121121

122122
for (int i = 0; i < GetGlobals()->maxClients; i++)
123123
{

src/utils/hud_manager.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,40 @@
2323
#include <string>
2424
#include <vector>
2525

26+
enum class EHudPriority
27+
{
28+
InfectionCountdown = 2,
29+
AdminHSay = 99
30+
};
31+
2632
class CHudMessage
2733
{
2834
public:
29-
CHudMessage(std::string sMessage, int iDuration, int iPriority)
35+
CHudMessage(std::string sMessage, int iDuration, EHudPriority ePriority)
3036
{
3137
m_strMessage = sMessage;
3238
m_iDuration = iDuration;
33-
m_iPriority = iPriority;
39+
m_ePriority = ePriority;
3440
}
3541

3642
const char* GetMessage() { return m_strMessage.c_str(); };
3743
int GetDuration() { return m_iDuration; };
38-
int GetPriority() { return m_iPriority; };
44+
EHudPriority GetPriority() { return m_ePriority; };
3945
std::vector<ZEPlayerHandle> GetRecipients() { return m_vecRecipients; };
4046
bool HasRecipient(ZEPlayerHandle hPlayer) { return std::find(m_vecRecipients.begin(), m_vecRecipients.end(), hPlayer) != m_vecRecipients.end(); };
4147
void AddRecipient(ZEPlayerHandle hPlayer) { m_vecRecipients.push_back(hPlayer); };
4248

4349
private:
4450
std::string m_strMessage;
4551
int m_iDuration;
46-
int m_iPriority;
52+
EHudPriority m_ePriority;
4753
std::vector<ZEPlayerHandle> m_vecRecipients;
4854
};
4955

5056
// When multiple hud messages are active, whichever one has highest priority one will display
5157
// Note this is a basic implementation (TODO: is this worth expanding?), so e.g. a previously sent lower priority message will not display once a higher priority one expires
52-
void SendHudMessage(ZEPlayer* pPlayer, int iDuration, int iPriority, const char* pszMessage, ...);
53-
void SendHudMessageAll(int iDuration, int iPriority, const char* pszMessage, ...);
58+
void SendHudMessage(ZEPlayer* pPlayer, int iDuration, EHudPriority ePriority, const char* pszMessage, ...);
59+
void SendHudMessageAll(int iDuration, EHudPriority ePriority, const char* pszMessage, ...);
5460

5561
void StartFlashingFixTimer();
5662
std::string EscapeHTMLSpecialCharacters(std::string strMsg);

src/zombiereborn.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,7 @@ void ZR_InitialInfection()
14351435
if (g_cvarRespawnDelay.Get() < 0.0f)
14361436
g_bRespawnEnabled = false;
14371437

1438-
SendHudMessageAll(4, 2, "First infection has started!");
1438+
SendHudMessageAll(4, EHudPriority::InfectionCountdown, "First infection has started!");
14391439
ClientPrintAll(HUD_PRINTTALK, ZR_PREFIX "First infection has started! Good luck, survivors!");
14401440
g_ZRRoundState = EZRRoundState::POST_INFECTION;
14411441
}
@@ -1469,7 +1469,7 @@ void ZR_StartInitialCountdown()
14691469
else
14701470
V_snprintf(classicSpawnMsg, sizeof(classicSpawnMsg), "");
14711471

1472-
SendHudMessageAll(2, 2, "%sFirst infection in <span color='#00FF00'>%i %s</span>!", classicSpawnMsg, g_iInfectionCountDown, g_iInfectionCountDown == 1 ? "second" : "seconds");
1472+
SendHudMessageAll(2, EHudPriority::InfectionCountdown, "%sFirst infection in <span color='#00FF00'>%i %s</span>!", classicSpawnMsg, g_iInfectionCountDown, g_iInfectionCountDown == 1 ? "second" : "seconds");
14731473

14741474
if (g_iInfectionCountDown % 5 == 0)
14751475
ClientPrintAll(HUD_PRINTTALK, "%sFirst infection in \7%i %s\1!", ZR_PREFIX, g_iInfectionCountDown, g_iInfectionCountDown == 1 ? "second" : "seconds");

0 commit comments

Comments
 (0)