]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/racetimer.qc
Move 2 panel specific functions to their relative files
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / racetimer.qc
1 /** Race timer (#8) */
2
3 // return the string of the onscreen race timer
4 string MakeRaceString(int cp, float mytime, float theirtime, float lapdelta, string theirname)
5 {
6         string col;
7         string timestr;
8         string cpname;
9         string lapstr;
10         lapstr = "";
11
12         if(theirtime == 0) // goal hit
13         {
14                 if(mytime > 0)
15                 {
16                         timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
17                         col = "^1";
18                 }
19                 else if(mytime == 0)
20                 {
21                         timestr = "+0.0";
22                         col = "^3";
23                 }
24                 else
25                 {
26                         timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
27                         col = "^2";
28                 }
29
30                 if(lapdelta > 0)
31                 {
32                         lapstr = sprintf(_(" (-%dL)"), lapdelta);
33                         col = "^2";
34                 }
35                 else if(lapdelta < 0)
36                 {
37                         lapstr = sprintf(_(" (+%dL)"), -lapdelta);
38                         col = "^1";
39                 }
40         }
41         else if(theirtime > 0) // anticipation
42         {
43                 if(mytime >= theirtime)
44                         timestr = strcat("+", ftos_decimals(mytime - theirtime, TIME_DECIMALS));
45                 else
46                         timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(theirtime));
47                 col = "^3";
48         }
49         else
50         {
51                 col = "^7";
52                 timestr = "";
53         }
54
55         if(cp == 254)
56                 cpname = _("Start line");
57         else if(cp == 255)
58                 cpname = _("Finish line");
59         else if(cp)
60                 cpname = sprintf(_("Intermediate %d"), cp);
61         else
62                 cpname = _("Finish line");
63
64         if(theirtime < 0)
65                 return strcat(col, cpname);
66         else if(theirname == "")
67                 return strcat(col, sprintf("%s (%s)", cpname, timestr));
68         else
69                 return strcat(col, sprintf("%s (%s %s)", cpname, timestr, strcat(theirname, col, lapstr)));
70 }
71
72 void HUD_RaceTimer ()
73 {
74         if(!autocvar__hud_configure)
75         {
76                 if(!autocvar_hud_panel_racetimer) return;
77                 if(!(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
78                 if(spectatee_status == -1) return;
79         }
80
81         HUD_Panel_UpdateCvars();
82
83         vector pos, mySize;
84         pos = panel_pos;
85         mySize = panel_size;
86
87         HUD_Panel_DrawBg(1);
88         if(panel_bg_padding)
89         {
90                 pos += '1 1 0' * panel_bg_padding;
91                 mySize -= '2 2 0' * panel_bg_padding;
92         }
93
94         // always force 4:1 aspect
95         vector newSize = '0 0 0';
96         if(mySize.x/mySize.y > 4)
97         {
98                 newSize.x = 4 * mySize.y;
99                 newSize.y = mySize.y;
100
101                 pos.x = pos.x + (mySize.x - newSize.x) / 2;
102         }
103         else
104         {
105                 newSize.y = 1/4 * mySize.x;
106                 newSize.x = mySize.x;
107
108                 pos.y = pos.y + (mySize.y - newSize.y) / 2;
109         }
110         mySize = newSize;
111
112         float a, t;
113         string s, forcetime;
114
115         if(autocvar__hud_configure)
116         {
117                 s = "0:13:37";
118                 draw_beginBoldFont();
119                 drawstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, false, '0.60 0.60 0' * mySize.y), s, '0.60 0.60 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
120                 draw_endBoldFont();
121                 s = _("^1Intermediate 1 (+15.42)");
122                 drawcolorcodedstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, true, '1 1 0' * 0.20 * mySize.y) + eY * 0.60 * mySize.y, s, '1 1 0' * 0.20 * mySize.y, panel_fg_alpha, DRAWFLAG_NORMAL);
123                 s = sprintf(_("^1PENALTY: %.1f (%s)"), 2, "missing a checkpoint");
124                 drawcolorcodedstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, true, '1 1 0' * 0.20 * mySize.y) + eY * 0.80 * mySize.y, s, '1 1 0' * 0.20 * mySize.y, panel_fg_alpha, DRAWFLAG_NORMAL);
125         }
126         else if(race_checkpointtime)
127         {
128                 a = bound(0, 2 - (time - race_checkpointtime), 1);
129                 s = "";
130                 forcetime = "";
131                 if(a > 0) // just hit a checkpoint?
132                 {
133                         if(race_checkpoint != 254)
134                         {
135                                 if(race_time && race_previousbesttime)
136                                         s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
137                                 else
138                                         s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
139                                 if(race_time)
140                                         forcetime = TIME_ENCODED_TOSTRING(race_time);
141                         }
142                 }
143                 else
144                 {
145                         if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
146                         {
147                                 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
148                                 if(a > 0) // next one?
149                                 {
150                                         s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
151                                 }
152                         }
153                 }
154
155                 if(s != "" && a > 0)
156                 {
157                         drawcolorcodedstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, true, '1 1 0' * 0.2 * mySize.y) + eY * 0.6 * mySize.y, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
158                 }
159
160                 if(race_penaltytime)
161                 {
162                         a = bound(0, 2 - (time - race_penaltyeventtime), 1);
163                         if(a > 0)
164                         {
165                                 s = sprintf(_("^1PENALTY: %.1f (%s)"), race_penaltytime * 0.1, race_penaltyreason);
166                                 drawcolorcodedstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, true, '1 1 0' * 0.2 * mySize.y) + eY * 0.8 * mySize.y, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
167                         }
168                 }
169
170                 draw_beginBoldFont();
171
172                 if(forcetime != "")
173                 {
174                         a = bound(0, (time - race_checkpointtime) / 0.5, 1);
175                         drawstring_expanding(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(forcetime, false, '1 1 0' * 0.6 * mySize.y), forcetime, '1 1 0' * 0.6 * mySize.y, '1 1 1', panel_fg_alpha, 0, a);
176                 }
177                 else
178                         a = 1;
179
180                 if(race_laptime && race_checkpoint != 255)
181                 {
182                         s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
183                         drawstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, false, '0.6 0.6 0' * mySize.y), s, '0.6 0.6 0' * mySize.y, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
184                 }
185
186                 draw_endBoldFont();
187         }
188         else
189         {
190                 if(race_mycheckpointtime)
191                 {
192                         a = bound(0, 2 - (time - race_mycheckpointtime), 1);
193                         s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -(race_mycheckpointenemy == ""), race_mycheckpointlapsdelta, race_mycheckpointenemy);
194                         drawcolorcodedstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, true, '1 1 0' * 0.2 * mySize.y) + eY * 0.6 * mySize.y, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
195                 }
196                 if(race_othercheckpointtime && race_othercheckpointenemy != "")
197                 {
198                         a = bound(0, 2 - (time - race_othercheckpointtime), 1);
199                         s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -(race_othercheckpointenemy == ""), race_othercheckpointlapsdelta, race_othercheckpointenemy);
200                         drawcolorcodedstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, true, '1 1 0' * 0.2 * mySize.y) + eY * 0.6 * mySize.y, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
201                 }
202
203                 if(race_penaltytime && !race_penaltyaccumulator)
204                 {
205                         t = race_penaltytime * 0.1 + race_penaltyeventtime;
206                         a = bound(0, (1 + t - time), 1);
207                         if(a > 0)
208                         {
209                                 if(time < t)
210                                         s = sprintf(_("^1PENALTY: %.1f (%s)"), (t - time) * 0.1, race_penaltyreason);
211                                 else
212                                         s = sprintf(_("^2PENALTY: %.1f (%s)"), 0, race_penaltyreason);
213                                 drawcolorcodedstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, true, '1 1 0' * 0.2 * mySize.y) + eY * 0.6 * mySize.y, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
214                         }
215                 }
216         }
217 }