From 11bcda704591426d175d7520691ab9fd1bd1d40d Mon Sep 17 00:00:00 2001 From: terencehill Date: Sun, 12 May 2013 20:44:44 +0200 Subject: [PATCH] Remove HUD_Panel_GetProgressBarColor and HUD_Panel_GetProgressBarColorForString macros, making use of autocvar_hud_progressbar* autocvars code is simpler and more optimized --- qcsrc/client/autocvars.qh | 10 ++++++ qcsrc/client/hud.qc | 71 +++++++++++---------------------------- qcsrc/client/hud.qh | 17 ---------- 3 files changed, 30 insertions(+), 68 deletions(-) diff --git a/qcsrc/client/autocvars.qh b/qcsrc/client/autocvars.qh index c13e2bf6e..a3814a0b5 100644 --- a/qcsrc/client/autocvars.qh +++ b/qcsrc/client/autocvars.qh @@ -334,7 +334,17 @@ float autocvar_hud_panel_weapons_timeout_fadebgmin; float autocvar_hud_panel_weapons_timeout_fadefgmin; var float autocvar_hud_panel_weapons_timeout_speed_in = 0.25; var float autocvar_hud_panel_weapons_timeout_speed_out = 0.75; +vector autocvar_hud_progressbar_acceleration_color; +vector autocvar_hud_progressbar_acceleration_neg_color; float autocvar_hud_progressbar_alpha; +vector autocvar_hud_progressbar_armor_color; +vector autocvar_hud_progressbar_fuel_color; +vector autocvar_hud_progressbar_health_color; +vector autocvar_hud_progressbar_nexball_color; +vector autocvar_hud_progressbar_shield_color; +vector autocvar_hud_progressbar_speed_color; +vector autocvar_hud_progressbar_strength_color; +vector autocvar_hud_progressbar_superweapons_color; float autocvar_hud_showbinds; float autocvar_hud_showbinds_limit; float autocvar__hud_showbinds_reload; diff --git a/qcsrc/client/hud.qc b/qcsrc/client/hud.qc index 201fe8551..4626bd968 100644 --- a/qcsrc/client/hud.qc +++ b/qcsrc/client/hud.qc @@ -1278,10 +1278,7 @@ void HUD_Powerups(void) const float maxshield = 30; float shield = ceil(shield_time); if(autocvar_hud_panel_powerups_progressbar) - { - HUD_Panel_GetProgressBarColor(shield); - HUD_Panel_DrawProgressBar(pos + shield_offset, mySize, autocvar_hud_panel_powerups_progressbar_shield, shield/maxshield, is_vertical, shield_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); - } + HUD_Panel_DrawProgressBar(pos + shield_offset, mySize, autocvar_hud_panel_powerups_progressbar_shield, shield/maxshield, is_vertical, shield_baralign, autocvar_hud_progressbar_shield_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); if(autocvar_hud_panel_powerups_text) { if(shield > 1) @@ -1296,10 +1293,7 @@ void HUD_Powerups(void) const float maxstrength = 30; float strength = ceil(strength_time); if(autocvar_hud_panel_powerups_progressbar) - { - HUD_Panel_GetProgressBarColor(strength); - HUD_Panel_DrawProgressBar(pos + strength_offset, mySize, autocvar_hud_panel_powerups_progressbar_strength, strength/maxstrength, is_vertical, strength_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); - } + HUD_Panel_DrawProgressBar(pos + strength_offset, mySize, autocvar_hud_panel_powerups_progressbar_strength, strength/maxstrength, is_vertical, strength_baralign, autocvar_hud_progressbar_strength_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); if(autocvar_hud_panel_powerups_text) { if(strength > 1) @@ -1314,10 +1308,7 @@ void HUD_Powerups(void) const float maxsuperweapons = 30; float superweapons = ceil(superweapons_time); if(autocvar_hud_panel_powerups_progressbar) - { - HUD_Panel_GetProgressBarColor(superweapons); - HUD_Panel_DrawProgressBar(pos + superweapons_offset, mySize, autocvar_hud_panel_powerups_progressbar_superweapons, superweapons/maxsuperweapons, is_vertical, superweapons_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); - } + HUD_Panel_DrawProgressBar(pos + superweapons_offset, mySize, autocvar_hud_panel_powerups_progressbar_superweapons, superweapons/maxsuperweapons, is_vertical, superweapons_baralign, autocvar_hud_progressbar_superweapons_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); if(autocvar_hud_panel_powerups_text) { if(superweapons > 1) @@ -1428,10 +1419,7 @@ void HUD_HealthArmor(void) { biggercount = "health"; if(autocvar_hud_panel_healtharmor_progressbar) - { - HUD_Panel_GetProgressBarColor(health); - HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_health, x/maxtotal, 0, (baralign == 1 || baralign == 2), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); - } + HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_health, x/maxtotal, 0, (baralign == 1 || baralign == 2), autocvar_hud_progressbar_health_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); if(armor) if(autocvar_hud_panel_healtharmor_text) drawpic_aspect_skin(pos + eX * mySize_x - eX * 0.5 * mySize_y, "armor", '0.5 0.5 0' * mySize_y, '1 1 1', panel_fg_alpha * armor / health, DRAWFLAG_NORMAL); @@ -1440,10 +1428,7 @@ void HUD_HealthArmor(void) { biggercount = "armor"; if(autocvar_hud_panel_healtharmor_progressbar) - { - HUD_Panel_GetProgressBarColor(armor); - HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, x/maxtotal, 0, (baralign == 1 || baralign == 2), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); - } + HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, x/maxtotal, 0, (baralign == 1 || baralign == 2), autocvar_hud_progressbar_armor_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); if(health) if(autocvar_hud_panel_healtharmor_text) drawpic_aspect_skin(pos + eX * mySize_x - eX * 0.5 * mySize_y, "health", '0.5 0.5 0' * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); @@ -1452,10 +1437,7 @@ void HUD_HealthArmor(void) DrawNumIcon(pos, mySize, x, biggercount, 0, iconalign, HUD_Get_Num_Color(x, maxtotal), 1); if(fuel) - { - HUD_Panel_GetProgressBarColor(fuel); - HUD_Panel_DrawProgressBar(pos, eX * mySize_x + eY * 0.2 * mySize_y, "progressbar", fuel/100, 0, (baralign == 1 || baralign == 3), progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL); - } + HUD_Panel_DrawProgressBar(pos, eX * mySize_x + eY * 0.2 * mySize_y, "progressbar", fuel/100, 0, (baralign == 1 || baralign == 3), autocvar_hud_progressbar_fuel_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL); } else { @@ -1502,7 +1484,6 @@ void HUD_HealthArmor(void) { if(autocvar_hud_panel_healtharmor_progressbar) { - HUD_Panel_GetProgressBarColor(health); float p_health, pain_health_alpha; p_health = health; pain_health_alpha = 1; @@ -1535,7 +1516,7 @@ void HUD_HealthArmor(void) if (time - health_damagetime < 1) { float health_damagealpha = 1 - (time - health_damagetime)*(time - health_damagetime); - HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, health_beforedamage/maxhealth, is_vertical, health_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * health_damagealpha, DRAWFLAG_NORMAL); + HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, health_beforedamage/maxhealth, is_vertical, health_baralign, autocvar_hud_progressbar_health_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * health_damagealpha, DRAWFLAG_NORMAL); } } prev_health = health; @@ -1548,7 +1529,7 @@ void HUD_HealthArmor(void) pain_health_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); } } - HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, p_health/maxhealth, is_vertical, health_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * pain_health_alpha, DRAWFLAG_NORMAL); + HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, p_health/maxhealth, is_vertical, health_baralign, autocvar_hud_progressbar_health_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * pain_health_alpha, DRAWFLAG_NORMAL); } if(autocvar_hud_panel_healtharmor_text) DrawNumIcon(pos + health_offset, mySize, health, "health", is_vertical, health_iconalign, HUD_Get_Num_Color(health, maxhealth), 1); @@ -1558,7 +1539,6 @@ void HUD_HealthArmor(void) { if(autocvar_hud_panel_healtharmor_progressbar) { - HUD_Panel_GetProgressBarColor(armor); float p_armor; p_armor = armor; if (autocvar_hud_panel_healtharmor_progressbar_gfx) @@ -1590,12 +1570,12 @@ void HUD_HealthArmor(void) if (time - armor_damagetime < 1) { float armor_damagealpha = 1 - (time - armor_damagetime)*(time - armor_damagetime); - HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, armor_beforedamage/maxarmor, is_vertical, armor_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * armor_damagealpha, DRAWFLAG_NORMAL); + HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, armor_beforedamage/maxarmor, is_vertical, armor_baralign, autocvar_hud_progressbar_armor_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * armor_damagealpha, DRAWFLAG_NORMAL); } } prev_armor = armor; } - HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, p_armor/maxarmor, is_vertical, armor_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, p_armor/maxarmor, is_vertical, armor_baralign, autocvar_hud_progressbar_armor_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); } if(autocvar_hud_panel_healtharmor_text) DrawNumIcon(pos + armor_offset, mySize, armor, "armor", is_vertical, armor_iconalign, HUD_Get_Num_Color(armor, maxarmor), 1); @@ -1611,8 +1591,7 @@ void HUD_HealthArmor(void) mySize_x *= 2; //restore full panel size else if (panel_ar < 1/4) mySize_y *= 2; //restore full panel size - HUD_Panel_GetProgressBarColor(fuel); - HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, fuel_baralign, progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL); + HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, fuel_baralign, autocvar_hud_progressbar_fuel_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL); } } } @@ -3094,12 +3073,7 @@ void HUD_Mod_NexBall(vector pos, vector mySize) if (p > 1) p = 2 - p; - //Draw the filling - HUD_Panel_GetProgressBarColor(nexball); - if(mySize_x > mySize_y) - HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", p, 0, 0, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); - else - HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", p, 1, 0, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", p, (mySize_x <= mySize_y), 0, autocvar_hud_progressbar_nexball_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); } if (stat_items & IT_KEY1) @@ -3945,10 +3919,7 @@ void HUD_Physics(void) //draw speed if(speed) if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2) - { - HUD_Panel_GetProgressBarColor(speed); - HUD_Panel_DrawProgressBar(panel_pos + speed_offset, panel_size, "progressbar", speed/max_speed, 0, speed_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); - } + HUD_Panel_DrawProgressBar(panel_pos + speed_offset, panel_size, "progressbar", speed/max_speed, 0, speed_baralign, autocvar_hud_progressbar_speed_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); vector tmp_offset = '0 0 0', tmp_size = '0 0 0'; if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2) { @@ -4015,18 +3986,15 @@ void HUD_Physics(void) peak_offset_x = (1 - min(top_speed, max_speed)/max_speed) * panel_size_x; else // if (speed_baralign == 2) peak_offset_x = min(top_speed, max_speed)/max_speed * panel_size_x * 0.5; - //if speed is not 0 the speed progressbar already fetched the color - if (speed == 0) - HUD_Panel_GetProgressBarColor(speed); peak_size_x = floor(panel_size_x * 0.01 + 1.5); peak_size_y = panel_size_y; if (speed_baralign == 2) // draw two peaks, on both sides { - drawfill(panel_pos + speed_offset + eX * (0.5 * panel_size_x + peak_offset_x - peak_size_x), peak_size, progressbar_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); - drawfill(panel_pos + speed_offset + eX * (0.5 * panel_size_x - peak_offset_x + peak_size_x), peak_size, progressbar_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + drawfill(panel_pos + speed_offset + eX * (0.5 * panel_size_x + peak_offset_x - peak_size_x), peak_size, autocvar_hud_progressbar_speed_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + drawfill(panel_pos + speed_offset + eX * (0.5 * panel_size_x - peak_offset_x + peak_size_x), peak_size, autocvar_hud_progressbar_speed_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); } else - drawfill(panel_pos + speed_offset + eX * (peak_offset_x - peak_size_x), peak_size, progressbar_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + drawfill(panel_pos + speed_offset + eX * (peak_offset_x - peak_size_x), peak_size, autocvar_hud_progressbar_speed_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); } //top speed @@ -4044,10 +4012,11 @@ void HUD_Physics(void) if(acceleration) if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 3) { - if (acceleration < 0) - HUD_Panel_GetProgressBarColor(acceleration_neg); + vector progressbar_color; + if(acceleration < 0) + progressbar_color = autocvar_hud_progressbar_acceleration_neg_color; else - HUD_Panel_GetProgressBarColor(acceleration); + progressbar_color = autocvar_hud_progressbar_acceleration_color; f = acceleration/autocvar_hud_panel_physics_acceleration_max; if (autocvar_hud_panel_physics_acceleration_progressbar_nonlinear) diff --git a/qcsrc/client/hud.qh b/qcsrc/client/hud.qh index 19cd36ddb..8397f0b4a 100644 --- a/qcsrc/client/hud.qh +++ b/qcsrc/client/hud.qh @@ -56,8 +56,6 @@ string hud_skin_prev; vector myteamcolors; -var vector progressbar_color; - entity highlightedPanel_backup; var vector panel_pos_backup; var vector panel_size_backup; @@ -146,21 +144,6 @@ HUD_PANELS // ---------------------- // Little help for the poor people who have to make sense of this: Start from the bottom ;) -#define HUD_Panel_GetProgressBarColor(item) \ - progressbar_color = stov(cvar_string("hud_progressbar_" #item "_color")) -#define HUD_Panel_GetProgressBarColorForString(item) \ -switch(item) {\ - case "health": HUD_Panel_GetProgressBarColor(health); break;\ - case "armor": HUD_Panel_GetProgressBarColor(armor); break;\ - case "strength": HUD_Panel_GetProgressBarColor(strength); break;\ - case "shield": HUD_Panel_GetProgressBarColor(shield); break;\ - case "fuel": HUD_Panel_GetProgressBarColor(fuel); break;\ - case "nexball": HUD_Panel_GetProgressBarColor(nexball); break;\ - case "speed": HUD_Panel_GetProgressBarColor(speed); break;\ - case "acceleration": HUD_Panel_GetProgressBarColor(acceleration); break;\ - case "acceleration_neg": HUD_Panel_GetProgressBarColor(acceleration_neg); break;\ -} ENDS_WITH_CURLY_BRACE - // Get value for panel_bg: if "" fetch default, else use panel_bg_str // comment on last line of macro: // we probably want to see a background in config mode at all times... #define HUD_Panel_GetBg()\ -- 2.39.2