zAmmo: bottom-counter total toggle + capacity-based counter colouring

This commit is contained in:
DuvelCorp
2026-10-06 15:09:19 +02:00
parent f6b495d68d
commit 69c6d44b8e
3 changed files with 74 additions and 24 deletions
+29 -1
View File
@@ -509,6 +509,18 @@ local function zButtonAmmo_GetTotalAmmoCount(category)
return total
end
-- Divisor for per-stack heat colouring: real quiver/pouch capacity, or a
-- fixed fallback when no matching ammo bag is equipped.
local function zButtonAmmo_GetCountDivisor(category)
if category then
local capacity = zButtonAmmo_GetAmmoCapacity(category)
if capacity and capacity > 0 then
return capacity
end
end
return 2000
end
local function zButtonAmmo_UpdateTotalPercent(button)
local totalText = zButtonAmmo_EnsureTotalPercentText(button)
if not totalText then
@@ -593,6 +605,11 @@ local function zButtonAmmo_UpdateTotalGauge(button)
gauge:Show()
end
local function zButtonAmmo_ShouldShowTotalCount()
local saved = zButtonAmmo_GetSaved()
return saved["counttotal"] and true or false
end
function zButtonAmmo_UpdateButton(button)
if not button then
button = this
@@ -641,7 +658,7 @@ function zButtonAmmo_UpdateButton(button)
button.ammoslot = ammoInfo.slot
button.ammocount = ammoInfo.count
if countText then
local r, g, b = zButtonAmmo_GetColorGradient((ammoInfo.count or 0) / 2000)
local r, g, b = zButtonAmmo_GetColorGradient((ammoInfo.count or 0) / zButtonAmmo_GetCountDivisor(ammoInfo.type))
countText:SetTextColor(r, g, b, 1)
countText:SetText(ammoInfo.count)
end
@@ -653,6 +670,17 @@ function zButtonAmmo_UpdateButton(button)
end
end
if button == zButtonAmmo then
if countText and zButtonAmmo_ShouldShowTotalCount() then
local category = zButtonAmmo_GetEquippedAmmoCategory()
if category then
local total = zButtonAmmo_GetTotalAmmoCount(category)
local capacity = zButtonAmmo_GetAmmoCapacity(category)
local frac = capacity > 0 and (total / capacity) or (total / 2000)
local r, g, b = zButtonAmmo_GetColorGradient(frac)
countText:SetTextColor(r, g, b, 1)
countText:SetText(total)
end
end
zButtonAmmo_UpdateTotalPercent(button)
zButtonAmmo_UpdateTotalGauge(button)
end