Skip to content

Commit

Permalink
All new items coming into bags now go to recent items and glow (inclu…
Browse files Browse the repository at this point in the history
…ding bank, containers, etc).

Bag view is now always sorted correctly.
  • Loading branch information
Cidan committed May 19, 2024
1 parent c88956b commit ab1b0f3
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
5 changes: 5 additions & 0 deletions annotations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
---@field BattlepayItemTexture Texture
---@field IconBorder Texture
---@field UpgradeIcon Texture
---@field flashAnim AnimationGroup
---@field newitemglowAnim AnimationGroup
local itemButton = {}

---@param bagid number
Expand Down Expand Up @@ -44,6 +46,9 @@ function itemButton:SetItemButtonQuality(quality) end

function itemButton:HasItem() end

---@return Enum.BagIndex
function itemButton:GetBagID() end

---@class Button
local Button = {}

Expand Down
27 changes: 26 additions & 1 deletion data/items.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ local itemDataProto = {}
---@field _newItemTimers table<string, number>
---@field _preSort boolean
---@field _refreshQueueEvent EventArg[]
---@field _firstLoad table<BagKind, boolean>
local items = addon:NewModule('Items')

function items:OnInitialize()
Expand All @@ -87,6 +88,11 @@ function items:OnInitialize()
self._newItemTimers = {}
self._preSort = false
self._doingRefresh = false
self._firstLoad = {
[const.BAG_KIND.BACKPACK] = true,
[const.BAG_KIND.BANK] = true,
[const.BAG_KIND.REAGENT_BANK] = true,
}
end

function items:OnEnable()
Expand Down Expand Up @@ -132,6 +138,9 @@ function items:OnEnable()
events:RegisterMessage('bags/SortBackpack', function()
self:RemoveNewItemFromAllItems()
self:ClearItemCache()
self._firstLoad[const.BAG_KIND.BACKPACK] = true
self._firstLoad[const.BAG_KIND.BANK] = true
self._firstLoad[const.BAG_KIND.REAGENT_BANK] = true
self:PreSort()
C_Container:SortBags()
end)
Expand Down Expand Up @@ -462,7 +471,10 @@ function items:LoadItems(kind, wipe, dataCache, reagent)
-- Process item changes.
if items:ItemAdded(currentItem, previousItem) then
debug:Log("ItemAdded", currentItem.itemInfo.itemLink)
slotInfo.addedItems[currentItem.slotkey] = currentItem
slotInfo.addedItems[currentItem.slotkey] = currentItem
if not wipe and addon.isRetail then
self:MarkItemAsNew(currentItem)
end
elseif items:ItemRemoved(currentItem, previousItem) then
debug:Log("ItemRemoved", previousItem.itemInfo.itemLink)
slotInfo.removedItems[previousItem.slotkey] = previousItem
Expand Down Expand Up @@ -507,6 +519,10 @@ end
---@param container ItemLoader
function items:ProcessContainer(kind, wipe, container)
container:Load(function()
if not wipe and self._firstLoad[kind] == true then
self._firstLoad[kind] = false
wipe = true
end
if kind == const.BAG_KIND.REAGENT_BANK then
kind = const.BAG_KIND.BANK
self:LoadItems(kind, wipe, container:GetDataCache(), true)
Expand Down Expand Up @@ -582,6 +598,15 @@ function items:ClearNewItems()
wipe(self._newItemTimers)
end

---@param data ItemData
function items:MarkItemAsNew(data)
if data and data.itemInfo and data.itemInfo.itemGUID and self._newItemTimers[data.itemInfo.itemGUID] == nil then
self._newItemTimers[data.itemInfo.itemGUID] = time()
data.itemInfo.isNewItem = true
data.itemInfo.category = self:GetCategory(data)
end
end

---@param link string
---@return ItemLinkInfo
function items:ParseItemLink(link)
Expand Down
34 changes: 33 additions & 1 deletion frames/item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ function itemFrame.itemProto:SetItemFromData(data)
--self:SetLock(data.itemInfo.isLocked)
self.button:UpdateExtended()
self.button:UpdateQuestItem(isQuestItem, questID, isActive)
self.button:UpdateNewItem(data.itemInfo.itemQuality)
self:UpdateNewItem(data.itemInfo.itemQuality)
self.button:UpdateJunkItem(data.itemInfo.itemQuality, noValue)
self.button:UpdateItemContextMatching()
self.button:UpdateCooldown(data.itemInfo.itemIcon)
Expand All @@ -391,6 +391,38 @@ function itemFrame.itemProto:SetItemFromData(data)
self.button:Show()
end

function itemFrame.itemProto:UpdateNewItem(quality)
if(not self.button.BattlepayItemTexture and not self.NewItemTexture) then
return
end

if items:IsNewItem(self:GetItemData()) then
if C_Container.IsBattlePayItem(self.button:GetBagID(), self.button:GetID()) then
self.button.NewItemTexture:Hide()
self.button.BattlepayItemTexture:Show();
else
if (quality and NEW_ITEM_ATLAS_BY_QUALITY[quality]) then
self.button.NewItemTexture:SetAtlas(NEW_ITEM_ATLAS_BY_QUALITY[quality]);
else
self.button.NewItemTexture:SetAtlas("bags-glow-white");
end
self.button.BattlepayItemTexture:Hide();
self.button.NewItemTexture:Show();
end
if (not self.button.flashAnim:IsPlaying() and not self.button.newitemglowAnim:IsPlaying()) then
self.button.flashAnim:Play();
self.button.newitemglowAnim:Play();
end
else
self.button.BattlepayItemTexture:Hide();
self.button.NewItemTexture:Hide();
if (self.button.flashAnim:IsPlaying() or self.button.newitemglowAnim:IsPlaying()) then
self.button.flashAnim:Stop();
self.button.newitemglowAnim:Stop();
end
end
end

function itemFrame.itemProto:ResetSize()
self:SetSize(37, 37)
self.button.NormalTexture:SetSize(64, 64)
Expand Down
2 changes: 1 addition & 1 deletion views/bagview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ local function BagView(view, bag, slotInfo)
end
view.content.maxCellWidth = sizeInfo.columnCount
-- Sort the sections.
view.content:Sort(sort:GetSectionSortFunction(bag.kind, const.BAG_VIEW.SECTION_GRID))
view.content:Sort(sort.SortSectionsAlphabetically)
debug:StartProfile('Content Draw Stage')
local w, h = view.content:Draw()
debug:EndProfile('Content Draw Stage')
Expand Down

0 comments on commit ab1b0f3

Please sign in to comment.