From c76d7da18a920a442ae79b3a18196eb0f1b90901 Mon Sep 17 00:00:00 2001 From: terencehill Date: Thu, 12 May 2011 22:29:18 +0200 Subject: [PATCH] hud_panel_weapons_onlyowned to display only owned weapons; panel gets dynamically reduced and recentered --- defaultXonotic.cfg | 1 + qcsrc/client/autocvars.qh | 1 + qcsrc/client/hud.qc | 41 +++++++++++++++++++++++++++++++++------ 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/defaultXonotic.cfg b/defaultXonotic.cfg index ee2570b9d..5ba1df638 100644 --- a/defaultXonotic.cfg +++ b/defaultXonotic.cfg @@ -1424,6 +1424,7 @@ seta hud_panel_weapons_ammo_full_nails 200 "show 100% of the status bar at this seta hud_panel_weapons_ammo_full_cells 80 "show 100% of the status bar at this ammo count" seta hud_panel_weapons_ammo_full_rockets 80 "show 100% of the status bar at this ammo count" seta hud_panel_weapons_ammo_full_fuel 100 "show 100% of the status bar at this ammo count" +seta hud_panel_weapons_onlyowned 0 "show only owned weapons" seta hud_panel_ammo_maxammo "40" "when you have this much ammo, the ammo status bar is full" diff --git a/qcsrc/client/autocvars.qh b/qcsrc/client/autocvars.qh index 2fe09ea1e..f7d18d993 100644 --- a/qcsrc/client/autocvars.qh +++ b/qcsrc/client/autocvars.qh @@ -271,6 +271,7 @@ float autocvar_hud_panel_weapons_complainbubble_padding; float autocvar_hud_panel_weapons_complainbubble_time; var float autocvar_hud_panel_weapons_fade = 1; float autocvar_hud_panel_weapons_label; +float autocvar_hud_panel_weapons_onlyowned; float autocvar_hud_panel_weapons_timeout; float autocvar_hud_panel_weapons_timeout_effect; float autocvar_hud_progressbar_alpha; diff --git a/qcsrc/client/hud.qc b/qcsrc/client/hud.qc index 91256b9c5..7924c2983 100644 --- a/qcsrc/client/hud.qc +++ b/qcsrc/client/hud.qc @@ -612,7 +612,7 @@ float GetAmmoTypeForWep(float i) void HUD_Weapons(void) { - float f, screen_ar; + float i, f, screen_ar; float center_x, center_y; if(!autocvar__hud_configure) @@ -644,6 +644,33 @@ void HUD_Weapons(void) HUD_Panel_UpdateCvars(weapons); + float weapons_st = getstati(STAT_WEAPONS); + float weapon_count; + if (!autocvar__hud_configure && autocvar_hud_panel_weapons_onlyowned) + { + vector old_panel_size; + for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i) + { + if(weapons_st & weaponorder[i].weapons) + ++weapon_count; + } + // reduce size of the panel + if (panel_size_y > panel_size_x) + { + old_panel_size_y = panel_size_y; + panel_size_y *= weapon_count / WEP_COUNT; + panel_pos_y += (old_panel_size_y - panel_size_y) / 2; + } + else + { + old_panel_size_x = panel_size_x; + panel_size_x *= weapon_count / WEP_COUNT; + panel_pos_x += (old_panel_size_x - panel_size_x) / 2; + } + } + else + weapon_count = WEP_COUNT; + if (timeout && time >= weapontime + timeout && !autocvar__hud_configure) { f = (time - (weapontime + timeout)) / timeout_effect_length; @@ -707,7 +734,7 @@ void HUD_Weapons(void) } } - float i, weapid, wpnalpha, weapon_cnt; + float weapid, wpnalpha, weapon_cnt; // TODO make this configurable if(weaponorder_bypriority != autocvar_cl_weaponpriority || !weaponorder[0]) @@ -756,9 +783,9 @@ void HUD_Weapons(void) float rows, columns; float aspect = autocvar_hud_panel_weapons_aspect; rows = panel_size_y/panel_size_x; - rows = bound(1, floor((sqrt(4 * aspect * rows * WEP_COUNT + rows * rows) + rows + 0.5) / 2), WEP_COUNT); + rows = bound(1, floor((sqrt(4 * aspect * rows * weapon_count + rows * rows) + rows + 0.5) / 2), weapon_count); - columns = ceil(WEP_COUNT/rows); + columns = ceil(weapon_count/rows); float row, column; float a, type, fullammo; @@ -805,13 +832,15 @@ void HUD_Weapons(void) acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i)))); } - float weapons_st = getstati(STAT_WEAPONS); - for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i) { self = weaponorder[i]; if (!self || self.impulse < 0) continue; + if (autocvar_hud_panel_weapons_onlyowned) + if (!(weapons_st & self.weapons)) + if (!autocvar__hud_configure) + continue; wpnpos = panel_pos + eX * column * wpnsize_x + eY * row * wpnsize_y; weapid = self.impulse; -- 2.39.2