Inserting a line in GameTooltip at arbitrary position?
I want to put an extra line in the item tooltip directly beneath the "Sell price" line.
I am hooking OnTooltipSetItem to do so: Code:
GameTooltip:HookScript("OnTooltipSetItem", function(self) I guess there is no way to enforce that my addon gets to hook its script first, unless I put it into the optional dependencies of the other addons? If so, is there another option than scanning the content of the current GameTooltip line by line and inserting my new line after the line beginning with SELL_PRICE? What would be the most efficient way to do this? Do I really have to read every line from GameTooltip to a new tooltip or table, then do a GameTooltip:ClearLines() and then GameTooltip:AddLine() everything back? |
No, just everything after where you want your text. Just change the text using :SetText() on the line you want, and then use :SetText() again for every line after that. (You might need to end with an AddLine().)
/edit: but I'd check to see if the last line in the tooltip is the sell price first before doing all that |
Thanks a lot, this helped me a great deal already.
But copying a tooltip line is not so straight forward, is it? First of all, I have to check if it is a single or double line by checking Code:
if (_G[self:GetName().."TextRight"..i]:GetText()) then And then I have to not just copy the text content but also the formating. For instance, if I want to duplicate the last line, I would do: Code:
local copyText = _G["GameTooltipTextLeft"..GameTooltip:NumLines()]:GetText() I could not find the equivalent to GetText() and GetTextColor() for that. I tried _G["GameTooltipTextLeft"..GameTooltip:NumLines()]:CanNonSpaceWrap() but this always returns false. EDIT: The same for GetIndentedWordWrap(). |
When I apply SetText() to a tooltip line like
Code:
_G["GameTooltipTextLeft1"]:SetText("bla", 1, 0, 0, 1, true) So if I want to have the same text colours in the modified tooltip, I would have to built my copy tooltip from scratch only using AddLine() and AddDoubleLine(). EDIT: This is not viable either. When I do GameTooltip:ClearLines() and refill the tooltip with my stored plus added lines, future calls of GameTooltip:GetItem() will only get nil, as the item is apparently cleared by ClearLines(). I can overcome this by Code:
local originalGetItem = GameTooltip.GetItem and Code:
local name, link = GameTooltip:GetItem() |
A simpler way would be to wait until later in the loading process to hook the tooltip and create a prehook the old fashioned way.
Lua Code:
In any occasion, trying to place your addon's text in a certain spot in the tooltip opens up race conditions competing with any other addon that might have that same design choice. The best and most efficient option is to let it be and do nothing. |
@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:
|
Since the "Sell Price" line you're wanting to put your text under is the last line in the standard tooltip text, there is no need to try to manually reconstruct the tooltip when the solution I provided has your code run before anything else does. And yes, all the standard text is there by the time the script is run, otherwise, you'd have addons' text popping up at the top instead of the bottom. :D
|
All right, thanks for the clarification! Now I understand the difference between SetScript and HookScript. :-D
However, if other Addons use the same method as you suggested, I have again no controll over which one is loaded first, right? E.g. the author of LibExtraTip (used by TheUndermineJournal) does it like this (LibExtraTip.lua, L545): Lua Code:
With your code, my lines always get appended after those of TheUndermineJournal. |
Apparently PLAYER_LOGIN was just not late enough. It works, when I am using a timer to make sure that I am really the last. :D Thanks again!!
Lua Code:
|
All times are GMT -6. The time now is 06:52 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI