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