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