3 #include <client/draw.qh>
4 #include <client/view.qh>
8 void HUD_Timer_Export(int fh)
10 // allow saving cvars that aesthetically change the panel into hud skin files
13 vector HUD_Timer_Color(float timeleft)
16 return '1 0 0'; // red
17 else if(timeleft <= 300)
18 return '1 1 0'; // yellow
20 return '1 1 1'; // white
23 float HUD_Timer_TimeElapsed(float curtime, float starttime)
25 float time_elapsed = curtime - starttime;
26 if (!autocvar_hud_panel_timer_unbound)
27 time_elapsed = max(0, time_elapsed);
28 return floor(time_elapsed);
31 float HUD_Timer_TimeLeft(float curtime, float starttime, float timelimit)
33 float timeleft = timelimit + starttime - curtime;
34 if (!autocvar_hud_panel_timer_unbound)
35 timeleft = bound(0, timeleft, timelimit);
36 return ceil(timeleft);
41 if(!autocvar__hud_configure)
43 if(!autocvar_hud_panel_timer) return;
46 HUD_Panel_LoadCvars();
54 if (autocvar_hud_panel_timer_dynamichud)
60 pos += '1 1 0' * panel_bg_padding;
61 mySize -= '2 2 0' * panel_bg_padding;
65 string subtimer = string_null;
66 string subtext = string_null;
67 float curtime, timelimit, timeleft;
68 vector timer_size, subtext_size, subtimer_size;
69 vector timer_color = '1 1 1';
70 vector subtimer_color = '1 1 1';
71 bool swap = (autocvar_hud_panel_timer_secondary == 2 && STAT(ROUNDSTARTTIME));
73 // Use real or frozen time and get the time limit
74 curtime = (intermission_time ? intermission_time : time);
77 timelimit = STAT(WARMUP_TIMELIMIT);
79 timelimit = STAT(TIMELIMIT) * 60;
83 timelimit = STAT(TIMELIMIT) * 60;
86 // Calculate time left
87 timeleft = HUD_Timer_TimeLeft(curtime, STAT(GAMESTARTTIME), timelimit);
90 if(!intermission_time && !warmup_stage && timelimit > 0)
91 timer_color = HUD_Timer_Color(timeleft);
94 if (autocvar_hud_panel_timer_increment || timelimit <= 0)
95 timer = seconds_tostring(HUD_Timer_TimeElapsed(curtime, STAT(GAMESTARTTIME)));
97 timer = seconds_tostring(timeleft);
99 // Secondary timer for round-based game modes
100 if(STAT(ROUNDSTARTTIME) && autocvar_hud_panel_timer_secondary)
102 if(STAT(ROUNDSTARTTIME) == -1) {
105 subtimer_color = '1 0 0';
107 float round_curtime, round_timelimit, round_timeleft;
109 // Use real or frozen time and get the time limit
110 round_curtime = (game_stopped_time ? game_stopped_time : time);
111 round_timelimit = STAT(ROUND_TIMELIMIT);
113 // Calculate time left
114 round_timeleft = HUD_Timer_TimeLeft(round_curtime, STAT(ROUNDSTARTTIME), round_timelimit);
117 if(!intermission_time && round_timelimit > 0)
118 subtimer_color = HUD_Timer_Color(round_timeleft);
121 if (autocvar_hud_panel_timer_increment || round_timelimit <= 0)
122 subtimer = seconds_tostring(HUD_Timer_TimeElapsed(round_curtime, STAT(ROUNDSTARTTIME)));
124 subtimer = seconds_tostring(round_timeleft);
129 int overtimes = STAT(OVERTIMES);
131 if(warmup_stage || autocvar__hud_configure)
132 subtext = _("Warmup");
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);