1 #include "hud_config.qh"
4 #include "panel/scoreboard.qh"
5 #include <client/autocvars.qh>
6 #include <client/defs.qh>
7 #include <client/miscfunctions.qh>
8 #include <client/view.qh>
11 void HUD_Panel_ExportCfg(string cfgname)
14 string filename = strcat("hud_", autocvar_hud_skin, "_", cfgname, ".cfg");
16 fh = fopen(filename, FILE_WRITE);
19 HUD_Write("//title \n");
20 HUD_Write("//author \n");
22 HUD_Write_Cvar("hud_skin");
23 HUD_Write_Cvar("hud_panel_bg");
24 HUD_Write_Cvar("hud_panel_bg_color");
25 HUD_Write_Cvar("hud_panel_bg_color_team");
26 HUD_Write_Cvar("hud_panel_bg_alpha");
27 HUD_Write_Cvar("hud_panel_bg_border");
28 HUD_Write_Cvar("hud_panel_bg_padding");
29 HUD_Write_Cvar("hud_panel_fg_alpha");
32 HUD_Write_Cvar("hud_dock");
33 HUD_Write_Cvar("hud_dock_color");
34 HUD_Write_Cvar("hud_dock_color_team");
35 HUD_Write_Cvar("hud_dock_alpha");
38 HUD_Write_Cvar("hud_progressbar_alpha");
39 HUD_Write_Cvar("hud_progressbar_strength_color");
40 HUD_Write_Cvar("hud_progressbar_superweapons_color");
41 HUD_Write_Cvar("hud_progressbar_shield_color");
42 HUD_Write_Cvar("hud_progressbar_health_color");
43 HUD_Write_Cvar("hud_progressbar_armor_color");
44 HUD_Write_Cvar("hud_progressbar_fuel_color");
45 HUD_Write_Cvar("hud_progressbar_oxygen_color");
46 HUD_Write_Cvar("hud_progressbar_nexball_color");
47 HUD_Write_Cvar("hud_progressbar_speed_color");
48 HUD_Write_Cvar("hud_progressbar_acceleration_color");
49 HUD_Write_Cvar("hud_progressbar_acceleration_neg_color");
50 HUD_Write_Cvar("hud_progressbar_vehicles_ammo1_color");
51 HUD_Write_Cvar("hud_progressbar_vehicles_ammo2_color");
54 HUD_Write_Cvar("_hud_panelorder");
57 HUD_Write_Cvar("hud_configure_grid");
58 HUD_Write_Cvar("hud_configure_grid_xsize");
59 HUD_Write_Cvar("hud_configure_grid_ysize");
62 // common cvars for all panels
63 for (int i = 0; i < hud_panels_COUNT; ++i)
65 panel = hud_panels_from(i);
67 HUD_Write_PanelCvar("_pos");
68 HUD_Write_PanelCvar("_size");
69 HUD_Write_PanelCvar("_bg");
70 HUD_Write_PanelCvar("_bg_color");
71 HUD_Write_PanelCvar("_bg_color_team");
72 HUD_Write_PanelCvar("_bg_alpha");
73 HUD_Write_PanelCvar("_bg_border");
74 HUD_Write_PanelCvar("_bg_padding");
75 panel.panel_export(panel, fh);
78 MUTATOR_CALLHOOK(HUD_WriteCvars, fh);
80 HUD_Write("menu_sync\n"); // force the menu to reread the cvars, so that the dialogs are updated
82 LOG_INFOF(_("^2Successfully exported to %s! (Note: It's saved in data/data/)"), filename);
86 LOG_INFOF(_("^1Couldn't write to %s"), filename);
89 void HUD_Configure_Exit_Force()
91 if (hud_configure_menu_open)
93 hud_configure_menu_open = 0;
94 localcmd("togglemenu\n");
96 cursor_type = CURSOR_NORMAL;
97 cvar_set("_hud_configure", "0");
100 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
101 vector HUD_Panel_CheckMove(vector myPos, vector mySize)
103 vector myCenter, targCenter;
104 vector myTarget = myPos;
106 for (i = 0; i < hud_panels_COUNT; ++i) {
107 panel = hud_panels_from(i);
108 if(!(panel.panel_configflags & PANEL_CONFIG_MAIN)) continue;
109 if(panel == highlightedPanel) continue;
110 HUD_Panel_UpdatePosSize();
111 if(!panel_enabled) continue;
113 panel_pos -= '1 1 0' * panel_bg_border;
114 panel_size += '2 2 0' * panel_bg_border;
116 if(myPos.y + mySize.y < panel_pos.y)
118 if(myPos.y > panel_pos.y + panel_size.y)
121 if(myPos.x + mySize.x < panel_pos.x)
123 if(myPos.x > panel_pos.x + panel_size.x)
126 // OK, there IS a collision.
128 myCenter.x = myPos.x + 0.5 * mySize.x;
129 myCenter.y = myPos.y + 0.5 * mySize.y;
131 targCenter.x = panel_pos.x + 0.5 * panel_size.x;
132 targCenter.y = panel_pos.y + 0.5 * panel_size.y;
134 if(myCenter.x < targCenter.x && myCenter.y < targCenter.y) // top left (of the target panel)
136 if(myPos.x + mySize.x - panel_pos.x < myPos.y + mySize.y - panel_pos.y) // push it to the side
137 myTarget.x = panel_pos.x - mySize.x;
138 else // push it upwards
139 myTarget.y = panel_pos.y - mySize.y;
141 else if(myCenter.x > targCenter.x && myCenter.y < targCenter.y) // top right
143 if(panel_pos.x + panel_size.x - myPos.x < myPos.y + mySize.y - panel_pos.y) // push it to the side
144 myTarget.x = panel_pos.x + panel_size.x;
145 else // push it upwards
146 myTarget.y = panel_pos.y - mySize.y;
148 else if(myCenter.x < targCenter.x && myCenter.y > targCenter.y) // bottom left
150 if(myPos.x + mySize.x - panel_pos.x < panel_pos.y + panel_size.y - myPos.y) // push it to the side
151 myTarget.x = panel_pos.x - mySize.x;
152 else // push it downwards
153 myTarget.y = panel_pos.y + panel_size.y;
155 else if(myCenter.x > targCenter.x && myCenter.y > targCenter.y) // bottom right
157 if(panel_pos.x + panel_size.x - myPos.x < panel_pos.y + panel_size.y - myPos.y) // push it to the side
158 myTarget.x = panel_pos.x + panel_size.x;
159 else // push it downwards
160 myTarget.y = panel_pos.y + panel_size.y;
162 //if(cvar("hud_configure_checkcollisions_debug"))
163 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
169 void HUD_Panel_SetPos(vector pos)
171 panel = highlightedPanel;
172 HUD_Panel_UpdatePosSize();
176 //if(cvar("hud_configure_checkcollisions_debug"))
177 //drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
179 if(autocvar_hud_configure_grid)
181 pos.x = floor((pos.x/vid_conwidth)/hud_configure_gridSize.x + 0.5) * hud_configure_realGridSize.x;
182 pos.y = floor((pos.y/vid_conheight)/hud_configure_gridSize.y + 0.5) * hud_configure_realGridSize.y;
185 if(hud_configure_checkcollisions)
186 pos = HUD_Panel_CheckMove(pos, mySize);
188 pos.x = bound(0, pos.x, vid_conwidth - mySize.x);
189 pos.y = bound(0, pos.y, vid_conheight - mySize.y);
192 s = strcat(ftos(pos.x/vid_conwidth), " ", ftos(pos.y/vid_conheight));
194 cvar_set(strcat("hud_panel_", highlightedPanel.panel_name, "_pos"), s);
197 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
198 vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
201 float ratio = mySize.x/mySize.y;
203 for (i = 0; i < hud_panels_COUNT; ++i) {
204 panel = hud_panels_from(i);
205 if(!(panel.panel_configflags & PANEL_CONFIG_MAIN)) continue;
206 if(panel == highlightedPanel) continue;
207 HUD_Panel_UpdatePosSize();
208 if(!panel_enabled) continue;
210 panel_pos -= '1 1 0' * panel_bg_border;
211 panel_size += '2 2 0' * panel_bg_border;
213 targEndPos = panel_pos + panel_size;
215 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
216 if(resizeorigin.x > panel_pos.x && resizeorigin.x < targEndPos.x && resizeorigin.y > panel_pos.y && resizeorigin.y < targEndPos.y)
219 if (resizeCorner == 1)
221 // check if this panel is on our way
222 if (resizeorigin.x <= panel_pos.x)
224 if (resizeorigin.y <= panel_pos.y)
226 if (targEndPos.x <= resizeorigin.x - mySize.x)
228 if (targEndPos.y <= resizeorigin.y - mySize.y)
231 // there is a collision:
232 // detect which side of the panel we are facing is actually limiting the resizing
233 // (which side the resize direction finds for first) and reduce the size up to there
235 // dist is the distance between resizeorigin and the "analogous" point of the panel
236 // in this case between resizeorigin (bottom-right point) and the bottom-right point of the panel
237 dist.x = resizeorigin.x - targEndPos.x;
238 dist.y = resizeorigin.y - targEndPos.y;
239 if (dist.y <= 0 || dist.x / dist.y > ratio)
240 mySize.x = min(mySize.x, dist.x);
242 mySize.y = min(mySize.y, dist.y);
244 else if (resizeCorner == 2)
246 if (resizeorigin.x >= targEndPos.x)
248 if (resizeorigin.y <= panel_pos.y)
250 if (panel_pos.x >= resizeorigin.x + mySize.x)
252 if (targEndPos.y <= resizeorigin.y - mySize.y)
255 dist.x = panel_pos.x - resizeorigin.x;
256 dist.y = resizeorigin.y - targEndPos.y;
257 if (dist.y <= 0 || dist.x / dist.y > ratio)
258 mySize.x = min(mySize.x, dist.x);
260 mySize.y = min(mySize.y, dist.y);
262 else if (resizeCorner == 3)
264 if (resizeorigin.x <= panel_pos.x)
266 if (resizeorigin.y >= targEndPos.y)
268 if (targEndPos.x <= resizeorigin.x - mySize.x)
270 if (panel_pos.y >= resizeorigin.y + mySize.y)
273 dist.x = resizeorigin.x - targEndPos.x;
274 dist.y = panel_pos.y - resizeorigin.y;
275 if (dist.y <= 0 || dist.x / dist.y > ratio)
276 mySize.x = min(mySize.x, dist.x);
278 mySize.y = min(mySize.y, dist.y);
280 else if (resizeCorner == 4)
282 if (resizeorigin.x >= targEndPos.x)
284 if (resizeorigin.y >= targEndPos.y)
286 if (panel_pos.x >= resizeorigin.x + mySize.x)
288 if (panel_pos.y >= resizeorigin.y + mySize.y)
291 dist.x = panel_pos.x - resizeorigin.x;
292 dist.y = panel_pos.y - resizeorigin.y;
293 if (dist.y <= 0 || dist.x / dist.y > ratio)
294 mySize.x = min(mySize.x, dist.x);
296 mySize.y = min(mySize.y, dist.y);
298 //if(cvar("hud_configure_checkcollisions_debug"))
299 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
305 void HUD_Panel_SetPosSize(vector mySize)
307 panel = highlightedPanel;
308 HUD_Panel_UpdatePosSize();
309 vector resizeorigin = panel_click_resizeorigin;
312 // minimum panel size cap
313 mySize.x = max(0.025 * vid_conwidth, mySize.x);
314 mySize.y = max(0.025 * vid_conheight, mySize.y);
316 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.
318 mySize.x = max(17 * autocvar_con_chatsize, mySize.x);
319 mySize.y = max(2 * autocvar_con_chatsize + 2 * panel_bg_padding, mySize.y);
322 // collision testing|
323 // -----------------+
325 // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
326 if(resizeCorner == 1) {
327 myPos.x = resizeorigin.x - mySize.x;
328 myPos.y = resizeorigin.y - mySize.y;
329 } else if(resizeCorner == 2) {
330 myPos.x = resizeorigin.x;
331 myPos.y = resizeorigin.y - mySize.y;
332 } else if(resizeCorner == 3) {
333 myPos.x = resizeorigin.x - mySize.x;
334 myPos.y = resizeorigin.y;
335 } else { // resizeCorner == 4
336 myPos.x = resizeorigin.x;
337 myPos.y = resizeorigin.y;
340 // left/top screen edges
342 mySize.x = mySize.x + myPos.x;
344 mySize.y = mySize.y + myPos.y;
346 // bottom/right screen edges
347 if(myPos.x + mySize.x > vid_conwidth)
348 mySize.x = vid_conwidth - myPos.x;
349 if(myPos.y + mySize.y > vid_conheight)
350 mySize.y = vid_conheight - myPos.y;
352 //if(cvar("hud_configure_checkcollisions_debug"))
353 //drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
355 // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
356 if(autocvar_hud_configure_grid)
358 mySize.x = floor((mySize.x/vid_conwidth)/hud_configure_gridSize.x + 0.5) * hud_configure_realGridSize.x;
359 mySize.y = floor((mySize.y/vid_conheight)/hud_configure_gridSize.y + 0.5) * hud_configure_realGridSize.y;
362 if(hud_configure_checkcollisions)
363 mySize = HUD_Panel_CheckResize(mySize, resizeorigin);
365 // 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)
366 mySize.x = max(0.025 * vid_conwidth, mySize.x);
367 mySize.y = max(0.025 * vid_conheight, mySize.y);
369 // do another pos check, as size might have changed by now
370 if(resizeCorner == 1) {
371 myPos.x = resizeorigin.x - mySize.x;
372 myPos.y = resizeorigin.y - mySize.y;
373 } else if(resizeCorner == 2) {
374 myPos.x = resizeorigin.x;
375 myPos.y = resizeorigin.y - mySize.y;
376 } else if(resizeCorner == 3) {
377 myPos.x = resizeorigin.x - mySize.x;
378 myPos.y = resizeorigin.y;
379 } else { // resizeCorner == 4
380 myPos.x = resizeorigin.x;
381 myPos.y = resizeorigin.y;
384 //if(cvar("hud_configure_checkcollisions_debug"))
385 //drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
388 s = strcat(ftos(mySize.x/vid_conwidth), " ", ftos(mySize.y/vid_conheight));
389 cvar_set(strcat("hud_panel_", highlightedPanel.panel_name, "_size"), s);
391 s = strcat(ftos(myPos.x/vid_conwidth), " ", ftos(myPos.y/vid_conheight));
392 cvar_set(strcat("hud_panel_", highlightedPanel.panel_name, "_pos"), s);
395 float pressed_key_time;
396 vector highlightedPanel_initial_pos, highlightedPanel_initial_size;
397 void HUD_Panel_Arrow_Action(float nPrimary)
399 if(!highlightedPanel)
402 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
405 if(autocvar_hud_configure_grid)
407 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
409 if (hudShiftState & S_SHIFT)
410 step = hud_configure_realGridSize.y;
412 step = 2 * hud_configure_realGridSize.y;
416 if (hudShiftState & S_SHIFT)
417 step = hud_configure_realGridSize.x;
419 step = 2 * hud_configure_realGridSize.x;
424 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
425 step = vid_conheight;
428 if (hudShiftState & S_SHIFT)
429 step = (step / 256); // more precision
431 step = (step / 64) * (1 + 2 * (time - pressed_key_time));
434 panel = highlightedPanel;
435 HUD_Panel_UpdatePosSize();
437 highlightedPanel_initial_pos = panel_pos;
438 highlightedPanel_initial_size = panel_size;
440 if (hudShiftState & S_ALT) // resize
442 if(nPrimary == K_UPARROW)
444 else if(nPrimary == K_RIGHTARROW)
446 else if(nPrimary == K_LEFTARROW)
448 else // if(nPrimary == K_DOWNARROW)
451 // ctrl+arrow reduces the size, instead of increasing it
452 // Note that ctrl disables collisions check too, but it's fine
453 // since we don't collide with anything reducing the size
454 if (hudShiftState & S_CTRL) {
456 resizeCorner = 5 - resizeCorner;
461 panel_click_resizeorigin = panel_pos;
462 if(resizeCorner == 1) {
463 panel_click_resizeorigin += mySize;
465 } else if(resizeCorner == 2) {
466 panel_click_resizeorigin.y += mySize.y;
468 } else if(resizeCorner == 3) {
469 panel_click_resizeorigin.x += mySize.x;
471 } else { // resizeCorner == 4
474 HUD_Panel_SetPosSize(mySize);
480 if(nPrimary == K_UPARROW)
482 else if(nPrimary == K_DOWNARROW)
484 else if(nPrimary == K_LEFTARROW)
486 else // if(nPrimary == K_RIGHTARROW)
489 HUD_Panel_SetPos(pos);
492 panel = highlightedPanel;
493 HUD_Panel_UpdatePosSize();
495 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
498 panel_pos_backup = highlightedPanel_initial_pos;
499 panel_size_backup = highlightedPanel_initial_size;
500 highlightedPanel_backup = highlightedPanel;
504 entity tab_panels[hud_panels_MAX];
506 vector tab_panel_pos;
508 void reset_tab_panels()
510 for (int i = 0; i < hud_panels_COUNT; ++i)
511 tab_panels[i] = NULL;
513 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
520 if(!autocvar__hud_configure)
525 mousepos.x = nPrimary;
526 mousepos.y = nSecondary;
530 // block any input while a menu dialog is fading
531 // don't block mousepos read as it leads to cursor jumps in the interaction with the menu
532 if(autocvar__menu_alpha)
539 // allow console bind to work
540 string con_keys = findkeysforcommand("toggleconsole", 0);
541 int keys = tokenize(con_keys); // findkeysforcommand returns data for this
543 bool hit_con_bind = false;
545 for (i = 0; i < keys; ++i)
547 if(nPrimary == stof(argv(i)))
551 if(bInputType == 0) {
552 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
553 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
554 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
556 else if(bInputType == 1) {
557 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
558 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
559 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
562 if(nPrimary == K_CTRL)
564 if (bInputType == 1) //ctrl has been released
568 //switch to selected panel
569 highlightedPanel = tab_panel;
570 highlightedAction = 0;
571 HUD_Panel_FirstInDrawQ(highlightedPanel.panel_id);
578 if(nPrimary == K_MOUSE1)
580 if(bInputType == 0) // key pressed
581 mouseClicked |= S_MOUSE1;
582 else if(bInputType == 1) // key released
583 mouseClicked -= (mouseClicked & S_MOUSE1);
585 else if(nPrimary == K_MOUSE2)
587 if(bInputType == 0) // key pressed
588 mouseClicked |= S_MOUSE2;
589 else if(bInputType == 1) // key released
590 mouseClicked -= (mouseClicked & S_MOUSE2);
592 else if(nPrimary == K_ESCAPE)
596 hud_configure_menu_open = 1;
597 localcmd("menu_showhudexit\n");
599 else if(nPrimary == K_BACKSPACE && hudShiftState & S_CTRL)
603 if (!hud_configure_menu_open)
604 HUD_Configure_Exit_Force();
606 else if(nPrimary == K_TAB && hudShiftState & S_CTRL) // switch panel
608 if (bInputType == 1 || mouseClicked)
611 // FIXME minor bug: if a panel is highlighted, has the same pos_x and
612 // lays in the same level of another panel then the next consecutive
613 // CTRL TAB presses will reselect once more the highlighted panel
615 entity starting_panel;
616 entity old_tab_panel = tab_panel;
617 if (!tab_panel) //first press of TAB
619 if (highlightedPanel)
621 panel = highlightedPanel;
622 HUD_Panel_UpdatePosSize();
626 starting_panel = highlightedPanel;
627 tab_panel_pos = panel_pos; //to compute level
631 if ( ((!tab_backward) && (hudShiftState & S_SHIFT)) || (tab_backward && !(hudShiftState & S_SHIFT)) ) //tab direction changed?
633 starting_panel = tab_panel;
635 tab_backward = (hudShiftState & S_SHIFT);
637 float k, level = 0, start_posX;
638 vector candidate_pos = '0 0 0';
639 const float LEVELS_NUM = 4;
640 float level_height = vid_conheight / LEVELS_NUM;
641 LABEL(find_tab_panel)
642 level = floor(tab_panel_pos.y / level_height) * level_height; //starting level
643 candidate_pos.x = (!tab_backward) ? vid_conwidth : 0;
644 start_posX = tab_panel_pos.x;
649 for(i = 0; i < hud_panels_COUNT; ++i)
651 panel = hud_panels_from(i);
652 if(!(panel.panel_configflags & PANEL_CONFIG_MAIN))
654 if (panel == tab_panels[i] || panel == starting_panel)
656 HUD_Panel_UpdatePosSize();
657 if (panel_pos.y >= level && (panel_pos.y - level) < level_height)
658 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)) )
659 || ( 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)) ) )
662 tab_panel_pos = candidate_pos = panel_pos;
667 if (k == LEVELS_NUM) //tab_panel not found
675 starting_panel = old_tab_panel;
676 old_tab_panel = NULL;
677 goto find_tab_panel; //u must find tab_panel!
681 level = (level + level_height) % vid_conheight;
683 candidate_pos.x = vid_conwidth;
687 level = (level - level_height) % vid_conheight;
688 start_posX = vid_conwidth;
693 tab_panels[tab_panel.panel_id] = tab_panel;
695 else if(nPrimary == K_SPACE && hudShiftState & S_CTRL) // enable/disable highlighted panel or dock
697 if (bInputType == 1 || mouseClicked)
700 if (highlightedPanel)
702 if(panel.panel_configflags & PANEL_CONFIG_CANBEOFF)
703 cvar_set(strcat("hud_panel_", highlightedPanel.panel_name), ftos(!cvar(strcat("hud_panel_", highlightedPanel.panel_name))));
706 cvar_set(strcat("hud_dock"), (autocvar_hud_dock == "") ? "dock" : "");
708 else if(nPrimary == 'c' && hudShiftState & S_CTRL) // copy highlighted panel size
710 if (bInputType == 1 || mouseClicked)
713 if (highlightedPanel)
715 panel = highlightedPanel;
716 HUD_Panel_UpdatePosSize();
717 panel_size_copied = panel_size;
720 else if(nPrimary == 'v' && hudShiftState & S_CTRL) // past copied size on the highlighted panel
722 if (bInputType == 1 || mouseClicked)
725 if (panel_size_copied == '0 0 0' || !highlightedPanel)
728 panel = highlightedPanel;
729 HUD_Panel_UpdatePosSize();
731 // reduce size if it'd go beyond screen boundaries
732 vector tmp_size = panel_size_copied;
733 if (panel_pos.x + panel_size_copied.x > vid_conwidth)
734 tmp_size.x = vid_conwidth - panel_pos.x;
735 if (panel_pos.y + panel_size_copied.y > vid_conheight)
736 tmp_size.y = vid_conheight - panel_pos.y;
738 if (panel_size == tmp_size)
742 panel_pos_backup = panel_pos;
743 panel_size_backup = panel_size;
744 highlightedPanel_backup = highlightedPanel;
746 s = strcat(ftos(tmp_size.x/vid_conwidth), " ", ftos(tmp_size.y/vid_conheight));
747 cvar_set(strcat("hud_panel_", highlightedPanel.panel_name, "_size"), s);
749 else if(nPrimary == 'z' && hudShiftState & S_CTRL) // undo last action
751 if (bInputType == 1 || mouseClicked)
753 //restore previous values
754 if (highlightedPanel_backup)
756 s = strcat(ftos(panel_pos_backup.x/vid_conwidth), " ", ftos(panel_pos_backup.y/vid_conheight));
757 cvar_set(strcat("hud_panel_", highlightedPanel_backup.panel_name, "_pos"), s);
758 s = strcat(ftos(panel_size_backup.x/vid_conwidth), " ", ftos(panel_size_backup.y/vid_conheight));
759 cvar_set(strcat("hud_panel_", highlightedPanel_backup.panel_name, "_size"), s);
760 highlightedPanel_backup = NULL;
763 else if(nPrimary == 's' && hudShiftState & S_CTRL) // save config
765 if (bInputType == 1 || mouseClicked)
767 localcmd("hud save myconfig\n");
769 else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
773 pressed_key_time = 0;
776 else if (pressed_key_time == 0)
777 pressed_key_time = time;
780 HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
782 else if(nPrimary == K_ENTER || nPrimary == K_SPACE || nPrimary == K_KP_ENTER)
786 if (highlightedPanel)
787 HUD_Panel_EnableMenu();
789 else if(hit_con_bind || nPrimary == K_PAUSE)
795 int HUD_Panel_Check_Mouse_Pos(bool allow_move)
798 while(j < hud_panels_COUNT)
803 panel = hud_panels_from(i);
804 if(!(panel.panel_configflags & PANEL_CONFIG_MAIN)) continue;
805 HUD_Panel_UpdatePosSize();
807 float border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
810 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)
814 // resize from topleft border
815 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)
817 return CURSOR_RESIZE;
819 // resize from topright border
820 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)
822 return CURSOR_RESIZE2;
824 // resize from bottomleft border
825 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)
827 return CURSOR_RESIZE2;
829 // resize from bottomright border
830 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)
832 return CURSOR_RESIZE;
835 return CURSOR_NORMAL;
838 // move a panel to the beginning of the panel order array (which means it gets drawn last, on top of everything else)
839 void HUD_Panel_FirstInDrawQ(float id)
843 // find out where in the array our current id is, save into place
844 for(i = 0; i < hud_panels_COUNT; ++i)
846 if(panel_order[i] == id)
852 // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
854 place = hud_panels_COUNT - 1;
856 // move all ids up by one step in the array until "place"
857 for(i = place; i > 0; --i)
859 panel_order[i] = panel_order[i-1];
861 // now save the new top id
864 // let's save them into the cvar by some strcat trickery
866 for(i = 0; i < hud_panels_COUNT; ++i)
868 s = strcat(s, ftos(panel_order[i]), " ");
870 cvar_set("_hud_panelorder", s);
871 strcpy(hud_panelorder_prev, autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here
874 void HUD_Panel_Highlight(float allow_move)
878 while(j < hud_panels_COUNT)
883 panel = hud_panels_from(i);
884 if(!(panel.panel_configflags & PANEL_CONFIG_MAIN))
886 HUD_Panel_UpdatePosSize();
888 float border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
891 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)
893 highlightedPanel = hud_panels_from(i);
894 HUD_Panel_FirstInDrawQ(i);
895 highlightedAction = 1;
896 panel_click_distance = mousepos - panel_pos;
899 // resize from topleft border
900 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)
902 highlightedPanel = hud_panels_from(i);
903 HUD_Panel_FirstInDrawQ(i);
904 highlightedAction = 2;
906 panel_click_distance = mousepos - panel_pos;
907 panel_click_resizeorigin = panel_pos + panel_size;
910 // resize from topright border
911 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)
913 highlightedPanel = hud_panels_from(i);
914 HUD_Panel_FirstInDrawQ(i);
915 highlightedAction = 2;
917 panel_click_distance.x = panel_size.x - mousepos.x + panel_pos.x;
918 panel_click_distance.y = mousepos.y - panel_pos.y;
919 panel_click_resizeorigin = panel_pos + eY * panel_size.y;
922 // resize from bottomleft border
923 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)
925 highlightedPanel = hud_panels_from(i);
926 HUD_Panel_FirstInDrawQ(i);
927 highlightedAction = 2;
929 panel_click_distance.x = mousepos.x - panel_pos.x;
930 panel_click_distance.y = panel_size.y - mousepos.y + panel_pos.y;
931 panel_click_resizeorigin = panel_pos + eX * panel_size.x;
934 // resize from bottomright border
935 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)
937 highlightedPanel = hud_panels_from(i);
938 HUD_Panel_FirstInDrawQ(i);
939 highlightedAction = 2;
941 panel_click_distance = panel_size - mousepos + panel_pos;
942 panel_click_resizeorigin = panel_pos;
946 highlightedPanel = NULL;
947 highlightedAction = 0;
950 void HUD_Panel_EnableMenu()
952 hud_configure_menu_open = 2;
953 localcmd("menu_showhudoptions ", highlightedPanel.panel_name, "\n");
955 void HUD_Panel_Mouse()
957 if(autocvar__menu_alpha == 1)
962 if(prevMouseClicked == 0)
966 //stop ctrl-tab selection
970 HUD_Panel_Highlight(mouseClicked & S_MOUSE1); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
971 // and calls HUD_Panel_UpdatePosSize() for the highlighted panel
972 if (highlightedPanel)
974 highlightedPanel_initial_pos = panel_pos;
975 highlightedPanel_initial_size = panel_size;
978 if ((mouseClicked & S_MOUSE1) && time - prevMouseClickedTime < 0.4 && highlightedPanel && prevMouseClickedPos == mousepos)
980 mouseClicked = 0; // to prevent spam, I guess.
981 HUD_Panel_EnableMenu();
985 if (mouseClicked & S_MOUSE1)
987 prevMouseClickedTime = time;
988 prevMouseClickedPos = mousepos;
990 cursor_type = HUD_Panel_Check_Mouse_Pos(mouseClicked & S_MOUSE1);
995 panel = highlightedPanel;
996 HUD_Panel_UpdatePosSize();
999 if (highlightedPanel)
1001 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1002 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
1004 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
1006 panel_pos_backup = highlightedPanel_initial_pos;
1007 panel_size_backup = highlightedPanel_initial_size;
1008 highlightedPanel_backup = highlightedPanel;
1011 // in case the clicked panel is inside another panel and we aren't
1012 // moving it, avoid the immediate "fix" of its position/size
1013 // (often unwanted and hateful) by disabling collisions check
1014 hud_configure_checkcollisions = false;
1017 if(highlightedAction == 1)
1018 HUD_Panel_SetPos(mousepos - panel_click_distance);
1019 else if(highlightedAction == 2)
1021 vector mySize = '0 0 0';
1022 if(resizeCorner == 1) {
1023 mySize.x = panel_click_resizeorigin.x - (mousepos.x - panel_click_distance.x);
1024 mySize.y = panel_click_resizeorigin.y - (mousepos.y - panel_click_distance.y);
1025 } else if(resizeCorner == 2) {
1026 mySize.x = mousepos.x + panel_click_distance.x - panel_click_resizeorigin.x;
1027 mySize.y = panel_click_distance.y + panel_click_resizeorigin.y - mousepos.y;
1028 } else if(resizeCorner == 3) {
1029 mySize.x = panel_click_resizeorigin.x + panel_click_distance.x - mousepos.x;
1030 mySize.y = mousepos.y + panel_click_distance.y - panel_click_resizeorigin.y;
1031 } else { // resizeCorner == 4
1032 mySize.x = mousepos.x - (panel_click_resizeorigin.x - panel_click_distance.x);
1033 mySize.y = mousepos.y - (panel_click_resizeorigin.y - panel_click_distance.y);
1035 HUD_Panel_SetPosSize(mySize);
1040 if(prevMouseClicked)
1041 highlightedAction = 0;
1042 if(hud_configure_menu_open == 2)
1043 cursor_type = CURSOR_NORMAL;
1045 cursor_type = HUD_Panel_Check_Mouse_Pos(true);
1046 if (cursor_type != CURSOR_NORMAL && !tab_panel) // mouse over a panel?
1047 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1050 void HUD_Configure_DrawGrid()
1053 if(autocvar_hud_configure_grid && autocvar_hud_configure_grid_alpha)
1055 hud_configure_gridSize.x = bound(0.005, cvar("hud_configure_grid_xsize"), 0.2);
1056 hud_configure_gridSize.y = bound(0.005, cvar("hud_configure_grid_ysize"), 0.2);
1057 hud_configure_realGridSize.x = hud_configure_gridSize.x * vid_conwidth;
1058 hud_configure_realGridSize.y = hud_configure_gridSize.y * vid_conheight;
1061 s = vec2(1, vid_conheight);
1062 for(i = 1; i < 1/hud_configure_gridSize.x; ++i)
1063 drawfill(eX * i * hud_configure_realGridSize.x, s, '0.5 0.5 0.5', autocvar_hud_configure_grid_alpha, DRAWFLAG_NORMAL);
1065 s = vec2(vid_conwidth, 1);
1066 for(i = 1; i < 1/hud_configure_gridSize.y; ++i)
1067 drawfill(eY * i * hud_configure_realGridSize.y, s, '0.5 0.5 0.5', autocvar_hud_configure_grid_alpha, DRAWFLAG_NORMAL);
1071 float _menu_alpha_prev;
1072 void HUD_Configure_Frame()
1075 if(autocvar__hud_configure)
1077 if(isdemo() || intermission == 2 || scoreboard_active)
1079 HUD_Configure_Exit_Force();
1083 if(!hud_configure_prev)
1086 for(i = hud_panels_COUNT - 1; i >= 0; --i)
1087 hud_panels_from(panel_order[i]).update_time = time;
1090 // NOTE this check is necessary because _menu_alpha isn't updated the frame the menu gets enabled
1091 if(autocvar__menu_alpha != _menu_alpha_prev)
1093 if(autocvar__menu_alpha == 0)
1094 hud_configure_menu_open = 0;
1095 _menu_alpha_prev = autocvar__menu_alpha;
1098 HUD_Configure_DrawGrid();
1100 else if(hud_configure_prev)
1102 if(hud_configure_menu_open)
1103 hud_configure_menu_open = 0;
1104 hud_dynamic_shake_factor = -1;
1108 const float hlBorderSize = 2;
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 theAlpha)
1113 vector pos = panel_pos - vec2(myBorder, myBorder);
1114 drawfill(pos, panel_size + '2 2 0' * myBorder, '0 0.5 1', .5 * theAlpha, DRAWFLAG_NORMAL);
1115 drawpic_tiled(pos, hlBorder, '8 1 0' * hlBorderSize, vec2(panel_size.x + 2 * myBorder, hlBorderSize), color, theAlpha, DRAWFLAG_NORMAL);
1116 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);
1117 pos.y += hlBorderSize;
1118 drawpic_tiled(pos, hlBorder2, '1 8 0' * hlBorderSize, vec2(hlBorderSize, panel_size.y + 2 * myBorder - 2 * hlBorderSize), color, theAlpha, DRAWFLAG_NORMAL);
1119 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);
1122 void HUD_Configure_PostDraw()
1124 if(autocvar__hud_configure)
1129 HUD_Panel_UpdatePosSize();
1130 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .2, DRAWFLAG_NORMAL);
1132 if(highlightedPanel)
1134 panel = highlightedPanel;
1135 HUD_Panel_UpdatePosSize();
1136 HUD_Panel_HlBorder(panel_bg_border * hlBorderSize, '0 0.5 1', 0.4 * (1 - autocvar__menu_alpha));