Thread Tools Display Modes
06-09-09, 12:40 AM   #1
Waverian
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 188
Removing a tooltip line.

Is there an "easy," or at least non-convoluted way to remove a single line from the game tooltip? I can't seem to find any documentation on wowwiki or wowprogramming. I've managed to accomplish what I want, but I basically have to rebuild the entire tooltip every time its OnShow is called, which is annoying.

It's not really relevant to the question, but the code is below.

Code:
local FAP = "Moonkin forms only."

local function UpdateTooltip(tooltip)
	local _, item = tooltip:GetItem()
	-- Ignore all of this unless our tooltip belongs to an item.
	if not item then return end
	-- Also ignore if our item isn't a weapon.
	if select(6, GetItemInfo(item)) ~= "Weapon" then return end

	
	local lines = {}
	-- Iterate through all of the lines on our tooltip.
	for i = 1, tooltip:NumLines() do
		local left = _G[tooltip:GetName().."TextLeft"..i]
		local lText = left:GetText()
		local lR, lG, lB = left:GetTextColor()
		
		-- Ignore any lines that have "Feral Attack Power" in them. Add everything else to a table used to reconstruct our tooltip later on.
		if not lText:find(FAP) then
			tinsert(lines, {line = lText, r = lR, g = lG, b = lB})
		end
	end
	
	-- We're going to clear the tooltip and reconstruct it without the feral attack power text. Is there a cleaner way to remove a line from the GameTooltip?
	tooltip:ClearLines()
	for k, v in pairs(lines) do
		tooltip:AddLine(v.line)
		_G[tooltip:GetName().."TextLeft"..k]:SetTextColor(v.r, v.g, v.b)
	end
end

-- Hook our GameTooltip and ItemRefTooltip OnShow
GameTooltip:HookScript("OnShow", function()
	UpdateTooltip(GameTooltip)
end)

ItemRefTooltip:HookScript("OnShow", function()
	UpdateTooltip(ItemRefTooltip)
end)
  Reply With Quote
06-09-09, 01:15 AM   #2
Tristanian
Andúril
Premium Member
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 279
Nope, you cannot remove lines from the GameTooltip, once it's populated. You need to redraw it, if you want to "update" the information displayed or simply use a different kind of frame to replace it entirely (or even a tooltip library).
__________________
  Reply With Quote
06-09-09, 01:21 AM   #3
Waverian
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 188
Originally Posted by Tristanian View Post
Nope, you cannot remove lines from the GameTooltip, once it's populated. You need to redraw it, if you want to "update" the information displayed or simply use a different kind of frame to replace it entirely (or even a tooltip library).
Fair enough. Thanks.
  Reply With Quote
06-16-09, 02:51 AM   #4
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
This is what I do.
Code:
local leftlines = setmetatable({}, {__index = function(tooltip, k)
    local t = setmetatable({}, {__index = function(self, i)
        local f = _G[tooltip:GetName().."TextLeft"..i]
        self[i] = f
        return f
    })
    self[k] = t
    return t
end})

local rightlines = setmetatable({}, {__index = function(tooltip, k)
    local t = setmetatable({}, {__index = function(self, i)
        local f = _G[tooltip:GetName().."TextRight"..i]
        self[i] = f
        return f
    })
    self[k] = t
    return t
end})

local function UpdateTooltip(tooltip)
    local numlines = tooltip:NumLines()
    local lefts, rights = leftlines[tooltip], rightlines[tooltip]
    for i = numlines, 1, -1 do
        local left = lefts[i]
        local text = left:GetText()
        if text:find(<thing we want to remove) then
            for j = i + 1, numlines do
                lefts[j-1]:SetText(lefts[j]:GetText())
                lefts[j-1]:SetTextColor(lefts[j]:GetTextColor())
                if rights[j]:IsShown() then
                    rights[j-1]:SetText(rights[j]:GetText())
                    rights[j-1]:SetTextColor(rights[j])
                else right[j-1]:Hide()
                end
            end
            lefts[numlines]:Hide()
            lefts[numlines]:SetText("")
            rights[numlines]:Hide()
            numlines = numlines - 1
        end
    end
    tooltip:Show()
end
Should work.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Removing a tooltip line.


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