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 HUD_Write_Cvar_q("scr_centerpos");
51 // common cvars for all panels
53 for (i = 0; i < HUD_PANEL_NUM; ++i)
57 HUD_Write_PanelCvar_n("");
58 HUD_Write_PanelCvar_q("_pos");
59 HUD_Write_PanelCvar_q("_size");
60 HUD_Write_PanelCvar_q("_bg");
61 HUD_Write_PanelCvar_q("_bg_color");
62 HUD_Write_PanelCvar_q("_bg_color_team");
63 HUD_Write_PanelCvar_q("_bg_alpha");
64 HUD_Write_PanelCvar_q("_bg_border");
65 HUD_Write_PanelCvar_q("_bg_padding");
67 case HUD_PANEL_WEAPONS:
68 HUD_Write_PanelCvar_q("_complainbubble");
69 HUD_Write_PanelCvar_q("_complainbubble_padding");
70 HUD_Write_PanelCvar_q("_complainbubble_color_outofammo");
71 HUD_Write_PanelCvar_q("_complainbubble_color_donthave");
72 HUD_Write_PanelCvar_q("_complainbubble_color_unavailable");
73 HUD_Write_PanelCvar_q("_ammo_color");
74 HUD_Write_PanelCvar_q("_ammo_alpha");
75 HUD_Write_PanelCvar_q("_aspect");
76 HUD_Write_PanelCvar_q("_timeout");
77 HUD_Write_PanelCvar_q("_timeout_effect");
80 HUD_Write_PanelCvar_q("_onlycurrent");
81 HUD_Write_PanelCvar_q("_iconalign");
82 HUD_Write_PanelCvar_q("_progressbar");
83 HUD_Write_PanelCvar_q("_progressbar_name");
84 HUD_Write_PanelCvar_q("_progressbar_xoffset");
85 HUD_Write_PanelCvar_q("_text");
87 case HUD_PANEL_POWERUPS:
88 HUD_Write_PanelCvar_q("_flip");
89 HUD_Write_PanelCvar_q("_iconalign");
90 HUD_Write_PanelCvar_q("_baralign");
91 HUD_Write_PanelCvar_q("_progressbar");
92 HUD_Write_PanelCvar_q("_progressbar_strength");
93 HUD_Write_PanelCvar_q("_progressbar_shield");
95 case HUD_PANEL_HEALTHARMOR:
96 HUD_Write_PanelCvar_q("_flip");
97 HUD_Write_PanelCvar_q("_iconalign");
98 HUD_Write_PanelCvar_q("_baralign");
99 HUD_Write_PanelCvar_q("_progressbar");
100 HUD_Write_PanelCvar_q("_progressbar_health");
101 HUD_Write_PanelCvar_q("_progressbar_armor");
102 HUD_Write_PanelCvar_q("_text");
104 case HUD_PANEL_NOTIFY:
105 HUD_Write_PanelCvar_q("_flip");
106 HUD_Write_PanelCvar_q("_print");
108 case HUD_PANEL_RADAR:
109 HUD_Write_PanelCvar_q("_foreground_alpha");
112 HUD_Write_PanelCvar_q("_alreadyvoted_alpha");
114 case HUD_PANEL_PRESSEDKEYS:
115 HUD_Write_PanelCvar_q("_aspect");
117 case HUD_PANEL_INFOMESSAGES:
118 HUD_Write_PanelCvar_q("_flip");
120 case HUD_PANEL_PHYSICS:
121 HUD_Write_PanelCvar_q("_flip");
122 HUD_Write_PanelCvar_q("_baralign");
123 HUD_Write_PanelCvar_q("_progressbar");
124 HUD_Write_PanelCvar_q("_acceleration_mode");
129 HUD_Write("menu_sync\n"); // force the menu to reread the cvars, so that the dialogs are updated
131 print(sprintf(_("^2Successfully exported to %s! (Note: It's saved in data/data/)\n"), filename));
135 print(sprintf(_("^1Couldn't write to %s\n"), filename));
138 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
139 vector HUD_Panel_CheckMove(vector myPos, vector mySize)
142 float myCenter_x, myCenter_y, targCenter_x, targCenter_y;
146 for (i = 0; i < HUD_PANEL_NUM; ++i) {
147 if(i == highlightedPanel || !panel_enabled)
150 HUD_Panel_UpdatePosSizeForId(i);
152 panel_pos -= '1 1 0' * panel_bg_border;
153 panel_size += '2 2 0' * panel_bg_border;
155 if(myPos_y + mySize_y < panel_pos_y)
157 if(myPos_y > panel_pos_y + panel_size_y)
160 if(myPos_x + mySize_x < panel_pos_x)
162 if(myPos_x > panel_pos_x + panel_size_x)
165 // OK, there IS a collision.
167 myCenter_x = myPos_x + 0.5 * mySize_x;
168 myCenter_y = myPos_y + 0.5 * mySize_y;
170 targCenter_x = panel_pos_x + 0.5 * panel_size_x;
171 targCenter_y = panel_pos_y + 0.5 * panel_size_y;
173 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
175 if(myPos_x + mySize_x - panel_pos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
176 myTarget_x = panel_pos_x - mySize_x;
177 else // push it upwards
178 myTarget_y = panel_pos_y - mySize_y;
180 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
182 if(panel_pos_x + panel_size_x - myPos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
183 myTarget_x = panel_pos_x + panel_size_x;
184 else // push it upwards
185 myTarget_y = panel_pos_y - mySize_y;
187 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
189 if(myPos_x + mySize_x - panel_pos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
190 myTarget_x = panel_pos_x - mySize_x;
191 else // push it downwards
192 myTarget_y = panel_pos_y + panel_size_y;
194 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
196 if(panel_pos_x + panel_size_x - myPos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
197 myTarget_x = panel_pos_x + panel_size_x;
198 else // push it downwards
199 myTarget_y = panel_pos_y + panel_size_y;
201 //if(cvar("hud_configure_checkcollisions_debug"))
202 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
208 void HUD_Panel_SetPos(vector pos)
210 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
214 //if(cvar("hud_configure_checkcollisions_debug"))
215 //drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
217 if(autocvar_hud_configure_grid)
219 pos_x = floor((pos_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
220 pos_y = floor((pos_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
223 if(hud_configure_checkcollisions)
224 pos = HUD_Panel_CheckMove(pos, mySize);
226 pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
227 pos_y = bound(0, pos_y, vid_conheight - mySize_y);
230 s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
232 HUD_Panel_GetName(highlightedPanel);
233 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
236 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
237 vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
242 float dist_x, dist_y;
244 ratio = mySize_x/mySize_y;
246 for (i = 0; i < HUD_PANEL_NUM; ++i) {
247 if(i == highlightedPanel || !panel_enabled)
250 HUD_Panel_UpdatePosSizeForId(i);
252 panel_pos -= '1 1 0' * panel_bg_border;
253 panel_size += '2 2 0' * panel_bg_border;
255 targEndPos = panel_pos + panel_size;
257 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
258 if(resizeorigin_x > panel_pos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > panel_pos_y && resizeorigin_y < targEndPos_y)
261 if (resizeCorner == 1)
263 // check if this panel is on our way
264 if (resizeorigin_x <= panel_pos_x)
266 if (resizeorigin_y <= panel_pos_y)
268 if (targEndPos_x <= resizeorigin_x - mySize_x)
270 if (targEndPos_y <= resizeorigin_y - mySize_y)
273 // there is a collision:
274 // detect which side of the panel we are facing is actually limiting the resizing
275 // (which side the resize direction finds for first) and reduce the size up to there
277 // dist is the distance between resizeorigin and the "analogous" point of the panel
278 // in this case between resizeorigin (bottom-right point) and the bottom-right point of the panel
279 dist_x = resizeorigin_x - targEndPos_x;
280 dist_y = resizeorigin_y - targEndPos_y;
281 if (dist_y <= 0 || dist_x / dist_y > ratio)
282 mySize_x = min(mySize_x, dist_x);
284 mySize_y = min(mySize_y, dist_y);
286 else if (resizeCorner == 2)
288 if (resizeorigin_x >= targEndPos_x)
290 if (resizeorigin_y <= panel_pos_y)
292 if (panel_pos_x >= resizeorigin_x + mySize_x)
294 if (targEndPos_y <= resizeorigin_y - mySize_y)
297 dist_x = panel_pos_x - resizeorigin_x;
298 dist_y = resizeorigin_y - targEndPos_y;
299 if (dist_y <= 0 || dist_x / dist_y > ratio)
300 mySize_x = min(mySize_x, dist_x);
302 mySize_y = min(mySize_y, dist_y);
304 else if (resizeCorner == 3)
306 if (resizeorigin_x <= panel_pos_x)
308 if (resizeorigin_y >= targEndPos_y)
310 if (targEndPos_x <= resizeorigin_x - mySize_x)
312 if (panel_pos_y >= resizeorigin_y + mySize_y)
315 dist_x = resizeorigin_x - targEndPos_x;
316 dist_y = panel_pos_y - resizeorigin_y;
317 if (dist_y <= 0 || dist_x / dist_y > ratio)
318 mySize_x = min(mySize_x, dist_x);
320 mySize_y = min(mySize_y, dist_y);
322 else if (resizeCorner == 4)
324 if (resizeorigin_x >= targEndPos_x)
326 if (resizeorigin_y >= targEndPos_y)
328 if (panel_pos_x >= resizeorigin_x + mySize_x)
330 if (panel_pos_y >= resizeorigin_y + mySize_y)
333 dist_x = panel_pos_x - resizeorigin_x;
334 dist_y = panel_pos_y - resizeorigin_y;
335 if (dist_y <= 0 || dist_x / dist_y > ratio)
336 mySize_x = min(mySize_x, dist_x);
338 mySize_y = min(mySize_y, dist_y);
340 //if(cvar("hud_configure_checkcollisions_debug"))
341 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
347 void HUD_Panel_SetPosSize(vector mySize)
349 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
351 resizeorigin = panel_click_resizeorigin;
354 // minimum panel size cap
355 mySize_x = max(0.025 * vid_conwidth, mySize_x);
356 mySize_y = max(0.025 * vid_conheight, mySize_y);
358 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.
360 mySize_x = max(17 * autocvar_con_chatsize, mySize_x);
361 mySize_y = max(2 * autocvar_con_chatsize + 2 * panel_bg_padding, mySize_y);
364 // collision testing|
365 // -----------------+
367 // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
368 if(resizeCorner == 1) {
369 myPos_x = resizeorigin_x - mySize_x;
370 myPos_y = resizeorigin_y - mySize_y;
371 } else if(resizeCorner == 2) {
372 myPos_x = resizeorigin_x;
373 myPos_y = resizeorigin_y - mySize_y;
374 } else if(resizeCorner == 3) {
375 myPos_x = resizeorigin_x - mySize_x;
376 myPos_y = resizeorigin_y;
377 } else { // resizeCorner == 4
378 myPos_x = resizeorigin_x;
379 myPos_y = resizeorigin_y;
382 // left/top screen edges
384 mySize_x = mySize_x + myPos_x;
386 mySize_y = mySize_y + myPos_y;
388 // bottom/right screen edges
389 if(myPos_x + mySize_x > vid_conwidth)
390 mySize_x = vid_conwidth - myPos_x;
391 if(myPos_y + mySize_y > vid_conheight)
392 mySize_y = vid_conheight - myPos_y;
394 //if(cvar("hud_configure_checkcollisions_debug"))
395 //drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
397 // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
398 if(autocvar_hud_configure_grid)
400 mySize_x = floor((mySize_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
401 mySize_y = floor((mySize_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
404 if(hud_configure_checkcollisions)
405 mySize = HUD_Panel_CheckResize(mySize, resizeorigin);
407 // 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)
408 mySize_x = max(0.025 * vid_conwidth, mySize_x);
409 mySize_y = max(0.025 * vid_conheight, mySize_y);
411 // do another pos check, as size might have changed by now
412 if(resizeCorner == 1) {
413 myPos_x = resizeorigin_x - mySize_x;
414 myPos_y = resizeorigin_y - mySize_y;
415 } else if(resizeCorner == 2) {
416 myPos_x = resizeorigin_x;
417 myPos_y = resizeorigin_y - mySize_y;
418 } else if(resizeCorner == 3) {
419 myPos_x = resizeorigin_x - mySize_x;
420 myPos_y = resizeorigin_y;
421 } else { // resizeCorner == 4
422 myPos_x = resizeorigin_x;
423 myPos_y = resizeorigin_y;
426 //if(cvar("hud_configure_checkcollisions_debug"))
427 //drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
429 HUD_Panel_GetName(highlightedPanel);
431 s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
432 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
434 s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
435 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
438 float pressed_key_time;
439 vector highlightedPanel_initial_pos, highlightedPanel_initial_size;
440 void HUD_Panel_Arrow_Action(float nPrimary)
442 if (highlightedPanel == -1)
445 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
448 if(autocvar_hud_configure_grid)
450 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
452 if (hudShiftState & S_SHIFT)
453 step = hud_configure_realGridSize_y;
455 step = 2 * hud_configure_realGridSize_y;
459 if (hudShiftState & S_SHIFT)
460 step = hud_configure_realGridSize_x;
462 step = 2 * hud_configure_realGridSize_x;
467 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
468 step = vid_conheight;
471 if (hudShiftState & S_SHIFT)
472 step = (step / 256); // more precision
474 step = (step / 64) * (1 + 2 * (time - pressed_key_time));
477 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
479 highlightedPanel_initial_pos = panel_pos;
480 highlightedPanel_initial_size = panel_size;
482 if (hudShiftState & S_ALT) // resize
484 highlightedAction = 1;
485 if(nPrimary == K_UPARROW)
487 else if(nPrimary == K_RIGHTARROW)
489 else if(nPrimary == K_LEFTARROW)
491 else // if(nPrimary == K_DOWNARROW)
494 // ctrl+arrow reduces the size, instead of increasing it
495 // Note that ctrl disables collisions check too, but it's fine
496 // since we don't collide with anything reducing the size
497 if (hudShiftState & S_CTRL) {
499 resizeCorner = 5 - resizeCorner;
504 panel_click_resizeorigin = panel_pos;
505 if(resizeCorner == 1) {
506 panel_click_resizeorigin += mySize;
508 } else if(resizeCorner == 2) {
509 panel_click_resizeorigin_y += mySize_y;
511 } else if(resizeCorner == 3) {
512 panel_click_resizeorigin_x += mySize_x;
514 } else { // resizeCorner == 4
517 HUD_Panel_SetPosSize(mySize);
521 highlightedAction = 2;
524 if(nPrimary == K_UPARROW)
526 else if(nPrimary == K_DOWNARROW)
528 else if(nPrimary == K_LEFTARROW)
530 else // if(nPrimary == K_RIGHTARROW)
533 HUD_Panel_SetPos(pos);
536 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
538 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
541 panel_pos_backup = highlightedPanel_initial_pos;
542 panel_size_backup = highlightedPanel_initial_size;
543 highlightedPanel_backup = highlightedPanel;
547 const float S_MOUSE1 = 1;
548 const float S_MOUSE2 = 2;
549 const float S_MOUSE3 = 4;
551 float prevMouseClicked; // previous state
552 float prevMouseClickedTime; // time during previous left mouse click, to check for doubleclicks
553 vector prevMouseClickedPos; // pos during previous left mouse click, to check for doubleclicks
555 void HUD_Panel_EnableMenu();
556 float tab_panels[HUD_PANEL_NUM];
557 float tab_panel, tab_backward;
558 vector tab_panel_pos;
559 void HUD_Panel_FirstInDrawQ(float id);
560 void reset_tab_panels()
563 for(i = 0; i < HUD_PANEL_NUM; ++i)
566 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
570 if(!autocvar__hud_configure)
573 // allow console bind to work
576 con_keys = findkeysforcommand("toggleconsole");
577 keys = tokenize(con_keys);
579 float hit_con_bind, i;
580 for (i = 0; i < keys; ++i)
582 if(nPrimary == stof(argv(i)))
586 if(bInputType == 0) {
587 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
588 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
589 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
591 else if(bInputType == 1) {
592 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
593 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
594 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
597 if(nPrimary == K_CTRL)
599 if (bInputType == 1) //ctrl has been released
603 //switch to selected panel
604 highlightedPanel = tab_panel;
605 highlightedAction = 0;
606 HUD_Panel_FirstInDrawQ(highlightedPanel);
613 if(nPrimary == K_MOUSE1)
615 if(bInputType == 0) // key pressed
616 mouseClicked |= S_MOUSE1;
617 else if(bInputType == 1) // key released
618 mouseClicked -= (mouseClicked & S_MOUSE1);
620 else if(nPrimary == K_MOUSE2)
622 if(bInputType == 0) // key pressed
623 mouseClicked |= S_MOUSE2;
624 else if(bInputType == 1) // key released
625 mouseClicked -= (mouseClicked & S_MOUSE2);
627 else if(nPrimary == K_ESCAPE)
632 menu_enabled_time = time;
633 localcmd("menu_showhudexit\n");
635 else if(nPrimary == K_BACKSPACE && hudShiftState & S_CTRL)
640 cvar_set("_hud_configure", "0");
642 else if(nPrimary == K_TAB && hudShiftState & S_CTRL) // select and highlight another panel
644 if (bInputType == 1 || mouseClicked)
647 //FIXME: if a panel is highlighted, has the same pos_x and lays in the same level
648 //of other panels then next consecutive ctrl-tab will select the highlighted panel too
649 //(it should only after every other panel of the hud)
650 //It's a minor bug anyway, we can live with it
652 float starting_panel;
653 float old_tab_panel = tab_panel;
654 if (tab_panel == -1) //first press of TAB
656 if (highlightedPanel != -1)
657 HUD_Panel_UpdatePosSizeForId(highlightedPanel)
660 starting_panel = highlightedPanel; //can be -1, it means no starting panel
661 tab_panel_pos = panel_pos; //to compute level
665 if ( ((!tab_backward) && (hudShiftState & S_SHIFT)) || (tab_backward && !(hudShiftState & S_SHIFT)) ) //tab direction changed?
667 starting_panel = tab_panel;
669 tab_backward = (hudShiftState & S_SHIFT);
671 float k, level, start_pos_x;
672 vector candidate_pos;
673 const float LEVELS_NUM = 4;
674 const float level_height = vid_conheight / LEVELS_NUM;
676 level = floor(tab_panel_pos_y / level_height) * level_height; //starting level
677 candidate_pos_x = (!tab_backward) ? vid_conwidth : 0;
678 start_pos_x = tab_panel_pos_x;
683 for(i = 0; i < HUD_PANEL_NUM; ++i)
685 if (i == tab_panels[i] || i == starting_panel)
687 HUD_Panel_UpdatePosSizeForId(i)
688 if (panel_pos_y >= level && (panel_pos_y - level) < level_height)
689 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)) )
690 || ( 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_panel_pos = candidate_pos = panel_pos;
698 if (k == LEVELS_NUM) //tab_panel not found
701 if (old_tab_panel == -2) //this prevents an infinite loop (should not happen normally)
706 starting_panel = old_tab_panel;
708 goto find_tab_panel; //u must find tab_panel!
712 level = mod(level + level_height, vid_conheight);
714 candidate_pos_x = vid_conwidth;
718 level = mod(level - level_height, vid_conheight);
719 start_pos_x = vid_conwidth;
724 tab_panels[tab_panel] = tab_panel;
726 else if(nPrimary == K_SPACE && hudShiftState & S_CTRL) // enable/disable highlighted panel or dock
728 if (bInputType == 1 || mouseClicked)
731 if (highlightedPanel != -1)
733 HUD_Panel_GetName(highlightedPanel);
734 cvar_set(strcat("hud_panel_", panel_name), ftos(!(panel_enabled)));
737 cvar_set(strcat("hud_dock"), (autocvar_hud_dock == "") ? "dock" : "");
739 else if(nPrimary == 'c' && hudShiftState & S_CTRL) // copy highlighted panel size
741 if (bInputType == 1 || mouseClicked)
744 if (highlightedPanel != -1)
746 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
747 panel_size_copied = panel_size;
748 highlightedPanel_copied = highlightedPanel;
751 else if(nPrimary == 'v' && hudShiftState & S_CTRL) // past copied size on the highlighted panel
753 if (bInputType == 1 || mouseClicked)
756 if (highlightedPanel_copied == -1 || highlightedPanel == -1)
759 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
761 // reduce size if it'd go beyond screen boundaries
762 vector tmp_size = panel_size_copied;
763 if (panel_pos_x + panel_size_copied_x > vid_conwidth)
764 tmp_size_x = vid_conwidth - panel_pos_x;
765 if (panel_pos_y + panel_size_copied_y > vid_conheight)
766 tmp_size_y = vid_conheight - panel_pos_y;
768 if (panel_size == tmp_size)
772 panel_pos_backup = panel_pos;
773 panel_size_backup = panel_size;
774 highlightedPanel_backup = highlightedPanel;
776 s = strcat(ftos(tmp_size_x/vid_conwidth), " ", ftos(tmp_size_y/vid_conheight));
777 HUD_Panel_GetName(highlightedPanel);
778 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
780 else if(nPrimary == 'z' && hudShiftState & S_CTRL) // undo last action
782 if (bInputType == 1 || mouseClicked)
784 //restore previous values
785 if (highlightedPanel_backup != -1)
787 HUD_Panel_GetName(highlightedPanel_backup);
788 s = strcat(ftos(panel_pos_backup_x/vid_conwidth), " ", ftos(panel_pos_backup_y/vid_conheight));
789 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
790 s = strcat(ftos(panel_size_backup_x/vid_conwidth), " ", ftos(panel_size_backup_y/vid_conheight));
791 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
792 highlightedPanel_backup = -1;
795 else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
799 pressed_key_time = 0;
802 else if (pressed_key_time == 0)
803 pressed_key_time = time;
806 HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
808 else if(nPrimary == K_ENTER || nPrimary == K_SPACE || nPrimary == K_KP_ENTER)
812 if (highlightedPanel != -1)
813 HUD_Panel_EnableMenu();
815 else if(hit_con_bind)
821 float HUD_Panel_Check_Mouse_Pos(float allow_move)
825 while(j < HUD_PANEL_NUM)
830 HUD_Panel_UpdatePosSizeForId(i);
832 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
835 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)
839 // resize from topleft border
840 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)
844 // resize from topright border
845 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)
849 // resize from bottomleft border
850 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)
854 // resize from bottomright border
855 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)
863 // move a panel to the beginning of the panel order array (which means it gets drawn last, on top of everything else)
864 void HUD_Panel_FirstInDrawQ(float id)
867 var float place = -1;
868 // find out where in the array our current id is, save into place
869 for(i = 0; i < HUD_PANEL_NUM; ++i)
871 if(panel_order[i] == id)
877 // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
879 place = HUD_PANEL_NUM - 1;
881 // move all ids up by one step in the array until "place"
882 for(i = place; i > 0; --i)
884 panel_order[i] = panel_order[i-1];
886 // now save the new top id
889 // let's save them into the cvar by some strcat trickery
891 for(i = 0; i < HUD_PANEL_NUM; ++i)
893 s = strcat(s, ftos(panel_order[i]), " ");
895 cvar_set("_hud_panelorder", s);
896 if(hud_panelorder_prev)
897 strunzone(hud_panelorder_prev);
898 hud_panelorder_prev = strzone(autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here
901 void HUD_Panel_Highlight(float allow_move)
905 while(j < HUD_PANEL_NUM)
910 HUD_Panel_UpdatePosSizeForId(i);
912 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
915 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)
917 highlightedPanel = i;
918 HUD_Panel_FirstInDrawQ(i);
919 highlightedAction = 1;
920 panel_click_distance = mousepos - panel_pos;
923 // resize from topleft border
924 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)
926 highlightedPanel = i;
927 HUD_Panel_FirstInDrawQ(i);
928 highlightedAction = 2;
930 panel_click_distance = mousepos - panel_pos;
931 panel_click_resizeorigin = panel_pos + panel_size;
934 // resize from topright border
935 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)
937 highlightedPanel = i;
938 HUD_Panel_FirstInDrawQ(i);
939 highlightedAction = 2;
941 panel_click_distance_x = panel_size_x - mousepos_x + panel_pos_x;
942 panel_click_distance_y = mousepos_y - panel_pos_y;
943 panel_click_resizeorigin = panel_pos + eY * panel_size_y;
946 // resize from bottomleft border
947 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)
949 highlightedPanel = i;
950 HUD_Panel_FirstInDrawQ(i);
951 highlightedAction = 2;
953 panel_click_distance_x = mousepos_x - panel_pos_x;
954 panel_click_distance_y = panel_size_y - mousepos_y + panel_pos_y;
955 panel_click_resizeorigin = panel_pos + eX * panel_size_x;
958 // resize from bottomright border
959 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)
961 highlightedPanel = i;
962 HUD_Panel_FirstInDrawQ(i);
963 highlightedAction = 2;
965 panel_click_distance = panel_size - mousepos + panel_pos;
966 panel_click_resizeorigin = panel_pos;
970 highlightedPanel = -1;
971 highlightedAction = 0;
974 void HUD_Panel_EnableMenu()
977 menu_enabled_time = time;
978 HUD_Panel_GetName(highlightedPanel);
979 localcmd("menu_showhudoptions ", panel_name, "\n");
981 float mouse_over_panel;
982 void HUD_Panel_Mouse()
984 // 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
985 if (autocvar__menu_alpha == 0 && time - menu_enabled_time > 0.5)
989 print("menu_enabled: ", ftos(menu_enabled), "\n");
990 print("Highlighted: ", ftos(highlightedPanel), "\n");
991 print("Menu alpha: ", ftos(autocvar__menu_alpha), "\n");
994 // instantly hide the editor cursor if we open the HUDExit dialog
995 // as hud_fade_alpha doesn't decrease to 0 in this case
996 // TODO: find a way to fade the cursor out even in this case
997 if(menu_enabled == 1 || (menu_enabled == 2 && !hud_fade_alpha))
1000 mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
1002 mousepos_x = bound(0, mousepos_x, vid_conwidth);
1003 mousepos_y = bound(0, mousepos_y, vid_conheight);
1007 if(prevMouseClicked == 0)
1009 if (tab_panel != -1)
1011 //stop ctrl-tab selection
1015 HUD_Panel_Highlight(mouseClicked & S_MOUSE1); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
1016 // and calls HUD_Panel_UpdatePosSizeForId() for the highlighted panel
1017 if (highlightedPanel != -1)
1019 highlightedPanel_initial_pos = panel_pos;
1020 highlightedPanel_initial_size = panel_size;
1022 // doubleclick check
1023 if ((mouseClicked & S_MOUSE1) && time - prevMouseClickedTime < 0.4 && highlightedPanel != -1 && prevMouseClickedPos == mousepos)
1025 mouseClicked = 0; // to prevent spam, I guess.
1026 HUD_Panel_EnableMenu();
1030 if (mouseClicked & S_MOUSE1)
1032 prevMouseClickedTime = time;
1033 prevMouseClickedPos = mousepos;
1035 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(mouseClicked & S_MOUSE1);
1039 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1041 if (highlightedPanel != -1)
1043 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1044 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
1046 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
1048 panel_pos_backup = highlightedPanel_initial_pos;
1049 panel_size_backup = highlightedPanel_initial_size;
1050 highlightedPanel_backup = highlightedPanel;
1053 // in case the clicked panel is inside another panel and we aren't
1054 // moving it, avoid the immediate "fix" of its position/size
1055 // (often unwanted and hateful) by disabling collisions check
1056 hud_configure_checkcollisions = false;
1059 if(highlightedAction == 1)
1060 HUD_Panel_SetPos(mousepos - panel_click_distance);
1061 else if(highlightedAction == 2)
1064 if(resizeCorner == 1) {
1065 mySize_x = panel_click_resizeorigin_x - (mousepos_x - panel_click_distance_x);
1066 mySize_y = panel_click_resizeorigin_y - (mousepos_y - panel_click_distance_y);
1067 } else if(resizeCorner == 2) {
1068 mySize_x = mousepos_x + panel_click_distance_x - panel_click_resizeorigin_x;
1069 mySize_y = panel_click_distance_y + panel_click_resizeorigin_y - mousepos_y;
1070 } else if(resizeCorner == 3) {
1071 mySize_x = panel_click_resizeorigin_x + panel_click_distance_x - mousepos_x;
1072 mySize_y = mousepos_y + panel_click_distance_y - panel_click_resizeorigin_y;
1073 } else { // resizeCorner == 4
1074 mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x);
1075 mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y);
1077 HUD_Panel_SetPosSize(mySize);
1082 if(menu_enabled == 2)
1083 mouse_over_panel = 0;
1085 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(TRUE);
1086 if (mouse_over_panel && tab_panel == -1)
1087 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1089 // draw cursor after performing move/resize to have the panel pos/size updated before mouse_over_panel
1090 const vector cursorsize = '32 32 0';
1092 if(!mouse_over_panel)
1093 drawpic(mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1094 else if(mouse_over_panel == 1)
1095 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_move.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1096 else if(mouse_over_panel == 2)
1097 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1099 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize2.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1101 prevMouseClicked = mouseClicked;
1104 const float hlBorderSize = 4;
1105 const string hlBorder = "gfx/hud/default/border_highlighted";
1106 const string hlBorder2 = "gfx/hud/default/border_highlighted2";
1107 void HUD_Panel_HlBorder(float myBorder, vector color, float alpha)
1109 drawfill(panel_pos - '1 1 0' * myBorder, panel_size + '2 2 0' * myBorder, '0 0.5 1', .5 * alpha, DRAWFLAG_NORMAL);
1110 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);
1111 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);
1112 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);
1113 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);