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("_complainbubble");
66 HUD_Write_PanelCvar_q("_complainbubble_padding");
67 HUD_Write_PanelCvar_q("_complainbubble_time");
68 HUD_Write_PanelCvar_q("_complainbubble_fadetime");
69 HUD_Write_PanelCvar_q("_complainbubble_color_outofammo");
70 HUD_Write_PanelCvar_q("_complainbubble_color_donthave");
71 HUD_Write_PanelCvar_q("_complainbubble_color_unavailable");
72 HUD_Write_PanelCvar_q("_ammo_color");
73 HUD_Write_PanelCvar_q("_ammo_alpha");
74 HUD_Write_PanelCvar_q("_aspect");
75 HUD_Write_PanelCvar_q("_timeout");
76 HUD_Write_PanelCvar_q("_timeout_effect");
79 HUD_Write_PanelCvar_q("_onlycurrent");
80 HUD_Write_PanelCvar_q("_iconalign");
81 HUD_Write_PanelCvar_q("_progressbar");
82 HUD_Write_PanelCvar_q("_progressbar_name");
83 HUD_Write_PanelCvar_q("_progressbar_xoffset");
84 HUD_Write_PanelCvar_q("_text");
86 case HUD_PANEL_POWERUPS:
87 HUD_Write_PanelCvar_q("_flip");
88 HUD_Write_PanelCvar_q("_iconalign");
89 HUD_Write_PanelCvar_q("_baralign");
90 HUD_Write_PanelCvar_q("_progressbar");
91 HUD_Write_PanelCvar_q("_progressbar_strength");
92 HUD_Write_PanelCvar_q("_progressbar_shield");
94 case HUD_PANEL_HEALTHARMOR:
95 HUD_Write_PanelCvar_q("_flip");
96 HUD_Write_PanelCvar_q("_iconalign");
97 HUD_Write_PanelCvar_q("_baralign");
98 HUD_Write_PanelCvar_q("_progressbar");
99 HUD_Write_PanelCvar_q("_progressbar_health");
100 HUD_Write_PanelCvar_q("_progressbar_armor");
101 HUD_Write_PanelCvar_q("_text");
103 case HUD_PANEL_NOTIFY:
104 HUD_Write_PanelCvar_q("_flip");
105 HUD_Write_PanelCvar_q("_fontsize");
106 HUD_Write_PanelCvar_q("_print");
108 case HUD_PANEL_RADAR:
109 HUD_Write_PanelCvar_q("_foreground_alpha");
111 case HUD_PANEL_SCORE:
112 HUD_Write_PanelCvar_q("_rankings");
115 HUD_Write_PanelCvar_q("_alreadyvoted_alpha");
117 case HUD_PANEL_PRESSEDKEYS:
118 HUD_Write_PanelCvar_q("_aspect");
120 case HUD_PANEL_INFOMESSAGES:
121 HUD_Write_PanelCvar_q("_flip");
123 case HUD_PANEL_PHYSICS:
124 HUD_Write_PanelCvar_q("_flip");
125 HUD_Write_PanelCvar_q("_baralign");
126 HUD_Write_PanelCvar_q("_progressbar");
127 HUD_Write_PanelCvar_q("_acceleration_mode");
129 case HUD_PANEL_CENTERPRINT:
130 HUD_Write_PanelCvar_q("_align");
131 HUD_Write_PanelCvar_q("_flip");
132 HUD_Write_PanelCvar_q("_fontscale");
133 HUD_Write_PanelCvar_q("_time");
134 HUD_Write_PanelCvar_q("_fadetime");
139 HUD_Write("menu_sync\n"); // force the menu to reread the cvars, so that the dialogs are updated
141 print(sprintf(_("^2Successfully exported to %s! (Note: It's saved in data/data/)\n"), filename));
145 print(sprintf(_("^1Couldn't write to %s\n"), filename));
148 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
149 vector HUD_Panel_CheckMove(vector myPos, vector mySize)
152 float myCenter_x, myCenter_y, targCenter_x, targCenter_y;
156 for (i = 0; i < HUD_PANEL_NUM; ++i) {
157 if(i == highlightedPanel || !panel_enabled)
160 HUD_Panel_UpdatePosSizeForId(i);
162 panel_pos -= '1 1 0' * panel_bg_border;
163 panel_size += '2 2 0' * panel_bg_border;
165 if(myPos_y + mySize_y < panel_pos_y)
167 if(myPos_y > panel_pos_y + panel_size_y)
170 if(myPos_x + mySize_x < panel_pos_x)
172 if(myPos_x > panel_pos_x + panel_size_x)
175 // OK, there IS a collision.
177 myCenter_x = myPos_x + 0.5 * mySize_x;
178 myCenter_y = myPos_y + 0.5 * mySize_y;
180 targCenter_x = panel_pos_x + 0.5 * panel_size_x;
181 targCenter_y = panel_pos_y + 0.5 * panel_size_y;
183 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
185 if(myPos_x + mySize_x - panel_pos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
186 myTarget_x = panel_pos_x - mySize_x;
187 else // push it upwards
188 myTarget_y = panel_pos_y - mySize_y;
190 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
192 if(panel_pos_x + panel_size_x - myPos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
193 myTarget_x = panel_pos_x + panel_size_x;
194 else // push it upwards
195 myTarget_y = panel_pos_y - mySize_y;
197 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
199 if(myPos_x + mySize_x - panel_pos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
200 myTarget_x = panel_pos_x - mySize_x;
201 else // push it downwards
202 myTarget_y = panel_pos_y + panel_size_y;
204 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
206 if(panel_pos_x + panel_size_x - myPos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
207 myTarget_x = panel_pos_x + panel_size_x;
208 else // push it downwards
209 myTarget_y = panel_pos_y + panel_size_y;
211 //if(cvar("hud_configure_checkcollisions_debug"))
212 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
218 void HUD_Panel_SetPos(vector pos)
220 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
224 //if(cvar("hud_configure_checkcollisions_debug"))
225 //drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
227 if(autocvar_hud_configure_grid)
229 pos_x = floor((pos_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
230 pos_y = floor((pos_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
233 if(hud_configure_checkcollisions)
234 pos = HUD_Panel_CheckMove(pos, mySize);
236 pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
237 pos_y = bound(0, pos_y, vid_conheight - mySize_y);
240 s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
242 HUD_Panel_GetName(highlightedPanel);
243 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
246 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
247 vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
252 float dist_x, dist_y;
254 ratio = mySize_x/mySize_y;
256 for (i = 0; i < HUD_PANEL_NUM; ++i) {
257 if(i == highlightedPanel || !panel_enabled)
260 HUD_Panel_UpdatePosSizeForId(i);
262 panel_pos -= '1 1 0' * panel_bg_border;
263 panel_size += '2 2 0' * panel_bg_border;
265 targEndPos = panel_pos + panel_size;
267 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
268 if(resizeorigin_x > panel_pos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > panel_pos_y && resizeorigin_y < targEndPos_y)
271 if (resizeCorner == 1)
273 // check if this panel is on our way
274 if (resizeorigin_x <= panel_pos_x)
276 if (resizeorigin_y <= panel_pos_y)
278 if (targEndPos_x <= resizeorigin_x - mySize_x)
280 if (targEndPos_y <= resizeorigin_y - mySize_y)
283 // there is a collision:
284 // detect which side of the panel we are facing is actually limiting the resizing
285 // (which side the resize direction finds for first) and reduce the size up to there
287 // dist is the distance between resizeorigin and the "analogous" point of the panel
288 // in this case between resizeorigin (bottom-right point) and the bottom-right point of the panel
289 dist_x = resizeorigin_x - targEndPos_x;
290 dist_y = resizeorigin_y - targEndPos_y;
291 if (dist_y <= 0 || dist_x / dist_y > ratio)
292 mySize_x = min(mySize_x, dist_x);
294 mySize_y = min(mySize_y, dist_y);
296 else if (resizeCorner == 2)
298 if (resizeorigin_x >= targEndPos_x)
300 if (resizeorigin_y <= panel_pos_y)
302 if (panel_pos_x >= resizeorigin_x + mySize_x)
304 if (targEndPos_y <= resizeorigin_y - mySize_y)
307 dist_x = panel_pos_x - resizeorigin_x;
308 dist_y = resizeorigin_y - targEndPos_y;
309 if (dist_y <= 0 || dist_x / dist_y > ratio)
310 mySize_x = min(mySize_x, dist_x);
312 mySize_y = min(mySize_y, dist_y);
314 else if (resizeCorner == 3)
316 if (resizeorigin_x <= panel_pos_x)
318 if (resizeorigin_y >= targEndPos_y)
320 if (targEndPos_x <= resizeorigin_x - mySize_x)
322 if (panel_pos_y >= resizeorigin_y + mySize_y)
325 dist_x = resizeorigin_x - targEndPos_x;
326 dist_y = panel_pos_y - resizeorigin_y;
327 if (dist_y <= 0 || dist_x / dist_y > ratio)
328 mySize_x = min(mySize_x, dist_x);
330 mySize_y = min(mySize_y, dist_y);
332 else if (resizeCorner == 4)
334 if (resizeorigin_x >= targEndPos_x)
336 if (resizeorigin_y >= targEndPos_y)
338 if (panel_pos_x >= resizeorigin_x + mySize_x)
340 if (panel_pos_y >= resizeorigin_y + mySize_y)
343 dist_x = panel_pos_x - resizeorigin_x;
344 dist_y = panel_pos_y - resizeorigin_y;
345 if (dist_y <= 0 || dist_x / dist_y > ratio)
346 mySize_x = min(mySize_x, dist_x);
348 mySize_y = min(mySize_y, dist_y);
350 //if(cvar("hud_configure_checkcollisions_debug"))
351 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
357 void HUD_Panel_SetPosSize(vector mySize)
359 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
361 resizeorigin = panel_click_resizeorigin;
364 // minimum panel size cap
365 mySize_x = max(0.025 * vid_conwidth, mySize_x);
366 mySize_y = max(0.025 * vid_conheight, mySize_y);
368 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.
370 mySize_x = max(17 * autocvar_con_chatsize, mySize_x);
371 mySize_y = max(2 * autocvar_con_chatsize + 2 * panel_bg_padding, mySize_y);
374 // collision testing|
375 // -----------------+
377 // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
378 if(resizeCorner == 1) {
379 myPos_x = resizeorigin_x - mySize_x;
380 myPos_y = resizeorigin_y - mySize_y;
381 } else if(resizeCorner == 2) {
382 myPos_x = resizeorigin_x;
383 myPos_y = resizeorigin_y - mySize_y;
384 } else if(resizeCorner == 3) {
385 myPos_x = resizeorigin_x - mySize_x;
386 myPos_y = resizeorigin_y;
387 } else { // resizeCorner == 4
388 myPos_x = resizeorigin_x;
389 myPos_y = resizeorigin_y;
392 // left/top screen edges
394 mySize_x = mySize_x + myPos_x;
396 mySize_y = mySize_y + myPos_y;
398 // bottom/right screen edges
399 if(myPos_x + mySize_x > vid_conwidth)
400 mySize_x = vid_conwidth - myPos_x;
401 if(myPos_y + mySize_y > vid_conheight)
402 mySize_y = vid_conheight - myPos_y;
404 //if(cvar("hud_configure_checkcollisions_debug"))
405 //drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
407 // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
408 if(autocvar_hud_configure_grid)
410 mySize_x = floor((mySize_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
411 mySize_y = floor((mySize_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
414 if(hud_configure_checkcollisions)
415 mySize = HUD_Panel_CheckResize(mySize, resizeorigin);
417 // 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)
418 mySize_x = max(0.025 * vid_conwidth, mySize_x);
419 mySize_y = max(0.025 * vid_conheight, mySize_y);
421 // do another pos check, as size might have changed by now
422 if(resizeCorner == 1) {
423 myPos_x = resizeorigin_x - mySize_x;
424 myPos_y = resizeorigin_y - mySize_y;
425 } else if(resizeCorner == 2) {
426 myPos_x = resizeorigin_x;
427 myPos_y = resizeorigin_y - mySize_y;
428 } else if(resizeCorner == 3) {
429 myPos_x = resizeorigin_x - mySize_x;
430 myPos_y = resizeorigin_y;
431 } else { // resizeCorner == 4
432 myPos_x = resizeorigin_x;
433 myPos_y = resizeorigin_y;
436 //if(cvar("hud_configure_checkcollisions_debug"))
437 //drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
439 HUD_Panel_GetName(highlightedPanel);
441 s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
442 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
444 s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
445 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
448 float pressed_key_time;
449 vector highlightedPanel_initial_pos, highlightedPanel_initial_size;
450 void HUD_Panel_Arrow_Action(float nPrimary)
452 if (highlightedPanel == -1)
455 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
458 if(autocvar_hud_configure_grid)
460 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
462 if (hudShiftState & S_SHIFT)
463 step = hud_configure_realGridSize_y;
465 step = 2 * hud_configure_realGridSize_y;
469 if (hudShiftState & S_SHIFT)
470 step = hud_configure_realGridSize_x;
472 step = 2 * hud_configure_realGridSize_x;
477 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
478 step = vid_conheight;
481 if (hudShiftState & S_SHIFT)
482 step = (step / 256); // more precision
484 step = (step / 64) * (1 + 2 * (time - pressed_key_time));
487 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
489 highlightedPanel_initial_pos = panel_pos;
490 highlightedPanel_initial_size = panel_size;
492 if (hudShiftState & S_ALT) // resize
494 highlightedAction = 1;
495 if(nPrimary == K_UPARROW)
497 else if(nPrimary == K_RIGHTARROW)
499 else if(nPrimary == K_LEFTARROW)
501 else // if(nPrimary == K_DOWNARROW)
504 // ctrl+arrow reduces the size, instead of increasing it
505 // Note that ctrl disables collisions check too, but it's fine
506 // since we don't collide with anything reducing the size
507 if (hudShiftState & S_CTRL) {
509 resizeCorner = 5 - resizeCorner;
514 panel_click_resizeorigin = panel_pos;
515 if(resizeCorner == 1) {
516 panel_click_resizeorigin += mySize;
518 } else if(resizeCorner == 2) {
519 panel_click_resizeorigin_y += mySize_y;
521 } else if(resizeCorner == 3) {
522 panel_click_resizeorigin_x += mySize_x;
524 } else { // resizeCorner == 4
527 HUD_Panel_SetPosSize(mySize);
531 highlightedAction = 2;
534 if(nPrimary == K_UPARROW)
536 else if(nPrimary == K_DOWNARROW)
538 else if(nPrimary == K_LEFTARROW)
540 else // if(nPrimary == K_RIGHTARROW)
543 HUD_Panel_SetPos(pos);
546 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
548 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
551 panel_pos_backup = highlightedPanel_initial_pos;
552 panel_size_backup = highlightedPanel_initial_size;
553 highlightedPanel_backup = highlightedPanel;
557 const float S_MOUSE1 = 1;
558 const float S_MOUSE2 = 2;
559 const float S_MOUSE3 = 4;
561 float prevMouseClicked; // previous state
562 float prevMouseClickedTime; // time during previous left mouse click, to check for doubleclicks
563 vector prevMouseClickedPos; // pos during previous left mouse click, to check for doubleclicks
565 void HUD_Panel_EnableMenu();
566 float tab_panels[HUD_PANEL_NUM];
567 float tab_panel, tab_backward;
568 vector tab_panel_pos;
569 void HUD_Panel_FirstInDrawQ(float id);
570 void reset_tab_panels()
573 for(i = 0; i < HUD_PANEL_NUM; ++i)
576 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
580 // we only care for keyboard events
581 if(bInputType != 0 && bInputType != 1)
584 if(!autocvar__hud_configure)
587 // allow console bind to work
590 con_keys = findkeysforcommand("toggleconsole");
591 keys = tokenize(con_keys);
593 float hit_con_bind, i;
594 for (i = 0; i < keys; ++i)
596 if(nPrimary == stof(argv(i)))
600 if(bInputType == 0) {
601 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
602 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
603 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
605 else if(bInputType == 1) {
606 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
607 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
608 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
611 if(nPrimary == K_CTRL)
613 if (bInputType == 1) //ctrl has been released
617 //switch to selected panel
618 highlightedPanel = tab_panel;
619 highlightedAction = 0;
620 HUD_Panel_FirstInDrawQ(highlightedPanel);
627 if(nPrimary == K_MOUSE1)
629 if(bInputType == 0) // key pressed
630 mouseClicked |= S_MOUSE1;
631 else if(bInputType == 1) // key released
632 mouseClicked -= (mouseClicked & S_MOUSE1);
634 else if(nPrimary == K_MOUSE2)
636 if(bInputType == 0) // key pressed
637 mouseClicked |= S_MOUSE2;
638 else if(bInputType == 1) // key released
639 mouseClicked -= (mouseClicked & S_MOUSE2);
641 else if(nPrimary == K_ESCAPE)
646 menu_enabled_time = time;
647 localcmd("menu_showhudexit\n");
649 else if(nPrimary == K_BACKSPACE && hudShiftState & S_CTRL)
654 cvar_set("_hud_configure", "0");
656 else if(nPrimary == K_TAB && hudShiftState & S_CTRL) // select and highlight another panel
658 if (bInputType == 1 || mouseClicked)
661 //FIXME: if a panel is highlighted, has the same pos_x and lays in the same level
662 //of other panels then next consecutive ctrl-tab will select the highlighted panel too
663 //(it should only after every other panel of the hud)
664 //It's a minor bug anyway, we can live with it
666 float starting_panel;
667 float old_tab_panel = tab_panel;
668 if (tab_panel == -1) //first press of TAB
670 if (highlightedPanel != -1)
671 HUD_Panel_UpdatePosSizeForId(highlightedPanel)
674 starting_panel = highlightedPanel; //can be -1, it means no starting panel
675 tab_panel_pos = panel_pos; //to compute level
679 if ( ((!tab_backward) && (hudShiftState & S_SHIFT)) || (tab_backward && !(hudShiftState & S_SHIFT)) ) //tab direction changed?
681 starting_panel = tab_panel;
683 tab_backward = (hudShiftState & S_SHIFT);
685 float k, level, start_pos_x;
686 vector candidate_pos;
687 const float LEVELS_NUM = 4;
688 float level_height = vid_conheight / LEVELS_NUM;
690 level = floor(tab_panel_pos_y / level_height) * level_height; //starting level
691 candidate_pos_x = (!tab_backward) ? vid_conwidth : 0;
692 start_pos_x = tab_panel_pos_x;
697 for(i = 0; i < HUD_PANEL_NUM; ++i)
699 if (i == tab_panels[i] || i == starting_panel)
701 HUD_Panel_UpdatePosSizeForId(i)
702 if (panel_pos_y >= level && (panel_pos_y - level) < level_height)
703 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)) )
704 || ( 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)) ) )
707 tab_panel_pos = candidate_pos = panel_pos;
712 if (k == LEVELS_NUM) //tab_panel not found
715 if (old_tab_panel == -2) //this prevents an infinite loop (should not happen normally)
720 starting_panel = old_tab_panel;
722 goto find_tab_panel; //u must find tab_panel!
726 level = mod(level + level_height, vid_conheight);
728 candidate_pos_x = vid_conwidth;
732 level = mod(level - level_height, vid_conheight);
733 start_pos_x = vid_conwidth;
738 tab_panels[tab_panel] = tab_panel;
740 else if(nPrimary == K_SPACE && hudShiftState & S_CTRL) // enable/disable highlighted panel or dock
742 if (bInputType == 1 || mouseClicked)
745 if (highlightedPanel != -1)
747 HUD_Panel_GetName(highlightedPanel);
748 cvar_set(strcat("hud_panel_", panel_name), ftos(!(panel_enabled)));
751 cvar_set(strcat("hud_dock"), (autocvar_hud_dock == "") ? "dock" : "");
753 else if(nPrimary == 'c' && hudShiftState & S_CTRL) // copy highlighted panel size
755 if (bInputType == 1 || mouseClicked)
758 if (highlightedPanel != -1)
760 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
761 panel_size_copied = panel_size;
762 highlightedPanel_copied = highlightedPanel;
765 else if(nPrimary == 'v' && hudShiftState & S_CTRL) // past copied size on the highlighted panel
767 if (bInputType == 1 || mouseClicked)
770 if (highlightedPanel_copied == -1 || highlightedPanel == -1)
773 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
775 // reduce size if it'd go beyond screen boundaries
776 vector tmp_size = panel_size_copied;
777 if (panel_pos_x + panel_size_copied_x > vid_conwidth)
778 tmp_size_x = vid_conwidth - panel_pos_x;
779 if (panel_pos_y + panel_size_copied_y > vid_conheight)
780 tmp_size_y = vid_conheight - panel_pos_y;
782 if (panel_size == tmp_size)
786 panel_pos_backup = panel_pos;
787 panel_size_backup = panel_size;
788 highlightedPanel_backup = highlightedPanel;
790 s = strcat(ftos(tmp_size_x/vid_conwidth), " ", ftos(tmp_size_y/vid_conheight));
791 HUD_Panel_GetName(highlightedPanel);
792 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
794 else if(nPrimary == 'z' && hudShiftState & S_CTRL) // undo last action
796 if (bInputType == 1 || mouseClicked)
798 //restore previous values
799 if (highlightedPanel_backup != -1)
801 HUD_Panel_GetName(highlightedPanel_backup);
802 s = strcat(ftos(panel_pos_backup_x/vid_conwidth), " ", ftos(panel_pos_backup_y/vid_conheight));
803 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
804 s = strcat(ftos(panel_size_backup_x/vid_conwidth), " ", ftos(panel_size_backup_y/vid_conheight));
805 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
806 highlightedPanel_backup = -1;
809 else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
813 pressed_key_time = 0;
816 else if (pressed_key_time == 0)
817 pressed_key_time = time;
820 HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
822 else if(nPrimary == K_ENTER || nPrimary == K_SPACE || nPrimary == K_KP_ENTER)
826 if (highlightedPanel != -1)
827 HUD_Panel_EnableMenu();
829 else if(hit_con_bind)
835 float HUD_Panel_Check_Mouse_Pos(float allow_move)
839 while(j < HUD_PANEL_NUM)
844 HUD_Panel_UpdatePosSizeForId(i);
846 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
849 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)
853 // resize from topleft border
854 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)
858 // resize from topright border
859 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)
863 // resize from bottomleft border
864 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)
868 // resize from bottomright border
869 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)
877 // move a panel to the beginning of the panel order array (which means it gets drawn last, on top of everything else)
878 void HUD_Panel_FirstInDrawQ(float id)
881 var float place = -1;
882 // find out where in the array our current id is, save into place
883 for(i = 0; i < HUD_PANEL_NUM; ++i)
885 if(panel_order[i] == id)
891 // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
893 place = HUD_PANEL_NUM - 1;
895 // move all ids up by one step in the array until "place"
896 for(i = place; i > 0; --i)
898 panel_order[i] = panel_order[i-1];
900 // now save the new top id
903 // let's save them into the cvar by some strcat trickery
905 for(i = 0; i < HUD_PANEL_NUM; ++i)
907 s = strcat(s, ftos(panel_order[i]), " ");
909 cvar_set("_hud_panelorder", s);
910 if(hud_panelorder_prev)
911 strunzone(hud_panelorder_prev);
912 hud_panelorder_prev = strzone(autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here
915 void HUD_Panel_Highlight(float allow_move)
919 while(j < HUD_PANEL_NUM)
924 HUD_Panel_UpdatePosSizeForId(i);
926 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
929 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)
931 highlightedPanel = i;
932 HUD_Panel_FirstInDrawQ(i);
933 highlightedAction = 1;
934 panel_click_distance = mousepos - panel_pos;
937 // resize from topleft border
938 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)
940 highlightedPanel = i;
941 HUD_Panel_FirstInDrawQ(i);
942 highlightedAction = 2;
944 panel_click_distance = mousepos - panel_pos;
945 panel_click_resizeorigin = panel_pos + panel_size;
948 // resize from topright border
949 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)
951 highlightedPanel = i;
952 HUD_Panel_FirstInDrawQ(i);
953 highlightedAction = 2;
955 panel_click_distance_x = panel_size_x - mousepos_x + panel_pos_x;
956 panel_click_distance_y = mousepos_y - panel_pos_y;
957 panel_click_resizeorigin = panel_pos + eY * panel_size_y;
960 // resize from bottomleft border
961 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)
963 highlightedPanel = i;
964 HUD_Panel_FirstInDrawQ(i);
965 highlightedAction = 2;
967 panel_click_distance_x = mousepos_x - panel_pos_x;
968 panel_click_distance_y = panel_size_y - mousepos_y + panel_pos_y;
969 panel_click_resizeorigin = panel_pos + eX * panel_size_x;
972 // resize from bottomright border
973 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)
975 highlightedPanel = i;
976 HUD_Panel_FirstInDrawQ(i);
977 highlightedAction = 2;
979 panel_click_distance = panel_size - mousepos + panel_pos;
980 panel_click_resizeorigin = panel_pos;
984 highlightedPanel = -1;
985 highlightedAction = 0;
988 void HUD_Panel_EnableMenu()
991 menu_enabled_time = time;
992 HUD_Panel_GetName(highlightedPanel);
993 localcmd("menu_showhudoptions ", panel_name, "\n");
995 float mouse_over_panel;
996 void HUD_Panel_Mouse()
998 // 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
999 if (autocvar__menu_alpha == 0 && time - menu_enabled_time > 0.5)
1003 print("menu_enabled: ", ftos(menu_enabled), "\n");
1004 print("Highlighted: ", ftos(highlightedPanel), "\n");
1005 print("Menu alpha: ", ftos(autocvar__menu_alpha), "\n");
1008 // instantly hide the editor cursor if we open the HUDExit dialog
1009 // as hud_fade_alpha doesn't decrease to 0 in this case
1010 // TODO: find a way to fade the cursor out even in this case
1011 if(menu_enabled == 1 || (menu_enabled == 2 && !hud_fade_alpha))
1014 mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
1016 mousepos_x = bound(0, mousepos_x, vid_conwidth);
1017 mousepos_y = bound(0, mousepos_y, vid_conheight);
1021 if(prevMouseClicked == 0)
1023 if (tab_panel != -1)
1025 //stop ctrl-tab selection
1029 HUD_Panel_Highlight(mouseClicked & S_MOUSE1); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
1030 // and calls HUD_Panel_UpdatePosSizeForId() for the highlighted panel
1031 if (highlightedPanel != -1)
1033 highlightedPanel_initial_pos = panel_pos;
1034 highlightedPanel_initial_size = panel_size;
1036 // doubleclick check
1037 if ((mouseClicked & S_MOUSE1) && time - prevMouseClickedTime < 0.4 && highlightedPanel != -1 && prevMouseClickedPos == mousepos)
1039 mouseClicked = 0; // to prevent spam, I guess.
1040 HUD_Panel_EnableMenu();
1044 if (mouseClicked & S_MOUSE1)
1046 prevMouseClickedTime = time;
1047 prevMouseClickedPos = mousepos;
1049 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(mouseClicked & S_MOUSE1);
1053 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1055 if (highlightedPanel != -1)
1057 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1058 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
1060 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
1062 panel_pos_backup = highlightedPanel_initial_pos;
1063 panel_size_backup = highlightedPanel_initial_size;
1064 highlightedPanel_backup = highlightedPanel;
1067 // in case the clicked panel is inside another panel and we aren't
1068 // moving it, avoid the immediate "fix" of its position/size
1069 // (often unwanted and hateful) by disabling collisions check
1070 hud_configure_checkcollisions = false;
1073 if(highlightedAction == 1)
1074 HUD_Panel_SetPos(mousepos - panel_click_distance);
1075 else if(highlightedAction == 2)
1078 if(resizeCorner == 1) {
1079 mySize_x = panel_click_resizeorigin_x - (mousepos_x - panel_click_distance_x);
1080 mySize_y = panel_click_resizeorigin_y - (mousepos_y - panel_click_distance_y);
1081 } else if(resizeCorner == 2) {
1082 mySize_x = mousepos_x + panel_click_distance_x - panel_click_resizeorigin_x;
1083 mySize_y = panel_click_distance_y + panel_click_resizeorigin_y - mousepos_y;
1084 } else if(resizeCorner == 3) {
1085 mySize_x = panel_click_resizeorigin_x + panel_click_distance_x - mousepos_x;
1086 mySize_y = mousepos_y + panel_click_distance_y - panel_click_resizeorigin_y;
1087 } else { // resizeCorner == 4
1088 mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x);
1089 mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y);
1091 HUD_Panel_SetPosSize(mySize);
1096 if(menu_enabled == 2)
1097 mouse_over_panel = 0;
1099 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(TRUE);
1100 if (mouse_over_panel && tab_panel == -1)
1101 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1103 // draw cursor after performing move/resize to have the panel pos/size updated before mouse_over_panel
1104 const vector cursorsize = '32 32 0';
1106 if(!mouse_over_panel)
1107 drawpic(mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1108 else if(mouse_over_panel == 1)
1109 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_move.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1110 else if(mouse_over_panel == 2)
1111 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1113 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize2.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1115 prevMouseClicked = mouseClicked;
1118 const float hlBorderSize = 4;
1119 const string hlBorder = "gfx/hud/default/border_highlighted";
1120 const string hlBorder2 = "gfx/hud/default/border_highlighted2";
1121 void HUD_Panel_HlBorder(float myBorder, vector color, float alpha)
1123 drawfill(panel_pos - '1 1 0' * myBorder, panel_size + '2 2 0' * myBorder, '0 0.5 1', .5 * alpha, DRAWFLAG_NORMAL);
1124 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);
1125 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);
1126 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);
1127 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);