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
+5 -1
View File
@@ -11,7 +11,11 @@ All notable changes to MetaHunt will be documented in this file.
- **zTrap — trap cooldown**: The zTrap buttons now show the trap re-arm cooldown (the ~15s before you can lay another trap) as a cooldown spiral plus a seconds countdown, on both the parent and child buttons. A new "Show cooldown" toggle lives in Options → zButtons → zTrap (on by default).
- **zAmmo — total ammo meter**: The zAmmo parent button can now show how stocked you are on your equipped weapon's ammo, as a percentage of your quiver/pouch capacity (all matching arrows or bullets across your bags ÷ total quiver/pouch slots × 200). Two heat-coloured display styles (red when low → green when full) are available as toggles in Options → zButtons → zAmmo → Parent Button: a **centered %** on the button, and a **vertical gauge** beside it (which flips to the side opposite the children's expand direction).
- **zAmmo — total ammo meter**: The zAmmo parent button can now show how stocked you are on your equipped weapon's ammo, as a percentage of your quiver/pouch capacity (all matching arrows or bullets across your bags ÷ total quiver/pouch slots × 200). Two heat-coloured display styles (red when low → green when full) are available as toggles in Options → zButtons → zAmmo → Parent Button: a **centered %** on the button, and a **vertical gauge** beside it (which flips to the side opposite the children's expand direction). A third toggle, **"Counter shows total ammo"**, switches the parent's bottom counter from the equipped stack to your full bag total.
### Changed
- **zAmmo — capacity-based counter colouring**: The heat colour on the ammo stack counters now scales to your real quiver/pouch capacity instead of a fixed number, so a stack turns green as it approaches filling your quiver (falls back to the old scale when no quiver/pouch is equipped).
### Fixed
+40 -22
View File
@@ -309,6 +309,10 @@ local function MTH_ZB_EnsureButtonOptionDefaults(buttonName)
saved["showtotalgauge"] = false
end
saved["showtotalgauge"] = saved["showtotalgauge"] and true or false
if saved["counttotal"] == nil then
saved["counttotal"] = false
end
saved["counttotal"] = saved["counttotal"] and true or false
end
if buttonName == "zButtonTrap" then
@@ -474,6 +478,42 @@ local function MTH_SetupButtonOptions(containerName, buttonName, displayName, ma
parentBox:Note(containerName.."AQFilterDesc", MTH_ZB_L("ZB_DESC_AQ_FILTER", "Hide Qiraji mounts outside AQ40. Show only Qiraji inside."))
end
if buttonName == "zButtonAmmo" then
parentBox:Checkbox(containerName.."ShowTotalPercent", MTH_ZB_L("ZB_LABEL_SHOW_TOTAL_PERCENT", "Show total % (center)"), {
checked = saved["showtotalperc"],
onClick = function()
if not this then return end
local checked = this:GetChecked() == 1
ZHunterMod_Saved[buttonName]["showtotalperc"] = checked
if buttonObj and buttonObj.ammoname and not buttonObj.isspell then
zButtonAmmo_UpdateButton(buttonObj)
end
end,
})
parentBox:Checkbox(containerName.."ShowTotalGauge", MTH_ZB_L("ZB_LABEL_SHOW_TOTAL_GAUGE", "Show total gauge (side)"), {
checked = saved["showtotalgauge"],
onClick = function()
if not this then return end
local checked = this:GetChecked() == 1
ZHunterMod_Saved[buttonName]["showtotalgauge"] = checked
if buttonObj and buttonObj.ammoname and not buttonObj.isspell then
zButtonAmmo_UpdateButton(buttonObj)
end
end,
})
parentBox:Checkbox(containerName.."CounterTotal", MTH_ZB_L("ZB_LABEL_COUNTER_TOTAL", "Counter shows total ammo"), {
checked = saved["counttotal"],
onClick = function()
if not this then return end
local checked = this:GetChecked() == 1
ZHunterMod_Saved[buttonName]["counttotal"] = checked
if buttonObj and buttonObj.ammoname and not buttonObj.isspell then
zButtonAmmo_UpdateButton(buttonObj)
end
end,
})
end
local childrenBox = panel:Box("left", containerName.."ChildrenSection", MTH_ZB_L("ZB_SECTION_CHILDREN_BUTTONS", "Children Buttons"))
childrenBox:Slider(containerName.."ButtonSize", {
label = MTH_ZB_L("ZB_LABEL_BUTTON_SIZE", "Button Size"),
@@ -604,28 +644,6 @@ local function MTH_SetupButtonOptions(containerName, buttonName, displayName, ma
end
end,
})
parentBox:Checkbox(containerName.."ShowTotalPercent", MTH_ZB_L("ZB_LABEL_SHOW_TOTAL_PERCENT", "Show total % (center)"), {
checked = saved["showtotalperc"],
onClick = function()
if not this then return end
local checked = this:GetChecked() == 1
ZHunterMod_Saved[buttonName]["showtotalperc"] = checked
if buttonObj and buttonObj.ammoname and not buttonObj.isspell then
zButtonAmmo_UpdateButton(buttonObj)
end
end,
})
parentBox:Checkbox(containerName.."ShowTotalGauge", MTH_ZB_L("ZB_LABEL_SHOW_TOTAL_GAUGE", "Show total gauge (side)"), {
checked = saved["showtotalgauge"],
onClick = function()
if not this then return end
local checked = this:GetChecked() == 1
ZHunterMod_Saved[buttonName]["showtotalgauge"] = checked
if buttonObj and buttonObj.ammoname and not buttonObj.isspell then
zButtonAmmo_UpdateButton(buttonObj)
end
end,
})
end
MTH_SetButtonEnabledState(buttonName, buttonObj, saved["enabled"] and true or false)
+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