]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/timer.qc
When the game is over stop timer and show elapsed time
[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(1);
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();
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(gameover_time || minutesLeft >= 5 || warmup_stage || timelimit == 0)
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 (gameover_time) {
58                 timer = seconds_tostring(max(0, floor(gameover_time - STAT(GAMESTARTTIME))));
59         } else if (autocvar_hud_panel_timer_increment || (!warmup_stage && timelimit == 0) || (warmup_stage && warmup_timeleft <= 0)) {
60                 if (time < STAT(GAMESTARTTIME)) {
61                         //while restart is still active, show 00:00
62                         timer = seconds_tostring(0);
63                 } else {
64                         elapsedTime = floor(time - STAT(GAMESTARTTIME));
65                         timer = seconds_tostring(elapsedTime);
66                 }
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 }