]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/radar.qc
Header police
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / radar.qc
1 #include "radar.qh"
2 // Radar (#6)
3
4 float HUD_Radar_Clickable()
5 {
6         return hud_panel_radar_mouse && !hud_panel_radar_temp_hidden;
7 }
8
9 void HUD_Radar_Show_Maximized(bool doshow,float clickable)
10 {
11         hud_panel_radar_maximized = doshow;
12         hud_panel_radar_temp_hidden = 0;
13
14         if ( doshow )
15         {
16                 if (clickable)
17                 {
18                         if(autocvar_hud_cursormode)
19                                 setcursormode(1);
20                         hud_panel_radar_mouse = 1;
21                 }
22         }
23         else if ( hud_panel_radar_mouse )
24         {
25                 hud_panel_radar_mouse = 0;
26                 mouseClicked = 0;
27                 if(autocvar_hud_cursormode)
28                 if(!mv_active)
29                         setcursormode(0);
30         }
31 }
32 void HUD_Radar_Hide_Maximized()
33 {
34         HUD_Radar_Show_Maximized(false,false);
35 }
36
37
38 float HUD_Radar_InputEvent(float bInputType, float nPrimary, float nSecondary)
39 {
40         if(!hud_panel_radar_maximized || !hud_panel_radar_mouse ||
41                 autocvar__hud_configure || mv_active)
42                 return false;
43
44         if(bInputType == 3)
45         {
46                 mousepos_x = nPrimary;
47                 mousepos_y = nSecondary;
48                 return true;
49         }
50
51         if(nPrimary == K_MOUSE1)
52         {
53                 if(bInputType == 0) // key pressed
54                         mouseClicked |= S_MOUSE1;
55                 else if(bInputType == 1) // key released
56                         mouseClicked -= (mouseClicked & S_MOUSE1);
57         }
58         else if(nPrimary == K_MOUSE2)
59         {
60                 if(bInputType == 0) // key pressed
61                         mouseClicked |= S_MOUSE2;
62                 else if(bInputType == 1) // key released
63                         mouseClicked -= (mouseClicked & S_MOUSE2);
64         }
65         else if ( nPrimary == K_ESCAPE && bInputType == 0 )
66         {
67                 HUD_Radar_Hide_Maximized();
68         }
69         else
70         {
71                 // allow console/use binds to work without hiding the map
72                 string con_keys;
73                 float keys;
74                 float i;
75                 con_keys = strcat(findkeysforcommand("toggleconsole", 0)," ",findkeysforcommand("+use", 0)) ;
76                 keys = tokenize(con_keys); // findkeysforcommand returns data for this
77                 for (i = 0; i < keys; ++i)
78                 {
79                         if(nPrimary == stof(argv(i)))
80                                 return false;
81                 }
82
83                 if ( STAT(HEALTH) <= 0 )
84                 {
85                         // Show scoreboard
86                         if ( bInputType < 2 )
87                         {
88                                 con_keys = findkeysforcommand("+showscores", 0);
89                                 keys = tokenize(con_keys);
90                                 for (i = 0; i < keys; ++i)
91                                 {
92                                         if ( nPrimary == stof(argv(i)) )
93                                         {
94                                                 hud_panel_radar_temp_hidden = bInputType == 0;
95                                                 return false;
96                                         }
97                                 }
98                         }
99                 }
100                 else if ( bInputType == 0 )
101                         HUD_Radar_Hide_Maximized();
102
103                 return false;
104         }
105
106         return true;
107 }
108
109 void HUD_Radar_Mouse()
110 {
111         if ( !hud_panel_radar_mouse ) return;
112         if(mv_active) return;
113
114         if ( intermission )
115         {
116                 HUD_Radar_Hide_Maximized();
117                 return;
118         }
119
120         if(mouseClicked & S_MOUSE2)
121         {
122                 HUD_Radar_Hide_Maximized();
123                 return;
124         }
125
126         if(!autocvar_hud_cursormode)
127         {
128                 mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
129
130                 mousepos_x = bound(0, mousepos_x, vid_conwidth);
131                 mousepos_y = bound(0, mousepos_y, vid_conheight);
132         }
133
134         HUD_Panel_UpdateCvars();
135
136
137         panel_size = autocvar_hud_panel_radar_maximized_size;
138         panel_size_x = bound(0.2, panel_size_x, 1) * vid_conwidth;
139         panel_size_y = bound(0.2, panel_size_y, 1) * vid_conheight;
140         panel_pos_x = (vid_conwidth - panel_size_x) / 2;
141         panel_pos_y = (vid_conheight - panel_size_y) / 2;
142
143         if(mouseClicked & S_MOUSE1)
144         {
145                 // click outside
146                 if ( mousepos_x < panel_pos_x || mousepos_x > panel_pos_x + panel_size_x ||
147                          mousepos_y < panel_pos_y || mousepos_y > panel_pos_y + panel_size_y )
148                 {
149                         HUD_Radar_Hide_Maximized();
150                         return;
151                 }
152                 vector pos = teamradar_texcoord_to_3dcoord(teamradar_2dcoord_to_texcoord(mousepos),view_origin_z);
153                 localcmd(sprintf("cmd ons_spawn %f %f %f",pos_x,pos_y,pos_z));
154
155                 HUD_Radar_Hide_Maximized();
156                 return;
157         }
158
159
160         draw_cursor_normal(mousepos, '1 1 1', 0.8);
161 }
162
163 void HUD_Radar()
164 {
165         if (!autocvar__hud_configure)
166         {
167                 if (hud_panel_radar_maximized)
168                 {
169                         if (!hud_draw_maximized) return;
170                 }
171                 else
172                 {
173                         if (autocvar_hud_panel_radar == 0) return;
174                         if (autocvar_hud_panel_radar != 2 && !teamplay) return;
175                         if(radar_panel_modified)
176                         {
177                                 panel.update_time = time; // forces reload of panel attributes
178                                 radar_panel_modified = false;
179                         }
180                 }
181         }
182
183         if ( hud_panel_radar_temp_hidden )
184                 return;
185
186         HUD_Panel_UpdateCvars();
187
188         float f = 0;
189
190         if (hud_panel_radar_maximized && !autocvar__hud_configure)
191         {
192                 panel_size = autocvar_hud_panel_radar_maximized_size;
193                 panel_size.x = bound(0.2, panel_size.x, 1) * vid_conwidth;
194                 panel_size.y = bound(0.2, panel_size.y, 1) * vid_conheight;
195                 panel_pos.x = (vid_conwidth - panel_size.x) / 2;
196                 panel_pos.y = (vid_conheight - panel_size.y) / 2;
197
198                 string panel_bg;
199                 panel_bg = strcat(hud_skin_path, "/border_default"); // always use the default border when maximized
200                 if(precache_pic(panel_bg) == "")
201                         panel_bg = "gfx/hud/default/border_default"; // fallback
202                 if(!radar_panel_modified && panel_bg != panel.current_panel_bg)
203                         radar_panel_modified = true;
204                 if(panel.current_panel_bg)
205                         strunzone(panel.current_panel_bg);
206                 panel.current_panel_bg = strzone(panel_bg);
207
208                 switch(hud_panel_radar_maximized_zoommode)
209                 {
210                         default:
211                         case 0:
212                                 f = current_zoomfraction;
213                                 break;
214                         case 1:
215                                 f = 1 - current_zoomfraction;
216                                 break;
217                         case 2:
218                                 f = 0;
219                                 break;
220                         case 3:
221                                 f = 1;
222                                 break;
223                 }
224
225                 switch(hud_panel_radar_maximized_rotation)
226                 {
227                         case 0:
228                                 teamradar_angle = view_angles.y - 90;
229                                 break;
230                         default:
231                                 teamradar_angle = 90 * hud_panel_radar_maximized_rotation;
232                                 break;
233                 }
234         }
235         if (!hud_panel_radar_maximized && !autocvar__hud_configure)
236         {
237                 switch(hud_panel_radar_zoommode)
238                 {
239                         default:
240                         case 0:
241                                 f = current_zoomfraction;
242                                 break;
243                         case 1:
244                                 f = 1 - current_zoomfraction;
245                                 break;
246                         case 2:
247                                 f = 0;
248                                 break;
249                         case 3:
250                                 f = 1;
251                                 break;
252                 }
253
254                 switch(hud_panel_radar_rotation)
255                 {
256                         case 0:
257                                 teamradar_angle = view_angles.y - 90;
258                                 break;
259                         default:
260                                 teamradar_angle = 90 * hud_panel_radar_rotation;
261                                 break;
262                 }
263         }
264
265         vector pos, mySize;
266         pos = panel_pos;
267         mySize = panel_size;
268
269         HUD_Panel_DrawBg(1);
270         if(panel_bg_padding)
271         {
272                 pos += '1 1 0' * panel_bg_padding;
273                 mySize -= '2 2 0' * panel_bg_padding;
274         }
275
276         int color2;
277         float scale2d, normalsize, bigsize;
278
279         teamradar_origin2d = pos + 0.5 * mySize;
280         teamradar_size2d = mySize;
281
282         if(minimapname == "")
283                 return;
284
285         teamradar_loadcvars();
286
287         scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
288         teamradar_size2d = mySize;
289
290         teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
291
292         // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
293         if((hud_panel_radar_rotation == 0 && !hud_panel_radar_maximized) || (hud_panel_radar_maximized_rotation == 0 && hud_panel_radar_maximized))
294         {
295                 // max-min distance must fit the radar in any rotation
296                 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen(vec2(mi_scale)));
297         }
298         else
299         {
300                 vector c0, c1, c2, c3, span;
301                 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
302                 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
303                 c2 = rotate('1 0 0' * mi_min.x + '0 1 0' * mi_max.y, teamradar_angle * DEG2RAD);
304                 c3 = rotate('1 0 0' * mi_max.x + '0 1 0' * mi_min.y, teamradar_angle * DEG2RAD);
305                 span = '0 0 0';
306                 span.x = max(c0_x, c1_x, c2_x, c3_x) - min(c0_x, c1_x, c2_x, c3_x);
307                 span.y = max(c0_y, c1_y, c2_y, c3_y) - min(c0_y, c1_y, c2_y, c3_y);
308
309                 // max-min distance must fit the radar in x=x, y=y
310                 bigsize = min(
311                         teamradar_size2d.x * scale2d / (1.05 * span.x),
312                         teamradar_size2d.y * scale2d / (1.05 * span.y)
313                 );
314         }
315
316         normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_panel_radar_scale;
317         if(bigsize > normalsize)
318                 normalsize = bigsize;
319
320         teamradar_size =
321                   f * bigsize
322                 + (1 - f) * normalsize;
323         teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
324                   f * mi_center
325                 + (1 - f) * view_origin);
326
327         drawsetcliparea(
328                 pos.x,
329                 pos.y,
330                 mySize.x,
331                 mySize.y
332         );
333
334         draw_teamradar_background(hud_panel_radar_foreground_alpha);
335
336         FOREACH_ENTITY_CLASS("radarlink", true, draw_teamradar_link(it.origin, it.velocity, it.team));
337
338         FOREACH_ENTITY_FLAGS(teamradar_icon, 0xFFFFFF, {
339                 if ( hud_panel_radar_mouse )
340                 if ( it.health > 0 )
341                 if ( it.team == myteam+1 || gametype == MAPINFO_TYPE_RACE )
342                 {
343                         vector coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(it.origin));
344                         if(vdist((mousepos - coord), <, 8))
345                         {
346                                 vector brightcolor;
347                                 brightcolor_x = min(1,it.teamradar_color_x*1.5);
348                                 brightcolor_y = min(1,it.teamradar_color_y*1.5);
349                                 brightcolor_z = min(1,it.teamradar_color_z*1.5);
350                                 drawpic(coord - '8 8 0', "gfx/teamradar_icon_glow", '16 16 0', brightcolor, panel_fg_alpha, 0);
351                         }
352                 }
353                 entity icon = RadarIcons_from(it.teamradar_icon);
354                 draw_teamradar_icon(it.origin, icon, it, spritelookupcolor(it, icon.netname, it.teamradar_color), panel_fg_alpha);
355         });
356         AL_EACH(_entcs, e, it != NULL, {
357                 if (!it.m_entcs_private) continue;
358                 if (entcs_is_self(it)) continue;
359                 color2 = entcs_GetTeam(it.sv_entnum);
360                 draw_teamradar_player(it.origin, it.angles, Team_ColorRGB(color2));
361         });
362         draw_teamradar_player(view_origin, view_angles, '1 1 1');
363
364         drawresetcliparea();
365
366         if ( hud_panel_radar_mouse )
367         {
368                 string message = "Click to select teleport destination";
369
370                 if ( STAT(HEALTH) <= 0 )
371                 {
372                         message = "Click to select spawn location";
373                 }
374
375                 drawcolorcodedstring(pos + '0.5 0 0' * (mySize_x - stringwidth(message, true, hud_fontsize)) - '0 1 0' * hud_fontsize_y * 2,
376                                                          message, hud_fontsize, hud_panel_radar_foreground_alpha, DRAWFLAG_NORMAL);
377
378                 hud_panel_radar_bottom = pos_y + mySize_y + hud_fontsize_y;
379         }
380 }