From: FruitieX Date: Fri, 23 Jul 2010 18:53:12 +0000 (+0300) Subject: use the hud_panel_weapons_accuracy_colorX system in the scoreboard too X-Git-Tag: xonotic-v0.1.0preview~362^2~15 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=1cbdd332a04d4926af7f5f9116e26fd361730c0f;p=xonotic%2Fxonotic-data.pk3dir.git use the hud_panel_weapons_accuracy_colorX system in the scoreboard too --- diff --git a/qcsrc/client/View.qc b/qcsrc/client/View.qc index 8c642415d..c8076b350 100644 --- a/qcsrc/client/View.qc +++ b/qcsrc/client/View.qc @@ -478,7 +478,6 @@ void CSQC_UpdateView(float w, float h) weapontime = time; last_weapon = activeweapon; - entity e; e = get_weaponinfo(activeweapon); if(e.netname != "") localcmd(strcat("\ncl_hook_activeweapon ", e.netname), "\n"); @@ -1190,6 +1189,18 @@ void CSQC_common_hud(void) switch(hud) { case HUD_NORMAL: + // do some accuracy var caching + float i; + if(!(gametype == GAME_RACE || gametype == GAME_CTS)) + { + acc_levels = tokenize(cvar_string("hud_panel_weapons_accuracy_color_levels")); + if (acc_levels > MAX_ACCURACY_LEVELS) + acc_levels = MAX_ACCURACY_LEVELS; + + for (i = 0; i < acc_levels; ++i) + acc_lev[i] = stof(argv(i)); + } + // hud first HUD_Main(); diff --git a/qcsrc/client/hud.qc b/qcsrc/client/hud.qc index 9e6e7d377..a4e0e9a20 100644 --- a/qcsrc/client/hud.qc +++ b/qcsrc/client/hud.qc @@ -1380,10 +1380,6 @@ float GetAmmoTypeForWep(float i) } } -#define acc_color(i) stov(cvar_string(strcat("hud_panel_weapons_accuracy_color", ftos(i)))) -#define MAX_ACCURACY_LEVELS 10 -float acc_lev[MAX_ACCURACY_LEVELS]; - void HUD_Weapons(void) { if(!autocvar_hud_panel_weapons && !autocvar__hud_configure) @@ -1469,17 +1465,6 @@ void HUD_Weapons(void) vector wpnpos; vector wpnsize; - float acc_levels; - if(autocvar_hud_panel_weapons_accuracy && !(gametype == GAME_RACE || gametype == GAME_CTS)) - { - acc_levels = tokenize(cvar_string("hud_panel_weapons_accuracy_color_levels")); - if (acc_levels > MAX_ACCURACY_LEVELS) - acc_levels = MAX_ACCURACY_LEVELS; - - for (i = 0; i < acc_levels; ++i) - acc_lev[i] = stof(argv(i)); - } - for(i = 0; i < weapon_cnt; ++i) { wpnpos = pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows); diff --git a/qcsrc/client/hud.qh b/qcsrc/client/hud.qh index 11a039bec..89f5edbdc 100644 --- a/qcsrc/client/hud.qh +++ b/qcsrc/client/hud.qh @@ -16,6 +16,11 @@ float scoreboard_bottom; float weapon_hits[WEP_MAXCOUNT]; float weapon_fired[WEP_MAXCOUNT]; +#define acc_color(i) stov(cvar_string(strcat("hud_panel_weapons_accuracy_color", ftos(i)))) +#define MAX_ACCURACY_LEVELS 10 +float acc_lev[MAX_ACCURACY_LEVELS]; +float acc_levels; + float complain_weapon; string complain_weapon_name; float complain_weapon_type; diff --git a/qcsrc/client/scoreboard.qc b/qcsrc/client/scoreboard.qc index 5efa9118d..b0865d326 100644 --- a/qcsrc/client/scoreboard.qc +++ b/qcsrc/client/scoreboard.qc @@ -969,19 +969,26 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size) float padding; padding = ((sbwidth/weapon_cnt) - stringwidth(s, FALSE, '1 0 0' * fontsize)) / 2; // center the accuracy value - // yellow_accuracy = value at which accuracy becomes yellow - if(weapon_stats >= 100) { - rgb_x = 0; - rgb_y = 1; - } - else if(weapon_stats > autocvar_hud_panel_weapons_accuracy_yellow) { - rgb_x = 1 - (weapon_stats-autocvar_hud_panel_weapons_accuracy_yellow)/(100-autocvar_hud_panel_weapons_accuracy_yellow); // red value between 1 -> 0 - rgb_y = 1; - } else { - rgb_x = 1; - rgb_y = weapon_stats/autocvar_hud_panel_weapons_accuracy_yellow; // green value between 0 -> 1 + float weapon_hit, weapon_damage; + weapon_damage = weapon_fired[self.weapon-WEP_FIRST]; + if(weapon_damage) + { + weapon_hit = weapon_hits[self.weapon-WEP_FIRST]; + weapon_stats = floor(100 * weapon_hit / weapon_damage); } - rgb_z = 0; + + // 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); } pos_x += sbwidth/weapon_cnt * rows;