From ca2d17bf7788b592958b0adc301a9d5bafcad8d9 Mon Sep 17 00:00:00 2001 From: Antonio Lobato Date: Sat, 24 Feb 2024 21:17:29 -0800 Subject: [PATCH] Fixed a bug in pawn arrow's that would cause them to be inconsistent when equipping items. (#228) --- frames/bag.lua | 1 + integrations/pawn.lua | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/frames/bag.lua b/frames/bag.lua index 7c251799..aa3ddf24 100644 --- a/frames/bag.lua +++ b/frames/bag.lua @@ -218,6 +218,7 @@ function bagFrame.bagProto:Draw(dirtyItems) local text = search:GetText() self:Search(text) self:OnResize() + events:SendMessage('bag/Rendered', self) end function bagFrame.bagProto:KeepBagInBounds() diff --git a/integrations/pawn.lua b/integrations/pawn.lua index 16e00aaf..f2fc0fa2 100644 --- a/integrations/pawn.lua +++ b/integrations/pawn.lua @@ -9,21 +9,19 @@ local events = addon:GetModule('Events') ---@class Pawn: AceModule local pawn = addon:NewModule('Pawn') ----@param event string ---@param item Item -local function onItemUpdateRetail(event, item) +local function onItemUpdateRetail(item) local bagid, slotid = item.data.bagid, item.data.slotid - if item.data.isItemEmpty or event == 'item/Clearing' or not bagid or not slotid then + if item.data.isItemEmpty or not bagid or not slotid then item.button.UpgradeIcon:SetShown(false) else item.button.UpgradeIcon:SetShown(PawnIsContainerItemAnUpgrade(bagid, slotid) or false) end end ----@param event string ---@param item Item -local function onItemUpdateClassic(event, item) - if item.data.isItemEmpty or event == 'item/Clearing' or not item.data.slotid or not item.data.bagid then +local function onItemUpdateClassic(item) + if item.data.isItemEmpty or not item.data.slotid or not item.data.bagid then item.button.UpgradeIcon:SetShown(false) else local isUpgrade = PawnShouldItemLinkHaveUpgradeArrow(item.data.itemInfo.itemLink) @@ -31,14 +29,21 @@ local function onItemUpdateClassic(event, item) end end +---@param bag Bag +local function onBagRendered(_, bag) + for _, item in pairs(bag.currentView.itemsByBagAndSlot) do + if addon.isRetail then + onItemUpdateRetail(item) + else + onItemUpdateClassic(item) + end + end +end + function pawn:OnEnable() if not PawnIsContainerItemAnUpgrade and not PawnGetItemData then return end + events:RegisterMessage('bag/Rendered', onBagRendered) print("BetterBags: Pawn integration enabled.") - if addon.isRetail then - events:RegisterMessage('item/Updated', onItemUpdateRetail) - else - events:RegisterMessage('item/Updated', onItemUpdateClassic) - end end \ No newline at end of file