WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   Tooltip scanning issues (https://www.wowinterface.com/forums/showthread.php?t=46111)

CobraA1 03-25-13 07:55 PM

Tooltip scanning issues
 
EDIT: Nevermind, I eventually figured it out.

Sigh - I have the following code:

Code:

print("==LOADED==")

MyScanningTooltip = CreateFrame( "GameTooltip", "MyScanningTooltip", nil, "GameTooltipTemplate" ); -- Tooltip name cannot be nil
MyScanningTooltip:SetOwner( WorldFrame, "ANCHOR_NONE" );

MyScanningTooltip:ClearLines()
 

local function EnumerateTooltipLines_helper(...)
  print("EnumerateTooltipLines_helper")
    for i = 1, select("#", ...) do
    print(i)
        local region = select(i, ...)
        if region and region:GetObjectType() == "FontString" then
            local text = region:GetText() -- string or nil
            if text ~= nil then
                print("=="..text.."==")
            else
                print("NIL!")
            end
        end
    end
end

function EnumerateTooltipLines(tooltip) -- good for script handlers that pass the tooltip as the first argument.
    EnumerateTooltipLines_helper(tooltip:GetRegions())
end

MyScanningTooltip:ClearLines()
MyScanningTooltip:SetBagItem(bagID, bagSlotID);
EnumerateTooltipLines_helper(MyScanningTooltip:GetRegions())

Problem is, it returns a lot of nil lines, and I'm not entirely sure how tooltip scanning is supposed to work. Help?

Phanx 03-25-13 11:37 PM

Enumerating regions is not really ideal... not only will it give you things that aren't fontstrings, but it'll give you all the fontstrings in the tooltip, even the ones that aren't in use. Here's a better way:

Code:

for i = 1, MyScanningTooltip:NumLines() do
    local left = _G["MyScanningTooltipTextLeft"..i]
    local text = left:GetText()
    if text and text ~= "" then
        -- do something with the text
    end
end

Also, when using the SetX methods (SetBagItem, SetItem, SetSpell, etc.) it's not necessary to use ClearLines; that happens automatically. The only reason to use ClearLines is to redraw the contents of an open tooltip without reopening it, and I can't really think of any good use-cases for doing that either.


All times are GMT -6. The time now is 08:30 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI