2 #include "scoreboard.qh"
4 #include <client/draw.qh>
5 #include <client/view.qh>
9 int autocvar_cl_timer_countdown = 3; // 0 = disabled, 1 = always on, 2 = only spec, 3 = as dictated by server
11 void HUD_Timer_Export(int fh)
13 // allow saving cvars that aesthetically change the panel into hud skin files
16 vector HUD_Timer_Color(float timeleft)
19 return '1 0 0'; // red
20 else if(timeleft <= 300)
21 return '1 1 0'; // yellow
23 return '1 1 1'; // white
26 float HUD_Timer_TimeElapsed(float curtime, float starttime)
28 float time_elapsed = curtime - starttime;
29 if (!autocvar_hud_panel_timer_unbound)
30 time_elapsed = max(0, time_elapsed);
31 return floor(time_elapsed);
34 float HUD_Timer_TimeLeft(float curtime, float starttime, float timelimit)
36 float timeleft = timelimit + starttime - curtime;
37 if (!autocvar_hud_panel_timer_unbound)
38 timeleft = bound(0, timeleft, timelimit);
39 return ceil(timeleft);
44 if(!autocvar__hud_configure)
46 if(!autocvar_hud_panel_timer) return;
49 HUD_Panel_LoadCvars();
57 if (autocvar_hud_panel_timer_dynamichud)
63 pos += '1 1 0' * panel_bg_padding;
64 mySize -= '2 2 0' * panel_bg_padding;
67 string timer_str = string_null;
68 string subtimer_str = string_null;
69 string subtext = string_null;
70 float curtime, timelimit, timeleft;
71 vector timer_size, subtext_size, subtimer_size;
72 vector timer_color = '1 1 1';
73 vector subtimer_color = '1 1 1';
74 bool swap = (autocvar_hud_panel_timer_secondary == 2 && STAT(ROUNDSTARTTIME));
75 float timeout_last = STAT(TIMEOUT_LAST);
77 // Use real or frozen time and get the time limit
78 curtime = (intermission_time ? intermission_time : time);
79 timelimit = (warmup_stage ? STAT(WARMUP_TIMELIMIT) : STAT(TIMELIMIT) * 60);
81 // Calculate time left
82 timeleft = HUD_Timer_TimeLeft(curtime, STAT(GAMESTARTTIME), timelimit);
85 if(!intermission_time && !warmup_stage && timelimit > 0)
86 timer_color = HUD_Timer_Color(timeleft);
89 // if 3 use server dictated option, otherwise the client's
91 if(autocvar_cl_timer_countdown == 3)
92 countdown_type = sv_timer_countdown;
94 countdown_type = autocvar_cl_timer_countdown;
96 if(countdown_type && !warmup_stage && timeleft > 0 && timeleft != last_timeleft && timeleft <= 10 && !intermission_time)
98 if(countdown_type == 1 || (countdown_type == 2 && spectatee_status))
99 sound(NULL, CH_INFO, SND_ENDCOUNT, VOL_BASE, ATTN_NONE);
101 last_timeleft = timeleft;
106 timer = (autocvar_hud_panel_timer_increment ? 0 : STAT(TIMELIMIT) * 60);
107 else if (autocvar_hud_panel_timer_increment || timelimit <= 0)
108 timer = HUD_Timer_TimeElapsed(curtime, STAT(GAMESTARTTIME));
112 // Secondary timer for round-based game modes
113 if(STAT(ROUNDSTARTTIME) && autocvar_hud_panel_timer_secondary)
115 if(STAT(ROUNDSTARTTIME) == -1) {
117 subtimer_str = "--:--";
118 subtimer_color = '1 0 0';
120 float round_curtime, round_endtime, round_timelimit, round_timeleft;
122 // Use real or frozen time and get the time limit
123 round_endtime = STAT(ROUNDENDTIME);
124 round_timelimit = STAT(ROUND_TIMELIMIT);
127 round_curtime = round_endtime;
128 else if(timeout_last)
129 round_curtime = timeout_last;
131 round_curtime = time;
133 // Calculate time left
134 round_timeleft = HUD_Timer_TimeLeft(round_curtime, STAT(ROUNDSTARTTIME), round_timelimit);
137 if(!intermission_time && round_timelimit > 0)
138 subtimer_color = HUD_Timer_Color(round_timeleft);
141 if (autocvar_hud_panel_timer_increment || round_timelimit <= 0)
142 subtimer_str = seconds_tostring(HUD_Timer_TimeElapsed(round_curtime, STAT(ROUNDSTARTTIME)));
144 subtimer_str = seconds_tostring(round_timeleft);
149 int overtimes = STAT(OVERTIMES);
151 if(warmup_stage || autocvar__hud_configure)
152 subtext = _("Warmup");
153 else if(STAT(TIMEOUT_STATUS) == 2)
154 subtext = _("Timeout");
155 else if(overtimes >= 2)
156 subtext = sprintf(_("Overtime #%d"), overtimes);
157 else if(overtimes != 0)
158 subtext = _("Overtime");
160 subtext_size = vec2(mySize.x, mySize.y / 3);
161 timer_size = vec2(mySize.x, mySize.y - subtext_size.y);
162 subtimer_size = vec2(mySize.x / 3, mySize.y - subtext_size.y);
163 timer_str = seconds_tostring(timer);
165 panel_size.y -= subtext_size.y;
169 float subtimer_padding = subtimer_size.y / 5;
170 timer_size.x -= subtimer_size.x;
171 drawstring_aspect(pos + eX * timer_size.x + eY * subtimer_padding, (swap ? timer_str : subtimer_str), subtimer_size - eY * subtimer_padding * 2, (swap ? timer_color : subtimer_color), panel_fg_alpha, DRAWFLAG_NORMAL);
174 drawstring_aspect(pos, (swap ? subtimer_str : timer_str), timer_size, (swap ? subtimer_color : timer_color), panel_fg_alpha, DRAWFLAG_NORMAL);
177 drawstring_aspect(pos + eY * timer_size.y, subtext, subtext_size, '0 1 0', panel_fg_alpha, DRAWFLAG_NORMAL);