1 #define HUD_Write(s) fputs(fh, s)
2 // q: quoted, n: not quoted
3 #define HUD_Write_Cvar_n(cvar) HUD_Write(strcat("seta ", cvar, " ", cvar_string(cvar), "\n"))
4 #define HUD_Write_Cvar_q(cvar) HUD_Write(strcat("seta ", cvar, " \"", cvar_string(cvar), "\"\n"))
5 #define HUD_Write_PanelCvar_n(cvar_suf) HUD_Write_Cvar_n(strcat("hud_panel_", panel_name, cvar_suf))
6 #define HUD_Write_PanelCvar_q(cvar_suf) HUD_Write_Cvar_q(strcat("hud_panel_", panel_name, cvar_suf))
8 void HUD_Panel_ExportCfg(string cfgname)
11 string filename = strcat("hud_", autocvar_hud_skin, "_", cfgname, ".cfg");
12 fh = fopen(filename, FILE_WRITE);
15 HUD_Write_Cvar_q("hud_skin");
16 HUD_Write_Cvar_q("hud_panel_bg");
17 HUD_Write_Cvar_q("hud_panel_bg_color");
18 HUD_Write_Cvar_q("hud_panel_bg_color_team");
19 HUD_Write_Cvar_q("hud_panel_bg_alpha");
20 HUD_Write_Cvar_q("hud_panel_bg_border");
21 HUD_Write_Cvar_q("hud_panel_bg_padding");
22 HUD_Write_Cvar_q("hud_panel_fg_alpha");
25 HUD_Write_Cvar_q("hud_dock");
26 HUD_Write_Cvar_q("hud_dock_color");
27 HUD_Write_Cvar_q("hud_dock_color_team");
28 HUD_Write_Cvar_q("hud_dock_alpha");
31 HUD_Write_Cvar_q("hud_progressbar_alpha");
32 HUD_Write_Cvar_q("hud_progressbar_strength_color");
33 HUD_Write_Cvar_q("hud_progressbar_shield_color");
34 HUD_Write_Cvar_q("hud_progressbar_health_color");
35 HUD_Write_Cvar_q("hud_progressbar_armor_color");
36 HUD_Write_Cvar_q("hud_progressbar_fuel_color");
37 HUD_Write_Cvar_q("hud_progressbar_nexball_color");
40 HUD_Write_Cvar_q("_hud_panelorder");
43 HUD_Write_Cvar_q("hud_configure_grid");
44 HUD_Write_Cvar_q("hud_configure_grid_xsize");
45 HUD_Write_Cvar_q("hud_configure_grid_ysize");
48 // common cvars for all panels
50 for (i = 0; i < HUD_PANEL_NUM; ++i)
54 HUD_Write_PanelCvar_n("");
55 HUD_Write_PanelCvar_q("_pos");
56 HUD_Write_PanelCvar_q("_size");
57 HUD_Write_PanelCvar_q("_bg");
58 HUD_Write_PanelCvar_q("_bg_color");
59 HUD_Write_PanelCvar_q("_bg_color_team");
60 HUD_Write_PanelCvar_q("_bg_alpha");
61 HUD_Write_PanelCvar_q("_bg_border");
62 HUD_Write_PanelCvar_q("_bg_padding");
64 case HUD_PANEL_WEAPONS:
65 HUD_Write_PanelCvar_q("_accuracy");
66 HUD_Write_PanelCvar_q("_label");
67 HUD_Write_PanelCvar_q("_complainbubble");
68 HUD_Write_PanelCvar_q("_complainbubble_padding");
69 HUD_Write_PanelCvar_q("_complainbubble_time");
70 HUD_Write_PanelCvar_q("_complainbubble_fadetime");
71 HUD_Write_PanelCvar_q("_complainbubble_color_outofammo");
72 HUD_Write_PanelCvar_q("_complainbubble_color_donthave");
73 HUD_Write_PanelCvar_q("_complainbubble_color_unavailable");
74 HUD_Write_PanelCvar_q("_ammo");
75 HUD_Write_PanelCvar_q("_ammo_color");
76 HUD_Write_PanelCvar_q("_ammo_alpha");
77 HUD_Write_PanelCvar_q("_aspect");
78 HUD_Write_PanelCvar_q("_timeout");
79 HUD_Write_PanelCvar_q("_timeout_effect");
80 HUD_Write_PanelCvar_q("_onlyowned");
83 HUD_Write_PanelCvar_q("_onlycurrent");
84 HUD_Write_PanelCvar_q("_iconalign");
85 HUD_Write_PanelCvar_q("_progressbar");
86 HUD_Write_PanelCvar_q("_progressbar_name");
87 HUD_Write_PanelCvar_q("_progressbar_xoffset");
88 HUD_Write_PanelCvar_q("_text");
90 case HUD_PANEL_POWERUPS:
91 HUD_Write_PanelCvar_q("_flip");
92 HUD_Write_PanelCvar_q("_iconalign");
93 HUD_Write_PanelCvar_q("_baralign");
94 HUD_Write_PanelCvar_q("_progressbar");
95 HUD_Write_PanelCvar_q("_progressbar_strength");
96 HUD_Write_PanelCvar_q("_progressbar_shield");
98 case HUD_PANEL_HEALTHARMOR:
99 HUD_Write_PanelCvar_q("_flip");
100 HUD_Write_PanelCvar_q("_iconalign");
101 HUD_Write_PanelCvar_q("_baralign");
102 HUD_Write_PanelCvar_q("_progressbar");
103 HUD_Write_PanelCvar_q("_progressbar_health");
104 HUD_Write_PanelCvar_q("_progressbar_armor");
105 HUD_Write_PanelCvar_q("_progressbar_gfx");
106 HUD_Write_PanelCvar_q("_progressbar_gfx_smooth");
107 HUD_Write_PanelCvar_q("_text");
109 case HUD_PANEL_NOTIFY:
110 HUD_Write_PanelCvar_q("_flip");
111 HUD_Write_PanelCvar_q("_fontsize");
112 HUD_Write_PanelCvar_q("_print");
113 HUD_Write_PanelCvar_q("_time");
114 HUD_Write_PanelCvar_q("_fadetime");
116 case HUD_PANEL_TIMER:
117 HUD_Write_PanelCvar_q("_increment");
119 case HUD_PANEL_RADAR:
120 HUD_Write_PanelCvar_q("_foreground_alpha");
121 HUD_Write_PanelCvar_q("_rotation");
122 HUD_Write_PanelCvar_q("_zoommode");
123 HUD_Write_PanelCvar_q("_scale");
124 HUD_Write_PanelCvar_q("_maximized_scale");
125 HUD_Write_PanelCvar_q("_maximized_size");
127 case HUD_PANEL_SCORE:
128 HUD_Write_PanelCvar_q("_rankings");
131 HUD_Write_PanelCvar_q("_alreadyvoted_alpha");
133 case HUD_PANEL_MODICONS:
134 HUD_Write_PanelCvar_q("_dom_layout");
136 case HUD_PANEL_PRESSEDKEYS:
137 HUD_Write_PanelCvar_q("_aspect");
139 case HUD_PANEL_ENGINEINFO:
140 HUD_Write_PanelCvar_q("_framecounter_time");
141 HUD_Write_PanelCvar_q("_framecounter_decimals");
143 case HUD_PANEL_INFOMESSAGES:
144 HUD_Write_PanelCvar_q("_flip");
146 case HUD_PANEL_PHYSICS:
147 HUD_Write_PanelCvar_q("_speed_unit");
148 HUD_Write_PanelCvar_q("_speed_unit_show");
149 HUD_Write_PanelCvar_q("_speed_max");
150 HUD_Write_PanelCvar_q("_speed_vertical");
151 HUD_Write_PanelCvar_q("_topspeed");
152 HUD_Write_PanelCvar_q("_topspeed_time");
153 HUD_Write_PanelCvar_q("_acceleration_max");
154 HUD_Write_PanelCvar_q("_acceleration_vertical");
155 HUD_Write_PanelCvar_q("_flip");
156 HUD_Write_PanelCvar_q("_baralign");
157 HUD_Write_PanelCvar_q("_progressbar");
158 HUD_Write_PanelCvar_q("_acceleration_mode");
160 case HUD_PANEL_CENTERPRINT:
161 HUD_Write_PanelCvar_q("_align");
162 HUD_Write_PanelCvar_q("_flip");
163 HUD_Write_PanelCvar_q("_fontscale");
164 HUD_Write_PanelCvar_q("_time");
165 HUD_Write_PanelCvar_q("_fade_in");
166 HUD_Write_PanelCvar_q("_fade_out");
167 HUD_Write_PanelCvar_q("_fade_subsequent");
168 HUD_Write_PanelCvar_q("_fade_subsequent_passone");
169 HUD_Write_PanelCvar_q("_fade_subsequent_passone_minalpha");
170 HUD_Write_PanelCvar_q("_fade_subsequent_passtwo");
171 HUD_Write_PanelCvar_q("_fade_subsequent_passtwo_minalpha");
172 HUD_Write_PanelCvar_q("_fade_subsequent_minfontsize");
173 HUD_Write_PanelCvar_q("_fade_minfontsize");
178 HUD_Write("menu_sync\n"); // force the menu to reread the cvars, so that the dialogs are updated
180 print(sprintf(_("^2Successfully exported to %s! (Note: It's saved in data/data/)\n"), filename));
184 print(sprintf(_("^1Couldn't write to %s\n"), filename));
187 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
188 vector HUD_Panel_CheckMove(vector myPos, vector mySize)
191 float myCenter_x, myCenter_y, targCenter_x, targCenter_y;
195 for (i = 0; i < HUD_PANEL_NUM; ++i) {
196 if(i == highlightedPanel || !panel_enabled)
199 HUD_Panel_UpdatePosSizeForId(i);
201 panel_pos -= '1 1 0' * panel_bg_border;
202 panel_size += '2 2 0' * panel_bg_border;
204 if(myPos_y + mySize_y < panel_pos_y)
206 if(myPos_y > panel_pos_y + panel_size_y)
209 if(myPos_x + mySize_x < panel_pos_x)
211 if(myPos_x > panel_pos_x + panel_size_x)
214 // OK, there IS a collision.
216 myCenter_x = myPos_x + 0.5 * mySize_x;
217 myCenter_y = myPos_y + 0.5 * mySize_y;
219 targCenter_x = panel_pos_x + 0.5 * panel_size_x;
220 targCenter_y = panel_pos_y + 0.5 * panel_size_y;
222 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
224 if(myPos_x + mySize_x - panel_pos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
225 myTarget_x = panel_pos_x - mySize_x;
226 else // push it upwards
227 myTarget_y = panel_pos_y - mySize_y;
229 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
231 if(panel_pos_x + panel_size_x - myPos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
232 myTarget_x = panel_pos_x + panel_size_x;
233 else // push it upwards
234 myTarget_y = panel_pos_y - mySize_y;
236 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
238 if(myPos_x + mySize_x - panel_pos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
239 myTarget_x = panel_pos_x - mySize_x;
240 else // push it downwards
241 myTarget_y = panel_pos_y + panel_size_y;
243 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
245 if(panel_pos_x + panel_size_x - myPos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
246 myTarget_x = panel_pos_x + panel_size_x;
247 else // push it downwards
248 myTarget_y = panel_pos_y + panel_size_y;
250 //if(cvar("hud_configure_checkcollisions_debug"))
251 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
257 void HUD_Panel_SetPos(vector pos)
259 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
263 //if(cvar("hud_configure_checkcollisions_debug"))
264 //drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
266 if(autocvar_hud_configure_grid)
268 pos_x = floor((pos_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
269 pos_y = floor((pos_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
272 if(hud_configure_checkcollisions)
273 pos = HUD_Panel_CheckMove(pos, mySize);
275 pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
276 pos_y = bound(0, pos_y, vid_conheight - mySize_y);
279 s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
281 HUD_Panel_GetName(highlightedPanel);
282 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
285 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
286 vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
291 float dist_x, dist_y;
293 ratio = mySize_x/mySize_y;
295 for (i = 0; i < HUD_PANEL_NUM; ++i) {
296 if(i == highlightedPanel || !panel_enabled)
299 HUD_Panel_UpdatePosSizeForId(i);
301 panel_pos -= '1 1 0' * panel_bg_border;
302 panel_size += '2 2 0' * panel_bg_border;
304 targEndPos = panel_pos + panel_size;
306 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
307 if(resizeorigin_x > panel_pos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > panel_pos_y && resizeorigin_y < targEndPos_y)
310 if (resizeCorner == 1)
312 // check if this panel is on our way
313 if (resizeorigin_x <= panel_pos_x)
315 if (resizeorigin_y <= panel_pos_y)
317 if (targEndPos_x <= resizeorigin_x - mySize_x)
319 if (targEndPos_y <= resizeorigin_y - mySize_y)
322 // there is a collision:
323 // detect which side of the panel we are facing is actually limiting the resizing
324 // (which side the resize direction finds for first) and reduce the size up to there
326 // dist is the distance between resizeorigin and the "analogous" point of the panel
327 // in this case between resizeorigin (bottom-right point) and the bottom-right point of the panel
328 dist_x = resizeorigin_x - targEndPos_x;
329 dist_y = resizeorigin_y - targEndPos_y;
330 if (dist_y <= 0 || dist_x / dist_y > ratio)
331 mySize_x = min(mySize_x, dist_x);
333 mySize_y = min(mySize_y, dist_y);
335 else if (resizeCorner == 2)
337 if (resizeorigin_x >= targEndPos_x)
339 if (resizeorigin_y <= panel_pos_y)
341 if (panel_pos_x >= resizeorigin_x + mySize_x)
343 if (targEndPos_y <= resizeorigin_y - mySize_y)
346 dist_x = panel_pos_x - resizeorigin_x;
347 dist_y = resizeorigin_y - targEndPos_y;
348 if (dist_y <= 0 || dist_x / dist_y > ratio)
349 mySize_x = min(mySize_x, dist_x);
351 mySize_y = min(mySize_y, dist_y);
353 else if (resizeCorner == 3)
355 if (resizeorigin_x <= panel_pos_x)
357 if (resizeorigin_y >= targEndPos_y)
359 if (targEndPos_x <= resizeorigin_x - mySize_x)
361 if (panel_pos_y >= resizeorigin_y + mySize_y)
364 dist_x = resizeorigin_x - targEndPos_x;
365 dist_y = panel_pos_y - resizeorigin_y;
366 if (dist_y <= 0 || dist_x / dist_y > ratio)
367 mySize_x = min(mySize_x, dist_x);
369 mySize_y = min(mySize_y, dist_y);
371 else if (resizeCorner == 4)
373 if (resizeorigin_x >= targEndPos_x)
375 if (resizeorigin_y >= targEndPos_y)
377 if (panel_pos_x >= resizeorigin_x + mySize_x)
379 if (panel_pos_y >= resizeorigin_y + mySize_y)
382 dist_x = panel_pos_x - resizeorigin_x;
383 dist_y = panel_pos_y - resizeorigin_y;
384 if (dist_y <= 0 || dist_x / dist_y > ratio)
385 mySize_x = min(mySize_x, dist_x);
387 mySize_y = min(mySize_y, dist_y);
389 //if(cvar("hud_configure_checkcollisions_debug"))
390 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
396 void HUD_Panel_SetPosSize(vector mySize)
398 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
400 resizeorigin = panel_click_resizeorigin;
403 // minimum panel size cap
404 mySize_x = max(0.025 * vid_conwidth, mySize_x);
405 mySize_y = max(0.025 * vid_conheight, mySize_y);
407 if(highlightedPanel == HUD_PANEL_CHAT) // some panels have their own restrictions, like the chat panel (which actually only moves the engine chat print around). Looks bad if it's too small.
409 mySize_x = max(17 * autocvar_con_chatsize, mySize_x);
410 mySize_y = max(2 * autocvar_con_chatsize + 2 * panel_bg_padding, mySize_y);
413 // collision testing|
414 // -----------------+
416 // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
417 if(resizeCorner == 1) {
418 myPos_x = resizeorigin_x - mySize_x;
419 myPos_y = resizeorigin_y - mySize_y;
420 } else if(resizeCorner == 2) {
421 myPos_x = resizeorigin_x;
422 myPos_y = resizeorigin_y - mySize_y;
423 } else if(resizeCorner == 3) {
424 myPos_x = resizeorigin_x - mySize_x;
425 myPos_y = resizeorigin_y;
426 } else { // resizeCorner == 4
427 myPos_x = resizeorigin_x;
428 myPos_y = resizeorigin_y;
431 // left/top screen edges
433 mySize_x = mySize_x + myPos_x;
435 mySize_y = mySize_y + myPos_y;
437 // bottom/right screen edges
438 if(myPos_x + mySize_x > vid_conwidth)
439 mySize_x = vid_conwidth - myPos_x;
440 if(myPos_y + mySize_y > vid_conheight)
441 mySize_y = vid_conheight - myPos_y;
443 //if(cvar("hud_configure_checkcollisions_debug"))
444 //drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
446 // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
447 if(autocvar_hud_configure_grid)
449 mySize_x = floor((mySize_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
450 mySize_y = floor((mySize_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
453 if(hud_configure_checkcollisions)
454 mySize = HUD_Panel_CheckResize(mySize, resizeorigin);
456 // minimum panel size cap, do this once more so we NEVER EVER EVER have a panel smaller than this, JUST IN CASE above code still makes the panel eg negative (impossible to resize back without changing cvars manually then)
457 mySize_x = max(0.025 * vid_conwidth, mySize_x);
458 mySize_y = max(0.025 * vid_conheight, mySize_y);
460 // do another pos check, as size might have changed by now
461 if(resizeCorner == 1) {
462 myPos_x = resizeorigin_x - mySize_x;
463 myPos_y = resizeorigin_y - mySize_y;
464 } else if(resizeCorner == 2) {
465 myPos_x = resizeorigin_x;
466 myPos_y = resizeorigin_y - mySize_y;
467 } else if(resizeCorner == 3) {
468 myPos_x = resizeorigin_x - mySize_x;
469 myPos_y = resizeorigin_y;
470 } else { // resizeCorner == 4
471 myPos_x = resizeorigin_x;
472 myPos_y = resizeorigin_y;
475 //if(cvar("hud_configure_checkcollisions_debug"))
476 //drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
478 HUD_Panel_GetName(highlightedPanel);
480 s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
481 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
483 s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
484 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
487 float pressed_key_time;
488 vector highlightedPanel_initial_pos, highlightedPanel_initial_size;
489 void HUD_Panel_Arrow_Action(float nPrimary)
491 if (highlightedPanel == -1)
494 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
497 if(autocvar_hud_configure_grid)
499 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
501 if (hudShiftState & S_SHIFT)
502 step = hud_configure_realGridSize_y;
504 step = 2 * hud_configure_realGridSize_y;
508 if (hudShiftState & S_SHIFT)
509 step = hud_configure_realGridSize_x;
511 step = 2 * hud_configure_realGridSize_x;
516 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
517 step = vid_conheight;
520 if (hudShiftState & S_SHIFT)
521 step = (step / 256); // more precision
523 step = (step / 64) * (1 + 2 * (time - pressed_key_time));
526 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
528 highlightedPanel_initial_pos = panel_pos;
529 highlightedPanel_initial_size = panel_size;
531 if (hudShiftState & S_ALT) // resize
533 highlightedAction = 1;
534 if(nPrimary == K_UPARROW)
536 else if(nPrimary == K_RIGHTARROW)
538 else if(nPrimary == K_LEFTARROW)
540 else // if(nPrimary == K_DOWNARROW)
543 // ctrl+arrow reduces the size, instead of increasing it
544 // Note that ctrl disables collisions check too, but it's fine
545 // since we don't collide with anything reducing the size
546 if (hudShiftState & S_CTRL) {
548 resizeCorner = 5 - resizeCorner;
553 panel_click_resizeorigin = panel_pos;
554 if(resizeCorner == 1) {
555 panel_click_resizeorigin += mySize;
557 } else if(resizeCorner == 2) {
558 panel_click_resizeorigin_y += mySize_y;
560 } else if(resizeCorner == 3) {
561 panel_click_resizeorigin_x += mySize_x;
563 } else { // resizeCorner == 4
566 HUD_Panel_SetPosSize(mySize);
570 highlightedAction = 2;
573 if(nPrimary == K_UPARROW)
575 else if(nPrimary == K_DOWNARROW)
577 else if(nPrimary == K_LEFTARROW)
579 else // if(nPrimary == K_RIGHTARROW)
582 HUD_Panel_SetPos(pos);
585 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
587 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
590 panel_pos_backup = highlightedPanel_initial_pos;
591 panel_size_backup = highlightedPanel_initial_size;
592 highlightedPanel_backup = highlightedPanel;
596 const float S_MOUSE1 = 1;
597 const float S_MOUSE2 = 2;
598 const float S_MOUSE3 = 4;
600 float prevMouseClicked; // previous state
601 float prevMouseClickedTime; // time during previous left mouse click, to check for doubleclicks
602 vector prevMouseClickedPos; // pos during previous left mouse click, to check for doubleclicks
604 void HUD_Panel_EnableMenu();
605 float tab_panels[HUD_PANEL_NUM];
606 float tab_panel, tab_backward;
607 vector tab_panel_pos;
608 void HUD_Panel_FirstInDrawQ(float id);
609 void reset_tab_panels()
612 for(i = 0; i < HUD_PANEL_NUM; ++i)
615 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
619 // we only care for keyboard events
620 if(bInputType != 0 && bInputType != 1)
623 if(!autocvar__hud_configure)
626 // allow console bind to work
629 con_keys = findkeysforcommand("toggleconsole");
630 keys = tokenize(con_keys); // findkeysforcommand returns data for this
632 float hit_con_bind, i;
633 for (i = 0; i < keys; ++i)
635 if(nPrimary == stof(argv(i)))
639 if(bInputType == 0) {
640 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
641 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
642 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
644 else if(bInputType == 1) {
645 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
646 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
647 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
650 if(nPrimary == K_CTRL)
652 if (bInputType == 1) //ctrl has been released
656 //switch to selected panel
657 highlightedPanel = tab_panel;
658 highlightedAction = 0;
659 HUD_Panel_FirstInDrawQ(highlightedPanel);
666 if(nPrimary == K_MOUSE1)
668 if(bInputType == 0) // key pressed
669 mouseClicked |= S_MOUSE1;
670 else if(bInputType == 1) // key released
671 mouseClicked -= (mouseClicked & S_MOUSE1);
673 else if(nPrimary == K_MOUSE2)
675 if(bInputType == 0) // key pressed
676 mouseClicked |= S_MOUSE2;
677 else if(bInputType == 1) // key released
678 mouseClicked -= (mouseClicked & S_MOUSE2);
680 else if(nPrimary == K_ESCAPE)
685 menu_enabled_time = time;
686 localcmd("menu_showhudexit\n");
688 else if(nPrimary == K_BACKSPACE && hudShiftState & S_CTRL)
693 cvar_set("_hud_configure", "0");
695 else if(nPrimary == K_TAB && hudShiftState & S_CTRL) // select and highlight another panel
697 if (bInputType == 1 || mouseClicked)
700 //FIXME: if a panel is highlighted, has the same pos_x and lays in the same level
701 //of other panels then next consecutive ctrl-tab will select the highlighted panel too
702 //(it should only after every other panel of the hud)
703 //It's a minor bug anyway, we can live with it
705 float starting_panel;
706 float old_tab_panel = tab_panel;
707 if (tab_panel == -1) //first press of TAB
709 if (highlightedPanel != -1)
710 HUD_Panel_UpdatePosSizeForId(highlightedPanel)
713 starting_panel = highlightedPanel; //can be -1, it means no starting panel
714 tab_panel_pos = panel_pos; //to compute level
718 if ( ((!tab_backward) && (hudShiftState & S_SHIFT)) || (tab_backward && !(hudShiftState & S_SHIFT)) ) //tab direction changed?
720 starting_panel = tab_panel;
722 tab_backward = (hudShiftState & S_SHIFT);
724 float k, level, start_pos_x;
725 vector candidate_pos;
726 const float LEVELS_NUM = 4;
727 float level_height = vid_conheight / LEVELS_NUM;
729 level = floor(tab_panel_pos_y / level_height) * level_height; //starting level
730 candidate_pos_x = (!tab_backward) ? vid_conwidth : 0;
731 start_pos_x = tab_panel_pos_x;
736 for(i = 0; i < HUD_PANEL_NUM; ++i)
738 if (i == tab_panels[i] || i == starting_panel)
740 HUD_Panel_UpdatePosSizeForId(i)
741 if (panel_pos_y >= level && (panel_pos_y - level) < level_height)
742 if ( ( !tab_backward && panel_pos_x >= start_pos_x && (panel_pos_x < candidate_pos_x || (panel_pos_x == candidate_pos_x && panel_pos_y <= candidate_pos_y)) )
743 || ( tab_backward && panel_pos_x <= start_pos_x && (panel_pos_x > candidate_pos_x || (panel_pos_x == candidate_pos_x && panel_pos_y >= candidate_pos_y)) ) )
746 tab_panel_pos = candidate_pos = panel_pos;
751 if (k == LEVELS_NUM) //tab_panel not found
754 if (old_tab_panel == -2) //this prevents an infinite loop (should not happen normally)
759 starting_panel = old_tab_panel;
761 goto find_tab_panel; //u must find tab_panel!
765 level = mod(level + level_height, vid_conheight);
767 candidate_pos_x = vid_conwidth;
771 level = mod(level - level_height, vid_conheight);
772 start_pos_x = vid_conwidth;
777 tab_panels[tab_panel] = tab_panel;
779 else if(nPrimary == K_SPACE && hudShiftState & S_CTRL) // enable/disable highlighted panel or dock
781 if (bInputType == 1 || mouseClicked)
784 if (highlightedPanel != -1)
786 HUD_Panel_GetName(highlightedPanel);
787 cvar_set(strcat("hud_panel_", panel_name), ftos(!(panel_enabled)));
790 cvar_set(strcat("hud_dock"), (autocvar_hud_dock == "") ? "dock" : "");
792 else if(nPrimary == 'c' && hudShiftState & S_CTRL) // copy highlighted panel size
794 if (bInputType == 1 || mouseClicked)
797 if (highlightedPanel != -1)
799 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
800 panel_size_copied = panel_size;
801 highlightedPanel_copied = highlightedPanel;
804 else if(nPrimary == 'v' && hudShiftState & S_CTRL) // past copied size on the highlighted panel
806 if (bInputType == 1 || mouseClicked)
809 if (highlightedPanel_copied == -1 || highlightedPanel == -1)
812 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
814 // reduce size if it'd go beyond screen boundaries
815 vector tmp_size = panel_size_copied;
816 if (panel_pos_x + panel_size_copied_x > vid_conwidth)
817 tmp_size_x = vid_conwidth - panel_pos_x;
818 if (panel_pos_y + panel_size_copied_y > vid_conheight)
819 tmp_size_y = vid_conheight - panel_pos_y;
821 if (panel_size == tmp_size)
825 panel_pos_backup = panel_pos;
826 panel_size_backup = panel_size;
827 highlightedPanel_backup = highlightedPanel;
829 s = strcat(ftos(tmp_size_x/vid_conwidth), " ", ftos(tmp_size_y/vid_conheight));
830 HUD_Panel_GetName(highlightedPanel);
831 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
833 else if(nPrimary == 'z' && hudShiftState & S_CTRL) // undo last action
835 if (bInputType == 1 || mouseClicked)
837 //restore previous values
838 if (highlightedPanel_backup != -1)
840 HUD_Panel_GetName(highlightedPanel_backup);
841 s = strcat(ftos(panel_pos_backup_x/vid_conwidth), " ", ftos(panel_pos_backup_y/vid_conheight));
842 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
843 s = strcat(ftos(panel_size_backup_x/vid_conwidth), " ", ftos(panel_size_backup_y/vid_conheight));
844 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
845 highlightedPanel_backup = -1;
848 else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
852 pressed_key_time = 0;
855 else if (pressed_key_time == 0)
856 pressed_key_time = time;
859 HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
861 else if(nPrimary == K_ENTER || nPrimary == K_SPACE || nPrimary == K_KP_ENTER)
865 if (highlightedPanel != -1)
866 HUD_Panel_EnableMenu();
868 else if(hit_con_bind)
874 float HUD_Panel_Check_Mouse_Pos(float allow_move)
878 while(j < HUD_PANEL_NUM)
883 HUD_Panel_UpdatePosSizeForId(i);
885 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
888 if(allow_move && mousepos_x >= panel_pos_x && mousepos_y >= panel_pos_y && mousepos_x <= panel_pos_x + panel_size_x && mousepos_y <= panel_pos_y + panel_size_y)
892 // resize from topleft border
893 else if(mousepos_x >= panel_pos_x - border && mousepos_y >= panel_pos_y - border && mousepos_x <= panel_pos_x + 0.5 * panel_size_x && mousepos_y <= panel_pos_y + 0.5 * panel_size_y)
897 // resize from topright border
898 else if(mousepos_x >= panel_pos_x + 0.5 * panel_size_x && mousepos_y >= panel_pos_y - border && mousepos_x <= panel_pos_x + panel_size_x + border && mousepos_y <= panel_pos_y + 0.5 * panel_size_y)
902 // resize from bottomleft border
903 else if(mousepos_x >= panel_pos_x - border && mousepos_y >= panel_pos_y + 0.5 * panel_size_y && mousepos_x <= panel_pos_x + 0.5 * panel_size_x && mousepos_y <= panel_pos_y + panel_size_y + border)
907 // resize from bottomright border
908 else if(mousepos_x >= panel_pos_x + 0.5 * panel_size_x && mousepos_y >= panel_pos_y + 0.5 * panel_size_y && mousepos_x <= panel_pos_x + panel_size_x + border && mousepos_y <= panel_pos_y + panel_size_y + border)
916 // move a panel to the beginning of the panel order array (which means it gets drawn last, on top of everything else)
917 void HUD_Panel_FirstInDrawQ(float id)
920 var float place = -1;
921 // find out where in the array our current id is, save into place
922 for(i = 0; i < HUD_PANEL_NUM; ++i)
924 if(panel_order[i] == id)
930 // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
932 place = HUD_PANEL_NUM - 1;
934 // move all ids up by one step in the array until "place"
935 for(i = place; i > 0; --i)
937 panel_order[i] = panel_order[i-1];
939 // now save the new top id
942 // let's save them into the cvar by some strcat trickery
944 for(i = 0; i < HUD_PANEL_NUM; ++i)
946 s = strcat(s, ftos(panel_order[i]), " ");
948 cvar_set("_hud_panelorder", s);
949 if(hud_panelorder_prev)
950 strunzone(hud_panelorder_prev);
951 hud_panelorder_prev = strzone(autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here
954 void HUD_Panel_Highlight(float allow_move)
958 while(j < HUD_PANEL_NUM)
963 HUD_Panel_UpdatePosSizeForId(i);
965 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
968 if(allow_move && mousepos_x >= panel_pos_x && mousepos_y >= panel_pos_y && mousepos_x <= panel_pos_x + panel_size_x && mousepos_y <= panel_pos_y + panel_size_y)
970 highlightedPanel = i;
971 HUD_Panel_FirstInDrawQ(i);
972 highlightedAction = 1;
973 panel_click_distance = mousepos - panel_pos;
976 // resize from topleft border
977 else if(mousepos_x >= panel_pos_x - border && mousepos_y >= panel_pos_y - border && mousepos_x <= panel_pos_x + 0.5 * panel_size_x && mousepos_y <= panel_pos_y + 0.5 * panel_size_y)
979 highlightedPanel = i;
980 HUD_Panel_FirstInDrawQ(i);
981 highlightedAction = 2;
983 panel_click_distance = mousepos - panel_pos;
984 panel_click_resizeorigin = panel_pos + panel_size;
987 // resize from topright border
988 else if(mousepos_x >= panel_pos_x + 0.5 * panel_size_x && mousepos_y >= panel_pos_y - border && mousepos_x <= panel_pos_x + panel_size_x + border && mousepos_y <= panel_pos_y + 0.5 * panel_size_y)
990 highlightedPanel = i;
991 HUD_Panel_FirstInDrawQ(i);
992 highlightedAction = 2;
994 panel_click_distance_x = panel_size_x - mousepos_x + panel_pos_x;
995 panel_click_distance_y = mousepos_y - panel_pos_y;
996 panel_click_resizeorigin = panel_pos + eY * panel_size_y;
999 // resize from bottomleft border
1000 else if(mousepos_x >= panel_pos_x - border && mousepos_y >= panel_pos_y + 0.5 * panel_size_y && mousepos_x <= panel_pos_x + 0.5 * panel_size_x && mousepos_y <= panel_pos_y + panel_size_y + border)
1002 highlightedPanel = i;
1003 HUD_Panel_FirstInDrawQ(i);
1004 highlightedAction = 2;
1006 panel_click_distance_x = mousepos_x - panel_pos_x;
1007 panel_click_distance_y = panel_size_y - mousepos_y + panel_pos_y;
1008 panel_click_resizeorigin = panel_pos + eX * panel_size_x;
1011 // resize from bottomright border
1012 else if(mousepos_x >= panel_pos_x + 0.5 * panel_size_x && mousepos_y >= panel_pos_y + 0.5 * panel_size_y && mousepos_x <= panel_pos_x + panel_size_x + border && mousepos_y <= panel_pos_y + panel_size_y + border)
1014 highlightedPanel = i;
1015 HUD_Panel_FirstInDrawQ(i);
1016 highlightedAction = 2;
1018 panel_click_distance = panel_size - mousepos + panel_pos;
1019 panel_click_resizeorigin = panel_pos;
1023 highlightedPanel = -1;
1024 highlightedAction = 0;
1027 void HUD_Panel_EnableMenu()
1030 menu_enabled_time = time;
1031 HUD_Panel_GetName(highlightedPanel);
1032 localcmd("menu_showhudoptions ", panel_name, "\n");
1034 float mouse_over_panel;
1035 void HUD_Panel_Mouse()
1037 // TODO: needs better check... is there any float that contains the current state of the menu? _menu_alpha isn't apparently updated the frame the menu gets enabled
1038 if (autocvar__menu_alpha == 0 && time - menu_enabled_time > 0.5)
1042 print("menu_enabled: ", ftos(menu_enabled), "\n");
1043 print("Highlighted: ", ftos(highlightedPanel), "\n");
1044 print("Menu alpha: ", ftos(autocvar__menu_alpha), "\n");
1047 // instantly hide the editor cursor if we open the HUDExit dialog
1048 // as hud_fade_alpha doesn't decrease to 0 in this case
1049 // TODO: find a way to fade the cursor out even in this case
1050 if(menu_enabled == 1 || (menu_enabled == 2 && !hud_fade_alpha))
1053 mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
1055 mousepos_x = bound(0, mousepos_x, vid_conwidth);
1056 mousepos_y = bound(0, mousepos_y, vid_conheight);
1060 if(prevMouseClicked == 0)
1062 if (tab_panel != -1)
1064 //stop ctrl-tab selection
1068 HUD_Panel_Highlight(mouseClicked & S_MOUSE1); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
1069 // and calls HUD_Panel_UpdatePosSizeForId() for the highlighted panel
1070 if (highlightedPanel != -1)
1072 highlightedPanel_initial_pos = panel_pos;
1073 highlightedPanel_initial_size = panel_size;
1075 // doubleclick check
1076 if ((mouseClicked & S_MOUSE1) && time - prevMouseClickedTime < 0.4 && highlightedPanel != -1 && prevMouseClickedPos == mousepos)
1078 mouseClicked = 0; // to prevent spam, I guess.
1079 HUD_Panel_EnableMenu();
1083 if (mouseClicked & S_MOUSE1)
1085 prevMouseClickedTime = time;
1086 prevMouseClickedPos = mousepos;
1088 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(mouseClicked & S_MOUSE1);
1092 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1094 if (highlightedPanel != -1)
1096 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1097 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
1099 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
1101 panel_pos_backup = highlightedPanel_initial_pos;
1102 panel_size_backup = highlightedPanel_initial_size;
1103 highlightedPanel_backup = highlightedPanel;
1106 // in case the clicked panel is inside another panel and we aren't
1107 // moving it, avoid the immediate "fix" of its position/size
1108 // (often unwanted and hateful) by disabling collisions check
1109 hud_configure_checkcollisions = false;
1112 if(highlightedAction == 1)
1113 HUD_Panel_SetPos(mousepos - panel_click_distance);
1114 else if(highlightedAction == 2)
1117 if(resizeCorner == 1) {
1118 mySize_x = panel_click_resizeorigin_x - (mousepos_x - panel_click_distance_x);
1119 mySize_y = panel_click_resizeorigin_y - (mousepos_y - panel_click_distance_y);
1120 } else if(resizeCorner == 2) {
1121 mySize_x = mousepos_x + panel_click_distance_x - panel_click_resizeorigin_x;
1122 mySize_y = panel_click_distance_y + panel_click_resizeorigin_y - mousepos_y;
1123 } else if(resizeCorner == 3) {
1124 mySize_x = panel_click_resizeorigin_x + panel_click_distance_x - mousepos_x;
1125 mySize_y = mousepos_y + panel_click_distance_y - panel_click_resizeorigin_y;
1126 } else { // resizeCorner == 4
1127 mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x);
1128 mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y);
1130 HUD_Panel_SetPosSize(mySize);
1135 if(menu_enabled == 2)
1136 mouse_over_panel = 0;
1138 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(TRUE);
1139 if (mouse_over_panel && tab_panel == -1)
1140 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1142 // draw cursor after performing move/resize to have the panel pos/size updated before mouse_over_panel
1143 const vector cursorsize = '32 32 0';
1145 if(!mouse_over_panel)
1146 drawpic(mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1147 else if(mouse_over_panel == 1)
1148 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_move.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1149 else if(mouse_over_panel == 2)
1150 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1152 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize2.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1154 prevMouseClicked = mouseClicked;
1157 const float hlBorderSize = 4;
1158 const string hlBorder = "gfx/hud/default/border_highlighted";
1159 const string hlBorder2 = "gfx/hud/default/border_highlighted2";
1160 void HUD_Panel_HlBorder(float myBorder, vector color, float alpha)
1162 drawfill(panel_pos - '1 1 0' * myBorder, panel_size + '2 2 0' * myBorder, '0 0.5 1', .5 * alpha, DRAWFLAG_NORMAL);
1163 drawpic_tiled(panel_pos - '1 1 0' * myBorder, hlBorder, '8 1 0' * hlBorderSize, eX * (panel_size_x + 2 * myBorder) + eY * hlBorderSize, color, alpha, DRAWFLAG_NORMAL);
1164 drawpic_tiled(panel_pos - '1 1 0' * myBorder + eY * (panel_size_y + 2 * myBorder - hlBorderSize), hlBorder, '8 1 0' * hlBorderSize, eX * (panel_size_x + 2 * myBorder) + eY * hlBorderSize, color, alpha, DRAWFLAG_NORMAL);
1165 drawpic_tiled(panel_pos - '1 1 0' * myBorder + eY * hlBorderSize, hlBorder2, '1 8 0' * hlBorderSize, eY * (panel_size_y + 2 * myBorder - 2 * hlBorderSize) + eX * hlBorderSize, color, alpha, DRAWFLAG_NORMAL);
1166 drawpic_tiled(panel_pos - '1 1 0' * myBorder + eY * hlBorderSize + eX * (panel_size_x + 2 * myBorder - hlBorderSize), hlBorder2, '1 8 0' * hlBorderSize, eY * (panel_size_y + 2 * myBorder - 2 * hlBorderSize) + eX * hlBorderSize, color, alpha, DRAWFLAG_NORMAL);