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 // we only care for keyboard events
576 if(bInputType != 0 && bInputType != 1)
579 if(!autocvar__hud_configure)
582 // allow console bind to work
585 con_keys = findkeysforcommand("toggleconsole");
586 keys = tokenize(con_keys);
588 float hit_con_bind, i;
589 for (i = 0; i < keys; ++i)
591 if(nPrimary == stof(argv(i)))
595 if(bInputType == 0) {
596 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
597 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
598 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
600 else if(bInputType == 1) {
601 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
602 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
603 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
606 if(nPrimary == K_CTRL)
608 if (bInputType == 1) //ctrl has been released
612 //switch to selected panel
613 highlightedPanel = tab_panel;
614 highlightedAction = 0;
615 HUD_Panel_FirstInDrawQ(highlightedPanel);
622 if(nPrimary == K_MOUSE1)
624 if(bInputType == 0) // key pressed
625 mouseClicked |= S_MOUSE1;
626 else if(bInputType == 1) // key released
627 mouseClicked -= (mouseClicked & S_MOUSE1);
629 else if(nPrimary == K_MOUSE2)
631 if(bInputType == 0) // key pressed
632 mouseClicked |= S_MOUSE2;
633 else if(bInputType == 1) // key released
634 mouseClicked -= (mouseClicked & S_MOUSE2);
636 else if(nPrimary == K_ESCAPE)
641 menu_enabled_time = time;
642 localcmd("menu_showhudexit\n");
644 else if(nPrimary == K_BACKSPACE && hudShiftState & S_CTRL)
649 cvar_set("_hud_configure", "0");
651 else if(nPrimary == K_TAB && hudShiftState & S_CTRL) // select and highlight another panel
653 if (bInputType == 1 || mouseClicked)
656 //FIXME: if a panel is highlighted, has the same pos_x and lays in the same level
657 //of other panels then next consecutive ctrl-tab will select the highlighted panel too
658 //(it should only after every other panel of the hud)
659 //It's a minor bug anyway, we can live with it
661 float starting_panel;
662 float old_tab_panel = tab_panel;
663 if (tab_panel == -1) //first press of TAB
665 if (highlightedPanel != -1)
666 HUD_Panel_UpdatePosSizeForId(highlightedPanel)
669 starting_panel = highlightedPanel; //can be -1, it means no starting panel
670 tab_panel_pos = panel_pos; //to compute level
674 if ( ((!tab_backward) && (hudShiftState & S_SHIFT)) || (tab_backward && !(hudShiftState & S_SHIFT)) ) //tab direction changed?
676 starting_panel = tab_panel;
678 tab_backward = (hudShiftState & S_SHIFT);
680 float k, level, start_pos_x;
681 vector candidate_pos;
682 const float LEVELS_NUM = 4;
683 const float level_height = vid_conheight / LEVELS_NUM;
685 level = floor(tab_panel_pos_y / level_height) * level_height; //starting level
686 candidate_pos_x = (!tab_backward) ? vid_conwidth : 0;
687 start_pos_x = tab_panel_pos_x;
692 for(i = 0; i < HUD_PANEL_NUM; ++i)
694 if (i == tab_panels[i] || i == starting_panel)
696 HUD_Panel_UpdatePosSizeForId(i)
697 if (panel_pos_y >= level && (panel_pos_y - level) < level_height)
698 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)) )
699 || ( 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)) ) )
702 tab_panel_pos = candidate_pos = panel_pos;
707 if (k == LEVELS_NUM) //tab_panel not found
710 if (old_tab_panel == -2) //this prevents an infinite loop (should not happen normally)
715 starting_panel = old_tab_panel;
717 goto find_tab_panel; //u must find tab_panel!
721 level = mod(level + level_height, vid_conheight);
723 candidate_pos_x = vid_conwidth;
727 level = mod(level - level_height, vid_conheight);
728 start_pos_x = vid_conwidth;
733 tab_panels[tab_panel] = tab_panel;
735 else if(nPrimary == K_SPACE && hudShiftState & S_CTRL) // enable/disable highlighted panel or dock
737 if (bInputType == 1 || mouseClicked)
740 if (highlightedPanel != -1)
742 HUD_Panel_GetName(highlightedPanel);
743 cvar_set(strcat("hud_panel_", panel_name), ftos(!(panel_enabled)));
746 cvar_set(strcat("hud_dock"), (autocvar_hud_dock == "") ? "dock" : "");
748 else if(nPrimary == 'c' && hudShiftState & S_CTRL) // copy highlighted panel size
750 if (bInputType == 1 || mouseClicked)
753 if (highlightedPanel != -1)
755 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
756 panel_size_copied = panel_size;
757 highlightedPanel_copied = highlightedPanel;
760 else if(nPrimary == 'v' && hudShiftState & S_CTRL) // past copied size on the highlighted panel
762 if (bInputType == 1 || mouseClicked)
765 if (highlightedPanel_copied == -1 || highlightedPanel == -1)
768 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
770 // reduce size if it'd go beyond screen boundaries
771 vector tmp_size = panel_size_copied;
772 if (panel_pos_x + panel_size_copied_x > vid_conwidth)
773 tmp_size_x = vid_conwidth - panel_pos_x;
774 if (panel_pos_y + panel_size_copied_y > vid_conheight)
775 tmp_size_y = vid_conheight - panel_pos_y;
777 if (panel_size == tmp_size)
781 panel_pos_backup = panel_pos;
782 panel_size_backup = panel_size;
783 highlightedPanel_backup = highlightedPanel;
785 s = strcat(ftos(tmp_size_x/vid_conwidth), " ", ftos(tmp_size_y/vid_conheight));
786 HUD_Panel_GetName(highlightedPanel);
787 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
789 else if(nPrimary == 'z' && hudShiftState & S_CTRL) // undo last action
791 if (bInputType == 1 || mouseClicked)
793 //restore previous values
794 if (highlightedPanel_backup != -1)
796 HUD_Panel_GetName(highlightedPanel_backup);
797 s = strcat(ftos(panel_pos_backup_x/vid_conwidth), " ", ftos(panel_pos_backup_y/vid_conheight));
798 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
799 s = strcat(ftos(panel_size_backup_x/vid_conwidth), " ", ftos(panel_size_backup_y/vid_conheight));
800 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
801 highlightedPanel_backup = -1;
804 else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
808 pressed_key_time = 0;
811 else if (pressed_key_time == 0)
812 pressed_key_time = time;
815 HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
817 else if(nPrimary == K_ENTER || nPrimary == K_SPACE || nPrimary == K_KP_ENTER)
821 if (highlightedPanel != -1)
822 HUD_Panel_EnableMenu();
824 else if(hit_con_bind)
830 float HUD_Panel_Check_Mouse_Pos(float allow_move)
834 while(j < HUD_PANEL_NUM)
839 HUD_Panel_UpdatePosSizeForId(i);
841 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
844 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)
848 // resize from topleft border
849 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)
853 // resize from topright border
854 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)
858 // resize from bottomleft border
859 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)
863 // resize from bottomright border
864 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)
872 // move a panel to the beginning of the panel order array (which means it gets drawn last, on top of everything else)
873 void HUD_Panel_FirstInDrawQ(float id)
876 var float place = -1;
877 // find out where in the array our current id is, save into place
878 for(i = 0; i < HUD_PANEL_NUM; ++i)
880 if(panel_order[i] == id)
886 // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
888 place = HUD_PANEL_NUM - 1;
890 // move all ids up by one step in the array until "place"
891 for(i = place; i > 0; --i)
893 panel_order[i] = panel_order[i-1];
895 // now save the new top id
898 // let's save them into the cvar by some strcat trickery
900 for(i = 0; i < HUD_PANEL_NUM; ++i)
902 s = strcat(s, ftos(panel_order[i]), " ");
904 cvar_set("_hud_panelorder", s);
905 if(hud_panelorder_prev)
906 strunzone(hud_panelorder_prev);
907 hud_panelorder_prev = strzone(autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here
910 void HUD_Panel_Highlight(float allow_move)
914 while(j < HUD_PANEL_NUM)
919 HUD_Panel_UpdatePosSizeForId(i);
921 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
924 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)
926 highlightedPanel = i;
927 HUD_Panel_FirstInDrawQ(i);
928 highlightedAction = 1;
929 panel_click_distance = mousepos - panel_pos;
932 // resize from topleft border
933 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)
935 highlightedPanel = i;
936 HUD_Panel_FirstInDrawQ(i);
937 highlightedAction = 2;
939 panel_click_distance = mousepos - panel_pos;
940 panel_click_resizeorigin = panel_pos + panel_size;
943 // resize from topright border
944 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)
946 highlightedPanel = i;
947 HUD_Panel_FirstInDrawQ(i);
948 highlightedAction = 2;
950 panel_click_distance_x = panel_size_x - mousepos_x + panel_pos_x;
951 panel_click_distance_y = mousepos_y - panel_pos_y;
952 panel_click_resizeorigin = panel_pos + eY * panel_size_y;
955 // resize from bottomleft border
956 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)
958 highlightedPanel = i;
959 HUD_Panel_FirstInDrawQ(i);
960 highlightedAction = 2;
962 panel_click_distance_x = mousepos_x - panel_pos_x;
963 panel_click_distance_y = panel_size_y - mousepos_y + panel_pos_y;
964 panel_click_resizeorigin = panel_pos + eX * panel_size_x;
967 // resize from bottomright border
968 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)
970 highlightedPanel = i;
971 HUD_Panel_FirstInDrawQ(i);
972 highlightedAction = 2;
974 panel_click_distance = panel_size - mousepos + panel_pos;
975 panel_click_resizeorigin = panel_pos;
979 highlightedPanel = -1;
980 highlightedAction = 0;
983 void HUD_Panel_EnableMenu()
986 menu_enabled_time = time;
987 HUD_Panel_GetName(highlightedPanel);
988 localcmd("menu_showhudoptions ", panel_name, "\n");
990 float mouse_over_panel;
991 void HUD_Panel_Mouse()
993 // 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
994 if (autocvar__menu_alpha == 0 && time - menu_enabled_time > 0.5)
998 print("menu_enabled: ", ftos(menu_enabled), "\n");
999 print("Highlighted: ", ftos(highlightedPanel), "\n");
1000 print("Menu alpha: ", ftos(autocvar__menu_alpha), "\n");
1003 // instantly hide the editor cursor if we open the HUDExit dialog
1004 // as hud_fade_alpha doesn't decrease to 0 in this case
1005 // TODO: find a way to fade the cursor out even in this case
1006 if(menu_enabled == 1 || (menu_enabled == 2 && !hud_fade_alpha))
1009 mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
1011 mousepos_x = bound(0, mousepos_x, vid_conwidth);
1012 mousepos_y = bound(0, mousepos_y, vid_conheight);
1016 if(prevMouseClicked == 0)
1018 if (tab_panel != -1)
1020 //stop ctrl-tab selection
1024 HUD_Panel_Highlight(mouseClicked & S_MOUSE1); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
1025 // and calls HUD_Panel_UpdatePosSizeForId() for the highlighted panel
1026 if (highlightedPanel != -1)
1028 highlightedPanel_initial_pos = panel_pos;
1029 highlightedPanel_initial_size = panel_size;
1031 // doubleclick check
1032 if ((mouseClicked & S_MOUSE1) && time - prevMouseClickedTime < 0.4 && highlightedPanel != -1 && prevMouseClickedPos == mousepos)
1034 mouseClicked = 0; // to prevent spam, I guess.
1035 HUD_Panel_EnableMenu();
1039 if (mouseClicked & S_MOUSE1)
1041 prevMouseClickedTime = time;
1042 prevMouseClickedPos = mousepos;
1044 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(mouseClicked & S_MOUSE1);
1048 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1050 if (highlightedPanel != -1)
1052 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1053 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
1055 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
1057 panel_pos_backup = highlightedPanel_initial_pos;
1058 panel_size_backup = highlightedPanel_initial_size;
1059 highlightedPanel_backup = highlightedPanel;
1062 // in case the clicked panel is inside another panel and we aren't
1063 // moving it, avoid the immediate "fix" of its position/size
1064 // (often unwanted and hateful) by disabling collisions check
1065 hud_configure_checkcollisions = false;
1068 if(highlightedAction == 1)
1069 HUD_Panel_SetPos(mousepos - panel_click_distance);
1070 else if(highlightedAction == 2)
1073 if(resizeCorner == 1) {
1074 mySize_x = panel_click_resizeorigin_x - (mousepos_x - panel_click_distance_x);
1075 mySize_y = panel_click_resizeorigin_y - (mousepos_y - panel_click_distance_y);
1076 } else if(resizeCorner == 2) {
1077 mySize_x = mousepos_x + panel_click_distance_x - panel_click_resizeorigin_x;
1078 mySize_y = panel_click_distance_y + panel_click_resizeorigin_y - mousepos_y;
1079 } else if(resizeCorner == 3) {
1080 mySize_x = panel_click_resizeorigin_x + panel_click_distance_x - mousepos_x;
1081 mySize_y = mousepos_y + panel_click_distance_y - panel_click_resizeorigin_y;
1082 } else { // resizeCorner == 4
1083 mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x);
1084 mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y);
1086 HUD_Panel_SetPosSize(mySize);
1091 if(menu_enabled == 2)
1092 mouse_over_panel = 0;
1094 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(TRUE);
1095 if (mouse_over_panel && tab_panel == -1)
1096 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1098 // draw cursor after performing move/resize to have the panel pos/size updated before mouse_over_panel
1099 const vector cursorsize = '32 32 0';
1101 if(!mouse_over_panel)
1102 drawpic(mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1103 else if(mouse_over_panel == 1)
1104 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_move.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1105 else if(mouse_over_panel == 2)
1106 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1108 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize2.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1110 prevMouseClicked = mouseClicked;
1113 const float hlBorderSize = 4;
1114 const string hlBorder = "gfx/hud/default/border_highlighted";
1115 const string hlBorder2 = "gfx/hud/default/border_highlighted2";
1116 void HUD_Panel_HlBorder(float myBorder, vector color, float alpha)
1118 drawfill(panel_pos - '1 1 0' * myBorder, panel_size + '2 2 0' * myBorder, '0 0.5 1', .5 * alpha, DRAWFLAG_NORMAL);
1119 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);
1120 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);
1121 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);
1122 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);