View Single Post
08-19-15, 04:20 PM   #7
Banknorris
A Chromatic Dragonspawn
 
Banknorris's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 153
If that frame has some distinctive features you might be able to use EnumerateFrames() to get a pointer to it. For example this code catches all existent action buttons (from standard UI, Bartender4, ButtonForge, Dominos etc) and new ones will be added as well. Doesn't matter if they have a name or parent. (code extracted and adapted from SetMacroIcon lib)

Lua Code:
  1. local action_buttons = {} --this table will contain all action buttons (present and future)
  2.  
  3. local hook_all_actionbuttons
  4. local CreateFrame_hook
  5.  
  6. local hook_new_buttons_frame = CreateFrame("Frame")
  7. hook_new_buttons_frame:Hide()
  8.  
  9. local f = CreateFrame("Frame")
  10. f:SetScript("OnEvent",function(self,event,...)
  11.     if event=="PLAYER_LOGIN" then
  12.         hook_all_actionbuttons()
  13.         hooksecurefunc("CreateFrame",CreateFrame_hook)
  14.     end
  15. end)
  16. f:RegisterEvent("PLAYER_LOGIN")
  17.            
  18. function CreateFrame_hook(frame_type,frame_name,frame_parent,frame_template)
  19.     --put code to identify viable candidates for the desired frame here (like bellow)
  20.     if string_upper(frame_type)=="CHECKBUTTON" and frame_template and string_upper(frame_template):match("ACTIONBUTTONTEMPLATE") then
  21.         hook_new_buttons_frame:Show()
  22.     end
  23. end
  24.  
  25. do
  26. local last_frame
  27. function hook_all_actionbuttons()
  28.     local frame = EnumerateFrames(last_frame)
  29.     while frame do
  30.         --put code to identify the desired frame here (like bellow)
  31.         local frame_type = frame:GetObjectType()
  32.         if frame_type=="CheckButton" and frame.GetAttribute and frame.icon and frame.Border and frame.Count then
  33.             action_buttons[frame] = true
  34.         end
  35.         last_frame = frame
  36.         frame = EnumerateFrames(frame)
  37.     end
  38. end
  39. end
  40.  
  41. hook_new_buttons_frame:SetScript("OnUpdate",function(self,elapsed)
  42.     self:Hide()
  43.     hook_all_actionbuttons()
  44. end)
__________________
"In this world nothing can be said to be certain, except that fractional reserve banking is a Ponzi scheme and that you won't believe it." - Mandrill

Last edited by Banknorris : 08-19-15 at 04:46 PM.
  Reply With Quote