From: terencehill Date: Tue, 3 Sep 2024 00:50:46 +0000 (+0200) Subject: Display fuel level on the Ammo panel X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=7fa74eecb48b86965587cd0dec56364564ed78c6;p=xonotic%2Fxonotic-data.pk3dir.git Display fuel level on the Ammo panel It was improperly displayed on the HealthArmor panel as a simple bar Normally Fuel is not displayed, it now appears under these updated conditions: if player has some fuel or unlimited ammo or jetpack or off-hand hook. The GetAmmoStat change allowed to handle the returned value in a consistent way (fuel should have called getstatf instead of getstati on the returned value) --- diff --git a/_hud_common.cfg b/_hud_common.cfg index 954ffbd80..c659bfe52 100644 --- a/_hud_common.cfg +++ b/_hud_common.cfg @@ -85,6 +85,7 @@ seta hud_panel_weapons_hide_ondeath 0 "hide this panel when dead" seta hud_panel_weapons_orderbyimpulse "1" "List weapons in their impulse order instead of priority" seta hud_panel_ammo_maxammo "40" "when you have this much ammo, the ammo status bar is full" +seta hud_panel_ammo_maxfuel "100" "when you have this much fuel, the fuel status bar is full" seta hud_panel_ammo_hide_ondeath 0 "hide this panel when dead" seta hud_panel_powerups_hide_ondeath 0 "hide this panel when dead" diff --git a/qcsrc/client/hud/panel/ammo.qc b/qcsrc/client/hud/panel/ammo.qc index 891123bf1..37e3dc45b 100644 --- a/qcsrc/client/hud/panel/ammo.qc +++ b/qcsrc/client/hud/panel/ammo.qc @@ -47,7 +47,7 @@ void DrawAmmoItem(vector myPos, vector mySize, Resource ammoType, bool isCurrent ammo = 60; } else - ammo = getstati(GetAmmoStat(ammoType)); + ammo = GetAmmoStat(ammoType); if(!isCurrent) { @@ -89,15 +89,28 @@ void DrawAmmoItem(vector myPos, vector mySize, Resource ammoType, bool isCurrent else alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_ammo_noncurrent_alpha, 1); - string text = isInfinite ? "\xE2\x88\x9E" : ftos(ammo); // Use infinity symbol (U+221E) + // Use infinity symbol (U+221E) + string text = isInfinite ? "\xE2\x88\x9E" : ftos((ammoType == RES_FUEL) ? ceil(ammo) : ammo); // Draw item if(isCurrent) drawpic_aspect_skin(myPos, "ammo_current_bg", mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); - if(ammo > 0 && autocvar_hud_panel_ammo_progressbar) - HUD_Panel_DrawProgressBar(myPos + eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x, mySize - eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x, autocvar_hud_panel_ammo_progressbar_name, ammo/autocvar_hud_panel_ammo_maxammo, 0, 0, textColor, autocvar_hud_progressbar_alpha * alpha, DRAWFLAG_NORMAL); + if(ammo > 0 && (autocvar_hud_panel_ammo_progressbar || ammoType == RES_FUEL)) + { + vector ammo_bar_color = textColor; + float ammo_bar_max = autocvar_hud_panel_ammo_maxammo; + if (ammoType == RES_FUEL) + { + ammo_bar_color = autocvar_hud_progressbar_fuel_color; + ammo_bar_max = autocvar_hud_panel_ammo_maxfuel; + } + vector ofs = eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x; + HUD_Panel_DrawProgressBar(myPos + ofs, mySize - ofs, autocvar_hud_panel_ammo_progressbar_name, + ammo / ammo_bar_max, 0, 0, ammo_bar_color, + autocvar_hud_progressbar_alpha * alpha, DRAWFLAG_NORMAL); + } if(autocvar_hud_panel_ammo_text) drawstring_aspect(textPos, text, eX * (2/3) * mySize.x + eY * mySize.y, textColor, alpha, DRAWFLAG_NORMAL); @@ -151,6 +164,15 @@ void HUD_Ammo() else total_ammo_count = AMMO_COUNT; + bool infinite_ammo = (STAT(ITEMS) & IT_UNLIMITED_AMMO); + bool have_hook = (WepSet_GetFromStat() & WEPSET(HOOK)) != '0 0 0'; + bool have_jetpack = boolean(STAT(ITEMS) & IT_JETPACK); + + // always show fuel if we have jetpack or off-hand hook + bool show_fuel = (STAT(FUEL) || infinite_ammo || have_jetpack || have_hook); + if (show_fuel) + ++total_ammo_count; + if(draw_nades) { ++total_ammo_count; @@ -189,7 +211,6 @@ void HUD_Ammo() Weapon wep = wepent.switchweapon; int i; - bool infinite_ammo = (STAT(ITEMS) & IT_UNLIMITED_AMMO); row = column = 0; if(autocvar_hud_panel_ammo_onlycurrent) { @@ -220,11 +241,20 @@ void HUD_Ammo() row = column = 0; IL_EACH(default_order_resources, it.instanceOfAmmoResource && !it.m_hidden, { + bool isCurrent = (wep.ammo_type == it); + if (it == RES_FUEL) + { + if (!show_fuel) + continue; + if (!isCurrent) + isCurrent = have_jetpack; // jetpack can be used anytime + } + DrawAmmoItem( pos + vec2(column * (ammo_size.x + offset.x), row * (ammo_size.y + offset.y)), ammo_size, it, - (wep.ammo_type == it), + isCurrent, infinite_ammo ); diff --git a/qcsrc/client/hud/panel/ammo.qh b/qcsrc/client/hud/panel/ammo.qh index 0906a1c7e..da36e8cc6 100644 --- a/qcsrc/client/hud/panel/ammo.qh +++ b/qcsrc/client/hud/panel/ammo.qh @@ -3,9 +3,11 @@ bool autocvar_hud_panel_ammo; bool autocvar_hud_panel_ammo_dynamichud = true; +vector autocvar_hud_progressbar_fuel_color; bool autocvar_hud_panel_ammo_hide_ondeath = false; bool autocvar_hud_panel_ammo_iconalign; int autocvar_hud_panel_ammo_maxammo; +int autocvar_hud_panel_ammo_maxfuel = 100; bool autocvar_hud_panel_ammo_onlycurrent; float autocvar_hud_panel_ammo_noncurrent_alpha = 0.7; float autocvar_hud_panel_ammo_noncurrent_scale = 1; diff --git a/qcsrc/client/hud/panel/healtharmor.qc b/qcsrc/client/hud/panel/healtharmor.qc index f84a37330..ce4a4a60a 100644 --- a/qcsrc/client/hud/panel/healtharmor.qc +++ b/qcsrc/client/hud/panel/healtharmor.qc @@ -22,7 +22,7 @@ void HUD_HealthArmor_Export(int fh) void HUD_HealthArmor() { - int armor, health, fuel, air_time; + int armor, health, air_time; if(!autocvar__hud_configure) { if((!autocvar_hud_panel_healtharmor) || (spectatee_status == -1)) @@ -64,14 +64,12 @@ void HUD_HealthArmor() prev_health = 0; prev_armor = 0; } - fuel = STAT(FUEL); air_time = bound(0, STAT(AIR_FINISHED) - time, 10); } else { health = 150; armor = 75; - fuel = 20; air_time = 6; } @@ -110,16 +108,6 @@ void HUD_HealthArmor() air_alpha = bound(0, start_alpha + (1 - start_alpha) * (1 - f), 1); } - float fuel_alpha; - if (!fuel) - fuel_alpha = 0; - else - { - float start_alpha = autocvar_hud_panel_healtharmor_fuelbar_startalpha; - float f = (100 - fuel) / 50; - fuel_alpha = bound(0, start_alpha + (1 - start_alpha) * f, 1); - } - int baralign = autocvar_hud_panel_healtharmor_baralign; int iconalign = autocvar_hud_panel_healtharmor_iconalign; @@ -151,8 +139,6 @@ void HUD_HealthArmor() if(autocvar_hud_panel_healtharmor_text) DrawNumIcon(pos, mySize, hp, biggercount, false, false, iconalign, HUD_Get_Num_Color(hp, maxtotal, true), 1); - if(fuel) - HUD_Panel_DrawProgressBar(pos, vec2(mySize.x, 0.2 * mySize.y), "progressbar", fuel / 100, 0, (baralign == 1 || baralign == 3), autocvar_hud_progressbar_fuel_color, fuel_alpha * panel_fg_alpha * 0.8, DRAWFLAG_NORMAL); if(air_time) HUD_Panel_DrawProgressBar(pos + eY * 0.8 * mySize.y, vec2(mySize.x, 0.2 * mySize.y), "progressbar", air_time / 10, 0, (baralign == 1 || baralign == 3), autocvar_hud_progressbar_oxygen_color, air_alpha * panel_fg_alpha * 0.8, DRAWFLAG_NORMAL); } @@ -178,13 +164,13 @@ void HUD_HealthArmor() armor_offset.y = mySize.y; } - bool health_baralign, armor_baralign, fuel_baralign, air_align; + bool health_baralign, armor_baralign, air_align; bool health_iconalign, armor_iconalign; if (autocvar_hud_panel_healtharmor_flip) { armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1); health_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1); - air_align = fuel_baralign = health_baralign; + air_align = health_baralign; armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1); health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1); } @@ -192,7 +178,7 @@ void HUD_HealthArmor() { health_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1); armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1); - air_align = fuel_baralign = armor_baralign; + air_align = armor_baralign; health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1); armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1); } @@ -297,7 +283,7 @@ void HUD_HealthArmor() } vector cell_size = mySize; - if (fuel || air_time) + if (air_time) { if (is_vertical) mySize.x *= 0.2 / 2; //if vertical always halve x to not cover too much numbers with 3 digits @@ -307,8 +293,6 @@ void HUD_HealthArmor() mySize.x *= 2; //restore full panel size else if (panel_ar < 1/4) mySize.y *= 2; //restore full panel size - if (fuel) - HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel / 100, is_vertical, fuel_baralign, autocvar_hud_progressbar_fuel_color, fuel_alpha * panel_fg_alpha * 0.8, DRAWFLAG_NORMAL); if (air_time) { if (panel_ar > 1 && panel_ar < 4) diff --git a/qcsrc/client/hud/panel/healtharmor.qh b/qcsrc/client/hud/panel/healtharmor.qh index 47a101738..b62d45fc6 100644 --- a/qcsrc/client/hud/panel/healtharmor.qh +++ b/qcsrc/client/hud/panel/healtharmor.qh @@ -10,7 +10,6 @@ bool autocvar_hud_panel_healtharmor_hide_ondeath = false; int autocvar_hud_panel_healtharmor_iconalign; int autocvar_hud_panel_healtharmor_maxarmor; int autocvar_hud_panel_healtharmor_maxhealth; -float autocvar_hud_panel_healtharmor_fuelbar_startalpha = 0.3; float autocvar_hud_panel_healtharmor_oxygenbar_startalpha = 0.2; bool autocvar_hud_panel_healtharmor_progressbar; string autocvar_hud_panel_healtharmor_progressbar_armor; @@ -22,6 +21,5 @@ float autocvar_hud_panel_healtharmor_progressbar_gfx_smooth; int autocvar_hud_panel_healtharmor_text; vector autocvar_hud_progressbar_armor_color; -vector autocvar_hud_progressbar_fuel_color; vector autocvar_hud_progressbar_health_color; vector autocvar_hud_progressbar_oxygen_color = '0.1 1 1'; diff --git a/qcsrc/client/hud/panel/weapons.qc b/qcsrc/client/hud/panel/weapons.qc index 2863f62d9..71f43e93f 100644 --- a/qcsrc/client/hud/panel/weapons.qc +++ b/qcsrc/client/hud/panel/weapons.qc @@ -121,7 +121,7 @@ void HUD_Weapons() // declarations WepSet weapons_stat = WepSet_GetFromStat(); int i; - float f, a; + float f; float screen_ar; vector center = '0 0 0'; int weapon_count, weapon_id; @@ -575,9 +575,9 @@ void HUD_Weapons() if(!infinite_ammo && autocvar_hud_panel_weapons_ammo && (it.ammo_type != RES_NONE)) { float ammo_full; - a = getstati(GetAmmoStat(it.ammo_type)); // how much ammo do we have? + float ammo = GetAmmoStat(it.ammo_type); - if(a > 0) + if(ammo > 0) { // TODO: registry handles switch (it.ammo_type) @@ -594,7 +594,7 @@ void HUD_Weapons() drawsetcliparea( weapon_pos.x + baroffset.x, weapon_pos.y + baroffset.y, - barsize.x * bound(0, a/ammo_full, 1), + barsize.x * bound(0, ammo / ammo_full, 1), barsize.y ); @@ -619,6 +619,7 @@ void HUD_Weapons() // draw the complain message if(it == complain_weapon) { + float a; if(fadetime) a = ((complain_weapon_time + when > time) ? 1 : bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1)); else diff --git a/qcsrc/common/resources/all.inc b/qcsrc/common/resources/all.inc index 8ef77ebf1..ab05f6972 100644 --- a/qcsrc/common/resources/all.inc +++ b/qcsrc/common/resources/all.inc @@ -72,6 +72,5 @@ REGISTER_RESOURCE(FUEL, NEW(AmmoResource)) { this.m_name = _("Fuel"); this.m_icon = "ammo_fuel"; #ifdef CSQC - this.m_hidden = true; // displayed in a separate panel #endif } diff --git a/qcsrc/common/weapons/all.qc b/qcsrc/common/weapons/all.qc index 255a921f0..10148e864 100644 --- a/qcsrc/common/weapons/all.qc +++ b/qcsrc/common/weapons/all.qc @@ -202,12 +202,12 @@ int GetAmmoStat(Resource ammotype) // TODO: handle networking via resources switch (ammotype) { - case RES_SHELLS: return STAT_SHELLS; - case RES_BULLETS: return STAT_NAILS; - case RES_ROCKETS: return STAT_ROCKETS; - case RES_CELLS: return STAT_CELLS; - case RES_PLASMA: return STAT_PLASMA.m_id; - case RES_FUEL: return STAT_FUEL.m_id; + case RES_SHELLS: return STAT(SHELLS); + case RES_BULLETS: return STAT(NAILS); + case RES_ROCKETS: return STAT(ROCKETS); + case RES_CELLS: return STAT(CELLS); + case RES_PLASMA: return STAT(PLASMA); + case RES_FUEL: return STAT(FUEL); default: return -1; } }