Skip to content

Commit 26b9311

Browse files
author
newby
committed
Grenade timer visual tweaks
zel pointed out it's nicer to stack timers by expiry time when some is spamm^Whas several active simultaneously. Also, he thought he might have seen 2 opaque timers. This could happen momentarily if prime and throw messages are reordered, but we can actually hide this easily by always rendering stacked timers as transparent.
1 parent c38b1b4 commit 26b9311

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

csqc/csextradefs.qc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,11 +446,13 @@ class CsGrenTimer;
446446
CsGrenTimer grentimers[NUM_GREN_TIMERS];
447447

448448
class CsGrenTimer {
449+
float index_;
449450
float primed_at_;
450451
float expires_at_;
451452
float flags_;
452453
float grentype_;
453454

455+
nonvirtual float() index { return index_; };
454456
nonvirtual float() active { return expires_at_ > time; };
455457
nonvirtual float() expiry { return expires_at_; };
456458
nonvirtual float() grentype { return grentype_; };
@@ -470,7 +472,7 @@ class CsGrenTimer {
470472

471473
static void() Init {
472474
for (float i = 0; i < grentimers.length; i++)
473-
grentimers[i] = spawn(CsGrenTimer);
475+
grentimers[i] = spawn(CsGrenTimer, index_: i);
474476
};
475477

476478
static void() StopAll {

csqc/status.qc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ void(string panelid, float display, string text) drawSpecial = {
9696
};
9797

9898
void(string panelid, float display, string text) drawGrenTimerPanel = {
99-
local float timeleft;
100-
local float timercount = 0;
99+
float timeleft;
100+
float timercount = 0;
101101

102102
if (display) {
103103
FO_Hud_Panel* panel = getAnyHudPanelByNamePointer(panelid);
@@ -110,8 +110,11 @@ void(string panelid, float display, string text) drawGrenTimerPanel = {
110110
panel2.Display = panel.Display;
111111
panel2.FillSize = panel.FillSize;
112112

113-
for (float i = 0; i < grentimers.length; i++) {
114-
local CsGrenTimer gt = grentimers[i];
113+
CsGrenTimer lt = CsGrenTimer::GetLast();
114+
// We want to render in reverse mod order from the last primed grenade
115+
// here, that way we'll properly stack timers relative to expiry.
116+
for (float i = grentimers.length; i > 0; i--) {
117+
CsGrenTimer gt = grentimers[(lt.index() + i) % grentimers.length];
115118

116119
if (!gt.active())
117120
continue;
@@ -125,7 +128,11 @@ void(string panelid, float display, string text) drawGrenTimerPanel = {
125128
panel2.TextScale = TextScale * 0.8;
126129
}
127130

128-
local float alpha = (gt.is_thrown()) ? 0.3 : 1.0;
131+
// It's technically possible to get a primed message before thrown
132+
// if things get reordered, but since we can only ever have one
133+
// grenade primed, we can obscure this by always considering
134+
// grenades after the first as primed.
135+
float alpha = (gt.is_thrown() || timercount) ? 0.3 : 1.0;
129136
Hud_DrawPanelLMP(&panel2, ftos(timeleft),
130137
GrenadeIcons[gt.grentype()].icon, alpha);
131138
panel2.Position = panel2.Position +

0 commit comments

Comments
 (0)