]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/timer.qc
Implement secondary timer and subtext
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / timer.qc
1 #include "timer.qh"
2
3 #include <client/draw.qh>
4 #include <client/view.qh>
5
6 // Timer (#5)
7
8 void HUD_Timer_Export(int fh)
9 {
10         // allow saving cvars that aesthetically change the panel into hud skin files
11 }
12
13 void HUD_Timer()
14 {
15         if(!autocvar__hud_configure)
16         {
17                 if(!autocvar_hud_panel_timer) return;
18         }
19
20         HUD_Panel_LoadCvars();
21
22         draw_beginBoldFont();
23
24         vector pos, mySize;
25         pos = panel_pos;
26         mySize = panel_size;
27
28         if (autocvar_hud_panel_timer_dynamichud)
29                 HUD_Scale_Enable();
30         else
31                 HUD_Scale_Disable();
32         if(panel_bg_padding)
33         {
34                 pos += '1 1 0' * panel_bg_padding;
35                 mySize -= '2 2 0' * panel_bg_padding;
36         }
37
38         string timer, subtimer, subtext;
39         float timelimit, timeleft, minutesLeft, overtimes;
40         float round_timelimit, round_timeleft;
41
42         // Calculate timelimit
43         if(warmup_stage)
44         {
45                 timelimit = STAT(WARMUP_TIMELIMIT);
46                 if(timelimit == 0)
47                         timelimit = STAT(TIMELIMIT) * 60;
48                 else if(timelimit == -1)
49                         timelimit = 0;
50         }
51         else
52         {
53                 timelimit = STAT(TIMELIMIT) * 60;
54         }
55         
56         // Calculate time left
57         timeleft = bound(0, timelimit + STAT(GAMESTARTTIME) - time, timelimit);
58         timeleft = ceil(timeleft);
59
60         minutesLeft = floor(timeleft / 60);
61
62         // Timer color
63         vector timer_color;
64         if(intermission_time || minutesLeft >= 5 || warmup_stage || timelimit == 0)
65                 timer_color = '1 1 1'; //white
66         else if(minutesLeft >= 1)
67                 timer_color = '1 1 0'; //yellow
68         else
69                 timer_color = '1 0 0'; //red
70
71         // Timer text
72         if (intermission_time) {
73                 timer = seconds_tostring(max(0, floor(intermission_time - STAT(GAMESTARTTIME))));
74         } else if (autocvar_hud_panel_timer_increment || timelimit == 0) {
75                 float time_elapsed = floor(time - STAT(GAMESTARTTIME));
76                 timer = seconds_tostring(max(0, time_elapsed));
77         } else {
78                 timer = seconds_tostring(timeleft);
79         }
80         
81         // Subtimer text
82         if(STAT(ROUNDSTARTTIME))
83         {
84                 round_timelimit = STAT(ROUND_TIMELIMIT);
85                 
86                 if (autocvar_hud_panel_timer_increment || round_timelimit <= 0) {
87                         float round_time_elapsed = floor(time - STAT(ROUNDSTARTTIME));
88                         subtimer = seconds_tostring(max(0, round_time_elapsed));
89                 } else {
90                         round_timeleft = bound(0, round_timelimit + STAT(ROUNDSTARTTIME) - time, round_timelimit);
91                         round_timeleft = ceil(round_timeleft);
92                         
93                         subtimer = seconds_tostring(round_timeleft);
94                 }
95         }
96         else
97                 subtimer = string_null;
98
99         // Subtext
100         overtimes = STAT(OVERTIMESADDED);
101         
102         if(warmup_stage)
103                 subtext = "Warmup";
104         else if(overtimes == 1)
105                 subtext = "Overtime";
106         else if (overtimes > 1)
107                 subtext = sprintf("Overtime #%d", overtimes);
108         else
109                 subtext = string_null;
110
111         vector timer_size, subtext_size, subtimer_size;
112         
113         subtext_size  = vec2(mySize.x, mySize.y / 3);
114         timer_size    = vec2(mySize.x, mySize.y - subtext_size.y);
115         subtimer_size = vec2(mySize.x / 3, mySize.y - subtext_size.y);
116         
117         panel_size.y -= subtext_size.y;
118         HUD_Panel_DrawBg();
119         
120         if(subtimer) {
121                 timer_size.x -= subtimer_size.x;
122                 drawstring_aspect(pos + eX * timer_size.x, subtimer, subtimer_size, '1 1 0', panel_fg_alpha, DRAWFLAG_NORMAL);
123         }
124         
125         drawstring_aspect(pos, timer, timer_size, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
126         
127         if(subtext)
128                 drawstring_aspect(pos + eY * timer_size.y, subtext, subtext_size, '1 0 0', panel_fg_alpha, DRAWFLAG_NORMAL);
129
130         draw_endBoldFont();
131 }