WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Issues with SetPoint and a Few Other Questions (https://www.wowinterface.com/forums/showthread.php?t=57190)

JDoubleU00 06-08-19 06:26 PM

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.

Fizzlemizz 06-08-19 07:22 PM

Code:

lt[j-1][2]
The lt table only has one entry per key so lt[j][2] and lt[j-1][2] is always nil (visually the same as using UIParent as the anchor for all frames). Just use _G[lt[j]] or _G[lt[j-1]]


Code:

_G[lt[j][2]]:SetPoint("BOTTOMLEFT",_G[lt[j-1][2]],"TOPLEFT",lt[3],lt[4])
lt[3], lt[4] are the third and fourth key in the lt table, frame name strings or nil depending. Did you mean
Code:

pestartpoint[4], pestartpoint[5] -- -10, 30

JDoubleU00 06-08-19 08:52 PM

1 Attachment(s)
Quote:

Originally Posted by Fizzlemizz (Post 332329)
Code:

lt[j-1][2]
The lt table only has one entry per key so lt[j][2] and lt[j-1][2] is always nil (visually the same as using UIParent as the anchor for all frames). Just use _G[lt[j]] or _G[lt[j-1]]


Code:

_G[lt[j][2]]:SetPoint("BOTTOMLEFT",_G[lt[j-1][2]],"TOPLEFT",lt[3],lt[4])
lt[3], lt[4] are the third and fourth key in the lt table, frame name strings or nil depending. Did you mean
Code:

pestartpoint[4], pestartpoint[5] -- -10, 30

The lt table has four items per key. It will look just like peorder but only has the active addons listed. I tested that with this code:

Lua Code:
  1. local peorder = {
  2.    {"JWXPBar","JWXPBarFrame",0,5},
  3.    {"JWRepBar","JWRepBarFrame",0,5},
  4.    {"BFAInvasionTimer","BFAInvasionTimer",0,25},
  5.    {"Skada","SkadaBarWindowSkada",0,25},
  6. }
  7.  
  8. local lt = {}
  9.  
  10. for key, value in pairs(peorder) do
  11.    if IsAddOnLoaded(peorder[key][1]) and _G[peorder[key][2]]:IsVisible() then
  12.       table.insert(lt,peorder[key])
  13.    end
  14. end
  15.  
  16. for j, k in pairs(lt) do
  17.    print(lt[j][1]..","..lt[j][2]..","..lt[j][3]..","..lt[j][4])
  18. end

The second piece of each key is the frame name I use for anchoring (except for the first time where I use unpack(pestartpoint). The third and fourth pieces are the x and y offset. I went back to a single line for setpoint:

_G[lt[j][2]]:SetPoint("BOTTOM",_G[lt[j-1][2]],"TOP",lt[j][3],lt[j][4])

The code works without errors, but does not always place the addons where I think they should be. Sorry, my screen grabs are crappy looking. In this image, JWXPBars is not enabled.

Attachment 9239

Fizzlemizz 06-08-19 09:27 PM

My bad, too much deciphering for a Sunday :(.

Have you checked the actual height of the frames you are anchoring. If a frame is taller than the visible components within it (if they are anchored to the top) then you will see a gap (you only anchor the bottom edge).

I don't know Skada (if it has an option for the bar count to "grow" upward might work).

JDoubleU00 06-08-19 09:40 PM

Quote:

Originally Posted by Fizzlemizz (Post 332331)
My bad, too much deciphering for a Sunday :(.

Have you checked the actual height of the frames you are anchoring. If a frame is taller than the visible components within it (if they are anchored to the top) then you will see a gap (you only anchor the bottom edge).

I don't know Skada, I don't see an XPbar.

I'll let you return to decipherless Sunday. :) You should not have seen XPbar, it is not loaded. You've given me some food for thought about frame heights that I did not realize.


All times are GMT -6. The time now is 12:36 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI