Skip to content

Commit

Permalink
Correctly detect new items that are wrapped (#653)
Browse files Browse the repository at this point in the history
* Added support for adding new items manually

* Changed items (wrapping paper, enchants, etc) now glow as new items.

* Correctly detect wrapped items/items with texture changes.

Co-authored-by: Antonio Lobato <[email protected]>
  • Loading branch information
Cidan and Antonio Lobato authored Aug 23, 2022
1 parent 72e2552 commit ebddb57
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
5 changes: 5 additions & 0 deletions modules/NewItemTracking.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ function mod:OnEnable()
end

self:RegisterMessage('AdiBags_UpdateButton', 'UpdateButton')
self:RegisterMessage('AdiBags_AddNewItem', 'AddNewItem')
self:RegisterEvent('BAG_NEW_ITEMS_UPDATED')
end

Expand Down Expand Up @@ -124,6 +125,10 @@ function mod:UpdateModuleButton()
self.button:SetEnabled(next(newItems) or self.container.ToSortSection:IsShown())
end

function mod:AddNewItem(event, link)
newItems[link] = true
end

--------------------------------------------------------------------------------
-- Filtering
--------------------------------------------------------------------------------
Expand Down
30 changes: 25 additions & 5 deletions widgets/ContainerFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ function containerProto:OnCreate(name, isBank, bagObject)
self.added = {}
self.removed = {}
self.changed = {}
self.sameChanged = {}

local ids
for bagId in pairs(BAG_IDS[isBank and "BANK" or "BAGS"]) do
Expand Down Expand Up @@ -604,7 +605,7 @@ end

function containerProto:UpdateContent(bag)
self:Debug('UpdateContent', bag)
local added, removed, changed = self.added, self.removed, self.changed
local added, removed, changed, sameChanged = self.added, self.removed, self.changed, self.sameChanged
local content = self.content[bag]
local newSize = self:GetBagIds()[bag] and GetContainerNumSlots(bag) or 0
local _, bagFamily = GetContainerNumFreeSlots(bag)
Expand Down Expand Up @@ -632,6 +633,11 @@ function containerProto:UpdateContent(bag)
if not name then
name, _, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemId)
end
-- Correctly catch battlepets and store their name.
if string.match(link, "|Hbattlepet:") then
local _, speciesID = strsplit(":", link)
name = C_PetJournal.GetPetInfoBySpeciesID(speciesID)
end
count = select(2, GetContainerItemInfo(bag, slot)) or 0
else
link, count = false, 0
Expand All @@ -640,6 +646,7 @@ function containerProto:UpdateContent(bag)
if slotData.link ~= link or slotData.texture ~= texture then
local prevSlotId = slotData.slotId
local prevLink = slotData.link
local prevTexture = slotData.texture
-- If links only differ in character level that's the same item
local sameItem = addon.IsSameLinkButLevel(slotData.link, link)

Expand All @@ -649,8 +656,15 @@ function containerProto:UpdateContent(bag)
slotData.name, slotData.quality, slotData.iLevel, slotData.reqLevel, slotData.class, slotData.subclass, slotData.equipSlot, slotData.texture, slotData.vendorPrice = name, quality, iLevel, reqLevel, class, subclass, equipSlot, texture, vendorPrice
slotData.maxStack = maxStack or (link and 1 or 0)

if sameItem and slotData.texture ~= texture then
changed[slotData.slotId] = slotData
if sameItem then
-- Items that are the same item but have mutated are marked as "new" to make them more visble.
-- However, only things with a new texture are marked as new, i.e. wrapped items.
if prevTexture ~= texture then
sameChanged[slotData.slotId] = slotData
addon:SendMessage('AdiBags_AddNewItem', slotData.link)
else
changed[slotData.slotId] = slotData
end
else
removed[prevSlotId] = prevLink
added[slotData.slotId] = slotData
Expand All @@ -672,7 +686,7 @@ function containerProto:UpdateContent(bag)
end

function containerProto:HasContentChanged()
return not not (next(self.added) or next(self.removed) or next(self.changed))
return not not (next(self.added) or next(self.removed) or next(self.changed) or next(self.sameChanged))
end

--------------------------------------------------------------------------------
Expand Down Expand Up @@ -810,7 +824,7 @@ function containerProto:UpdateButtons()
end
self:Debug('UpdateButtons')

local added, removed, changed = self.added, self.removed, self.changed
local added, removed, changed, sameChanged = self.added, self.removed, self.changed, self.sameChanged
self:SendMessage('AdiBags_PreContentUpdate', self, added, removed, changed)

for slotId in pairs(removed) do
Expand All @@ -829,11 +843,17 @@ function containerProto:UpdateButtons()
for slotId in pairs(changed) do
buttons[slotId]:FullUpdate()
end

for slotId, slotData in pairs(sameChanged) do
self:DispatchItem(slotData)
buttons[slotId]:FullUpdate()
end

self:SendMessage('AdiBags_PostContentUpdate', self, added, removed, changed)
wipe(added)
wipe(removed)
wipe(changed)
wipe(sameChanged)

self:ResizeToSortSection()
end
Expand Down

0 comments on commit ebddb57

Please sign in to comment.