3 #include <client/miscfunctions.qh>
4 #include <client/autocvars.qh>
5 #include <common/mapinfo.qh>
6 #include <common/ent_cs.qh>
7 #include <common/scores.qh>
8 #include <common/gamemodes/_mod.qh>
12 void DrawCAItem(vector myPos, vector mySize, float aspect_ratio, int layout, int i)
14 TC(int, layout); TC(int, i);
17 vector color = '0 0 0';
20 case 0: stat = STAT(REDALIVE); pic = "player_red"; color = '1 0 0'; break;
21 case 1: stat = STAT(BLUEALIVE); pic = "player_blue"; color = '0 0 1'; break;
22 case 2: stat = STAT(YELLOWALIVE); pic = "player_yellow"; color = '1 1 0'; break;
24 case 3: stat = STAT(PINKALIVE); pic = "player_pink"; color = '1 0 1'; break;
27 if(mySize.x/mySize.y > aspect_ratio)
29 i = aspect_ratio * mySize.y;
30 myPos.x = myPos.x + (mySize.x - i) / 2;
35 i = 1/aspect_ratio * mySize.x;
36 myPos.y = myPos.y + (mySize.y - i) / 2;
42 drawpic_aspect_skin(myPos, pic, vec2(0.5 * mySize.x, mySize.y), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
43 drawstring_aspect(myPos + eX * 0.5 * mySize.x, ftos(stat), vec2(0.5 * mySize.x, mySize.y), color, panel_fg_alpha, DRAWFLAG_NORMAL);
46 drawstring_aspect(myPos, ftos(stat), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
49 // Clan Arena and Freeze Tag HUD modicons
50 void HUD_Mod_CA(vector myPos, vector mySize)
52 mod_active = 1; // required in each mod function that always shows something
56 layout = autocvar_hud_panel_modicons_ca_layout;
57 else //if(ISGAMETYPE(FREEZETAG))
58 layout = autocvar_hud_panel_modicons_freezetag_layout;
61 aspect_ratio = (layout) ? 2 : 1;
62 rows = HUD_GetRowCount(team_count, mySize, aspect_ratio);
63 columns = ceil(team_count/rows);
66 float row = 0, column = 0;
67 vector pos = '0 0 0', itemSize;
68 itemSize = vec2(mySize.x / columns, mySize.y / rows);
69 for(i=0; i<team_count; ++i)
71 pos.x = myPos.x + column * itemSize.x;
72 pos.y = myPos.y + row * itemSize.y;
74 DrawCAItem(pos, itemSize, aspect_ratio, layout, i);
85 // Race/CTS HUD mod icons
86 float crecordtime_prev; // last remembered crecordtime
87 float crecordtime_change_time; // time when crecordtime last changed
88 float srecordtime_prev; // last remembered srecordtime
89 float srecordtime_change_time; // time when srecordtime last changed
91 float race_status_time;
93 string race_status_name_prev;
95 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
96 int race_CheckName(string net_name)
99 string zoned_name = strzone(strdecolorize(entcs_GetName(player_localnum)));
100 for (int i = RANKINGS_CNT - 1; i >= 0; --i)
101 if (strdecolorize(grecordholder[i]) == zoned_name)
110 void race_showTime(string text, vector pos, vector timeText_ofs, float theTime, vector textSize, float f)
112 drawstring_aspect(pos, text, textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
113 drawstring_aspect(pos + timeText_ofs, TIME_ENCODED_TOSTRING(theTime), textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
115 drawstring_aspect_expanding(pos, text, textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
116 drawstring_aspect_expanding(pos + timeText_ofs, TIME_ENCODED_TOSTRING(theTime), textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
120 void HUD_Mod_Race(vector pos, vector mySize)
122 entity me = playerslots[player_localnum];
123 float score = me.(scores(ps_primary));
125 if(!(scores_flags(ps_primary) & SFL_TIME) || teamplay) // race/cts record display on HUD
127 mod_active = 0; // hide it in this case!
128 return; // no records in the actual race
133 // clientside personal record
139 float t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
141 if(score && (score < t || !t)) {
142 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
143 if(autocvar_cl_autodemo_delete_keeprecords)
145 float f = autocvar_cl_autodemo_delete;
147 cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
151 if(t != crecordtime_prev) {
152 crecordtime_prev = t;
153 crecordtime_change_time = time;
156 vector textPos, medalPos;
158 if(mySize.x > mySize.y) {
160 squareSize = min(mySize.y, mySize.x/2);
161 vector ofs = vec2(0.5 * max(0, mySize.x/2 - squareSize), 0.5 * (mySize.y - squareSize));
163 ofs.x += 0.5 * mySize.x;
164 medalPos = pos + ofs;
167 squareSize = min(mySize.x, mySize.y/2);
168 vector ofs = vec2(0.5 * (mySize.x - squareSize), 0.5 * max(0, mySize.y/2 - squareSize));
170 ofs.y += 0.5 * mySize.y;
171 medalPos = pos + ofs;
173 vector textSize = vec2(squareSize, 0.25 * squareSize);
175 race_showTime(_("Personal best"), textPos, eY * 0.25 * squareSize, t, textSize, time - crecordtime_change_time);
178 t = race_server_record;
179 if(t != srecordtime_prev) {
180 srecordtime_prev = t;
181 srecordtime_change_time = time;
184 textPos += eY * 0.5 * squareSize;
185 race_showTime(_("Server best"), textPos, eY * 0.25 * squareSize, t, textSize, time - srecordtime_change_time);
187 if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
188 race_status_time = time + 5;
189 race_status_prev = race_status;
190 strcpy(race_status_name_prev, race_status_name);
194 float a = bound(0, race_status_time - time, 1);
195 string s = textShortenToWidth(ColorTranslateRGB(race_status_name), squareSize, '1 1 0' * 0.1 * squareSize, stringwidth_colors);
199 rank = race_CheckName(race_status_name);
200 string rankname = count_ordinal(rank);
201 vector namepos = medalPos + '0 0.8 0' * squareSize;
202 vector rankpos = medalPos + '0 0.15 0' * squareSize;
205 drawpic_aspect_skin(medalPos, "race_newfail", '1 1 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
206 else if(race_status == 1) {
207 drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newtime", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
208 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
209 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
210 } else if(race_status == 2) {
211 if(strdecolorize(race_status_name) == strdecolorize(entcs_GetName(player_localnum)) || !race_myrank || race_myrank < rank)
212 drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newrankgreen", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
214 drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newrankyellow", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
215 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
216 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
217 } else if(race_status == 3) {
218 drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newrecordserver", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
219 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
220 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
223 if (race_status_time - time <= 0) {
224 race_status_prev = -1;
226 strfree(race_status_name);
227 strfree(race_status_name_prev);
231 void HUD_ModIcons_SetFunc()
233 HUD_ModIcons_GameType = gametype.m_modicons;
240 if(!autocvar__hud_configure)
242 if(!autocvar_hud_panel_modicons) return;
243 if(!HUD_ModIcons_GameType) return;
246 if(mod_active || autocvar__hud_configure)
247 mod_alpha = min(mod_alpha + frametime * 2, 1);
249 mod_alpha = max(mod_alpha - frametime * 2, 0);
253 panel_fade_alpha *= mod_alpha;
254 HUD_Panel_LoadCvars();
256 draw_beginBoldFont();
258 if (autocvar_hud_panel_modicons_dynamichud)
267 panel_pos += '1 1 0' * panel_bg_padding;
268 panel_size -= '2 2 0' * panel_bg_padding;
271 if(autocvar__hud_configure)
272 HUD_Mod_CTF(panel_pos, panel_size);
274 HUD_ModIcons_GameType(panel_pos, panel_size);