Lua - 魔兽世界 API Debuff 框架

标签 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

最佳答案

我认为这完全与框架位置有关,正如您所说,新框架显示在前一框架之上。

您需要让新的框架位置紧挨着前一个框架位置,这样每次您运行 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),所以毫无疑问会有更好、更高效/有效的方法来解决您的问题。

关于Lua - 魔兽世界 API Debuff 框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49834962/

相关文章:

Lua 模拟 require 函数

lua - 魔兽世界 LUA API UnitClass() 返回 nil 值

arrays - 如何在lua中循环遍历二维数组

c++ - 如何在不运行 Lua 脚本的情况下识别未初始化的变量

lua - 当 block 函数返回 nil 时 load() 的行为

string - 如何检查Lua中的字符串中是否找到匹配的文本?

Lua, WOW 和 "..."

php - Lua 与 PHP/Python/JSP/等

oop - 如何导出,然后在 Lua 中访问导出的方法

c# - 在 C# 中选择名称相同但属性内部文本不同的 XML 节点