Thread Tools Display Modes
03-26-21, 09:25 AM   #1
MinguasBeef
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: May 2019
Posts: 51
[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)
  Reply With Quote
03-26-21, 10:05 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
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.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 03-26-21 at 10:28 AM.
  Reply With Quote
03-26-21, 11:35 AM   #3
MinguasBeef
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: May 2019
Posts: 51
Originally Posted by Fizzlemizz View Post
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.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » [Classic] Create & show tooltip

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off