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");
133 HUD_Write("menu_sync\n"); // force the menu to reread the cvars, so that the dialogs are updated
135 print(sprintf(_("^2Successfully exported to %s! (Note: It's saved in data/data/)\n"), filename));
139 print(sprintf(_("^1Couldn't write to %s\n"), filename));
142 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
143 vector HUD_Panel_CheckMove(vector myPos, vector mySize)
146 float myCenter_x, myCenter_y, targCenter_x, targCenter_y;
150 for (i = 0; i < HUD_PANEL_NUM; ++i) {
151 if(i == highlightedPanel || !panel_enabled)
154 HUD_Panel_UpdatePosSizeForId(i);
156 panel_pos -= '1 1 0' * panel_bg_border;
157 panel_size += '2 2 0' * panel_bg_border;
159 if(myPos_y + mySize_y < panel_pos_y)
161 if(myPos_y > panel_pos_y + panel_size_y)
164 if(myPos_x + mySize_x < panel_pos_x)
166 if(myPos_x > panel_pos_x + panel_size_x)
169 // OK, there IS a collision.
171 myCenter_x = myPos_x + 0.5 * mySize_x;
172 myCenter_y = myPos_y + 0.5 * mySize_y;
174 targCenter_x = panel_pos_x + 0.5 * panel_size_x;
175 targCenter_y = panel_pos_y + 0.5 * panel_size_y;
177 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
179 if(myPos_x + mySize_x - panel_pos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
180 myTarget_x = panel_pos_x - mySize_x;
181 else // push it upwards
182 myTarget_y = panel_pos_y - mySize_y;
184 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
186 if(panel_pos_x + panel_size_x - myPos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
187 myTarget_x = panel_pos_x + panel_size_x;
188 else // push it upwards
189 myTarget_y = panel_pos_y - mySize_y;
191 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
193 if(myPos_x + mySize_x - panel_pos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
194 myTarget_x = panel_pos_x - mySize_x;
195 else // push it downwards
196 myTarget_y = panel_pos_y + panel_size_y;
198 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
200 if(panel_pos_x + panel_size_x - myPos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
201 myTarget_x = panel_pos_x + panel_size_x;
202 else // push it downwards
203 myTarget_y = panel_pos_y + panel_size_y;
205 //if(cvar("hud_configure_checkcollisions_debug"))
206 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
212 void HUD_Panel_SetPos(vector pos)
214 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
218 //if(cvar("hud_configure_checkcollisions_debug"))
219 //drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
221 if(autocvar_hud_configure_grid)
223 pos_x = floor((pos_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
224 pos_y = floor((pos_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
227 if(hud_configure_checkcollisions)
228 pos = HUD_Panel_CheckMove(pos, mySize);
230 pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
231 pos_y = bound(0, pos_y, vid_conheight - mySize_y);
234 s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
236 HUD_Panel_GetName(highlightedPanel);
237 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
240 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
241 vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
246 float dist_x, dist_y;
248 ratio = mySize_x/mySize_y;
250 for (i = 0; i < HUD_PANEL_NUM; ++i) {
251 if(i == highlightedPanel || !panel_enabled)
254 HUD_Panel_UpdatePosSizeForId(i);
256 panel_pos -= '1 1 0' * panel_bg_border;
257 panel_size += '2 2 0' * panel_bg_border;
259 targEndPos = panel_pos + panel_size;
261 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
262 if(resizeorigin_x > panel_pos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > panel_pos_y && resizeorigin_y < targEndPos_y)
265 if (resizeCorner == 1)
267 // check if this panel is on our way
268 if (resizeorigin_x <= panel_pos_x)
270 if (resizeorigin_y <= panel_pos_y)
272 if (targEndPos_x <= resizeorigin_x - mySize_x)
274 if (targEndPos_y <= resizeorigin_y - mySize_y)
277 // there is a collision:
278 // detect which side of the panel we are facing is actually limiting the resizing
279 // (which side the resize direction finds for first) and reduce the size up to there
281 // dist is the distance between resizeorigin and the "analogous" point of the panel
282 // in this case between resizeorigin (bottom-right point) and the bottom-right point of the panel
283 dist_x = resizeorigin_x - targEndPos_x;
284 dist_y = resizeorigin_y - targEndPos_y;
285 if (dist_y <= 0 || dist_x / dist_y > ratio)
286 mySize_x = min(mySize_x, dist_x);
288 mySize_y = min(mySize_y, dist_y);
290 else if (resizeCorner == 2)
292 if (resizeorigin_x >= targEndPos_x)
294 if (resizeorigin_y <= panel_pos_y)
296 if (panel_pos_x >= resizeorigin_x + mySize_x)
298 if (targEndPos_y <= resizeorigin_y - mySize_y)
301 dist_x = panel_pos_x - resizeorigin_x;
302 dist_y = resizeorigin_y - targEndPos_y;
303 if (dist_y <= 0 || dist_x / dist_y > ratio)
304 mySize_x = min(mySize_x, dist_x);
306 mySize_y = min(mySize_y, dist_y);
308 else if (resizeCorner == 3)
310 if (resizeorigin_x <= panel_pos_x)
312 if (resizeorigin_y >= targEndPos_y)
314 if (targEndPos_x <= resizeorigin_x - mySize_x)
316 if (panel_pos_y >= resizeorigin_y + mySize_y)
319 dist_x = resizeorigin_x - targEndPos_x;
320 dist_y = panel_pos_y - resizeorigin_y;
321 if (dist_y <= 0 || dist_x / dist_y > ratio)
322 mySize_x = min(mySize_x, dist_x);
324 mySize_y = min(mySize_y, dist_y);
326 else if (resizeCorner == 4)
328 if (resizeorigin_x >= targEndPos_x)
330 if (resizeorigin_y >= targEndPos_y)
332 if (panel_pos_x >= resizeorigin_x + mySize_x)
334 if (panel_pos_y >= resizeorigin_y + mySize_y)
337 dist_x = panel_pos_x - resizeorigin_x;
338 dist_y = panel_pos_y - resizeorigin_y;
339 if (dist_y <= 0 || dist_x / dist_y > ratio)
340 mySize_x = min(mySize_x, dist_x);
342 mySize_y = min(mySize_y, dist_y);
344 //if(cvar("hud_configure_checkcollisions_debug"))
345 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
351 void HUD_Panel_SetPosSize(vector mySize)
353 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
355 resizeorigin = panel_click_resizeorigin;
358 // minimum panel size cap
359 mySize_x = max(0.025 * vid_conwidth, mySize_x);
360 mySize_y = max(0.025 * vid_conheight, mySize_y);
362 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.
364 mySize_x = max(17 * autocvar_con_chatsize, mySize_x);
365 mySize_y = max(2 * autocvar_con_chatsize + 2 * panel_bg_padding, mySize_y);
368 // collision testing|
369 // -----------------+
371 // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
372 if(resizeCorner == 1) {
373 myPos_x = resizeorigin_x - mySize_x;
374 myPos_y = resizeorigin_y - mySize_y;
375 } else if(resizeCorner == 2) {
376 myPos_x = resizeorigin_x;
377 myPos_y = resizeorigin_y - mySize_y;
378 } else if(resizeCorner == 3) {
379 myPos_x = resizeorigin_x - mySize_x;
380 myPos_y = resizeorigin_y;
381 } else { // resizeCorner == 4
382 myPos_x = resizeorigin_x;
383 myPos_y = resizeorigin_y;
386 // left/top screen edges
388 mySize_x = mySize_x + myPos_x;
390 mySize_y = mySize_y + myPos_y;
392 // bottom/right screen edges
393 if(myPos_x + mySize_x > vid_conwidth)
394 mySize_x = vid_conwidth - myPos_x;
395 if(myPos_y + mySize_y > vid_conheight)
396 mySize_y = vid_conheight - myPos_y;
398 //if(cvar("hud_configure_checkcollisions_debug"))
399 //drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
401 // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
402 if(autocvar_hud_configure_grid)
404 mySize_x = floor((mySize_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
405 mySize_y = floor((mySize_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
408 if(hud_configure_checkcollisions)
409 mySize = HUD_Panel_CheckResize(mySize, resizeorigin);
411 // 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)
412 mySize_x = max(0.025 * vid_conwidth, mySize_x);
413 mySize_y = max(0.025 * vid_conheight, mySize_y);
415 // do another pos check, as size might have changed by now
416 if(resizeCorner == 1) {
417 myPos_x = resizeorigin_x - mySize_x;
418 myPos_y = resizeorigin_y - mySize_y;
419 } else if(resizeCorner == 2) {
420 myPos_x = resizeorigin_x;
421 myPos_y = resizeorigin_y - mySize_y;
422 } else if(resizeCorner == 3) {
423 myPos_x = resizeorigin_x - mySize_x;
424 myPos_y = resizeorigin_y;
425 } else { // resizeCorner == 4
426 myPos_x = resizeorigin_x;
427 myPos_y = resizeorigin_y;
430 //if(cvar("hud_configure_checkcollisions_debug"))
431 //drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
433 HUD_Panel_GetName(highlightedPanel);
435 s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
436 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
438 s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
439 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
442 float pressed_key_time;
443 vector highlightedPanel_initial_pos, highlightedPanel_initial_size;
444 void HUD_Panel_Arrow_Action(float nPrimary)
446 if (highlightedPanel == -1)
449 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
452 if(autocvar_hud_configure_grid)
454 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
456 if (hudShiftState & S_SHIFT)
457 step = hud_configure_realGridSize_y;
459 step = 2 * hud_configure_realGridSize_y;
463 if (hudShiftState & S_SHIFT)
464 step = hud_configure_realGridSize_x;
466 step = 2 * hud_configure_realGridSize_x;
471 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
472 step = vid_conheight;
475 if (hudShiftState & S_SHIFT)
476 step = (step / 256); // more precision
478 step = (step / 64) * (1 + 2 * (time - pressed_key_time));
481 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
483 highlightedPanel_initial_pos = panel_pos;
484 highlightedPanel_initial_size = panel_size;
486 if (hudShiftState & S_ALT) // resize
488 highlightedAction = 1;
489 if(nPrimary == K_UPARROW)
491 else if(nPrimary == K_RIGHTARROW)
493 else if(nPrimary == K_LEFTARROW)
495 else // if(nPrimary == K_DOWNARROW)
498 // ctrl+arrow reduces the size, instead of increasing it
499 // Note that ctrl disables collisions check too, but it's fine
500 // since we don't collide with anything reducing the size
501 if (hudShiftState & S_CTRL) {
503 resizeCorner = 5 - resizeCorner;
508 panel_click_resizeorigin = panel_pos;
509 if(resizeCorner == 1) {
510 panel_click_resizeorigin += mySize;
512 } else if(resizeCorner == 2) {
513 panel_click_resizeorigin_y += mySize_y;
515 } else if(resizeCorner == 3) {
516 panel_click_resizeorigin_x += mySize_x;
518 } else { // resizeCorner == 4
521 HUD_Panel_SetPosSize(mySize);
525 highlightedAction = 2;
528 if(nPrimary == K_UPARROW)
530 else if(nPrimary == K_DOWNARROW)
532 else if(nPrimary == K_LEFTARROW)
534 else // if(nPrimary == K_RIGHTARROW)
537 HUD_Panel_SetPos(pos);
540 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
542 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
545 panel_pos_backup = highlightedPanel_initial_pos;
546 panel_size_backup = highlightedPanel_initial_size;
547 highlightedPanel_backup = highlightedPanel;
551 const float S_MOUSE1 = 1;
552 const float S_MOUSE2 = 2;
553 const float S_MOUSE3 = 4;
555 float prevMouseClicked; // previous state
556 float prevMouseClickedTime; // time during previous left mouse click, to check for doubleclicks
557 vector prevMouseClickedPos; // pos during previous left mouse click, to check for doubleclicks
559 void HUD_Panel_EnableMenu();
560 float tab_panels[HUD_PANEL_NUM];
561 float tab_panel, tab_backward;
562 vector tab_panel_pos;
563 void HUD_Panel_FirstInDrawQ(float id);
564 void reset_tab_panels()
567 for(i = 0; i < HUD_PANEL_NUM; ++i)
570 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
574 if(!autocvar__hud_configure)
577 // allow console bind to work
580 con_keys = findkeysforcommand("toggleconsole");
581 keys = tokenize(con_keys);
583 float hit_con_bind, i;
584 for (i = 0; i < keys; ++i)
586 if(nPrimary == stof(argv(i)))
590 if(bInputType == 0) {
591 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
592 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
593 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
595 else if(bInputType == 1) {
596 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
597 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
598 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
601 if(nPrimary == K_CTRL)
603 if (bInputType == 1) //ctrl has been released
607 //switch to selected panel
608 highlightedPanel = tab_panel;
609 highlightedAction = 0;
610 HUD_Panel_FirstInDrawQ(highlightedPanel);
617 if(nPrimary == K_MOUSE1)
619 if(bInputType == 0) // key pressed
620 mouseClicked |= S_MOUSE1;
621 else if(bInputType == 1) // key released
622 mouseClicked -= (mouseClicked & S_MOUSE1);
624 else if(nPrimary == K_MOUSE2)
626 if(bInputType == 0) // key pressed
627 mouseClicked |= S_MOUSE2;
628 else if(bInputType == 1) // key released
629 mouseClicked -= (mouseClicked & S_MOUSE2);
631 else if(nPrimary == K_ESCAPE)
636 menu_enabled_time = time;
637 localcmd("menu_showhudexit\n");
639 else if(nPrimary == K_BACKSPACE && hudShiftState & S_CTRL)
644 cvar_set("_hud_configure", "0");
646 else if(nPrimary == K_TAB && hudShiftState & S_CTRL) // select and highlight another panel
648 if (bInputType == 1 || mouseClicked)
651 //FIXME: if a panel is highlighted, has the same pos_x and lays in the same level
652 //of other panels then next consecutive ctrl-tab will select the highlighted panel too
653 //(it should only after every other panel of the hud)
654 //It's a minor bug anyway, we can live with it
656 float starting_panel;
657 float old_tab_panel = tab_panel;
658 if (tab_panel == -1) //first press of TAB
660 if (highlightedPanel != -1)
661 HUD_Panel_UpdatePosSizeForId(highlightedPanel)
664 starting_panel = highlightedPanel; //can be -1, it means no starting panel
665 tab_panel_pos = panel_pos; //to compute level
669 if ( ((!tab_backward) && (hudShiftState & S_SHIFT)) || (tab_backward && !(hudShiftState & S_SHIFT)) ) //tab direction changed?
671 starting_panel = tab_panel;
673 tab_backward = (hudShiftState & S_SHIFT);
675 float k, level, start_pos_x;
676 vector candidate_pos;
677 const float LEVELS_NUM = 4;
678 const float level_height = vid_conheight / LEVELS_NUM;
680 level = floor(tab_panel_pos_y / level_height) * level_height; //starting level
681 candidate_pos_x = (!tab_backward) ? vid_conwidth : 0;
682 start_pos_x = tab_panel_pos_x;
687 for(i = 0; i < HUD_PANEL_NUM; ++i)
689 if (i == tab_panels[i] || i == starting_panel)
691 HUD_Panel_UpdatePosSizeForId(i)
692 if (panel_pos_y >= level && (panel_pos_y - level) < level_height)
693 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)) )
694 || ( 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)) ) )
697 tab_panel_pos = candidate_pos = panel_pos;
702 if (k == LEVELS_NUM) //tab_panel not found
705 if (old_tab_panel == -2) //this prevents an infinite loop (should not happen normally)
710 starting_panel = old_tab_panel;
712 goto find_tab_panel; //u must find tab_panel!
716 level = mod(level + level_height, vid_conheight);
718 candidate_pos_x = vid_conwidth;
722 level = mod(level - level_height, vid_conheight);
723 start_pos_x = vid_conwidth;
728 tab_panels[tab_panel] = tab_panel;
730 else if(nPrimary == K_SPACE && hudShiftState & S_CTRL) // enable/disable highlighted panel or dock
732 if (bInputType == 1 || mouseClicked)
735 if (highlightedPanel != -1)
737 HUD_Panel_GetName(highlightedPanel);
738 cvar_set(strcat("hud_panel_", panel_name), ftos(!(panel_enabled)));
741 cvar_set(strcat("hud_dock"), (autocvar_hud_dock == "") ? "dock" : "");
743 else if(nPrimary == 'c' && hudShiftState & S_CTRL) // copy highlighted panel size
745 if (bInputType == 1 || mouseClicked)
748 if (highlightedPanel != -1)
750 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
751 panel_size_copied = panel_size;
752 highlightedPanel_copied = highlightedPanel;
755 else if(nPrimary == 'v' && hudShiftState & S_CTRL) // past copied size on the highlighted panel
757 if (bInputType == 1 || mouseClicked)
760 if (highlightedPanel_copied == -1 || highlightedPanel == -1)
763 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
765 // reduce size if it'd go beyond screen boundaries
766 vector tmp_size = panel_size_copied;
767 if (panel_pos_x + panel_size_copied_x > vid_conwidth)
768 tmp_size_x = vid_conwidth - panel_pos_x;
769 if (panel_pos_y + panel_size_copied_y > vid_conheight)
770 tmp_size_y = vid_conheight - panel_pos_y;
772 if (panel_size == tmp_size)
776 panel_pos_backup = panel_pos;
777 panel_size_backup = panel_size;
778 highlightedPanel_backup = highlightedPanel;
780 s = strcat(ftos(tmp_size_x/vid_conwidth), " ", ftos(tmp_size_y/vid_conheight));
781 HUD_Panel_GetName(highlightedPanel);
782 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
784 else if(nPrimary == 'z' && hudShiftState & S_CTRL) // undo last action
786 if (bInputType == 1 || mouseClicked)
788 //restore previous values
789 if (highlightedPanel_backup != -1)
791 HUD_Panel_GetName(highlightedPanel_backup);
792 s = strcat(ftos(panel_pos_backup_x/vid_conwidth), " ", ftos(panel_pos_backup_y/vid_conheight));
793 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
794 s = strcat(ftos(panel_size_backup_x/vid_conwidth), " ", ftos(panel_size_backup_y/vid_conheight));
795 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
796 highlightedPanel_backup = -1;
799 else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
803 pressed_key_time = 0;
806 else if (pressed_key_time == 0)
807 pressed_key_time = time;
810 HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
812 else if(nPrimary == K_ENTER || nPrimary == K_SPACE || nPrimary == K_KP_ENTER)
816 if (highlightedPanel != -1)
817 HUD_Panel_EnableMenu();
819 else if(hit_con_bind)
825 float HUD_Panel_Check_Mouse_Pos(float allow_move)
829 while(j < HUD_PANEL_NUM)
834 HUD_Panel_UpdatePosSizeForId(i);
836 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
839 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)
843 // resize from topleft border
844 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)
848 // resize from topright border
849 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)
853 // resize from bottomleft border
854 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)
858 // resize from bottomright border
859 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)
867 // move a panel to the beginning of the panel order array (which means it gets drawn last, on top of everything else)
868 void HUD_Panel_FirstInDrawQ(float id)
871 var float place = -1;
872 // find out where in the array our current id is, save into place
873 for(i = 0; i < HUD_PANEL_NUM; ++i)
875 if(panel_order[i] == id)
881 // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
883 place = HUD_PANEL_NUM - 1;
885 // move all ids up by one step in the array until "place"
886 for(i = place; i > 0; --i)
888 panel_order[i] = panel_order[i-1];
890 // now save the new top id
893 // let's save them into the cvar by some strcat trickery
895 for(i = 0; i < HUD_PANEL_NUM; ++i)
897 s = strcat(s, ftos(panel_order[i]), " ");
899 cvar_set("_hud_panelorder", s);
900 if(hud_panelorder_prev)
901 strunzone(hud_panelorder_prev);
902 hud_panelorder_prev = strzone(autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here
905 void HUD_Panel_Highlight(float allow_move)
909 while(j < HUD_PANEL_NUM)
914 HUD_Panel_UpdatePosSizeForId(i);
916 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
919 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)
921 highlightedPanel = i;
922 HUD_Panel_FirstInDrawQ(i);
923 highlightedAction = 1;
924 panel_click_distance = mousepos - panel_pos;
927 // resize from topleft border
928 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)
930 highlightedPanel = i;
931 HUD_Panel_FirstInDrawQ(i);
932 highlightedAction = 2;
934 panel_click_distance = mousepos - panel_pos;
935 panel_click_resizeorigin = panel_pos + panel_size;
938 // resize from topright border
939 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)
941 highlightedPanel = i;
942 HUD_Panel_FirstInDrawQ(i);
943 highlightedAction = 2;
945 panel_click_distance_x = panel_size_x - mousepos_x + panel_pos_x;
946 panel_click_distance_y = mousepos_y - panel_pos_y;
947 panel_click_resizeorigin = panel_pos + eY * panel_size_y;
950 // resize from bottomleft border
951 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)
953 highlightedPanel = i;
954 HUD_Panel_FirstInDrawQ(i);
955 highlightedAction = 2;
957 panel_click_distance_x = mousepos_x - panel_pos_x;
958 panel_click_distance_y = panel_size_y - mousepos_y + panel_pos_y;
959 panel_click_resizeorigin = panel_pos + eX * panel_size_x;
962 // resize from bottomright border
963 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)
965 highlightedPanel = i;
966 HUD_Panel_FirstInDrawQ(i);
967 highlightedAction = 2;
969 panel_click_distance = panel_size - mousepos + panel_pos;
970 panel_click_resizeorigin = panel_pos;
974 highlightedPanel = -1;
975 highlightedAction = 0;
978 void HUD_Panel_EnableMenu()
981 menu_enabled_time = time;
982 HUD_Panel_GetName(highlightedPanel);
983 localcmd("menu_showhudoptions ", panel_name, "\n");
985 float mouse_over_panel;
986 void HUD_Panel_Mouse()
988 // 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
989 if (autocvar__menu_alpha == 0 && time - menu_enabled_time > 0.5)
993 print("menu_enabled: ", ftos(menu_enabled), "\n");
994 print("Highlighted: ", ftos(highlightedPanel), "\n");
995 print("Menu alpha: ", ftos(autocvar__menu_alpha), "\n");
998 // instantly hide the editor cursor if we open the HUDExit dialog
999 // as hud_fade_alpha doesn't decrease to 0 in this case
1000 // TODO: find a way to fade the cursor out even in this case
1001 if(menu_enabled == 1 || (menu_enabled == 2 && !hud_fade_alpha))
1004 mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
1006 mousepos_x = bound(0, mousepos_x, vid_conwidth);
1007 mousepos_y = bound(0, mousepos_y, vid_conheight);
1011 if(prevMouseClicked == 0)
1013 if (tab_panel != -1)
1015 //stop ctrl-tab selection
1019 HUD_Panel_Highlight(mouseClicked & S_MOUSE1); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
1020 // and calls HUD_Panel_UpdatePosSizeForId() for the highlighted panel
1021 if (highlightedPanel != -1)
1023 highlightedPanel_initial_pos = panel_pos;
1024 highlightedPanel_initial_size = panel_size;
1026 // doubleclick check
1027 if ((mouseClicked & S_MOUSE1) && time - prevMouseClickedTime < 0.4 && highlightedPanel != -1 && prevMouseClickedPos == mousepos)
1029 mouseClicked = 0; // to prevent spam, I guess.
1030 HUD_Panel_EnableMenu();
1034 if (mouseClicked & S_MOUSE1)
1036 prevMouseClickedTime = time;
1037 prevMouseClickedPos = mousepos;
1039 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(mouseClicked & S_MOUSE1);
1043 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1045 if (highlightedPanel != -1)
1047 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1048 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
1050 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
1052 panel_pos_backup = highlightedPanel_initial_pos;
1053 panel_size_backup = highlightedPanel_initial_size;
1054 highlightedPanel_backup = highlightedPanel;
1057 // in case the clicked panel is inside another panel and we aren't
1058 // moving it, avoid the immediate "fix" of its position/size
1059 // (often unwanted and hateful) by disabling collisions check
1060 hud_configure_checkcollisions = false;
1063 if(highlightedAction == 1)
1064 HUD_Panel_SetPos(mousepos - panel_click_distance);
1065 else if(highlightedAction == 2)
1068 if(resizeCorner == 1) {
1069 mySize_x = panel_click_resizeorigin_x - (mousepos_x - panel_click_distance_x);
1070 mySize_y = panel_click_resizeorigin_y - (mousepos_y - panel_click_distance_y);
1071 } else if(resizeCorner == 2) {
1072 mySize_x = mousepos_x + panel_click_distance_x - panel_click_resizeorigin_x;
1073 mySize_y = panel_click_distance_y + panel_click_resizeorigin_y - mousepos_y;
1074 } else if(resizeCorner == 3) {
1075 mySize_x = panel_click_resizeorigin_x + panel_click_distance_x - mousepos_x;
1076 mySize_y = mousepos_y + panel_click_distance_y - panel_click_resizeorigin_y;
1077 } else { // resizeCorner == 4
1078 mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x);
1079 mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y);
1081 HUD_Panel_SetPosSize(mySize);
1086 if(menu_enabled == 2)
1087 mouse_over_panel = 0;
1089 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(TRUE);
1090 if (mouse_over_panel && tab_panel == -1)
1091 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1093 // draw cursor after performing move/resize to have the panel pos/size updated before mouse_over_panel
1094 const vector cursorsize = '32 32 0';
1096 if(!mouse_over_panel)
1097 drawpic(mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1098 else if(mouse_over_panel == 1)
1099 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_move.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1100 else if(mouse_over_panel == 2)
1101 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1103 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize2.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1105 prevMouseClicked = mouseClicked;
1108 const float hlBorderSize = 4;
1109 const string hlBorder = "gfx/hud/default/border_highlighted";
1110 const string hlBorder2 = "gfx/hud/default/border_highlighted2";
1111 void HUD_Panel_HlBorder(float myBorder, vector color, float alpha)
1113 drawfill(panel_pos - '1 1 0' * myBorder, panel_size + '2 2 0' * myBorder, '0 0.5 1', .5 * alpha, DRAWFLAG_NORMAL);
1114 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);
1115 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);
1116 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);
1117 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);