The API is no longer being updated here until further notice. |
GameTooltip (inherits from Frame) formats a tooltip. There is one named _G["GameTooltip"]
, but others are created with CreateFrame("GameTooltip") or <GameTooltip>.
Custom tooltips made in Lua must inherit a virtual XML template:
- SharedTooltipTemplate - Includes base font strings and textures. {, }
- GameTooltipTemplate - Additionally includes a unit health bar. {, }
Alternatively, see <GameTooltip> for minimum requirements in XML.
Defined methods[]
- GameTooltip:AddAtlas(atlas [, minx, maxx, miny, maxy] or [, textureInfoTable])
- GameTooltip:AddDoubleLine(textL, textR, rL, gL, bL, rR, gR, bR)
- GameTooltip:AddFontStrings(leftstring, rightstring) - Dynamically expands the size of a tooltip - New in 1.11.
- GameTooltip:AddLine(tooltipText [, r, g, b [, wrapText]]) - Appends the new line to the tooltip.
- GameTooltip:AddSpellByID(spellID)
- GameTooltip:AddTexture(texture) - Add a texture to the last line added.
- GameTooltip:AdvanceSecondaryCompareItem()
- GameTooltip:AppendText(text) - Append text to the end of the first line of the tooltip.
- GameTooltip:ClearLines() - Clear all lines of tooltip (both left and right ones)
- GameTooltip:CopyTooltip()
- GameTooltip:FadeOut()
- GameTooltip:GetAnchorType() - Returns the current anchoring type.
- GameTooltip:GetAzeritePowerID()
- GameTooltip:GetCustomLineSpacing()
- GameTooltip:GetItem() - Returns name, link.
- GameTooltip:GetMinimumWidth()
- GameTooltip:GetOwner() - Returns owner frame, anchor.
- GameTooltip:GetPadding()
- GameTooltip:GetSpell() - Returns name, rank, id.
- GameTooltip:GetUnit() - Returns unit name, unit id.
- GameTooltip:IsEquippedItem()
- GameTooltip:IsOwned(frame)
- GameTooltip:IsUnit(unit) - Returns bool.
- GameTooltip:NumLines() - Get the number of lines in the tooltip.
- GameTooltip:ResetSecondaryCompareItem()
- GameTooltip:SetAchievementByID(id)
- GameTooltip:SetAction(slot) - Shows the tooltip for the specified action button.
- GameTooltip:SetAllowShowWithNoLines(bool)
- GameTooltip:SetAnchorType(anchorType [,Xoffset] [,Yoffset])
- GameTooltip:SetArtifactItem()
- GameTooltip:SetArtifactPowerByID()
- GameTooltip:SetAzeriteEssence(essenceID)
- GameTooltip:SetAzeriteEssenceSlot(slot)
- GameTooltip:SetAzeritePower(itemID, itemLevel, powerID[, owningItemLink])
- GameTooltip:SetBackpackToken(id)
- GameTooltip:SetBagItem(bag, slot)
- GameTooltip:SetBagItemChild()
- GameTooltip:SetBuybackItem(slot)
- GameTooltip:SetCompanionPet()
- GameTooltip:SetCompareAzeritePower(itemID, itemLevel, powerID[, owningItemLink])
- GameTooltip:SetCompareItem(shoppingTooltipTwo, primaryMouseover)
- GameTooltip:SetConduit(id, rank)
- GameTooltip:SetCurrencyByID(id)
- GameTooltip:SetCurrencyToken(tokenId) - Shows the tooltip for the specified token
- GameTooltip:SetCurrencyTokenByID(currencyID)
- GameTooltip:SetEquipmentSet(name) - Shows details for the equipment manager set identified by "name".
- GameTooltip:SetCustomLineSpacing(spacing)
- GameTooltip:SetEnhancedConduit(conduitID, conduitRank)
- GameTooltip:SetExistingSocketGem(index, [toDestroy])
- GameTooltip:SetFrameStack(showhidden) - Shows the mouseover frame stack, used for debugging.
- GameTooltip:SetGuildBankItem(tab, id) - Shows the tooltip for the specified guild bank item
- GameTooltip:SetHeirloomByItemID(itemID)
- GameTooltip:SetHyperlink(itemString or itemLink) - Changes the item which is displayed in the tooltip according to the passed argument.
- GameTooltip:SetInboxItem(index) - Shows the tooltip for the specified mail inbox item.
- GameTooltip:SetInstanceLockEncountersComplete(index)
- GameTooltip:SetInventoryItem(unit, slot[, nameOnly, hideUselessStats])
- GameTooltip:SetInventoryItemByID(itemID)
- GameTooltip:SetItemByID(itemID) - Shows the tooltip for a specified Item ID. (added in 4.2.0.14002 along with the Encounter Journal)
- GameTooltip:SetItemKey(itemID, itemLevel, itemSuffix)
- GameTooltip:SetLFGDungeonReward(dungeonID, lootIndex)
- GameTooltip:SetLFGDungeonShortageReward(dungeonID, shortageSeverity, lootIndex)
- GameTooltip:SetLootCurrency(lootSlot)
- GameTooltip:SetLootItem(lootSlot)
- GameTooltip:SetLootRollItem(id) - Shows the tooltip for the specified loot roll item.
- GameTooltip:SetMerchantCostItem(index, item)
- GameTooltip:SetMerchantItem(merchantSlot)
- GameTooltip:SetMinimumWidth(width) - (Formerly SetMoneyWidth)
- GameTooltip:SetMountBySpellID()
- GameTooltip:SetOwnedItemByID(ID)
- GameTooltip:SetOwner(owner, anchor[, x, y])
- GameTooltip:SetPadding(width, height)
- GameTooltip:SetPetAction(slot) - Shows the tooltip for the specified pet action.
- GameTooltip:SetPossession(slot)
- GameTooltip:SetPvpBrawl()
- GameTooltip:SetPvpTalent(talentID[, talentIndex])
- GameTooltip:SetQuestCurrency(type, index)
- GameTooltip:SetQuestItem(type, index)
- GameTooltip:SetQuestLogCurrency(type, index)
- GameTooltip:SetQuestLogItem(type, index)
- GameTooltip:SetQuestLogRewardSpell(rewardSpellIndex[, questID])
- GameTooltip:SetQuestLogSpecialItem(index)
- GameTooltip:SetQuestPartyProgress(questID, omitTitle, ignoreActivePlayer)
- GameTooltip:SetQuestRewardSpell(rewardSpellIndex)
- GameTooltip:SetRecipeRankInfo(recipeID, learnedRank)
- GameTooltip:SetRecipeReagentItem(recipeID, reagentIndex)
- GameTooltip:SetRecipeResultItem(recipeID)
- GameTooltip:SetRuneforgeResultItem(itemID, itemLevel [, powerID, modifiers])
- GameTooltip:SetSendMailItem()
- GameTooltip:SetShapeshift(slot) - Shows the tooltip for the specified shapeshift form.
- GameTooltip:SetShrinkToFitWrapped()
- GameTooltip:SetSocketedItem()
- GameTooltip:SetSocketedRelic(relicSlotIndex)
- GameTooltip:SetSocketGem(index)
- GameTooltip:SetSpecialPvpBrawl()
- GameTooltip:SetSpellBookItem(spellId, bookType) - Shows the tooltip for the specified spell in the spellbook.
- GameTooltip:SetSpellByID(spellId) - Shows the tooltip for the specified spell by global spell ID.
- GameTooltip:SetTalent(talentIndex [, isInspect, talentGroup, inspectedUnit, classId]) - Shows the tooltip for the specified talent.
- GameTooltip:SetText(text, r, g, b[, alphaValue[, textWrap]]) - Set the text of the tooltip.
- GameTooltip:SetTotem(slot)
- GameTooltip:SetToyByItemID(itemID)
- GameTooltip:SetTradePlayerItem(tradeSlot)
- GameTooltip:SetTradeTargetItem(tradeSlot)
- GameTooltip:SetTrainerService(index)
- GameTooltip:SetTransmogrifyItem(slotId) - Shows the tooltip when there is a pending (de)transmogrification
- GameTooltip:SetUnit(unit[, hideStatus])
- GameTooltip:SetUnitAura(unit, auraIndex [, filter]) - Shows the tooltip for a unit's aura. (Exclusive to 3.x.x / WotLK)
- GameTooltip:SetUnitBuff(unit, buffIndex [, raidFilter]) - Shows the tooltip for a unit's buff.
- GameTooltip:SetUnitDebuff(unit, buffIndex [, raidFilter]) - Shows the tooltip for a unit's debuff.
- GameTooltip:SetUpgradeItem()
- GameTooltip:SetVoidDepositItem(slotIndex) - Shows the tooltip for the specified Void Transfer deposit slot (added in 4.3.0)
- GameTooltip:SetVoidItem(slotIndex) - Shows the tooltip for the specified Void Storage slot (added in 4.3.0)
- GameTooltip:SetVoidWithdrawalItem(slotIndex) - Shows the tooltip for the specified Void Transfer withdrawal slot (added in 4.3.0)
- GameTooltip:SetWeeklyReward(itemDBID)
- GameTooltip:SetAuctionItem(type, index) - Shows the tooltip for the specified auction item.
- GameTooltip:SetAuctionSellItem()
- GameTooltip:SetCraftItem(index, reagent)
- GameTooltip:SetCraftSpell(index)
- GameTooltip:SetTrackingSpell()
- GameTooltip:SetTradeSkillItem(index [, reagent])
Details[]
- GameTooltip:SetOwner() clears and hides the tooltip, then sets a temporary "owner" independent of the frame's "parent".
- The second argument anchors the tooltip rather than Region:SetPoint().
- Use ANCHOR_NONE for scanning tooltips (more details below).
- Region:Show() resizes the tooltip and reapplies any anchor defined with SetOwner().
- Showing a tooltip without content causes it to hide and clear its owner.
- AppendText() and most Set methods (SetUnit, SetItemByID, etc.) trigger Show(); however, AddLine() and AddDoubleLine() do not.
- Region:Hide() clears the tooltip's owner.
- GameTooltip:ClearLines() is an alternative without clearing the owner (and anchor).
- GameTooltip:AddLine() and similar methods add new lines as required, called
_G["$parentTextLeft"..i]
and_G["$parentTextRight"..i]
.- Each new FontString copies the same Font object as the previous line.
- However, the tooltip malfunctions without the first line present before loading (i.e. defined in XML).
Scanning tooltips[]
AddOns commonly create a hidden tooltip with ANCHOR_NONE
to query Set___()
methods invisibly to the player. Scanning tooltips can impact performance, so it is best to cache results and consider other API whenever feasible.
<GameTooltip name="MyScanningTooltip" inherits="SharedTooltipTemplate">
<Scripts>
<OnLoad inherit="prepend">
self:SetOwner(WorldFrame, "ANCHOR_NONE")
</OnLoad>
</Scripts>
</GameTooltip>
Each time scanning is desired, call ClearLines(), populate the tooltip, and then read the contents of the text fields.
MyScanningTooltip:ClearLines()
MyScanningTooltip:SetUnit("player")
print(MyScanningTooltipTextLeft2:GetText())
Examples[]
Function to return a table containing all the lines in the tooltip
local function GetTooltipLines(tooltip)
local textLines = {}
local regions = {tooltip:GetRegions()}
for _, r in ipairs(regions) do
if r:IsObjectType("FontString") then
table.insert(textLines, r:GetText())
end
end
return textLines
end
Iterator for looping through all tooltip lines
local function EnumerateTooltipLines_helper(...)
for i = 1, select("#", ...) do
local region = select(i, ...)
if region and region:GetObjectType() == "FontString" then
local text = region:GetText() -- string or nil
end
end
end
function EnumerateTooltipLines(tooltip) -- good for script handlers that pass the tooltip as the first argument.
EnumerateTooltipLines_helper(tooltip:GetRegions())
end
Macro to print each line:
/run for i=1,GameTooltip:NumLines()do print(_G["GameTooltipTextLeft"..i]:GetText())end
Macro to print left and right lines:
/run for i=1,select("#",GameTooltip:GetRegions())do local region=select(i,GameTooltip:GetRegions())if region and region:GetObjectType()=="FontString" and region:GetText()then print(region:GetText()) end end
Creating a scanning tooltip in Lua that has all features (status bar, textures, etc.):
CreateFrame("GameTooltip", "MyScanningTooltip", nil, "GameTooltipTemplate")
MyScanningTooltip:SetOwner( WorldFrame, "ANCHOR_NONE" )
local function scanUnit(unit)
MyScanningTooltip:ClearLines()
MyScanningTooltip:SetUnit(unit)
local i=1
while _G["MyScanningTooltipTextLeft" .. i] do
local text = _G["MyScanningTooltipTextLeft" .. i]:GetText()
if text and text ~= "" then print(text) end
i = i + 1
end
end
scanUnit(player)