Merge branch 'terencehill/spectatee_status_update' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / timer.qc
1 #include "timer.qh"
2 void HUD_Timer()
3 {
4         if(!autocvar__hud_configure)
5         {
6                 if(!autocvar_hud_panel_timer) return;
7         }
8
9         HUD_Panel_UpdateCvars();
10
11         draw_beginBoldFont();
12
13         vector pos, mySize;
14         pos = panel_pos;
15         mySize = panel_size;
16
17         if (autocvar_hud_panel_timer_dynamichud)
18                 HUD_Scale_Enable();
19         else
20                 HUD_Scale_Disable();
21         HUD_Panel_DrawBg(1);
22         if(panel_bg_padding)
23         {
24                 pos += '1 1 0' * panel_bg_padding;
25                 mySize -= '2 2 0' * panel_bg_padding;
26         }
27
28         string timer;
29         float timelimit, elapsedTime, timeleft, minutesLeft;
30
31         timelimit = STAT(TIMELIMIT);
32
33         timeleft = max(0, timelimit * 60 + STAT(GAMESTARTTIME) - time);
34         timeleft = ceil(timeleft);
35
36         minutesLeft = floor(timeleft / 60);
37
38         float warmup_timeleft = 0;
39         if(warmup_stage)
40         {
41                 float warmup_timelimit = STAT(WARMUP_TIMELIMIT);
42                 if(warmup_timelimit > 0)
43                         warmup_timeleft = max(0, warmup_timelimit - time);
44                 else if(warmup_timelimit == 0)
45                         warmup_timeleft = timeleft;
46                 warmup_timeleft = ceil(warmup_timeleft);
47         }
48
49         vector timer_color;
50         if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
51                 timer_color = '1 1 1'; //white
52         else if(minutesLeft >= 1)
53                 timer_color = '1 1 0'; //yellow
54         else
55                 timer_color = '1 0 0'; //red
56
57         if (autocvar_hud_panel_timer_increment || (!warmup_stage && timelimit == 0) || (warmup_stage && warmup_timeleft <= 0)) {
58                 if (time < STAT(GAMESTARTTIME)) {
59                         //while restart is still active, show 00:00
60                         timer = seconds_tostring(0);
61                 } else {
62                         elapsedTime = floor(time - STAT(GAMESTARTTIME));
63                         timer = seconds_tostring(elapsedTime);
64                 }
65         } else {
66                 if(warmup_stage)
67                         timer = seconds_tostring(warmup_timeleft);
68                 else
69                         timer = seconds_tostring(timeleft);
70         }
71
72         drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
73
74         draw_endBoldFont();
75 }