diff --git a/Cache.lua b/Cache.lua index 844557e..1816fed 100644 --- a/Cache.lua +++ b/Cache.lua @@ -36,6 +36,7 @@ function cache:CacheItemInfo(itemID, loadedCallback) self.itemInfo[itemID] = { name = itemInfo[1], link = itemInfo[2], + quality = itemInfo[3], icon = itemInfo[10], type = itemInfo[12], subType = itemInfo[13], diff --git a/Core.lua b/Core.lua index a022491..81d68cc 100644 --- a/Core.lua +++ b/Core.lua @@ -57,7 +57,7 @@ local function itemListInitializer(frame, data) if not self.Extract then return end local info = self.Extract.info if not info then return end - if info.locType ~= "SOCKET" then return end + if info.locType ~= "EQUIP_SOCKET" then return end uiElements:HighlightEquipmentSlot(info.locIndex) end end) @@ -99,25 +99,22 @@ local function itemListInitializer(frame, data) else frame.Name:SetFontObject(const.FONT_OBJECTS.NORMAL) local exInf = data.info - if exInf and exInf.type ~= "UNCOLLECTED" then + if exInf and exInf.locType ~= "UNCOLLECTED" then frame.Icon:SetDesaturated(false) frame.Extract:Show() - frame.Extract:UpdateInfo( - exInf.type, - exInf.index, - exInf.slot, - exInf.gemType - ) + frame.Extract:UpdateInfo(exInf) else frame.Icon:SetDesaturated(true) frame.Extract:Hide() end local state, color - if exInf.type == "SOCKET" then + if exInf.locType == "EQUIP_SOCKET" then state, color = "Socketed", const.COLORS.POSITIVE - elseif exInf.type == "BAG" then - state, color = "In Bag", const.COLORS.NEGATIVE + elseif exInf.locType == "BAG_GEM" then + state, color = "In Bag", const.COLORS.NEUTRAL + elseif exInf.locType == "BAG_SOCKET" then + state, color = "In Bag Item!", const.COLORS.NEGATIVE else state, color = "Uncollected", const.COLORS.GREY name = color:WrapTextInColorCode(name) @@ -248,7 +245,6 @@ local function createFrame() local scrollView = CreateScrollBoxListLinearView() scrollView:SetElementInitializer("BackDropTemplate", itemListInitializer) ScrollUtil.InitScrollBoxListWithScrollBar(scrollBox, scrollBar, scrollView) - scrollView:SetElementExtent(25) function scrollView:UpdateTree(data) diff --git a/GemUtil.lua b/GemUtil.lua index 1624380..a0e1258 100644 --- a/GemUtil.lua +++ b/GemUtil.lua @@ -72,25 +72,46 @@ function gemUtil:GetSocketsInfo(socketTypeName) return usedSlots, maxSlots, freeEquipmentSlot, freeSocketSlot end ----@param itemInfo table ----@param locType "BAG"|"SOCKET" ----@param locIndex integer ----@param locSlot integer -function gemUtil:AddGemData(itemInfo, locType, locIndex, locSlot) - ---@cast itemInfo ContainerItemInfo - if not itemInfo then return end +---@class GemItemInfo +---@field hyperlink string +---@field stackCount number +---@field itemID number + +---@param dataTable table +---@param itemInfo GemItemInfo|ContainerItemInfo +---@param locType "BAG_GEM"|"BAG_SOCKET"|"EQUIP_SOCKET"|"UNCOLLECTED" +---@param locIndex integer|? +---@param locSlot integer|? +function gemUtil:AddGemData(dataTable, itemInfo, locType, locIndex, locSlot) + if type(itemInfo) ~= "table" then return end local itemType = select(6, C_Item.GetItemInfoInstant(itemInfo.hyperlink)) if itemType == 3 and self:GetGemSocketType(itemInfo.itemID) then for i = 1, itemInfo.stackCount do - tinsert(self.owned_gems, { + tinsert(dataTable, { itemID = itemInfo.itemID, - type = locType, - index = locIndex, - slot = locSlot, + locType = locType, + locIndex = locIndex, + locSlot = locSlot, gemType = self:GetSocketTypeName(self:GetGemSocketType(itemInfo.itemID)), }) Private.Cache:CacheItemInfo(itemInfo.itemID) end + else + local gems = self:GetItemGems(itemInfo.hyperlink) + if #gems < 1 then return end + for _, gemID in ipairs(gems) do + if type(gemID) == "number" then + local cacheInfo = Private.Cache:GetItemInfo(gemID) + local hyperlink = cacheInfo.link + if hyperlink then + self:AddGemData(dataTable, { + itemID = gemID, + stackCount = 1, + hyperlink = hyperlink, + }, "BAG_SOCKET", locIndex, locSlot) + end + end + end end end @@ -98,7 +119,7 @@ function gemUtil:RefreshOwnedGems() wipe(self.owned_gems) for bag = BACKPACK_CONTAINER, NUM_TOTAL_EQUIPPED_BAG_SLOTS do for slot = 1, C_Container.GetContainerNumSlots(bag) do - self:AddGemData(C_Container.GetContainerItemInfo(bag, slot), "BAG", bag, slot) + self:AddGemData(self.owned_gems, C_Container.GetContainerItemInfo(bag, slot), "BAG_GEM", bag, slot) end end for _, itemSlot in ipairs(const.SOCKET_EQUIPMENT_SLOTS) do @@ -110,12 +131,12 @@ function gemUtil:RefreshOwnedGems() for gemIndex = 1, 3 do local gemName, gemLink = C_Item.GetItemGem(itemLink, gemIndex) if gemName and gemLink then - self:AddGemData({ + self:AddGemData(self.owned_gems, { itemName = gemName, itemID = C_Item.GetItemInfoInstant(gemLink), stackCount = 1, hyperlink = gemLink - }, "SOCKET", itemSlot, gemIndex) + }, "EQUIP_SOCKET", itemSlot, gemIndex) end end end @@ -157,49 +178,54 @@ local function isMatchingFilter(itemID, filter) return false end ----@param category string|number|? +---@param socketTypeFilter string|number|? ---@param nameFilter string|? ---@return table -function gemUtil:GetFilteredGems(category, nameFilter) +function gemUtil:GetFilteredGems(socketTypeFilter, nameFilter) local validGems = {} self:RefreshOwnedGems() if nameFilter then nameFilter = nameFilter:lower() end - if type(category) == "number" then - category = self:GetSocketTypeName(category) + if type(socketTypeFilter) == "number" then + socketTypeFilter = self:GetSocketTypeName(socketTypeFilter) end - category = category or "ALL" - category = category:upper() + socketTypeFilter = socketTypeFilter or "ALL" + socketTypeFilter = socketTypeFilter:upper() for _, socketType in ipairs(const.SOCKET_TYPES_INDEX) do validGems[socketType] = {} end for _, gemInfo in pairs(self.owned_gems) do - local gemCategory = self:GetGemSocketType(gemInfo.itemID) - if category == "ALL" or gemCategory == category then - if gemCategory ~= "PRIMORDIAL" or Private.Settings:GetSetting("show_primordial") then + local gemType = self:GetGemSocketType(gemInfo.itemID) + if socketTypeFilter == "ALL" or gemType == socketTypeFilter then + if gemType ~= "PRIMORDIAL" or Private.Settings:GetSetting("show_primordial") then if isMatchingFilter(gemInfo.itemID, nameFilter) then - tinsert(validGems[gemCategory], gemInfo) + tinsert(validGems[gemType], gemInfo) end end end end if Private.Settings:GetSetting("show_unowned") then - for gemItemID, gemCategory in pairs(const.GEM_SOCKET_TYPE) do - if category == "ALL" or gemCategory == category then + for gemItemID, gemType in pairs(const.GEM_SOCKET_TYPE) do + if socketTypeFilter == "ALL" or gemType == socketTypeFilter then if isMatchingFilter(gemItemID, nameFilter) then local dupeID = false - for _, gemInf in ipairs(self.owned_gems) do - if gemInf.itemID == gemItemID then + for _, gemInfo in ipairs(self.owned_gems) do + if gemInfo.itemID == gemItemID then dupeID = true break end end - if (not dupeID) and (gemCategory ~= "PRIMORDIAL" or Private.Settings:GetSetting("show_primordial")) then - tinsert(validGems[gemCategory], { - itemID = gemItemID, - type = "UNCOLLECTED", - gemType = self:GetSocketTypeName(gemCategory), - }) + if (not dupeID) and (gemType ~= "PRIMORDIAL" or Private.Settings:GetSetting("show_primordial")) then + local cacheInfo = Private.Cache:GetItemInfo(gemItemID) + local hyperlink = cacheInfo.link + if hyperlink then + self:AddGemData(validGems[gemType], + { + itemID = gemItemID, + stackCount = 1, + hyperlink = hyperlink + }, "UNCOLLECTED") + end end end end diff --git a/UIElements.lua b/UIElements.lua index b7e39e8..0f5dcb3 100644 --- a/UIElements.lua +++ b/UIElements.lua @@ -10,9 +10,11 @@ local function extractPreClick(self) if not misc:IsAllowedForClick("EXTRACT_PRECLICK") then return end if not self.info then return end local info = self.info - if info.locType == "SOCKET" then + if info.locType == "EQUIP_SOCKET" then SocketInventoryItem(info.locIndex) - elseif info.locType == "BAG" then + elseif info.locType == "BAG_SOCKET" then + C_Container.SocketContainerItem(info.locIndex, info.locSlot) + elseif info.locType == "BAG_GEM" then local equipSlot, equipSocket = select(3, gemUtil:GetSocketsInfo(info.gemType)) C_Container.PickupContainerItem(info.locIndex, info.locSlot) SocketInventoryItem(equipSlot) @@ -24,7 +26,7 @@ local function extractPostClick(self) if not misc:IsAllowedForClick("EXTRACT_POSTCLICK") then return end if not self.info then return end local info = self.info - if info.locType == "BAG" then + if info.locType == "BAG_GEM" then ClearCursor() if not info.freeSlot then misc:PrintError("You don't have a valid free Slot for this Gem") @@ -39,7 +41,7 @@ local function extractPostClick(self) end function uiElements:CreateExtractButton(parent) ---@class ExtractButton : Button - ---@field UpdateInfo fun(self:ExtractButton, infoType:"BAG_GEM"|"BAG_SOCKET"|"EQUIP_SOCKET", infoIndex:number, infoSlot:number, infoGemType:"Meta"|"Cogwheel"|"Tinker"|"Prismatic"|"Primordial") + ---@field UpdateInfo fun(self:ExtractButton, infoType:"BAG_GEM"|"BAG_SOCKET"|"EQUIP_SOCKET"|table, infoIndex:number|?, infoSlot:number|?, infoGemType:"Meta"|"Cogwheel"|"Tinker"|"Prismatic"|"Primordial"|?) local extractButton = CreateFrame("Button", nil, parent, "InsecureActionButtonTemplate") extractButton:SetAllPoints() extractButton:SetScript("PreClick", extractPreClick) @@ -49,21 +51,26 @@ function uiElements:CreateExtractButton(parent) extractButton:SetAttribute("type", "macro") function extractButton:UpdateInfo(newType, newIndex, newSlot, newGemType) - self.info = { - locType = newType, - locIndex = newIndex, - locSlot = newSlot, - gemType = newGemType, - - gemSlot = 0, - } + if type(newType) == "table" then + self.info = newType + else + self.info = { + locType = newType, + locIndex = newIndex, + locSlot = newSlot, + gemType = newGemType, + gemSlot = 0, + } + end + local locType = self.info.locType + local locSlot = self.info.locSlot local txt = "" - if newType == "SOCKET" then + if locType == "EQUIP_SOCKET" or locType == "BAG_SOCKET" then txt = "/cast " .. const.EXTRACT_GEM_SPELL - if newSlot == "Primordial" then + if locSlot == "Primordial" then txt = "/click ExtraActionButton1" end - txt = string.format("%s\n/click ItemSocketingSocket%s", txt, newSlot) + txt = string.format("%s\n/click ItemSocketingSocket%s", txt, locSlot) end self:SetAttribute("macrotext", txt) end