Modcraft - The community dedicated to quality WoW modding!
Wrath of the Lich King Modding => Serverside Modding => Topic started by: jeaks on December 08, 2016, 05:49:34 pm
-
I recently compiled Eluna and I'm using AIO with it to create some nice scripts.
I made a frame with a spell's icon and I want to show its tooltip on mouse hover but I can't find the function for it. ( except for GameTooltip:GetSpellById() which doesn't do anything )
My work so far:
local SpellName1,SpellRank1,SpellIcon1,SpellCost1 = GetSpellInfo(168)
local imgSpellIcon1 = CreateFrame("Button", "imgSpellIcon1", frameAttributes, nil)
imgSpellIcon1:SetSize(50, 50)
imgSpellIcon1:SetPoint("TOPLEFT", 30, -69)
imgSpellIcon1:EnableMouse(true)
imgSpellIcon1:SetNormalTexture(SpellIcon1)
local function OnEnter(self, motion)
GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT")
GameTooltip:SetText(SpellName1,1,1,1)
-- GameTooltip:AddLine(SpellRank1, 1, 1, 1)
GameTooltip:AddLine(SpellCost1.." Mana", 1, 1, 1)
GameTooltip:Show()
end
imgSpellIcon1:SetScript("OnEnter", OnEnter)
imgSpellIcon1:SetScript("OnLeave", function() GameTooltip:Hide() end)
I managed to get to this point but it's ugly.
I want the real tooltip to show not a custom one.
[center:xpja7nde](http://i.imgur.com/ofbNAcx.png)[/center:xpja7nde]
Game Version: 3.3.5a
Thank you
How to solve:
Instead of using
SetSpellByID(spellid)
which might not even work, use
SetHyperlink("spell:"..spellid)
-
I couldn't get GameTooltip:SetSpellByID(ID) to work, so I used a hacky way to populate the gametooltip from a spell hyperlink. The only downside is that if you have a hyperlink popup on screen (the little box that appears when you click a chat link for a spell/talent/item), the popup will disappear.
If anyone knows how to actually get GameTooltip:SetSpellByID to work instead of resorting to ghetto magic, please let us know!
local AIO = AIO or require("AIO")
AIO.AddAddon()
if not AIO.IsServer() then
-- Hacky way to set up custom talent tooltips. Creates and reads an ItemRefTooltip from a spellID and returns a table of text with color and wrap data.
-- The ItemRefTooltip is shown, read and hidden again without ever appearing on the screen (hopefully)
local function GetSpellTooltip(spellID)
if (not ItemRefTooltip:IsVisible()) then
ItemRefTooltip:SetOwner(UIParent, "ANCHOR_PRESERVE");
end
ItemRefTooltip:ClearLines();
local linky = "124cff71d5ff124Hspell:"..spellID.."124h124h124r"
ItemRefTooltip:SetHyperlink(linky)
local numLines = ItemRefTooltip:NumLines();
local tmp = {};
local i = 1;
for currentLine=1, numLines do
local line = {};
local left = _G["ItemRefTooltipTextLeft"..currentLine];
local right = _G["ItemRefTooltipTextRight"..currentLine];
if ( left ) then
line.w = left:CanWordWrap();
line.leftR, line.leftG, line.leftB = left:GetTextColor();
line.left = left:GetText();
end
if ( right ) then
line.rightR, line.rightG, line.rightB = right:GetTextColor();
line.right = right:GetText();
end
tmp[i] = line;
i = i + 1;
end
HideUIPanel(ItemRefTooltip);
return(tmp)
end
function GameTooltip:ActuallySetSpellByID(spellID)
local tmp = GetSpellTooltip(spellID)
GameTooltip:ClearLines()
for i=1, #tmp do
if ( tmp[i].left and tmp[i].right ) then
GameTooltip:AddDoubleLine(tmp[i].left, tmp[i].right, tmp[i].leftR, tmp[i].leftG, tmp[i].leftB, tmp[i].rightR, tmp[i].rightG, tmp[i].rightB);
elseif ( tmp[i].left ) then
GameTooltip:AddLine(tmp[i].left, tmp[i].leftR, tmp[i].leftG, tmp[i].leftB, tmp[i].w);
elseif ( tmp[i].right ) then
GameTooltip:AddDoubleLine("", tmp[i].right, 0, 0, 0, tmp[i].rightR, tmp[i].rightG, tmp[i].rightB);
end
end
GameTooltip:Show()
end
end
To test it, enter the game, mouse over a spell in your spellbook and paste this in chat to set the tooltip to Blizzard rank 1:
/run GameTooltip:ActuallySetSpellByID(10)
-
I couldn't get GameTooltip:SetSpellByID(ID) to work, so I used a hacky way to populate the gametooltip from a spell hyperlink. The only downside is that if you have a hyperlink popup on screen (the little box that appears when you click a chat link for a spell/talent/item), the popup will disappear.
If anyone knows how to actually get GameTooltip:SetSpellByID to work instead of resorting to ghetto magic, please let us know!
local AIO = AIO or require("AIO")
AIO.AddAddon()
if not AIO.IsServer() then
-- Hacky way to set up custom talent tooltips. Creates and reads an ItemRefTooltip from a spellID and returns a table of text with color and wrap data.
-- The ItemRefTooltip is shown, read and hidden again without ever appearing on the screen (hopefully)
local function GetSpellTooltip(spellID)
if (not ItemRefTooltip:IsVisible()) then
ItemRefTooltip:SetOwner(UIParent, "ANCHOR_PRESERVE");
end
ItemRefTooltip:ClearLines();
local linky = "124cff71d5ff124Hspell:"..spellID.."124h124h124r"
ItemRefTooltip:SetHyperlink(linky)
local numLines = ItemRefTooltip:NumLines();
local tmp = {};
local i = 1;
for currentLine=1, numLines do
local line = {};
local left = _G["ItemRefTooltipTextLeft"..currentLine];
local right = _G["ItemRefTooltipTextRight"..currentLine];
if ( left ) then
line.w = left:CanWordWrap();
line.leftR, line.leftG, line.leftB = left:GetTextColor();
line.left = left:GetText();
end
if ( right ) then
line.rightR, line.rightG, line.rightB = right:GetTextColor();
line.right = right:GetText();
end
tmp[i] = line;
i = i + 1;
end
HideUIPanel(ItemRefTooltip);
return(tmp)
end
function GameTooltip:ActuallySetSpellByID(spellID)
local tmp = GetSpellTooltip(spellID)
GameTooltip:ClearLines()
for i=1, #tmp do
if ( tmp[i].left and tmp[i].right ) then
GameTooltip:AddDoubleLine(tmp[i].left, tmp[i].right, tmp[i].leftR, tmp[i].leftG, tmp[i].leftB, tmp[i].rightR, tmp[i].rightG, tmp[i].rightB);
elseif ( tmp[i].left ) then
GameTooltip:AddLine(tmp[i].left, tmp[i].leftR, tmp[i].leftG, tmp[i].leftB, tmp[i].w);
elseif ( tmp[i].right ) then
GameTooltip:AddDoubleLine("", tmp[i].right, 0, 0, 0, tmp[i].rightR, tmp[i].rightG, tmp[i].rightB);
end
end
GameTooltip:Show()
end
end
To test it, enter the game, mouse over a spell in your spellbook and paste this in chat to set the tooltip to Blizzard rank 1:
/run GameTooltip:ActuallySetSpellByID(10)
I used GameTooltip:SetHyperlink("spell:"..SPELL_ID) and it worked for me
-
Oh yeah, that's a lot better lol