3 #include <client/draw.qh>
4 #include <client/view.qh>
8 int autocvar_cl_timer_countdown = 3; // 0 = disabled, 1 = always on, 2 = only spec, 3 = as dictated by server
10 void HUD_Timer_Export(int fh)
12 // allow saving cvars that aesthetically change the panel into hud skin files
15 vector HUD_Timer_Color(float timeleft)
18 return '1 0 0'; // red
19 else if(timeleft <= 300)
20 return '1 1 0'; // yellow
22 return '1 1 1'; // white
25 float HUD_Timer_TimeElapsed(float curtime, float starttime)
27 float time_elapsed = curtime - starttime;
28 if (!autocvar_hud_panel_timer_unbound)
29 time_elapsed = max(0, time_elapsed);
30 return floor(time_elapsed);
33 float HUD_Timer_TimeLeft(float curtime, float starttime, float timelimit)
35 float timeleft = timelimit + starttime - curtime;
36 if (!autocvar_hud_panel_timer_unbound)
37 timeleft = bound(0, timeleft, timelimit);
38 return ceil(timeleft);
43 if(!autocvar__hud_configure)
45 if(!autocvar_hud_panel_timer) return;
48 HUD_Panel_LoadCvars();
56 if (autocvar_hud_panel_timer_dynamichud)
62 pos += '1 1 0' * panel_bg_padding;
63 mySize -= '2 2 0' * panel_bg_padding;
67 string subtimer = string_null;
68 string subtext = string_null;
69 float curtime, timelimit, timeleft;
70 vector timer_size, subtext_size, subtimer_size;
71 vector timer_color = '1 1 1';
72 vector subtimer_color = '1 1 1';
73 bool swap = (autocvar_hud_panel_timer_secondary == 2 && STAT(ROUNDSTARTTIME));
74 float timeout_last = STAT(TIMEOUT_LAST);
76 // Use real or frozen time and get the time limit
78 curtime = intermission_time;
80 curtime = timeout_last;
86 timelimit = STAT(WARMUP_TIMELIMIT);
88 timelimit = STAT(TIMELIMIT) * 60;
92 timelimit = STAT(TIMELIMIT) * 60;
95 // Calculate time left
96 timeleft = HUD_Timer_TimeLeft(curtime, STAT(GAMESTARTTIME), timelimit);
99 if(!intermission_time && !warmup_stage && timelimit > 0)
100 timer_color = HUD_Timer_Color(timeleft);
103 // if 3 use server dictated option, otherwise the client's
105 if(autocvar_cl_timer_countdown == 3)
106 countdown_type = sv_timer_countdown;
108 countdown_type = autocvar_cl_timer_countdown;
110 if(countdown_type && !warmup_stage && timeleft > 0 && timeleft != last_timeleft && timeleft <= 10 && !intermission_time)
112 if(countdown_type == 1 || (countdown_type == 2 && spectatee_status))
113 sound(NULL, CH_INFO, SND_ENDCOUNT, VOL_BASE, ATTN_NONE);
115 last_timeleft = timeleft;
119 if (warmup_stage && timelimit == -1)
121 // Lock timer in infinite warmup
122 if (autocvar_hud_panel_timer_increment)
123 timer = seconds_tostring(0);
125 timer = seconds_tostring(STAT(TIMELIMIT) * 60);
129 if (autocvar_hud_panel_timer_increment || timelimit <= 0)
130 timer = seconds_tostring(HUD_Timer_TimeElapsed(curtime, STAT(GAMESTARTTIME)));
132 timer = seconds_tostring(timeleft);
135 // Secondary timer for round-based game modes
136 if(STAT(ROUNDSTARTTIME) && autocvar_hud_panel_timer_secondary)
138 if(STAT(ROUNDSTARTTIME) == -1) {
141 subtimer_color = '1 0 0';
143 float round_curtime, round_endtime, round_timelimit, round_timeleft;
145 // Use real or frozen time and get the time limit
146 round_endtime = STAT(ROUNDENDTIME);
147 round_timelimit = STAT(ROUND_TIMELIMIT);
150 round_curtime = round_endtime;
151 else if(timeout_last)
152 round_curtime = timeout_last;
154 round_curtime = time;
156 // Calculate time left
157 round_timeleft = HUD_Timer_TimeLeft(round_curtime, STAT(ROUNDSTARTTIME), round_timelimit);
160 if(!intermission_time && round_timelimit > 0)
161 subtimer_color = HUD_Timer_Color(round_timeleft);
164 if (autocvar_hud_panel_timer_increment || round_timelimit <= 0)
165 subtimer = seconds_tostring(HUD_Timer_TimeElapsed(round_curtime, STAT(ROUNDSTARTTIME)));
167 subtimer = seconds_tostring(round_timeleft);
172 int overtimes = STAT(OVERTIMES);
174 if(warmup_stage || autocvar__hud_configure)
175 subtext = _("Warmup");
176 else if(STAT(TIMEOUT_STATUS) == 2)
177 subtext = _("Timeout");
178 else if(overtimes >= 2)
179 subtext = sprintf(_("Overtime #%d"), overtimes);
180 else if(overtimes != 0)
181 subtext = _("Overtime");
183 subtext_size = vec2(mySize.x, mySize.y / 3);
184 timer_size = vec2(mySize.x, mySize.y - subtext_size.y);
185 subtimer_size = vec2(mySize.x / 3, mySize.y - subtext_size.y);
187 panel_size.y -= subtext_size.y;
191 float subtimer_padding = subtimer_size.y / 5;
192 timer_size.x -= subtimer_size.x;
193 drawstring_aspect(pos + eX * timer_size.x + eY * subtimer_padding, (swap ? timer : subtimer), subtimer_size - eY * subtimer_padding * 2, (swap ? timer_color : subtimer_color), panel_fg_alpha, DRAWFLAG_NORMAL);
196 drawstring_aspect(pos, (swap ? subtimer : timer), timer_size, (swap ? subtimer_color : timer_color), panel_fg_alpha, DRAWFLAG_NORMAL);
199 drawstring_aspect(pos + eY * timer_size.y, subtext, subtext_size, '0 1 0', panel_fg_alpha, DRAWFLAG_NORMAL);