]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/timer.qc
Merge branch 'master' into TimePath/csqc_viewmodels
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / timer.qc
1 void HUD_Timer()
2 {
3         if(!autocvar__hud_configure)
4         {
5                 if(!autocvar_hud_panel_timer) return;
6         }
7
8         HUD_Panel_UpdateCvars();
9
10         draw_beginBoldFont();
11
12         vector pos, mySize;
13         pos = panel_pos;
14         mySize = panel_size;
15
16         HUD_Panel_DrawBg(1);
17         if(panel_bg_padding)
18         {
19                 pos += '1 1 0' * panel_bg_padding;
20                 mySize -= '2 2 0' * panel_bg_padding;
21         }
22
23         string timer;
24         float timelimit, elapsedTime, timeleft, minutesLeft;
25
26         timelimit = STAT(TIMELIMIT);
27
28         timeleft = max(0, timelimit * 60 + STAT(GAMESTARTTIME) - time);
29         timeleft = ceil(timeleft);
30
31         minutesLeft = floor(timeleft / 60);
32
33         vector timer_color;
34         if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
35                 timer_color = '1 1 1'; //white
36         else if(minutesLeft >= 1)
37                 timer_color = '1 1 0'; //yellow
38         else
39                 timer_color = '1 0 0'; //red
40
41         if (autocvar_hud_panel_timer_increment || timelimit == 0 || warmup_stage) {
42                 if (time < STAT(GAMESTARTTIME)) {
43                         //while restart is still active, show 00:00
44                         timer = seconds_tostring(0);
45                 } else {
46                         elapsedTime = floor(time - STAT(GAMESTARTTIME)); //127
47                         timer = seconds_tostring(elapsedTime);
48                 }
49         } else {
50                 timer = seconds_tostring(timeleft);
51         }
52
53         drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
54
55         draw_endBoldFont();
56 }