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");
128 HUD_Write("menu_sync\n"); // force the menu to reread the cvars, so that the dialogs are updated
130 print("^2Successfully exported to ", filename, "! (Note: It's saved in data/data/)\n");
134 print("^1Couldn't write to ", filename, "\n");
137 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
138 vector HUD_Panel_CheckMove(vector myPos, vector mySize)
141 float myCenter_x, myCenter_y, targCenter_x, targCenter_y;
145 for (i = 0; i < HUD_PANEL_NUM; ++i) {
146 if(i == highlightedPanel || !panel_enabled)
149 HUD_Panel_UpdatePosSizeForId(i);
151 panel_pos -= '1 1 0' * panel_bg_border;
152 panel_size += '2 2 0' * panel_bg_border;
154 if(myPos_y + mySize_y < panel_pos_y)
156 if(myPos_y > panel_pos_y + panel_size_y)
159 if(myPos_x + mySize_x < panel_pos_x)
161 if(myPos_x > panel_pos_x + panel_size_x)
164 // OK, there IS a collision.
166 myCenter_x = myPos_x + 0.5 * mySize_x;
167 myCenter_y = myPos_y + 0.5 * mySize_y;
169 targCenter_x = panel_pos_x + 0.5 * panel_size_x;
170 targCenter_y = panel_pos_y + 0.5 * panel_size_y;
172 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
174 if(myPos_x + mySize_x - panel_pos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
175 myTarget_x = panel_pos_x - mySize_x;
176 else // push it upwards
177 myTarget_y = panel_pos_y - mySize_y;
179 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
181 if(panel_pos_x + panel_size_x - myPos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
182 myTarget_x = panel_pos_x + panel_size_x;
183 else // push it upwards
184 myTarget_y = panel_pos_y - mySize_y;
186 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
188 if(myPos_x + mySize_x - panel_pos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
189 myTarget_x = panel_pos_x - mySize_x;
190 else // push it downwards
191 myTarget_y = panel_pos_y + panel_size_y;
193 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
195 if(panel_pos_x + panel_size_x - myPos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
196 myTarget_x = panel_pos_x + panel_size_x;
197 else // push it downwards
198 myTarget_y = panel_pos_y + panel_size_y;
200 //if(cvar("hud_configure_checkcollisions_debug"))
201 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
207 void HUD_Panel_SetPos(vector pos)
209 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
213 //if(cvar("hud_configure_checkcollisions_debug"))
214 //drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
216 if(autocvar_hud_configure_grid)
218 pos_x = floor((pos_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
219 pos_y = floor((pos_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
222 if(hud_configure_checkcollisions)
223 pos = HUD_Panel_CheckMove(pos, mySize);
225 pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
226 pos_y = bound(0, pos_y, vid_conheight - mySize_y);
229 s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
231 HUD_Panel_GetName(highlightedPanel);
232 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
235 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
236 vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
241 float dist_x, dist_y;
243 ratio = mySize_x/mySize_y;
245 for (i = 0; i < HUD_PANEL_NUM; ++i) {
246 if(i == highlightedPanel || !panel_enabled)
249 HUD_Panel_UpdatePosSizeForId(i);
251 panel_pos -= '1 1 0' * panel_bg_border;
252 panel_size += '2 2 0' * panel_bg_border;
254 targEndPos = panel_pos + panel_size;
256 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
257 if(resizeorigin_x > panel_pos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > panel_pos_y && resizeorigin_y < targEndPos_y)
260 if (resizeCorner == 1)
262 // check if this panel is on our way
263 if (resizeorigin_x <= panel_pos_x)
265 if (resizeorigin_y <= panel_pos_y)
267 if (targEndPos_x <= resizeorigin_x - mySize_x)
269 if (targEndPos_y <= resizeorigin_y - mySize_y)
272 // there is a collision:
273 // detect which side of the panel we are facing is actually limiting the resizing
274 // (which side the resize direction finds for first) and reduce the size up to there
276 // dist is the distance between resizeorigin and the "analogous" point of the panel
277 // in this case between resizeorigin (bottom-right point) and the bottom-right point of the panel
278 dist_x = resizeorigin_x - targEndPos_x;
279 dist_y = resizeorigin_y - targEndPos_y;
280 if (dist_y <= 0 || dist_x / dist_y > ratio)
281 mySize_x = min(mySize_x, dist_x);
283 mySize_y = min(mySize_y, dist_y);
285 else if (resizeCorner == 2)
287 if (resizeorigin_x >= targEndPos_x)
289 if (resizeorigin_y <= panel_pos_y)
291 if (panel_pos_x >= resizeorigin_x + mySize_x)
293 if (targEndPos_y <= resizeorigin_y - mySize_y)
296 dist_x = panel_pos_x - resizeorigin_x;
297 dist_y = resizeorigin_y - targEndPos_y;
298 if (dist_y <= 0 || dist_x / dist_y > ratio)
299 mySize_x = min(mySize_x, dist_x);
301 mySize_y = min(mySize_y, dist_y);
303 else if (resizeCorner == 3)
305 if (resizeorigin_x <= panel_pos_x)
307 if (resizeorigin_y >= targEndPos_y)
309 if (targEndPos_x <= resizeorigin_x - mySize_x)
311 if (panel_pos_y >= resizeorigin_y + mySize_y)
314 dist_x = resizeorigin_x - targEndPos_x;
315 dist_y = panel_pos_y - resizeorigin_y;
316 if (dist_y <= 0 || dist_x / dist_y > ratio)
317 mySize_x = min(mySize_x, dist_x);
319 mySize_y = min(mySize_y, dist_y);
321 else if (resizeCorner == 4)
323 if (resizeorigin_x >= targEndPos_x)
325 if (resizeorigin_y >= targEndPos_y)
327 if (panel_pos_x >= resizeorigin_x + mySize_x)
329 if (panel_pos_y >= resizeorigin_y + mySize_y)
332 dist_x = panel_pos_x - resizeorigin_x;
333 dist_y = panel_pos_y - resizeorigin_y;
334 if (dist_y <= 0 || dist_x / dist_y > ratio)
335 mySize_x = min(mySize_x, dist_x);
337 mySize_y = min(mySize_y, dist_y);
339 //if(cvar("hud_configure_checkcollisions_debug"))
340 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
346 void HUD_Panel_SetPosSize(vector mySize)
348 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
350 resizeorigin = panel_click_resizeorigin;
353 // minimum panel size cap
354 mySize_x = max(0.025 * vid_conwidth, mySize_x);
355 mySize_y = max(0.025 * vid_conheight, mySize_y);
357 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.
359 mySize_x = max(17 * autocvar_con_chatsize, mySize_x);
360 mySize_y = max(2 * autocvar_con_chatsize + 2 * panel_bg_padding, mySize_y);
363 // collision testing|
364 // -----------------+
366 // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
367 if(resizeCorner == 1) {
368 myPos_x = resizeorigin_x - mySize_x;
369 myPos_y = resizeorigin_y - mySize_y;
370 } else if(resizeCorner == 2) {
371 myPos_x = resizeorigin_x;
372 myPos_y = resizeorigin_y - mySize_y;
373 } else if(resizeCorner == 3) {
374 myPos_x = resizeorigin_x - mySize_x;
375 myPos_y = resizeorigin_y;
376 } else { // resizeCorner == 4
377 myPos_x = resizeorigin_x;
378 myPos_y = resizeorigin_y;
381 // left/top screen edges
383 mySize_x = mySize_x + myPos_x;
385 mySize_y = mySize_y + myPos_y;
387 // bottom/right screen edges
388 if(myPos_x + mySize_x > vid_conwidth)
389 mySize_x = vid_conwidth - myPos_x;
390 if(myPos_y + mySize_y > vid_conheight)
391 mySize_y = vid_conheight - myPos_y;
393 //if(cvar("hud_configure_checkcollisions_debug"))
394 //drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
396 // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
397 if(autocvar_hud_configure_grid)
399 mySize_x = floor((mySize_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
400 mySize_y = floor((mySize_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
403 if(hud_configure_checkcollisions)
404 mySize = HUD_Panel_CheckResize(mySize, resizeorigin);
406 // 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)
407 mySize_x = max(0.025 * vid_conwidth, mySize_x);
408 mySize_y = max(0.025 * vid_conheight, mySize_y);
410 // do another pos check, as size might have changed by now
411 if(resizeCorner == 1) {
412 myPos_x = resizeorigin_x - mySize_x;
413 myPos_y = resizeorigin_y - mySize_y;
414 } else if(resizeCorner == 2) {
415 myPos_x = resizeorigin_x;
416 myPos_y = resizeorigin_y - mySize_y;
417 } else if(resizeCorner == 3) {
418 myPos_x = resizeorigin_x - mySize_x;
419 myPos_y = resizeorigin_y;
420 } else { // resizeCorner == 4
421 myPos_x = resizeorigin_x;
422 myPos_y = resizeorigin_y;
425 //if(cvar("hud_configure_checkcollisions_debug"))
426 //drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
428 HUD_Panel_GetName(highlightedPanel);
430 s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
431 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
433 s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
434 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
437 float pressed_key_time;
438 vector highlightedPanel_initial_pos, highlightedPanel_initial_size;
439 void HUD_Panel_Arrow_Action(float nPrimary)
441 if (highlightedPanel == -1)
444 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
447 if(autocvar_hud_configure_grid)
449 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
451 if (hudShiftState & S_SHIFT)
452 step = hud_configure_realGridSize_y;
454 step = 2 * hud_configure_realGridSize_y;
458 if (hudShiftState & S_SHIFT)
459 step = hud_configure_realGridSize_x;
461 step = 2 * hud_configure_realGridSize_x;
466 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
467 step = vid_conheight;
470 if (hudShiftState & S_SHIFT)
471 step = (step / 256); // more precision
473 step = (step / 64) * (1 + 2 * (time - pressed_key_time));
476 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
478 highlightedPanel_initial_pos = panel_pos;
479 highlightedPanel_initial_size = panel_size;
481 if (hudShiftState & S_ALT) // resize
483 highlightedAction = 1;
484 if(nPrimary == K_UPARROW)
486 else if(nPrimary == K_RIGHTARROW)
488 else if(nPrimary == K_LEFTARROW)
490 else // if(nPrimary == K_DOWNARROW)
493 // ctrl+arrow reduces the size, instead of increasing it
494 // Note that ctrl disables collisions check too, but it's fine
495 // since we don't collide with anything reducing the size
496 if (hudShiftState & S_CTRL) {
498 resizeCorner = 5 - resizeCorner;
503 panel_click_resizeorigin = panel_pos;
504 if(resizeCorner == 1) {
505 panel_click_resizeorigin += mySize;
507 } else if(resizeCorner == 2) {
508 panel_click_resizeorigin_y += mySize_y;
510 } else if(resizeCorner == 3) {
511 panel_click_resizeorigin_x += mySize_x;
513 } else { // resizeCorner == 4
516 HUD_Panel_SetPosSize(mySize);
520 highlightedAction = 2;
523 if(nPrimary == K_UPARROW)
525 else if(nPrimary == K_DOWNARROW)
527 else if(nPrimary == K_LEFTARROW)
529 else // if(nPrimary == K_RIGHTARROW)
532 HUD_Panel_SetPos(pos);
535 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
537 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
540 panel_pos_backup = highlightedPanel_initial_pos;
541 panel_size_backup = highlightedPanel_initial_size;
542 highlightedPanel_backup = highlightedPanel;
547 float prevMouseClicked; // previous state
548 float prevMouseClickedTime; // time during previous mouse click, to check for doubleclicks
549 vector prevMouseClickedPos; // pos during previous mouse click, to check for doubleclicks
551 void HUD_Panel_EnableMenu();
552 float tab_panels[HUD_PANEL_NUM];
553 float tab_panel, tab_backward;
554 vector tab_panel_pos;
555 void HUD_Panel_FirstInDrawQ(float id);
556 void reset_tab_panels()
559 for(i = 0; i < HUD_PANEL_NUM; ++i)
562 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
566 if(!autocvar__hud_configure)
569 // allow console bind to work
572 con_keys = findkeysforcommand("toggleconsole");
573 keys = tokenize(con_keys);
575 float hit_con_bind, i;
576 for (i = 0; i < keys; ++i)
578 if(nPrimary == stof(argv(i)))
582 if(bInputType == 0) {
583 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
584 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
585 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
587 else if(bInputType == 1) {
588 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
589 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
590 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
593 if(nPrimary == K_CTRL)
595 if (bInputType == 1) //ctrl has been released
599 //switch to selected panel
600 highlightedPanel = tab_panel;
601 highlightedAction = 0;
602 HUD_Panel_FirstInDrawQ(highlightedPanel);
609 if(nPrimary == K_MOUSE1)
611 if(bInputType == 0) { // key pressed
615 else if(bInputType == 1) {// key released
620 else if(nPrimary == K_ESCAPE)
625 menu_enabled_time = time;
626 localcmd("menu_showhudexit\n");
628 else if(nPrimary == K_BACKSPACE && hudShiftState & S_CTRL)
633 cvar_set("_hud_configure", "0");
635 else if(nPrimary == K_TAB && hudShiftState & S_CTRL) // select and highlight another panel
637 if (bInputType == 1 || mouseClicked)
640 //FIXME: if a panel is highlighted, has the same pos_x and lays in the same level
641 //of other panels then next consecutive ctrl-tab will select the highlighted panel too
642 //(it should only after every other panel of the hud)
643 //It's a minor bug anyway, we can live with it
645 float starting_panel;
646 float old_tab_panel = tab_panel;
647 if (tab_panel == -1) //first press of TAB
649 if (highlightedPanel != -1)
650 HUD_Panel_UpdatePosSizeForId(highlightedPanel)
653 starting_panel = highlightedPanel; //can be -1, it means no starting panel
654 tab_panel_pos = panel_pos; //to compute level
658 if ( ((!tab_backward) && (hudShiftState & S_SHIFT)) || (tab_backward && !(hudShiftState & S_SHIFT)) ) //tab direction changed?
660 starting_panel = tab_panel;
662 tab_backward = (hudShiftState & S_SHIFT);
664 float k, level, start_pos_x;
665 vector candidate_pos;
666 const float LEVELS_NUM = 4;
667 const float level_height = vid_conheight / LEVELS_NUM;
669 level = floor(tab_panel_pos_y / level_height) * level_height; //starting level
670 candidate_pos_x = (!tab_backward) ? vid_conwidth : 0;
671 start_pos_x = tab_panel_pos_x;
676 for(i = 0; i < HUD_PANEL_NUM; ++i)
678 if (i == tab_panels[i] || i == starting_panel)
680 HUD_Panel_UpdatePosSizeForId(i)
681 if (panel_pos_y >= level && (panel_pos_y - level) < level_height)
682 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)) )
683 || ( 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)) ) )
686 tab_panel_pos = candidate_pos = panel_pos;
691 if (k == LEVELS_NUM) //tab_panel not found
694 if (old_tab_panel == -2) //this prevents an infinite loop (should not happen normally)
699 starting_panel = old_tab_panel;
701 goto find_tab_panel; //u must find tab_panel!
705 level = mod(level + level_height, vid_conheight);
707 candidate_pos_x = vid_conwidth;
711 level = mod(level - level_height, vid_conheight);
712 start_pos_x = vid_conwidth;
717 tab_panels[tab_panel] = tab_panel;
719 else if(nPrimary == K_SPACE && hudShiftState & S_CTRL) // enable/disable highlighted panel or dock
721 if (bInputType == 1 || mouseClicked)
724 if (highlightedPanel != -1)
726 HUD_Panel_GetName(highlightedPanel);
727 cvar_set(strcat("hud_panel_", panel_name), ftos(!(panel_enabled)));
730 cvar_set(strcat("hud_dock"), (autocvar_hud_dock == "") ? "dock" : "");
732 else if(nPrimary == 'c' && hudShiftState & S_CTRL) // copy highlighted panel size
734 if (bInputType == 1 || mouseClicked)
737 if (highlightedPanel != -1)
739 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
740 panel_size_copied = panel_size;
741 highlightedPanel_copied = highlightedPanel;
744 else if(nPrimary == 'v' && hudShiftState & S_CTRL) // past copied size on the highlighted panel
746 if (bInputType == 1 || mouseClicked)
749 if (highlightedPanel_copied == -1 || highlightedPanel == -1)
752 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
754 // reduce size if it'd go beyond screen boundaries
755 vector tmp_size = panel_size_copied;
756 if (panel_pos_x + panel_size_copied_x > vid_conwidth)
757 tmp_size_x = vid_conwidth - panel_pos_x;
758 if (panel_pos_y + panel_size_copied_y > vid_conheight)
759 tmp_size_y = vid_conheight - panel_pos_y;
761 if (panel_size == tmp_size)
765 panel_pos_backup = panel_pos;
766 panel_size_backup = panel_size;
767 highlightedPanel_backup = highlightedPanel;
769 s = strcat(ftos(tmp_size_x/vid_conwidth), " ", ftos(tmp_size_y/vid_conheight));
770 HUD_Panel_GetName(highlightedPanel);
771 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
773 else if(nPrimary == 'z' && hudShiftState & S_CTRL) // undo last action
775 if (bInputType == 1 || mouseClicked)
777 //restore previous values
778 if (highlightedPanel_backup != -1)
780 HUD_Panel_GetName(highlightedPanel_backup);
781 s = strcat(ftos(panel_pos_backup_x/vid_conwidth), " ", ftos(panel_pos_backup_y/vid_conheight));
782 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
783 s = strcat(ftos(panel_size_backup_x/vid_conwidth), " ", ftos(panel_size_backup_y/vid_conheight));
784 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
785 highlightedPanel_backup = -1;
788 else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
792 pressed_key_time = 0;
795 else if (pressed_key_time == 0)
796 pressed_key_time = time;
799 HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
801 else if(nPrimary == K_ENTER || nPrimary == K_SPACE || nPrimary == K_KP_ENTER)
805 if (highlightedPanel != -1)
806 HUD_Panel_EnableMenu();
808 else if(hit_con_bind)
814 float HUD_Panel_Check_Mouse_Pos()
818 while(j < HUD_PANEL_NUM)
823 HUD_Panel_UpdatePosSizeForId(i);
825 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
828 if(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)
832 // resize from topleft border
833 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)
837 // resize from topright border
838 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)
842 // resize from bottomleft border
843 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)
847 // resize from bottomright border
848 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)
856 // move a panel to the beginning of the panel order array (which means it gets drawn last, on top of everything else)
857 void HUD_Panel_FirstInDrawQ(float id)
860 var float place = -1;
861 // find out where in the array our current id is, save into place
862 for(i = 0; i < HUD_PANEL_NUM; ++i)
864 if(panel_order[i] == id)
870 // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
872 place = HUD_PANEL_NUM - 1;
874 // move all ids up by one step in the array until "place"
875 for(i = place; i > 0; --i)
877 panel_order[i] = panel_order[i-1];
879 // now save the new top id
882 // let's save them into the cvar by some strcat trickery
884 for(i = 0; i < HUD_PANEL_NUM; ++i)
886 s = strcat(s, ftos(panel_order[i]), " ");
888 cvar_set("_hud_panelorder", s);
889 if(hud_panelorder_prev)
890 strunzone(hud_panelorder_prev);
891 hud_panelorder_prev = strzone(autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here
894 void HUD_Panel_Highlight()
898 while(j < HUD_PANEL_NUM)
903 HUD_Panel_UpdatePosSizeForId(i);
905 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
908 if(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)
910 highlightedPanel = i;
911 HUD_Panel_FirstInDrawQ(i);
912 highlightedAction = 1;
913 panel_click_distance = mousepos - panel_pos;
916 // resize from topleft border
917 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)
919 highlightedPanel = i;
920 HUD_Panel_FirstInDrawQ(i);
921 highlightedAction = 2;
923 panel_click_distance = mousepos - panel_pos;
924 panel_click_resizeorigin = panel_pos + panel_size;
927 // resize from topright border
928 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)
930 highlightedPanel = i;
931 HUD_Panel_FirstInDrawQ(i);
932 highlightedAction = 2;
934 panel_click_distance_x = panel_size_x - mousepos_x + panel_pos_x;
935 panel_click_distance_y = mousepos_y - panel_pos_y;
936 panel_click_resizeorigin = panel_pos + eY * panel_size_y;
939 // resize from bottomleft border
940 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)
942 highlightedPanel = i;
943 HUD_Panel_FirstInDrawQ(i);
944 highlightedAction = 2;
946 panel_click_distance_x = mousepos_x - panel_pos_x;
947 panel_click_distance_y = panel_size_y - mousepos_y + panel_pos_y;
948 panel_click_resizeorigin = panel_pos + eX * panel_size_x;
951 // resize from bottomright border
952 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)
954 highlightedPanel = i;
955 HUD_Panel_FirstInDrawQ(i);
956 highlightedAction = 2;
958 panel_click_distance = panel_size - mousepos + panel_pos;
959 panel_click_resizeorigin = panel_pos;
963 highlightedPanel = -1;
964 highlightedAction = 0;
967 void HUD_Panel_EnableMenu()
970 menu_enabled_time = time;
971 HUD_Panel_GetName(highlightedPanel);
972 localcmd("menu_showhudoptions ", panel_name, "\n");
974 float mouse_over_panel;
975 void HUD_Panel_Mouse()
977 // 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
978 if (autocvar__menu_alpha == 0 && time - menu_enabled_time > 0.5)
982 print("menu_enabled: ", ftos(menu_enabled), "\n");
983 print("Highlighted: ", ftos(highlightedPanel), "\n");
984 print("Menu alpha: ", ftos(autocvar__menu_alpha), "\n");
987 // instantly hide the editor cursor if we open the HUDExit dialog
988 // as hud_fade_alpha doesn't decrease to 0 in this case
989 // TODO: find a way to fade the cursor out even in this case
990 if(menu_enabled == 1 || (menu_enabled == 2 && !hud_fade_alpha))
993 mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
995 mousepos_x = bound(0, mousepos_x, vid_conwidth);
996 mousepos_y = bound(0, mousepos_y, vid_conheight);
1000 if(prevMouseClicked == 0)
1002 if (tab_panel != -1)
1004 //stop ctrl-tab selection
1008 HUD_Panel_Highlight(); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
1009 // and calls HUD_Panel_UpdatePosSizeForId() for the highlighted panel
1010 if (highlightedPanel != -1)
1012 highlightedPanel_initial_pos = panel_pos;
1013 highlightedPanel_initial_size = panel_size;
1015 // doubleclick check
1016 if (time - prevMouseClickedTime < 0.4 && highlightedPanel != -1 && prevMouseClickedPos == mousepos)
1018 mouseClicked = 0; // to prevent spam, I guess.
1019 HUD_Panel_EnableMenu();
1023 prevMouseClickedTime = time;
1024 prevMouseClickedPos = mousepos;
1028 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1030 if (highlightedPanel != -1)
1032 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1033 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
1035 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
1037 panel_pos_backup = highlightedPanel_initial_pos;
1038 panel_size_backup = highlightedPanel_initial_size;
1039 highlightedPanel_backup = highlightedPanel;
1042 // in case the clicked panel is inside another panel and we aren't
1043 // moving it, avoid the immediate "fix" of its position/size
1044 // (often unwanted and hateful) by disabling collisions check
1045 hud_configure_checkcollisions = false;
1048 if(highlightedAction == 1)
1049 HUD_Panel_SetPos(mousepos - panel_click_distance);
1050 else if(highlightedAction == 2)
1053 if(resizeCorner == 1) {
1054 mySize_x = panel_click_resizeorigin_x - (mousepos_x - panel_click_distance_x);
1055 mySize_y = panel_click_resizeorigin_y - (mousepos_y - panel_click_distance_y);
1056 } else if(resizeCorner == 2) {
1057 mySize_x = mousepos_x + panel_click_distance_x - panel_click_resizeorigin_x;
1058 mySize_y = panel_click_distance_y + panel_click_resizeorigin_y - mousepos_y;
1059 } else if(resizeCorner == 3) {
1060 mySize_x = panel_click_resizeorigin_x + panel_click_distance_x - mousepos_x;
1061 mySize_y = mousepos_y + panel_click_distance_y - panel_click_resizeorigin_y;
1062 } else { // resizeCorner == 4
1063 mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x);
1064 mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y);
1066 HUD_Panel_SetPosSize(mySize);
1071 if(menu_enabled == 2)
1072 mouse_over_panel = 0;
1074 mouse_over_panel = HUD_Panel_Check_Mouse_Pos();
1075 if (mouse_over_panel && tab_panel == -1)
1076 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1078 // draw cursor after performing move/resize to have the panel pos/size updated before mouse_over_panel
1079 const vector cursorsize = '32 32 0';
1081 if(!mouse_over_panel)
1082 drawpic(mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1083 else if(mouse_over_panel == 1)
1084 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_move.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1085 else if(mouse_over_panel == 2)
1086 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1088 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize2.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1090 prevMouseClicked = mouseClicked;
1093 const float hlBorderSize = 4;
1094 const string hlBorder = "gfx/hud/default/border_highlighted";
1095 const string hlBorder2 = "gfx/hud/default/border_highlighted2";
1096 void HUD_Panel_HlBorder(float myBorder, vector color, float alpha)
1098 drawfill(panel_pos - '1 1 0' * myBorder, panel_size + '2 2 0' * myBorder, '0 0.5 1', .5 * alpha, DRAWFLAG_NORMAL);
1099 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);
1100 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);
1101 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);
1102 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);