WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Changing Alert Frame anchors (https://www.wowinterface.com/forums/showthread.php?t=44372)

eiszeit 09-15-12 01:13 PM

Changing Alert Frame anchors
 
Hello,

I am trying to get my alert frame (for achievements, etc) on top and reverse the grow order. Normally they get put on top of each other.

Since I don't find any small addon which does that or is out of date I was looking into ElvUI, since I know there is some code like that. I kinda get it to work w/o having all of ElvUI stuff in my UI, since I don't need it.

Now to my problem: somehow it kinda works but throwing out a lot of erros .. maybe someone can help me to figure out what exactly is wrong.

Code:

-- All credits to Elv
local AlertFrameHolder = CreateFrame("Frame", "AlertFrameHolder", UIParent)
AlertFrameHolder:SetWidth(180)
AlertFrameHolder:SetHeight(20)
AlertFrameHolder:SetPoint("TOP", UIParent, "TOP", 0, -5)

local POSITION, ANCHOR_POINT, YOFFSET = "TOP", "BOTTOM", -10

local function fixAnchors(pos)
        POSITION = pos or POSITION
       
        if POSITION == 'TOP' then
                ANCHOR_POINT = 'BOTTOM'
                YOFFSET = -10
        else
                ANCHOR_POINT = 'TOP'
                YOFFSET = 10
        end
       
        AlertFrame:ClearAllPoints()
        AlertFrame:SetAllPoints(AlertFrameHolder)

        GroupLootContainer:ClearAllPoints()
        GroupLootContainer:SetPoint(POSITION, AlertFrame, ANCHOR_POINT)
       
        MissingLootFrame:ClearAllPoints()
        MissingLootFrame:SetPoint(POSITION, AlertFrame, ANCHOR_POINT)
       
        AlertFrame_FixAnchors()
end
hooksecurefunc("AlertFrame_FixAnchors", fixAnchors)

local function AlertFrame_SetLootWonAnchors(alertAnchor)
        for i=1, #LOOT_WON_ALERT_FRAMES do
                local frame = LOOT_WON_ALERT_FRAMES[i];
                if ( frame:IsShown() ) then
                        frame:ClearAllPoints()
                        frame:SetPoint(POSITION, alertAnchor, ANCHOR_POINT, 0, YOFFSET);
                        alertAnchor = frame
                end
        end
end
hooksecurefunc("AlertFrame_SetLootWonAnchors", AlertFrame_SetLootWonAnchors)

local function AlertFrame_SetMoneyWonAnchors(alertAnchor)
        for i=1, #MONEY_WON_ALERT_FRAMES do
                local frame = MONEY_WON_ALERT_FRAMES[i];
                if ( frame:IsShown() ) then
                        frame:ClearAllPoints()
                        frame:SetPoint(POSITION, alertAnchor, ANCHOR_POINT, 0, YOFFSET);
                        alertAnchor = frame
                end
        end
end
hooksecurefunc("AlertFrame_SetMoneyWonAnchors", AlertFrame_SetMoneyWonAnchors)

local function AlertFrame_SetAchievementAnchors(alertAnchor)
        if ( AchievementAlertFrame1 ) then
                for i = 1, MAX_ACHIEVEMENT_ALERTS do
                        local frame = _G["AchievementAlertFrame"..i];
                        if ( frame and frame:IsShown() ) then
                                frame:ClearAllPoints()
                                frame:SetPoint(POSITION, alertAnchor, ANCHOR_POINT, 0, YOFFSET);
                                alertAnchor = frame
                        end
                end
        end
end
hooksecurefunc("AlertFrame_SetAchievementAnchors", AlertFrame_SetAchievementAnchors)

local function AlertFrame_SetCriteriaAnchors(alertAnchor)
        if ( CriteriaAlertFrame1 ) then
                for i = 1, MAX_ACHIEVEMENT_ALERTS do
                        local frame = _G["CriteriaAlertFrame"..i];
                        if ( frame and frame:IsShown() ) then
                                frame:ClearAllPoints()
                                frame:SetPoint(POSITION, alertAnchor, ANCHOR_POINT, 0, YOFFSET);
                                alertAnchor = frame
                        end
                end
        end
end
hooksecurefunc("AlertFrame_SetCriteriaAnchors", AlertFrame_SetCriteriaAnchors)

local function AlertFrame_SetChallengeModeAnchors(alertAnchor)
        local frame = ChallengeModeAlertFrame1;
        if ( frame:IsShown() ) then
                frame:ClearAllPoints()
                frame:SetPoint(POSITION, alertAnchor, ANCHOR_POINT, 0, YOFFSET);
        end
end
hooksecurefunc("AlertFrame_SetChallengeModeAnchors", AlertFrame_SetChallengeModeAnchors)

local function AlertFrame_SetDungeonCompletionAnchors(alertAnchor)
        local frame = DungeonCompletionAlertFrame1;
        if ( frame:IsShown() ) then
                frame:ClearAllPoints()
                frame:SetPoint(POSITION, alertAnchor, ANCHOR_POINT, 0, YOFFSET);
        end
end
hooksecurefunc("AlertFrame_SetDungeonCompletionAnchors", AlertFrame_SetDungeonCompletionAnchors)

local function AlertFrame_SetScenarioAnchors(alertAnchor)
        local frame = ScenarioAlertFrame1;
        if ( frame:IsShown() ) then
                frame:ClearAllPoints()
                frame:SetPoint(POSITION, alertAnchor, ANCHOR_POINT, 0, YOFFSET);
        end
end
hooksecurefunc("AlertFrame_SetScenarioAnchors", AlertFrame_SetScenarioAnchors)

local function AlertFrame_SetGuildChallengeAnchors(alertAnchor)
        local frame = GuildChallengeAlertFrame;
        if ( frame:IsShown() ) then
                frame:ClearAllPoints()
                frame:SetPoint(POSITION, alertAnchor, ANCHOR_POINT, 0, YOFFSET);
        end
end
hooksecurefunc("AlertFrame_SetGuildChallengeAnchors", AlertFrame_SetGuildChallengeAnchors)

SlashCmdList.TEST_ACHIEVEMENT = function()
        PlaySound("LFG_Rewards")
        AchievementFrame_LoadUI()
        AchievementAlertFrame_ShowAlert(5780)
        AchievementAlertFrame_ShowAlert(5000)
        GuildChallengeAlertFrame_ShowAlert(3, 2, 5)
        ChallengeModeAlertFrame_ShowAlert()
        CriteriaAlertFrame_GetAlertFrame()
        AlertFrame_AnimateIn(CriteriaAlertFrame1)
        AlertFrame_AnimateIn(DungeonCompletionAlertFrame1)
        AlertFrame_AnimateIn(ScenarioAlertFrame1)
       
        local _, itemLink = GetItemInfo(6948)
        LootWonAlertFrame_ShowAlert(itemLink, -1, 1, 1)
        MoneyWonAlertFrame_ShowAlert(1)
       
        AlertFrame_FixAnchors()
end
SLASH_TEST_ACHIEVEMENT1 = "/testalerts"

Also on pastebin: http://pastebin.com/SVgaRvmN

eiszeit 09-15-12 01:21 PM

Ah, I was blind. After looking into the official AlertFrames.lua, I found my error. FixAnchors has no argument .. so I deleted it, now it works. :)


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

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