]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/racetimer.qc
Update default video settings
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / racetimer.qc
1 #include "racetimer.qh"
2
3 #include <client/draw.qh>
4
5 // Race timer (#8)
6
7 void HUD_RaceTimer_Export(int fh)
8 {
9         // allow saving cvars that aesthetically change the panel into hud skin files
10 }
11
12 // return the string of the onscreen race timer
13 string MakeRaceString(int cp, float mytime, float theirtime, float othertime, float lapdelta, string theirname)
14 {
15         TC(int, cp);
16         string cpname, lapstr = "", timestr = "", col = "^7", othercol = "^7", othertimestr = "";
17         if(theirname == "" || !autocvar_cl_race_cptimes_showself)
18                 othertime = 0; // don't count personal time
19
20         if(theirtime == 0) // goal hit
21         {
22                 if(mytime > 0)
23                 {
24                         timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
25                         col = "^1";
26                 }
27                 else if(mytime == 0)
28                 {
29                         timestr = "+0.0";
30                         col = "^3";
31                 }
32                 else
33                 {
34                         timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
35                         col = "^2";
36                 }
37
38                 if(othertime > 0)
39                 {
40                         othertimestr = strcat("+", ftos_decimals(+othertime, TIME_DECIMALS));
41                         othercol = "^1";
42                 }
43                 else if(othertime == 0)
44                 {
45                         othertimestr = "+0.0";
46                         othercol = "^3";
47                 }
48                 else
49                 {
50                         othertimestr = strcat("-", ftos_decimals(-othertime, TIME_DECIMALS));
51                         othercol = "^2";
52                 }
53
54                 if(lapdelta > 0)
55                 {
56                         lapstr = sprintf(_(" (-%dL)"), lapdelta);
57                         col = "^2";
58                 }
59                 else if(lapdelta < 0)
60                 {
61                         lapstr = sprintf(_(" (+%dL)"), -lapdelta);
62                         col = "^1";
63                 }
64         }
65         else if(theirtime > 0) // anticipation
66         {
67                 if(mytime >= theirtime)
68                         timestr = strcat("+", ftos_decimals(mytime - theirtime, TIME_DECIMALS));
69                 else
70                         timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(theirtime), false);
71                 col = "^3";
72                 if(mytime >= othertime)
73                         othertimestr = strcat("+", ftos_decimals(mytime - othertime, TIME_DECIMALS));
74                 else
75                         othertimestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(othertime), false);
76                 othercol = "^7";
77         }
78
79         if(cp == 254)
80                 cpname = _("Start line");
81         else if(cp == 255)
82                 cpname = _("Finish line");
83         else if(cp)
84                 cpname = sprintf(_("Intermediate %d"), cp);
85         else
86                 cpname = _("Finish line");
87
88         if(theirtime < 0)
89                 return strcat(col, cpname);
90         else if(theirname == "")
91                 return strcat(col, sprintf("%s (%s)", cpname, timestr));
92         else if(othertime)
93                 return strcat(col, sprintf("%s %s(%s)%s (%s %s)", cpname, othercol, othertimestr, col, timestr, strcat(ColorTranslateRGB(theirname), col, lapstr)));
94         else
95                 return strcat(col, sprintf("%s (%s %s)", cpname, timestr, strcat(ColorTranslateRGB(theirname), col, lapstr)));
96 }
97
98 void HUD_RaceTimer ()
99 {
100         if(!autocvar__hud_configure)
101         {
102                 if(!autocvar_hud_panel_racetimer) return;
103                 if(!MUTATOR_CALLHOOK(ShowRaceTimer)) return;
104                 if(spectatee_status == -1) return;
105         }
106
107         HUD_Panel_LoadCvars();
108
109         vector pos, mySize;
110         pos = panel_pos;
111         mySize = panel_size;
112
113         if (autocvar_hud_panel_racetimer_dynamichud)
114                 HUD_Scale_Enable();
115         else
116                 HUD_Scale_Disable();
117         HUD_Panel_DrawBg();
118         if(panel_bg_padding)
119         {
120                 pos += '1 1 0' * panel_bg_padding;
121                 mySize -= '2 2 0' * panel_bg_padding;
122         }
123
124         // always force 4:1 aspect
125         vector newSize = '0 0 0';
126         if(mySize.x/mySize.y > 4)
127         {
128                 newSize.x = 4 * mySize.y;
129                 newSize.y = mySize.y;
130
131                 pos.x = pos.x + (mySize.x - newSize.x) / 2;
132         }
133         else
134         {
135                 newSize.y = 1/4 * mySize.x;
136                 newSize.x = mySize.x;
137
138                 pos.y = pos.y + (mySize.y - newSize.y) / 2;
139         }
140         mySize = newSize;
141
142         float a, t;
143         string s, forcetime;
144         vector str_pos;
145
146         if(autocvar__hud_configure)
147         {
148                 s = "0:13:37";
149                 draw_beginBoldFont();
150                 str_pos = pos + eX * 0.5 * (mySize.x - stringwidth(s, false, '1 1 0' * 0.6 * mySize.y));
151                 drawstring(str_pos, s, '1 1 0' * 0.6 * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
152                 draw_endBoldFont();
153                 s = strcat("^1", sprintf(_("Intermediate %d"), 1), " (+15.42)");
154                 str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
155                 drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha, DRAWFLAG_NORMAL);
156                 s = sprintf(_("PENALTY: %.1f (%s)"), 2, _("missing a checkpoint"));
157                 s = strcat("^1", s);
158                 str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.8 * mySize.y);
159                 drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha, DRAWFLAG_NORMAL);
160         }
161         else if(race_checkpointtime)
162         {
163                 a = bound(0, 2 - (time - race_checkpointtime), 1);
164                 s = "";
165                 forcetime = "";
166                 if(a > 0) // just hit a checkpoint?
167                 {
168                         if(race_checkpoint != 254)
169                         {
170                                 if(race_time && race_previousbesttime)
171                                         s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, ((race_mypreviousbesttime) ? TIME_DECODE(race_time) - TIME_DECODE(race_mypreviousbesttime) : 0), 0, race_previousbestname);
172                                 else
173                                         s = MakeRaceString(race_checkpoint, 0, -1, 0, 0, race_previousbestname);
174                                 if(race_time)
175                                         forcetime = TIME_ENCODED_TOSTRING(race_time, false);
176                         }
177                 }
178                 else
179                 {
180                         if(race_laptime && race_nextcheckpoint != 254)
181                         {
182                                 if(race_nextbesttime)
183                                 {
184                                         a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
185                                         float a2 = ((race_mybesttime) ? bound(0, 2 - ((race_laptime + TIME_DECODE(race_mybesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1) : 0);
186                                         if(a > 0) // next one?
187                                                 s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), ((a2 > 0) ? TIME_DECODE(race_mybesttime) : 0), 0, race_nextbestname);
188                                 }
189                         }
190                 }
191
192                 if(s != "" && a > 0)
193                 {
194                         str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
195                         drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
196                 }
197
198                 if(race_penaltytime)
199                 {
200                         a = bound(0, 2 - (time - race_penaltyeventtime), 1);
201                         if(a > 0)
202                         {
203                                 s = sprintf(_("PENALTY: %.1f (%s)"), race_penaltytime * 0.1, race_penaltyreason);
204                                 s = strcat("^1", s);
205                                 str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.8 * mySize.y);
206                                 drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
207                         }
208                 }
209
210                 draw_beginBoldFont();
211
212                 if(forcetime != "")
213                 {
214                         a = bound(0, (time - race_checkpointtime) / 0.5, 1);
215                         str_pos = pos + eX * 0.5 * (mySize.x - stringwidth(forcetime, false, '1 1 0' * 0.6 * mySize.y));
216                         drawstring_expanding(str_pos, forcetime, '1 1 0' * 0.6 * mySize.y, '1 1 1', panel_fg_alpha, 0, a);
217                 }
218                 else
219                         a = 1;
220
221                 if(race_laptime && race_checkpoint != 255)
222                 {
223                         s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime), false);
224                         str_pos = pos + eX * 0.5 * (mySize.x - stringwidth(s, false, '0.6 0.6 0' * mySize.y));
225                         drawstring(str_pos, s, '0.6 0.6 0' * mySize.y, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
226                 }
227
228                 draw_endBoldFont();
229         }
230         else
231         {
232                 if(race_mycheckpointtime)
233                 {
234                         a = bound(0, 2 - (time - race_mycheckpointtime), 1);
235                         s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -(race_mycheckpointenemy == ""), 0, race_mycheckpointlapsdelta, race_mycheckpointenemy);
236                         str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
237                         drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
238                 }
239                 if(race_othercheckpointtime && race_othercheckpointenemy != "")
240                 {
241                         a = bound(0, 2 - (time - race_othercheckpointtime), 1);
242                         s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -(race_othercheckpointenemy == ""), 0, race_othercheckpointlapsdelta, race_othercheckpointenemy);
243                         str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
244                         drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
245                 }
246
247                 if(race_penaltytime && !race_penaltyaccumulator)
248                 {
249                         t = race_penaltytime * 0.1 + race_penaltyeventtime;
250                         a = bound(0, (1 + t - time), 1);
251                         if(a > 0)
252                         {
253                                 string col;
254                                 if(time < t)
255                                 {
256                                         t = (t - time) * 0.1;
257                                         col = "^1";
258                                 }
259                                 else
260                                 {
261                                         t = 0;
262                                         col = "^2";
263                                 }
264                                 s = sprintf(_("PENALTY: %.1f (%s)"), t, race_penaltyreason);
265                                 s = strcat(col, s);
266                                 str_pos = pos + vec2(0.5 * (mySize.x - stringwidth(s, true, '1 1 0' * 0.2 * mySize.y)), 0.6 * mySize.y);
267                                 drawcolorcodedstring(str_pos, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
268                         }
269                 }
270         }
271 }