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:
local name, mod = ...
local peorder = {
{"JWXPBar","JWXPBarFrame",0,5},
{"JWRepBar","JWRepBarFrame",0,5},
{"BFAInvasionTimer","BFAInvasionTimer",0,25},
{"Skada","SkadaBarWindowSkada",0,25},
}
local pestartpoint = {"BOTTOMRIGHT","UIParent", "BOTTOMRIGHT",-10,30}
local lt = {}
local function PlaceStuff()
for key, value in pairs(peorder) do
if IsAddOnLoaded(peorder[key][1]) and _G[peorder[key][2]]:IsVisible() then
table.insert(lt,peorder[key])
end
end
for j, k in pairs(lt) do
_G[lt[j][2]]:SetMovable(true)
_G[lt[j][2]]:SetUserPlaced(true)
_G[lt[j][2]]:ClearAllPoints()
if j == 1 then
_G[lt[j][2]]:SetPoint(unpack(pestartpoint)) --first frame gets anchored to UIParent
else
--_G[lt[j][2]]:SetPoint("BOTTOM",_G[lt[j-1][2]],"TOP",lt[3],lt[4]) --look at the table entry for anchoring
_G[lt[j][2]]:SetPoint("BOTTOMLEFT",_G[lt[j-1][2]],"TOPLEFT",lt[3],lt[4])
_G[lt[j][2]]:SetPoint("BOTTOMRIGHT",_G[lt[j-1][2]],"TOPRIGHT",lt[3],lt[4])
end
end
end
local PEF = CreateFrame("Frame", name, UIParent)
PEF:RegisterEvent("PLAYER_ENTERING_WORLD")
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.