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("_fontsize");
107 HUD_Write_PanelCvar_q("_print");
109 case HUD_PANEL_RADAR:
110 HUD_Write_PanelCvar_q("_foreground_alpha");
113 HUD_Write_PanelCvar_q("_alreadyvoted_alpha");
115 case HUD_PANEL_PRESSEDKEYS:
116 HUD_Write_PanelCvar_q("_aspect");
118 case HUD_PANEL_INFOMESSAGES:
119 HUD_Write_PanelCvar_q("_flip");
121 case HUD_PANEL_PHYSICS:
122 HUD_Write_PanelCvar_q("_flip");
123 HUD_Write_PanelCvar_q("_baralign");
124 HUD_Write_PanelCvar_q("_progressbar");
125 HUD_Write_PanelCvar_q("_acceleration_mode");
130 HUD_Write("menu_sync\n"); // force the menu to reread the cvars, so that the dialogs are updated
132 print(sprintf(_("^2Successfully exported to %s! (Note: It's saved in data/data/)\n"), filename));
136 print(sprintf(_("^1Couldn't write to %s\n"), filename));
139 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
140 vector HUD_Panel_CheckMove(vector myPos, vector mySize)
143 float myCenter_x, myCenter_y, targCenter_x, targCenter_y;
147 for (i = 0; i < HUD_PANEL_NUM; ++i) {
148 if(i == highlightedPanel || !panel_enabled)
151 HUD_Panel_UpdatePosSizeForId(i);
153 panel_pos -= '1 1 0' * panel_bg_border;
154 panel_size += '2 2 0' * panel_bg_border;
156 if(myPos_y + mySize_y < panel_pos_y)
158 if(myPos_y > panel_pos_y + panel_size_y)
161 if(myPos_x + mySize_x < panel_pos_x)
163 if(myPos_x > panel_pos_x + panel_size_x)
166 // OK, there IS a collision.
168 myCenter_x = myPos_x + 0.5 * mySize_x;
169 myCenter_y = myPos_y + 0.5 * mySize_y;
171 targCenter_x = panel_pos_x + 0.5 * panel_size_x;
172 targCenter_y = panel_pos_y + 0.5 * panel_size_y;
174 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
176 if(myPos_x + mySize_x - panel_pos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
177 myTarget_x = panel_pos_x - mySize_x;
178 else // push it upwards
179 myTarget_y = panel_pos_y - mySize_y;
181 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
183 if(panel_pos_x + panel_size_x - myPos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
184 myTarget_x = panel_pos_x + panel_size_x;
185 else // push it upwards
186 myTarget_y = panel_pos_y - mySize_y;
188 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
190 if(myPos_x + mySize_x - panel_pos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
191 myTarget_x = panel_pos_x - mySize_x;
192 else // push it downwards
193 myTarget_y = panel_pos_y + panel_size_y;
195 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
197 if(panel_pos_x + panel_size_x - myPos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
198 myTarget_x = panel_pos_x + panel_size_x;
199 else // push it downwards
200 myTarget_y = panel_pos_y + panel_size_y;
202 //if(cvar("hud_configure_checkcollisions_debug"))
203 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
209 void HUD_Panel_SetPos(vector pos)
211 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
215 //if(cvar("hud_configure_checkcollisions_debug"))
216 //drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
218 if(autocvar_hud_configure_grid)
220 pos_x = floor((pos_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
221 pos_y = floor((pos_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
224 if(hud_configure_checkcollisions)
225 pos = HUD_Panel_CheckMove(pos, mySize);
227 pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
228 pos_y = bound(0, pos_y, vid_conheight - mySize_y);
231 s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
233 HUD_Panel_GetName(highlightedPanel);
234 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
237 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
238 vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
243 float dist_x, dist_y;
245 ratio = mySize_x/mySize_y;
247 for (i = 0; i < HUD_PANEL_NUM; ++i) {
248 if(i == highlightedPanel || !panel_enabled)
251 HUD_Panel_UpdatePosSizeForId(i);
253 panel_pos -= '1 1 0' * panel_bg_border;
254 panel_size += '2 2 0' * panel_bg_border;
256 targEndPos = panel_pos + panel_size;
258 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
259 if(resizeorigin_x > panel_pos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > panel_pos_y && resizeorigin_y < targEndPos_y)
262 if (resizeCorner == 1)
264 // check if this panel is on our way
265 if (resizeorigin_x <= panel_pos_x)
267 if (resizeorigin_y <= panel_pos_y)
269 if (targEndPos_x <= resizeorigin_x - mySize_x)
271 if (targEndPos_y <= resizeorigin_y - mySize_y)
274 // there is a collision:
275 // detect which side of the panel we are facing is actually limiting the resizing
276 // (which side the resize direction finds for first) and reduce the size up to there
278 // dist is the distance between resizeorigin and the "analogous" point of the panel
279 // in this case between resizeorigin (bottom-right point) and the bottom-right point of the panel
280 dist_x = resizeorigin_x - targEndPos_x;
281 dist_y = resizeorigin_y - targEndPos_y;
282 if (dist_y <= 0 || dist_x / dist_y > ratio)
283 mySize_x = min(mySize_x, dist_x);
285 mySize_y = min(mySize_y, dist_y);
287 else if (resizeCorner == 2)
289 if (resizeorigin_x >= targEndPos_x)
291 if (resizeorigin_y <= panel_pos_y)
293 if (panel_pos_x >= resizeorigin_x + mySize_x)
295 if (targEndPos_y <= resizeorigin_y - mySize_y)
298 dist_x = panel_pos_x - resizeorigin_x;
299 dist_y = resizeorigin_y - targEndPos_y;
300 if (dist_y <= 0 || dist_x / dist_y > ratio)
301 mySize_x = min(mySize_x, dist_x);
303 mySize_y = min(mySize_y, dist_y);
305 else if (resizeCorner == 3)
307 if (resizeorigin_x <= panel_pos_x)
309 if (resizeorigin_y >= targEndPos_y)
311 if (targEndPos_x <= resizeorigin_x - mySize_x)
313 if (panel_pos_y >= resizeorigin_y + mySize_y)
316 dist_x = resizeorigin_x - targEndPos_x;
317 dist_y = panel_pos_y - resizeorigin_y;
318 if (dist_y <= 0 || dist_x / dist_y > ratio)
319 mySize_x = min(mySize_x, dist_x);
321 mySize_y = min(mySize_y, dist_y);
323 else if (resizeCorner == 4)
325 if (resizeorigin_x >= targEndPos_x)
327 if (resizeorigin_y >= targEndPos_y)
329 if (panel_pos_x >= resizeorigin_x + mySize_x)
331 if (panel_pos_y >= resizeorigin_y + mySize_y)
334 dist_x = panel_pos_x - resizeorigin_x;
335 dist_y = panel_pos_y - resizeorigin_y;
336 if (dist_y <= 0 || dist_x / dist_y > ratio)
337 mySize_x = min(mySize_x, dist_x);
339 mySize_y = min(mySize_y, dist_y);
341 //if(cvar("hud_configure_checkcollisions_debug"))
342 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
348 void HUD_Panel_SetPosSize(vector mySize)
350 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
352 resizeorigin = panel_click_resizeorigin;
355 // minimum panel size cap
356 mySize_x = max(0.025 * vid_conwidth, mySize_x);
357 mySize_y = max(0.025 * vid_conheight, mySize_y);
359 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.
361 mySize_x = max(17 * autocvar_con_chatsize, mySize_x);
362 mySize_y = max(2 * autocvar_con_chatsize + 2 * panel_bg_padding, mySize_y);
365 // collision testing|
366 // -----------------+
368 // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
369 if(resizeCorner == 1) {
370 myPos_x = resizeorigin_x - mySize_x;
371 myPos_y = resizeorigin_y - mySize_y;
372 } else if(resizeCorner == 2) {
373 myPos_x = resizeorigin_x;
374 myPos_y = resizeorigin_y - mySize_y;
375 } else if(resizeCorner == 3) {
376 myPos_x = resizeorigin_x - mySize_x;
377 myPos_y = resizeorigin_y;
378 } else { // resizeCorner == 4
379 myPos_x = resizeorigin_x;
380 myPos_y = resizeorigin_y;
383 // left/top screen edges
385 mySize_x = mySize_x + myPos_x;
387 mySize_y = mySize_y + myPos_y;
389 // bottom/right screen edges
390 if(myPos_x + mySize_x > vid_conwidth)
391 mySize_x = vid_conwidth - myPos_x;
392 if(myPos_y + mySize_y > vid_conheight)
393 mySize_y = vid_conheight - myPos_y;
395 //if(cvar("hud_configure_checkcollisions_debug"))
396 //drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
398 // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
399 if(autocvar_hud_configure_grid)
401 mySize_x = floor((mySize_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
402 mySize_y = floor((mySize_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
405 if(hud_configure_checkcollisions)
406 mySize = HUD_Panel_CheckResize(mySize, resizeorigin);
408 // 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)
409 mySize_x = max(0.025 * vid_conwidth, mySize_x);
410 mySize_y = max(0.025 * vid_conheight, mySize_y);
412 // do another pos check, as size might have changed by now
413 if(resizeCorner == 1) {
414 myPos_x = resizeorigin_x - mySize_x;
415 myPos_y = resizeorigin_y - mySize_y;
416 } else if(resizeCorner == 2) {
417 myPos_x = resizeorigin_x;
418 myPos_y = resizeorigin_y - mySize_y;
419 } else if(resizeCorner == 3) {
420 myPos_x = resizeorigin_x - mySize_x;
421 myPos_y = resizeorigin_y;
422 } else { // resizeCorner == 4
423 myPos_x = resizeorigin_x;
424 myPos_y = resizeorigin_y;
427 //if(cvar("hud_configure_checkcollisions_debug"))
428 //drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
430 HUD_Panel_GetName(highlightedPanel);
432 s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
433 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
435 s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
436 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
439 float pressed_key_time;
440 vector highlightedPanel_initial_pos, highlightedPanel_initial_size;
441 void HUD_Panel_Arrow_Action(float nPrimary)
443 if (highlightedPanel == -1)
446 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
449 if(autocvar_hud_configure_grid)
451 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
453 if (hudShiftState & S_SHIFT)
454 step = hud_configure_realGridSize_y;
456 step = 2 * hud_configure_realGridSize_y;
460 if (hudShiftState & S_SHIFT)
461 step = hud_configure_realGridSize_x;
463 step = 2 * hud_configure_realGridSize_x;
468 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
469 step = vid_conheight;
472 if (hudShiftState & S_SHIFT)
473 step = (step / 256); // more precision
475 step = (step / 64) * (1 + 2 * (time - pressed_key_time));
478 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
480 highlightedPanel_initial_pos = panel_pos;
481 highlightedPanel_initial_size = panel_size;
483 if (hudShiftState & S_ALT) // resize
485 highlightedAction = 1;
486 if(nPrimary == K_UPARROW)
488 else if(nPrimary == K_RIGHTARROW)
490 else if(nPrimary == K_LEFTARROW)
492 else // if(nPrimary == K_DOWNARROW)
495 // ctrl+arrow reduces the size, instead of increasing it
496 // Note that ctrl disables collisions check too, but it's fine
497 // since we don't collide with anything reducing the size
498 if (hudShiftState & S_CTRL) {
500 resizeCorner = 5 - resizeCorner;
505 panel_click_resizeorigin = panel_pos;
506 if(resizeCorner == 1) {
507 panel_click_resizeorigin += mySize;
509 } else if(resizeCorner == 2) {
510 panel_click_resizeorigin_y += mySize_y;
512 } else if(resizeCorner == 3) {
513 panel_click_resizeorigin_x += mySize_x;
515 } else { // resizeCorner == 4
518 HUD_Panel_SetPosSize(mySize);
522 highlightedAction = 2;
525 if(nPrimary == K_UPARROW)
527 else if(nPrimary == K_DOWNARROW)
529 else if(nPrimary == K_LEFTARROW)
531 else // if(nPrimary == K_RIGHTARROW)
534 HUD_Panel_SetPos(pos);
537 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
539 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
542 panel_pos_backup = highlightedPanel_initial_pos;
543 panel_size_backup = highlightedPanel_initial_size;
544 highlightedPanel_backup = highlightedPanel;
548 const float S_MOUSE1 = 1;
549 const float S_MOUSE2 = 2;
550 const float S_MOUSE3 = 4;
552 float prevMouseClicked; // previous state
553 float prevMouseClickedTime; // time during previous left mouse click, to check for doubleclicks
554 vector prevMouseClickedPos; // pos during previous left mouse click, to check for doubleclicks
556 void HUD_Panel_EnableMenu();
557 float tab_panels[HUD_PANEL_NUM];
558 float tab_panel, tab_backward;
559 vector tab_panel_pos;
560 void HUD_Panel_FirstInDrawQ(float id);
561 void reset_tab_panels()
564 for(i = 0; i < HUD_PANEL_NUM; ++i)
567 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
571 if(!autocvar__hud_configure)
574 // allow console bind to work
577 con_keys = findkeysforcommand("toggleconsole");
578 keys = tokenize(con_keys);
580 float hit_con_bind, i;
581 for (i = 0; i < keys; ++i)
583 if(nPrimary == stof(argv(i)))
587 if(bInputType == 0) {
588 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
589 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
590 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
592 else if(bInputType == 1) {
593 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
594 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
595 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
598 if(nPrimary == K_CTRL)
600 if (bInputType == 1) //ctrl has been released
604 //switch to selected panel
605 highlightedPanel = tab_panel;
606 highlightedAction = 0;
607 HUD_Panel_FirstInDrawQ(highlightedPanel);
614 if(nPrimary == K_MOUSE1)
616 if(bInputType == 0) // key pressed
617 mouseClicked |= S_MOUSE1;
618 else if(bInputType == 1) // key released
619 mouseClicked -= (mouseClicked & S_MOUSE1);
621 else if(nPrimary == K_MOUSE2)
623 if(bInputType == 0) // key pressed
624 mouseClicked |= S_MOUSE2;
625 else if(bInputType == 1) // key released
626 mouseClicked -= (mouseClicked & S_MOUSE2);
628 else if(nPrimary == K_ESCAPE)
633 menu_enabled_time = time;
634 localcmd("menu_showhudexit\n");
636 else if(nPrimary == K_BACKSPACE && hudShiftState & S_CTRL)
641 cvar_set("_hud_configure", "0");
643 else if(nPrimary == K_TAB && hudShiftState & S_CTRL) // select and highlight another panel
645 if (bInputType == 1 || mouseClicked)
648 //FIXME: if a panel is highlighted, has the same pos_x and lays in the same level
649 //of other panels then next consecutive ctrl-tab will select the highlighted panel too
650 //(it should only after every other panel of the hud)
651 //It's a minor bug anyway, we can live with it
653 float starting_panel;
654 float old_tab_panel = tab_panel;
655 if (tab_panel == -1) //first press of TAB
657 if (highlightedPanel != -1)
658 HUD_Panel_UpdatePosSizeForId(highlightedPanel)
661 starting_panel = highlightedPanel; //can be -1, it means no starting panel
662 tab_panel_pos = panel_pos; //to compute level
666 if ( ((!tab_backward) && (hudShiftState & S_SHIFT)) || (tab_backward && !(hudShiftState & S_SHIFT)) ) //tab direction changed?
668 starting_panel = tab_panel;
670 tab_backward = (hudShiftState & S_SHIFT);
672 float k, level, start_pos_x;
673 vector candidate_pos;
674 const float LEVELS_NUM = 4;
675 const float level_height = vid_conheight / LEVELS_NUM;
677 level = floor(tab_panel_pos_y / level_height) * level_height; //starting level
678 candidate_pos_x = (!tab_backward) ? vid_conwidth : 0;
679 start_pos_x = tab_panel_pos_x;
684 for(i = 0; i < HUD_PANEL_NUM; ++i)
686 if (i == tab_panels[i] || i == starting_panel)
688 HUD_Panel_UpdatePosSizeForId(i)
689 if (panel_pos_y >= level && (panel_pos_y - level) < level_height)
690 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)) )
691 || ( 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)) ) )
694 tab_panel_pos = candidate_pos = panel_pos;
699 if (k == LEVELS_NUM) //tab_panel not found
702 if (old_tab_panel == -2) //this prevents an infinite loop (should not happen normally)
707 starting_panel = old_tab_panel;
709 goto find_tab_panel; //u must find tab_panel!
713 level = mod(level + level_height, vid_conheight);
715 candidate_pos_x = vid_conwidth;
719 level = mod(level - level_height, vid_conheight);
720 start_pos_x = vid_conwidth;
725 tab_panels[tab_panel] = tab_panel;
727 else if(nPrimary == K_SPACE && hudShiftState & S_CTRL) // enable/disable highlighted panel or dock
729 if (bInputType == 1 || mouseClicked)
732 if (highlightedPanel != -1)
734 HUD_Panel_GetName(highlightedPanel);
735 cvar_set(strcat("hud_panel_", panel_name), ftos(!(panel_enabled)));
738 cvar_set(strcat("hud_dock"), (autocvar_hud_dock == "") ? "dock" : "");
740 else if(nPrimary == 'c' && hudShiftState & S_CTRL) // copy highlighted panel size
742 if (bInputType == 1 || mouseClicked)
745 if (highlightedPanel != -1)
747 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
748 panel_size_copied = panel_size;
749 highlightedPanel_copied = highlightedPanel;
752 else if(nPrimary == 'v' && hudShiftState & S_CTRL) // past copied size on the highlighted panel
754 if (bInputType == 1 || mouseClicked)
757 if (highlightedPanel_copied == -1 || highlightedPanel == -1)
760 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
762 // reduce size if it'd go beyond screen boundaries
763 vector tmp_size = panel_size_copied;
764 if (panel_pos_x + panel_size_copied_x > vid_conwidth)
765 tmp_size_x = vid_conwidth - panel_pos_x;
766 if (panel_pos_y + panel_size_copied_y > vid_conheight)
767 tmp_size_y = vid_conheight - panel_pos_y;
769 if (panel_size == tmp_size)
773 panel_pos_backup = panel_pos;
774 panel_size_backup = panel_size;
775 highlightedPanel_backup = highlightedPanel;
777 s = strcat(ftos(tmp_size_x/vid_conwidth), " ", ftos(tmp_size_y/vid_conheight));
778 HUD_Panel_GetName(highlightedPanel);
779 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
781 else if(nPrimary == 'z' && hudShiftState & S_CTRL) // undo last action
783 if (bInputType == 1 || mouseClicked)
785 //restore previous values
786 if (highlightedPanel_backup != -1)
788 HUD_Panel_GetName(highlightedPanel_backup);
789 s = strcat(ftos(panel_pos_backup_x/vid_conwidth), " ", ftos(panel_pos_backup_y/vid_conheight));
790 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
791 s = strcat(ftos(panel_size_backup_x/vid_conwidth), " ", ftos(panel_size_backup_y/vid_conheight));
792 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
793 highlightedPanel_backup = -1;
796 else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
800 pressed_key_time = 0;
803 else if (pressed_key_time == 0)
804 pressed_key_time = time;
807 HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
809 else if(nPrimary == K_ENTER || nPrimary == K_SPACE || nPrimary == K_KP_ENTER)
813 if (highlightedPanel != -1)
814 HUD_Panel_EnableMenu();
816 else if(hit_con_bind)
822 float HUD_Panel_Check_Mouse_Pos(float allow_move)
826 while(j < HUD_PANEL_NUM)
831 HUD_Panel_UpdatePosSizeForId(i);
833 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
836 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)
840 // resize from topleft border
841 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)
845 // resize from topright border
846 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)
850 // resize from bottomleft border
851 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)
855 // resize from bottomright border
856 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)
864 // move a panel to the beginning of the panel order array (which means it gets drawn last, on top of everything else)
865 void HUD_Panel_FirstInDrawQ(float id)
868 var float place = -1;
869 // find out where in the array our current id is, save into place
870 for(i = 0; i < HUD_PANEL_NUM; ++i)
872 if(panel_order[i] == id)
878 // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
880 place = HUD_PANEL_NUM - 1;
882 // move all ids up by one step in the array until "place"
883 for(i = place; i > 0; --i)
885 panel_order[i] = panel_order[i-1];
887 // now save the new top id
890 // let's save them into the cvar by some strcat trickery
892 for(i = 0; i < HUD_PANEL_NUM; ++i)
894 s = strcat(s, ftos(panel_order[i]), " ");
896 cvar_set("_hud_panelorder", s);
897 if(hud_panelorder_prev)
898 strunzone(hud_panelorder_prev);
899 hud_panelorder_prev = strzone(autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here
902 void HUD_Panel_Highlight(float allow_move)
906 while(j < HUD_PANEL_NUM)
911 HUD_Panel_UpdatePosSizeForId(i);
913 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
916 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)
918 highlightedPanel = i;
919 HUD_Panel_FirstInDrawQ(i);
920 highlightedAction = 1;
921 panel_click_distance = mousepos - panel_pos;
924 // resize from topleft border
925 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)
927 highlightedPanel = i;
928 HUD_Panel_FirstInDrawQ(i);
929 highlightedAction = 2;
931 panel_click_distance = mousepos - panel_pos;
932 panel_click_resizeorigin = panel_pos + panel_size;
935 // resize from topright border
936 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)
938 highlightedPanel = i;
939 HUD_Panel_FirstInDrawQ(i);
940 highlightedAction = 2;
942 panel_click_distance_x = panel_size_x - mousepos_x + panel_pos_x;
943 panel_click_distance_y = mousepos_y - panel_pos_y;
944 panel_click_resizeorigin = panel_pos + eY * panel_size_y;
947 // resize from bottomleft border
948 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)
950 highlightedPanel = i;
951 HUD_Panel_FirstInDrawQ(i);
952 highlightedAction = 2;
954 panel_click_distance_x = mousepos_x - panel_pos_x;
955 panel_click_distance_y = panel_size_y - mousepos_y + panel_pos_y;
956 panel_click_resizeorigin = panel_pos + eX * panel_size_x;
959 // resize from bottomright border
960 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)
962 highlightedPanel = i;
963 HUD_Panel_FirstInDrawQ(i);
964 highlightedAction = 2;
966 panel_click_distance = panel_size - mousepos + panel_pos;
967 panel_click_resizeorigin = panel_pos;
971 highlightedPanel = -1;
972 highlightedAction = 0;
975 void HUD_Panel_EnableMenu()
978 menu_enabled_time = time;
979 HUD_Panel_GetName(highlightedPanel);
980 localcmd("menu_showhudoptions ", panel_name, "\n");
982 float mouse_over_panel;
983 void HUD_Panel_Mouse()
985 // 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
986 if (autocvar__menu_alpha == 0 && time - menu_enabled_time > 0.5)
990 print("menu_enabled: ", ftos(menu_enabled), "\n");
991 print("Highlighted: ", ftos(highlightedPanel), "\n");
992 print("Menu alpha: ", ftos(autocvar__menu_alpha), "\n");
995 // instantly hide the editor cursor if we open the HUDExit dialog
996 // as hud_fade_alpha doesn't decrease to 0 in this case
997 // TODO: find a way to fade the cursor out even in this case
998 if(menu_enabled == 1 || (menu_enabled == 2 && !hud_fade_alpha))
1001 mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
1003 mousepos_x = bound(0, mousepos_x, vid_conwidth);
1004 mousepos_y = bound(0, mousepos_y, vid_conheight);
1008 if(prevMouseClicked == 0)
1010 if (tab_panel != -1)
1012 //stop ctrl-tab selection
1016 HUD_Panel_Highlight(mouseClicked & S_MOUSE1); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
1017 // and calls HUD_Panel_UpdatePosSizeForId() for the highlighted panel
1018 if (highlightedPanel != -1)
1020 highlightedPanel_initial_pos = panel_pos;
1021 highlightedPanel_initial_size = panel_size;
1023 // doubleclick check
1024 if ((mouseClicked & S_MOUSE1) && time - prevMouseClickedTime < 0.4 && highlightedPanel != -1 && prevMouseClickedPos == mousepos)
1026 mouseClicked = 0; // to prevent spam, I guess.
1027 HUD_Panel_EnableMenu();
1031 if (mouseClicked & S_MOUSE1)
1033 prevMouseClickedTime = time;
1034 prevMouseClickedPos = mousepos;
1036 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(mouseClicked & S_MOUSE1);
1040 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1042 if (highlightedPanel != -1)
1044 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1045 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
1047 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
1049 panel_pos_backup = highlightedPanel_initial_pos;
1050 panel_size_backup = highlightedPanel_initial_size;
1051 highlightedPanel_backup = highlightedPanel;
1054 // in case the clicked panel is inside another panel and we aren't
1055 // moving it, avoid the immediate "fix" of its position/size
1056 // (often unwanted and hateful) by disabling collisions check
1057 hud_configure_checkcollisions = false;
1060 if(highlightedAction == 1)
1061 HUD_Panel_SetPos(mousepos - panel_click_distance);
1062 else if(highlightedAction == 2)
1065 if(resizeCorner == 1) {
1066 mySize_x = panel_click_resizeorigin_x - (mousepos_x - panel_click_distance_x);
1067 mySize_y = panel_click_resizeorigin_y - (mousepos_y - panel_click_distance_y);
1068 } else if(resizeCorner == 2) {
1069 mySize_x = mousepos_x + panel_click_distance_x - panel_click_resizeorigin_x;
1070 mySize_y = panel_click_distance_y + panel_click_resizeorigin_y - mousepos_y;
1071 } else if(resizeCorner == 3) {
1072 mySize_x = panel_click_resizeorigin_x + panel_click_distance_x - mousepos_x;
1073 mySize_y = mousepos_y + panel_click_distance_y - panel_click_resizeorigin_y;
1074 } else { // resizeCorner == 4
1075 mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x);
1076 mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y);
1078 HUD_Panel_SetPosSize(mySize);
1083 if(menu_enabled == 2)
1084 mouse_over_panel = 0;
1086 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(TRUE);
1087 if (mouse_over_panel && tab_panel == -1)
1088 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1090 // draw cursor after performing move/resize to have the panel pos/size updated before mouse_over_panel
1091 const vector cursorsize = '32 32 0';
1093 if(!mouse_over_panel)
1094 drawpic(mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1095 else if(mouse_over_panel == 1)
1096 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_move.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1097 else if(mouse_over_panel == 2)
1098 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1100 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize2.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1102 prevMouseClicked = mouseClicked;
1105 const float hlBorderSize = 4;
1106 const string hlBorder = "gfx/hud/default/border_highlighted";
1107 const string hlBorder2 = "gfx/hud/default/border_highlighted2";
1108 void HUD_Panel_HlBorder(float myBorder, vector color, float alpha)
1110 drawfill(panel_pos - '1 1 0' * myBorder, panel_size + '2 2 0' * myBorder, '0 0.5 1', .5 * alpha, DRAWFLAG_NORMAL);
1111 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);
1112 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);
1113 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);
1114 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);