Lua - 魔兽世界 API Debuff 框体

我遇到一个奇怪的问题,使用这个插件会显示当前的 Debuff 框体。我想它只显示第一个,如果有另一个应用它就会覆盖第一个。我该如何使它显示新的 Debuff 次于旧的 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 表示由于 HARMFUL 过滤器,足够了。
        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
点赞
用户1434791
用户1434791

我认为这一切都是关于框体位置,就像你说的一样,新框体显示在旧框体的上面。

你需要让新框体紧挨在旧框体旁边,这样每次运行你的**WCCPlayer_OnLoad()**函数时都会将X坐标增加框体的宽度。

首先在函数外声明一个本地变量**setPointX**,然后每次函数运行时将该变量增加框体的宽度(在你的情况下是40);

local setPointX, setPointY = 0,0 -- x和y变量

function WCCPlayer_OnLoad()
    this:SetHeight(40)
    this:SetWidth(40)
    this:SetPoint('CENTER', setPointX, setPointY) -- 使用变量设置框体点
    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 -- 将X变量增加框体的宽度
end

我没有编程背景(只是尝试自学Java和Lua),因此肯定会有更好的和更高效/有效的方法来解决您的问题。

2018-06-25 04:41:24