I had an idea for an addon that involved making changes to the tooltip that you see when you mouseover an EquipmentSet button in the EquipmentSet pullout on the Character Window.
I'm familiar with the API, but I have no idea where to begin on making changes to a tooltip. Are there certain events I need to register? Are there any Wowace frameworks that make accessing and editting tooltips easier?
Making changes or adding (lines) to it? In either case, a good start would be to have a look at the code that does the tooltip magic for those buttons. You should probably hook the function that does it.
The first two is just the buttons to equip or save equipment sets that you see in the interface. So I have to assume that the PaperDollEquipmentManagerPaneScrollBar is the parent of the PaperDollEquipmentManagerPaneButtonN buttons. So looking at the inherited HybridScrollBarTemplate:
I see <Slider name="HybridScrollBarTemplate" virtual="true">
The only buttons I see as children are the scroll up and down buttons. No equipment set buttons...
So I'm stuck. I'm not sure where to look to figure out where the buttons are the in XML and I don't know where to look to figure out what function is used when the mouse _OnEnter's the buttons...
Can anyone help me out here? I'm sure that my problem is just lack of experience with the Wow xml code. Also I looked at the Global String variables for common text that shows up in the tooltip normally, like ITEMS_IN_INVENTORY, but searching all the XML and LUA for that string and I can't find it.
<ScrollFrame name="PaperDollEquipmentManagerPane" inherits="HybridScrollFrameTemplate" hidden="true">
So I have to assume that the PaperDollEquipmentManagerPaneScrollBar is the parent of the PaperDollEquipmentManagerPaneButtonN buttons. So looking at the inherited HybridScrollBarTemplate:
You're on the right track, mostly. The ScrollFrame templates are a little funky. They dynamically create an array of buttons based on how many will fit into the visible scrolling area. As you scroll the bar, the visible buttons get their labels and icons and whatnot changed, so that they're a moving window into the data behind the scenes. Even though there may be dozens of "things" in the list, if there are only 5 of them visible at a time, then only 5 buttons ever get created.
For equipment sets, look again at the PaperDollEquipmentManagerPane definition in the XML. Go down past the (statically defined) child frames, to the scripts. OnLoad does some basic setup and then calls PaperDollEquipmentManagerPane_OnLoad(), defined in the corresponding .lua file. In there, you can see how it calls the "base class" HybridScrollFrame_CreateButtons(), defined in HybridScrollFramel.lua. That's an educational function to study:
- It uses/sets certain fields in the scrolling frame. In particular, PaperDollEquipmentManagerPane.buttons is the array table of visible buttons, created on the fly.
- The buttons are created with names composed of the scrollframe's name, plus "Button", plus a loop counter. That's where your PaperDollEquipmentManagerPaneButton4, etc, is coming from.
- The buttons all inherit from a template passed as a parameter to HSF_CreateButtons(). In this case, it's "GearSetButtonTemplate", defined back in PaperDollFrame.xml. There you can see the buttons for editing/deleting the individual gear sets, and past the <Frames> block you can see the scripts for the main button. The OnEnter script for the template forwards to GearSetButton_OnEnter. Using hooksecurefunc(link) on that should get you where you want to be. For a quick sanity check,
Ah man I was so close! Everything you said makes sense.
Okay so now that you have pointed me in the right direction, how do people normally modify tooltips? Do they hook the OnEnter functions and add stuff to the tooltip somehow? When there are so many Ace libraries that people use these days, I look at addon code but its hard wading through the library code to figure out exactly how things are happening on a low level...
That list isn't handed to us by Blizzard, it's built up by addon authors who say, "hey, I just used function F and it's not listed, I should list it". :-)
Most/all of the GameTooltip:SetX functions are implemented in C++ code, so there's nothing we can look at. Once you call a SetX method, the tooltip is rewritten to display whatever text is associated with X, after which your hooked code can piece through the text, delete it, change it, append to it, etc.
...your hooked code can piece through the text, delete it, change it, append to it, etc.
So... how do I do this? I don't need step by step instructions... but can you point me to a wiki page or something like that with some basic instruction on how to alter/edit/change the content of GameTooltip? I just need some instruction. Thank you
On this page, http://www.wowpedia.org/Hooking_functions under the "Hooking a Function" section it discusses how to generate a tooltip and add lines to it. Is this still how it is done or is this old outdated info?
Not much has changed with respect to function hooking, so that page is still mostly good info. The important bit is not breaking secure status, so you'll want to use either hooksecurefunc (for functions) or :HookScript (for frame scripts).
for i = 1, GameTooltip:GetNumLines() do
local left = _G["GameTooltipTextLeft" .. i]
local right = _G["GameTooltipTextLeft" .. i]
local leftText = left:GetText()
if leftText:match("searchtext") then
left:SetText(leftText .. " appendtext")
Pretty much any tooltip addon should have a wealth of more complex and actually working example code for you.