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