Merge branch 'Mario/warmup_timer' into 'master'
[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()
10 {
11         if(!autocvar__hud_configure)
12         {
13                 if(!autocvar_hud_panel_timer) return;
14         }
15
16         HUD_Panel_LoadCvars();
17
18         draw_beginBoldFont();
19
20         vector pos, mySize;
21         pos = panel_pos;
22         mySize = panel_size;
23
24         if (autocvar_hud_panel_timer_dynamichud)
25                 HUD_Scale_Enable();
26         else
27                 HUD_Scale_Disable();
28         HUD_Panel_DrawBg();
29         if(panel_bg_padding)
30         {
31                 pos += '1 1 0' * panel_bg_padding;
32                 mySize -= '2 2 0' * panel_bg_padding;
33         }
34
35         string timer;
36         float timelimit, timeleft, minutesLeft;
37
38         timelimit = STAT(TIMELIMIT);
39
40         timeleft = max(0, timelimit * 60 + STAT(GAMESTARTTIME) - time);
41         timeleft = ceil(timeleft);
42
43         minutesLeft = floor(timeleft / 60);
44
45         float warmup_timeleft = 0;
46         if(warmup_stage)
47         {
48                 float warmup_timelimit = STAT(WARMUP_TIMELIMIT);
49                 if(warmup_timelimit > 0)
50                         warmup_timeleft = max(0, warmup_timelimit - time);
51                 else if(warmup_timelimit == 0)
52                         warmup_timeleft = timeleft;
53                 warmup_timeleft = ceil(warmup_timeleft);
54         }
55
56         vector timer_color;
57         if(intermission_time || minutesLeft >= 5 || warmup_stage || timelimit == 0)
58                 timer_color = '1 1 1'; //white
59         else if(minutesLeft >= 1)
60                 timer_color = '1 1 0'; //yellow
61         else
62                 timer_color = '1 0 0'; //red
63
64         if (intermission_time) {
65                 timer = seconds_tostring(max(0, floor(intermission_time - STAT(GAMESTARTTIME))));
66         } else if (warmup_stage && warmup_timeleft >= 60) {
67                 timer = _("WARMUP");
68         } else if (autocvar_hud_panel_timer_increment || (!warmup_stage && timelimit == 0) || (warmup_stage && warmup_timeleft <= 0)) {
69                 if (time < STAT(GAMESTARTTIME))
70                         timer = seconds_tostring(0); //while restart is still active, show 00:00
71                 else
72                         timer = seconds_tostring(floor(time - STAT(GAMESTARTTIME)));
73         } else {
74                 if(warmup_stage)
75                         timer = seconds_tostring(warmup_timeleft);
76                 else
77                         timer = seconds_tostring(timeleft);
78         }
79
80         drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
81
82         draw_endBoldFont();
83 }