From: Juhu <5894800-Juhu_@users.noreply.gitlab.com> Date: Wed, 25 Jan 2023 19:35:19 +0000 (+0100) Subject: Add patch from Juhu/strafehud-features branch: "strafehud: fix switch indicator posit... X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=9fe51ea9d221318bdd640763ac16ffaecdbc7742;p=xonotic%2Fxonotic-data.pk3dir.git Add patch from Juhu/strafehud-features branch: "strafehud: fix switch indicator positioning when using projection" --- diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index 177442247..06d34ad97 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -743,6 +743,9 @@ void HUD_StrafeHUD() float offset = !odd_angles ? bestangle_offset : odd_bestangle_offset; float switch_offset = !odd_angles ? switch_bestangle_offset : switch_odd_bestangle_offset; + offset = StrafeHUD_projectOffset(offset, hudangle); + switch_offset = StrafeHUD_projectOffset(switch_offset, hudangle); + // remove switch indicator width from offset if(direction == STRAFEHUD_DIRECTION_LEFT) { @@ -1091,7 +1094,7 @@ float StrafeHUD_projectWidth(float offset, float width, float range) { } // functions to make hud elements align perfectly in the hud area -void HUD_Panel_DrawStrafeHUD(float offset, float width, float hidden_width, vector color, float alpha, int type, int gradientType, bool projectWidth, float range) +void HUD_Panel_DrawStrafeHUD(float offset, float width, float hidden_width, vector color, float alpha, int type, int gradientType, bool doProject, float range) { float mirror_offset, mirror_width; vector size = panel_size; @@ -1126,8 +1129,10 @@ void HUD_Panel_DrawStrafeHUD(float offset, float width, float hidden_width, vect vector original_size = size; float original_offset = offset; - if(projectWidth && size.x > 0) size.x = StrafeHUD_projectWidth(offset, size.x, range); - offset = StrafeHUD_projectOffset(offset, range); + if(doProject) { + if(size.x > 0) size.x = StrafeHUD_projectWidth(offset, size.x, range); + offset = StrafeHUD_projectOffset(offset, range); + } if(mirror_offset < 0) { @@ -1145,8 +1150,10 @@ void HUD_Panel_DrawStrafeHUD(float offset, float width, float hidden_width, vect vector original_mirror_size = mirror_size; float original_mirror_offset = mirror_offset; - if(projectWidth && mirror_size.x > 0) mirror_size.x = StrafeHUD_projectWidth(mirror_offset, mirror_size.x, range); - mirror_offset = StrafeHUD_projectOffset(mirror_offset, range); + if(doProject) { + if(mirror_size.x > 0) mirror_size.x = StrafeHUD_projectWidth(mirror_offset, mirror_size.x, range); + mirror_offset = StrafeHUD_projectOffset(mirror_offset, range); + } switch(type) { @@ -1186,8 +1193,8 @@ void HUD_Panel_DrawStrafeHUD(float offset, float width, float hidden_width, vect gradient_mirror_offset = 0; } - StrafeHUD_drawGradient(color, autocvar_hud_panel_strafehud_bar_neutral_color, original_mirror_size, original_width, original_mirror_offset, alpha, gradient_mirror_offset, gradientType, range); - StrafeHUD_drawGradient(color, autocvar_hud_panel_strafehud_bar_neutral_color, original_size, original_width, original_offset, alpha, gradient_offset, gradientType, range); + StrafeHUD_drawGradient(color, autocvar_hud_panel_strafehud_bar_neutral_color, original_mirror_size, original_width, original_mirror_offset, alpha, gradient_mirror_offset, gradientType, doProject, range); + StrafeHUD_drawGradient(color, autocvar_hud_panel_strafehud_bar_neutral_color, original_size, original_width, original_offset, alpha, gradient_offset, gradientType, doProject, range); } } @@ -1202,7 +1209,7 @@ vector StrafeHUD_mixColors(vector color1, vector color2, float ratio) return mixedColor; } -void StrafeHUD_drawGradient(vector color1, vector color2, vector size, float original_width, float offset, float alpha, float gradientOffset, int gradientType, float range) +void StrafeHUD_drawGradient(vector color1, vector color2, vector size, float original_width, float offset, float alpha, float gradientOffset, int gradientType, bool doProject, float range) { float color_ratio, alpha1, alpha2; vector segment_size = size; @@ -1213,10 +1220,13 @@ void StrafeHUD_drawGradient(vector color1, vector color2, vector size, float ori for(int i = 0; i < size.x; ++i) { float ratio, alpha_ratio, combine_ratio1, combine_ratio2, segment_offset; - segment_offset = offset + i; segment_size.x = min(size.x - i, 1); // each gradient segment is 1 unit wide except if there is less than 1 unit of gradient remaining - segment_size.x = StrafeHUD_projectWidth(segment_offset, segment_size.x, range); - segment_offset = StrafeHUD_projectOffset(segment_offset, range); + segment_offset = offset + i; + if(doProject) + { + segment_size.x = StrafeHUD_projectWidth(segment_offset, segment_size.x, range); + segment_offset = StrafeHUD_projectOffset(segment_offset, range); + } ratio = (i + gradientOffset) / original_width * (gradientType == STRAFEHUD_GRADIENT_BOTH ? 2 : 1); if(ratio > 1) ratio = 2 - ratio; if(gradientType != STRAFEHUD_GRADIENT_RIGHT) ratio = 1 - ratio; diff --git a/qcsrc/client/hud/panel/strafehud.qh b/qcsrc/client/hud/panel/strafehud.qh index 50e335db1..4cbfbeddf 100644 --- a/qcsrc/client/hud/panel/strafehud.qh +++ b/qcsrc/client/hud/panel/strafehud.qh @@ -78,7 +78,7 @@ AUTOCVAR_SAVE(hud_panel_strafehud_projection, int, 0, "strafehud projection mode void HUD_Panel_DrawStrafeHUD(float, float, float, vector, float, int, int, bool, float); vector StrafeHUD_mixColors(vector, vector, float); -void StrafeHUD_drawGradient(vector, vector, vector, float, float, float, float, int, float); +void StrafeHUD_drawGradient(vector, vector, vector, float, float, float, float, int, bool, float); float GetLengthUnitFactor(int); string GetLengthUnit(int); void StrafeHUD_drawStrafeArrow(vector, float, vector, float, bool);