@SDPhantom: Thanks, but when I do a pre-hook of OnTooltipSetItem(), will there be anything at all in the GameTooltip for me to modify? I do not care about what other addons my later append but I want to rearrange the original GameTooltip content which the BlizzardUI has put there.
Anyway, here is how I solved this now by manually copy-pasting every line.
Unfortunately, I still do not know how to copy the "intended word wrap" of a tooltip line.
But I have thus far not seen any case where the wrap would have been set to false, so I am setting it to true by default for every copied line.
Lua Code:
-- Have to override GameTooltip.GetItem() after calling ClearLines().
-- This will restore the original after the tooltip is closed.
local originalGetItem = GameTooltip.GetItem
GameTooltip:HookScript("OnHide", function(self)
GameTooltip.GetItem = originalGetItem
end)
GameTooltip:HookScript("OnTooltipSetItem", function(self)
-- Only interested in tooltips with money frame, as I want to put my text below this.
if not self.shownMoneyFrames then return end
-- The money frame is anchored to a blank line of the tootlip.
-- Find out which line it is and what the sell price is.
local moneyFrameLineNumber = nil
local money = nil
-- Check all shown money frames of the tooltip.
-- (There is normally only one, except other addons have added more.)
for i = 1, self.shownMoneyFrames, 1 do
local moneyFrameName = self:GetName().."MoneyFrame"..i
-- If the money frame's PrefixText is "SELL_PRICE:", we assume it is the one we are looking for.
if _G[moneyFrameName.."PrefixText"]:GetText() == string_format("%s:", SELL_PRICE) then
local _, moneyFrameAnchor = _G[moneyFrameName]:GetPoint(1)
-- Get line number and amount of money.
moneyFrameLineNumber = tonumber(string_match(moneyFrameAnchor:GetName(), self:GetName().."TextLeft(%d+)"))
money = _G[moneyFrameName].staticMoney
break
end
end
if not moneyFrameLineNumber then return end
-- Store all text and text colours of the original tooltip lines.
-- TODO: Unfortunately I do not know how to store the "indented word wrap".
-- Therefore, we have to put wrap=true for all lines in the new tooltip.
local leftText = {}
local leftTextR = {}
local leftTextG = {}
local leftTextB = {}
local rightText = {}
local rightTextR = {}
local rightTextG = {}
local rightTextB = {}
-- Store the number of lines for after ClearLines().
local numLines = self:NumLines()
-- Store all lines of the original tooltip.
for i = 1, numLines, 1 do
leftText[i] = _G[self:GetName().."TextLeft"..i]:GetText()
leftTextR[i], leftTextG[i], leftTextB[i] = _G[self:GetName().."TextLeft"..i]:GetTextColor()
rightText[i] = _G[self:GetName().."TextRight"..i]:GetText()
rightTextR[i], rightTextG[i], rightTextB[i] = _G[self:GetName().."TextRight"..i]:GetTextColor()
end
self:ClearLines()
-- Got to override GameTooltip.GetItem(), such that other addons can still use it
-- to learn which item is displayed. Will be restored after GameTooltip:OnHide() (see above).
local name, link = self:GetItem()
self.GetItem = function(self) return name, link end
-- Refill the tooltip with the stored lines plus my added lines.
for i = 1, moneyFrameLineNumber-1, 1 do
if rightText[i] then
self:AddDoubleLine(leftText[i], rightText[i], leftTextR[i], leftTextG[i], leftTextB[i], rightTextR[i], rightTextG[i], rightTextB[i])
else
-- TODO: Unfortunately I do not know how to store the "indented word wrap".
-- Therefore, we have to put wrap=true for all lines in the new tooltip.
self:AddLine(leftText[i], leftTextR[i], leftTextG[i], leftTextB[i], true)
end
end
-- Set original money frame.
SetTooltipMoney(self, money, nil, string_format("%s:", SELL_PRICE))
-- Set my new stuff!
self:AddLine("My new stuff here...")
-- Set the remaining original tooltip lines.
for i = moneyFrameLineNumber+1, numLines, 1 do
if rightText[i] then
self:AddDoubleLine(leftText[i], rightText[i], leftTextR[i], leftTextG[i], leftTextB[i], rightTextR[i], rightTextG[i], rightTextB[i])
else
-- TODO: Unfortunately I do not know how to store the "indented word wrap".
-- Therefore, we have to put wrap=true for all lines in the new tooltip.
self:AddLine(leftText[i], leftTextR[i], leftTextG[i], leftTextB[i], true)
end
end
end
)