]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/timer.qc
Use timer color for secondary timer too
[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 vector HUD_Timer_Color(float timeleft)
14 {
15         if(timeleft >= 300)
16                 return '1 1 1'; //white
17         else if(timeleft >= 60)
18                 return '1 1 0'; //yellow
19         else
20                 return '1 0 0'; //red
21 }
22
23 void HUD_Timer()
24 {
25         if(!autocvar__hud_configure)
26         {
27                 if(!autocvar_hud_panel_timer) return;
28         }
29
30         HUD_Panel_LoadCvars();
31
32         draw_beginBoldFont();
33
34         vector pos, mySize;
35         pos = panel_pos;
36         mySize = panel_size;
37
38         if (autocvar_hud_panel_timer_dynamichud)
39                 HUD_Scale_Enable();
40         else
41                 HUD_Scale_Disable();
42         if(panel_bg_padding)
43         {
44                 pos += '1 1 0' * panel_bg_padding;
45                 mySize -= '2 2 0' * panel_bg_padding;
46         }
47
48         string timer;
49         string subtimer = string_null;
50         string subtext = string_null;
51         float timelimit, timeleft, overtimes;
52         float round_timelimit, round_timeleft;
53         vector timer_size, subtext_size, subtimer_size;
54         vector timer_color = '1 1 1';
55         vector subtimer_color = '1 1 1';
56
57         // Calculate timelimit
58         if(warmup_stage)
59         {
60                 timelimit = STAT(WARMUP_TIMELIMIT);
61                 if(timelimit == 0)
62                         timelimit = STAT(TIMELIMIT) * 60;
63         }
64         else
65         {
66                 timelimit = STAT(TIMELIMIT) * 60;
67         }
68
69         // Calculate time left
70         timeleft = timelimit + STAT(GAMESTARTTIME) - time;
71         if (!autocvar_hud_panel_timer_unbound)
72                 timeleft = bound(0, timeleft, timelimit);
73         timeleft = ceil(timeleft);
74
75         // Timer color
76         if(!intermission_time && !warmup_stage && timelimit > 0)
77                 timer_color = HUD_Timer_Color(timeleft);
78
79         // Timer text
80         if (intermission_time) {
81                 timer = seconds_tostring(max(0, floor(intermission_time - STAT(GAMESTARTTIME))));
82         } else if (autocvar_hud_panel_timer_increment || timelimit <= 0) {
83                 float time_elapsed = floor(time - STAT(GAMESTARTTIME));
84                 if (!autocvar_hud_panel_timer_unbound)
85                         time_elapsed = max(0, time_elapsed);
86
87                 timer = seconds_tostring(time_elapsed);
88         } else {
89                 timer = seconds_tostring(timeleft);
90         }
91         
92         // Round-based game modes
93         if(STAT(ROUNDSTARTTIME))
94         {
95                 round_timelimit = STAT(ROUND_TIMELIMIT);
96
97                 // Calculate round time left
98                 round_timeleft = round_timelimit + STAT(ROUNDSTARTTIME) - time;
99                 if (!autocvar_hud_panel_timer_unbound)
100                         round_timeleft = bound(0, round_timeleft, round_timelimit);
101                 round_timeleft = ceil(round_timeleft);
102
103                 // Subtimer color
104                 if(!intermission_time && round_timelimit > 0)
105                         subtimer_color = HUD_Timer_Color(round_timeleft);
106
107                 // Subtimer text
108                 if (intermission_time) {
109                         subtimer = seconds_tostring(max(0, floor(intermission_time - STAT(ROUNDSTARTTIME))));
110                 } else if (autocvar_hud_panel_timer_increment || round_timelimit <= 0) {
111                         float round_time_elapsed = floor(time - STAT(ROUNDSTARTTIME));
112                         if (!autocvar_hud_panel_timer_unbound)
113                                 round_time_elapsed = max(0, round_time_elapsed);
114
115                         subtimer = seconds_tostring(round_time_elapsed);
116                 } else {
117                         subtimer = seconds_tostring(round_timeleft);
118                 }
119         }
120
121         // Subtext
122         overtimes = STAT(OVERTIMESADDED);
123
124         if(warmup_stage || autocvar__hud_configure)
125                 subtext = _("Warmup");
126         else if(intermission_time)
127                 subtext = _("Intermission");
128         else if(STAT(TIMEOUT_STATUS))
129                 subtext = _("Timeout");
130         else if (overtimes >= 2)
131                 subtext = sprintf(_("Overtime #%d"), overtimes);
132         else if(overtimes)
133                 subtext = _("Overtime");
134
135         subtext_size  = vec2(mySize.x, mySize.y / 3);
136         timer_size    = vec2(mySize.x, mySize.y - subtext_size.y);
137         subtimer_size = vec2(mySize.x / 3, mySize.y - subtext_size.y);
138         
139         panel_size.y -= subtext_size.y;
140         HUD_Panel_DrawBg();
141         
142         if(subtimer) {
143                 timer_size.x -= subtimer_size.x;
144                 drawstring_aspect(pos + eX * timer_size.x, subtimer, subtimer_size, subtimer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
145         }
146         
147         drawstring_aspect(pos, timer, timer_size, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
148         
149         if(subtext)
150                 drawstring_aspect(pos + eY * timer_size.y, subtext, subtext_size, '1 0 0', panel_fg_alpha, DRAWFLAG_NORMAL);
151
152         draw_endBoldFont();
153 }