I'm making an auto vendor addon (QuestJunk) and I want it to mark items that are to be vendored. Currently I'm creating a crossed circle on top of ContainerFrame#Item#, with IDs matching the item I'm going to vendor, and it works perfectly with default UI. However, it probably won't work with bag addons, would it? Is there any easy way to fix that? Perhaps going through all frames and figuring out which ones are derived from ContainerFrameItemButtonTemplate?
How is that going to help? They seem to create their own buttons derived from the template.
I figured hooking ContainerFrameItemButton_OnLoad and making a list of all item buttons, then looping through them to find buttons corresponding to a given bag/slot works though, except I don't detect ones that were created before my addon loaded.
Oh thanks, that's definitely better than doing for k,v in pairs (_G) and checking for variables that contain IconQuestTexture.
Edit: nope, doesn't work this way, the OnLoad script isn't that function, its a noname function that calls it (defined in frame xml).
Just be aware that EnumerateFrames() will cycle through every single frame that ever was made, everything from UI panels to font strings. I would recommend saving the frame to a local variable once you find it so you're not constantly cycling through the frames and exit the loop.
local function FindFrame()
if frameIWant then
local f = EnumerateFrames()
while f do
if f is the frame I want then
frameIWant = f
f = EnumerateFrames(f)
Edit: If you're looking for multiple frames, then, don't break from the loop, but still save the frames for reuse.
you may also want to consider that item frames are created dynamically in some bag mods (mine does), so perhaps hooking createframe to catch any newly created frames based on that template may help there, unless you want to enumerate through everything constantly.
the downside is that i use a custom template that inherits from the standard one so that might not necessarily work either.
What I did was call EnumerateFrames once when loading, and save all frames derived from ContainerFrameItemButtonTemplate in a list.
Then I hook the ContainerFrameItemButton_OnLoad and add the newly created frame to the list. So, unless your custom template overwrites OnLoad and doesn't call the original one (does that even work that way, or templates call their parent OnLoad first like class constructors do in c++?), I will catch it.
Then, when I need to update the icons, I just go through the list.