]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/timer.qc
HUD: allow panels to define in their own files their own saved cvars
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / timer.qc
1 #include "timer.qh"
2
3 #include <client/autocvars.qh>
4 #include <client/defs.qh>
5 #include <client/miscfunctions.qh>
6
7 // Timer (#5)
8
9 void HUD_Timer_Export(entity panel, int fh)
10 {
11         // allow saving cvars that aesthetically change the panel into hud skin files
12 }
13
14 void HUD_Timer()
15 {
16         if(!autocvar__hud_configure)
17         {
18                 if(!autocvar_hud_panel_timer) return;
19         }
20
21         HUD_Panel_LoadCvars();
22
23         draw_beginBoldFont();
24
25         vector pos, mySize;
26         pos = panel_pos;
27         mySize = panel_size;
28
29         if (autocvar_hud_panel_timer_dynamichud)
30                 HUD_Scale_Enable();
31         else
32                 HUD_Scale_Disable();
33         HUD_Panel_DrawBg();
34         if(panel_bg_padding)
35         {
36                 pos += '1 1 0' * panel_bg_padding;
37                 mySize -= '2 2 0' * panel_bg_padding;
38         }
39
40         string timer;
41         float timelimit, timeleft, minutesLeft;
42
43         timelimit = STAT(TIMELIMIT);
44
45         timeleft = max(0, timelimit * 60 + STAT(GAMESTARTTIME) - time);
46         timeleft = ceil(timeleft);
47
48         minutesLeft = floor(timeleft / 60);
49
50         float warmup_timeleft = 0;
51         if(warmup_stage)
52         {
53                 float warmup_timelimit = STAT(WARMUP_TIMELIMIT);
54                 if(warmup_timelimit > 0)
55                         warmup_timeleft = max(0, warmup_timelimit - time);
56                 else if(warmup_timelimit == 0)
57                         warmup_timeleft = timeleft;
58                 warmup_timeleft = ceil(warmup_timeleft);
59         }
60
61         vector timer_color;
62         if(intermission_time || minutesLeft >= 5 || warmup_stage || timelimit == 0)
63                 timer_color = '1 1 1'; //white
64         else if(minutesLeft >= 1)
65                 timer_color = '1 1 0'; //yellow
66         else
67                 timer_color = '1 0 0'; //red
68
69         if (intermission_time) {
70                 timer = seconds_tostring(max(0, floor(intermission_time - STAT(GAMESTARTTIME))));
71         } else if (warmup_stage && warmup_timeleft >= 60) {
72                 timer = _("WARMUP");
73         } else if (autocvar_hud_panel_timer_increment || (!warmup_stage && timelimit == 0) || (warmup_stage && warmup_timeleft <= 0)) {
74                 if (time < STAT(GAMESTARTTIME))
75                         timer = seconds_tostring(0); //while restart is still active, show 00:00
76                 else
77                         timer = seconds_tostring(floor(time - STAT(GAMESTARTTIME)));
78         } else {
79                 if(warmup_stage)
80                         timer = seconds_tostring(warmup_timeleft);
81                 else
82                         timer = seconds_tostring(timeleft);
83         }
84
85         drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
86
87         draw_endBoldFont();
88 }