WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   [Classic] Create & show tooltip (https://www.wowinterface.com/forums/showthread.php?t=58649)

MinguasBeef 03-26-21 09:25 AM

[Classic] Create & show tooltip
 
I'm working on my own unit frames.

I want to show a tooltip for the buff at index 1 when I mouse over my frame. I am not seeing anything, however.

Wrote up a simple example to see what i'm doing.

Code:

local f = CreateFrame("Frame", "TestFrame", UIParent)
f:SetWidth(100)
f:SetHeight(100)
f:SetPoint("CENTER")
f.texture = f:CreateTexture("Texture", "Background")
f.texture:SetColorTexture(0.03, 0.03, 0.03, 0.8)
f.texture:SetAllPoints(f)

local tt = CreateFrame("GameTooltip", "MyTooltip", UIParent, "GameTooltipTemplate")
tt:SetOwner(f, "ANCHOR_RIGHT")
tt:Hide()
 
f:SetScript("OnEnter", function()
    if (UnitBuff("player", 1)) then
        tt:SetUnitBuff("player", 1)
        tt:Show()
    end
end)


Fizzlemizz 03-26-21 10:05 AM

You want to anchor the tooltip and you can just use the standard GameTooltip.

Code:

f:SetScript("OnEnter", function(self)
    if (UnitBuff("player", 1)) then
        GameTooltip:SetOwner(self, "ANCHOR_LEFT")
        GameTooltip:SetUnitBuff("player", 1, "HELPFUL")
    end
end)

Just noticed you did anchor the tt but it's best to do it just before you show it because it might have been moved (re-anchored) by another process.

MinguasBeef 03-26-21 11:35 AM

Quote:

Originally Posted by Fizzlemizz (Post 338698)
You want to anchor the tooltip and you can just use the standard GameTooltip.

Code:

f:SetScript("OnEnter", function(self)
    if (UnitBuff("player", 1)) then
        GameTooltip:SetOwner(self, "ANCHOR_LEFT")
        GameTooltip:SetUnitBuff("player", 1, "HELPFUL")
    end
end)

Just noticed you did anchor the tt but it's best to do it just before you show it because it might have been moved (re-anchored) by another process.

Thank you very much for the quick answer! Finally getting back into the swing of working on addons with the tbc announcement. Appreciate the help.


All times are GMT -6. The time now is 10:29 PM.

vBulletin © 2021, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI