]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/timer.qc
Purge autocvars.qh from the client-side codebase, cvars are defined in the headers...
[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 void HUD_Timer()
14 {
15         if(!autocvar__hud_configure)
16         {
17                 if(!autocvar_hud_panel_timer) return;
18         }
19
20         HUD_Panel_LoadCvars();
21
22         draw_beginBoldFont();
23
24         vector pos, mySize;
25         pos = panel_pos;
26         mySize = panel_size;
27
28         if (autocvar_hud_panel_timer_dynamichud)
29                 HUD_Scale_Enable();
30         else
31                 HUD_Scale_Disable();
32         HUD_Panel_DrawBg();
33         if(panel_bg_padding)
34         {
35                 pos += '1 1 0' * panel_bg_padding;
36                 mySize -= '2 2 0' * panel_bg_padding;
37         }
38
39         string timer;
40         float timelimit, timeleft, minutesLeft;
41
42         timelimit = STAT(TIMELIMIT);
43
44         timeleft = max(0, timelimit * 60 + STAT(GAMESTARTTIME) - time);
45         timeleft = ceil(timeleft);
46
47         minutesLeft = floor(timeleft / 60);
48
49         float warmup_timeleft = 0;
50         if(warmup_stage)
51         {
52                 float warmup_timelimit = STAT(WARMUP_TIMELIMIT);
53                 if(warmup_timelimit > 0)
54                         warmup_timeleft = max(0, warmup_timelimit - time);
55                 else if(warmup_timelimit == 0)
56                         warmup_timeleft = timeleft;
57                 warmup_timeleft = ceil(warmup_timeleft);
58         }
59
60         vector timer_color;
61         if(intermission_time || minutesLeft >= 5 || warmup_stage || timelimit == 0)
62                 timer_color = '1 1 1'; //white
63         else if(minutesLeft >= 1)
64                 timer_color = '1 1 0'; //yellow
65         else
66                 timer_color = '1 0 0'; //red
67
68         if (intermission_time) {
69                 timer = seconds_tostring(max(0, floor(intermission_time - STAT(GAMESTARTTIME))));
70         } else if (warmup_stage && warmup_timeleft >= 60) {
71                 timer = _("WARMUP");
72         } else if (autocvar_hud_panel_timer_increment || (!warmup_stage && timelimit == 0) || (warmup_stage && warmup_timeleft <= 0)) {
73                 if (time < STAT(GAMESTARTTIME))
74                         timer = seconds_tostring(0); //while restart is still active, show 00:00
75                 else
76                         timer = seconds_tostring(floor(time - STAT(GAMESTARTTIME)));
77         } else {
78                 if(warmup_stage)
79                         timer = seconds_tostring(warmup_timeleft);
80                 else
81                         timer = seconds_tostring(timeleft);
82         }
83
84         drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
85
86         draw_endBoldFont();
87 }