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