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_time");
68 HUD_Write_PanelCvar_q("_complainbubble_fadetime");
69 HUD_Write_PanelCvar_q("_complainbubble_color_outofammo");
70 HUD_Write_PanelCvar_q("_complainbubble_color_donthave");
71 HUD_Write_PanelCvar_q("_complainbubble_color_unavailable");
72 HUD_Write_PanelCvar_q("_ammo_color");
73 HUD_Write_PanelCvar_q("_ammo_alpha");
74 HUD_Write_PanelCvar_q("_aspect");
75 HUD_Write_PanelCvar_q("_timeout");
76 HUD_Write_PanelCvar_q("_timeout_effect");
79 HUD_Write_PanelCvar_q("_onlycurrent");
80 HUD_Write_PanelCvar_q("_iconalign");
81 HUD_Write_PanelCvar_q("_progressbar");
82 HUD_Write_PanelCvar_q("_progressbar_name");
83 HUD_Write_PanelCvar_q("_progressbar_xoffset");
84 HUD_Write_PanelCvar_q("_text");
86 case HUD_PANEL_POWERUPS:
87 HUD_Write_PanelCvar_q("_flip");
88 HUD_Write_PanelCvar_q("_iconalign");
89 HUD_Write_PanelCvar_q("_baralign");
90 HUD_Write_PanelCvar_q("_progressbar");
91 HUD_Write_PanelCvar_q("_progressbar_strength");
92 HUD_Write_PanelCvar_q("_progressbar_shield");
94 case HUD_PANEL_HEALTHARMOR:
95 HUD_Write_PanelCvar_q("_flip");
96 HUD_Write_PanelCvar_q("_iconalign");
97 HUD_Write_PanelCvar_q("_baralign");
98 HUD_Write_PanelCvar_q("_progressbar");
99 HUD_Write_PanelCvar_q("_progressbar_health");
100 HUD_Write_PanelCvar_q("_progressbar_armor");
101 HUD_Write_PanelCvar_q("_text");
103 case HUD_PANEL_NOTIFY:
104 HUD_Write_PanelCvar_q("_flip");
105 HUD_Write_PanelCvar_q("_fontsize");
106 HUD_Write_PanelCvar_q("_print");
108 case HUD_PANEL_RADAR:
109 HUD_Write_PanelCvar_q("_foreground_alpha");
112 HUD_Write_PanelCvar_q("_alreadyvoted_alpha");
114 case HUD_PANEL_PRESSEDKEYS:
115 HUD_Write_PanelCvar_q("_aspect");
117 case HUD_PANEL_INFOMESSAGES:
118 HUD_Write_PanelCvar_q("_flip");
120 case HUD_PANEL_PHYSICS:
121 HUD_Write_PanelCvar_q("_flip");
122 HUD_Write_PanelCvar_q("_baralign");
123 HUD_Write_PanelCvar_q("_progressbar");
124 HUD_Write_PanelCvar_q("_acceleration_mode");
126 case HUD_PANEL_CENTERPRINT:
127 HUD_Write_PanelCvar_q("_align");
128 HUD_Write_PanelCvar_q("_flip");
129 HUD_Write_PanelCvar_q("_fontscale");
130 HUD_Write_PanelCvar_q("_time");
131 HUD_Write_PanelCvar_q("_fadetime");
136 HUD_Write("menu_sync\n"); // force the menu to reread the cvars, so that the dialogs are updated
138 print(sprintf(_("^2Successfully exported to %s! (Note: It's saved in data/data/)\n"), filename));
142 print(sprintf(_("^1Couldn't write to %s\n"), filename));
145 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
146 vector HUD_Panel_CheckMove(vector myPos, vector mySize)
149 float myCenter_x, myCenter_y, targCenter_x, targCenter_y;
153 for (i = 0; i < HUD_PANEL_NUM; ++i) {
154 if(i == highlightedPanel || !panel_enabled)
157 HUD_Panel_UpdatePosSizeForId(i);
159 panel_pos -= '1 1 0' * panel_bg_border;
160 panel_size += '2 2 0' * panel_bg_border;
162 if(myPos_y + mySize_y < panel_pos_y)
164 if(myPos_y > panel_pos_y + panel_size_y)
167 if(myPos_x + mySize_x < panel_pos_x)
169 if(myPos_x > panel_pos_x + panel_size_x)
172 // OK, there IS a collision.
174 myCenter_x = myPos_x + 0.5 * mySize_x;
175 myCenter_y = myPos_y + 0.5 * mySize_y;
177 targCenter_x = panel_pos_x + 0.5 * panel_size_x;
178 targCenter_y = panel_pos_y + 0.5 * panel_size_y;
180 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
182 if(myPos_x + mySize_x - panel_pos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
183 myTarget_x = panel_pos_x - mySize_x;
184 else // push it upwards
185 myTarget_y = panel_pos_y - mySize_y;
187 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
189 if(panel_pos_x + panel_size_x - myPos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
190 myTarget_x = panel_pos_x + panel_size_x;
191 else // push it upwards
192 myTarget_y = panel_pos_y - mySize_y;
194 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
196 if(myPos_x + mySize_x - panel_pos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
197 myTarget_x = panel_pos_x - mySize_x;
198 else // push it downwards
199 myTarget_y = panel_pos_y + panel_size_y;
201 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
203 if(panel_pos_x + panel_size_x - myPos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
204 myTarget_x = panel_pos_x + panel_size_x;
205 else // push it downwards
206 myTarget_y = panel_pos_y + panel_size_y;
208 //if(cvar("hud_configure_checkcollisions_debug"))
209 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
215 void HUD_Panel_SetPos(vector pos)
217 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
221 //if(cvar("hud_configure_checkcollisions_debug"))
222 //drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
224 if(autocvar_hud_configure_grid)
226 pos_x = floor((pos_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
227 pos_y = floor((pos_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
230 if(hud_configure_checkcollisions)
231 pos = HUD_Panel_CheckMove(pos, mySize);
233 pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
234 pos_y = bound(0, pos_y, vid_conheight - mySize_y);
237 s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
239 HUD_Panel_GetName(highlightedPanel);
240 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
243 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
244 vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
249 float dist_x, dist_y;
251 ratio = mySize_x/mySize_y;
253 for (i = 0; i < HUD_PANEL_NUM; ++i) {
254 if(i == highlightedPanel || !panel_enabled)
257 HUD_Panel_UpdatePosSizeForId(i);
259 panel_pos -= '1 1 0' * panel_bg_border;
260 panel_size += '2 2 0' * panel_bg_border;
262 targEndPos = panel_pos + panel_size;
264 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
265 if(resizeorigin_x > panel_pos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > panel_pos_y && resizeorigin_y < targEndPos_y)
268 if (resizeCorner == 1)
270 // check if this panel is on our way
271 if (resizeorigin_x <= panel_pos_x)
273 if (resizeorigin_y <= panel_pos_y)
275 if (targEndPos_x <= resizeorigin_x - mySize_x)
277 if (targEndPos_y <= resizeorigin_y - mySize_y)
280 // there is a collision:
281 // detect which side of the panel we are facing is actually limiting the resizing
282 // (which side the resize direction finds for first) and reduce the size up to there
284 // dist is the distance between resizeorigin and the "analogous" point of the panel
285 // in this case between resizeorigin (bottom-right point) and the bottom-right point of the panel
286 dist_x = resizeorigin_x - targEndPos_x;
287 dist_y = resizeorigin_y - targEndPos_y;
288 if (dist_y <= 0 || dist_x / dist_y > ratio)
289 mySize_x = min(mySize_x, dist_x);
291 mySize_y = min(mySize_y, dist_y);
293 else if (resizeCorner == 2)
295 if (resizeorigin_x >= targEndPos_x)
297 if (resizeorigin_y <= panel_pos_y)
299 if (panel_pos_x >= resizeorigin_x + mySize_x)
301 if (targEndPos_y <= resizeorigin_y - mySize_y)
304 dist_x = panel_pos_x - resizeorigin_x;
305 dist_y = resizeorigin_y - targEndPos_y;
306 if (dist_y <= 0 || dist_x / dist_y > ratio)
307 mySize_x = min(mySize_x, dist_x);
309 mySize_y = min(mySize_y, dist_y);
311 else if (resizeCorner == 3)
313 if (resizeorigin_x <= panel_pos_x)
315 if (resizeorigin_y >= targEndPos_y)
317 if (targEndPos_x <= resizeorigin_x - mySize_x)
319 if (panel_pos_y >= resizeorigin_y + mySize_y)
322 dist_x = resizeorigin_x - targEndPos_x;
323 dist_y = panel_pos_y - resizeorigin_y;
324 if (dist_y <= 0 || dist_x / dist_y > ratio)
325 mySize_x = min(mySize_x, dist_x);
327 mySize_y = min(mySize_y, dist_y);
329 else if (resizeCorner == 4)
331 if (resizeorigin_x >= targEndPos_x)
333 if (resizeorigin_y >= targEndPos_y)
335 if (panel_pos_x >= resizeorigin_x + mySize_x)
337 if (panel_pos_y >= resizeorigin_y + mySize_y)
340 dist_x = panel_pos_x - resizeorigin_x;
341 dist_y = panel_pos_y - resizeorigin_y;
342 if (dist_y <= 0 || dist_x / dist_y > ratio)
343 mySize_x = min(mySize_x, dist_x);
345 mySize_y = min(mySize_y, dist_y);
347 //if(cvar("hud_configure_checkcollisions_debug"))
348 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
354 void HUD_Panel_SetPosSize(vector mySize)
356 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
358 resizeorigin = panel_click_resizeorigin;
361 // minimum panel size cap
362 mySize_x = max(0.025 * vid_conwidth, mySize_x);
363 mySize_y = max(0.025 * vid_conheight, mySize_y);
365 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.
367 mySize_x = max(17 * autocvar_con_chatsize, mySize_x);
368 mySize_y = max(2 * autocvar_con_chatsize + 2 * panel_bg_padding, mySize_y);
371 // collision testing|
372 // -----------------+
374 // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
375 if(resizeCorner == 1) {
376 myPos_x = resizeorigin_x - mySize_x;
377 myPos_y = resizeorigin_y - mySize_y;
378 } else if(resizeCorner == 2) {
379 myPos_x = resizeorigin_x;
380 myPos_y = resizeorigin_y - mySize_y;
381 } else if(resizeCorner == 3) {
382 myPos_x = resizeorigin_x - mySize_x;
383 myPos_y = resizeorigin_y;
384 } else { // resizeCorner == 4
385 myPos_x = resizeorigin_x;
386 myPos_y = resizeorigin_y;
389 // left/top screen edges
391 mySize_x = mySize_x + myPos_x;
393 mySize_y = mySize_y + myPos_y;
395 // bottom/right screen edges
396 if(myPos_x + mySize_x > vid_conwidth)
397 mySize_x = vid_conwidth - myPos_x;
398 if(myPos_y + mySize_y > vid_conheight)
399 mySize_y = vid_conheight - myPos_y;
401 //if(cvar("hud_configure_checkcollisions_debug"))
402 //drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
404 // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
405 if(autocvar_hud_configure_grid)
407 mySize_x = floor((mySize_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
408 mySize_y = floor((mySize_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
411 if(hud_configure_checkcollisions)
412 mySize = HUD_Panel_CheckResize(mySize, resizeorigin);
414 // 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)
415 mySize_x = max(0.025 * vid_conwidth, mySize_x);
416 mySize_y = max(0.025 * vid_conheight, mySize_y);
418 // do another pos check, as size might have changed by now
419 if(resizeCorner == 1) {
420 myPos_x = resizeorigin_x - mySize_x;
421 myPos_y = resizeorigin_y - mySize_y;
422 } else if(resizeCorner == 2) {
423 myPos_x = resizeorigin_x;
424 myPos_y = resizeorigin_y - mySize_y;
425 } else if(resizeCorner == 3) {
426 myPos_x = resizeorigin_x - mySize_x;
427 myPos_y = resizeorigin_y;
428 } else { // resizeCorner == 4
429 myPos_x = resizeorigin_x;
430 myPos_y = resizeorigin_y;
433 //if(cvar("hud_configure_checkcollisions_debug"))
434 //drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
436 HUD_Panel_GetName(highlightedPanel);
438 s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
439 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
441 s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
442 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
445 float pressed_key_time;
446 vector highlightedPanel_initial_pos, highlightedPanel_initial_size;
447 void HUD_Panel_Arrow_Action(float nPrimary)
449 if (highlightedPanel == -1)
452 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
455 if(autocvar_hud_configure_grid)
457 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
459 if (hudShiftState & S_SHIFT)
460 step = hud_configure_realGridSize_y;
462 step = 2 * hud_configure_realGridSize_y;
466 if (hudShiftState & S_SHIFT)
467 step = hud_configure_realGridSize_x;
469 step = 2 * hud_configure_realGridSize_x;
474 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
475 step = vid_conheight;
478 if (hudShiftState & S_SHIFT)
479 step = (step / 256); // more precision
481 step = (step / 64) * (1 + 2 * (time - pressed_key_time));
484 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
486 highlightedPanel_initial_pos = panel_pos;
487 highlightedPanel_initial_size = panel_size;
489 if (hudShiftState & S_ALT) // resize
491 highlightedAction = 1;
492 if(nPrimary == K_UPARROW)
494 else if(nPrimary == K_RIGHTARROW)
496 else if(nPrimary == K_LEFTARROW)
498 else // if(nPrimary == K_DOWNARROW)
501 // ctrl+arrow reduces the size, instead of increasing it
502 // Note that ctrl disables collisions check too, but it's fine
503 // since we don't collide with anything reducing the size
504 if (hudShiftState & S_CTRL) {
506 resizeCorner = 5 - resizeCorner;
511 panel_click_resizeorigin = panel_pos;
512 if(resizeCorner == 1) {
513 panel_click_resizeorigin += mySize;
515 } else if(resizeCorner == 2) {
516 panel_click_resizeorigin_y += mySize_y;
518 } else if(resizeCorner == 3) {
519 panel_click_resizeorigin_x += mySize_x;
521 } else { // resizeCorner == 4
524 HUD_Panel_SetPosSize(mySize);
528 highlightedAction = 2;
531 if(nPrimary == K_UPARROW)
533 else if(nPrimary == K_DOWNARROW)
535 else if(nPrimary == K_LEFTARROW)
537 else // if(nPrimary == K_RIGHTARROW)
540 HUD_Panel_SetPos(pos);
543 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
545 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
548 panel_pos_backup = highlightedPanel_initial_pos;
549 panel_size_backup = highlightedPanel_initial_size;
550 highlightedPanel_backup = highlightedPanel;
554 const float S_MOUSE1 = 1;
555 const float S_MOUSE2 = 2;
556 const float S_MOUSE3 = 4;
558 float prevMouseClicked; // previous state
559 float prevMouseClickedTime; // time during previous left mouse click, to check for doubleclicks
560 vector prevMouseClickedPos; // pos during previous left mouse click, to check for doubleclicks
562 void HUD_Panel_EnableMenu();
563 float tab_panels[HUD_PANEL_NUM];
564 float tab_panel, tab_backward;
565 vector tab_panel_pos;
566 void HUD_Panel_FirstInDrawQ(float id);
567 void reset_tab_panels()
570 for(i = 0; i < HUD_PANEL_NUM; ++i)
573 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
577 // we only care for keyboard events
578 if(bInputType != 0 && bInputType != 1)
581 if(!autocvar__hud_configure)
584 // allow console bind to work
587 con_keys = findkeysforcommand("toggleconsole");
588 keys = tokenize(con_keys);
590 float hit_con_bind, i;
591 for (i = 0; i < keys; ++i)
593 if(nPrimary == stof(argv(i)))
597 if(bInputType == 0) {
598 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
599 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
600 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
602 else if(bInputType == 1) {
603 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
604 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
605 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
608 if(nPrimary == K_CTRL)
610 if (bInputType == 1) //ctrl has been released
614 //switch to selected panel
615 highlightedPanel = tab_panel;
616 highlightedAction = 0;
617 HUD_Panel_FirstInDrawQ(highlightedPanel);
624 if(nPrimary == K_MOUSE1)
626 if(bInputType == 0) // key pressed
627 mouseClicked |= S_MOUSE1;
628 else if(bInputType == 1) // key released
629 mouseClicked -= (mouseClicked & S_MOUSE1);
631 else if(nPrimary == K_MOUSE2)
633 if(bInputType == 0) // key pressed
634 mouseClicked |= S_MOUSE2;
635 else if(bInputType == 1) // key released
636 mouseClicked -= (mouseClicked & S_MOUSE2);
638 else if(nPrimary == K_ESCAPE)
643 menu_enabled_time = time;
644 localcmd("menu_showhudexit\n");
646 else if(nPrimary == K_BACKSPACE && hudShiftState & S_CTRL)
651 cvar_set("_hud_configure", "0");
653 else if(nPrimary == K_TAB && hudShiftState & S_CTRL) // select and highlight another panel
655 if (bInputType == 1 || mouseClicked)
658 //FIXME: if a panel is highlighted, has the same pos_x and lays in the same level
659 //of other panels then next consecutive ctrl-tab will select the highlighted panel too
660 //(it should only after every other panel of the hud)
661 //It's a minor bug anyway, we can live with it
663 float starting_panel;
664 float old_tab_panel = tab_panel;
665 if (tab_panel == -1) //first press of TAB
667 if (highlightedPanel != -1)
668 HUD_Panel_UpdatePosSizeForId(highlightedPanel)
671 starting_panel = highlightedPanel; //can be -1, it means no starting panel
672 tab_panel_pos = panel_pos; //to compute level
676 if ( ((!tab_backward) && (hudShiftState & S_SHIFT)) || (tab_backward && !(hudShiftState & S_SHIFT)) ) //tab direction changed?
678 starting_panel = tab_panel;
680 tab_backward = (hudShiftState & S_SHIFT);
682 float k, level, start_pos_x;
683 vector candidate_pos;
684 const float LEVELS_NUM = 4;
685 const float level_height = vid_conheight / LEVELS_NUM;
687 level = floor(tab_panel_pos_y / level_height) * level_height; //starting level
688 candidate_pos_x = (!tab_backward) ? vid_conwidth : 0;
689 start_pos_x = tab_panel_pos_x;
694 for(i = 0; i < HUD_PANEL_NUM; ++i)
696 if (i == tab_panels[i] || i == starting_panel)
698 HUD_Panel_UpdatePosSizeForId(i)
699 if (panel_pos_y >= level && (panel_pos_y - level) < level_height)
700 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)) )
701 || ( 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)) ) )
704 tab_panel_pos = candidate_pos = panel_pos;
709 if (k == LEVELS_NUM) //tab_panel not found
712 if (old_tab_panel == -2) //this prevents an infinite loop (should not happen normally)
717 starting_panel = old_tab_panel;
719 goto find_tab_panel; //u must find tab_panel!
723 level = mod(level + level_height, vid_conheight);
725 candidate_pos_x = vid_conwidth;
729 level = mod(level - level_height, vid_conheight);
730 start_pos_x = vid_conwidth;
735 tab_panels[tab_panel] = tab_panel;
737 else if(nPrimary == K_SPACE && hudShiftState & S_CTRL) // enable/disable highlighted panel or dock
739 if (bInputType == 1 || mouseClicked)
742 if (highlightedPanel != -1)
744 HUD_Panel_GetName(highlightedPanel);
745 cvar_set(strcat("hud_panel_", panel_name), ftos(!(panel_enabled)));
748 cvar_set(strcat("hud_dock"), (autocvar_hud_dock == "") ? "dock" : "");
750 else if(nPrimary == 'c' && hudShiftState & S_CTRL) // copy highlighted panel size
752 if (bInputType == 1 || mouseClicked)
755 if (highlightedPanel != -1)
757 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
758 panel_size_copied = panel_size;
759 highlightedPanel_copied = highlightedPanel;
762 else if(nPrimary == 'v' && hudShiftState & S_CTRL) // past copied size on the highlighted panel
764 if (bInputType == 1 || mouseClicked)
767 if (highlightedPanel_copied == -1 || highlightedPanel == -1)
770 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
772 // reduce size if it'd go beyond screen boundaries
773 vector tmp_size = panel_size_copied;
774 if (panel_pos_x + panel_size_copied_x > vid_conwidth)
775 tmp_size_x = vid_conwidth - panel_pos_x;
776 if (panel_pos_y + panel_size_copied_y > vid_conheight)
777 tmp_size_y = vid_conheight - panel_pos_y;
779 if (panel_size == tmp_size)
783 panel_pos_backup = panel_pos;
784 panel_size_backup = panel_size;
785 highlightedPanel_backup = highlightedPanel;
787 s = strcat(ftos(tmp_size_x/vid_conwidth), " ", ftos(tmp_size_y/vid_conheight));
788 HUD_Panel_GetName(highlightedPanel);
789 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
791 else if(nPrimary == 'z' && hudShiftState & S_CTRL) // undo last action
793 if (bInputType == 1 || mouseClicked)
795 //restore previous values
796 if (highlightedPanel_backup != -1)
798 HUD_Panel_GetName(highlightedPanel_backup);
799 s = strcat(ftos(panel_pos_backup_x/vid_conwidth), " ", ftos(panel_pos_backup_y/vid_conheight));
800 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
801 s = strcat(ftos(panel_size_backup_x/vid_conwidth), " ", ftos(panel_size_backup_y/vid_conheight));
802 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
803 highlightedPanel_backup = -1;
806 else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
810 pressed_key_time = 0;
813 else if (pressed_key_time == 0)
814 pressed_key_time = time;
817 HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
819 else if(nPrimary == K_ENTER || nPrimary == K_SPACE || nPrimary == K_KP_ENTER)
823 if (highlightedPanel != -1)
824 HUD_Panel_EnableMenu();
826 else if(hit_con_bind)
832 float HUD_Panel_Check_Mouse_Pos(float allow_move)
836 while(j < HUD_PANEL_NUM)
841 HUD_Panel_UpdatePosSizeForId(i);
843 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
846 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)
850 // resize from topleft border
851 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)
855 // resize from topright border
856 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)
860 // resize from bottomleft border
861 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)
865 // resize from bottomright border
866 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)
874 // move a panel to the beginning of the panel order array (which means it gets drawn last, on top of everything else)
875 void HUD_Panel_FirstInDrawQ(float id)
878 var float place = -1;
879 // find out where in the array our current id is, save into place
880 for(i = 0; i < HUD_PANEL_NUM; ++i)
882 if(panel_order[i] == id)
888 // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
890 place = HUD_PANEL_NUM - 1;
892 // move all ids up by one step in the array until "place"
893 for(i = place; i > 0; --i)
895 panel_order[i] = panel_order[i-1];
897 // now save the new top id
900 // let's save them into the cvar by some strcat trickery
902 for(i = 0; i < HUD_PANEL_NUM; ++i)
904 s = strcat(s, ftos(panel_order[i]), " ");
906 cvar_set("_hud_panelorder", s);
907 if(hud_panelorder_prev)
908 strunzone(hud_panelorder_prev);
909 hud_panelorder_prev = strzone(autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here
912 void HUD_Panel_Highlight(float allow_move)
916 while(j < HUD_PANEL_NUM)
921 HUD_Panel_UpdatePosSizeForId(i);
923 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
926 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)
928 highlightedPanel = i;
929 HUD_Panel_FirstInDrawQ(i);
930 highlightedAction = 1;
931 panel_click_distance = mousepos - panel_pos;
934 // resize from topleft border
935 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)
937 highlightedPanel = i;
938 HUD_Panel_FirstInDrawQ(i);
939 highlightedAction = 2;
941 panel_click_distance = mousepos - panel_pos;
942 panel_click_resizeorigin = panel_pos + panel_size;
945 // resize from topright border
946 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)
948 highlightedPanel = i;
949 HUD_Panel_FirstInDrawQ(i);
950 highlightedAction = 2;
952 panel_click_distance_x = panel_size_x - mousepos_x + panel_pos_x;
953 panel_click_distance_y = mousepos_y - panel_pos_y;
954 panel_click_resizeorigin = panel_pos + eY * panel_size_y;
957 // resize from bottomleft border
958 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)
960 highlightedPanel = i;
961 HUD_Panel_FirstInDrawQ(i);
962 highlightedAction = 2;
964 panel_click_distance_x = mousepos_x - panel_pos_x;
965 panel_click_distance_y = panel_size_y - mousepos_y + panel_pos_y;
966 panel_click_resizeorigin = panel_pos + eX * panel_size_x;
969 // resize from bottomright border
970 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)
972 highlightedPanel = i;
973 HUD_Panel_FirstInDrawQ(i);
974 highlightedAction = 2;
976 panel_click_distance = panel_size - mousepos + panel_pos;
977 panel_click_resizeorigin = panel_pos;
981 highlightedPanel = -1;
982 highlightedAction = 0;
985 void HUD_Panel_EnableMenu()
988 menu_enabled_time = time;
989 HUD_Panel_GetName(highlightedPanel);
990 localcmd("menu_showhudoptions ", panel_name, "\n");
992 float mouse_over_panel;
993 void HUD_Panel_Mouse()
995 // 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
996 if (autocvar__menu_alpha == 0 && time - menu_enabled_time > 0.5)
1000 print("menu_enabled: ", ftos(menu_enabled), "\n");
1001 print("Highlighted: ", ftos(highlightedPanel), "\n");
1002 print("Menu alpha: ", ftos(autocvar__menu_alpha), "\n");
1005 // instantly hide the editor cursor if we open the HUDExit dialog
1006 // as hud_fade_alpha doesn't decrease to 0 in this case
1007 // TODO: find a way to fade the cursor out even in this case
1008 if(menu_enabled == 1 || (menu_enabled == 2 && !hud_fade_alpha))
1011 mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
1013 mousepos_x = bound(0, mousepos_x, vid_conwidth);
1014 mousepos_y = bound(0, mousepos_y, vid_conheight);
1018 if(prevMouseClicked == 0)
1020 if (tab_panel != -1)
1022 //stop ctrl-tab selection
1026 HUD_Panel_Highlight(mouseClicked & S_MOUSE1); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
1027 // and calls HUD_Panel_UpdatePosSizeForId() for the highlighted panel
1028 if (highlightedPanel != -1)
1030 highlightedPanel_initial_pos = panel_pos;
1031 highlightedPanel_initial_size = panel_size;
1033 // doubleclick check
1034 if ((mouseClicked & S_MOUSE1) && time - prevMouseClickedTime < 0.4 && highlightedPanel != -1 && prevMouseClickedPos == mousepos)
1036 mouseClicked = 0; // to prevent spam, I guess.
1037 HUD_Panel_EnableMenu();
1041 if (mouseClicked & S_MOUSE1)
1043 prevMouseClickedTime = time;
1044 prevMouseClickedPos = mousepos;
1046 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(mouseClicked & S_MOUSE1);
1050 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1052 if (highlightedPanel != -1)
1054 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1055 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
1057 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
1059 panel_pos_backup = highlightedPanel_initial_pos;
1060 panel_size_backup = highlightedPanel_initial_size;
1061 highlightedPanel_backup = highlightedPanel;
1064 // in case the clicked panel is inside another panel and we aren't
1065 // moving it, avoid the immediate "fix" of its position/size
1066 // (often unwanted and hateful) by disabling collisions check
1067 hud_configure_checkcollisions = false;
1070 if(highlightedAction == 1)
1071 HUD_Panel_SetPos(mousepos - panel_click_distance);
1072 else if(highlightedAction == 2)
1075 if(resizeCorner == 1) {
1076 mySize_x = panel_click_resizeorigin_x - (mousepos_x - panel_click_distance_x);
1077 mySize_y = panel_click_resizeorigin_y - (mousepos_y - panel_click_distance_y);
1078 } else if(resizeCorner == 2) {
1079 mySize_x = mousepos_x + panel_click_distance_x - panel_click_resizeorigin_x;
1080 mySize_y = panel_click_distance_y + panel_click_resizeorigin_y - mousepos_y;
1081 } else if(resizeCorner == 3) {
1082 mySize_x = panel_click_resizeorigin_x + panel_click_distance_x - mousepos_x;
1083 mySize_y = mousepos_y + panel_click_distance_y - panel_click_resizeorigin_y;
1084 } else { // resizeCorner == 4
1085 mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x);
1086 mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y);
1088 HUD_Panel_SetPosSize(mySize);
1093 if(menu_enabled == 2)
1094 mouse_over_panel = 0;
1096 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(TRUE);
1097 if (mouse_over_panel && tab_panel == -1)
1098 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1100 // draw cursor after performing move/resize to have the panel pos/size updated before mouse_over_panel
1101 const vector cursorsize = '32 32 0';
1103 if(!mouse_over_panel)
1104 drawpic(mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1105 else if(mouse_over_panel == 1)
1106 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_move.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1107 else if(mouse_over_panel == 2)
1108 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1110 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize2.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1112 prevMouseClicked = mouseClicked;
1115 const float hlBorderSize = 4;
1116 const string hlBorder = "gfx/hud/default/border_highlighted";
1117 const string hlBorder2 = "gfx/hud/default/border_highlighted2";
1118 void HUD_Panel_HlBorder(float myBorder, vector color, float alpha)
1120 drawfill(panel_pos - '1 1 0' * myBorder, panel_size + '2 2 0' * myBorder, '0 0.5 1', .5 * alpha, DRAWFLAG_NORMAL);
1121 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);
1122 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);
1123 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);
1124 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);