diff --git a/annotations.lua b/annotations.lua index 1a05aa9..888fa3d 100644 --- a/annotations.lua +++ b/annotations.lua @@ -10,6 +10,8 @@ ---@field BattlepayItemTexture Texture ---@field IconBorder Texture ---@field UpgradeIcon Texture +---@field flashAnim AnimationGroup +---@field newitemglowAnim AnimationGroup local itemButton = {} ---@param bagid number @@ -44,6 +46,9 @@ function itemButton:SetItemButtonQuality(quality) end function itemButton:HasItem() end +---@return Enum.BagIndex +function itemButton:GetBagID() end + ---@class Button local Button = {} diff --git a/data/items.lua b/data/items.lua index 123449e..3a97026 100644 --- a/data/items.lua +++ b/data/items.lua @@ -78,6 +78,7 @@ local itemDataProto = {} ---@field _newItemTimers table ---@field _preSort boolean ---@field _refreshQueueEvent EventArg[] +---@field _firstLoad table local items = addon:NewModule('Items') function items:OnInitialize() @@ -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() @@ -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) @@ -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 @@ -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) @@ -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) diff --git a/frames/item.lua b/frames/item.lua index 41e7dcd..ffab12a 100644 --- a/frames/item.lua +++ b/frames/item.lua @@ -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) @@ -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) diff --git a/views/bagview.lua b/views/bagview.lua index 7c98b50..fbc3118 100644 --- a/views/bagview.lua +++ b/views/bagview.lua @@ -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')