View Single Post
06-08-19, 06:26 PM   #1
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
Issues with SetPoint and a Few Other Questions

I'm working on a personal addon that will place addons listed in a table based on which addons are loaded and visible. SetPoint seems to be my kryptonite, as you can see, I have triedtwo ways to anchor the frames. No matter how hard I try to place them, they tend to overlap. What am I missing?


Lua Code:
  1. local name, mod = ...
  2. local peorder = {
  3.     {"JWXPBar","JWXPBarFrame",0,5},
  4.     {"JWRepBar","JWRepBarFrame",0,5},
  5.     {"BFAInvasionTimer","BFAInvasionTimer",0,25},
  6.     {"Skada","SkadaBarWindowSkada",0,25},
  7. }
  8. local pestartpoint = {"BOTTOMRIGHT","UIParent", "BOTTOMRIGHT",-10,30}
  9. local lt = {}
  10.  
  11. local function PlaceStuff()
  12.     for key, value in pairs(peorder) do
  13.       if IsAddOnLoaded(peorder[key][1]) and _G[peorder[key][2]]:IsVisible() then
  14.          table.insert(lt,peorder[key])
  15.       end
  16.    end
  17.    
  18.    for j, k in pairs(lt) do
  19.       _G[lt[j][2]]:SetMovable(true)
  20.       _G[lt[j][2]]:SetUserPlaced(true)
  21.       _G[lt[j][2]]:ClearAllPoints()
  22.       if j == 1 then
  23.          _G[lt[j][2]]:SetPoint(unpack(pestartpoint)) --first frame gets anchored to UIParent
  24.       else
  25.          --_G[lt[j][2]]:SetPoint("BOTTOM",_G[lt[j-1][2]],"TOP",lt[3],lt[4]) --look at the table entry for anchoring
  26.          _G[lt[j][2]]:SetPoint("BOTTOMLEFT",_G[lt[j-1][2]],"TOPLEFT",lt[3],lt[4])
  27.          _G[lt[j][2]]:SetPoint("BOTTOMRIGHT",_G[lt[j-1][2]],"TOPRIGHT",lt[3],lt[4])
  28.       end
  29.    end
  30. end
  31.  
  32. local PEF = CreateFrame("Frame", name, UIParent)
  33. PEF:RegisterEvent("PLAYER_ENTERING_WORLD")
  34. PEF:SetScript("OnEvent", PlaceStuff)

Is it OK to use _G to lookup the frames? I tried just using the name, but I wasn't successful.

Finally, maybe I am overthinking the design. I'm not sure if using two loops is the most efficient way, or creating a second table to correctly list the active and visible addons.

Thanks as always.
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote