]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge branch 'terencehill/hud_editor_centerline' into 'master'
authorterencehill <piuntn@gmail.com>
Tue, 2 May 2023 17:02:48 +0000 (17:02 +0000)
committerterencehill <piuntn@gmail.com>
Tue, 2 May 2023 17:02:48 +0000 (17:02 +0000)
Hud editor center line

See merge request xonotic/xonotic-data.pk3dir!1157

_hud_common.cfg
qcsrc/client/hud/hud_config.qc
qcsrc/client/hud/hud_config.qh
qcsrc/menu/xonotic/dialog_hudsetup_exit.qc

index 0028a732265d8f9dfec02bf3b604ed8a38a88a27..5f03a479038da70ac91d1bba2db29a0683d22d0c 100644 (file)
@@ -4,6 +4,7 @@ seta hud_configure_teamcolorforced 0 "1 = force display of team colors in config
 seta hud_configure_checkcollisions 0 "check for collisions against other panels when in hud configure mode"
 seta hud_configure_bg_minalpha 0.25 "minimum panel background alpha when in hud configure mode"
 seta hud_configure_grid_alpha 0.15 "alpha for visible grid when in configure mode"
+seta hud_configure_vertical_lines 0.5 "list of space-separated intervals at which to draw a vertical line, useful for aligning panels; e.g. 0.5 draws a vertical line in the center, \"0.25 0.5 0.75\" draws a vertical line every quarter of the screen width"
 
 seta hud_cursormode 1 "handle mouse input in cursor mode when CSQC displays a cursor"
 
index 78ed8442adecd81d685aaba6d2a183f6c47464bf..726b2e78d9565097699d67bcb5a46018d8194d33 100644 (file)
@@ -496,6 +496,7 @@ void HUD_Panel_Arrow_Action(float nPrimary)
                panel_pos_backup = highlightedPanel_initial_pos;
                panel_size_backup = highlightedPanel_initial_size;
                highlightedPanel_backup = highlightedPanel;
+               hud_configure_centerline_time = time + 1;
        }
 }
 
@@ -944,6 +945,7 @@ void HUD_Panel_EnableMenu()
        hud_configure_menu_open = 2;
        localcmd("menu_showhudoptions ", highlightedPanel.panel_name, "\n");
 }
+
 void HUD_Panel_Mouse()
 {
        if(autocvar__menu_alpha == 1)
@@ -1004,6 +1006,9 @@ void HUD_Panel_Mouse()
                                // moving it, avoid the immediate "fix" of its position/size
                                // (often unwanted and hateful) by disabling collisions check
                                hud_configure_checkcollisions = false;
+
+                       if (time - prevMouseClickedTime > 0.25) // avoid showing the center line immediately on mouse click
+                               hud_configure_centerline_time = time + 0.5;
                }
 
                if(highlightedAction == 1)
@@ -1041,7 +1046,7 @@ void HUD_Panel_Mouse()
 }
 void HUD_Configure_DrawGrid()
 {
-       float i;
+       int i;
        if(autocvar_hud_configure_grid && autocvar_hud_configure_grid_alpha)
        {
                hud_configure_gridSize.x = bound(0.005, cvar("hud_configure_grid_xsize"), 0.2);
@@ -1049,6 +1054,14 @@ void HUD_Configure_DrawGrid()
                hud_configure_realGridSize.x = hud_configure_gridSize.x * vid_conwidth;
                hud_configure_realGridSize.y = hud_configure_gridSize.y * vid_conheight;
                vector s;
+               // vertical center line, wider than vertical grid lines so that it's more visible
+               // NOTE: depending on grid size the vertical center line may not overlap any vertical grid line
+               int n = tokenize(autocvar_hud_configure_vertical_lines);
+               for (i = 0; i < n; ++i)
+               {
+                       float xpos_rel = stof(argv(i));
+                       drawfill(eX * (xpos_rel * vid_conwidth - 1), vec2(3, vid_conheight), '0.5 0.5 0.5', autocvar_hud_configure_grid_alpha, DRAWFLAG_NORMAL);
+               }
                // x-axis
                s = vec2(1, vid_conheight);
                for(i = 1; i < 1/hud_configure_gridSize.x; ++i)
@@ -1111,6 +1124,30 @@ void HUD_Panel_HlBorder(float myBorder, vector color, float theAlpha)
        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);
 }
 
+void HUD_Panel_HlCenterLine(float myBorder)
+{
+       if (time > hud_configure_centerline_time)
+               return;
+       float panel_centerpos_x = (panel_pos.x + panel_size.x * 0.5);
+       int n = tokenize(autocvar_hud_configure_vertical_lines);
+       for (int i = 0; i < n; ++i)
+       {
+               float xpos_rel = stof(argv(i));
+               if (xpos_rel <= 0 || xpos_rel >= 1)
+                       continue;
+               float ofs = fabs(panel_centerpos_x / vid_conwidth - xpos_rel);
+               if (ofs < 0.02) // don't bother showing the center line if it's evident that the panel is not centered
+               {
+                       float f = map_bound_ranges(ofs, 0.001, 0.01, 0, 1);
+                       vector col = '1 0 0' * f + '0 1 0' * (1 - f); // from red (far) to green (close)
+                       float theAlpha = 0.3 + 0.1 * sin(6 * time); // blink
+                       theAlpha *= (1 - autocvar__menu_alpha) * bound(0, hud_configure_centerline_time - time, 0.5) * 2; // fade
+                       vector pos = vec2(panel_centerpos_x - 1, panel_pos.y - myBorder);
+                       drawfill(pos, vec2(3, panel_size.y + 2 * myBorder), col, theAlpha, DRAWFLAG_NORMAL);
+               }
+       }
+}
+
 void HUD_Configure_PostDraw()
 {
        if(autocvar__hud_configure)
@@ -1126,6 +1163,7 @@ void HUD_Configure_PostDraw()
                        panel = highlightedPanel;
                        HUD_Panel_UpdatePosSize();
                        HUD_Panel_HlBorder(panel_bg_border * hlBorderSize, '0 0.5 1', 0.4 * (1 - autocvar__menu_alpha));
+                       HUD_Panel_HlCenterLine(panel_bg_border * hlBorderSize);
                }
        }
 }
index aa4c734b41fa691d2715ec657d28195e81653417..81182c65af6a50c5a52df26e042d5f593abd6f8e 100644 (file)
@@ -4,6 +4,7 @@ bool autocvar__hud_configure;
 bool autocvar_hud_configure_checkcollisions;
 bool autocvar_hud_configure_grid;
 float autocvar_hud_configure_grid_alpha;
+string autocvar_hud_configure_vertical_lines = "0.5";
 bool autocvar_hud_configure_teamcolorforced;
 
 const int S_MOUSE1 = 1;
@@ -19,6 +20,7 @@ float hud_configure_checkcollisions;
 vector hud_configure_gridSize;
 vector hud_configure_realGridSize;
 float hud_configure_menu_open; // 1 showing the entire HUD, 2 showing only the clicked panel
+float hud_configure_centerline_time;
 
 void HUD_Panel_ExportCfg(string cfgname);
 
index cf65049ea580713aaad277ae9c4a41325ea269ee..6cfcef251ca9afa6afed9ef541c6776650ea05b8 100644 (file)
@@ -118,10 +118,8 @@ void XonoticHUDExitDialog_fill(entity me)
                                        e.addValue(e, strzone(ftos_decimals(i/10, 1)), strzone(ftos(i/10)));
                                e.configureXonoticTextSliderValues(e);
        me.TR(me);
-               me.TD(me, 1, 4, makeXonoticTextLabel(0, _("Grid settings:")));
-       me.TR(me);
-               me.TDempty(me, 0.2);
-               me.TD(me, 1, 3.8, e = makeXonoticCheckBox(0, "hud_configure_grid", _("Snap panels to grid")));
+               me.TD(me, 1, 1.4, makeXonoticTextLabel(0, _("Grid settings:")));
+               me.TD(me, 1, 2.6, e = makeXonoticCheckBox(0, "hud_configure_grid", _("Snap panels to grid")));
        me.TR(me);
                me.TDempty(me, 0.2);
                me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Grid size:")));
@@ -140,6 +138,11 @@ void XonoticHUDExitDialog_fill(entity me)
                                        e.addValue(e, strzone(sprintf("%.1f%%", i/2)), strzone(ftos(i/200)));
                                e.configureXonoticTextSliderValues(e);
                                setDependent(e, "hud_configure_grid", 1, 1);
+       me.TR(me);
+               me.TDempty(me, 0.2);
+               string vertical_lines_cvarname = "hud_configure_vertical_lines";
+               me.TD(me, 1, 3.6, e = makeXonoticCheckBoxEx_T(0.5, 0, vertical_lines_cvarname, _("Center line"),
+                       sprintf(_("Show a vertical centerline to help align panels. It's possible to show more vertical lines by editing %s in the console"), vertical_lines_cvarname)));
 
        me.gotoRC(me, me.rows - 1, 0);
                me.TD(me, 1, me.columns, e = makeXonoticCommandButton(_("Exit setup"), '0 0 0', "_hud_configure 0", COMMANDBUTTON_CLOSE));