]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/racetimer.qc
Header police
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / racetimer.qc
1 #include "racetimer.qh"
2 /** Race timer (#8) */
3 void HUD_RaceTimer ()
4 {
5         if(!autocvar__hud_configure)
6         {
7                 if(!autocvar_hud_panel_racetimer) return;
8                 if(!(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
9                 if(spectatee_status == -1) return;
10         }
11
12         HUD_Panel_UpdateCvars();
13
14         vector pos, mySize;
15         pos = panel_pos;
16         mySize = panel_size;
17
18         HUD_Panel_DrawBg(1);
19         if(panel_bg_padding)
20         {
21                 pos += '1 1 0' * panel_bg_padding;
22                 mySize -= '2 2 0' * panel_bg_padding;
23         }
24
25         // always force 4:1 aspect
26         vector newSize = '0 0 0';
27         if(mySize.x/mySize.y > 4)
28         {
29                 newSize.x = 4 * mySize.y;
30                 newSize.y = mySize.y;
31
32                 pos.x = pos.x + (mySize.x - newSize.x) / 2;
33         }
34         else
35         {
36                 newSize.y = 1/4 * mySize.x;
37                 newSize.x = mySize.x;
38
39                 pos.y = pos.y + (mySize.y - newSize.y) / 2;
40         }
41         mySize = newSize;
42
43         float a, t;
44         string s, forcetime;
45
46         if(autocvar__hud_configure)
47         {
48                 s = "0:13:37";
49                 draw_beginBoldFont();
50                 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);
51                 draw_endBoldFont();
52                 s = _("^1Intermediate 1 (+15.42)");
53                 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);
54                 s = sprintf(_("^1PENALTY: %.1f (%s)"), 2, "missing a checkpoint");
55                 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);
56         }
57         else if(race_checkpointtime)
58         {
59                 a = bound(0, 2 - (time - race_checkpointtime), 1);
60                 s = "";
61                 forcetime = "";
62                 if(a > 0) // just hit a checkpoint?
63                 {
64                         if(race_checkpoint != 254)
65                         {
66                                 if(race_time && race_previousbesttime)
67                                         s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
68                                 else
69                                         s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
70                                 if(race_time)
71                                         forcetime = TIME_ENCODED_TOSTRING(race_time);
72                         }
73                 }
74                 else
75                 {
76                         if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
77                         {
78                                 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
79                                 if(a > 0) // next one?
80                                 {
81                                         s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
82                                 }
83                         }
84                 }
85
86                 if(s != "" && a > 0)
87                 {
88                         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);
89                 }
90
91                 if(race_penaltytime)
92                 {
93                         a = bound(0, 2 - (time - race_penaltyeventtime), 1);
94                         if(a > 0)
95                         {
96                                 s = sprintf(_("^1PENALTY: %.1f (%s)"), race_penaltytime * 0.1, race_penaltyreason);
97                                 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);
98                         }
99                 }
100
101                 draw_beginBoldFont();
102
103                 if(forcetime != "")
104                 {
105                         a = bound(0, (time - race_checkpointtime) / 0.5, 1);
106                         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);
107                 }
108                 else
109                         a = 1;
110
111                 if(race_laptime && race_checkpoint != 255)
112                 {
113                         s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
114                         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);
115                 }
116
117                 draw_endBoldFont();
118         }
119         else
120         {
121                 if(race_mycheckpointtime)
122                 {
123                         a = bound(0, 2 - (time - race_mycheckpointtime), 1);
124                         s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -(race_mycheckpointenemy == ""), race_mycheckpointlapsdelta, race_mycheckpointenemy);
125                         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);
126                 }
127                 if(race_othercheckpointtime && race_othercheckpointenemy != "")
128                 {
129                         a = bound(0, 2 - (time - race_othercheckpointtime), 1);
130                         s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -(race_othercheckpointenemy == ""), race_othercheckpointlapsdelta, race_othercheckpointenemy);
131                         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);
132                 }
133
134                 if(race_penaltytime && !race_penaltyaccumulator)
135                 {
136                         t = race_penaltytime * 0.1 + race_penaltyeventtime;
137                         a = bound(0, (1 + t - time), 1);
138                         if(a > 0)
139                         {
140                                 if(time < t)
141                                         s = sprintf(_("^1PENALTY: %.1f (%s)"), (t - time) * 0.1, race_penaltyreason);
142                                 else
143                                         s = sprintf(_("^2PENALTY: %.1f (%s)"), 0, race_penaltyreason);
144                                 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);
145                         }
146                 }
147         }
148 }