From: Juhu <5894800-Juhu_@users.noreply.gitlab.com> Date: Fri, 4 Oct 2024 17:00:22 +0000 (+0200) Subject: strafehud: free text positioning system, supersedes the old system X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=f099ec106e7c85ef49697ed3b995b401e0659dfa;p=xonotic%2Fxonotic-data.pk3dir.git strafehud: free text positioning system, supersedes the old system --- diff --git a/_hud_common.cfg b/_hud_common.cfg index 6c5050c07..35b53e928 100644 --- a/_hud_common.cfg +++ b/_hud_common.cfg @@ -219,11 +219,13 @@ seta hud_panel_strafehud_slickdetector_height "0.125" "height of the slick detec seta hud_panel_strafehud_startspeed "1" "set to 1 to enable the start speed indicator which shows you the speed you had while passing the start trigger of a race map" seta hud_panel_strafehud_startspeed_fade "4" "fade time (in seconds) of the start speed text" seta hud_panel_strafehud_startspeed_color "1 0.75 0" "color of the start speed text" +seta hud_panel_strafehud_startspeed_pos "0 -1 0" "position of the start speed text (relative to the panel), the Y coordinate must be <= -1 (below) or >= 1 (above) the panel" seta hud_panel_strafehud_startspeed_size "1.5" "size of the start speed text (relative to the panel height)" seta hud_panel_strafehud_jumpheight "0" "set to 1 to enable the jump height indicator which tells you how high you jumped" seta hud_panel_strafehud_jumpheight_fade "4" "fade time (in seconds) of the jump height text" seta hud_panel_strafehud_jumpheight_min "50" "minimum jump height to display in the selected unit" seta hud_panel_strafehud_jumpheight_color "0 1 0.75" "color of the jump height text" +seta hud_panel_strafehud_jumpheight_pos "0 -2 0" "position of the jump height text (relative to the panel), the Y coordinate must be <= -1 (below) or >= 1 (above) the panel" seta hud_panel_strafehud_jumpheight_size "1.5" "size of the jump height text (relative to the panel height)" seta hud_panel_strafehud_timeout_ground "0.1" "time (in seconds) after take off before changing to air strafe physics when not jumping (visually more consistent hud while on slick downwards ramps)" seta hud_panel_strafehud_timeout_turn "0.1" "time (in seconds) after releasing the strafe keys before changing mode (visually more consistent hud while switching between left/right strafe turning)" @@ -243,8 +245,10 @@ seta hud_panel_strafehud_sonar_pitch_range "0.1" "dynamic playback speed range o seta hud_panel_strafehud_sonar_pitch_exponent "1" "exponent of the dynamic playback speed range of the strafe sonar" seta hud_panel_strafehud_vangle "0" "set to 1 to enable the vertical angle indicator" seta hud_panel_strafehud_vangle_color "0.75 0.75 0.75" "color of the vertical angle text" +seta hud_panel_strafehud_vangle_pos "-0.25 1 0" "position of the vertical angle text (relative to the panel), the Y coordinate must be <= -1 (below) or >= 1 (above) the panel" seta hud_panel_strafehud_vangle_size "1" "size of the vertical angle text (relative to the panel height)" seta hud_panel_strafehud_strafeefficiency "0" "set to 1 to enable the strafe efficiency indicator" +seta hud_panel_strafehud_strafeefficiency_pos "0.25 1 0" "size of the strafe efficiency text (relative to the panel), the Y coordinate must be <= -1 (below) or >= 1 (above) the panel" seta hud_panel_strafehud_strafeefficiency_size "1" "size of the strafe efficiency text (relative to the panel height)" seta hud_panel_strafehud_projection "0" "strafehud projection mode, 0 = linear, 1 = perspective, 2 = panoramic" diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index 912686fd4..6159f022b 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -719,12 +719,12 @@ void HUD_StrafeHUD() } } - text_offset_bottom += StrafeHUD_DrawVerticalAngle(strafeplayer, text_offset_bottom); + StrafeHUD_DrawVerticalAngle(strafeplayer, text_offset_top, text_offset_bottom); draw_beginBoldFont(); - text_offset_bottom += StrafeHUD_DrawStartSpeed(speed, text_offset_bottom); - text_offset_top += StrafeHUD_DrawStrafeEfficiency(strafe_ratio, text_offset_top); - text_offset_top += StrafeHUD_DrawJumpHeight(strafeplayer, real_onground, swimming, text_offset_top); + StrafeHUD_DrawStartSpeed(speed, text_offset_top, text_offset_bottom); + StrafeHUD_DrawStrafeEfficiency(strafe_ratio, text_offset_top, text_offset_bottom); + StrafeHUD_DrawJumpHeight(strafeplayer, real_onground, swimming, text_offset_top, text_offset_bottom); draw_endBoldFont(); StrafeHUD_Sonar(strafe_ratio, StrafeHUD_UpdateSonarSound()); diff --git a/qcsrc/client/hud/panel/strafehud.qh b/qcsrc/client/hud/panel/strafehud.qh index 041d69c12..eefb6b66f 100644 --- a/qcsrc/client/hud/panel/strafehud.qh +++ b/qcsrc/client/hud/panel/strafehud.qh @@ -61,11 +61,13 @@ float autocvar_hud_panel_strafehud_slickdetector_height = 0.125; bool autocvar_hud_panel_strafehud_startspeed = true; float autocvar_hud_panel_strafehud_startspeed_fade = 4; vector autocvar_hud_panel_strafehud_startspeed_color = '1 0.75 0'; +vector autocvar_hud_panel_strafehud_startspeed_pos = '0 -1 0'; float autocvar_hud_panel_strafehud_startspeed_size = 1.5; bool autocvar_hud_panel_strafehud_jumpheight = false; float autocvar_hud_panel_strafehud_jumpheight_fade = 4; float autocvar_hud_panel_strafehud_jumpheight_min = 50; vector autocvar_hud_panel_strafehud_jumpheight_color = '0 1 0.75'; +vector autocvar_hud_panel_strafehud_jumpheight_pos = '0 -2 0'; float autocvar_hud_panel_strafehud_jumpheight_size = 1.5; float autocvar_hud_panel_strafehud_timeout_ground = 0.1; float autocvar_hud_panel_strafehud_timeout_turn = 0.1; @@ -85,8 +87,10 @@ float autocvar_hud_panel_strafehud_sonar_pitch_range = 0.1; float autocvar_hud_panel_strafehud_sonar_pitch_exponent = 1; bool autocvar_hud_panel_strafehud_vangle = false; vector autocvar_hud_panel_strafehud_vangle_color = '0.75 0.75 0.75'; +vector autocvar_hud_panel_strafehud_vangle_pos = '-0.25 1 0'; float autocvar_hud_panel_strafehud_vangle_size = 1; bool autocvar_hud_panel_strafehud_strafeefficiency = false; +vector autocvar_hud_panel_strafehud_strafeefficiency_pos = '0.25 1 0'; float autocvar_hud_panel_strafehud_strafeefficiency_size = 1; int autocvar_hud_panel_strafehud_projection = 0; @@ -129,9 +133,6 @@ const int STRAFEHUD_INDICATOR_NONE = 0; const int STRAFEHUD_INDICATOR_SOLID = 1; const int STRAFEHUD_INDICATOR_DASHED = 2; -const int STRAFEHUD_TEXT_TOP = 0; -const int STRAFEHUD_TEXT_BOTTOM = 1; - const int STRAFEHUD_PROJECTION_LINEAR = 0; const int STRAFEHUD_PROJECTION_PERSPECTIVE = 1; const int STRAFEHUD_PROJECTION_PANORAMIC = 2; diff --git a/qcsrc/client/hud/panel/strafehud/draw.qc b/qcsrc/client/hud/panel/strafehud/draw.qc index 526677cd7..b0ab58f02 100644 --- a/qcsrc/client/hud/panel/strafehud/draw.qc +++ b/qcsrc/client/hud/panel/strafehud/draw.qc @@ -273,26 +273,39 @@ void StrafeHUD_DrawStrafeArrow(vector origin, float size, vector color, float al } // draw a fading text indicator above or below the strafe meter, return true if something was displayed -bool StrafeHUD_DrawTextIndicator(string text, float height, vector color, float fadetime, float lasttime, float offset, int position) +void StrafeHUD_DrawTextIndicator(string text, float height, vector color, float fadetime, float lasttime, vector pos, float offset_top, float offset_bottom) { if((height <= 0) || (lasttime <= 0) || (fadetime <= 0) || ((time - lasttime) >= fadetime)) - return false; + return; float alpha = cos(((time - lasttime) / fadetime) * M_PI_2); // fade non-linear like the physics panel does vector size = panel_size; size.y = height; - switch(position) + if(pos.y >= 1) { - case STRAFEHUD_TEXT_TOP: - offset += size.y; - offset *= -1; - break; - case STRAFEHUD_TEXT_BOTTOM: - offset += panel_size.y; - break; + pos.y--; // for calculations the position should not start at +1 + pos = StrafeHUD_CalculateTextIndicatorPosition(pos); + pos.y += size.y + offset_top; + pos.y *= -1; // it's more intuitive for up to be positive + } + else if(pos.y <= -1) + { + pos.y++; // for calculations the position should not start at -1 + pos = StrafeHUD_CalculateTextIndicatorPosition(pos); + pos.y *= -1; // it's more intuitive for down to be negative + pos.y += panel_size.y + offset_bottom; } + else return; + + drawstring_aspect(panel_pos + pos, text, size, color, alpha * panel_fg_alpha, DRAWFLAG_NORMAL); +} + +vector StrafeHUD_CalculateTextIndicatorPosition(vector pos) +{ + pos.x *= panel_size.x / 2; // more intuitive since we start in the middle, this turns the range from -0.5 to +0.5 into -1 to +1 + pos.y *= panel_size.y; + pos.z = 0; - drawstring_aspect(panel_pos + eY * offset, text, size, color, alpha * panel_fg_alpha, DRAWFLAG_NORMAL); - return true; + return pos; } diff --git a/qcsrc/client/hud/panel/strafehud/draw.qh b/qcsrc/client/hud/panel/strafehud/draw.qh index b3ec1a26e..b3d140fcf 100644 --- a/qcsrc/client/hud/panel/strafehud/draw.qh +++ b/qcsrc/client/hud/panel/strafehud/draw.qh @@ -5,4 +5,5 @@ void StrafeHUD_DrawStrafeHUD(float, float, vector, float, int, int, bool, float) void StrafeHUD_DrawGradient(vector, vector, vector, float, float, float, float, float, int, float); void StrafeHUD_DrawGradientFast(vector, vector, vector, float, float, float, float, int); void StrafeHUD_DrawStrafeArrow(vector, float, vector, float, bool, float); -bool StrafeHUD_DrawTextIndicator(string, float, vector, float, float, float, int); +void StrafeHUD_DrawTextIndicator(string, float, vector, float, float, vector, float, float); +vector StrafeHUD_CalculateTextIndicatorPosition(vector); diff --git a/qcsrc/client/hud/panel/strafehud/extra.qc b/qcsrc/client/hud/panel/strafehud/extra.qc index 99283ed6b..03d285ba2 100644 --- a/qcsrc/client/hud/panel/strafehud/extra.qc +++ b/qcsrc/client/hud/panel/strafehud/extra.qc @@ -103,7 +103,7 @@ float StrafeHUD_DrawSlickDetector(entity e, bool onslick) } // vertical angle for weapon jumps -float StrafeHUD_DrawVerticalAngle(entity e, float text_offset_bottom) +void StrafeHUD_DrawVerticalAngle(entity e, float text_offset_top, float text_offset_bottom) { if(autocvar_hud_panel_strafehud_vangle) { @@ -111,16 +111,12 @@ float StrafeHUD_DrawVerticalAngle(entity e, float text_offset_bottom) float vangle_height = autocvar_hud_panel_strafehud_vangle_size * panel_size.y; string vangle_text = strcat(ftos_decimals(vangle, 2), "°"); - bool was_drawn = StrafeHUD_DrawTextIndicator( + StrafeHUD_DrawTextIndicator( vangle_text, vangle_height, autocvar_hud_panel_strafehud_vangle_color, 1, - time, text_offset_bottom, STRAFEHUD_TEXT_BOTTOM); - - if(was_drawn) - return vangle_height; + time, autocvar_hud_panel_strafehud_vangle_pos, + text_offset_top, text_offset_bottom); } - - return 0; } // strafe sonar for audible feedback when strafing @@ -185,7 +181,7 @@ string StrafeHUD_UpdateSonarSound() // show height achieved by a single jump // FIXME: checking z position differences is unreliable (warpzones, teleporter, kill, etc), use velocity to calculate jump height instead // FIXME: move capturing the jump height value out of the HUD -float StrafeHUD_DrawJumpHeight(entity e, bool onground, bool swimming, float text_offset_top) +void StrafeHUD_DrawJumpHeight(entity e, bool onground, bool swimming, float text_offset_top, float text_offset_bottom) { float length_conversion_factor = StrafeHUD_GetLengthUnitFactor(autocvar_hud_speed_unit); static float height_min = 0, height_max = 0; // ground and peak of jump z coordinates @@ -218,46 +214,36 @@ float StrafeHUD_DrawJumpHeight(entity e, bool onground, bool swimming, float tex if(autocvar_hud_panel_strafehud_unit_show) jumpheight_text = strcat(jumpheight_text, StrafeHUD_GetLengthUnit(autocvar_hud_speed_unit)); - bool was_drawn = StrafeHUD_DrawTextIndicator( + StrafeHUD_DrawTextIndicator( jumpheight_text, jumpheight_height, autocvar_hud_panel_strafehud_jumpheight_color, autocvar_hud_panel_strafehud_jumpheight_fade, - jumptime, text_offset_top, STRAFEHUD_TEXT_TOP); - - if(was_drawn) - return jumpheight_height; + jumptime, autocvar_hud_panel_strafehud_jumpheight_pos, + text_offset_top, text_offset_bottom); } - - return 0; } // strafe efficiency, percentage of how far away the current angle is from the optimal angle // the percentage changes linearly with angular distance -float StrafeHUD_DrawStrafeEfficiency(float strafe_ratio, float text_offset_top) +void StrafeHUD_DrawStrafeEfficiency(float strafe_ratio, float text_offset_top, float text_offset_bottom) { + if(autocvar_hud_panel_strafehud_strafeefficiency) { - if(autocvar_hud_panel_strafehud_strafeefficiency) - { - float strafeeff_height = autocvar_hud_panel_strafehud_strafeefficiency_size * panel_size.y; - string strafeeff_text = strcat(ftos_decimals(strafe_ratio * 100, 2), "%"); - vector strafeeff_color = '1 1 1' - (strafe_ratio > 0 ? '1 0 1' : '0 1 1') * fabs(strafe_ratio); - - bool was_drawn = StrafeHUD_DrawTextIndicator( - strafeeff_text, strafeeff_height, - strafeeff_color, 1, - time, text_offset_top, STRAFEHUD_TEXT_TOP); - - if(was_drawn) - return strafeeff_height; - } + float strafeeff_height = autocvar_hud_panel_strafehud_strafeefficiency_size * panel_size.y; + string strafeeff_text = strcat(ftos_decimals(strafe_ratio * 100, 2), "%"); + vector strafeeff_color = '1 1 1' - (strafe_ratio > 0 ? '1 0 1' : '0 1 1') * fabs(strafe_ratio); + + StrafeHUD_DrawTextIndicator( + strafeeff_text, strafeeff_height, + strafeeff_color, 1, + time, autocvar_hud_panel_strafehud_strafeefficiency_pos, + text_offset_top, text_offset_bottom); } - - return 0; } // show speed when crossing the start trigger // FIXME: move capturing the race start speed value out of the HUD -float StrafeHUD_DrawStartSpeed(float speed, float text_offset_bottom) +void StrafeHUD_DrawStartSpeed(float speed, float text_offset_top, float text_offset_bottom) { static float startspeed = 0, starttime = 0; // displayed value and timestamp for fade out @@ -279,15 +265,11 @@ float StrafeHUD_DrawStartSpeed(float speed, float text_offset_bottom) if(autocvar_hud_panel_strafehud_unit_show) startspeed_text = strcat(startspeed_text, GetSpeedUnit(autocvar_hud_speed_unit)); - bool was_drawn = StrafeHUD_DrawTextIndicator( + StrafeHUD_DrawTextIndicator( startspeed_text, startspeed_height, autocvar_hud_panel_strafehud_startspeed_color, autocvar_hud_panel_strafehud_startspeed_fade, - starttime, text_offset_bottom, STRAFEHUD_TEXT_BOTTOM); - - if(was_drawn) - return startspeed_height; + starttime, autocvar_hud_panel_strafehud_startspeed_pos, + text_offset_top, text_offset_bottom); } - - return 0; } diff --git a/qcsrc/client/hud/panel/strafehud/extra.qh b/qcsrc/client/hud/panel/strafehud/extra.qh index 079ad31a5..be6e81753 100644 --- a/qcsrc/client/hud/panel/strafehud/extra.qh +++ b/qcsrc/client/hud/panel/strafehud/extra.qh @@ -2,9 +2,9 @@ #include "../strafehud.qh" float StrafeHUD_DrawSlickDetector(entity, bool); -float StrafeHUD_DrawVerticalAngle(entity, float); +void StrafeHUD_DrawVerticalAngle(entity, float, float); void StrafeHUD_Sonar(float, string); string StrafeHUD_UpdateSonarSound(); -float StrafeHUD_DrawJumpHeight(entity, bool, bool, float); -float StrafeHUD_DrawStrafeEfficiency(float, float); -float StrafeHUD_DrawStartSpeed(float, float); +void StrafeHUD_DrawJumpHeight(entity, bool, bool, float, float); +void StrafeHUD_DrawStrafeEfficiency(float, float, float); +void StrafeHUD_DrawStartSpeed(float, float, float);