Quantcast
WoWInterface - View Single Post - Alternative to MinimapButtonFrame
View Single Post
10-01-19, 06:29 PM   #6
Terenna
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 105
I think you might want to do something like this:

Lua Code:
  1. --This block of code will move our minimap addon icons to below the minimap in a custom frame
  2. local btnblklist = { --these are the children of the minimap that we DON'T want to move to our button bar, that way when we look for other children, we only take addon icons
  3.     ['MinimapMailFrame']            = true,
  4.     ['MinimapBackdrop']             = true,
  5.     ['GameTimeFrame']               = true,
  6.     ['TimeManagerClockButton']      = true,
  7.     ['MiniMapWorldMapButton']       = true,
  8.     ['MiniMapTracking']             = true,
  9.     ['MinimapZoomIn']               = true,
  10.     ['MinimapZoomOut']              = true,
  11.     ['QueueStatusMinimapButton']    = true,
  12.     ['MinimapZoneTextButton']       = true
  13. }
  14.  
  15. local ButtonHoldBarChildren = {ButtonHoldBar:GetChildren()}
  16. local MiniMapChildren = {Minimap:GetChildren()}
  17. local function moveMinimapButtons() --stolen from bdMinimap and changed to be more efficient
  18.     ButtonHoldBarChildren = {ButtonHoldBar:GetChildren()}
  19.     MiniMapChildren = {Minimap:GetChildren()}
  20.     for k, v in pairs(MiniMapChildren) do
  21.         if not btnblklist[v:GetName()] then --check against our table made above, only add things that we want in the bar
  22.             table.insert(ButtonHoldBarChildren, v)
  23.         end
  24.     end
  25.  
  26.     local last = nil
  27.     for i = 1, #ButtonHoldBarChildren do
  28.         local f = ButtonHoldBarChildren[i]
  29.         local n = f:GetName() or ''
  30.         if ((f:GetName() and (strfind(n, 'LibDB') or strfind(n, 'Button') or strfind(n, 'Btn') or strfind(n,'AllTheThings')) and f:IsShown())) then
  31.             if not f.skinned then
  32.                 f:SetParent(ButtonHoldBar)
  33.                 local r = {f:GetRegions()}
  34.                 for o = 1, #r do
  35.                     if (r[o].GetTexture and r[o]:GetTexture()) then
  36.                         local tex = r[o]:GetTexture()
  37.                         r[o]:SetAllPoints(f)
  38.                         if (hideTextures[tex]) then
  39.                             r[o]:Hide()
  40.                         elseif not strfind(tex, 'WHITE8x8') then
  41.                             local coord = table.concat({r[o]:GetTexCoord()})
  42.                             if coord == '00011011' then
  43.                                 r[o]:SetTexCoord(0.3, 0.7, 0.3, 0.7)
  44.                             end
  45.                         end
  46.                     end
  47.                 end
  48.  
  49.                 f.tbackground = f.tbackground or CreateFrame('frame', nil, f)
  50.                 f.tbackground:SetAllPoints()
  51.                 f.tbackground:SetFrameStrata('BACKGROUND')
  52.                 f:SetHitRectInsets(0, 0, 0, 0)
  53.                 f:HookScript('OnEnter', function(self)
  54.                     local newlines = {}
  55.                     for l = 1, 10 do
  56.                         local line = _G['GameTooltipTextLeft'..l]
  57.                         if (line and line:GetText()) then
  58.                             newlines[line:GetText()] = true
  59.                         end
  60.                     end
  61.  
  62.                     GameTooltip:Hide()
  63.                     GameTooltip:SetOwner(self, 'ANCHOR_TOPLEFT', 0, 6)
  64.                     for k, v in pairs(newlines) do
  65.                         GameTooltip:AddLine(k)
  66.                     end
  67.                     GameTooltip:Show()
  68.                 end)
  69.                 f.skinned = true
  70.             end
  71.  
  72.             -- sometimes a frame can get in here twice, don't let it
  73.             f:ClearAllPoints()
  74.             f:SetSize(20, 20)
  75.             if last then
  76.                 f:SetPoint('TOPLEFT', last, 'TOPRIGHT', 4, 0)
  77.                 f:SetPoint('BOTTOMRIGHT', last, 'BOTTOMRIGHT', f:GetWidth()+4, 0)
  78.             else
  79.                 f:SetPoint('TOPLEFT', ButtonHoldBar, 'TOPLEFT', 0, 0)
  80.                 f:SetPoint('BOTTOMRIGHT', ButtonHoldBar, 'TOPLEFT', f:GetWidth(), -f:GetHeight())
  81.             end
  82.             last = f
  83.         end
  84.     end
  85. end
  86. --This block of code runs the moveMinimapButtons() once, about 1s after init
  87. --because some addons handle their minimap icons slightly after loading
  88. local g = CreateFrame('frame')
  89. g.elapsed, g.counter = 0, 0
  90. g:SetScript('OnUpdate', function(self, elapsed)
  91.     self.elapsed = self.elapsed + elapsed
  92.     while (self.elapsed > 1 and self.counter <= 1) do
  93.         moveMinimapButtons()
  94.         self.counter = self.counter + 1
  95.         self.elapsed = 0
  96.     end
  97.  
  98.     if self.counter >= 2 then g:SetScript('OnUpdate', nil) end
  99. end)

It probably isn't the most optimized code in the world, but it runs exactly twice on load in and shouldn't impact things after that. It should grab most buttons, but if for some reason you have an addon whose button doesn't, you could /fstack and get its name and add it to this line:

Lua Code:
  1. if ((f:GetName() and (strfind(n, 'LibDB') or strfind(n, 'Button') or strfind(n, 'Btn') or strfind(n,'AllTheThings')) and f:IsShown())) then
  Reply With Quote