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