1 #define HUD_Write(s) fputs(fh, s)
2 // q: quoted, n: not quoted
3 #define HUD_Write_Cvar_n(cvar) HUD_Write(strcat("seta ", cvar, " ", cvar_string(cvar), "\n"))
4 #define HUD_Write_Cvar_q(cvar) HUD_Write(strcat("seta ", cvar, " \"", cvar_string(cvar), "\"\n"))
5 #define HUD_Write_PanelCvar_n(cvar_suf) HUD_Write_Cvar_n(strcat("hud_panel_", panel_name, cvar_suf))
6 #define HUD_Write_PanelCvar_q(cvar_suf) HUD_Write_Cvar_q(strcat("hud_panel_", panel_name, cvar_suf))
8 void HUD_Panel_ExportCfg(string cfgname)
11 string filename = strcat("hud_", autocvar_hud_skin, "_", cfgname, ".cfg");
12 fh = fopen(filename, FILE_WRITE);
15 HUD_Write_Cvar_q("hud_skin");
16 HUD_Write_Cvar_q("hud_panel_bg");
17 HUD_Write_Cvar_q("hud_panel_bg_color");
18 HUD_Write_Cvar_q("hud_panel_bg_color_team");
19 HUD_Write_Cvar_q("hud_panel_bg_alpha");
20 HUD_Write_Cvar_q("hud_panel_bg_border");
21 HUD_Write_Cvar_q("hud_panel_bg_padding");
22 HUD_Write_Cvar_q("hud_panel_fg_alpha");
25 HUD_Write_Cvar_q("hud_dock");
26 HUD_Write_Cvar_q("hud_dock_color");
27 HUD_Write_Cvar_q("hud_dock_color_team");
28 HUD_Write_Cvar_q("hud_dock_alpha");
31 HUD_Write_Cvar_q("hud_progressbar_alpha");
32 HUD_Write_Cvar_q("hud_progressbar_strength_color");
33 HUD_Write_Cvar_q("hud_progressbar_shield_color");
34 HUD_Write_Cvar_q("hud_progressbar_health_color");
35 HUD_Write_Cvar_q("hud_progressbar_armor_color");
36 HUD_Write_Cvar_q("hud_progressbar_fuel_color");
37 HUD_Write_Cvar_q("hud_progressbar_nexball_color");
40 HUD_Write_Cvar_q("_hud_panelorder");
43 HUD_Write_Cvar_q("hud_configure_grid");
44 HUD_Write_Cvar_q("hud_configure_grid_xsize");
45 HUD_Write_Cvar_q("hud_configure_grid_ysize");
48 // common cvars for all panels
50 for (i = 0; i < HUD_PANEL_NUM; ++i)
54 HUD_Write_PanelCvar_n("");
55 HUD_Write_PanelCvar_q("_pos");
56 HUD_Write_PanelCvar_q("_size");
57 HUD_Write_PanelCvar_q("_bg");
58 HUD_Write_PanelCvar_q("_bg_color");
59 HUD_Write_PanelCvar_q("_bg_color_team");
60 HUD_Write_PanelCvar_q("_bg_alpha");
61 HUD_Write_PanelCvar_q("_bg_border");
62 HUD_Write_PanelCvar_q("_bg_padding");
64 case HUD_PANEL_WEAPONS:
65 HUD_Write_PanelCvar_q("_complainbubble");
66 HUD_Write_PanelCvar_q("_complainbubble_padding");
67 HUD_Write_PanelCvar_q("_complainbubble_color_outofammo");
68 HUD_Write_PanelCvar_q("_complainbubble_color_donthave");
69 HUD_Write_PanelCvar_q("_complainbubble_color_unavailable");
70 HUD_Write_PanelCvar_q("_ammo_color");
71 HUD_Write_PanelCvar_q("_ammo_alpha");
72 HUD_Write_PanelCvar_q("_aspect");
73 HUD_Write_PanelCvar_q("_timeout");
74 HUD_Write_PanelCvar_q("_timeout_effect");
77 HUD_Write_PanelCvar_q("_onlycurrent");
78 HUD_Write_PanelCvar_q("_iconalign");
79 HUD_Write_PanelCvar_q("_progressbar");
80 HUD_Write_PanelCvar_q("_progressbar_name");
81 HUD_Write_PanelCvar_q("_progressbar_xoffset");
82 HUD_Write_PanelCvar_q("_text");
84 case HUD_PANEL_POWERUPS:
85 HUD_Write_PanelCvar_q("_flip");
86 HUD_Write_PanelCvar_q("_iconalign");
87 HUD_Write_PanelCvar_q("_baralign");
88 HUD_Write_PanelCvar_q("_progressbar");
89 HUD_Write_PanelCvar_q("_progressbar_strength");
90 HUD_Write_PanelCvar_q("_progressbar_shield");
92 case HUD_PANEL_HEALTHARMOR:
93 HUD_Write_PanelCvar_q("_flip");
94 HUD_Write_PanelCvar_q("_iconalign");
95 HUD_Write_PanelCvar_q("_baralign");
96 HUD_Write_PanelCvar_q("_progressbar");
97 HUD_Write_PanelCvar_q("_progressbar_health");
98 HUD_Write_PanelCvar_q("_progressbar_armor");
99 HUD_Write_PanelCvar_q("_text");
101 case HUD_PANEL_NOTIFY:
102 HUD_Write_PanelCvar_q("_flip");
103 HUD_Write_PanelCvar_q("_fontsize");
104 HUD_Write_PanelCvar_q("_print");
106 case HUD_PANEL_RADAR:
107 HUD_Write_PanelCvar_q("_foreground_alpha");
110 HUD_Write_PanelCvar_q("_alreadyvoted_alpha");
112 case HUD_PANEL_PRESSEDKEYS:
113 HUD_Write_PanelCvar_q("_aspect");
115 case HUD_PANEL_INFOMESSAGES:
116 HUD_Write_PanelCvar_q("_flip");
118 case HUD_PANEL_PHYSICS:
119 HUD_Write_PanelCvar_q("_flip");
120 HUD_Write_PanelCvar_q("_baralign");
121 HUD_Write_PanelCvar_q("_progressbar");
122 HUD_Write_PanelCvar_q("_acceleration_mode");
124 case HUD_PANEL_CENTERPRINT:
125 HUD_Write_PanelCvar_q("_align");
126 HUD_Write_PanelCvar_q("_flip");
127 HUD_Write_PanelCvar_q("_fontscale");
128 HUD_Write_PanelCvar_q("_time");
129 HUD_Write_PanelCvar_q("_fadetime");
134 HUD_Write("menu_sync\n"); // force the menu to reread the cvars, so that the dialogs are updated
136 print(sprintf(_("^2Successfully exported to %s! (Note: It's saved in data/data/)\n"), filename));
140 print(sprintf(_("^1Couldn't write to %s\n"), filename));
143 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
144 vector HUD_Panel_CheckMove(vector myPos, vector mySize)
147 float myCenter_x, myCenter_y, targCenter_x, targCenter_y;
151 for (i = 0; i < HUD_PANEL_NUM; ++i) {
152 if(i == highlightedPanel || !panel_enabled)
155 HUD_Panel_UpdatePosSizeForId(i);
157 panel_pos -= '1 1 0' * panel_bg_border;
158 panel_size += '2 2 0' * panel_bg_border;
160 if(myPos_y + mySize_y < panel_pos_y)
162 if(myPos_y > panel_pos_y + panel_size_y)
165 if(myPos_x + mySize_x < panel_pos_x)
167 if(myPos_x > panel_pos_x + panel_size_x)
170 // OK, there IS a collision.
172 myCenter_x = myPos_x + 0.5 * mySize_x;
173 myCenter_y = myPos_y + 0.5 * mySize_y;
175 targCenter_x = panel_pos_x + 0.5 * panel_size_x;
176 targCenter_y = panel_pos_y + 0.5 * panel_size_y;
178 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
180 if(myPos_x + mySize_x - panel_pos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
181 myTarget_x = panel_pos_x - mySize_x;
182 else // push it upwards
183 myTarget_y = panel_pos_y - mySize_y;
185 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
187 if(panel_pos_x + panel_size_x - myPos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
188 myTarget_x = panel_pos_x + panel_size_x;
189 else // push it upwards
190 myTarget_y = panel_pos_y - mySize_y;
192 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
194 if(myPos_x + mySize_x - panel_pos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
195 myTarget_x = panel_pos_x - mySize_x;
196 else // push it downwards
197 myTarget_y = panel_pos_y + panel_size_y;
199 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
201 if(panel_pos_x + panel_size_x - myPos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
202 myTarget_x = panel_pos_x + panel_size_x;
203 else // push it downwards
204 myTarget_y = panel_pos_y + panel_size_y;
206 //if(cvar("hud_configure_checkcollisions_debug"))
207 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
213 void HUD_Panel_SetPos(vector pos)
215 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
219 //if(cvar("hud_configure_checkcollisions_debug"))
220 //drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
222 if(autocvar_hud_configure_grid)
224 pos_x = floor((pos_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
225 pos_y = floor((pos_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
228 if(hud_configure_checkcollisions)
229 pos = HUD_Panel_CheckMove(pos, mySize);
231 pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
232 pos_y = bound(0, pos_y, vid_conheight - mySize_y);
235 s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
237 HUD_Panel_GetName(highlightedPanel);
238 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
241 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
242 vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
247 float dist_x, dist_y;
249 ratio = mySize_x/mySize_y;
251 for (i = 0; i < HUD_PANEL_NUM; ++i) {
252 if(i == highlightedPanel || !panel_enabled)
255 HUD_Panel_UpdatePosSizeForId(i);
257 panel_pos -= '1 1 0' * panel_bg_border;
258 panel_size += '2 2 0' * panel_bg_border;
260 targEndPos = panel_pos + panel_size;
262 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
263 if(resizeorigin_x > panel_pos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > panel_pos_y && resizeorigin_y < targEndPos_y)
266 if (resizeCorner == 1)
268 // check if this panel is on our way
269 if (resizeorigin_x <= panel_pos_x)
271 if (resizeorigin_y <= panel_pos_y)
273 if (targEndPos_x <= resizeorigin_x - mySize_x)
275 if (targEndPos_y <= resizeorigin_y - mySize_y)
278 // there is a collision:
279 // detect which side of the panel we are facing is actually limiting the resizing
280 // (which side the resize direction finds for first) and reduce the size up to there
282 // dist is the distance between resizeorigin and the "analogous" point of the panel
283 // in this case between resizeorigin (bottom-right point) and the bottom-right point of the panel
284 dist_x = resizeorigin_x - targEndPos_x;
285 dist_y = resizeorigin_y - targEndPos_y;
286 if (dist_y <= 0 || dist_x / dist_y > ratio)
287 mySize_x = min(mySize_x, dist_x);
289 mySize_y = min(mySize_y, dist_y);
291 else if (resizeCorner == 2)
293 if (resizeorigin_x >= targEndPos_x)
295 if (resizeorigin_y <= panel_pos_y)
297 if (panel_pos_x >= resizeorigin_x + mySize_x)
299 if (targEndPos_y <= resizeorigin_y - mySize_y)
302 dist_x = panel_pos_x - resizeorigin_x;
303 dist_y = resizeorigin_y - targEndPos_y;
304 if (dist_y <= 0 || dist_x / dist_y > ratio)
305 mySize_x = min(mySize_x, dist_x);
307 mySize_y = min(mySize_y, dist_y);
309 else if (resizeCorner == 3)
311 if (resizeorigin_x <= panel_pos_x)
313 if (resizeorigin_y >= targEndPos_y)
315 if (targEndPos_x <= resizeorigin_x - mySize_x)
317 if (panel_pos_y >= resizeorigin_y + mySize_y)
320 dist_x = resizeorigin_x - targEndPos_x;
321 dist_y = panel_pos_y - resizeorigin_y;
322 if (dist_y <= 0 || dist_x / dist_y > ratio)
323 mySize_x = min(mySize_x, dist_x);
325 mySize_y = min(mySize_y, dist_y);
327 else if (resizeCorner == 4)
329 if (resizeorigin_x >= targEndPos_x)
331 if (resizeorigin_y >= targEndPos_y)
333 if (panel_pos_x >= resizeorigin_x + mySize_x)
335 if (panel_pos_y >= resizeorigin_y + mySize_y)
338 dist_x = panel_pos_x - resizeorigin_x;
339 dist_y = panel_pos_y - resizeorigin_y;
340 if (dist_y <= 0 || dist_x / dist_y > ratio)
341 mySize_x = min(mySize_x, dist_x);
343 mySize_y = min(mySize_y, dist_y);
345 //if(cvar("hud_configure_checkcollisions_debug"))
346 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
352 void HUD_Panel_SetPosSize(vector mySize)
354 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
356 resizeorigin = panel_click_resizeorigin;
359 // minimum panel size cap
360 mySize_x = max(0.025 * vid_conwidth, mySize_x);
361 mySize_y = max(0.025 * vid_conheight, mySize_y);
363 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.
365 mySize_x = max(17 * autocvar_con_chatsize, mySize_x);
366 mySize_y = max(2 * autocvar_con_chatsize + 2 * panel_bg_padding, mySize_y);
369 // collision testing|
370 // -----------------+
372 // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
373 if(resizeCorner == 1) {
374 myPos_x = resizeorigin_x - mySize_x;
375 myPos_y = resizeorigin_y - mySize_y;
376 } else if(resizeCorner == 2) {
377 myPos_x = resizeorigin_x;
378 myPos_y = resizeorigin_y - mySize_y;
379 } else if(resizeCorner == 3) {
380 myPos_x = resizeorigin_x - mySize_x;
381 myPos_y = resizeorigin_y;
382 } else { // resizeCorner == 4
383 myPos_x = resizeorigin_x;
384 myPos_y = resizeorigin_y;
387 // left/top screen edges
389 mySize_x = mySize_x + myPos_x;
391 mySize_y = mySize_y + myPos_y;
393 // bottom/right screen edges
394 if(myPos_x + mySize_x > vid_conwidth)
395 mySize_x = vid_conwidth - myPos_x;
396 if(myPos_y + mySize_y > vid_conheight)
397 mySize_y = vid_conheight - myPos_y;
399 //if(cvar("hud_configure_checkcollisions_debug"))
400 //drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
402 // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
403 if(autocvar_hud_configure_grid)
405 mySize_x = floor((mySize_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
406 mySize_y = floor((mySize_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
409 if(hud_configure_checkcollisions)
410 mySize = HUD_Panel_CheckResize(mySize, resizeorigin);
412 // 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)
413 mySize_x = max(0.025 * vid_conwidth, mySize_x);
414 mySize_y = max(0.025 * vid_conheight, mySize_y);
416 // do another pos check, as size might have changed by now
417 if(resizeCorner == 1) {
418 myPos_x = resizeorigin_x - mySize_x;
419 myPos_y = resizeorigin_y - mySize_y;
420 } else if(resizeCorner == 2) {
421 myPos_x = resizeorigin_x;
422 myPos_y = resizeorigin_y - mySize_y;
423 } else if(resizeCorner == 3) {
424 myPos_x = resizeorigin_x - mySize_x;
425 myPos_y = resizeorigin_y;
426 } else { // resizeCorner == 4
427 myPos_x = resizeorigin_x;
428 myPos_y = resizeorigin_y;
431 //if(cvar("hud_configure_checkcollisions_debug"))
432 //drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
434 HUD_Panel_GetName(highlightedPanel);
436 s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
437 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
439 s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
440 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
443 float pressed_key_time;
444 vector highlightedPanel_initial_pos, highlightedPanel_initial_size;
445 void HUD_Panel_Arrow_Action(float nPrimary)
447 if (highlightedPanel == -1)
450 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
453 if(autocvar_hud_configure_grid)
455 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
457 if (hudShiftState & S_SHIFT)
458 step = hud_configure_realGridSize_y;
460 step = 2 * hud_configure_realGridSize_y;
464 if (hudShiftState & S_SHIFT)
465 step = hud_configure_realGridSize_x;
467 step = 2 * hud_configure_realGridSize_x;
472 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
473 step = vid_conheight;
476 if (hudShiftState & S_SHIFT)
477 step = (step / 256); // more precision
479 step = (step / 64) * (1 + 2 * (time - pressed_key_time));
482 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
484 highlightedPanel_initial_pos = panel_pos;
485 highlightedPanel_initial_size = panel_size;
487 if (hudShiftState & S_ALT) // resize
489 highlightedAction = 1;
490 if(nPrimary == K_UPARROW)
492 else if(nPrimary == K_RIGHTARROW)
494 else if(nPrimary == K_LEFTARROW)
496 else // if(nPrimary == K_DOWNARROW)
499 // ctrl+arrow reduces the size, instead of increasing it
500 // Note that ctrl disables collisions check too, but it's fine
501 // since we don't collide with anything reducing the size
502 if (hudShiftState & S_CTRL) {
504 resizeCorner = 5 - resizeCorner;
509 panel_click_resizeorigin = panel_pos;
510 if(resizeCorner == 1) {
511 panel_click_resizeorigin += mySize;
513 } else if(resizeCorner == 2) {
514 panel_click_resizeorigin_y += mySize_y;
516 } else if(resizeCorner == 3) {
517 panel_click_resizeorigin_x += mySize_x;
519 } else { // resizeCorner == 4
522 HUD_Panel_SetPosSize(mySize);
526 highlightedAction = 2;
529 if(nPrimary == K_UPARROW)
531 else if(nPrimary == K_DOWNARROW)
533 else if(nPrimary == K_LEFTARROW)
535 else // if(nPrimary == K_RIGHTARROW)
538 HUD_Panel_SetPos(pos);
541 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
543 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
546 panel_pos_backup = highlightedPanel_initial_pos;
547 panel_size_backup = highlightedPanel_initial_size;
548 highlightedPanel_backup = highlightedPanel;
552 const float S_MOUSE1 = 1;
553 const float S_MOUSE2 = 2;
554 const float S_MOUSE3 = 4;
556 float prevMouseClicked; // previous state
557 float prevMouseClickedTime; // time during previous left mouse click, to check for doubleclicks
558 vector prevMouseClickedPos; // pos during previous left mouse click, to check for doubleclicks
560 void HUD_Panel_EnableMenu();
561 float tab_panels[HUD_PANEL_NUM];
562 float tab_panel, tab_backward;
563 vector tab_panel_pos;
564 void HUD_Panel_FirstInDrawQ(float id);
565 void reset_tab_panels()
568 for(i = 0; i < HUD_PANEL_NUM; ++i)
571 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
575 if(!autocvar__hud_configure)
578 // allow console bind to work
581 con_keys = findkeysforcommand("toggleconsole");
582 keys = tokenize(con_keys);
584 float hit_con_bind, i;
585 for (i = 0; i < keys; ++i)
587 if(nPrimary == stof(argv(i)))
591 if(bInputType == 0) {
592 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
593 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
594 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
596 else if(bInputType == 1) {
597 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
598 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
599 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
602 if(nPrimary == K_CTRL)
604 if (bInputType == 1) //ctrl has been released
608 //switch to selected panel
609 highlightedPanel = tab_panel;
610 highlightedAction = 0;
611 HUD_Panel_FirstInDrawQ(highlightedPanel);
618 if(nPrimary == K_MOUSE1)
620 if(bInputType == 0) // key pressed
621 mouseClicked |= S_MOUSE1;
622 else if(bInputType == 1) // key released
623 mouseClicked -= (mouseClicked & S_MOUSE1);
625 else if(nPrimary == K_MOUSE2)
627 if(bInputType == 0) // key pressed
628 mouseClicked |= S_MOUSE2;
629 else if(bInputType == 1) // key released
630 mouseClicked -= (mouseClicked & S_MOUSE2);
632 else if(nPrimary == K_ESCAPE)
637 menu_enabled_time = time;
638 localcmd("menu_showhudexit\n");
640 else if(nPrimary == K_BACKSPACE && hudShiftState & S_CTRL)
645 cvar_set("_hud_configure", "0");
647 else if(nPrimary == K_TAB && hudShiftState & S_CTRL) // select and highlight another panel
649 if (bInputType == 1 || mouseClicked)
652 //FIXME: if a panel is highlighted, has the same pos_x and lays in the same level
653 //of other panels then next consecutive ctrl-tab will select the highlighted panel too
654 //(it should only after every other panel of the hud)
655 //It's a minor bug anyway, we can live with it
657 float starting_panel;
658 float old_tab_panel = tab_panel;
659 if (tab_panel == -1) //first press of TAB
661 if (highlightedPanel != -1)
662 HUD_Panel_UpdatePosSizeForId(highlightedPanel)
665 starting_panel = highlightedPanel; //can be -1, it means no starting panel
666 tab_panel_pos = panel_pos; //to compute level
670 if ( ((!tab_backward) && (hudShiftState & S_SHIFT)) || (tab_backward && !(hudShiftState & S_SHIFT)) ) //tab direction changed?
672 starting_panel = tab_panel;
674 tab_backward = (hudShiftState & S_SHIFT);
676 float k, level, start_pos_x;
677 vector candidate_pos;
678 const float LEVELS_NUM = 4;
679 const float level_height = vid_conheight / LEVELS_NUM;
681 level = floor(tab_panel_pos_y / level_height) * level_height; //starting level
682 candidate_pos_x = (!tab_backward) ? vid_conwidth : 0;
683 start_pos_x = tab_panel_pos_x;
688 for(i = 0; i < HUD_PANEL_NUM; ++i)
690 if (i == tab_panels[i] || i == starting_panel)
692 HUD_Panel_UpdatePosSizeForId(i)
693 if (panel_pos_y >= level && (panel_pos_y - level) < level_height)
694 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)) )
695 || ( 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)) ) )
698 tab_panel_pos = candidate_pos = panel_pos;
703 if (k == LEVELS_NUM) //tab_panel not found
706 if (old_tab_panel == -2) //this prevents an infinite loop (should not happen normally)
711 starting_panel = old_tab_panel;
713 goto find_tab_panel; //u must find tab_panel!
717 level = mod(level + level_height, vid_conheight);
719 candidate_pos_x = vid_conwidth;
723 level = mod(level - level_height, vid_conheight);
724 start_pos_x = vid_conwidth;
729 tab_panels[tab_panel] = tab_panel;
731 else if(nPrimary == K_SPACE && hudShiftState & S_CTRL) // enable/disable highlighted panel or dock
733 if (bInputType == 1 || mouseClicked)
736 if (highlightedPanel != -1)
738 HUD_Panel_GetName(highlightedPanel);
739 cvar_set(strcat("hud_panel_", panel_name), ftos(!(panel_enabled)));
742 cvar_set(strcat("hud_dock"), (autocvar_hud_dock == "") ? "dock" : "");
744 else if(nPrimary == 'c' && hudShiftState & S_CTRL) // copy highlighted panel size
746 if (bInputType == 1 || mouseClicked)
749 if (highlightedPanel != -1)
751 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
752 panel_size_copied = panel_size;
753 highlightedPanel_copied = highlightedPanel;
756 else if(nPrimary == 'v' && hudShiftState & S_CTRL) // past copied size on the highlighted panel
758 if (bInputType == 1 || mouseClicked)
761 if (highlightedPanel_copied == -1 || highlightedPanel == -1)
764 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
766 // reduce size if it'd go beyond screen boundaries
767 vector tmp_size = panel_size_copied;
768 if (panel_pos_x + panel_size_copied_x > vid_conwidth)
769 tmp_size_x = vid_conwidth - panel_pos_x;
770 if (panel_pos_y + panel_size_copied_y > vid_conheight)
771 tmp_size_y = vid_conheight - panel_pos_y;
773 if (panel_size == tmp_size)
777 panel_pos_backup = panel_pos;
778 panel_size_backup = panel_size;
779 highlightedPanel_backup = highlightedPanel;
781 s = strcat(ftos(tmp_size_x/vid_conwidth), " ", ftos(tmp_size_y/vid_conheight));
782 HUD_Panel_GetName(highlightedPanel);
783 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
785 else if(nPrimary == 'z' && hudShiftState & S_CTRL) // undo last action
787 if (bInputType == 1 || mouseClicked)
789 //restore previous values
790 if (highlightedPanel_backup != -1)
792 HUD_Panel_GetName(highlightedPanel_backup);
793 s = strcat(ftos(panel_pos_backup_x/vid_conwidth), " ", ftos(panel_pos_backup_y/vid_conheight));
794 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
795 s = strcat(ftos(panel_size_backup_x/vid_conwidth), " ", ftos(panel_size_backup_y/vid_conheight));
796 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
797 highlightedPanel_backup = -1;
800 else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
804 pressed_key_time = 0;
807 else if (pressed_key_time == 0)
808 pressed_key_time = time;
811 HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
813 else if(nPrimary == K_ENTER || nPrimary == K_SPACE || nPrimary == K_KP_ENTER)
817 if (highlightedPanel != -1)
818 HUD_Panel_EnableMenu();
820 else if(hit_con_bind)
826 float HUD_Panel_Check_Mouse_Pos(float allow_move)
830 while(j < HUD_PANEL_NUM)
835 HUD_Panel_UpdatePosSizeForId(i);
837 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
840 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)
844 // resize from topleft border
845 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)
849 // resize from topright border
850 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)
854 // resize from bottomleft border
855 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)
859 // resize from bottomright border
860 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)
868 // move a panel to the beginning of the panel order array (which means it gets drawn last, on top of everything else)
869 void HUD_Panel_FirstInDrawQ(float id)
872 var float place = -1;
873 // find out where in the array our current id is, save into place
874 for(i = 0; i < HUD_PANEL_NUM; ++i)
876 if(panel_order[i] == id)
882 // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
884 place = HUD_PANEL_NUM - 1;
886 // move all ids up by one step in the array until "place"
887 for(i = place; i > 0; --i)
889 panel_order[i] = panel_order[i-1];
891 // now save the new top id
894 // let's save them into the cvar by some strcat trickery
896 for(i = 0; i < HUD_PANEL_NUM; ++i)
898 s = strcat(s, ftos(panel_order[i]), " ");
900 cvar_set("_hud_panelorder", s);
901 if(hud_panelorder_prev)
902 strunzone(hud_panelorder_prev);
903 hud_panelorder_prev = strzone(autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here
906 void HUD_Panel_Highlight(float allow_move)
910 while(j < HUD_PANEL_NUM)
915 HUD_Panel_UpdatePosSizeForId(i);
917 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
920 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)
922 highlightedPanel = i;
923 HUD_Panel_FirstInDrawQ(i);
924 highlightedAction = 1;
925 panel_click_distance = mousepos - panel_pos;
928 // resize from topleft border
929 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)
931 highlightedPanel = i;
932 HUD_Panel_FirstInDrawQ(i);
933 highlightedAction = 2;
935 panel_click_distance = mousepos - panel_pos;
936 panel_click_resizeorigin = panel_pos + panel_size;
939 // resize from topright border
940 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)
942 highlightedPanel = i;
943 HUD_Panel_FirstInDrawQ(i);
944 highlightedAction = 2;
946 panel_click_distance_x = panel_size_x - mousepos_x + panel_pos_x;
947 panel_click_distance_y = mousepos_y - panel_pos_y;
948 panel_click_resizeorigin = panel_pos + eY * panel_size_y;
951 // resize from bottomleft border
952 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)
954 highlightedPanel = i;
955 HUD_Panel_FirstInDrawQ(i);
956 highlightedAction = 2;
958 panel_click_distance_x = mousepos_x - panel_pos_x;
959 panel_click_distance_y = panel_size_y - mousepos_y + panel_pos_y;
960 panel_click_resizeorigin = panel_pos + eX * panel_size_x;
963 // resize from bottomright border
964 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)
966 highlightedPanel = i;
967 HUD_Panel_FirstInDrawQ(i);
968 highlightedAction = 2;
970 panel_click_distance = panel_size - mousepos + panel_pos;
971 panel_click_resizeorigin = panel_pos;
975 highlightedPanel = -1;
976 highlightedAction = 0;
979 void HUD_Panel_EnableMenu()
982 menu_enabled_time = time;
983 HUD_Panel_GetName(highlightedPanel);
984 localcmd("menu_showhudoptions ", panel_name, "\n");
986 float mouse_over_panel;
987 void HUD_Panel_Mouse()
989 // 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
990 if (autocvar__menu_alpha == 0 && time - menu_enabled_time > 0.5)
994 print("menu_enabled: ", ftos(menu_enabled), "\n");
995 print("Highlighted: ", ftos(highlightedPanel), "\n");
996 print("Menu alpha: ", ftos(autocvar__menu_alpha), "\n");
999 // instantly hide the editor cursor if we open the HUDExit dialog
1000 // as hud_fade_alpha doesn't decrease to 0 in this case
1001 // TODO: find a way to fade the cursor out even in this case
1002 if(menu_enabled == 1 || (menu_enabled == 2 && !hud_fade_alpha))
1005 mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
1007 mousepos_x = bound(0, mousepos_x, vid_conwidth);
1008 mousepos_y = bound(0, mousepos_y, vid_conheight);
1012 if(prevMouseClicked == 0)
1014 if (tab_panel != -1)
1016 //stop ctrl-tab selection
1020 HUD_Panel_Highlight(mouseClicked & S_MOUSE1); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
1021 // and calls HUD_Panel_UpdatePosSizeForId() for the highlighted panel
1022 if (highlightedPanel != -1)
1024 highlightedPanel_initial_pos = panel_pos;
1025 highlightedPanel_initial_size = panel_size;
1027 // doubleclick check
1028 if ((mouseClicked & S_MOUSE1) && time - prevMouseClickedTime < 0.4 && highlightedPanel != -1 && prevMouseClickedPos == mousepos)
1030 mouseClicked = 0; // to prevent spam, I guess.
1031 HUD_Panel_EnableMenu();
1035 if (mouseClicked & S_MOUSE1)
1037 prevMouseClickedTime = time;
1038 prevMouseClickedPos = mousepos;
1040 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(mouseClicked & S_MOUSE1);
1044 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1046 if (highlightedPanel != -1)
1048 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1049 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
1051 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
1053 panel_pos_backup = highlightedPanel_initial_pos;
1054 panel_size_backup = highlightedPanel_initial_size;
1055 highlightedPanel_backup = highlightedPanel;
1058 // in case the clicked panel is inside another panel and we aren't
1059 // moving it, avoid the immediate "fix" of its position/size
1060 // (often unwanted and hateful) by disabling collisions check
1061 hud_configure_checkcollisions = false;
1064 if(highlightedAction == 1)
1065 HUD_Panel_SetPos(mousepos - panel_click_distance);
1066 else if(highlightedAction == 2)
1069 if(resizeCorner == 1) {
1070 mySize_x = panel_click_resizeorigin_x - (mousepos_x - panel_click_distance_x);
1071 mySize_y = panel_click_resizeorigin_y - (mousepos_y - panel_click_distance_y);
1072 } else if(resizeCorner == 2) {
1073 mySize_x = mousepos_x + panel_click_distance_x - panel_click_resizeorigin_x;
1074 mySize_y = panel_click_distance_y + panel_click_resizeorigin_y - mousepos_y;
1075 } else if(resizeCorner == 3) {
1076 mySize_x = panel_click_resizeorigin_x + panel_click_distance_x - mousepos_x;
1077 mySize_y = mousepos_y + panel_click_distance_y - panel_click_resizeorigin_y;
1078 } else { // resizeCorner == 4
1079 mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x);
1080 mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y);
1082 HUD_Panel_SetPosSize(mySize);
1087 if(menu_enabled == 2)
1088 mouse_over_panel = 0;
1090 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(TRUE);
1091 if (mouse_over_panel && tab_panel == -1)
1092 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1094 // draw cursor after performing move/resize to have the panel pos/size updated before mouse_over_panel
1095 const vector cursorsize = '32 32 0';
1097 if(!mouse_over_panel)
1098 drawpic(mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1099 else if(mouse_over_panel == 1)
1100 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_move.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1101 else if(mouse_over_panel == 2)
1102 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1104 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize2.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1106 prevMouseClicked = mouseClicked;
1109 const float hlBorderSize = 4;
1110 const string hlBorder = "gfx/hud/default/border_highlighted";
1111 const string hlBorder2 = "gfx/hud/default/border_highlighted2";
1112 void HUD_Panel_HlBorder(float myBorder, vector color, float alpha)
1114 drawfill(panel_pos - '1 1 0' * myBorder, panel_size + '2 2 0' * myBorder, '0 0.5 1', .5 * alpha, DRAWFLAG_NORMAL);
1115 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);
1116 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);
1117 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);
1118 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);