Lua - 魔兽世界API Debuff框架

时间:2018-04-14 18:45:49

标签: lua world-of-warcraft

我有一个奇怪的问题,用这个AddOn它会显示一个带有当前debuff的帧。我认为它只显示第一个,如果应用另一个,它只是重叠第一个。我该如何制作它以便在旧的旁边显示新的?

这是代码:

function WCCPlayer_OnLoad() 
    this:SetHeight(40)
    this:SetWidth(40)
    this:SetPoint("CENTER", 0, 0)
    this:RegisterEvent("UNIT_AURA")
    this:RegisterEvent("PLAYER_AURAS_CHANGED")

    this.texture = this:CreateTexture(this, "BACKGROUND")
    this.texture:SetAllPoints(this)
    this.cooldown = CreateFrame("Model", "Cooldown", this, "CooldownFrameTemplate")
    this.cooldown:SetAllPoints(this) 
    this.maxExpirationTime = 0
    this:Hide()
end

function WCCPlayer_OnEvent()
    local spellFound = false
    for i=1, 16 do -- 16 is enough due to HARMFUL filter
        local texture = UnitDebuff("player", i)
        WCCTooltip:ClearLines()
        WCCTooltip:SetUnitDebuff("player", i)
        local buffName = WCCTooltipTextLeft1:GetText()

    if spellIds[buffName] then
        spellFound = true
        for j=0, 31 do
            local buffTexture = GetPlayerBuffTexture(j)
            if texture == buffTexture then
                local expirationTime = GetPlayerBuffTimeLeft(j)
                this:Show()
                this.texture:SetTexture(buffTexture)
                this.cooldown:SetModelScale(1)
                if this.maxExpirationTime <= expirationTime then
                    CooldownFrame_SetTimer(this.cooldown, GetTime(), expirationTime, 1)
                    this.maxExpirationTime = expirationTime
                end
                return
            end
        end     
    end
end
if spellFound == false then
    this.maxExpirationTime = 0
    this:Hide()
end
end

function WCCTarget_OnLoad()

end

function WCCTarget_OnEvent()

end

1 个答案:

答案 0 :(得分:0)

我认为这与帧位置有关,正如您所说,新帧显示在前一帧的顶部。

您需要在前一个位置旁边放置一个新的帧位置,以便每次运行WCCPlayer_OnLoad()函数时,都会将X坐标增加帧的宽度。

首先在函数外部声明局部 setPointX 变量,然后将 setPointX 变量增加每次运行该功能时的帧宽度(在您的情况下为40);

local setPointX, setPointY = 0,0 -- x and y variables

function WCCPlayer_OnLoad()
    this:SetHeight(40)
    this:SetWidth(40)
    this:SetPoint('CENTER', setPointX, setPointY) -- use variables to set the frame point
    this:RegisterEvent('UNIT_AURA')
    this:RegisterEvent('PLAYER_AURAS_CHANGED')

    this.texture = this:CreateTexture(this, 'BACKGROUND')
    this.texture:SetAllPoints(this)
    this.cooldown = CreateFrame('Model', 'Cooldown', this, 'CooldownFrameTemplate')
    this.cooldown:SetAllPoints(this)
    this.maxExpirationTime = 0
    this:Hide()
    setPointX = setPointX + 40 -- increase the x variable by the width of the frame
end

我没有编程的背景,(只是想教自己Java和Lua),因此无疑会有更好,更有效的方法来解决您的问题。