]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/radar.qc
client: pass compilation units test
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / radar.qc
1 #include "radar.qh"
2
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>
8
9 // Radar (#6)
10
11 float HUD_Radar_Clickable()
12 {
13         return hud_panel_radar_mouse && !hud_panel_radar_temp_hidden;
14 }
15
16 void HUD_Radar_Show_Maximized(bool doshow,float clickable)
17 {
18         hud_panel_radar_maximized = doshow;
19         hud_panel_radar_temp_hidden = 0;
20
21         if ( doshow )
22         {
23                 if (clickable)
24                 {
25                         if(autocvar_hud_cursormode)
26                                 setcursormode(1);
27                         hud_panel_radar_mouse = 1;
28                 }
29         }
30         else if ( hud_panel_radar_mouse )
31         {
32                 hud_panel_radar_mouse = 0;
33                 mouseClicked = 0;
34                 if(autocvar_hud_cursormode)
35                 if(!mv_active)
36                         setcursormode(0);
37         }
38 }
39 void HUD_Radar_Hide_Maximized()
40 {
41         HUD_Radar_Show_Maximized(false,false);
42 }
43
44
45 float HUD_Radar_InputEvent(float bInputType, float nPrimary, float nSecondary)
46 {
47         if(!hud_panel_radar_maximized || !hud_panel_radar_mouse ||
48                 autocvar__hud_configure || mv_active)
49                 return false;
50
51         if(bInputType == 3)
52         {
53                 mousepos_x = nPrimary;
54                 mousepos_y = nSecondary;
55                 return true;
56         }
57
58         if(nPrimary == K_MOUSE1)
59         {
60                 if(bInputType == 0) // key pressed
61                         mouseClicked |= S_MOUSE1;
62                 else if(bInputType == 1) // key released
63                         mouseClicked -= (mouseClicked & S_MOUSE1);
64         }
65         else if(nPrimary == K_MOUSE2)
66         {
67                 if(bInputType == 0) // key pressed
68                         mouseClicked |= S_MOUSE2;
69                 else if(bInputType == 1) // key released
70                         mouseClicked -= (mouseClicked & S_MOUSE2);
71         }
72         else if ( nPrimary == K_ESCAPE && bInputType == 0 )
73         {
74                 HUD_Radar_Hide_Maximized();
75         }
76         else
77         {
78                 // allow console/use binds to work without hiding the map
79                 string con_keys;
80                 float keys;
81                 float i;
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)
85                 {
86                         if(nPrimary == stof(argv(i)))
87                                 return false;
88                 }
89
90                 if ( STAT(HEALTH) <= 0 )
91                 {
92                         // Show scoreboard
93                         if ( bInputType < 2 )
94                         {
95                                 con_keys = findkeysforcommand("+showscores", 0);
96                                 keys = tokenize(con_keys);
97                                 for (i = 0; i < keys; ++i)
98                                 {
99                                         if ( nPrimary == stof(argv(i)) )
100                                         {
101                                                 hud_panel_radar_temp_hidden = bInputType == 0;
102                                                 return false;
103                                         }
104                                 }
105                         }
106                 }
107                 else if ( bInputType == 0 )
108                         HUD_Radar_Hide_Maximized();
109
110                 return false;
111         }
112
113         return true;
114 }
115
116 void HUD_Radar_Mouse()
117 {
118         if ( !hud_panel_radar_mouse ) return;
119         if(mv_active) return;
120
121         if ( intermission )
122         {
123                 HUD_Radar_Hide_Maximized();
124                 return;
125         }
126
127         if(mouseClicked & S_MOUSE2)
128         {
129                 HUD_Radar_Hide_Maximized();
130                 return;
131         }
132
133         if(!autocvar_hud_cursormode)
134         {
135                 mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
136
137                 mousepos_x = bound(0, mousepos_x, vid_conwidth);
138                 mousepos_y = bound(0, mousepos_y, vid_conheight);
139         }
140
141         HUD_Panel_UpdateCvars();
142
143
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;
149
150         if(mouseClicked & S_MOUSE1)
151         {
152                 // click outside
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 )
155                 {
156                         HUD_Radar_Hide_Maximized();
157                         return;
158                 }
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));
161
162                 HUD_Radar_Hide_Maximized();
163                 return;
164         }
165
166
167         draw_cursor_normal(mousepos, '1 1 1', 0.8);
168 }
169
170 void HUD_Radar()
171 {
172         if (!autocvar__hud_configure)
173         {
174                 if (hud_panel_radar_maximized)
175                 {
176                         if (!hud_draw_maximized) return;
177                 }
178                 else
179                 {
180                         if (autocvar_hud_panel_radar == 0) return;
181                         if (autocvar_hud_panel_radar != 2 && !teamplay) return;
182                         if(radar_panel_modified)
183                         {
184                                 panel.update_time = time; // forces reload of panel attributes
185                                 radar_panel_modified = false;
186                         }
187                 }
188         }
189
190         if ( hud_panel_radar_temp_hidden )
191                 return;
192
193         HUD_Panel_UpdateCvars();
194
195         float f = 0;
196
197         if (hud_panel_radar_maximized && !autocvar__hud_configure)
198         {
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;
204
205                 string panel_bg;
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);
214
215                 switch(hud_panel_radar_maximized_zoommode)
216                 {
217                         default:
218                         case 0:
219                                 f = current_zoomfraction;
220                                 break;
221                         case 1:
222                                 f = 1 - current_zoomfraction;
223                                 break;
224                         case 2:
225                                 f = 0;
226                                 break;
227                         case 3:
228                                 f = 1;
229                                 break;
230                 }
231
232                 switch(hud_panel_radar_maximized_rotation)
233                 {
234                         case 0:
235                                 teamradar_angle = view_angles.y - 90;
236                                 break;
237                         default:
238                                 teamradar_angle = 90 * hud_panel_radar_maximized_rotation;
239                                 break;
240                 }
241         }
242         if (!hud_panel_radar_maximized && !autocvar__hud_configure)
243         {
244                 switch(hud_panel_radar_zoommode)
245                 {
246                         default:
247                         case 0:
248                                 f = current_zoomfraction;
249                                 break;
250                         case 1:
251                                 f = 1 - current_zoomfraction;
252                                 break;
253                         case 2:
254                                 f = 0;
255                                 break;
256                         case 3:
257                                 f = 1;
258                                 break;
259                 }
260
261                 switch(hud_panel_radar_rotation)
262                 {
263                         case 0:
264                                 teamradar_angle = view_angles.y - 90;
265                                 break;
266                         default:
267                                 teamradar_angle = 90 * hud_panel_radar_rotation;
268                                 break;
269                 }
270         }
271
272         vector pos, mySize;
273         pos = panel_pos;
274         mySize = panel_size;
275
276         HUD_Panel_DrawBg(1);
277         if(panel_bg_padding)
278         {
279                 pos += '1 1 0' * panel_bg_padding;
280                 mySize -= '2 2 0' * panel_bg_padding;
281         }
282
283         int color2;
284         float scale2d, normalsize, bigsize;
285
286         teamradar_origin2d = pos + 0.5 * mySize;
287         teamradar_size2d = mySize;
288
289         if(minimapname == "")
290                 return;
291
292         teamradar_loadcvars();
293
294         scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
295         teamradar_size2d = mySize;
296
297         teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
298
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))
301         {
302                 // max-min distance must fit the radar in any rotation
303                 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen(vec2(mi_scale)));
304         }
305         else
306         {
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);
312                 span = '0 0 0';
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);
315
316                 // max-min distance must fit the radar in x=x, y=y
317                 bigsize = min(
318                         teamradar_size2d.x * scale2d / (1.05 * span.x),
319                         teamradar_size2d.y * scale2d / (1.05 * span.y)
320                 );
321         }
322
323         normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_panel_radar_scale;
324         if(bigsize > normalsize)
325                 normalsize = bigsize;
326
327         teamradar_size =
328                   f * bigsize
329                 + (1 - f) * normalsize;
330         teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
331                   f * mi_center
332                 + (1 - f) * view_origin);
333
334         drawsetcliparea(
335                 pos.x,
336                 pos.y,
337                 mySize.x,
338                 mySize.y
339         );
340
341         draw_teamradar_background(hud_panel_radar_foreground_alpha);
342
343         FOREACH_ENTITY_CLASS("radarlink", true, draw_teamradar_link(it.origin, it.velocity, it.team));
344
345         FOREACH_ENTITY_FLAGS(teamradar_icon, 0xFFFFFF, {
346                 if ( hud_panel_radar_mouse )
347                 if ( it.health > 0 )
348                 if ( it.team == myteam+1 || gametype == MAPINFO_TYPE_RACE )
349                 {
350                         vector coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(it.origin));
351                         if(vdist((mousepos - coord), <, 8))
352                         {
353                                 vector brightcolor;
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);
358                         }
359                 }
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);
362         });
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));
368         });
369         draw_teamradar_player(view_origin, view_angles, '1 1 1');
370
371         drawresetcliparea();
372
373         if ( hud_panel_radar_mouse )
374         {
375                 string message = "Click to select teleport destination";
376
377                 if ( STAT(HEALTH) <= 0 )
378                 {
379                         message = "Click to select spawn location";
380                 }
381
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);
384
385                 hud_panel_radar_bottom = pos_y + mySize_y + hud_fontsize_y;
386         }
387 }