]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/timer.qc
1b4dc20707704691c510f0b39ace7c8e7d9d6379
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / timer.qc
1 #include "timer.qh"
2
3 #include <client/draw.qh>
4 #include <client/view.qh>
5
6 // Timer (#5)
7
8 void HUD_Timer_Export(int fh)
9 {
10         // allow saving cvars that aesthetically change the panel into hud skin files
11 }
12
13 vector HUD_Timer_Color(float timeleft)
14 {
15         if(timeleft >= 300)
16                 return '1 1 1'; //white
17         else if(timeleft >= 60)
18                 return '1 1 0'; //yellow
19         else
20                 return '1 0 0'; //red
21 }
22
23 void HUD_Timer()
24 {
25         if(!autocvar__hud_configure)
26         {
27                 if(!autocvar_hud_panel_timer) return;
28         }
29
30         HUD_Panel_LoadCvars();
31
32         draw_beginBoldFont();
33
34         vector pos, mySize;
35         pos = panel_pos;
36         mySize = panel_size;
37
38         if (autocvar_hud_panel_timer_dynamichud)
39                 HUD_Scale_Enable();
40         else
41                 HUD_Scale_Disable();
42         if(panel_bg_padding)
43         {
44                 pos += '1 1 0' * panel_bg_padding;
45                 mySize -= '2 2 0' * panel_bg_padding;
46         }
47
48         string timer;
49         string subtimer = string_null;
50         string subtext = string_null;
51         float timelimit, timeleft, round_timelimit, round_timeleft;
52         int overtimes;
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);
57
58         // Calculate timelimit
59         if(warmup_stage)
60         {
61                 timelimit = STAT(WARMUP_TIMELIMIT);
62                 if(timelimit == 0)
63                         timelimit = STAT(TIMELIMIT) * 60;
64         }
65         else
66         {
67                 timelimit = STAT(TIMELIMIT) * 60;
68         }
69
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);
75
76         // Timer color
77         if(!intermission_time && !warmup_stage && timelimit > 0)
78                 timer_color = HUD_Timer_Color(timeleft);
79
80         // Timer text
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);
87
88                 timer = seconds_tostring(time_elapsed);
89         } else {
90                 timer = seconds_tostring(timeleft);
91         }
92         
93         // Round-based game modes
94         if(STAT(ROUNDSTARTTIME) && autocvar_hud_panel_timer_secondary)
95         {
96                 round_timelimit = STAT(ROUND_TIMELIMIT);
97
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);
103
104                 // Subtimer color
105                 if(!intermission_time && round_timelimit > 0)
106                         subtimer_color = HUD_Timer_Color(round_timeleft);
107
108                 // Subtimer text
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);
115
116                         subtimer = seconds_tostring(round_time_elapsed);
117                 } else {
118                         subtimer = seconds_tostring(round_timeleft);
119                 }
120         }
121
122         // Subtext
123         overtimes = STAT(OVERTIMESADDED);
124
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);
133         else if(overtimes)
134                 subtext = _("Overtime");
135
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);
139         
140         panel_size.y -= subtext_size.y;
141         HUD_Panel_DrawBg();
142         
143         if(subtimer) {
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);
146         }
147         
148         drawstring_aspect(pos, (swap ? subtimer : timer), timer_size, (swap ? subtimer_color : timer_color), panel_fg_alpha, DRAWFLAG_NORMAL);
149         
150         if(subtext)
151                 drawstring_aspect(pos + eY * timer_size.y, subtext, subtext_size, '0 1 0', panel_fg_alpha, DRAWFLAG_NORMAL);
152
153         draw_endBoldFont();
154 }