3 #include <common/ent_cs.qh>
4 #include <common/mapinfo.qh>
5 #include <client/mapvoting.qh>
6 #include <client/teamradar.qh>
7 #include <common/mutators/mutator/waypoints/all.qh>
11 float HUD_Radar_Clickable()
13 return hud_panel_radar_mouse && !hud_panel_radar_temp_hidden;
16 void HUD_Radar_Show_Maximized(bool doshow,float clickable)
18 hud_panel_radar_maximized = doshow;
19 hud_panel_radar_temp_hidden = 0;
25 if(autocvar_hud_cursormode)
27 hud_panel_radar_mouse = 1;
30 else if ( hud_panel_radar_mouse )
32 hud_panel_radar_mouse = 0;
34 if(autocvar_hud_cursormode)
39 void HUD_Radar_Hide_Maximized()
41 HUD_Radar_Show_Maximized(false,false);
45 float HUD_Radar_InputEvent(float bInputType, float nPrimary, float nSecondary)
47 if(!hud_panel_radar_maximized || !hud_panel_radar_mouse ||
48 autocvar__hud_configure || mv_active)
53 mousepos_x = nPrimary;
54 mousepos_y = nSecondary;
58 if(nPrimary == K_MOUSE1)
60 if(bInputType == 0) // key pressed
61 mouseClicked |= S_MOUSE1;
62 else if(bInputType == 1) // key released
63 mouseClicked -= (mouseClicked & S_MOUSE1);
65 else if(nPrimary == K_MOUSE2)
67 if(bInputType == 0) // key pressed
68 mouseClicked |= S_MOUSE2;
69 else if(bInputType == 1) // key released
70 mouseClicked -= (mouseClicked & S_MOUSE2);
72 else if ( nPrimary == K_ESCAPE && bInputType == 0 )
74 HUD_Radar_Hide_Maximized();
78 // allow console/use binds to work without hiding the map
82 con_keys = strcat(findkeysforcommand("toggleconsole", 0)," ",findkeysforcommand("+use", 0)) ;
83 keys = tokenize(con_keys); // findkeysforcommand returns data for this
84 for (i = 0; i < keys; ++i)
86 if(nPrimary == stof(argv(i)))
90 if ( STAT(HEALTH) <= 0 )
95 con_keys = findkeysforcommand("+showscores", 0);
96 keys = tokenize(con_keys);
97 for (i = 0; i < keys; ++i)
99 if ( nPrimary == stof(argv(i)) )
101 hud_panel_radar_temp_hidden = bInputType == 0;
107 else if ( bInputType == 0 )
108 HUD_Radar_Hide_Maximized();
116 void HUD_Radar_Mouse()
118 if ( !hud_panel_radar_mouse ) return;
119 if(mv_active) return;
123 HUD_Radar_Hide_Maximized();
127 if(mouseClicked & S_MOUSE2)
129 HUD_Radar_Hide_Maximized();
133 if(!autocvar_hud_cursormode)
135 mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
137 mousepos_x = bound(0, mousepos_x, vid_conwidth);
138 mousepos_y = bound(0, mousepos_y, vid_conheight);
141 HUD_Panel_UpdateCvars();
144 panel_size = autocvar_hud_panel_radar_maximized_size;
145 panel_size_x = bound(0.2, panel_size_x, 1) * vid_conwidth;
146 panel_size_y = bound(0.2, panel_size_y, 1) * vid_conheight;
147 panel_pos_x = (vid_conwidth - panel_size_x) / 2;
148 panel_pos_y = (vid_conheight - panel_size_y) / 2;
150 if(mouseClicked & S_MOUSE1)
153 if ( mousepos_x < panel_pos_x || mousepos_x > panel_pos_x + panel_size_x ||
154 mousepos_y < panel_pos_y || mousepos_y > panel_pos_y + panel_size_y )
156 HUD_Radar_Hide_Maximized();
159 vector pos = teamradar_texcoord_to_3dcoord(teamradar_2dcoord_to_texcoord(mousepos),view_origin_z);
160 localcmd(sprintf("cmd ons_spawn %f %f %f",pos_x,pos_y,pos_z));
162 HUD_Radar_Hide_Maximized();
167 draw_cursor_normal(mousepos, '1 1 1', 0.8);
172 if (!autocvar__hud_configure)
174 if (hud_panel_radar_maximized)
176 if (!hud_draw_maximized) return;
180 if (autocvar_hud_panel_radar == 0) return;
181 if (autocvar_hud_panel_radar != 2 && !teamplay) return;
182 if(radar_panel_modified)
184 panel.update_time = time; // forces reload of panel attributes
185 radar_panel_modified = false;
190 if ( hud_panel_radar_temp_hidden )
193 HUD_Panel_UpdateCvars();
197 if (hud_panel_radar_maximized && !autocvar__hud_configure)
199 panel_size = autocvar_hud_panel_radar_maximized_size;
200 panel_size.x = bound(0.2, panel_size.x, 1) * vid_conwidth;
201 panel_size.y = bound(0.2, panel_size.y, 1) * vid_conheight;
202 panel_pos.x = (vid_conwidth - panel_size.x) / 2;
203 panel_pos.y = (vid_conheight - panel_size.y) / 2;
206 panel_bg = strcat(hud_skin_path, "/border_default"); // always use the default border when maximized
207 if(precache_pic(panel_bg) == "")
208 panel_bg = "gfx/hud/default/border_default"; // fallback
209 if(!radar_panel_modified && panel_bg != panel.current_panel_bg)
210 radar_panel_modified = true;
211 if(panel.current_panel_bg)
212 strunzone(panel.current_panel_bg);
213 panel.current_panel_bg = strzone(panel_bg);
215 switch(hud_panel_radar_maximized_zoommode)
219 f = current_zoomfraction;
222 f = 1 - current_zoomfraction;
232 switch(hud_panel_radar_maximized_rotation)
235 teamradar_angle = view_angles.y - 90;
238 teamradar_angle = 90 * hud_panel_radar_maximized_rotation;
242 if (!hud_panel_radar_maximized && !autocvar__hud_configure)
244 switch(hud_panel_radar_zoommode)
248 f = current_zoomfraction;
251 f = 1 - current_zoomfraction;
261 switch(hud_panel_radar_rotation)
264 teamradar_angle = view_angles.y - 90;
267 teamradar_angle = 90 * hud_panel_radar_rotation;
279 pos += '1 1 0' * panel_bg_padding;
280 mySize -= '2 2 0' * panel_bg_padding;
284 float scale2d, normalsize, bigsize;
286 teamradar_origin2d = pos + 0.5 * mySize;
287 teamradar_size2d = mySize;
289 if(minimapname == "")
292 teamradar_loadcvars();
294 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
295 teamradar_size2d = mySize;
297 teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
299 // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
300 if((hud_panel_radar_rotation == 0 && !hud_panel_radar_maximized) || (hud_panel_radar_maximized_rotation == 0 && hud_panel_radar_maximized))
302 // max-min distance must fit the radar in any rotation
303 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen(vec2(mi_scale)));
307 vector c0, c1, c2, c3, span;
308 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
309 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
310 c2 = rotate('1 0 0' * mi_min.x + '0 1 0' * mi_max.y, teamradar_angle * DEG2RAD);
311 c3 = rotate('1 0 0' * mi_max.x + '0 1 0' * mi_min.y, teamradar_angle * DEG2RAD);
313 span.x = max(c0_x, c1_x, c2_x, c3_x) - min(c0_x, c1_x, c2_x, c3_x);
314 span.y = max(c0_y, c1_y, c2_y, c3_y) - min(c0_y, c1_y, c2_y, c3_y);
316 // max-min distance must fit the radar in x=x, y=y
318 teamradar_size2d.x * scale2d / (1.05 * span.x),
319 teamradar_size2d.y * scale2d / (1.05 * span.y)
323 normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_panel_radar_scale;
324 if(bigsize > normalsize)
325 normalsize = bigsize;
329 + (1 - f) * normalsize;
330 teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
332 + (1 - f) * view_origin);
341 draw_teamradar_background(hud_panel_radar_foreground_alpha);
343 FOREACH_ENTITY_CLASS("radarlink", true, draw_teamradar_link(it.origin, it.velocity, TMID(it.team)));
345 FOREACH_ENTITY_FLAGS(teamradar_icon, 0xFFFFFF, {
346 if ( hud_panel_radar_mouse )
348 if ( TMID(it.team) == myteam+1 || gametype == MAPINFO_TYPE_RACE )
350 vector coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(it.origin));
351 if(vdist((mousepos - coord), <, 8))
354 brightcolor_x = min(1,it.teamradar_color_x*1.5);
355 brightcolor_y = min(1,it.teamradar_color_y*1.5);
356 brightcolor_z = min(1,it.teamradar_color_z*1.5);
357 drawpic(coord - '8 8 0', "gfx/teamradar_icon_glow", '16 16 0', brightcolor, panel_fg_alpha, 0);
360 entity icon = RadarIcons_from(it.teamradar_icon);
361 draw_teamradar_icon(it.origin, icon, it, spritelookupcolor(it, icon.netname, it.teamradar_color), panel_fg_alpha);
363 AL_EACH(_entcs, e, it != NULL, {
364 if (!it.m_entcs_private) continue;
365 if (entcs_is_self(it)) continue;
366 color2 = entcs_GetTeam(it.sv_entnum);
367 draw_teamradar_player(it.origin, it.angles, Team_ColorRGB(color2));
369 draw_teamradar_player(view_origin, view_angles, '1 1 1');
373 if ( hud_panel_radar_mouse )
375 string message = "Click to select teleport destination";
377 if ( STAT(HEALTH) <= 0 )
379 message = "Click to select spawn location";
382 drawcolorcodedstring(pos + '0.5 0 0' * (mySize_x - stringwidth(message, true, hud_fontsize)) - '0 1 0' * hud_fontsize_y * 2,
383 message, hud_fontsize, hud_panel_radar_foreground_alpha, DRAWFLAG_NORMAL);
385 hud_panel_radar_bottom = pos_y + mySize_y + hud_fontsize_y;