diff --git a/BetterBags.toc b/BetterBags.toc index abc79038..729290ae 100644 --- a/BetterBags.toc +++ b/BetterBags.toc @@ -37,8 +37,8 @@ debug\frames.lua theme\masque.lua -data\items.lua data\equipmentsets.lua +data\items.lua data\categories.lua util\color.lua diff --git a/annotations.lua b/annotations.lua index aa041d8c..fff1a852 100644 --- a/annotations.lua +++ b/annotations.lua @@ -151,6 +151,10 @@ function MinimalScrollBar:SetInterpolateScroll(interpolate) end ---@class EventFrame local EventFrame = {} +---@param location number +---@return boolean, boolean, boolean, boolean, number, number +function EquipmentManager_UnpackLocation(location) end + -- ItemInfo is the information about an item that is returned by GetItemInfo. ---@class (exact) ExpandedItemInfo ---@field itemID number @@ -182,6 +186,7 @@ local EventFrame = {} ---@field currentItemCount number ---@field category string ---@field currentItemLevel number +---@field equipmentSet string|nil --[[ ---@class ItemMixin diff --git a/data/equipmentsets.lua b/data/equipmentsets.lua index 979d311f..4c6f592f 100644 --- a/data/equipmentsets.lua +++ b/data/equipmentsets.lua @@ -4,42 +4,42 @@ local addonName = ... ---@type string local addon = LibStub('AceAddon-3.0'):GetAddon(addonName) ---@class EquipmentSets: AceModule ----@field itemToSet table +---@field bagAndSlotToSet table> local equipmentSets = addon:NewModule('EquipmentSets') ---@class Events: AceModule local events = addon:GetModule('Events') ----@class Items: AceModule -local items = addon:GetModule('Items') - function equipmentSets:OnInitialize() - self.itemToSet = {} + self.bagAndSlotToSet = {} end function equipmentSets:OnEnable() - events:RegisterEvent('EQUIPMENT_SETS_CHANGED', function() self:Update() end) self:Update() end function equipmentSets:Update() - wipe(self.itemToSet) + wipe(self.bagAndSlotToSet) local sets = C_EquipmentSet.GetEquipmentSetIDs() for _, setID in ipairs(sets) do local setName = C_EquipmentSet.GetEquipmentSetInfo(setID) - local itemIDs = C_EquipmentSet.GetItemIDs(setID) - for _, itemID in ipairs(itemIDs) do - self.itemToSet[itemID] = setName + local setLocations = C_EquipmentSet.GetItemLocations(setID) + for _, location in ipairs(setLocations) do + local _, bank, bags, _, slot, bag = EquipmentManager_UnpackLocation(location) + if (bank or bags) and slot ~= nil and bag ~= nil then + self.bagAndSlotToSet[bag] = self.bagAndSlotToSet[bag] or {} + self.bagAndSlotToSet[bag][slot] = setName + end end end - items:RefreshAll() end ----@param itemID number|nil +---@param bagid number +---@param slotid number ---@return string|nil -function equipmentSets:GetItemSet(itemID) - if not itemID then return nil end - return self.itemToSet[itemID] +function equipmentSets:GetItemSet(bagid, slotid) + if not bagid or not slotid then return nil end + return self.bagAndSlotToSet[bagid] and self.bagAndSlotToSet[bagid][slotid] end equipmentSets:Enable() \ No newline at end of file diff --git a/data/items.lua b/data/items.lua index b4a512da..b6f52371 100644 --- a/data/items.lua +++ b/data/items.lua @@ -9,6 +9,9 @@ local events = addon:GetModule('Events') ---@class Constants: AceModule local const = addon:GetModule('Constants') +---@class EquipmentSets: AceModule +local equipmentSets = addon:GetModule('EquipmentSets') + ---@class Debug: AceModule local debug = addon:GetModule('Debug') @@ -41,6 +44,7 @@ end function items:OnEnable() --events:RegisterMessage('items/RefreshAllItems/Done', printDirtyItems) --events:RegisterEvent('BAG_UPDATE_DELAYED', self.RefreshAll, self) + events:RegisterEvent('EQUIPMENT_SETS_CHANGED', function() self:RefreshAll() end) events:BucketEvent('BAG_UPDATE_DELAYED', function() self:RefreshAll() end) events:RegisterEvent('BANKFRAME_OPENED', self.RefreshBank, self) end @@ -74,6 +78,7 @@ function items:RefreshReagentBank() end function items:RefreshBank() + equipmentSets:Update() self._bankContainer = ContinuableContainer:Create() -- This is a small hack to force the bank bag quality data to be cached @@ -100,6 +105,7 @@ function items:RefreshBackpack() if self._doingRefreshAll then return end + equipmentSets:Update() self._doingRefreshAll = true self._container = ContinuableContainer:Create() wipe(self.dirtyItems) @@ -195,6 +201,7 @@ function items:AttachItemInfo(data) currentItemCount = C_Item.GetStackCount(itemLocation), category = "", currentItemLevel = C_Item.GetCurrentItemLevel(itemLocation) --[[@as number]], + equipmentSet = equipmentSets:GetItemSet(bagid, slotid), } end diff --git a/frames/item.lua b/frames/item.lua index 0c72654e..ee1cab9b 100644 --- a/frames/item.lua +++ b/frames/item.lua @@ -204,9 +204,8 @@ function itemProto:GetCategory() end -- Check for equipment sets next. - local equipmentSet = equipmentSets:GetItemSet(self.data.itemInfo.itemID) - if equipmentSet then - self.data.itemInfo.category = "Gear: " .. equipmentSet + if self.data.itemInfo.equipmentSet then + self.data.itemInfo.category = "Gear: " .. self.data.itemInfo.equipmentSet return self.data.itemInfo.category end