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_color_outofammo");
68 HUD_Write_PanelCvar_q("_complainbubble_color_donthave");
69 HUD_Write_PanelCvar_q("_complainbubble_color_unavailable");
70 HUD_Write_PanelCvar_q("_ammo_color");
71 HUD_Write_PanelCvar_q("_ammo_alpha");
72 HUD_Write_PanelCvar_q("_aspect");
73 HUD_Write_PanelCvar_q("_timeout");
74 HUD_Write_PanelCvar_q("_timeout_effect");
77 HUD_Write_PanelCvar_q("_onlycurrent");
78 HUD_Write_PanelCvar_q("_iconalign");
79 HUD_Write_PanelCvar_q("_progressbar");
80 HUD_Write_PanelCvar_q("_progressbar_name");
81 HUD_Write_PanelCvar_q("_progressbar_xoffset");
82 HUD_Write_PanelCvar_q("_text");
84 case HUD_PANEL_POWERUPS:
85 HUD_Write_PanelCvar_q("_flip");
86 HUD_Write_PanelCvar_q("_iconalign");
87 HUD_Write_PanelCvar_q("_baralign");
88 HUD_Write_PanelCvar_q("_progressbar");
89 HUD_Write_PanelCvar_q("_progressbar_strength");
90 HUD_Write_PanelCvar_q("_progressbar_shield");
92 case HUD_PANEL_HEALTHARMOR:
93 HUD_Write_PanelCvar_q("_flip");
94 HUD_Write_PanelCvar_q("_iconalign");
95 HUD_Write_PanelCvar_q("_baralign");
96 HUD_Write_PanelCvar_q("_progressbar");
97 HUD_Write_PanelCvar_q("_progressbar_health");
98 HUD_Write_PanelCvar_q("_progressbar_armor");
99 HUD_Write_PanelCvar_q("_text");
101 case HUD_PANEL_NOTIFY:
102 HUD_Write_PanelCvar_q("_flip");
103 HUD_Write_PanelCvar_q("_fontsize");
104 HUD_Write_PanelCvar_q("_print");
106 case HUD_PANEL_RADAR:
107 HUD_Write_PanelCvar_q("_foreground_alpha");
110 HUD_Write_PanelCvar_q("_alreadyvoted_alpha");
112 case HUD_PANEL_PRESSEDKEYS:
113 HUD_Write_PanelCvar_q("_aspect");
115 case HUD_PANEL_INFOMESSAGES:
116 HUD_Write_PanelCvar_q("_flip");
118 case HUD_PANEL_PHYSICS:
119 HUD_Write_PanelCvar_q("_flip");
120 HUD_Write_PanelCvar_q("_baralign");
121 HUD_Write_PanelCvar_q("_progressbar");
122 HUD_Write_PanelCvar_q("_acceleration_mode");
124 case HUD_PANEL_CENTERPRINT:
125 HUD_Write_PanelCvar_q("_fontscale");
126 HUD_Write_PanelCvar_q("_time");
131 HUD_Write("menu_sync\n"); // force the menu to reread the cvars, so that the dialogs are updated
133 print(sprintf(_("^2Successfully exported to %s! (Note: It's saved in data/data/)\n"), filename));
137 print(sprintf(_("^1Couldn't write to %s\n"), filename));
140 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
141 vector HUD_Panel_CheckMove(vector myPos, vector mySize)
144 float myCenter_x, myCenter_y, targCenter_x, targCenter_y;
148 for (i = 0; i < HUD_PANEL_NUM; ++i) {
149 if(i == highlightedPanel || !panel_enabled)
152 HUD_Panel_UpdatePosSizeForId(i);
154 panel_pos -= '1 1 0' * panel_bg_border;
155 panel_size += '2 2 0' * panel_bg_border;
157 if(myPos_y + mySize_y < panel_pos_y)
159 if(myPos_y > panel_pos_y + panel_size_y)
162 if(myPos_x + mySize_x < panel_pos_x)
164 if(myPos_x > panel_pos_x + panel_size_x)
167 // OK, there IS a collision.
169 myCenter_x = myPos_x + 0.5 * mySize_x;
170 myCenter_y = myPos_y + 0.5 * mySize_y;
172 targCenter_x = panel_pos_x + 0.5 * panel_size_x;
173 targCenter_y = panel_pos_y + 0.5 * panel_size_y;
175 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
177 if(myPos_x + mySize_x - panel_pos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
178 myTarget_x = panel_pos_x - mySize_x;
179 else // push it upwards
180 myTarget_y = panel_pos_y - mySize_y;
182 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
184 if(panel_pos_x + panel_size_x - myPos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
185 myTarget_x = panel_pos_x + panel_size_x;
186 else // push it upwards
187 myTarget_y = panel_pos_y - mySize_y;
189 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
191 if(myPos_x + mySize_x - panel_pos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
192 myTarget_x = panel_pos_x - mySize_x;
193 else // push it downwards
194 myTarget_y = panel_pos_y + panel_size_y;
196 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
198 if(panel_pos_x + panel_size_x - myPos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
199 myTarget_x = panel_pos_x + panel_size_x;
200 else // push it downwards
201 myTarget_y = panel_pos_y + panel_size_y;
203 //if(cvar("hud_configure_checkcollisions_debug"))
204 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
210 void HUD_Panel_SetPos(vector pos)
212 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
216 //if(cvar("hud_configure_checkcollisions_debug"))
217 //drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
219 if(autocvar_hud_configure_grid)
221 pos_x = floor((pos_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
222 pos_y = floor((pos_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
225 if(hud_configure_checkcollisions)
226 pos = HUD_Panel_CheckMove(pos, mySize);
228 pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
229 pos_y = bound(0, pos_y, vid_conheight - mySize_y);
232 s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
234 HUD_Panel_GetName(highlightedPanel);
235 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
238 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
239 vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
244 float dist_x, dist_y;
246 ratio = mySize_x/mySize_y;
248 for (i = 0; i < HUD_PANEL_NUM; ++i) {
249 if(i == highlightedPanel || !panel_enabled)
252 HUD_Panel_UpdatePosSizeForId(i);
254 panel_pos -= '1 1 0' * panel_bg_border;
255 panel_size += '2 2 0' * panel_bg_border;
257 targEndPos = panel_pos + panel_size;
259 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
260 if(resizeorigin_x > panel_pos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > panel_pos_y && resizeorigin_y < targEndPos_y)
263 if (resizeCorner == 1)
265 // check if this panel is on our way
266 if (resizeorigin_x <= panel_pos_x)
268 if (resizeorigin_y <= panel_pos_y)
270 if (targEndPos_x <= resizeorigin_x - mySize_x)
272 if (targEndPos_y <= resizeorigin_y - mySize_y)
275 // there is a collision:
276 // detect which side of the panel we are facing is actually limiting the resizing
277 // (which side the resize direction finds for first) and reduce the size up to there
279 // dist is the distance between resizeorigin and the "analogous" point of the panel
280 // in this case between resizeorigin (bottom-right point) and the bottom-right point of the panel
281 dist_x = resizeorigin_x - targEndPos_x;
282 dist_y = resizeorigin_y - targEndPos_y;
283 if (dist_y <= 0 || dist_x / dist_y > ratio)
284 mySize_x = min(mySize_x, dist_x);
286 mySize_y = min(mySize_y, dist_y);
288 else if (resizeCorner == 2)
290 if (resizeorigin_x >= targEndPos_x)
292 if (resizeorigin_y <= panel_pos_y)
294 if (panel_pos_x >= resizeorigin_x + mySize_x)
296 if (targEndPos_y <= resizeorigin_y - mySize_y)
299 dist_x = panel_pos_x - resizeorigin_x;
300 dist_y = resizeorigin_y - targEndPos_y;
301 if (dist_y <= 0 || dist_x / dist_y > ratio)
302 mySize_x = min(mySize_x, dist_x);
304 mySize_y = min(mySize_y, dist_y);
306 else if (resizeCorner == 3)
308 if (resizeorigin_x <= panel_pos_x)
310 if (resizeorigin_y >= targEndPos_y)
312 if (targEndPos_x <= resizeorigin_x - mySize_x)
314 if (panel_pos_y >= resizeorigin_y + mySize_y)
317 dist_x = resizeorigin_x - targEndPos_x;
318 dist_y = panel_pos_y - resizeorigin_y;
319 if (dist_y <= 0 || dist_x / dist_y > ratio)
320 mySize_x = min(mySize_x, dist_x);
322 mySize_y = min(mySize_y, dist_y);
324 else if (resizeCorner == 4)
326 if (resizeorigin_x >= targEndPos_x)
328 if (resizeorigin_y >= targEndPos_y)
330 if (panel_pos_x >= resizeorigin_x + mySize_x)
332 if (panel_pos_y >= resizeorigin_y + mySize_y)
335 dist_x = panel_pos_x - resizeorigin_x;
336 dist_y = panel_pos_y - resizeorigin_y;
337 if (dist_y <= 0 || dist_x / dist_y > ratio)
338 mySize_x = min(mySize_x, dist_x);
340 mySize_y = min(mySize_y, dist_y);
342 //if(cvar("hud_configure_checkcollisions_debug"))
343 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
349 void HUD_Panel_SetPosSize(vector mySize)
351 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
353 resizeorigin = panel_click_resizeorigin;
356 // minimum panel size cap
357 mySize_x = max(0.025 * vid_conwidth, mySize_x);
358 mySize_y = max(0.025 * vid_conheight, mySize_y);
360 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.
362 mySize_x = max(17 * autocvar_con_chatsize, mySize_x);
363 mySize_y = max(2 * autocvar_con_chatsize + 2 * panel_bg_padding, mySize_y);
366 // collision testing|
367 // -----------------+
369 // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
370 if(resizeCorner == 1) {
371 myPos_x = resizeorigin_x - mySize_x;
372 myPos_y = resizeorigin_y - mySize_y;
373 } else if(resizeCorner == 2) {
374 myPos_x = resizeorigin_x;
375 myPos_y = resizeorigin_y - mySize_y;
376 } else if(resizeCorner == 3) {
377 myPos_x = resizeorigin_x - mySize_x;
378 myPos_y = resizeorigin_y;
379 } else { // resizeCorner == 4
380 myPos_x = resizeorigin_x;
381 myPos_y = resizeorigin_y;
384 // left/top screen edges
386 mySize_x = mySize_x + myPos_x;
388 mySize_y = mySize_y + myPos_y;
390 // bottom/right screen edges
391 if(myPos_x + mySize_x > vid_conwidth)
392 mySize_x = vid_conwidth - myPos_x;
393 if(myPos_y + mySize_y > vid_conheight)
394 mySize_y = vid_conheight - myPos_y;
396 //if(cvar("hud_configure_checkcollisions_debug"))
397 //drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
399 // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
400 if(autocvar_hud_configure_grid)
402 mySize_x = floor((mySize_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
403 mySize_y = floor((mySize_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
406 if(hud_configure_checkcollisions)
407 mySize = HUD_Panel_CheckResize(mySize, resizeorigin);
409 // 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)
410 mySize_x = max(0.025 * vid_conwidth, mySize_x);
411 mySize_y = max(0.025 * vid_conheight, mySize_y);
413 // do another pos check, as size might have changed by now
414 if(resizeCorner == 1) {
415 myPos_x = resizeorigin_x - mySize_x;
416 myPos_y = resizeorigin_y - mySize_y;
417 } else if(resizeCorner == 2) {
418 myPos_x = resizeorigin_x;
419 myPos_y = resizeorigin_y - mySize_y;
420 } else if(resizeCorner == 3) {
421 myPos_x = resizeorigin_x - mySize_x;
422 myPos_y = resizeorigin_y;
423 } else { // resizeCorner == 4
424 myPos_x = resizeorigin_x;
425 myPos_y = resizeorigin_y;
428 //if(cvar("hud_configure_checkcollisions_debug"))
429 //drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
431 HUD_Panel_GetName(highlightedPanel);
433 s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
434 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
436 s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
437 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
440 float pressed_key_time;
441 vector highlightedPanel_initial_pos, highlightedPanel_initial_size;
442 void HUD_Panel_Arrow_Action(float nPrimary)
444 if (highlightedPanel == -1)
447 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
450 if(autocvar_hud_configure_grid)
452 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
454 if (hudShiftState & S_SHIFT)
455 step = hud_configure_realGridSize_y;
457 step = 2 * hud_configure_realGridSize_y;
461 if (hudShiftState & S_SHIFT)
462 step = hud_configure_realGridSize_x;
464 step = 2 * hud_configure_realGridSize_x;
469 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
470 step = vid_conheight;
473 if (hudShiftState & S_SHIFT)
474 step = (step / 256); // more precision
476 step = (step / 64) * (1 + 2 * (time - pressed_key_time));
479 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
481 highlightedPanel_initial_pos = panel_pos;
482 highlightedPanel_initial_size = panel_size;
484 if (hudShiftState & S_ALT) // resize
486 highlightedAction = 1;
487 if(nPrimary == K_UPARROW)
489 else if(nPrimary == K_RIGHTARROW)
491 else if(nPrimary == K_LEFTARROW)
493 else // if(nPrimary == K_DOWNARROW)
496 // ctrl+arrow reduces the size, instead of increasing it
497 // Note that ctrl disables collisions check too, but it's fine
498 // since we don't collide with anything reducing the size
499 if (hudShiftState & S_CTRL) {
501 resizeCorner = 5 - resizeCorner;
506 panel_click_resizeorigin = panel_pos;
507 if(resizeCorner == 1) {
508 panel_click_resizeorigin += mySize;
510 } else if(resizeCorner == 2) {
511 panel_click_resizeorigin_y += mySize_y;
513 } else if(resizeCorner == 3) {
514 panel_click_resizeorigin_x += mySize_x;
516 } else { // resizeCorner == 4
519 HUD_Panel_SetPosSize(mySize);
523 highlightedAction = 2;
526 if(nPrimary == K_UPARROW)
528 else if(nPrimary == K_DOWNARROW)
530 else if(nPrimary == K_LEFTARROW)
532 else // if(nPrimary == K_RIGHTARROW)
535 HUD_Panel_SetPos(pos);
538 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
540 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
543 panel_pos_backup = highlightedPanel_initial_pos;
544 panel_size_backup = highlightedPanel_initial_size;
545 highlightedPanel_backup = highlightedPanel;
549 const float S_MOUSE1 = 1;
550 const float S_MOUSE2 = 2;
551 const float S_MOUSE3 = 4;
553 float prevMouseClicked; // previous state
554 float prevMouseClickedTime; // time during previous left mouse click, to check for doubleclicks
555 vector prevMouseClickedPos; // pos during previous left mouse click, to check for doubleclicks
557 void HUD_Panel_EnableMenu();
558 float tab_panels[HUD_PANEL_NUM];
559 float tab_panel, tab_backward;
560 vector tab_panel_pos;
561 void HUD_Panel_FirstInDrawQ(float id);
562 void reset_tab_panels()
565 for(i = 0; i < HUD_PANEL_NUM; ++i)
568 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
572 if(!autocvar__hud_configure)
575 // allow console bind to work
578 con_keys = findkeysforcommand("toggleconsole");
579 keys = tokenize(con_keys);
581 float hit_con_bind, i;
582 for (i = 0; i < keys; ++i)
584 if(nPrimary == stof(argv(i)))
588 if(bInputType == 0) {
589 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
590 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
591 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
593 else if(bInputType == 1) {
594 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
595 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
596 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
599 if(nPrimary == K_CTRL)
601 if (bInputType == 1) //ctrl has been released
605 //switch to selected panel
606 highlightedPanel = tab_panel;
607 highlightedAction = 0;
608 HUD_Panel_FirstInDrawQ(highlightedPanel);
615 if(nPrimary == K_MOUSE1)
617 if(bInputType == 0) // key pressed
618 mouseClicked |= S_MOUSE1;
619 else if(bInputType == 1) // key released
620 mouseClicked -= (mouseClicked & S_MOUSE1);
622 else if(nPrimary == K_MOUSE2)
624 if(bInputType == 0) // key pressed
625 mouseClicked |= S_MOUSE2;
626 else if(bInputType == 1) // key released
627 mouseClicked -= (mouseClicked & S_MOUSE2);
629 else if(nPrimary == K_ESCAPE)
634 menu_enabled_time = time;
635 localcmd("menu_showhudexit\n");
637 else if(nPrimary == K_BACKSPACE && hudShiftState & S_CTRL)
642 cvar_set("_hud_configure", "0");
644 else if(nPrimary == K_TAB && hudShiftState & S_CTRL) // select and highlight another panel
646 if (bInputType == 1 || mouseClicked)
649 //FIXME: if a panel is highlighted, has the same pos_x and lays in the same level
650 //of other panels then next consecutive ctrl-tab will select the highlighted panel too
651 //(it should only after every other panel of the hud)
652 //It's a minor bug anyway, we can live with it
654 float starting_panel;
655 float old_tab_panel = tab_panel;
656 if (tab_panel == -1) //first press of TAB
658 if (highlightedPanel != -1)
659 HUD_Panel_UpdatePosSizeForId(highlightedPanel)
662 starting_panel = highlightedPanel; //can be -1, it means no starting panel
663 tab_panel_pos = panel_pos; //to compute level
667 if ( ((!tab_backward) && (hudShiftState & S_SHIFT)) || (tab_backward && !(hudShiftState & S_SHIFT)) ) //tab direction changed?
669 starting_panel = tab_panel;
671 tab_backward = (hudShiftState & S_SHIFT);
673 float k, level, start_pos_x;
674 vector candidate_pos;
675 const float LEVELS_NUM = 4;
676 const float level_height = vid_conheight / LEVELS_NUM;
678 level = floor(tab_panel_pos_y / level_height) * level_height; //starting level
679 candidate_pos_x = (!tab_backward) ? vid_conwidth : 0;
680 start_pos_x = tab_panel_pos_x;
685 for(i = 0; i < HUD_PANEL_NUM; ++i)
687 if (i == tab_panels[i] || i == starting_panel)
689 HUD_Panel_UpdatePosSizeForId(i)
690 if (panel_pos_y >= level && (panel_pos_y - level) < level_height)
691 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)) )
692 || ( 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)) ) )
695 tab_panel_pos = candidate_pos = panel_pos;
700 if (k == LEVELS_NUM) //tab_panel not found
703 if (old_tab_panel == -2) //this prevents an infinite loop (should not happen normally)
708 starting_panel = old_tab_panel;
710 goto find_tab_panel; //u must find tab_panel!
714 level = mod(level + level_height, vid_conheight);
716 candidate_pos_x = vid_conwidth;
720 level = mod(level - level_height, vid_conheight);
721 start_pos_x = vid_conwidth;
726 tab_panels[tab_panel] = tab_panel;
728 else if(nPrimary == K_SPACE && hudShiftState & S_CTRL) // enable/disable highlighted panel or dock
730 if (bInputType == 1 || mouseClicked)
733 if (highlightedPanel != -1)
735 HUD_Panel_GetName(highlightedPanel);
736 cvar_set(strcat("hud_panel_", panel_name), ftos(!(panel_enabled)));
739 cvar_set(strcat("hud_dock"), (autocvar_hud_dock == "") ? "dock" : "");
741 else if(nPrimary == 'c' && hudShiftState & S_CTRL) // copy highlighted panel size
743 if (bInputType == 1 || mouseClicked)
746 if (highlightedPanel != -1)
748 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
749 panel_size_copied = panel_size;
750 highlightedPanel_copied = highlightedPanel;
753 else if(nPrimary == 'v' && hudShiftState & S_CTRL) // past copied size on the highlighted panel
755 if (bInputType == 1 || mouseClicked)
758 if (highlightedPanel_copied == -1 || highlightedPanel == -1)
761 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
763 // reduce size if it'd go beyond screen boundaries
764 vector tmp_size = panel_size_copied;
765 if (panel_pos_x + panel_size_copied_x > vid_conwidth)
766 tmp_size_x = vid_conwidth - panel_pos_x;
767 if (panel_pos_y + panel_size_copied_y > vid_conheight)
768 tmp_size_y = vid_conheight - panel_pos_y;
770 if (panel_size == tmp_size)
774 panel_pos_backup = panel_pos;
775 panel_size_backup = panel_size;
776 highlightedPanel_backup = highlightedPanel;
778 s = strcat(ftos(tmp_size_x/vid_conwidth), " ", ftos(tmp_size_y/vid_conheight));
779 HUD_Panel_GetName(highlightedPanel);
780 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
782 else if(nPrimary == 'z' && hudShiftState & S_CTRL) // undo last action
784 if (bInputType == 1 || mouseClicked)
786 //restore previous values
787 if (highlightedPanel_backup != -1)
789 HUD_Panel_GetName(highlightedPanel_backup);
790 s = strcat(ftos(panel_pos_backup_x/vid_conwidth), " ", ftos(panel_pos_backup_y/vid_conheight));
791 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
792 s = strcat(ftos(panel_size_backup_x/vid_conwidth), " ", ftos(panel_size_backup_y/vid_conheight));
793 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
794 highlightedPanel_backup = -1;
797 else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
801 pressed_key_time = 0;
804 else if (pressed_key_time == 0)
805 pressed_key_time = time;
808 HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
810 else if(nPrimary == K_ENTER || nPrimary == K_SPACE || nPrimary == K_KP_ENTER)
814 if (highlightedPanel != -1)
815 HUD_Panel_EnableMenu();
817 else if(hit_con_bind)
823 float HUD_Panel_Check_Mouse_Pos(float allow_move)
827 while(j < HUD_PANEL_NUM)
832 HUD_Panel_UpdatePosSizeForId(i);
834 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
837 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)
841 // resize from topleft border
842 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)
846 // resize from topright border
847 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)
851 // resize from bottomleft border
852 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)
856 // resize from bottomright border
857 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)
865 // move a panel to the beginning of the panel order array (which means it gets drawn last, on top of everything else)
866 void HUD_Panel_FirstInDrawQ(float id)
869 var float place = -1;
870 // find out where in the array our current id is, save into place
871 for(i = 0; i < HUD_PANEL_NUM; ++i)
873 if(panel_order[i] == id)
879 // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
881 place = HUD_PANEL_NUM - 1;
883 // move all ids up by one step in the array until "place"
884 for(i = place; i > 0; --i)
886 panel_order[i] = panel_order[i-1];
888 // now save the new top id
891 // let's save them into the cvar by some strcat trickery
893 for(i = 0; i < HUD_PANEL_NUM; ++i)
895 s = strcat(s, ftos(panel_order[i]), " ");
897 cvar_set("_hud_panelorder", s);
898 if(hud_panelorder_prev)
899 strunzone(hud_panelorder_prev);
900 hud_panelorder_prev = strzone(autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here
903 void HUD_Panel_Highlight(float allow_move)
907 while(j < HUD_PANEL_NUM)
912 HUD_Panel_UpdatePosSizeForId(i);
914 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
917 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)
919 highlightedPanel = i;
920 HUD_Panel_FirstInDrawQ(i);
921 highlightedAction = 1;
922 panel_click_distance = mousepos - panel_pos;
925 // resize from topleft border
926 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)
928 highlightedPanel = i;
929 HUD_Panel_FirstInDrawQ(i);
930 highlightedAction = 2;
932 panel_click_distance = mousepos - panel_pos;
933 panel_click_resizeorigin = panel_pos + panel_size;
936 // resize from topright border
937 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)
939 highlightedPanel = i;
940 HUD_Panel_FirstInDrawQ(i);
941 highlightedAction = 2;
943 panel_click_distance_x = panel_size_x - mousepos_x + panel_pos_x;
944 panel_click_distance_y = mousepos_y - panel_pos_y;
945 panel_click_resizeorigin = panel_pos + eY * panel_size_y;
948 // resize from bottomleft border
949 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)
951 highlightedPanel = i;
952 HUD_Panel_FirstInDrawQ(i);
953 highlightedAction = 2;
955 panel_click_distance_x = mousepos_x - panel_pos_x;
956 panel_click_distance_y = panel_size_y - mousepos_y + panel_pos_y;
957 panel_click_resizeorigin = panel_pos + eX * panel_size_x;
960 // resize from bottomright border
961 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)
963 highlightedPanel = i;
964 HUD_Panel_FirstInDrawQ(i);
965 highlightedAction = 2;
967 panel_click_distance = panel_size - mousepos + panel_pos;
968 panel_click_resizeorigin = panel_pos;
972 highlightedPanel = -1;
973 highlightedAction = 0;
976 void HUD_Panel_EnableMenu()
979 menu_enabled_time = time;
980 HUD_Panel_GetName(highlightedPanel);
981 localcmd("menu_showhudoptions ", panel_name, "\n");
983 float mouse_over_panel;
984 void HUD_Panel_Mouse()
986 // 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
987 if (autocvar__menu_alpha == 0 && time - menu_enabled_time > 0.5)
991 print("menu_enabled: ", ftos(menu_enabled), "\n");
992 print("Highlighted: ", ftos(highlightedPanel), "\n");
993 print("Menu alpha: ", ftos(autocvar__menu_alpha), "\n");
996 // instantly hide the editor cursor if we open the HUDExit dialog
997 // as hud_fade_alpha doesn't decrease to 0 in this case
998 // TODO: find a way to fade the cursor out even in this case
999 if(menu_enabled == 1 || (menu_enabled == 2 && !hud_fade_alpha))
1002 mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
1004 mousepos_x = bound(0, mousepos_x, vid_conwidth);
1005 mousepos_y = bound(0, mousepos_y, vid_conheight);
1009 if(prevMouseClicked == 0)
1011 if (tab_panel != -1)
1013 //stop ctrl-tab selection
1017 HUD_Panel_Highlight(mouseClicked & S_MOUSE1); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
1018 // and calls HUD_Panel_UpdatePosSizeForId() for the highlighted panel
1019 if (highlightedPanel != -1)
1021 highlightedPanel_initial_pos = panel_pos;
1022 highlightedPanel_initial_size = panel_size;
1024 // doubleclick check
1025 if ((mouseClicked & S_MOUSE1) && time - prevMouseClickedTime < 0.4 && highlightedPanel != -1 && prevMouseClickedPos == mousepos)
1027 mouseClicked = 0; // to prevent spam, I guess.
1028 HUD_Panel_EnableMenu();
1032 if (mouseClicked & S_MOUSE1)
1034 prevMouseClickedTime = time;
1035 prevMouseClickedPos = mousepos;
1037 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(mouseClicked & S_MOUSE1);
1041 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1043 if (highlightedPanel != -1)
1045 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1046 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
1048 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
1050 panel_pos_backup = highlightedPanel_initial_pos;
1051 panel_size_backup = highlightedPanel_initial_size;
1052 highlightedPanel_backup = highlightedPanel;
1055 // in case the clicked panel is inside another panel and we aren't
1056 // moving it, avoid the immediate "fix" of its position/size
1057 // (often unwanted and hateful) by disabling collisions check
1058 hud_configure_checkcollisions = false;
1061 if(highlightedAction == 1)
1062 HUD_Panel_SetPos(mousepos - panel_click_distance);
1063 else if(highlightedAction == 2)
1066 if(resizeCorner == 1) {
1067 mySize_x = panel_click_resizeorigin_x - (mousepos_x - panel_click_distance_x);
1068 mySize_y = panel_click_resizeorigin_y - (mousepos_y - panel_click_distance_y);
1069 } else if(resizeCorner == 2) {
1070 mySize_x = mousepos_x + panel_click_distance_x - panel_click_resizeorigin_x;
1071 mySize_y = panel_click_distance_y + panel_click_resizeorigin_y - mousepos_y;
1072 } else if(resizeCorner == 3) {
1073 mySize_x = panel_click_resizeorigin_x + panel_click_distance_x - mousepos_x;
1074 mySize_y = mousepos_y + panel_click_distance_y - panel_click_resizeorigin_y;
1075 } else { // resizeCorner == 4
1076 mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x);
1077 mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y);
1079 HUD_Panel_SetPosSize(mySize);
1084 if(menu_enabled == 2)
1085 mouse_over_panel = 0;
1087 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(TRUE);
1088 if (mouse_over_panel && tab_panel == -1)
1089 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1091 // draw cursor after performing move/resize to have the panel pos/size updated before mouse_over_panel
1092 const vector cursorsize = '32 32 0';
1094 if(!mouse_over_panel)
1095 drawpic(mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1096 else if(mouse_over_panel == 1)
1097 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_move.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1098 else if(mouse_over_panel == 2)
1099 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1101 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize2.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1103 prevMouseClicked = mouseClicked;
1106 const float hlBorderSize = 4;
1107 const string hlBorder = "gfx/hud/default/border_highlighted";
1108 const string hlBorder2 = "gfx/hud/default/border_highlighted2";
1109 void HUD_Panel_HlBorder(float myBorder, vector color, float alpha)
1111 drawfill(panel_pos - '1 1 0' * myBorder, panel_size + '2 2 0' * myBorder, '0 0.5 1', .5 * alpha, DRAWFLAG_NORMAL);
1112 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);
1113 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);
1114 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);
1115 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);