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