From 1303603cf4e428612cb3c7972425690c1c56a270 Mon Sep 17 00:00:00 2001 From: terencehill Date: Thu, 30 Sep 2010 16:29:26 +0200 Subject: [PATCH] - Fix hud_panel_weapons_accuracy usage that was considered always true - Initialize accuracy levels only when the cvar hud_panel_weapons_accuracy_color_levels changes, not at every frame - Show accuracy stats data without colors on the scoreboard if hud_panel_weapons_accuracy_color_levels is "", instead of not showing at all the whole accuracy panel --- defaultXonotic.cfg | 2 +- qcsrc/client/View.qc | 4 +++- qcsrc/client/hud.qc | 6 +++++- qcsrc/client/hud.qh | 1 + qcsrc/client/scoreboard.qc | 28 +++++++++++++++++----------- 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/defaultXonotic.cfg b/defaultXonotic.cfg index d3e5f56e6..0ec3e0696 100644 --- a/defaultXonotic.cfg +++ b/defaultXonotic.cfg @@ -1383,7 +1383,7 @@ seta scoreboard_columns default seta scoreboard_border_thickness 1 "scoreboard border thickness" seta scoreboard_accuracy_border_thickness 1 "accuracy stats border thickness" seta scoreboard_accuracy_doublerows 0 "use two rows instead of one" -seta scoreboard_accuracy 1 "0 = no weapon accuracy stats panel on scoreboard" +seta scoreboard_accuracy 1 "show accuracy stats panel on scoreboard" seta scoreboard_color_bg_r 0 "red color component of the HUD background" seta scoreboard_color_bg_g 0.25 "green color component of the HUD background" seta scoreboard_color_bg_b 0.17 "blue color component of the HUD background" diff --git a/qcsrc/client/View.qc b/qcsrc/client/View.qc index 829eeb701..111db52e1 100644 --- a/qcsrc/client/View.qc +++ b/qcsrc/client/View.qc @@ -1200,9 +1200,11 @@ void CSQC_common_hud(void) case HUD_NORMAL: // do some accuracy var caching float i; + if(cvar_string("hud_panel_weapons_accuracy_color_levels") != acc_color_levels) if(!(gametype == GAME_RACE || gametype == GAME_CTS)) { - acc_levels = tokenize(cvar_string("hud_panel_weapons_accuracy_color_levels")); + acc_color_levels = cvar_string("hud_panel_weapons_accuracy_color_levels"); + acc_levels = tokenize(acc_color_levels); if (acc_levels > MAX_ACCURACY_LEVELS) acc_levels = MAX_ACCURACY_LEVELS; diff --git a/qcsrc/client/hud.qc b/qcsrc/client/hud.qc index 3a9be97bb..906a01928 100644 --- a/qcsrc/client/hud.qc +++ b/qcsrc/client/hud.qc @@ -1657,6 +1657,10 @@ void HUD_Weapons(void) vector wpnpos; vector wpnsize; + float show_accuracy; + if(autocvar_hud_panel_weapons_accuracy && acc_levels) + show_accuracy = true; + for(i = 0; i < weapon_cnt; ++i) { wpnpos = panel_pos + eX * column * panel_size_x*(1/columns) + eY * row * panel_size_y*(1/rows); @@ -1670,7 +1674,7 @@ void HUD_Weapons(void) drawpic_aspect_skin(wpnpos, "weapon_current_bg", wpnsize, '1 1 1', fade * panel_fg_alpha, DRAWFLAG_NORMAL); // draw the weapon accuracy - if(acc_levels) + if(show_accuracy) { float weapon_hit, weapon_damage; weapon_damage = weapon_fired[self.weapon-WEP_FIRST]; diff --git a/qcsrc/client/hud.qh b/qcsrc/client/hud.qh index 371dd64b7..1754dcb58 100644 --- a/qcsrc/client/hud.qh +++ b/qcsrc/client/hud.qh @@ -22,6 +22,7 @@ float weapon_fired[WEP_MAXCOUNT]; #define MAX_ACCURACY_LEVELS 10 float acc_lev[MAX_ACCURACY_LEVELS]; float acc_levels; +string acc_color_levels; float complain_weapon; string complain_weapon_name; diff --git a/qcsrc/client/scoreboard.qc b/qcsrc/client/scoreboard.qc index 76b19a54c..0149f9d96 100644 --- a/qcsrc/client/scoreboard.qc +++ b/qcsrc/client/scoreboard.qc @@ -947,6 +947,9 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size) if(getstati(STAT_SWITCHWEAPON) == WEP_MINSTANEX) g_minstagib = 1; // TODO: real detection for minstagib? + if (!acc_levels) + rgb = '1 1 1'; + for(i = WEP_FIRST; i <= WEP_LAST; ++i) { self = get_weaponinfo(i); @@ -986,17 +989,20 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size) weapon_stats = floor(100 * weapon_hit / weapon_damage); } - // find the max level lower than weapon_stats - float j; - j = acc_levels-1; - while ( j && weapon_stats < acc_lev[j] ) - --j; - - // inject color j+1 in color j, how much depending on how much weapon_stats is higher than level j - float factor; - factor = (weapon_stats - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]); - rgb = acc_color(j); - rgb = rgb + factor * (acc_color(j+1) - rgb); + if (acc_levels) + { + // find the max level lower than weapon_stats + float j; + j = acc_levels-1; + while ( j && weapon_stats < acc_lev[j] ) + --j; + + // inject color j+1 in color j, how much depending on how much weapon_stats is higher than level j + float factor; + factor = (weapon_stats - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]); + rgb = acc_color(j); + rgb = rgb + factor * (acc_color(j+1) - rgb); + } drawstring(pos + '1 0 0' * padding + '0 1 0' * height * (2/3), s, '1 1 0' * fontsize, rgb, scoreboard_alpha_fg, DRAWFLAG_NORMAL); } -- 2.39.2