You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

魔兽世界插件Debuff框架显示异常:如何实现Debuff横向排列不重叠?

Fixing WoW Plugin Debuff Frame: Display Multiple Debuffs Side-by-Side

Hey there, let's sort out this Debuff display issue you're facing. The root problem here is that your current code only creates a single texture element, so every new Debuff just overwrites the old one instead of showing up next to it. Here's how to adjust your code to make Debuffs line up properly:

Step 1: Adjust the Initial Setup

First, update your WCCPlayer_OnLoad function to initialize an array for storing multiple Debuff textures, and widen the frame to fit multiple icons:

function WCCPlayer_OnLoad()
    this:SetHeight(40)
    this:SetWidth(220) -- Widen to fit ~5 Debuffs (adjust as needed)
    this:SetPoint("CENTER", 0, 0)
    this:RegisterEvent("UNIT_AURA")
    this:RegisterEvent("PLAYER_AURAS_CHANGED")
    
    -- Initialize an array to hold all our Debuff texture objects
    this.debuffTextures = {}
end

Step 2: Create a Debuff Update Function

Next, make a dedicated function to handle loading and arranging Debuffs. This will either reuse existing textures or create new ones as needed, then position them side-by-side:

function WCCPlayer_UpdateDebuffs(unit)
    -- Only process the player's Debuffs (adjust if you need other units)
    if unit ~= "player" then return end

    local debuffIndex = 1
    local debuffSpacing = 45 -- 40px icon + 5px gap

    -- Hide all existing Debuff textures first (we'll show active ones below)
    for _, texture in ipairs(this.debuffTextures) do
        texture:Hide()
    end

    -- Loop through all active Debuffs on the player
    while true do
        -- Get Debuff details (check your WoW version's UnitDebuff docs for parameter order!)
        local name, _, icon, count, _, duration, expirationTime, _, _, spellId = UnitDebuff(unit, debuffIndex)
        
        -- Exit loop if there are no more Debuffs
        if not name then break end

        -- Grab an existing texture or create a new one
        local debuffTexture = this.debuffTextures[debuffIndex]
        if not debuffTexture then
            debuffTexture = this:CreateTexture(nil, "BACKGROUND")
            debuffTexture:SetHeight(40)
            debuffTexture:SetWidth(40)
            this.debuffTextures[debuffIndex] = debuffTexture
        end

        -- Set the Debuff icon and show it
        debuffTexture:SetTexture(icon)
        debuffTexture:Show()

        -- Position the texture: first one left-aligned, others shifted right
        debuffTexture:SetPoint("LEFT", this, "LEFT", (debuffIndex - 1) * debuffSpacing, 0)

        -- Optional: Add stack count text (uncomment if you want this)
        -- if count and count > 1 then
        --     if not debuffTexture.countText then
        --         debuffTexture.countText = this:CreateFontString(nil, "OVERLAY")
        --         debuffTexture.countText:SetFont("Fonts\\FRIZQT__.TTF", 14, "OUTLINE")
        --         debuffTexture.countText:SetPoint("BOTTOMRIGHT", debuffTexture, "BOTTOMRIGHT", 2, -2)
        --     end
        --     debuffTexture.countText:SetText(tostring(count))
        --     debuffTexture.countText:Show()
        -- elseif debuffTexture.countText then
        --     debuffTexture.countText:Hide()
        -- end

        debuffIndex = debuffIndex + 1
    end
end

Step 3: Hook the Update to Your Event Handler

Finally, update your event handler to call the new update function whenever a player's auras change:

function WCCPlayer_OnEvent(event, unit)
    -- Handle both UNIT_AURA (targeted unit auras change) and PLAYER_AURAS_CHANGED (player's own auras)
    if event == "UNIT_AURA" then
        WCCPlayer_UpdateDebuffs(unit)
    elseif event == "PLAYER_AURAS_CHANGED" then
        WCCPlayer_UpdateDebuffs("player")
    end
end

Quick Notes

  • Frame Width: Adjust the SetWidth value in WCCPlayer_OnLoad based on how many Debuffs you want to display at once. For example, 45 * 8 would fit 8 Debuffs with spacing.
  • WoW Version Compatibility: Double-check the UnitDebuff parameter order for your specific WoW version (Classic vs. Retail have slight differences).
  • Extra Features: The commented-out code adds stack count text—feel free to uncomment and tweak it if you want that functionality.

内容的提问来源于stack exchange,提问作者Pokeystab

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 03:51:51