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