fix: item cooldowns

This commit is contained in:
Salikh Gurgenidze
2025-11-22 00:58:01 +04:00
parent c5b0622453
commit 9641229d1a
2 changed files with 92 additions and 9 deletions
+55 -9
View File
@@ -367,8 +367,13 @@ function BagFrame:DisplayItems(bagData, isOtherChar, charName)
end
end
-- Resize frame dynamically based on content
self:ResizeFrame(row, col, perRow)
-- Resize frame dynamically based on content
self:ResizeFrame(row, col, perRow)
-- Ensure cooldown visuals are current after (re)building buttons
if self.RefreshCooldowns then
self:RefreshCooldowns()
end
end
-- Resize frame based on number of rows and columns
@@ -1887,12 +1892,21 @@ function BagFrame:Initialize()
end
end)
-- Update on bag changes
addon.Modules.Events:OnBagUpdate(function()
if not currentViewChar then
BagFrame:Update()
end
end, "BagFrame")
-- Update on bag changes
addon.Modules.Events:OnBagUpdate(function()
if not currentViewChar then
BagFrame:Update()
end
end, "BagFrame")
-- Update item cooldown overlays when item cooldowns change
addon.Modules.Events:Register("BAG_UPDATE_COOLDOWN", function()
if not currentViewChar then
if BagFrame.RefreshCooldowns then
BagFrame:RefreshCooldowns()
end
end
end, "BagFrame")
-- Update on money changes
addon.Modules.Events:OnMoneyChanged(function()
@@ -1923,5 +1937,37 @@ function BagFrame:Initialize()
end)
end
addon:Debug("Bag frame initialized")
addon:Debug("Bag frame initialized")
end
-- Refresh cooldown overlays for all visible item buttons
function BagFrame:RefreshCooldowns()
local itemContainer = getglobal("Guda_BagFrame_ItemContainer")
if not itemContainer then return end
-- Iterate through all children; our item buttons are direct children of per-bag parents inside the container,
-- so iterate all descendants by scanning children of children as well.
local function refreshChildren(parent)
local children = { parent:GetChildren() }
for _, child in ipairs(children) do
if child and child.hasItem ~= nil then
if child:IsShown() and Guda_ItemButton_UpdateCooldown then
Guda_ItemButton_UpdateCooldown(child)
end
end
-- Recurse one level to reach actual buttons under bag parents
local grandChildren = { child:GetChildren() }
if table.getn(grandChildren) > 0 then
for _, gc in ipairs(grandChildren) do
if gc and gc.hasItem ~= nil then
if gc:IsShown() and Guda_ItemButton_UpdateCooldown then
Guda_ItemButton_UpdateCooldown(gc)
end
end
end
end
end
end
refreshChildren(itemContainer)
end
+37
View File
@@ -131,6 +131,35 @@ function Guda_ItemButton_OnLoad(self)
end
end
-- Update the Blizzard cooldown overlay on this item button
function Guda_ItemButton_UpdateCooldown(self)
-- Only show cooldowns for live items of the current character
if not self or self.isReadOnly or self.otherChar then return end
local cooldown = getglobal(self:GetName().."Cooldown") or self.cooldown
if not cooldown then return end
if not self.hasItem or not self.bagID or not self.slotID then
cooldown:Hide()
return
end
local start, duration, enable = GetContainerItemCooldown(self.bagID, self.slotID)
if start and duration and duration > 0 and enable == 1 then
if CooldownFrame_SetTimer then
CooldownFrame_SetTimer(cooldown, start, duration, enable)
elseif CooldownFrame_Set then
-- Some clients expose CooldownFrame_Set instead
CooldownFrame_Set(cooldown, start, duration, enable)
else
-- Fallback: show the frame if API missing
cooldown:Show()
end
else
cooldown:Hide()
end
end
-- Set item data
function Guda_ItemButton_SetItem(self, bagID, slotID, itemData, isBank, otherCharName, matchesFilter, isReadOnly)
self.bagID = bagID
@@ -218,12 +247,20 @@ function Guda_ItemButton_SetItem(self, bagID, slotID, itemData, isBank, otherCha
if SetItemButtonTexture then SetItemButtonTexture(self, displayTexture) end
if SetItemButtonCount then SetItemButtonCount(self, displayCount or 1) end
if emptySlotBg then emptySlotBg:Hide() end
-- Update cooldown overlay for live items
if not self.isReadOnly and Guda_ItemButton_UpdateCooldown then
Guda_ItemButton_UpdateCooldown(self)
end
else
-- Fully clear all item button state for empty slots
if SetItemButtonTexture then SetItemButtonTexture(self, nil) end
if SetItemButtonCount then SetItemButtonCount(self, 0) end
if SetItemButtonDesaturated then SetItemButtonDesaturated(self, false) end
-- Ensure cooldown overlay is hidden for empty slots
local cooldown = getglobal(self:GetName().."Cooldown") or self.cooldown
if cooldown and cooldown.Hide then cooldown:Hide() end
-- Also clear the icon texture directly
local iconTexture = getglobal(self:GetName().."IconTexture")
if not iconTexture then