]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/timer.qc
Merge branch 'master' into z411/new_timer
[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, 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         }
49         else
50         {
51                 timelimit = STAT(TIMELIMIT) * 60;
52         }
53
54         // Calculate time left
55         timeleft = timelimit + STAT(GAMESTARTTIME) - time;
56         if (!autocvar_hud_panel_timer_unbound)
57                 timeleft = bound(0, timeleft, timelimit);
58         timeleft = ceil(timeleft);
59
60         // Timer color
61         vector timer_color;
62         if(intermission_time || timeleft >= 300 || warmup_stage || timelimit <= 0)
63                 timer_color = '1 1 1'; //white
64         else if(timeleft >= 60)
65                 timer_color = '1 1 0'; //yellow
66         else
67                 timer_color = '1 0 0'; //red
68
69         // Timer text
70         if (intermission_time) {
71                 timer = seconds_tostring(max(0, floor(intermission_time - STAT(GAMESTARTTIME))));
72         } else if (autocvar_hud_panel_timer_increment || timelimit <= 0) {
73                 float time_elapsed = floor(time - STAT(GAMESTARTTIME));
74                 if (!autocvar_hud_panel_timer_unbound)
75                         time_elapsed = max(0, time_elapsed);
76
77                 timer = seconds_tostring(time_elapsed);
78         } else {
79                 timer = seconds_tostring(timeleft);
80         }
81         
82         // Subtimer text
83         if(STAT(ROUNDSTARTTIME))
84         {
85                 round_timelimit = STAT(ROUND_TIMELIMIT);
86                 
87                 if (autocvar_hud_panel_timer_increment || round_timelimit <= 0) {
88                         float round_time_elapsed = floor(time - STAT(ROUNDSTARTTIME));
89                         if (!autocvar_hud_panel_timer_unbound)
90                                 round_time_elapsed = max(0, round_time_elapsed);
91
92                         subtimer = seconds_tostring(round_time_elapsed);
93                 } else {
94                         round_timeleft = round_timelimit + STAT(ROUNDSTARTTIME) - time;
95                         if (!autocvar_hud_panel_timer_unbound)
96                                 round_timeleft = bound(0, round_timeleft, round_timelimit);
97                         round_timeleft = ceil(round_timeleft);
98                         
99                         subtimer = seconds_tostring(round_timeleft);
100                 }
101         }
102         else
103                 subtimer = string_null;
104
105         // Subtext
106         overtimes = STAT(OVERTIMESADDED);
107
108         if(warmup_stage || autocvar__hud_configure)
109                 subtext = _("Warmup");
110         else if(intermission_time)
111                 subtext = _("Intermission");
112         else if(STAT(TIMEOUT_STATUS))
113                 subtext = _("Timeout");
114         else if (overtimes >= 2)
115                 subtext = sprintf(_("Overtime #%d"), overtimes);
116         else if(overtimes)
117                 subtext = _("Overtime");
118         else
119                 subtext = string_null;
120
121         vector timer_size, subtext_size, subtimer_size;
122         
123         subtext_size  = vec2(mySize.x, mySize.y / 3);
124         timer_size    = vec2(mySize.x, mySize.y - subtext_size.y);
125         subtimer_size = vec2(mySize.x / 3, mySize.y - subtext_size.y);
126         
127         panel_size.y -= subtext_size.y;
128         HUD_Panel_DrawBg();
129         
130         if(subtimer) {
131                 timer_size.x -= subtimer_size.x;
132                 drawstring_aspect(pos + eX * timer_size.x, subtimer, subtimer_size, '1 1 0', panel_fg_alpha, DRAWFLAG_NORMAL);
133         }
134         
135         drawstring_aspect(pos, timer, timer_size, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
136         
137         if(subtext)
138                 drawstring_aspect(pos + eY * timer_size.y, subtext, subtext_size, '1 0 0', panel_fg_alpha, DRAWFLAG_NORMAL);
139
140         draw_endBoldFont();
141 }