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 1 1'; //white
17 else if(timeleft >= 60)
18 return '1 1 0'; //yellow
25 if(!autocvar__hud_configure)
27 if(!autocvar_hud_panel_timer) return;
30 HUD_Panel_LoadCvars();
38 if (autocvar_hud_panel_timer_dynamichud)
44 pos += '1 1 0' * panel_bg_padding;
45 mySize -= '2 2 0' * panel_bg_padding;
49 string subtimer = string_null;
50 string subtext = string_null;
51 float timelimit, timeleft, round_timelimit, round_timeleft;
53 vector timer_size, subtext_size, subtimer_size;
54 vector timer_color = '1 1 1';
55 vector subtimer_color = '1 1 1';
56 bool swap = (autocvar_hud_panel_timer_secondary == 2 && STAT(ROUNDSTARTTIME));
58 // Calculate timelimit
61 timelimit = STAT(WARMUP_TIMELIMIT);
63 timelimit = STAT(TIMELIMIT) * 60;
67 timelimit = STAT(TIMELIMIT) * 60;
70 // Calculate time left
71 timeleft = timelimit + STAT(GAMESTARTTIME) - time;
72 if (!autocvar_hud_panel_timer_unbound)
73 timeleft = bound(0, timeleft, timelimit);
74 timeleft = ceil(timeleft);
77 if(!intermission_time && !warmup_stage && timelimit > 0)
78 timer_color = HUD_Timer_Color(timeleft);
81 if (intermission_time) {
82 timer = seconds_tostring(max(0, floor(intermission_time - STAT(GAMESTARTTIME))));
83 } else if (autocvar_hud_panel_timer_increment || timelimit <= 0) {
84 float time_elapsed = floor(time - STAT(GAMESTARTTIME));
85 if (!autocvar_hud_panel_timer_unbound)
86 time_elapsed = max(0, time_elapsed);
88 timer = seconds_tostring(time_elapsed);
90 timer = seconds_tostring(timeleft);
93 // Round-based game modes
94 if(STAT(ROUNDSTARTTIME) && autocvar_hud_panel_timer_secondary)
96 round_timelimit = STAT(ROUND_TIMELIMIT);
98 // Calculate round time left
99 round_timeleft = round_timelimit + STAT(ROUNDSTARTTIME) - (game_stopped_time ? game_stopped_time : time);
100 if (!autocvar_hud_panel_timer_unbound)
101 round_timeleft = bound(0, round_timeleft, round_timelimit);
102 round_timeleft = ceil(round_timeleft);
105 if(!intermission_time && round_timelimit > 0)
106 subtimer_color = HUD_Timer_Color(round_timeleft);
109 if (intermission_time) {
110 subtimer = seconds_tostring(max(0, floor(intermission_time - STAT(ROUNDSTARTTIME))));
111 } else if (autocvar_hud_panel_timer_increment || round_timelimit <= 0) {
112 float round_time_elapsed = floor((game_stopped_time ? game_stopped_time : time) - STAT(ROUNDSTARTTIME));
113 if (!autocvar_hud_panel_timer_unbound)
114 round_time_elapsed = max(0, round_time_elapsed);
116 subtimer = seconds_tostring(round_time_elapsed);
118 subtimer = seconds_tostring(round_timeleft);
123 overtimes = STAT(OVERTIMESADDED);
125 if(warmup_stage || autocvar__hud_configure)
126 subtext = _("Warmup");
127 else if(intermission_time)
128 subtext = _("Intermission");
129 else if(STAT(TIMEOUT_STATUS))
130 subtext = _("Timeout");
131 else if (overtimes >= 2)
132 subtext = sprintf(_("Overtime #%d"), overtimes);
134 subtext = _("Overtime");
136 subtext_size = vec2(mySize.x, mySize.y / 3);
137 timer_size = vec2(mySize.x, mySize.y - subtext_size.y);
138 subtimer_size = vec2(mySize.x / 3, mySize.y - subtext_size.y);
140 panel_size.y -= subtext_size.y;
144 timer_size.x -= subtimer_size.x;
145 drawstring_aspect(pos + eX * timer_size.x, (swap ? timer : subtimer), subtimer_size, (swap ? timer_color : subtimer_color), panel_fg_alpha, DRAWFLAG_NORMAL);
148 drawstring_aspect(pos, (swap ? subtimer : timer), timer_size, (swap ? subtimer_color : timer_color), panel_fg_alpha, DRAWFLAG_NORMAL);
151 drawstring_aspect(pos + eY * timer_size.y, subtext, subtext_size, '0 1 0', panel_fg_alpha, DRAWFLAG_NORMAL);