3 #include <client/autocvars.qh>
4 #include <client/draw.qh>
5 #include <common/ent_cs.qh>
6 #include <client/mapvoting.qh>
7 #include <client/resources.qh>
8 #include <client/teamradar.qh>
9 #include <common/mutators/mutator/waypoints/all.qh>
13 void HUD_Radar_Export(int fh)
15 // allow saving cvars that aesthetically change the panel into hud skin files
16 HUD_Write_Cvar("hud_panel_radar_foreground_alpha");
17 HUD_Write_Cvar("hud_panel_radar_rotation");
18 HUD_Write_Cvar("hud_panel_radar_zoommode");
19 HUD_Write_Cvar("hud_panel_radar_scale");
20 HUD_Write_Cvar("hud_panel_radar_maximized_scale");
21 HUD_Write_Cvar("hud_panel_radar_maximized_size");
22 HUD_Write_Cvar("hud_panel_radar_maximized_rotation");
23 HUD_Write_Cvar("hud_panel_radar_maximized_zoommode");
26 bool HUD_Radar_Clickable()
28 return hud_panel_radar_mouse && !hud_panel_radar_temp_hidden;
31 void HUD_Radar_Show_Maximized(bool doshow, bool clickable)
34 hud_panel_radar_maximized = doshow;
35 hud_panel_radar_temp_hidden = 0;
41 hud_panel_radar_mouse = 1;
43 // we must unset the player's buttons, as they aren't released elsewhere
51 else if ( hud_panel_radar_mouse )
53 hud_panel_radar_mouse = 0;
57 void HUD_Radar_Hide_Maximized()
59 HUD_Radar_Show_Maximized(false,false);
63 float HUD_Radar_InputEvent(int bInputType, float nPrimary, float nSecondary)
66 if(!hud_panel_radar_maximized || !hud_panel_radar_mouse ||
67 autocvar__hud_configure || mv_active)
72 mousepos_x = nPrimary;
73 mousepos_y = nSecondary;
77 if(nPrimary == K_MOUSE1)
79 if(bInputType == 0) // key pressed
80 mouseClicked |= S_MOUSE1;
81 else if(bInputType == 1) // key released
82 mouseClicked -= (mouseClicked & S_MOUSE1);
84 else if(nPrimary == K_MOUSE2)
86 if(bInputType == 0) // key pressed
87 mouseClicked |= S_MOUSE2;
88 else if(bInputType == 1) // key released
89 mouseClicked -= (mouseClicked & S_MOUSE2);
91 else if ( nPrimary == K_ESCAPE && bInputType == 0 )
93 HUD_Radar_Hide_Maximized();
97 // allow console/use binds to work without hiding the map
98 string con_keys = strcat(findkeysforcommand("toggleconsole", 0), " ", findkeysforcommand("+use", 0)) ;
99 int keys = tokenize(con_keys); // findkeysforcommand returns data for this
101 for (i = 0; i < keys; ++i)
103 if(nPrimary == stof(argv(i)))
107 if ( STAT(HEALTH) <= 0 )
110 if ( bInputType < 2 )
112 con_keys = findkeysforcommand("+showscores", 0);
113 keys = tokenize(con_keys);
114 for (i = 0; i < keys; ++i)
116 if ( nPrimary == stof(argv(i)) )
118 hud_panel_radar_temp_hidden = bInputType == 0;
124 else if ( bInputType == 0 )
125 HUD_Radar_Hide_Maximized();
133 void HUD_Radar_Mouse()
135 if ( !hud_panel_radar_mouse ) return;
136 if(mv_active) return;
140 HUD_Radar_Hide_Maximized();
144 if(mouseClicked & S_MOUSE2)
146 HUD_Radar_Hide_Maximized();
150 panel = HUD_PANEL(RADAR);
151 HUD_Panel_LoadCvars();
154 panel_size = autocvar_hud_panel_radar_maximized_size;
155 panel_size_x = bound(0.2, panel_size_x, 1) * vid_conwidth;
156 panel_size_y = bound(0.2, panel_size_y, 1) * vid_conheight;
157 panel_pos_x = (vid_conwidth - panel_size_x) / 2;
158 panel_pos_y = (vid_conheight - panel_size_y) / 2;
160 if(mouseClicked & S_MOUSE1)
163 if ( mousepos_x < panel_pos_x || mousepos_x > panel_pos_x + panel_size_x ||
164 mousepos_y < panel_pos_y || mousepos_y > panel_pos_y + panel_size_y )
166 HUD_Radar_Hide_Maximized();
169 vector pos = teamradar_texcoord_to_3dcoord(teamradar_2dcoord_to_texcoord(mousepos),view_origin_z);
170 localcmd(sprintf("cmd ons_spawn %f %f %f",pos_x,pos_y,pos_z));
172 HUD_Radar_Hide_Maximized();
179 if (!autocvar__hud_configure)
181 if (hud_panel_radar_maximized)
183 if (!hud_draw_maximized) return;
187 if (autocvar_hud_panel_radar == 0) return;
188 if (autocvar_hud_panel_radar != 2 && !teamplay) return;
189 if(radar_panel_modified)
191 panel.update_time = time; // forces reload of panel attributes
192 radar_panel_modified = false;
197 if ( hud_panel_radar_temp_hidden )
200 HUD_Panel_LoadCvars();
204 if (hud_panel_radar_maximized && !autocvar__hud_configure)
206 panel_size = autocvar_hud_panel_radar_maximized_size;
207 panel_size.x = bound(0.2, panel_size.x, 1) * vid_conwidth;
208 panel_size.y = bound(0.2, panel_size.y, 1) * vid_conheight;
209 panel_pos.x = (vid_conwidth - panel_size.x) / 2;
210 panel_pos.y = (vid_conheight - panel_size.y) / 2;
213 panel_bg = strcat(hud_skin_path, "/border_default"); // always use the default border when maximized
214 if(precache_pic(panel_bg) == "")
215 panel_bg = "gfx/hud/default/border_default"; // fallback
216 if(!radar_panel_modified && panel_bg != panel.current_panel_bg)
217 radar_panel_modified = true;
218 strcpy(panel.current_panel_bg, panel_bg);
220 switch(hud_panel_radar_maximized_zoommode)
224 f = current_zoomfraction;
227 f = 1 - current_zoomfraction;
237 switch(hud_panel_radar_maximized_rotation)
240 teamradar_angle = view_angles.y - 90;
243 teamradar_angle = 90 * hud_panel_radar_maximized_rotation;
247 if (!hud_panel_radar_maximized && !autocvar__hud_configure)
249 switch(hud_panel_radar_zoommode)
253 f = current_zoomfraction;
256 f = 1 - current_zoomfraction;
266 switch(hud_panel_radar_rotation)
269 teamradar_angle = view_angles.y - 90;
272 teamradar_angle = 90 * hud_panel_radar_rotation;
281 if (autocvar_hud_panel_radar_dynamichud)
288 pos += '1 1 0' * panel_bg_padding;
289 mySize -= '2 2 0' * panel_bg_padding;
293 float scale2d, normalsize, bigsize;
295 teamradar_origin2d = HUD_Shift(pos + 0.5 * mySize);
296 teamradar_size2d = mySize;
298 if(minimapname == "")
301 teamradar_loadcvars();
303 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
304 teamradar_size2d = HUD_Scale(mySize);
306 teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
308 // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
309 if((hud_panel_radar_rotation == 0 && !hud_panel_radar_maximized) || (hud_panel_radar_maximized_rotation == 0 && hud_panel_radar_maximized))
311 // max-min distance must fit the radar in any rotation
312 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen(vec2(mi_scale)));
316 vector c0, c1, c2, c3, span;
317 c0 = Rotate(mi_min, teamradar_angle * DEG2RAD);
318 c1 = Rotate(mi_max, teamradar_angle * DEG2RAD);
319 c2 = Rotate('1 0 0' * mi_min.x + '0 1 0' * mi_max.y, teamradar_angle * DEG2RAD);
320 c3 = Rotate('1 0 0' * mi_max.x + '0 1 0' * mi_min.y, teamradar_angle * DEG2RAD);
322 span.x = max(c0_x, c1_x, c2_x, c3_x) - min(c0_x, c1_x, c2_x, c3_x);
323 span.y = max(c0_y, c1_y, c2_y, c3_y) - min(c0_y, c1_y, c2_y, c3_y);
325 // max-min distance must fit the radar in x=x, y=y
327 teamradar_size2d.x * scale2d / (1.05 * span.x),
328 teamradar_size2d.y * scale2d / (1.05 * span.y)
332 normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_panel_radar_scale;
333 if(bigsize > normalsize)
334 normalsize = bigsize;
338 + (1 - f) * normalsize;
339 teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
341 + (1 - f) * view_origin);
350 draw_teamradar_background(hud_panel_radar_foreground_alpha);
352 IL_EACH(g_radarlinks, true, draw_teamradar_link(it.origin, it.velocity, it.team));
354 bool mutator_returnvalue = MUTATOR_CALLHOOK(TeamRadar_Draw); // TODO: allow players to show on the radar as well!
356 IL_EACH(g_radaricons, it.teamradar_icon, {
357 if ( hud_panel_radar_mouse )
358 if ( GetResource(it, RES_HEALTH) >= 0 )
359 if ( it.team == myteam + 1 || mutator_returnvalue || !teamplay )
361 vector coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(it.origin));
362 if(vdist((mousepos - coord), <, 8))
365 brightcolor_x = min(1,it.teamradar_color_x*1.5);
366 brightcolor_y = min(1,it.teamradar_color_y*1.5);
367 brightcolor_z = min(1,it.teamradar_color_z*1.5);
368 drawpic(coord - '8 8 0', "gfx/teamradar_icon_glow", '16 16 0', brightcolor, panel_fg_alpha, 0);
371 entity icon = REGISTRY_GET(RadarIcons, it.teamradar_icon);
372 draw_teamradar_icon(it.origin, icon, it, spritelookupcolor(it, icon.netname, it.teamradar_color), panel_fg_alpha);
374 AL_EACH(_entcs, e, it != NULL, {
375 if (!it.m_entcs_private) continue;
376 if (it.sv_entnum == current_player) continue;
377 color2 = entcs_GetTeam(it.sv_entnum);
378 draw_teamradar_player(it.origin, it.angles, Team_ColorRGB(color2));
380 draw_teamradar_player(entcs_receiver(current_player).origin, view_angles, '1 1 1');
384 if ( hud_panel_radar_mouse )
386 string message = _("Click to select teleport destination");
388 if ( STAT(HEALTH) <= 0 )
390 message = _("Click to select spawn location");
393 drawcolorcodedstring(pos + '0.5 0 0' * (mySize_x - stringwidth(message, true, hud_fontsize)) - '0 1 0' * hud_fontsize_y * 2,
394 message, hud_fontsize, hud_panel_radar_foreground_alpha, DRAWFLAG_NORMAL);
396 hud_panel_radar_bottom = pos_y + mySize_y + hud_fontsize_y;