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("_align");
126 HUD_Write_PanelCvar_q("_fontscale");
127 HUD_Write_PanelCvar_q("_time");
132 HUD_Write("menu_sync\n"); // force the menu to reread the cvars, so that the dialogs are updated
134 print(sprintf(_("^2Successfully exported to %s! (Note: It's saved in data/data/)\n"), filename));
138 print(sprintf(_("^1Couldn't write to %s\n"), filename));
141 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
142 vector HUD_Panel_CheckMove(vector myPos, vector mySize)
145 float myCenter_x, myCenter_y, targCenter_x, targCenter_y;
149 for (i = 0; i < HUD_PANEL_NUM; ++i) {
150 if(i == highlightedPanel || !panel_enabled)
153 HUD_Panel_UpdatePosSizeForId(i);
155 panel_pos -= '1 1 0' * panel_bg_border;
156 panel_size += '2 2 0' * panel_bg_border;
158 if(myPos_y + mySize_y < panel_pos_y)
160 if(myPos_y > panel_pos_y + panel_size_y)
163 if(myPos_x + mySize_x < panel_pos_x)
165 if(myPos_x > panel_pos_x + panel_size_x)
168 // OK, there IS a collision.
170 myCenter_x = myPos_x + 0.5 * mySize_x;
171 myCenter_y = myPos_y + 0.5 * mySize_y;
173 targCenter_x = panel_pos_x + 0.5 * panel_size_x;
174 targCenter_y = panel_pos_y + 0.5 * panel_size_y;
176 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
178 if(myPos_x + mySize_x - panel_pos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
179 myTarget_x = panel_pos_x - mySize_x;
180 else // push it upwards
181 myTarget_y = panel_pos_y - mySize_y;
183 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
185 if(panel_pos_x + panel_size_x - myPos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
186 myTarget_x = panel_pos_x + panel_size_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) // bottom left
192 if(myPos_x + mySize_x - panel_pos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
193 myTarget_x = panel_pos_x - mySize_x;
194 else // push it downwards
195 myTarget_y = panel_pos_y + panel_size_y;
197 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
199 if(panel_pos_x + panel_size_x - myPos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
200 myTarget_x = panel_pos_x + panel_size_x;
201 else // push it downwards
202 myTarget_y = panel_pos_y + panel_size_y;
204 //if(cvar("hud_configure_checkcollisions_debug"))
205 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
211 void HUD_Panel_SetPos(vector pos)
213 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
217 //if(cvar("hud_configure_checkcollisions_debug"))
218 //drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
220 if(autocvar_hud_configure_grid)
222 pos_x = floor((pos_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
223 pos_y = floor((pos_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
226 if(hud_configure_checkcollisions)
227 pos = HUD_Panel_CheckMove(pos, mySize);
229 pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
230 pos_y = bound(0, pos_y, vid_conheight - mySize_y);
233 s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
235 HUD_Panel_GetName(highlightedPanel);
236 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
239 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
240 vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
245 float dist_x, dist_y;
247 ratio = mySize_x/mySize_y;
249 for (i = 0; i < HUD_PANEL_NUM; ++i) {
250 if(i == highlightedPanel || !panel_enabled)
253 HUD_Panel_UpdatePosSizeForId(i);
255 panel_pos -= '1 1 0' * panel_bg_border;
256 panel_size += '2 2 0' * panel_bg_border;
258 targEndPos = panel_pos + panel_size;
260 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
261 if(resizeorigin_x > panel_pos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > panel_pos_y && resizeorigin_y < targEndPos_y)
264 if (resizeCorner == 1)
266 // check if this panel is on our way
267 if (resizeorigin_x <= panel_pos_x)
269 if (resizeorigin_y <= panel_pos_y)
271 if (targEndPos_x <= resizeorigin_x - mySize_x)
273 if (targEndPos_y <= resizeorigin_y - mySize_y)
276 // there is a collision:
277 // detect which side of the panel we are facing is actually limiting the resizing
278 // (which side the resize direction finds for first) and reduce the size up to there
280 // dist is the distance between resizeorigin and the "analogous" point of the panel
281 // in this case between resizeorigin (bottom-right point) and the bottom-right point of the panel
282 dist_x = resizeorigin_x - targEndPos_x;
283 dist_y = resizeorigin_y - targEndPos_y;
284 if (dist_y <= 0 || dist_x / dist_y > ratio)
285 mySize_x = min(mySize_x, dist_x);
287 mySize_y = min(mySize_y, dist_y);
289 else if (resizeCorner == 2)
291 if (resizeorigin_x >= targEndPos_x)
293 if (resizeorigin_y <= panel_pos_y)
295 if (panel_pos_x >= resizeorigin_x + mySize_x)
297 if (targEndPos_y <= resizeorigin_y - mySize_y)
300 dist_x = panel_pos_x - resizeorigin_x;
301 dist_y = resizeorigin_y - targEndPos_y;
302 if (dist_y <= 0 || dist_x / dist_y > ratio)
303 mySize_x = min(mySize_x, dist_x);
305 mySize_y = min(mySize_y, dist_y);
307 else if (resizeCorner == 3)
309 if (resizeorigin_x <= panel_pos_x)
311 if (resizeorigin_y >= targEndPos_y)
313 if (targEndPos_x <= resizeorigin_x - mySize_x)
315 if (panel_pos_y >= resizeorigin_y + mySize_y)
318 dist_x = resizeorigin_x - targEndPos_x;
319 dist_y = panel_pos_y - resizeorigin_y;
320 if (dist_y <= 0 || dist_x / dist_y > ratio)
321 mySize_x = min(mySize_x, dist_x);
323 mySize_y = min(mySize_y, dist_y);
325 else if (resizeCorner == 4)
327 if (resizeorigin_x >= targEndPos_x)
329 if (resizeorigin_y >= targEndPos_y)
331 if (panel_pos_x >= resizeorigin_x + mySize_x)
333 if (panel_pos_y >= resizeorigin_y + mySize_y)
336 dist_x = panel_pos_x - resizeorigin_x;
337 dist_y = panel_pos_y - resizeorigin_y;
338 if (dist_y <= 0 || dist_x / dist_y > ratio)
339 mySize_x = min(mySize_x, dist_x);
341 mySize_y = min(mySize_y, dist_y);
343 //if(cvar("hud_configure_checkcollisions_debug"))
344 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
350 void HUD_Panel_SetPosSize(vector mySize)
352 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
354 resizeorigin = panel_click_resizeorigin;
357 // minimum panel size cap
358 mySize_x = max(0.025 * vid_conwidth, mySize_x);
359 mySize_y = max(0.025 * vid_conheight, mySize_y);
361 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.
363 mySize_x = max(17 * autocvar_con_chatsize, mySize_x);
364 mySize_y = max(2 * autocvar_con_chatsize + 2 * panel_bg_padding, mySize_y);
367 // collision testing|
368 // -----------------+
370 // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
371 if(resizeCorner == 1) {
372 myPos_x = resizeorigin_x - mySize_x;
373 myPos_y = resizeorigin_y - mySize_y;
374 } else if(resizeCorner == 2) {
375 myPos_x = resizeorigin_x;
376 myPos_y = resizeorigin_y - mySize_y;
377 } else if(resizeCorner == 3) {
378 myPos_x = resizeorigin_x - mySize_x;
379 myPos_y = resizeorigin_y;
380 } else { // resizeCorner == 4
381 myPos_x = resizeorigin_x;
382 myPos_y = resizeorigin_y;
385 // left/top screen edges
387 mySize_x = mySize_x + myPos_x;
389 mySize_y = mySize_y + myPos_y;
391 // bottom/right screen edges
392 if(myPos_x + mySize_x > vid_conwidth)
393 mySize_x = vid_conwidth - myPos_x;
394 if(myPos_y + mySize_y > vid_conheight)
395 mySize_y = vid_conheight - myPos_y;
397 //if(cvar("hud_configure_checkcollisions_debug"))
398 //drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
400 // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
401 if(autocvar_hud_configure_grid)
403 mySize_x = floor((mySize_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
404 mySize_y = floor((mySize_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
407 if(hud_configure_checkcollisions)
408 mySize = HUD_Panel_CheckResize(mySize, resizeorigin);
410 // 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)
411 mySize_x = max(0.025 * vid_conwidth, mySize_x);
412 mySize_y = max(0.025 * vid_conheight, mySize_y);
414 // do another pos check, as size might have changed by now
415 if(resizeCorner == 1) {
416 myPos_x = resizeorigin_x - mySize_x;
417 myPos_y = resizeorigin_y - mySize_y;
418 } else if(resizeCorner == 2) {
419 myPos_x = resizeorigin_x;
420 myPos_y = resizeorigin_y - mySize_y;
421 } else if(resizeCorner == 3) {
422 myPos_x = resizeorigin_x - mySize_x;
423 myPos_y = resizeorigin_y;
424 } else { // resizeCorner == 4
425 myPos_x = resizeorigin_x;
426 myPos_y = resizeorigin_y;
429 //if(cvar("hud_configure_checkcollisions_debug"))
430 //drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
432 HUD_Panel_GetName(highlightedPanel);
434 s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
435 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
437 s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
438 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
441 float pressed_key_time;
442 vector highlightedPanel_initial_pos, highlightedPanel_initial_size;
443 void HUD_Panel_Arrow_Action(float nPrimary)
445 if (highlightedPanel == -1)
448 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
451 if(autocvar_hud_configure_grid)
453 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
455 if (hudShiftState & S_SHIFT)
456 step = hud_configure_realGridSize_y;
458 step = 2 * hud_configure_realGridSize_y;
462 if (hudShiftState & S_SHIFT)
463 step = hud_configure_realGridSize_x;
465 step = 2 * hud_configure_realGridSize_x;
470 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
471 step = vid_conheight;
474 if (hudShiftState & S_SHIFT)
475 step = (step / 256); // more precision
477 step = (step / 64) * (1 + 2 * (time - pressed_key_time));
480 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
482 highlightedPanel_initial_pos = panel_pos;
483 highlightedPanel_initial_size = panel_size;
485 if (hudShiftState & S_ALT) // resize
487 highlightedAction = 1;
488 if(nPrimary == K_UPARROW)
490 else if(nPrimary == K_RIGHTARROW)
492 else if(nPrimary == K_LEFTARROW)
494 else // if(nPrimary == K_DOWNARROW)
497 // ctrl+arrow reduces the size, instead of increasing it
498 // Note that ctrl disables collisions check too, but it's fine
499 // since we don't collide with anything reducing the size
500 if (hudShiftState & S_CTRL) {
502 resizeCorner = 5 - resizeCorner;
507 panel_click_resizeorigin = panel_pos;
508 if(resizeCorner == 1) {
509 panel_click_resizeorigin += mySize;
511 } else if(resizeCorner == 2) {
512 panel_click_resizeorigin_y += mySize_y;
514 } else if(resizeCorner == 3) {
515 panel_click_resizeorigin_x += mySize_x;
517 } else { // resizeCorner == 4
520 HUD_Panel_SetPosSize(mySize);
524 highlightedAction = 2;
527 if(nPrimary == K_UPARROW)
529 else if(nPrimary == K_DOWNARROW)
531 else if(nPrimary == K_LEFTARROW)
533 else // if(nPrimary == K_RIGHTARROW)
536 HUD_Panel_SetPos(pos);
539 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
541 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
544 panel_pos_backup = highlightedPanel_initial_pos;
545 panel_size_backup = highlightedPanel_initial_size;
546 highlightedPanel_backup = highlightedPanel;
550 const float S_MOUSE1 = 1;
551 const float S_MOUSE2 = 2;
552 const float S_MOUSE3 = 4;
554 float prevMouseClicked; // previous state
555 float prevMouseClickedTime; // time during previous left mouse click, to check for doubleclicks
556 vector prevMouseClickedPos; // pos during previous left mouse click, to check for doubleclicks
558 void HUD_Panel_EnableMenu();
559 float tab_panels[HUD_PANEL_NUM];
560 float tab_panel, tab_backward;
561 vector tab_panel_pos;
562 void HUD_Panel_FirstInDrawQ(float id);
563 void reset_tab_panels()
566 for(i = 0; i < HUD_PANEL_NUM; ++i)
569 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
573 if(!autocvar__hud_configure)
576 // allow console bind to work
579 con_keys = findkeysforcommand("toggleconsole");
580 keys = tokenize(con_keys);
582 float hit_con_bind, i;
583 for (i = 0; i < keys; ++i)
585 if(nPrimary == stof(argv(i)))
589 if(bInputType == 0) {
590 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
591 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
592 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
594 else if(bInputType == 1) {
595 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
596 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
597 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
600 if(nPrimary == K_CTRL)
602 if (bInputType == 1) //ctrl has been released
606 //switch to selected panel
607 highlightedPanel = tab_panel;
608 highlightedAction = 0;
609 HUD_Panel_FirstInDrawQ(highlightedPanel);
616 if(nPrimary == K_MOUSE1)
618 if(bInputType == 0) // key pressed
619 mouseClicked |= S_MOUSE1;
620 else if(bInputType == 1) // key released
621 mouseClicked -= (mouseClicked & S_MOUSE1);
623 else if(nPrimary == K_MOUSE2)
625 if(bInputType == 0) // key pressed
626 mouseClicked |= S_MOUSE2;
627 else if(bInputType == 1) // key released
628 mouseClicked -= (mouseClicked & S_MOUSE2);
630 else if(nPrimary == K_ESCAPE)
635 menu_enabled_time = time;
636 localcmd("menu_showhudexit\n");
638 else if(nPrimary == K_BACKSPACE && hudShiftState & S_CTRL)
643 cvar_set("_hud_configure", "0");
645 else if(nPrimary == K_TAB && hudShiftState & S_CTRL) // select and highlight another panel
647 if (bInputType == 1 || mouseClicked)
650 //FIXME: if a panel is highlighted, has the same pos_x and lays in the same level
651 //of other panels then next consecutive ctrl-tab will select the highlighted panel too
652 //(it should only after every other panel of the hud)
653 //It's a minor bug anyway, we can live with it
655 float starting_panel;
656 float old_tab_panel = tab_panel;
657 if (tab_panel == -1) //first press of TAB
659 if (highlightedPanel != -1)
660 HUD_Panel_UpdatePosSizeForId(highlightedPanel)
663 starting_panel = highlightedPanel; //can be -1, it means no starting panel
664 tab_panel_pos = panel_pos; //to compute level
668 if ( ((!tab_backward) && (hudShiftState & S_SHIFT)) || (tab_backward && !(hudShiftState & S_SHIFT)) ) //tab direction changed?
670 starting_panel = tab_panel;
672 tab_backward = (hudShiftState & S_SHIFT);
674 float k, level, start_pos_x;
675 vector candidate_pos;
676 const float LEVELS_NUM = 4;
677 const float level_height = vid_conheight / LEVELS_NUM;
679 level = floor(tab_panel_pos_y / level_height) * level_height; //starting level
680 candidate_pos_x = (!tab_backward) ? vid_conwidth : 0;
681 start_pos_x = tab_panel_pos_x;
686 for(i = 0; i < HUD_PANEL_NUM; ++i)
688 if (i == tab_panels[i] || i == starting_panel)
690 HUD_Panel_UpdatePosSizeForId(i)
691 if (panel_pos_y >= level && (panel_pos_y - level) < level_height)
692 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)) )
693 || ( 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)) ) )
696 tab_panel_pos = candidate_pos = panel_pos;
701 if (k == LEVELS_NUM) //tab_panel not found
704 if (old_tab_panel == -2) //this prevents an infinite loop (should not happen normally)
709 starting_panel = old_tab_panel;
711 goto find_tab_panel; //u must find tab_panel!
715 level = mod(level + level_height, vid_conheight);
717 candidate_pos_x = vid_conwidth;
721 level = mod(level - level_height, vid_conheight);
722 start_pos_x = vid_conwidth;
727 tab_panels[tab_panel] = tab_panel;
729 else if(nPrimary == K_SPACE && hudShiftState & S_CTRL) // enable/disable highlighted panel or dock
731 if (bInputType == 1 || mouseClicked)
734 if (highlightedPanel != -1)
736 HUD_Panel_GetName(highlightedPanel);
737 cvar_set(strcat("hud_panel_", panel_name), ftos(!(panel_enabled)));
740 cvar_set(strcat("hud_dock"), (autocvar_hud_dock == "") ? "dock" : "");
742 else if(nPrimary == 'c' && hudShiftState & S_CTRL) // copy highlighted panel size
744 if (bInputType == 1 || mouseClicked)
747 if (highlightedPanel != -1)
749 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
750 panel_size_copied = panel_size;
751 highlightedPanel_copied = highlightedPanel;
754 else if(nPrimary == 'v' && hudShiftState & S_CTRL) // past copied size on the highlighted panel
756 if (bInputType == 1 || mouseClicked)
759 if (highlightedPanel_copied == -1 || highlightedPanel == -1)
762 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
764 // reduce size if it'd go beyond screen boundaries
765 vector tmp_size = panel_size_copied;
766 if (panel_pos_x + panel_size_copied_x > vid_conwidth)
767 tmp_size_x = vid_conwidth - panel_pos_x;
768 if (panel_pos_y + panel_size_copied_y > vid_conheight)
769 tmp_size_y = vid_conheight - panel_pos_y;
771 if (panel_size == tmp_size)
775 panel_pos_backup = panel_pos;
776 panel_size_backup = panel_size;
777 highlightedPanel_backup = highlightedPanel;
779 s = strcat(ftos(tmp_size_x/vid_conwidth), " ", ftos(tmp_size_y/vid_conheight));
780 HUD_Panel_GetName(highlightedPanel);
781 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
783 else if(nPrimary == 'z' && hudShiftState & S_CTRL) // undo last action
785 if (bInputType == 1 || mouseClicked)
787 //restore previous values
788 if (highlightedPanel_backup != -1)
790 HUD_Panel_GetName(highlightedPanel_backup);
791 s = strcat(ftos(panel_pos_backup_x/vid_conwidth), " ", ftos(panel_pos_backup_y/vid_conheight));
792 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
793 s = strcat(ftos(panel_size_backup_x/vid_conwidth), " ", ftos(panel_size_backup_y/vid_conheight));
794 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
795 highlightedPanel_backup = -1;
798 else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
802 pressed_key_time = 0;
805 else if (pressed_key_time == 0)
806 pressed_key_time = time;
809 HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
811 else if(nPrimary == K_ENTER || nPrimary == K_SPACE || nPrimary == K_KP_ENTER)
815 if (highlightedPanel != -1)
816 HUD_Panel_EnableMenu();
818 else if(hit_con_bind)
824 float HUD_Panel_Check_Mouse_Pos(float allow_move)
828 while(j < HUD_PANEL_NUM)
833 HUD_Panel_UpdatePosSizeForId(i);
835 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
838 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)
842 // resize from topleft border
843 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)
847 // resize from topright border
848 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)
852 // resize from bottomleft border
853 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)
857 // resize from bottomright border
858 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)
866 // move a panel to the beginning of the panel order array (which means it gets drawn last, on top of everything else)
867 void HUD_Panel_FirstInDrawQ(float id)
870 var float place = -1;
871 // find out where in the array our current id is, save into place
872 for(i = 0; i < HUD_PANEL_NUM; ++i)
874 if(panel_order[i] == id)
880 // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
882 place = HUD_PANEL_NUM - 1;
884 // move all ids up by one step in the array until "place"
885 for(i = place; i > 0; --i)
887 panel_order[i] = panel_order[i-1];
889 // now save the new top id
892 // let's save them into the cvar by some strcat trickery
894 for(i = 0; i < HUD_PANEL_NUM; ++i)
896 s = strcat(s, ftos(panel_order[i]), " ");
898 cvar_set("_hud_panelorder", s);
899 if(hud_panelorder_prev)
900 strunzone(hud_panelorder_prev);
901 hud_panelorder_prev = strzone(autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here
904 void HUD_Panel_Highlight(float allow_move)
908 while(j < HUD_PANEL_NUM)
913 HUD_Panel_UpdatePosSizeForId(i);
915 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
918 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)
920 highlightedPanel = i;
921 HUD_Panel_FirstInDrawQ(i);
922 highlightedAction = 1;
923 panel_click_distance = mousepos - panel_pos;
926 // resize from topleft border
927 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)
929 highlightedPanel = i;
930 HUD_Panel_FirstInDrawQ(i);
931 highlightedAction = 2;
933 panel_click_distance = mousepos - panel_pos;
934 panel_click_resizeorigin = panel_pos + panel_size;
937 // resize from topright border
938 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)
940 highlightedPanel = i;
941 HUD_Panel_FirstInDrawQ(i);
942 highlightedAction = 2;
944 panel_click_distance_x = panel_size_x - mousepos_x + panel_pos_x;
945 panel_click_distance_y = mousepos_y - panel_pos_y;
946 panel_click_resizeorigin = panel_pos + eY * panel_size_y;
949 // resize from bottomleft border
950 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)
952 highlightedPanel = i;
953 HUD_Panel_FirstInDrawQ(i);
954 highlightedAction = 2;
956 panel_click_distance_x = mousepos_x - panel_pos_x;
957 panel_click_distance_y = panel_size_y - mousepos_y + panel_pos_y;
958 panel_click_resizeorigin = panel_pos + eX * panel_size_x;
961 // resize from bottomright border
962 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)
964 highlightedPanel = i;
965 HUD_Panel_FirstInDrawQ(i);
966 highlightedAction = 2;
968 panel_click_distance = panel_size - mousepos + panel_pos;
969 panel_click_resizeorigin = panel_pos;
973 highlightedPanel = -1;
974 highlightedAction = 0;
977 void HUD_Panel_EnableMenu()
980 menu_enabled_time = time;
981 HUD_Panel_GetName(highlightedPanel);
982 localcmd("menu_showhudoptions ", panel_name, "\n");
984 float mouse_over_panel;
985 void HUD_Panel_Mouse()
987 // 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
988 if (autocvar__menu_alpha == 0 && time - menu_enabled_time > 0.5)
992 print("menu_enabled: ", ftos(menu_enabled), "\n");
993 print("Highlighted: ", ftos(highlightedPanel), "\n");
994 print("Menu alpha: ", ftos(autocvar__menu_alpha), "\n");
997 // instantly hide the editor cursor if we open the HUDExit dialog
998 // as hud_fade_alpha doesn't decrease to 0 in this case
999 // TODO: find a way to fade the cursor out even in this case
1000 if(menu_enabled == 1 || (menu_enabled == 2 && !hud_fade_alpha))
1003 mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
1005 mousepos_x = bound(0, mousepos_x, vid_conwidth);
1006 mousepos_y = bound(0, mousepos_y, vid_conheight);
1010 if(prevMouseClicked == 0)
1012 if (tab_panel != -1)
1014 //stop ctrl-tab selection
1018 HUD_Panel_Highlight(mouseClicked & S_MOUSE1); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
1019 // and calls HUD_Panel_UpdatePosSizeForId() for the highlighted panel
1020 if (highlightedPanel != -1)
1022 highlightedPanel_initial_pos = panel_pos;
1023 highlightedPanel_initial_size = panel_size;
1025 // doubleclick check
1026 if ((mouseClicked & S_MOUSE1) && time - prevMouseClickedTime < 0.4 && highlightedPanel != -1 && prevMouseClickedPos == mousepos)
1028 mouseClicked = 0; // to prevent spam, I guess.
1029 HUD_Panel_EnableMenu();
1033 if (mouseClicked & S_MOUSE1)
1035 prevMouseClickedTime = time;
1036 prevMouseClickedPos = mousepos;
1038 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(mouseClicked & S_MOUSE1);
1042 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1044 if (highlightedPanel != -1)
1046 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1047 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
1049 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
1051 panel_pos_backup = highlightedPanel_initial_pos;
1052 panel_size_backup = highlightedPanel_initial_size;
1053 highlightedPanel_backup = highlightedPanel;
1056 // in case the clicked panel is inside another panel and we aren't
1057 // moving it, avoid the immediate "fix" of its position/size
1058 // (often unwanted and hateful) by disabling collisions check
1059 hud_configure_checkcollisions = false;
1062 if(highlightedAction == 1)
1063 HUD_Panel_SetPos(mousepos - panel_click_distance);
1064 else if(highlightedAction == 2)
1067 if(resizeCorner == 1) {
1068 mySize_x = panel_click_resizeorigin_x - (mousepos_x - panel_click_distance_x);
1069 mySize_y = panel_click_resizeorigin_y - (mousepos_y - panel_click_distance_y);
1070 } else if(resizeCorner == 2) {
1071 mySize_x = mousepos_x + panel_click_distance_x - panel_click_resizeorigin_x;
1072 mySize_y = panel_click_distance_y + panel_click_resizeorigin_y - mousepos_y;
1073 } else if(resizeCorner == 3) {
1074 mySize_x = panel_click_resizeorigin_x + panel_click_distance_x - mousepos_x;
1075 mySize_y = mousepos_y + panel_click_distance_y - panel_click_resizeorigin_y;
1076 } else { // resizeCorner == 4
1077 mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x);
1078 mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y);
1080 HUD_Panel_SetPosSize(mySize);
1085 if(menu_enabled == 2)
1086 mouse_over_panel = 0;
1088 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(TRUE);
1089 if (mouse_over_panel && tab_panel == -1)
1090 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1092 // draw cursor after performing move/resize to have the panel pos/size updated before mouse_over_panel
1093 const vector cursorsize = '32 32 0';
1095 if(!mouse_over_panel)
1096 drawpic(mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1097 else if(mouse_over_panel == 1)
1098 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_move.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1099 else if(mouse_over_panel == 2)
1100 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1102 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize2.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1104 prevMouseClicked = mouseClicked;
1107 const float hlBorderSize = 4;
1108 const string hlBorder = "gfx/hud/default/border_highlighted";
1109 const string hlBorder2 = "gfx/hud/default/border_highlighted2";
1110 void HUD_Panel_HlBorder(float myBorder, vector color, float alpha)
1112 drawfill(panel_pos - '1 1 0' * myBorder, panel_size + '2 2 0' * myBorder, '0 0.5 1', .5 * alpha, DRAWFLAG_NORMAL);
1113 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);
1114 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);
1115 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);
1116 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);