1. #1

    Macro to move buttons works in-game, fails in AddOn

    I have a very simple macro to move 3 of the buttons on the default action bar. The macro works just fine:

    Code:
        x="MultiBarBottomRightButton"
        for i=1,12 do
          _G[x..i]:ClearAllPoints()
        end
        f=function(a,p,x,y)
          a:SetPoint("TOPLEFT",p,"TOPRIGHT",x,y)
          a:SetFrameStrata("MEDIUM")
        end
        f(_G[x..1],"UIParent",-1065,-235)
        f(_G[x..8],x..1,5,0)
        f(_G[x..9],x..8,5,0)

    I have this macro keybound and I hit it every time I enter the game. However, for a number of reasons, I'd like the macro to run automatically when I enter the game--so I created an AddOn using Treeston's guide which runs this macro and many others. After logging in, the 3 action buttons are in the correct position, but my bottom right action bar (the one containing these 3 buttons) completely disappears. It isn't difficult to imagine why this might happen:

    When I run the macro after my UI is completely loaded, running ClearAllPoints on every button in the action bar leaves them right where they are; but if the macro is run when my AddOn is loaded, it seems the buttons in that bar have not yet been placed, so running ClearAllPoints leaves them somewhere off the screen.

    How would you guys solve this? Is there an event that fires after UI layout is complete? If not, maybe there is a function I can post-hook?

    Thanks!

  2. #2
    Deleted
    Try preventing them from being SetPoint-ed again.
    Code:
    local d = function() end
    local f=function(a,p,x,y)
        a:SetPoint("TOPLEFT",p,"TOPRIGHT",x,y)
        a:SetFrameStrata("MEDIUM")
        a.SetPoint = d
        a.ClearAllPoints = d
    end
    (Oh, and make your variables local. You don't have to conserve space if you're in an addon.)

  3. #3
    Thanks for the quick reply, Treeston!

    My title is probably misleading: after moving the macro into the AddOn, the 3 buttons move fine. It's the 8 _other_ buttons in the bottom right action bar that disappear. This loop is what causes the issue:

    Code:
        x="MultiBarBottomRightButton"
        for i=1,12 do
          _G[x..i]:ClearAllPoints()
        end
    If an AddOn does this at load time, it seems that WoW has not yet assigned *real* coordinates to the 12 buttons in the bar. So when I run ClearAllPoints(), every button that I do not place explicitly goes off the screen. If I run this as a macro, the buttons already have real coordinates, so removing their *relative* points (i.e., button 2's topleft is set to button 1's topright + some padding) does not alter their usual position.

    Does that make sense?

    Thanks again!

  4. #4
    Deleted
    Hm, that's not how the anchoring system works - if you ClearAllPoints after the buttons are loaded, they should still disappear. Weird.

    Why do you even ClearAllPoints the buttons that you don't want to move? Why not simply add the ClearAllPoints call to your function and only ClearAllPoints the three buttons you want to move?

  5. #5
    Technically, I only have to ClearAllPoints on buttons 1, 2 and 10. I have to clear 1 because it's anchored by one of its bottom corners (or perhaps the bottom edge); so if I reposition it using its TOPLEFT point and the bottom anchor is still set, then the button will stretch all the way across my screen. Buttons 2 and 10 have to be cleared because of the way Blizzard laid out the action bar. They first position MultiBarBottomRightButton1, and then they anchor button 2's topleft to button 1's topright. All of the buttons in the action bar are laid out this fashion: button X is anchored to button X-1. For example, if I didn't clear the points on button 2, it would follow button 1 to wherever I move it and every other button in the action bar would follow suit (i.e., 3 would follow 2, 4 would follow 3, and so on).

    Hm, that's not how the anchoring system works - if you ClearAllPoints after the buttons are loaded, they should still disappear. Weird.
    I think this is the problem. The buttons haven't loaded yet when the AddOn is being run. Do you know of any hooks or events that fire after, say, the buttons have been loaded?

    Do you think it'd help if I posted screenshots of the correct behavior (macro) vs. the incorrect behavior (addon)?

    Thanks for the help!

  6. #6
    Deleted
    Well, then re-position #2 to whatever #1 used to be + #1's size.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •