void CSQC_common_hud(void)
{
- // do some accuracy var caching
- float i;
- if(!(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS))
- {
- if(autocvar_accuracy_color_levels != acc_color_levels)
- {
- if(acc_color_levels)
- strunzone(acc_color_levels);
- acc_color_levels = strzone(autocvar_accuracy_color_levels);
- acc_levels = tokenize_console(acc_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)) / 100.0;
- }
- // let know that acc_col[] needs to be loaded
- acc_col[0] = '-1 0 0';
- }
+ if(!(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS))
+ Accuracy_LoadLevels();
HUD_Main(); // always run these functions for alpha checks
HUD_DrawScoreboard();
// declarations
WEPSET_DECLARE_A(weapons_stat);
WEPSET_COPY_AS(weapons_stat);
- float i, f, a, j, factor;
+ float i, f, a;
float screen_ar, center_x = 0, center_y;
float weapon_count, weapon_id;
float row, column, rows, columns;
float aspect = autocvar_hud_panel_weapons_aspect;
- float show_accuracy = false, panel_weapon_accuracy;
+ float panel_weapon_accuracy;
float timeout = autocvar_hud_panel_weapons_timeout;
float timein_effect_length = autocvar_hud_panel_weapons_timeout_speed_in; //? 0.375 : 0);
baroffset_y = (weapon_size_y - barsize_y) / 2;
}
}
-
- if(autocvar_hud_panel_weapons_accuracy && acc_levels)
- {
- show_accuracy = true;
- if (acc_col[0] == '-1 0 0')
- for (i = 0; i < acc_levels; ++i)
- acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
- }
+ if(autocvar_hud_panel_weapons_accuracy)
+ Accuracy_LoadColors();
row = column = 0;
for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
drawpic_aspect_skin(weapon_pos, "weapon_current_bg", weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
// draw the weapon accuracy
- if(show_accuracy)
+ if(autocvar_hud_panel_weapons_accuracy)
{
panel_weapon_accuracy = weapon_accuracy[self.weapon-WEP_FIRST];
if(panel_weapon_accuracy >= 0)
{
- // find the max level lower than weapon_accuracy
- j = acc_levels-1;
- while ( j && panel_weapon_accuracy < acc_lev[j] )
- --j;
-
- // inject color j+1 in color j, how much depending on how much weapon_accuracy is higher than level j
- factor = (panel_weapon_accuracy - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
- color = acc_col[j];
- color = color + factor * (acc_col[j+1] - color);
-
+ color = Accuracy_GetColor(panel_weapon_accuracy);
drawpic_aspect_skin(weapon_pos, "weapon_accuracy", weapon_size, color, panel_fg_alpha, DRAWFLAG_NORMAL);
}
}
float scoreboard_bottom;
float weapon_accuracy[WEP_MAXCOUNT];
-#define MAX_ACCURACY_LEVELS 10
-float acc_lev[MAX_ACCURACY_LEVELS];
-vector acc_col[MAX_ACCURACY_LEVELS];
-float acc_levels;
-string acc_color_levels;
-
float complain_weapon;
string complain_weapon_name;
float complain_weapon_type;
{
drawfont = FONT_USER+1;
}
+
+
+#define MAX_ACCURACY_LEVELS 10
+float acc_lev[MAX_ACCURACY_LEVELS];
+vector acc_col[MAX_ACCURACY_LEVELS];
+float acc_col_loadtime;
+float acc_levels;
+string acc_color_levels;
+void Accuracy_LoadLevels()
+{
+ float i;
+ if(autocvar_accuracy_color_levels != acc_color_levels)
+ {
+ if(acc_color_levels)
+ strunzone(acc_color_levels);
+ acc_color_levels = strzone(autocvar_accuracy_color_levels);
+ acc_levels = tokenize_console(acc_color_levels);
+ if(acc_levels > MAX_ACCURACY_LEVELS)
+ acc_levels = MAX_ACCURACY_LEVELS;
+ if(acc_levels < 2)
+ print("Warning: accuracy_color_levels must contain at least 2 values\n");
+
+ for(i = 0; i < acc_levels; ++i)
+ acc_lev[i] = stof(argv(i)) / 100.0;
+ }
+}
+
+void Accuracy_LoadColors()
+{
+ float i;
+ if(time > acc_col_loadtime)
+ if(acc_levels >= 2)
+ {
+ for(i = 0; i < acc_levels; ++i)
+ acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
+ acc_col_loadtime = time + 2;
+ }
+}
+
+vector Accuracy_GetColor(float accuracy)
+{
+ float j, factor;
+ vector color;
+ if(acc_levels < 2)
+ return '0 0 0'; // return black, can't determine the right color
+
+ // find the max level lower than acc
+ j = acc_levels-1;
+ while(j && accuracy < acc_lev[j])
+ --j;
+
+ // inject color j+1 in color j, how much depending on how much accuracy is higher than level j
+ factor = (accuracy - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
+ color = acc_col[j];
+ color = color + factor * (acc_col[j+1] - color);
+ return color;
+}
+
float weapon_stats;
- if (!acc_levels)
- rgb = '1 1 1';
- else if (acc_col[0] == '-1 0 0')
- for (i = 0; i < acc_levels; ++i)
- acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
+ Accuracy_LoadColors();
for(i = WEP_FIRST; i <= WEP_LAST; ++i)
{
float padding;
padding = (weapon_width - stringwidth(s, FALSE, '1 0 0' * fontsize)) / 2; // center the accuracy value
- 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_col[j];
- rgb = rgb + factor * (acc_col[j+1] - rgb);
- }
+ rgb = Accuracy_GetColor(weapon_stats);
drawstring(pos + '1 0 0' * padding + '0 1 0' * weapon_height, s, '1 1 0' * fontsize, rgb, scoreboard_alpha_fg, DRAWFLAG_NORMAL);
}