diff --git a/Bagnon_ItemLevel/main.lua b/Bagnon_ItemLevel/main.lua index 7451624..61832f3 100644 --- a/Bagnon_ItemLevel/main.lua +++ b/Bagnon_ItemLevel/main.lua @@ -18,8 +18,8 @@ local ADDON, Addon = MODULE:match("[^_]+"), _G[MODULE:match("[^_]+")] local Module = Bagnon:NewModule("ItemLevel", Addon) -- Tooltip used for scanning -local ScannerTip = _G.BagnonItemInfoScannerTooltip or CreateFrame("GameTooltip", "BagnonItemInfoScannerTooltip", WorldFrame, "GameTooltipTemplate") -local ScannerTipName = ScannerTip:GetName() +local ScannerTipName = "BagnonItemInfoScannerTooltip" +local ScannerTip = _G[ScannerTipName] or CreateFrame("GameTooltip", ScannerTipName, WorldFrame, "GameTooltipTemplate") -- Lua API local _G = _G @@ -31,9 +31,7 @@ local tonumber = tonumber -- WoW API local CreateFrame = _G.CreateFrame -local GetAchievementInfo = _G.GetAchievementInfo -local GetBuildInfo = _G.GetBuildInfo -local GetDetailedItemLevelInfo = _G.GetDetailedItemLevelInfo +local GetDetailedItemLevelInfo = _G.GetDetailedItemLevelInfo local GetItemInfo = _G.GetItemInfo local GetItemQualityColor = _G.GetItemQualityColor local IsArtifactRelicItem = _G.IsArtifactRelicItem @@ -49,28 +47,6 @@ local S_CONTAINER_SLOTS = "^" .. (string.gsub(string.gsub(CONTAINER_SLOTS, "%%([ -- FontString Caches local Cache_ItemLevel = {} ------------------------------------------------------------ --- Utility Functions ------------------------------------------------------------ --- Update our secret scanner tooltip with the current button -local RefreshScanner = function(button) - local bag, slot = button:GetBag(), button:GetID() - ScannerTip.owner = button - ScannerTip.bag = bag - ScannerTip.slot = slot - ScannerTip:SetOwner(button, "ANCHOR_NONE") - ScannerTip:SetBagItem(button:GetBag(), button:GetID()) -end - --- Check if it's a caged battle pet -local GetBattlePetInfo = function(itemLink) - if (string_find(itemLink, "battlepet")) then - local data, name = string_match(itemLink, "|H(.-)|h(.-)|h") - local _, _, level, rarity = string_match(data, "(%w+):(%d+):(%d+):(%d+)") - return true, level or 1, tonumber(rarity) or 0 - end -end - ----------------------------------------------------------- -- Cache & Creation ----------------------------------------------------------- @@ -93,15 +69,11 @@ local Cache_GetItemLevel = function(button) ItemLevel:SetFontObject(_G.NumberFont_Outline_Med or _G.NumberFontNormal) ItemLevel:SetShadowOffset(1, -1) ItemLevel:SetShadowColor(0, 0, 0, .5) - - -- Move Pawn out of the way local UpgradeIcon = button.UpgradeIcon if UpgradeIcon then UpgradeIcon:ClearAllPoints() UpgradeIcon:SetPoint("BOTTOMRIGHT", 2, 0) end - - -- Store the reference for the next time Cache_ItemLevel[button] = ItemLevel end return Cache_ItemLevel[button] @@ -111,103 +83,99 @@ end -- Main Update ----------------------------------------------------------- local Update = function(self) + local displayMsg, displayR, displayG, displayB local itemLink = self:GetItem() - if itemLink then - - -- Get some blizzard info about the current item + if (itemLink) then local itemName, _itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, iconFileDataID, itemSellPrice, itemClassID, itemSubClassID, bindType, expacID, itemSetID, isCraftingReagent = GetItemInfo(itemLink) - local effectiveLevel, previewLevel, origLevel = GetDetailedItemLevelInfo(itemLink) - local isBattlePet, battlePetLevel, battlePetRarity = GetBattlePetInfo(itemLink) - - -- Retrieve the itemID from the itemLink + local isBattlePet, battlePetLevel, battlePetRarity + if (string_find(itemLink, "battlepet")) then + local data, name = string_match(itemLink, "|H(.-)|h(.-)|h") + local _, _, level, rarity = string_match(data, "(%w+):(%d+):(%d+):(%d+)") + isBattlePet, battlePetLevel, battlePetRarity = true, level or 1, tonumber(rarity) or 0 + end local itemID = tonumber(string_match(itemLink, "item:(%d+)")) - --------------------------------------------------- - -- ItemLevel - --------------------------------------------------- if (itemEquipLoc == "INVTYPE_BAG") then - RefreshScanner(self) + local bag,slot = self:GetBag(),self:GetID() + ScannerTip.owner = self + ScannerTip.bag = bag + ScannerTip.slot = slot + ScannerTip:SetOwner(self, "ANCHOR_NONE") + ScannerTip:SetBagItem(bag,slot) - local scannedSlots local line = _G[ScannerTipName.."TextLeft3"] - if line then + if (line) then local msg = line:GetText() - if msg and string_find(msg, S_CONTAINER_SLOTS) then + if (msg) and (string_find(msg, S_CONTAINER_SLOTS)) then local bagSlots = string_match(msg, S_CONTAINER_SLOTS) - if bagSlots and (tonumber(bagSlots) > 0) then - scannedSlots = bagSlots + if (bagSlots) and (tonumber(bagSlots) > 0) then + displayMsg = bagSlots end else line = _G[ScannerTipName.."TextLeft4"] - if line then + if (line) then local msg = line:GetText() - if msg and string_find(msg, S_CONTAINER_SLOTS) then + if (msg) and (string_find(msg, S_CONTAINER_SLOTS)) then local bagSlots = string_match(msg, S_CONTAINER_SLOTS) - if bagSlots and (tonumber(bagSlots) > 0) then - scannedSlots = bagSlots + if (bagSlots) and (tonumber(bagSlots) > 0) then + displayMsg = bagSlots end end end end end - if scannedSlots then - local ItemLevel = Cache_ItemLevel[self] or Cache_GetItemLevel(self) - ItemLevel:SetTextColor(240/255, 240/255, 240/255) - ItemLevel:SetText(scannedSlots) - else - if Cache_ItemLevel[self] then - Cache_ItemLevel[self]:SetText("") - end - end - - -- Display item level of equippable gear and artifact relics + -- Display item level of equippable gear and artifact relics, and battle pet level elseif ((itemRarity and (itemRarity > 0)) and ((itemEquipLoc and _G[itemEquipLoc]) or (itemID and IsArtifactRelicItem(itemID)))) or (isBattlePet) then local scannedLevel if (not isBattlePet) then - RefreshScanner(self) - + local bag,slot = self:GetBag(),self:GetID() + ScannerTip.owner = self + ScannerTip.bag = bag + ScannerTip.slot = slot + ScannerTip:SetOwner(self, "ANCHOR_NONE") + ScannerTip:SetBagItem(bag,slot) + local line = _G[ScannerTipName.."TextLeft2"] - if line then + if (line) then local msg = line:GetText() - if msg and string_find(msg, S_ITEM_LEVEL) then - local ItemLevel = string_match(msg, S_ITEM_LEVEL) - if ItemLevel and (tonumber(ItemLevel) > 0) then - scannedLevel = ItemLevel + if (msg) and (string_find(msg, S_ITEM_LEVEL)) then + local ilvl = (string_match(msg, S_ITEM_LEVEL)) + if (ilvl) and (tonumber(ilvl) > 0) then + scannedLevel = ilvl end else -- Check line 3, some artifacts have the ilevel there line = _G[ScannerTipName.."TextLeft3"] if line then local msg = line:GetText() - if msg and string_find(msg, S_ITEM_LEVEL) then - local ItemLevel = string_match(msg, S_ITEM_LEVEL) - if ItemLevel and (tonumber(ItemLevel) > 0) then - scannedLevel = ItemLevel + if (msg) and (string_find(msg, S_ITEM_LEVEL)) then + local ilvl = (string_match(msg, S_ITEM_LEVEL)) + if (ilvl) and (tonumber(ilvl) > 0) then + scannedLevel = ilvl end end end end end end - - local r, g, b = GetItemQualityColor(battlePetRarity or itemRarity) - local ItemLevel = Cache_ItemLevel[self] or Cache_GetItemLevel(self) - ItemLevel:SetTextColor(r, g, b) - ItemLevel:SetText(scannedLevel or battlePetLevel or effectiveLevel or itemLevel or "") - - else - if Cache_ItemLevel[self] then - Cache_ItemLevel[self]:SetText("") - end + displayR, displayG, displayB = GetItemQualityColor(battlePetRarity or itemRarity) + displayMsg = scannedLevel or battlePetLevel or GetDetailedItemLevelInfo(itemLink) or itemLevel or "" end + end - else - if Cache_ItemLevel[self] then - Cache_ItemLevel[self]:SetText("") + if (displayMsg) then + local ItemLevel = Cache_ItemLevel[self] or Cache_GetItemLevel(self) + if (displayR) and (displayG) and (displayB) then + ItemLevel:SetTextColor(displayR, displayG, displayB) + else + ItemLevel:SetTextColor(240/255, 240/255, 240/255) end - end + ItemLevel:SetText(displayMsg) + elseif (Cache_ItemLevel[self]) then + Cache_ItemLevel[self]:SetText("") + end end local item = Bagnon.ItemSlot or Bagnon.Item diff --git a/CHANGELOG.md b/CHANGELOG.md index 95b65d0..2b1c09c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [1.0.36-Release] 2021-04-29 +### Changed +- Optimized code and efficiency. +- Removed some unused function calls. + ## [1.0.35-Release] 2021-04-05 - Spring cleaning.