2 #include "scoreboard.qh"
4 #include <client/draw.qh>
5 #include <client/view.qh>
9 void HUD_Timer_Export(int fh)
11 // allow saving cvars that aesthetically change the panel into hud skin files
14 vector HUD_Timer_Color(float timeleft)
17 return '1 0 0'; // red
18 else if(timeleft <= 300)
19 return '1 1 0'; // yellow
21 return '1 1 1'; // white
24 float HUD_Timer_TimeElapsed(float curtime, float starttime)
26 float time_elapsed = curtime - starttime;
27 if (!autocvar_hud_panel_timer_unbound)
28 time_elapsed = max(0, time_elapsed);
29 return floor(time_elapsed);
32 float HUD_Timer_TimeLeft(float curtime, float starttime, float timelimit)
34 float timeleft = timelimit + starttime - curtime;
35 if (!autocvar_hud_panel_timer_unbound)
36 timeleft = bound(0, timeleft, timelimit);
37 return ceil(timeleft);
42 if(!autocvar__hud_configure)
44 if(!autocvar_hud_panel_timer) return;
47 HUD_Panel_LoadCvars();
55 if (autocvar_hud_panel_timer_dynamichud)
61 pos += '1 1 0' * panel_bg_padding;
62 mySize -= '2 2 0' * panel_bg_padding;
66 string subtimer = string_null;
67 string subtext = string_null;
68 float curtime, timelimit, timeleft;
69 vector timer_size, subtext_size, subtimer_size;
70 vector timer_color = '1 1 1';
71 vector subtimer_color = '1 1 1';
72 bool swap = (autocvar_hud_panel_timer_secondary == 2 && STAT(ROUNDSTARTTIME));
74 // Use real or frozen time and get the time limit
75 curtime = (intermission_time ? intermission_time : time);
77 timelimit = STAT(WARMUP_TIMELIMIT);
79 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 (autocvar_hud_panel_timer_increment || timelimit <= 0)
90 timer = seconds_tostring(HUD_Timer_TimeElapsed(curtime, STAT(GAMESTARTTIME)));
92 timer = seconds_tostring(timeleft);
94 // Secondary timer for round-based game modes
95 if(STAT(ROUNDSTARTTIME) && autocvar_hud_panel_timer_secondary)
97 if(STAT(ROUNDSTARTTIME) == -1) {
100 subtimer_color = '1 0 0';
102 float round_curtime, round_timelimit, round_timeleft;
104 // Use real or frozen time and get the time limit
105 round_curtime = (game_stopped_time ? game_stopped_time : time);
106 round_timelimit = STAT(ROUND_TIMELIMIT);
108 // Calculate time left
109 round_timeleft = HUD_Timer_TimeLeft(round_curtime, STAT(ROUNDSTARTTIME), round_timelimit);
112 if(!intermission_time && round_timelimit > 0)
113 subtimer_color = HUD_Timer_Color(round_timeleft);
116 if (autocvar_hud_panel_timer_increment || round_timelimit <= 0)
117 subtimer = seconds_tostring(HUD_Timer_TimeElapsed(round_curtime, STAT(ROUNDSTARTTIME)));
119 subtimer = seconds_tostring(round_timeleft);
124 int overtimes = STAT(OVERTIMES);
126 if(warmup_stage || autocvar__hud_configure)
128 if (STAT(WARMUP_TIMELIMIT) > 0)
129 subtext = _("Warmup");
131 subtext = srv_minplayers ? _("Warmup: too few players") : _("Warmup: no time limit");
133 else if(STAT(TIMEOUT_STATUS) == 2)
134 subtext = _("Timeout");
135 else if (overtimes == -1)
136 subtext = _("Sudden Death");
137 else if(overtimes == 1)
138 subtext = _("Overtime");
139 else if (overtimes >= 2)
140 subtext = sprintf(_("Overtime #%d"), overtimes);
142 subtext_size = vec2(mySize.x, mySize.y / 3);
143 timer_size = vec2(mySize.x, mySize.y - subtext_size.y);
144 subtimer_size = vec2(mySize.x / 3, mySize.y - subtext_size.y);
146 panel_size.y -= subtext_size.y;
150 float subtimer_padding = subtimer_size.y / 5;
151 timer_size.x -= subtimer_size.x;
152 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);
155 drawstring_aspect(pos, (swap ? subtimer : timer), timer_size, (swap ? subtimer_color : timer_color), panel_fg_alpha, DRAWFLAG_NORMAL);
158 drawstring_aspect(pos + eY * timer_size.y, subtext, subtext_size, '0 1 0', panel_fg_alpha, DRAWFLAG_NORMAL);