Quantcast
WoWInterface - View Single Post - Upgraded items and GetItemInfo()
View Single Post
12-07-12, 05:00 AM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Something like:

Code:
-- Construct your saarch pattern based on the existing global string:
local S_UPGRADE_LEVEL   = "^" .. gsub(ITEM_UPGRADE_TOOLTIP_FORMAT, "%%d", "(%%d+)")

-- Create the tooltip:
local scantip = CreateFrame("GameTooltip", "MyScanningTooltip", nil, "GameTooltipTemplate")
scantip:SetOwner(UIParent, "ANCHOR_NONE")

-- Create a function for simplicity's sake:
local function GetItemUpgradeLevel(itemLink)
    -- Pass the item link to the tooltip:
    scantip:SetHyperlink(itemLink)

    -- Scan the tooltip:
    for i = 2, scantip:NumLines() do -- Line 1 is always the name so you can skip it.
        local text = _G["MyScanningTooltipTextLeft"..i]:GetText()
        if text and text ~= "" then
            local currentUpgradeLevel, maxUpgradeLevel = strmatch(text, S_UPGRADE_LEVEL)
            if currentUpgradeLevel then
                return currentUpgradeLevel, maxUpgradeLevel
            end
        end
    end
end

-- Now you can just call the function to get the levels:
local currentUpgradeLevel, maxUpgradeLevel = GetItemUpgradeLevel(itemLink)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Donít message me about addon bugs or programming questions.