From ad707696d5fdad86f90ea506cc5544a74c0da603 Mon Sep 17 00:00:00 2001 From: Juhu <5894800-Juhu_@users.noreply.gitlab.com> Date: Wed, 24 Jun 2020 20:22:40 +0200 Subject: [PATCH] strafehud: unify HUD_Panel_DrawStrafeHUD_* functions into one function and provide type as parameter --- _hud_common.cfg | 2 +- qcsrc/client/autocvars.qh | 2 +- qcsrc/client/hud/panel/strafehud.qc | 100 ++++++++-------------------- qcsrc/client/hud/panel/strafehud.qh | 3 +- 4 files changed, 32 insertions(+), 75 deletions(-) diff --git a/_hud_common.cfg b/_hud_common.cfg index 8d7195fc3..2848250aa 100644 --- a/_hud_common.cfg +++ b/_hud_common.cfg @@ -144,7 +144,7 @@ seta hud_panel_strafehud_direction_show "1" "show the direction indicator caps" seta hud_panel_strafehud_direction_color "0 0.5 1" "direction indicator color" seta hud_panel_strafehud_direction_width "0.25" "direction indicator width relative to the panel height" seta hud_panel_strafehud_direction_length "0.02" "direction indicator length relative to the panel width" -seta hud_panel_strafehud_unstyled "0" "don't apply any progressbar styles to the strafehud" +seta hud_panel_strafehud_style "1" "\"0\" = no styling, \"1\" = progress bar style for the strafe bar" seta hud_panel_strafehud_timeout_air "0.1" "time after take off before changing strafehud mode (prevents flickering on slick ramps)" seta hud_panel_strafehud_timeout_ground "0.03333333" "time after landing before changing strafehud mode (prevents flickering on regular strafe turns)" seta hud_panel_strafehud_timeout_strafe "0.1" "time after releasing the strafe keys before changing mode (prevents flickering when switching between left/right strafe turning)" diff --git a/qcsrc/client/autocvars.qh b/qcsrc/client/autocvars.qh index 8ee844744..42608b20b 100644 --- a/qcsrc/client/autocvars.qh +++ b/qcsrc/client/autocvars.qh @@ -342,7 +342,7 @@ bool autocvar_hud_panel_strafehud_direction_show = true; vector autocvar_hud_panel_strafehud_direction_color = '0 0.5 1'; float autocvar_hud_panel_strafehud_direction_width = 0.25; float autocvar_hud_panel_strafehud_direction_length = 0.02; -bool autocvar_hud_panel_strafehud_unstyled = false; +int autocvar_hud_panel_strafehud_style = 1; float autocvar_hud_panel_strafehud_timeout_air = 0.1; float autocvar_hud_panel_strafehud_timeout_ground = 0.03333333; float autocvar_hud_panel_strafehud_timeout_strafe = 0.1; diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index 6f8abeb3c..346c2919f 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -466,13 +466,15 @@ void HUD_StrafeHUD() // add a background to the strafe-o-meter if(panel_size.x > 0 && panel_size.y > 0) { - if(!autocvar_hud_panel_strafehud_unstyled) + switch(autocvar_hud_panel_strafehud_style) { - HUD_Panel_DrawProgressBar(panel_pos, panel_size, "progressbar", 1, 0, 0, autocvar_hud_panel_strafehud_bar_color, autocvar_hud_panel_strafehud_bar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); - } - else - { - drawfill(panel_pos, panel_size, autocvar_hud_panel_strafehud_bar_color, autocvar_hud_panel_strafehud_bar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + default: + case 0: + drawfill(panel_pos, panel_size, autocvar_hud_panel_strafehud_bar_color, autocvar_hud_panel_strafehud_bar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + break; + + case 1: + HUD_Panel_DrawProgressBar(panel_pos, panel_size, "progressbar", 1, 0, 0, autocvar_hud_panel_strafehud_bar_color, autocvar_hud_panel_strafehud_bar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); } } } @@ -536,34 +538,17 @@ void HUD_StrafeHUD() switch_odd_bestangle_offset -= currentangle_offset; } - if(!autocvar_hud_panel_strafehud_unstyled) - { - // draw acceleration zone - HUD_Panel_DrawStrafeHUD_ProgressBar(accelzone_offset, accelzone_width, autocvar_hud_panel_strafehud_indicator_color, autocvar_hud_panel_strafehud_bar_alpha); - - // draw odd acceleration zone - HUD_Panel_DrawStrafeHUD_ProgressBar(odd_accelzone_offset, odd_accelzone_width, autocvar_hud_panel_strafehud_indicator_color, autocvar_hud_panel_strafehud_bar_alpha); - - // draw overturn area - HUD_Panel_DrawStrafeHUD_ProgressBar(overturn_offset, overturn_width, autocvar_hud_panel_strafehud_alert_color, autocvar_hud_panel_strafehud_bar_alpha); - - // draw the strafe bar background - HUD_Panel_DrawStrafeHUD_ProgressBar(bar_offset, bar_width, autocvar_hud_panel_strafehud_bar_color, autocvar_hud_panel_strafehud_bar_alpha); - } - else - { - // draw acceleration zone - HUD_Panel_DrawStrafeHUD_drawfill(accelzone_offset, accelzone_width, autocvar_hud_panel_strafehud_indicator_color, autocvar_hud_panel_strafehud_bar_alpha); + // draw acceleration zone + HUD_Panel_DrawStrafeHUD(accelzone_offset, accelzone_width, autocvar_hud_panel_strafehud_indicator_color, autocvar_hud_panel_strafehud_bar_alpha, autocvar_hud_panel_strafehud_style); - // draw odd acceleration zone - HUD_Panel_DrawStrafeHUD_drawfill(odd_accelzone_offset, odd_accelzone_width, autocvar_hud_panel_strafehud_indicator_color, autocvar_hud_panel_strafehud_bar_alpha); + // draw odd acceleration zone + HUD_Panel_DrawStrafeHUD(odd_accelzone_offset, odd_accelzone_width, autocvar_hud_panel_strafehud_indicator_color, autocvar_hud_panel_strafehud_bar_alpha, autocvar_hud_panel_strafehud_style); - // draw overturn area - HUD_Panel_DrawStrafeHUD_drawfill(overturn_offset, overturn_width, autocvar_hud_panel_strafehud_alert_color, autocvar_hud_panel_strafehud_bar_alpha); + // draw overturn area + HUD_Panel_DrawStrafeHUD(overturn_offset, overturn_width, autocvar_hud_panel_strafehud_alert_color, autocvar_hud_panel_strafehud_bar_alpha, autocvar_hud_panel_strafehud_style); - // draw the strafe bar background - HUD_Panel_DrawStrafeHUD_drawfill(bar_offset, bar_width, autocvar_hud_panel_strafehud_bar_color, autocvar_hud_panel_strafehud_bar_alpha); - } + // draw the strafe bar background + HUD_Panel_DrawStrafeHUD(bar_offset, bar_width, autocvar_hud_panel_strafehud_bar_color, autocvar_hud_panel_strafehud_bar_alpha, autocvar_hud_panel_strafehud_style); if(autocvar_hud_panel_strafehud_direction_show && direction != 0) { @@ -591,8 +576,8 @@ void HUD_StrafeHUD() float switch_offset = !odd_angles ? switch_bestangle_offset : switch_odd_bestangle_offset; // both indicators are yellow if no direction can be determined indicator_color = direction != 0 ? autocvar_hud_panel_strafehud_indicator_color : autocvar_hud_panel_strafehud_indicator_switch_color; - HUD_Panel_DrawStrafeHUD_drawfill(switch_offset, bestangle_width, autocvar_hud_panel_strafehud_indicator_switch_color, 1); - HUD_Panel_DrawStrafeHUD_drawfill(offset, bestangle_width, indicator_color, 1); + HUD_Panel_DrawStrafeHUD(switch_offset, bestangle_width, autocvar_hud_panel_strafehud_indicator_switch_color, 1, 0); + HUD_Panel_DrawStrafeHUD(offset, bestangle_width, indicator_color, 1, 0); } } @@ -627,7 +612,7 @@ void HUD_StrafeHUD() } // functions to make hud elements align perfectly in the hud area -void HUD_Panel_DrawStrafeHUD_ProgressBar(float offset, float width, vector color, float alpha) +void HUD_Panel_DrawStrafeHUD(float offset, float width, vector color, float alpha, int type) { float mirror_offset, mirror_width; vector size = panel_size; @@ -661,44 +646,17 @@ void HUD_Panel_DrawStrafeHUD_ProgressBar(float offset, float width, vector color size.x = width; mirror_size.x = mirror_width; - if(mirror_size.x > 0 && mirror_size.y > 0) HUD_Panel_DrawProgressBar(panel_pos + eX * mirror_offset, mirror_size, "progressbar", 1, 0, 0, color, alpha * panel_fg_alpha, DRAWFLAG_NORMAL); - if(size.x > 0 && size.y > 0) HUD_Panel_DrawProgressBar(panel_pos + eX * offset, size, "progressbar", 1, 0, 0, color, alpha * panel_fg_alpha, DRAWFLAG_NORMAL); -} -void HUD_Panel_DrawStrafeHUD_drawfill(float offset, float width, vector color, float alpha) -{ - float mirror_offset, mirror_width; - vector size = panel_size; - vector mirror_size = panel_size; - - if(offset < 0) - { - mirror_width = min(fabs(offset), width); - mirror_offset = panel_size.x + hidden_width - fabs(offset); - width += offset; - offset = 0; - } - else - { - mirror_width = min(offset + width - panel_size.x - hidden_width, width); - mirror_offset = max(offset - panel_size.x - hidden_width, 0); - } - if((offset + width) > panel_size.x) - { - width = panel_size.x - offset; - } - if(mirror_offset < 0) + switch(type) { - mirror_width += mirror_offset; - mirror_offset = 0; + default: + case 0: + if(mirror_width > 0) drawfill(panel_pos + eX * mirror_offset, mirror_size, color, alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + if(width > 0) drawfill(panel_pos + eX * offset, size, color, alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + break; + + case 1: + if(mirror_size.x > 0 && mirror_size.y > 0) HUD_Panel_DrawProgressBar(panel_pos + eX * mirror_offset, mirror_size, "progressbar", 1, 0, 0, color, alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + if(size.x > 0 && size.y > 0) HUD_Panel_DrawProgressBar(panel_pos + eX * offset, size, "progressbar", 1, 0, 0, color, alpha * panel_fg_alpha, DRAWFLAG_NORMAL); } - if((mirror_offset + mirror_width) > panel_size.x) - { - mirror_width = panel_size.x - mirror_offset; - } - - size.x = width; - mirror_size.x = mirror_width; - if(mirror_width > 0) drawfill(panel_pos + eX * mirror_offset, mirror_size, color, alpha * panel_fg_alpha, DRAWFLAG_NORMAL); - if(width > 0) drawfill(panel_pos + eX * offset, size, color, alpha * panel_fg_alpha, DRAWFLAG_NORMAL); } diff --git a/qcsrc/client/hud/panel/strafehud.qh b/qcsrc/client/hud/panel/strafehud.qh index d50345309..2c27c5737 100644 --- a/qcsrc/client/hud/panel/strafehud.qh +++ b/qcsrc/client/hud/panel/strafehud.qh @@ -1,5 +1,4 @@ #pragma once #include "../panel.qh" -void HUD_Panel_DrawStrafeHUD_ProgressBar(float, float, vector, float); -void HUD_Panel_DrawStrafeHUD_drawfill(float, float, vector, float); +void HUD_Panel_DrawStrafeHUD(float, float, vector, float, int); -- 2.39.2