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)
19 hud_panel_radar_maximized = doshow;
20 hud_panel_radar_temp_hidden = 0;
26 if(autocvar_hud_cursormode)
28 hud_panel_radar_mouse = 1;
30 // we must unset the player's buttons, as they aren't released elsewhere
38 else if ( hud_panel_radar_mouse )
40 hud_panel_radar_mouse = 0;
42 if(autocvar_hud_cursormode)
47 void HUD_Radar_Hide_Maximized()
49 HUD_Radar_Show_Maximized(false,false);
53 float HUD_Radar_InputEvent(int bInputType, float nPrimary, float nSecondary)
56 if(!hud_panel_radar_maximized || !hud_panel_radar_mouse ||
57 autocvar__hud_configure || mv_active)
62 mousepos_x = nPrimary;
63 mousepos_y = nSecondary;
67 if(nPrimary == K_MOUSE1)
69 if(bInputType == 0) // key pressed
70 mouseClicked |= S_MOUSE1;
71 else if(bInputType == 1) // key released
72 mouseClicked -= (mouseClicked & S_MOUSE1);
74 else if(nPrimary == K_MOUSE2)
76 if(bInputType == 0) // key pressed
77 mouseClicked |= S_MOUSE2;
78 else if(bInputType == 1) // key released
79 mouseClicked -= (mouseClicked & S_MOUSE2);
81 else if ( nPrimary == K_ESCAPE && bInputType == 0 )
83 HUD_Radar_Hide_Maximized();
87 // allow console/use binds to work without hiding the map
88 string con_keys = strcat(findkeysforcommand("toggleconsole", 0), " ", findkeysforcommand("+use", 0)) ;
89 int keys = tokenize(con_keys); // findkeysforcommand returns data for this
91 for (i = 0; i < keys; ++i)
93 if(nPrimary == stof(argv(i)))
97 if ( STAT(HEALTH) <= 0 )
100 if ( bInputType < 2 )
102 con_keys = findkeysforcommand("+showscores", 0);
103 keys = tokenize(con_keys);
104 for (i = 0; i < keys; ++i)
106 if ( nPrimary == stof(argv(i)) )
108 hud_panel_radar_temp_hidden = bInputType == 0;
114 else if ( bInputType == 0 )
115 HUD_Radar_Hide_Maximized();
123 void HUD_Radar_Mouse()
125 if ( !hud_panel_radar_mouse ) return;
126 if(mv_active) return;
130 HUD_Radar_Hide_Maximized();
134 if(mouseClicked & S_MOUSE2)
136 HUD_Radar_Hide_Maximized();
140 if(!autocvar_hud_cursormode)
142 mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
144 mousepos_x = bound(0, mousepos_x, vid_conwidth);
145 mousepos_y = bound(0, mousepos_y, vid_conheight);
148 if(1 - scoreboard_fade_alpha <= 0)
150 HUD_Panel_UpdateCvars(1 - scoreboard_fade_alpha);
153 panel_size = autocvar_hud_panel_radar_maximized_size;
154 panel_size_x = bound(0.2, panel_size_x, 1) * vid_conwidth;
155 panel_size_y = bound(0.2, panel_size_y, 1) * vid_conheight;
156 panel_pos_x = (vid_conwidth - panel_size_x) / 2;
157 panel_pos_y = (vid_conheight - panel_size_y) / 2;
159 if(mouseClicked & S_MOUSE1)
162 if ( mousepos_x < panel_pos_x || mousepos_x > panel_pos_x + panel_size_x ||
163 mousepos_y < panel_pos_y || mousepos_y > panel_pos_y + panel_size_y )
165 HUD_Radar_Hide_Maximized();
168 vector pos = teamradar_texcoord_to_3dcoord(teamradar_2dcoord_to_texcoord(mousepos),view_origin_z);
169 localcmd(sprintf("cmd ons_spawn %f %f %f",pos_x,pos_y,pos_z));
171 HUD_Radar_Hide_Maximized();
176 draw_cursor_normal(mousepos, '1 1 1', 0.8);
181 if (!autocvar__hud_configure)
183 if (hud_panel_radar_maximized)
185 if (!hud_draw_maximized) return;
189 if (autocvar_hud_panel_radar == 0) return;
190 if (autocvar_hud_panel_radar != 2 && !teamplay) return;
191 if(radar_panel_modified)
193 panel.update_time = time; // forces reload of panel attributes
194 radar_panel_modified = false;
199 if ( hud_panel_radar_temp_hidden )
202 if(1 - scoreboard_fade_alpha <= 0)
204 HUD_Panel_UpdateCvars(1 - scoreboard_fade_alpha);
208 if (hud_panel_radar_maximized && !autocvar__hud_configure)
210 panel_size = autocvar_hud_panel_radar_maximized_size;
211 panel_size.x = bound(0.2, panel_size.x, 1) * vid_conwidth;
212 panel_size.y = bound(0.2, panel_size.y, 1) * vid_conheight;
213 panel_pos.x = (vid_conwidth - panel_size.x) / 2;
214 panel_pos.y = (vid_conheight - panel_size.y) / 2;
217 panel_bg = strcat(hud_skin_path, "/border_default"); // always use the default border when maximized
218 if(precache_pic(panel_bg) == "")
219 panel_bg = "gfx/hud/default/border_default"; // fallback
220 if(!radar_panel_modified && panel_bg != panel.current_panel_bg)
221 radar_panel_modified = true;
222 if(panel.current_panel_bg)
223 strunzone(panel.current_panel_bg);
224 panel.current_panel_bg = strzone(panel_bg);
226 switch(hud_panel_radar_maximized_zoommode)
230 f = current_zoomfraction;
233 f = 1 - current_zoomfraction;
243 switch(hud_panel_radar_maximized_rotation)
246 teamradar_angle = view_angles.y - 90;
249 teamradar_angle = 90 * hud_panel_radar_maximized_rotation;
253 if (!hud_panel_radar_maximized && !autocvar__hud_configure)
255 switch(hud_panel_radar_zoommode)
259 f = current_zoomfraction;
262 f = 1 - current_zoomfraction;
272 switch(hud_panel_radar_rotation)
275 teamradar_angle = view_angles.y - 90;
278 teamradar_angle = 90 * hud_panel_radar_rotation;
287 if (autocvar_hud_panel_radar_dynamichud)
294 pos += '1 1 0' * panel_bg_padding;
295 mySize -= '2 2 0' * panel_bg_padding;
299 float scale2d, normalsize, bigsize;
301 teamradar_origin2d = HUD_Shift(pos + 0.5 * mySize);
302 teamradar_size2d = mySize;
304 if(minimapname == "")
307 teamradar_loadcvars();
309 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
310 teamradar_size2d = HUD_Scale(mySize);
312 teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
314 // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
315 if((hud_panel_radar_rotation == 0 && !hud_panel_radar_maximized) || (hud_panel_radar_maximized_rotation == 0 && hud_panel_radar_maximized))
317 // max-min distance must fit the radar in any rotation
318 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen(vec2(mi_scale)));
322 vector c0, c1, c2, c3, span;
323 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
324 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
325 c2 = rotate('1 0 0' * mi_min.x + '0 1 0' * mi_max.y, teamradar_angle * DEG2RAD);
326 c3 = rotate('1 0 0' * mi_max.x + '0 1 0' * mi_min.y, teamradar_angle * DEG2RAD);
328 span.x = max(c0_x, c1_x, c2_x, c3_x) - min(c0_x, c1_x, c2_x, c3_x);
329 span.y = max(c0_y, c1_y, c2_y, c3_y) - min(c0_y, c1_y, c2_y, c3_y);
331 // max-min distance must fit the radar in x=x, y=y
333 teamradar_size2d.x * scale2d / (1.05 * span.x),
334 teamradar_size2d.y * scale2d / (1.05 * span.y)
338 normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_panel_radar_scale;
339 if(bigsize > normalsize)
340 normalsize = bigsize;
344 + (1 - f) * normalsize;
345 teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
347 + (1 - f) * view_origin);
356 draw_teamradar_background(hud_panel_radar_foreground_alpha);
358 IL_EACH(g_radarlinks, true, draw_teamradar_link(it.origin, it.velocity, it.team));
360 IL_EACH(g_radaricons, it.teamradar_icon, {
361 if ( hud_panel_radar_mouse )
362 if ( it.health >= 0 )
363 if ( it.team == myteam+1 || gametype == MAPINFO_TYPE_RACE || !(serverflags & SERVERFLAG_TEAMPLAY) )
365 vector coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(it.origin));
366 if(vdist((mousepos - coord), <, 8))
369 brightcolor_x = min(1,it.teamradar_color_x*1.5);
370 brightcolor_y = min(1,it.teamradar_color_y*1.5);
371 brightcolor_z = min(1,it.teamradar_color_z*1.5);
372 drawpic(coord - '8 8 0', "gfx/teamradar_icon_glow", '16 16 0', brightcolor, panel_fg_alpha, 0);
375 entity icon = RadarIcons_from(it.teamradar_icon);
376 draw_teamradar_icon(it.origin, icon, it, spritelookupcolor(it, icon.netname, it.teamradar_color), panel_fg_alpha);
378 AL_EACH(_entcs, e, it != NULL, {
379 if (!it.m_entcs_private) continue;
380 if (it.sv_entnum == current_player) continue;
381 color2 = entcs_GetTeam(it.sv_entnum);
382 draw_teamradar_player(it.origin, it.angles, Team_ColorRGB(color2));
384 draw_teamradar_player(entcs_receiver(current_player).origin, view_angles, '1 1 1');
388 if ( hud_panel_radar_mouse )
390 string message = "Click to select teleport destination";
392 if ( STAT(HEALTH) <= 0 )
394 message = "Click to select spawn location";
397 drawcolorcodedstring(pos + '0.5 0 0' * (mySize_x - stringwidth(message, true, hud_fontsize)) - '0 1 0' * hud_fontsize_y * 2,
398 message, hud_fontsize, hud_panel_radar_foreground_alpha, DRAWFLAG_NORMAL);
400 hud_panel_radar_bottom = pos_y + mySize_y + hud_fontsize_y;