1 #include "hud_config.qh"
3 #include <client/draw.qh>
4 #include <client/hud/hud.qh>
5 #include <client/hud/panel/chat.qh>
6 #include <client/hud/panel/scoreboard.qh>
7 #include <client/view.qh>
10 void HUD_Panel_ExportCfg(string cfgname)
13 string filename = strcat("hud_", autocvar_hud_skin, "_", cfgname, ".cfg");
15 fh = fopen(filename, FILE_WRITE);
18 HUD_Write("//title \n");
19 HUD_Write("//author \n");
21 HUD_Write_Cvar("hud_skin");
22 HUD_Write_Cvar("hud_panel_bg");
23 HUD_Write_Cvar("hud_panel_bg_color");
24 HUD_Write_Cvar("hud_panel_bg_color_team");
25 HUD_Write_Cvar("hud_panel_bg_alpha");
26 HUD_Write_Cvar("hud_panel_bg_border");
27 HUD_Write_Cvar("hud_panel_bg_padding");
28 HUD_Write_Cvar("hud_panel_fg_alpha");
31 HUD_Write_Cvar("hud_dock");
32 HUD_Write_Cvar("hud_dock_color");
33 HUD_Write_Cvar("hud_dock_color_team");
34 HUD_Write_Cvar("hud_dock_alpha");
37 HUD_Write_Cvar("hud_progressbar_alpha");
38 HUD_Write_Cvar("hud_progressbar_strength_color");
39 HUD_Write_Cvar("hud_progressbar_superweapons_color");
40 HUD_Write_Cvar("hud_progressbar_shield_color");
41 HUD_Write_Cvar("hud_progressbar_health_color");
42 HUD_Write_Cvar("hud_progressbar_armor_color");
43 HUD_Write_Cvar("hud_progressbar_fuel_color");
44 HUD_Write_Cvar("hud_progressbar_oxygen_color");
45 HUD_Write_Cvar("hud_progressbar_nexball_color");
46 HUD_Write_Cvar("hud_progressbar_speed_color");
47 HUD_Write_Cvar("hud_progressbar_acceleration_color");
48 HUD_Write_Cvar("hud_progressbar_acceleration_neg_color");
49 HUD_Write_Cvar("hud_progressbar_vehicles_ammo1_color");
50 HUD_Write_Cvar("hud_progressbar_vehicles_ammo2_color");
53 HUD_Write_Cvar("_hud_panelorder");
56 HUD_Write_Cvar("hud_configure_grid");
57 HUD_Write_Cvar("hud_configure_grid_xsize");
58 HUD_Write_Cvar("hud_configure_grid_ysize");
61 // common cvars for all panels
62 for (int i = 0; i < REGISTRY_COUNT(hud_panels); ++i)
64 panel = REGISTRY_GET(hud_panels, i);
66 HUD_Write_PanelCvar("_pos");
67 HUD_Write_PanelCvar("_size");
68 HUD_Write_PanelCvar("_bg");
69 HUD_Write_PanelCvar("_bg_color");
70 HUD_Write_PanelCvar("_bg_color_team");
71 HUD_Write_PanelCvar("_bg_alpha");
72 HUD_Write_PanelCvar("_bg_border");
73 HUD_Write_PanelCvar("_bg_padding");
74 panel.panel_export(fh);
78 HUD_Write("menu_sync\n"); // force the menu to reread the cvars, so that the dialogs are updated
80 LOG_INFOF(_("^2Successfully exported to %s! (Note: It's saved in data/data/)"), filename);
84 LOG_INFOF(_("^1Couldn't write to %s"), filename);
87 void HUD_Configure_Exit_Force()
89 if (hud_configure_menu_open)
91 hud_configure_menu_open = 0;
92 localcmd("togglemenu\n");
94 cursor_type = CURSOR_NORMAL;
95 cvar_set("_hud_configure", "0");
98 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
99 vector HUD_Panel_CheckMove(vector myPos, vector mySize)
101 vector myCenter, targCenter;
102 vector myTarget = myPos;
104 for (i = 0; i < REGISTRY_COUNT(hud_panels); ++i) {
105 panel = REGISTRY_GET(hud_panels, i);
106 if(!(panel.panel_configflags & PANEL_CONFIG_MAIN)) continue;
107 if(panel == highlightedPanel) continue;
108 HUD_Panel_UpdatePosSize();
109 if(!panel_enabled) continue;
111 panel_pos -= '1 1 0' * panel_bg_border;
112 panel_size += '2 2 0' * panel_bg_border;
114 if(myPos.y + mySize.y < panel_pos.y)
116 if(myPos.y > panel_pos.y + panel_size.y)
119 if(myPos.x + mySize.x < panel_pos.x)
121 if(myPos.x > panel_pos.x + panel_size.x)
124 // OK, there IS a collision.
126 myCenter.x = myPos.x + 0.5 * mySize.x;
127 myCenter.y = myPos.y + 0.5 * mySize.y;
129 targCenter.x = panel_pos.x + 0.5 * panel_size.x;
130 targCenter.y = panel_pos.y + 0.5 * panel_size.y;
132 if(myCenter.x < targCenter.x && myCenter.y < targCenter.y) // top left (of the target panel)
134 if(myPos.x + mySize.x - panel_pos.x < myPos.y + mySize.y - panel_pos.y) // push it to the side
135 myTarget.x = panel_pos.x - mySize.x;
136 else // push it upwards
137 myTarget.y = panel_pos.y - mySize.y;
139 else if(myCenter.x > targCenter.x && myCenter.y < targCenter.y) // top right
141 if(panel_pos.x + panel_size.x - myPos.x < myPos.y + mySize.y - panel_pos.y) // push it to the side
142 myTarget.x = panel_pos.x + panel_size.x;
143 else // push it upwards
144 myTarget.y = panel_pos.y - mySize.y;
146 else if(myCenter.x < targCenter.x && myCenter.y > targCenter.y) // bottom left
148 if(myPos.x + mySize.x - panel_pos.x < panel_pos.y + panel_size.y - myPos.y) // push it to the side
149 myTarget.x = panel_pos.x - mySize.x;
150 else // push it downwards
151 myTarget.y = panel_pos.y + panel_size.y;
153 else if(myCenter.x > targCenter.x && myCenter.y > targCenter.y) // bottom right
155 if(panel_pos.x + panel_size.x - myPos.x < panel_pos.y + panel_size.y - myPos.y) // push it to the side
156 myTarget.x = panel_pos.x + panel_size.x;
157 else // push it downwards
158 myTarget.y = panel_pos.y + panel_size.y;
160 //if(cvar("hud_configure_checkcollisions_debug"))
161 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
167 void HUD_Panel_SetPos(vector pos)
169 panel = highlightedPanel;
170 HUD_Panel_UpdatePosSize();
174 //if(cvar("hud_configure_checkcollisions_debug"))
175 //drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
177 if(autocvar_hud_configure_grid)
179 pos.x = floor((pos.x/vid_conwidth)/hud_configure_gridSize.x + 0.5) * hud_configure_realGridSize.x;
180 pos.y = floor((pos.y/vid_conheight)/hud_configure_gridSize.y + 0.5) * hud_configure_realGridSize.y;
183 if(hud_configure_checkcollisions)
184 pos = HUD_Panel_CheckMove(pos, mySize);
186 pos.x = bound(0, pos.x, vid_conwidth - mySize.x);
187 pos.y = bound(0, pos.y, vid_conheight - mySize.y);
190 s = strcat(ftos(pos.x/vid_conwidth), " ", ftos(pos.y/vid_conheight));
192 cvar_set(strcat("hud_panel_", highlightedPanel.panel_name, "_pos"), s);
195 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
196 vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
199 float ratio = mySize.x/mySize.y;
201 for (i = 0; i < REGISTRY_COUNT(hud_panels); ++i) {
202 panel = REGISTRY_GET(hud_panels, i);
203 if(!(panel.panel_configflags & PANEL_CONFIG_MAIN)) continue;
204 if(panel == highlightedPanel) continue;
205 HUD_Panel_UpdatePosSize();
206 if(!panel_enabled) continue;
208 panel_pos -= '1 1 0' * panel_bg_border;
209 panel_size += '2 2 0' * panel_bg_border;
211 targEndPos = panel_pos + panel_size;
213 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
214 if(resizeorigin.x > panel_pos.x && resizeorigin.x < targEndPos.x && resizeorigin.y > panel_pos.y && resizeorigin.y < targEndPos.y)
217 if (resizeCorner == 1)
219 // check if this panel is on our way
220 if (resizeorigin.x <= panel_pos.x)
222 if (resizeorigin.y <= panel_pos.y)
224 if (targEndPos.x <= resizeorigin.x - mySize.x)
226 if (targEndPos.y <= resizeorigin.y - mySize.y)
229 // there is a collision:
230 // detect which side of the panel we are facing is actually limiting the resizing
231 // (which side the resize direction finds for first) and reduce the size up to there
233 // dist is the distance between resizeorigin and the "analogous" point of the panel
234 // in this case between resizeorigin (bottom-right point) and the bottom-right point of the panel
235 dist.x = resizeorigin.x - targEndPos.x;
236 dist.y = resizeorigin.y - targEndPos.y;
237 if (dist.y <= 0 || dist.x / dist.y > ratio)
238 mySize.x = min(mySize.x, dist.x);
240 mySize.y = min(mySize.y, dist.y);
242 else if (resizeCorner == 2)
244 if (resizeorigin.x >= targEndPos.x)
246 if (resizeorigin.y <= panel_pos.y)
248 if (panel_pos.x >= resizeorigin.x + mySize.x)
250 if (targEndPos.y <= resizeorigin.y - mySize.y)
253 dist.x = panel_pos.x - resizeorigin.x;
254 dist.y = resizeorigin.y - targEndPos.y;
255 if (dist.y <= 0 || dist.x / dist.y > ratio)
256 mySize.x = min(mySize.x, dist.x);
258 mySize.y = min(mySize.y, dist.y);
260 else if (resizeCorner == 3)
262 if (resizeorigin.x <= panel_pos.x)
264 if (resizeorigin.y >= targEndPos.y)
266 if (targEndPos.x <= resizeorigin.x - mySize.x)
268 if (panel_pos.y >= resizeorigin.y + mySize.y)
271 dist.x = resizeorigin.x - targEndPos.x;
272 dist.y = panel_pos.y - resizeorigin.y;
273 if (dist.y <= 0 || dist.x / dist.y > ratio)
274 mySize.x = min(mySize.x, dist.x);
276 mySize.y = min(mySize.y, dist.y);
278 else if (resizeCorner == 4)
280 if (resizeorigin.x >= targEndPos.x)
282 if (resizeorigin.y >= targEndPos.y)
284 if (panel_pos.x >= resizeorigin.x + mySize.x)
286 if (panel_pos.y >= resizeorigin.y + mySize.y)
289 dist.x = panel_pos.x - resizeorigin.x;
290 dist.y = panel_pos.y - resizeorigin.y;
291 if (dist.y <= 0 || dist.x / dist.y > ratio)
292 mySize.x = min(mySize.x, dist.x);
294 mySize.y = min(mySize.y, dist.y);
296 //if(cvar("hud_configure_checkcollisions_debug"))
297 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
303 void HUD_Panel_SetPosSize(vector mySize)
305 panel = highlightedPanel;
306 HUD_Panel_UpdatePosSize();
307 vector resizeorigin = panel_click_resizeorigin;
310 // minimum panel size cap
311 mySize.x = max(0.025 * vid_conwidth, mySize.x);
312 mySize.y = max(0.025 * vid_conheight, mySize.y);
314 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.
316 mySize.x = max(17 * autocvar_con_chatsize, mySize.x);
317 mySize.y = max(2 * autocvar_con_chatsize + 2 * panel_bg_padding, mySize.y);
320 // collision testing|
321 // -----------------+
323 // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
324 if(resizeCorner == 1) {
325 myPos.x = resizeorigin.x - mySize.x;
326 myPos.y = resizeorigin.y - mySize.y;
327 } else if(resizeCorner == 2) {
328 myPos.x = resizeorigin.x;
329 myPos.y = resizeorigin.y - mySize.y;
330 } else if(resizeCorner == 3) {
331 myPos.x = resizeorigin.x - mySize.x;
332 myPos.y = resizeorigin.y;
333 } else { // resizeCorner == 4
334 myPos.x = resizeorigin.x;
335 myPos.y = resizeorigin.y;
338 // left/top screen edges
340 mySize.x = mySize.x + myPos.x;
342 mySize.y = mySize.y + myPos.y;
344 // bottom/right screen edges
345 if(myPos.x + mySize.x > vid_conwidth)
346 mySize.x = vid_conwidth - myPos.x;
347 if(myPos.y + mySize.y > vid_conheight)
348 mySize.y = vid_conheight - myPos.y;
350 //if(cvar("hud_configure_checkcollisions_debug"))
351 //drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
353 // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
354 if(autocvar_hud_configure_grid)
356 mySize.x = floor((mySize.x/vid_conwidth)/hud_configure_gridSize.x + 0.5) * hud_configure_realGridSize.x;
357 mySize.y = floor((mySize.y/vid_conheight)/hud_configure_gridSize.y + 0.5) * hud_configure_realGridSize.y;
360 if(hud_configure_checkcollisions)
361 mySize = HUD_Panel_CheckResize(mySize, resizeorigin);
363 // 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)
364 mySize.x = max(0.025 * vid_conwidth, mySize.x);
365 mySize.y = max(0.025 * vid_conheight, mySize.y);
367 // do another pos check, as size might have changed by now
368 if(resizeCorner == 1) {
369 myPos.x = resizeorigin.x - mySize.x;
370 myPos.y = resizeorigin.y - mySize.y;
371 } else if(resizeCorner == 2) {
372 myPos.x = resizeorigin.x;
373 myPos.y = resizeorigin.y - mySize.y;
374 } else if(resizeCorner == 3) {
375 myPos.x = resizeorigin.x - mySize.x;
376 myPos.y = resizeorigin.y;
377 } else { // resizeCorner == 4
378 myPos.x = resizeorigin.x;
379 myPos.y = resizeorigin.y;
382 //if(cvar("hud_configure_checkcollisions_debug"))
383 //drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
386 s = strcat(ftos(mySize.x/vid_conwidth), " ", ftos(mySize.y/vid_conheight));
387 cvar_set(strcat("hud_panel_", highlightedPanel.panel_name, "_size"), s);
389 s = strcat(ftos(myPos.x/vid_conwidth), " ", ftos(myPos.y/vid_conheight));
390 cvar_set(strcat("hud_panel_", highlightedPanel.panel_name, "_pos"), s);
393 float pressed_key_time;
394 vector highlightedPanel_initial_pos, highlightedPanel_initial_size;
395 void HUD_Panel_Arrow_Action(float nPrimary)
397 if(!highlightedPanel)
400 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
403 if(autocvar_hud_configure_grid)
405 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
407 if (hudShiftState & S_SHIFT)
408 step = hud_configure_realGridSize.y;
410 step = 2 * hud_configure_realGridSize.y;
414 if (hudShiftState & S_SHIFT)
415 step = hud_configure_realGridSize.x;
417 step = 2 * hud_configure_realGridSize.x;
422 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
423 step = vid_conheight;
426 if (hudShiftState & S_SHIFT)
427 step = (step / 256); // more precision
429 step = (step / 64) * (1 + 2 * (time - pressed_key_time));
432 panel = highlightedPanel;
433 HUD_Panel_UpdatePosSize();
435 highlightedPanel_initial_pos = panel_pos;
436 highlightedPanel_initial_size = panel_size;
438 if (hudShiftState & S_ALT) // resize
440 if(nPrimary == K_UPARROW)
442 else if(nPrimary == K_RIGHTARROW)
444 else if(nPrimary == K_LEFTARROW)
446 else // if(nPrimary == K_DOWNARROW)
449 // ctrl+arrow reduces the size, instead of increasing it
450 // Note that ctrl disables collisions check too, but it's fine
451 // since we don't collide with anything reducing the size
452 if (hudShiftState & S_CTRL) {
454 resizeCorner = 5 - resizeCorner;
459 panel_click_resizeorigin = panel_pos;
460 if(resizeCorner == 1) {
461 panel_click_resizeorigin += mySize;
463 } else if(resizeCorner == 2) {
464 panel_click_resizeorigin.y += mySize.y;
466 } else if(resizeCorner == 3) {
467 panel_click_resizeorigin.x += mySize.x;
469 } else { // resizeCorner == 4
472 HUD_Panel_SetPosSize(mySize);
478 if(nPrimary == K_UPARROW)
480 else if(nPrimary == K_DOWNARROW)
482 else if(nPrimary == K_LEFTARROW)
484 else // if(nPrimary == K_RIGHTARROW)
487 HUD_Panel_SetPos(pos);
490 panel = highlightedPanel;
491 HUD_Panel_UpdatePosSize();
493 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
496 panel_pos_backup = highlightedPanel_initial_pos;
497 panel_size_backup = highlightedPanel_initial_size;
498 highlightedPanel_backup = highlightedPanel;
502 entity tab_panels[REGISTRY_MAX(hud_panels)];
504 vector tab_panel_pos;
506 void reset_tab_panels()
508 for (int i = 0; i < REGISTRY_COUNT(hud_panels); ++i)
509 tab_panels[i] = NULL;
511 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
518 if(!autocvar__hud_configure)
523 mousepos.x = nPrimary;
524 mousepos.y = nSecondary;
528 // block any input while a menu dialog is fading
529 // don't block mousepos read as it leads to cursor jumps in the interaction with the menu
530 if(autocvar__menu_alpha)
537 // allow console bind to work
538 string con_keys = findkeysforcommand("toggleconsole", 0);
539 int keys = tokenize(con_keys); // findkeysforcommand returns data for this
541 bool hit_con_bind = false;
543 for (i = 0; i < keys; ++i)
545 if(nPrimary == stof(argv(i)))
549 if(bInputType == 0) {
550 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
551 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
552 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
554 else if(bInputType == 1) {
555 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
556 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
557 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
560 if(nPrimary == K_CTRL)
562 if (bInputType == 1) //ctrl has been released
566 //switch to selected panel
567 highlightedPanel = tab_panel;
568 highlightedAction = 0;
569 HUD_Panel_FirstInDrawQ(highlightedPanel.panel_id);
576 if(nPrimary == K_MOUSE1)
578 if(bInputType == 0) // key pressed
579 mouseClicked |= S_MOUSE1;
580 else if(bInputType == 1) // key released
581 mouseClicked -= (mouseClicked & S_MOUSE1);
583 else if(nPrimary == K_MOUSE2)
585 if(bInputType == 0) // key pressed
586 mouseClicked |= S_MOUSE2;
587 else if(bInputType == 1) // key released
588 mouseClicked -= (mouseClicked & S_MOUSE2);
590 else if(nPrimary == K_ESCAPE)
594 hud_configure_menu_open = 1;
595 localcmd("menu_showhudexit\n");
597 else if(nPrimary == K_BACKSPACE && hudShiftState & S_CTRL)
601 if (!hud_configure_menu_open)
602 HUD_Configure_Exit_Force();
604 else if(nPrimary == K_TAB && hudShiftState & S_CTRL) // switch panel
606 if (bInputType == 1 || mouseClicked)
609 // FIXME minor bug: if a panel is highlighted, has the same pos_x and
610 // lays in the same level of another panel then the next consecutive
611 // CTRL TAB presses will reselect once more the highlighted panel
613 entity starting_panel;
614 entity old_tab_panel = tab_panel;
615 if (!tab_panel) //first press of TAB
617 if (highlightedPanel)
619 panel = highlightedPanel;
620 HUD_Panel_UpdatePosSize();
624 starting_panel = highlightedPanel;
625 tab_panel_pos = panel_pos; //to compute level
629 if ( ((!tab_backward) && (hudShiftState & S_SHIFT)) || (tab_backward && !(hudShiftState & S_SHIFT)) ) //tab direction changed?
631 starting_panel = tab_panel;
633 tab_backward = (hudShiftState & S_SHIFT);
635 float k, level = 0, start_posX;
636 vector candidate_pos = '0 0 0';
637 const float LEVELS_NUM = 4;
638 float level_height = vid_conheight / LEVELS_NUM;
639 LABEL(find_tab_panel)
640 level = floor(tab_panel_pos.y / level_height) * level_height; //starting level
641 candidate_pos.x = (!tab_backward) ? vid_conwidth : 0;
642 start_posX = tab_panel_pos.x;
647 for(i = 0; i < REGISTRY_COUNT(hud_panels); ++i)
649 panel = REGISTRY_GET(hud_panels, i);
650 if(!(panel.panel_configflags & PANEL_CONFIG_MAIN))
652 if (panel == tab_panels[i] || panel == starting_panel)
654 HUD_Panel_UpdatePosSize();
655 if (panel_pos.y >= level && (panel_pos.y - level) < level_height)
656 if ( ( !tab_backward && panel_pos.x >= start_posX && (panel_pos.x < candidate_pos.x || (panel_pos.x == candidate_pos.x && panel_pos.y <= candidate_pos.y)) )
657 || ( tab_backward && panel_pos.x <= start_posX && (panel_pos.x > candidate_pos.x || (panel_pos.x == candidate_pos.x && panel_pos.y >= candidate_pos.y)) ) )
660 tab_panel_pos = candidate_pos = panel_pos;
665 if (k == LEVELS_NUM) //tab_panel not found
673 starting_panel = old_tab_panel;
674 old_tab_panel = NULL;
675 goto find_tab_panel; //u must find tab_panel!
679 level = (level + level_height) % vid_conheight;
681 candidate_pos.x = vid_conwidth;
685 level = (level - level_height) % vid_conheight;
686 start_posX = vid_conwidth;
691 tab_panels[tab_panel.panel_id] = tab_panel;
693 else if(nPrimary == K_SPACE && hudShiftState & S_CTRL) // enable/disable highlighted panel or dock
695 if (bInputType == 1 || mouseClicked)
698 if (highlightedPanel)
700 if(panel.panel_configflags & PANEL_CONFIG_CANBEOFF)
701 cvar_set(strcat("hud_panel_", highlightedPanel.panel_name), ftos(!cvar(strcat("hud_panel_", highlightedPanel.panel_name))));
704 cvar_set(strcat("hud_dock"), (autocvar_hud_dock == "") ? "dock" : "");
706 else if(nPrimary == 'c' && hudShiftState & S_CTRL) // copy highlighted panel size
708 if (bInputType == 1 || mouseClicked)
711 if (highlightedPanel)
713 panel = highlightedPanel;
714 HUD_Panel_UpdatePosSize();
715 panel_size_copied = panel_size;
718 else if(nPrimary == 'v' && hudShiftState & S_CTRL) // past copied size on the highlighted panel
720 if (bInputType == 1 || mouseClicked)
723 if (panel_size_copied == '0 0 0' || !highlightedPanel)
726 panel = highlightedPanel;
727 HUD_Panel_UpdatePosSize();
729 // reduce size if it'd go beyond screen boundaries
730 vector tmp_size = panel_size_copied;
731 if (panel_pos.x + panel_size_copied.x > vid_conwidth)
732 tmp_size.x = vid_conwidth - panel_pos.x;
733 if (panel_pos.y + panel_size_copied.y > vid_conheight)
734 tmp_size.y = vid_conheight - panel_pos.y;
736 if (panel_size == tmp_size)
740 panel_pos_backup = panel_pos;
741 panel_size_backup = panel_size;
742 highlightedPanel_backup = highlightedPanel;
744 s = strcat(ftos(tmp_size.x/vid_conwidth), " ", ftos(tmp_size.y/vid_conheight));
745 cvar_set(strcat("hud_panel_", highlightedPanel.panel_name, "_size"), s);
747 else if(nPrimary == 'z' && hudShiftState & S_CTRL) // undo last action
749 if (bInputType == 1 || mouseClicked)
751 //restore previous values
752 if (highlightedPanel_backup)
754 s = strcat(ftos(panel_pos_backup.x/vid_conwidth), " ", ftos(panel_pos_backup.y/vid_conheight));
755 cvar_set(strcat("hud_panel_", highlightedPanel_backup.panel_name, "_pos"), s);
756 s = strcat(ftos(panel_size_backup.x/vid_conwidth), " ", ftos(panel_size_backup.y/vid_conheight));
757 cvar_set(strcat("hud_panel_", highlightedPanel_backup.panel_name, "_size"), s);
758 highlightedPanel_backup = NULL;
761 else if(nPrimary == 's' && hudShiftState & S_CTRL) // save config
763 if (bInputType == 1 || mouseClicked)
765 localcmd("hud save myconfig\n");
767 else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
771 pressed_key_time = 0;
774 else if (pressed_key_time == 0)
775 pressed_key_time = time;
778 HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
780 else if(nPrimary == K_ENTER || nPrimary == K_SPACE || nPrimary == K_KP_ENTER)
784 if (highlightedPanel)
785 HUD_Panel_EnableMenu();
787 else if(hit_con_bind || nPrimary == K_PAUSE)
793 int HUD_Panel_Check_Mouse_Pos(bool allow_move)
796 while(j < REGISTRY_COUNT(hud_panels))
801 panel = REGISTRY_GET(hud_panels, i);
802 if(!(panel.panel_configflags & PANEL_CONFIG_MAIN)) continue;
803 HUD_Panel_UpdatePosSize();
805 float border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
808 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)
812 // resize from topleft border
813 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)
815 return CURSOR_RESIZE;
817 // resize from topright border
818 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)
820 return CURSOR_RESIZE2;
822 // resize from bottomleft border
823 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)
825 return CURSOR_RESIZE2;
827 // resize from bottomright border
828 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)
830 return CURSOR_RESIZE;
833 return CURSOR_NORMAL;
836 // move a panel to the beginning of the panel order array (which means it gets drawn last, on top of everything else)
837 void HUD_Panel_FirstInDrawQ(float id)
841 // find out where in the array our current id is, save into place
842 for(i = 0; i < REGISTRY_COUNT(hud_panels); ++i)
844 if(panel_order[i] == id)
850 // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
852 place = REGISTRY_COUNT(hud_panels) - 1;
854 // move all ids up by one step in the array until "place"
855 for(i = place; i > 0; --i)
857 panel_order[i] = panel_order[i-1];
859 // now save the new top id
862 // let's save them into the cvar by some strcat trickery
864 for(i = 0; i < REGISTRY_COUNT(hud_panels); ++i)
866 s = strcat(s, ftos(panel_order[i]), " ");
868 cvar_set("_hud_panelorder", s);
869 strcpy(hud_panelorder_prev, autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here
872 void HUD_Panel_Highlight(float allow_move)
876 while(j < REGISTRY_COUNT(hud_panels))
881 panel = REGISTRY_GET(hud_panels, i);
882 if(!(panel.panel_configflags & PANEL_CONFIG_MAIN))
884 HUD_Panel_UpdatePosSize();
886 float border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
889 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)
891 highlightedPanel = REGISTRY_GET(hud_panels, i);
892 HUD_Panel_FirstInDrawQ(i);
893 highlightedAction = 1;
894 panel_click_distance = mousepos - panel_pos;
897 // resize from topleft border
898 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)
900 highlightedPanel = REGISTRY_GET(hud_panels, i);
901 HUD_Panel_FirstInDrawQ(i);
902 highlightedAction = 2;
904 panel_click_distance = mousepos - panel_pos;
905 panel_click_resizeorigin = panel_pos + panel_size;
908 // resize from topright border
909 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)
911 highlightedPanel = REGISTRY_GET(hud_panels, i);
912 HUD_Panel_FirstInDrawQ(i);
913 highlightedAction = 2;
915 panel_click_distance.x = panel_size.x - mousepos.x + panel_pos.x;
916 panel_click_distance.y = mousepos.y - panel_pos.y;
917 panel_click_resizeorigin = panel_pos + eY * panel_size.y;
920 // resize from bottomleft border
921 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)
923 highlightedPanel = REGISTRY_GET(hud_panels, i);
924 HUD_Panel_FirstInDrawQ(i);
925 highlightedAction = 2;
927 panel_click_distance.x = mousepos.x - panel_pos.x;
928 panel_click_distance.y = panel_size.y - mousepos.y + panel_pos.y;
929 panel_click_resizeorigin = panel_pos + eX * panel_size.x;
932 // resize from bottomright border
933 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)
935 highlightedPanel = REGISTRY_GET(hud_panels, i);
936 HUD_Panel_FirstInDrawQ(i);
937 highlightedAction = 2;
939 panel_click_distance = panel_size - mousepos + panel_pos;
940 panel_click_resizeorigin = panel_pos;
944 highlightedPanel = NULL;
945 highlightedAction = 0;
948 void HUD_Panel_EnableMenu()
950 hud_configure_menu_open = 2;
951 localcmd("menu_showhudoptions ", highlightedPanel.panel_name, "\n");
953 void HUD_Panel_Mouse()
955 if(autocvar__menu_alpha == 1)
960 if(prevMouseClicked == 0)
964 //stop ctrl-tab selection
968 HUD_Panel_Highlight(mouseClicked & S_MOUSE1); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
969 // and calls HUD_Panel_UpdatePosSize() for the highlighted panel
970 if (highlightedPanel)
972 highlightedPanel_initial_pos = panel_pos;
973 highlightedPanel_initial_size = panel_size;
976 if ((mouseClicked & S_MOUSE1) && time - prevMouseClickedTime < 0.4 && highlightedPanel && prevMouseClickedPos == mousepos)
978 mouseClicked = 0; // to prevent spam, I guess.
979 HUD_Panel_EnableMenu();
983 if (mouseClicked & S_MOUSE1)
985 prevMouseClickedTime = time;
986 prevMouseClickedPos = mousepos;
988 cursor_type = HUD_Panel_Check_Mouse_Pos(mouseClicked & S_MOUSE1);
993 panel = highlightedPanel;
994 HUD_Panel_UpdatePosSize();
997 if (highlightedPanel)
999 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1000 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
1002 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
1004 panel_pos_backup = highlightedPanel_initial_pos;
1005 panel_size_backup = highlightedPanel_initial_size;
1006 highlightedPanel_backup = highlightedPanel;
1009 // in case the clicked panel is inside another panel and we aren't
1010 // moving it, avoid the immediate "fix" of its position/size
1011 // (often unwanted and hateful) by disabling collisions check
1012 hud_configure_checkcollisions = false;
1015 if(highlightedAction == 1)
1016 HUD_Panel_SetPos(mousepos - panel_click_distance);
1017 else if(highlightedAction == 2)
1019 vector mySize = '0 0 0';
1020 if(resizeCorner == 1) {
1021 mySize.x = panel_click_resizeorigin.x - (mousepos.x - panel_click_distance.x);
1022 mySize.y = panel_click_resizeorigin.y - (mousepos.y - panel_click_distance.y);
1023 } else if(resizeCorner == 2) {
1024 mySize.x = mousepos.x + panel_click_distance.x - panel_click_resizeorigin.x;
1025 mySize.y = panel_click_distance.y + panel_click_resizeorigin.y - mousepos.y;
1026 } else if(resizeCorner == 3) {
1027 mySize.x = panel_click_resizeorigin.x + panel_click_distance.x - mousepos.x;
1028 mySize.y = mousepos.y + panel_click_distance.y - panel_click_resizeorigin.y;
1029 } else { // resizeCorner == 4
1030 mySize.x = mousepos.x - (panel_click_resizeorigin.x - panel_click_distance.x);
1031 mySize.y = mousepos.y - (panel_click_resizeorigin.y - panel_click_distance.y);
1033 HUD_Panel_SetPosSize(mySize);
1038 if(prevMouseClicked)
1039 highlightedAction = 0;
1040 if(hud_configure_menu_open == 2)
1041 cursor_type = CURSOR_NORMAL;
1043 cursor_type = HUD_Panel_Check_Mouse_Pos(true);
1044 if (cursor_type != CURSOR_NORMAL && !tab_panel) // mouse over a panel?
1045 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1048 void HUD_Configure_DrawGrid()
1051 if(autocvar_hud_configure_grid && autocvar_hud_configure_grid_alpha)
1053 hud_configure_gridSize.x = bound(0.005, cvar("hud_configure_grid_xsize"), 0.2);
1054 hud_configure_gridSize.y = bound(0.005, cvar("hud_configure_grid_ysize"), 0.2);
1055 hud_configure_realGridSize.x = hud_configure_gridSize.x * vid_conwidth;
1056 hud_configure_realGridSize.y = hud_configure_gridSize.y * vid_conheight;
1059 s = vec2(1, vid_conheight);
1060 for(i = 1; i < 1/hud_configure_gridSize.x; ++i)
1061 drawfill(eX * i * hud_configure_realGridSize.x, s, '0.5 0.5 0.5', autocvar_hud_configure_grid_alpha, DRAWFLAG_NORMAL);
1063 s = vec2(vid_conwidth, 1);
1064 for(i = 1; i < 1/hud_configure_gridSize.y; ++i)
1065 drawfill(eY * i * hud_configure_realGridSize.y, s, '0.5 0.5 0.5', autocvar_hud_configure_grid_alpha, DRAWFLAG_NORMAL);
1069 float _menu_alpha_prev;
1070 void HUD_Configure_Frame()
1073 if(autocvar__hud_configure)
1075 if(isdemo() || intermission == 2 || scoreboard_active)
1077 HUD_Configure_Exit_Force();
1081 if(!hud_configure_prev)
1084 for(i = REGISTRY_COUNT(hud_panels) - 1; i >= 0; --i)
1085 REGISTRY_GET(hud_panels, panel_order[i]).update_time = time;
1088 // NOTE this check is necessary because _menu_alpha isn't updated the frame the menu gets enabled
1089 if(autocvar__menu_alpha != _menu_alpha_prev)
1091 if(autocvar__menu_alpha == 0)
1092 hud_configure_menu_open = 0;
1093 _menu_alpha_prev = autocvar__menu_alpha;
1096 HUD_Configure_DrawGrid();
1098 else if(hud_configure_prev)
1100 if(hud_configure_menu_open)
1101 hud_configure_menu_open = 0;
1102 hud_dynamic_shake_factor = -1;
1106 const float hlBorderSize = 2;
1107 const string hlBorder = "gfx/hud/default/border_highlighted";
1108 const string hlBorder2 = "gfx/hud/default/border_highlighted2";
1109 void HUD_Panel_HlBorder(float myBorder, vector color, float theAlpha)
1111 vector pos = panel_pos - vec2(myBorder, myBorder);
1112 drawfill(pos, panel_size + '2 2 0' * myBorder, '0 0.5 1', .5 * theAlpha, DRAWFLAG_NORMAL);
1113 drawpic_tiled(pos, hlBorder, '8 1 0' * hlBorderSize, vec2(panel_size.x + 2 * myBorder, hlBorderSize), color, theAlpha, DRAWFLAG_NORMAL);
1114 drawpic_tiled(pos + eY * (panel_size.y + 2 * myBorder - hlBorderSize), hlBorder, '8 1 0' * hlBorderSize, vec2(panel_size.x + 2 * myBorder, hlBorderSize), color, theAlpha, DRAWFLAG_NORMAL);
1115 pos.y += hlBorderSize;
1116 drawpic_tiled(pos, hlBorder2, '1 8 0' * hlBorderSize, vec2(hlBorderSize, panel_size.y + 2 * myBorder - 2 * hlBorderSize), color, theAlpha, DRAWFLAG_NORMAL);
1117 drawpic_tiled(pos + eX * (panel_size.x + 2 * myBorder - hlBorderSize), hlBorder2, '1 8 0' * hlBorderSize, vec2(hlBorderSize, panel_size.y + 2 * myBorder - 2 * hlBorderSize), color, theAlpha, DRAWFLAG_NORMAL);
1120 void HUD_Configure_PostDraw()
1122 if(autocvar__hud_configure)
1127 HUD_Panel_UpdatePosSize();
1128 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .2, DRAWFLAG_NORMAL);
1130 if(highlightedPanel)
1132 panel = highlightedPanel;
1133 HUD_Panel_UpdatePosSize();
1134 HUD_Panel_HlBorder(panel_bg_border * hlBorderSize, '0 0.5 1', 0.4 * (1 - autocvar__menu_alpha));