From 831302210ca74da4d319c33528aeb29fcc591049 Mon Sep 17 00:00:00 2001 From: Juhu <5894800-Juhu_@users.noreply.gitlab.com> Date: Thu, 6 Jul 2023 21:01:20 +0200 Subject: [PATCH] strafehud: add strafe efficiency indicator --- _hud_common.cfg | 2 ++ qcsrc/client/hud/panel/strafehud.qc | 20 +++++++++++++++++++- qcsrc/client/hud/panel/strafehud.qh | 2 ++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/_hud_common.cfg b/_hud_common.cfg index a3b4a5c20..953984a77 100644 --- a/_hud_common.cfg +++ b/_hud_common.cfg @@ -224,6 +224,8 @@ seta hud_panel_strafehud_sonar_pitch_exponent "1" "exponent of the dynamic playb 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_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_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" // hud panel aliases diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index 88a80976f..3bfcdd3dc 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -921,10 +921,10 @@ void HUD_StrafeHUD() } // draw the actual strafe angle + float strafe_ratio = 0; if(!immobile) { float moveangle = fabs(angle + wishangle); - float strafe_ratio = 0; // player is overturning if(moveangle >= 90) @@ -1136,6 +1136,24 @@ void HUD_StrafeHUD() } } + // strafe efficiency + { + 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) + text_offset_top += strafeeff_height; + } + } + // show height achieved by a single jump // FIXME: checking z position differences is unreliable (warpzones, teleporter, kill, etc) but using velocity to calculate jump height would be // inaccurate in hud code (possibly different tick rate than physics, doesn't run when hud isn't drawn, rounding errors) diff --git a/qcsrc/client/hud/panel/strafehud.qh b/qcsrc/client/hud/panel/strafehud.qh index 782831acd..861a566b7 100644 --- a/qcsrc/client/hud/panel/strafehud.qh +++ b/qcsrc/client/hud/panel/strafehud.qh @@ -73,6 +73,8 @@ 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'; float autocvar_hud_panel_strafehud_vangle_size = 1; +bool autocvar_hud_panel_strafehud_strafeefficiency = false; +float autocvar_hud_panel_strafehud_strafeefficiency_size = 1; int autocvar_hud_panel_strafehud_projection = 0; void HUD_Panel_DrawStrafeHUD(float, float, float, vector, float, int, int, bool, float); -- 2.39.2