#Custom Anchors

4 messages · Page 1 of 1 (latest)

runic coral
#

So this is probably a niche one but currently trying to build a dynamic custom anchor that attaches the same aura group to the player frame depending on if you use elvui, cell, shadow or blizzard, but for some reason Occasionally the aura just vanishes, usually on login or reload specifically even though adding print statements would indicate it properly anchored. Here is my current attempt with print statements still in it:

function()
    local NUI = unpack(NaowhUI)
    
    local C_AddOns, CUF_Player, ElvUF_Player, SUFUnitplayer, PlayerFrame = C_AddOns, CUF_Player, ElvUF_Player, SUFUnitplayer, PlayerFrame
    local frame = CUF_Player or ElvUF_Player or SUFUnitplayer or PlayerFrame
    
    print("Using frame: ", frame)
    
    if frame then
        local screenWidth = GetScreenWidth()
        local screenHeight = GetScreenHeight()

        local frameLeft = frame:GetLeft()
        local frameTop = frame:GetTop()

        print("Frame position before adjustments: Left = ", frameLeft, " Top = ", frameTop)

        if frameLeft < 0 then 
            print("Adjusting frame to the right...")
            frame:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 0, frameTop)
        end
        if frameTop > screenHeight then 
            print("Adjusting frame to be within screen height...")
            frame:SetPoint("TOPLEFT", UIParent, "TOPLEFT", frameLeft, screenHeight)
        end
        local newFrameLeft = frame:GetLeft()
        local newFrameTop = frame:GetTop()
        print("Frame position after adjustments: Left = ", newFrameLeft, " Top = ", newFrameTop)
    else
        print("No frame found for anchoring.")
    end
   
    if NUI:IsAddOnEnabled("Cell_UnitFrames") then
        if not C_AddOns.LoadAddOn("Cell_UnitFrames") then
            print("Loading Cell_UnitFrames...")
            C_AddOns.LoadAddOn("Cell_UnitFrames")
        else
            print("Cell_UnitFrames is already loaded.")
        end
        
        if CUF_Player and CUF_Player:IsShown() then
            print("Returning CUF_Player...")
            return CUF_Player
        end
    end
    
    if NUI:IsAddOnEnabled("ElvUI") then
        if not C_AddOns.LoadAddOn("ElvUI") then
            print("Loading ElvUI...")
            C_AddOns.LoadAddOn("ElvUI")
        else
            print("ElvUI is already loaded.")
        end
        
        if ElvUF_Player then
            local point, relativeTo, relativePoint, offsetX, offsetY = ElvUF_Player:GetPoint()
            print("ElvUF_Player anchor point:", point, relativeTo, relativePoint, offsetX, offsetY)
            
            if ElvUF_Player:IsShown() then
                print("ElvUF_Player is shown and being returned...")
                return ElvUF_Player
            else
                print("ElvUF_Player is not visible.")
            end
        end
    end
    
    if NUI:IsAddOnEnabled("ShadowedUnitFrames") then
        if not C_AddOns.LoadAddOn("ShadowedUnitFrames") then
            print("Loading ShadowedUnitFrames...")
            C_AddOns.LoadAddOn("ShadowedUnitFrames")
        else
            print("ShadowedUnitFrames is already loaded.")
        end
        
        if SUFUnitplayer and SUFUnitplayer:IsShown() then
            print("Returning SUFUnitplayer...")
            return SUFUnitplayer
        end
    end
    
    if PlayerFrame and PlayerFrame:IsShown() then
        print("Returning PlayerFrame...")
        return PlayerFrame
    end
    
    print("No valid frame found.")
    return nil
end

and it properly returns everything I'd expect:
Using frame: table: 0000022BFC7EC1C0
Frame position before adjustments: Left = 689.42852783203 Top = 424.8571472168
Frame position after adjustments: Left = 689.42852783203 Top = 424.8571472168
ElvUI is already loaded.
ElvUF_Player anchor point: BOTTOM table: 0000022BFC7FE6A0 BOTTOM 0 0
ElvUF_Player is shown and being returned...

(mind you the original code is much simpler, this is heavily modified to troubleshoot)

#

Original code for comparison

function()
    local NUI = unpack(NaowhUI)

    if NUI:IsAddOnEnabled("Cell_UnitFrames") then
        if not C_AddOns.IsAddOnLoaded("Cell_UnitFrames") then
            C_AddOns.LoadAddOn("Cell_UnitFrames")
        end

        local CUF_Player = _G["Cell_UnitFrames_Player"]
        if CUF_Player and CUF_Player:IsShown() then
            return CUF_Player
        end
    end

    if NUI:IsAddOnEnabled("ElvUI") then
        if not C_AddOns.IsAddOnLoaded("ElvUI") then
            C_AddOns.LoadAddOn("ElvUI")
        end

        local ElvUF_Player = _G["ElvUF_Player"]
        if ElvUF_Player and ElvUF_Player:IsShown() then
            return ElvUF_Player
        end
    end

    if NUI:IsAddOnEnabled("ShadowedUnitFrames") then
        if not C_AddOns.IsAddOnLoaded("ShadowedUnitFrames") then
            C_AddOns.LoadAddOn("ShadowedUnitFrames")
        end

        local SUFUnitplayer = _G["SUFUnitplayer"]
        if SUFUnitplayer and SUFUnitplayer:IsShown() then
            return SUFUnitplayer
        end
    end

    if PlayerFrame and PlayerFrame:IsShown() then
        return PlayerFrame
    end
end
bronze oar
#

there's someone who has an Addon that creates only anchors, and then there are raid teams who use the addon to move anchor-points, and their Auras they tie to those anchors

this reduces the notion to making (one of those points) their anchor, instead of trying to decide which guildies do or do not use (elvUI, SUF, etc)

#

I might be not answering your question, but I hope it's addressing the Need you've described.