]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/timer.qc
Header police
[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         HUD_Panel_DrawBg(1);
18         if(panel_bg_padding)
19         {
20                 pos += '1 1 0' * panel_bg_padding;
21                 mySize -= '2 2 0' * panel_bg_padding;
22         }
23
24         string timer;
25         float timelimit, elapsedTime, timeleft, minutesLeft;
26
27         timelimit = STAT(TIMELIMIT);
28
29         timeleft = max(0, timelimit * 60 + STAT(GAMESTARTTIME) - time);
30         timeleft = ceil(timeleft);
31
32         minutesLeft = floor(timeleft / 60);
33
34         vector timer_color;
35         if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
36                 timer_color = '1 1 1'; //white
37         else if(minutesLeft >= 1)
38                 timer_color = '1 1 0'; //yellow
39         else
40                 timer_color = '1 0 0'; //red
41
42         if (autocvar_hud_panel_timer_increment || timelimit == 0 || warmup_stage) {
43                 if (time < STAT(GAMESTARTTIME)) {
44                         //while restart is still active, show 00:00
45                         timer = seconds_tostring(0);
46                 } else {
47                         elapsedTime = floor(time - STAT(GAMESTARTTIME)); //127
48                         timer = seconds_tostring(elapsedTime);
49                 }
50         } else {
51                 timer = seconds_tostring(timeleft);
52         }
53
54         drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
55
56         draw_endBoldFont();
57 }