8e02510745
camelot's aura bars for the player, with weapon enchants first and the collapse button for long and permanent buffs, on 1.12's player aura API (GetPlayerBuff indices, PLAYER_AURAS_CHANGED, CancelPlayerBuff, SetPlayerBuff tooltips). 1.12 has no consolidation and cannot cancel a weapon enchant, so neither is offered. Verified with the addon harness on the forever test build: a clean load, the harness player's buff on the bar with its icon, the stock BuffFrame hidden, the collapse button hiding the long buff. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
443 lines
13 KiB
Lua
443 lines
13 KiB
Lua
-- Ported from data/addon/ForeverUI/Buffs.lua: the player's buff and debuff bars in camelot style
|
|
-- (blizzard_buffframe, AuraContainerMixin), with the collapse button for long and permanent
|
|
-- buffs; the client's BuffFrame and weapon enchants are hidden.
|
|
-- 1.12: a player aura is a buff index from GetPlayerBuff(slot, filter), its texture, stacks,
|
|
-- dispel type and time left read by that index, cancelled by CancelPlayerBuff, its tooltip
|
|
-- SetPlayerBuff; PLAYER_AURAS_CHANGED tells a change. 1.12 has no consolidation, no colorblind
|
|
-- symbols, and its weapon enchants cannot be cancelled.
|
|
|
|
if not MoonWellUI_IsForever() then
|
|
return
|
|
end
|
|
|
|
local B = {}
|
|
ForeverUI.Buffs = B
|
|
|
|
local L = ForeverUI.L
|
|
|
|
local G = {
|
|
width = 30, height = 40, icon = 30,
|
|
border = 40, enchantBorder = 32,
|
|
space = 5,
|
|
collapseW = 15, collapseH = 30, arrowW = 10, arrowH = 16, highlight = 0.4,
|
|
alert = 31, alertDuration = 90,
|
|
period = 1.5, alphaMin = 0.3, alphaMax = 1,
|
|
check = 0.2, tooltip = 0.2,
|
|
}
|
|
|
|
-- 1.12 shows up to 16 buffs and 16 debuffs on the player.
|
|
local BARS = {
|
|
buffs = { name = "ForeverUIBuffFrame", filter = "HELPFUL", max = 16, perRow = 11,
|
|
x = -255, y = -10, caption = L.BUFFS_EDIT_LABEL_BUFFS },
|
|
debuffs = { name = "ForeverUIDebuffFrame", filter = "HARMFUL", max = 16, perRow = 8,
|
|
x = -270, y = -155, caption = L.BUFFS_EDIT_LABEL_DEBUFFS, showType = true },
|
|
}
|
|
|
|
-- Border per type (camelot DEBUFF_DISPLAY_INFO): no icon, with icon.
|
|
local TYPES = {
|
|
Magic = { "ui-debuff-border-magic-noicon", "ui-debuff-border-magic-icon" },
|
|
Curse = { "ui-debuff-border-curse-noicon", "ui-debuff-border-curse-icon" },
|
|
Disease = { "ui-debuff-border-disease-noicon", "ui-debuff-border-disease-icon" },
|
|
Poison = { "ui-debuff-border-poison-noicon", "ui-debuff-border-poison-icon" },
|
|
None = { "ui-debuff-border-default-noicon" },
|
|
}
|
|
|
|
local ENCHANT_BORDER = "Interface\\Buttons\\UI-TempEnchant-Border"
|
|
|
|
local function durations() return SHOW_BUFF_DURATIONS == "1" end
|
|
|
|
-- ---------- Warning blink
|
|
|
|
-- AuraContainerWarningFader: under 31 s, alpha goes 0.3 -> 1 -> 0.3 over 1.5 s, the same for
|
|
-- all icons. rest: seconds left.
|
|
function B.warningAlpha(rest)
|
|
if rest and rest < G.alert then
|
|
local half = G.period / 2
|
|
local t = math.mod(GetTime(), G.period)
|
|
local p = (t < half) and (t / half) or ((G.period - t) / half)
|
|
return G.alphaMin + (G.alphaMax - G.alphaMin) * p
|
|
end
|
|
return G.alphaMax
|
|
end
|
|
|
|
-- ---------- One button
|
|
|
|
local function tooltip(b)
|
|
GameTooltip:SetOwner(b, "ANCHOR_BOTTOMLEFT")
|
|
if b.auraType == "TempEnchant" then
|
|
GameTooltip:SetInventoryItem("player", b.info.ID)
|
|
else
|
|
GameTooltip:SetPlayerBuff(b.info.index)
|
|
end
|
|
end
|
|
|
|
local function updateDuration(b, rest)
|
|
if rest and durations() then
|
|
b.Duration:SetText(SecondsToTimeAbbrev(rest))
|
|
local c = (rest < G.alertDuration) and HIGHLIGHT_FONT_COLOR or NORMAL_FONT_COLOR
|
|
b.Duration:SetVertexColor(c.r, c.g, c.b)
|
|
b.Duration:Show()
|
|
else
|
|
b.Duration:Hide()
|
|
end
|
|
end
|
|
|
|
local function onUpdate()
|
|
local b = this
|
|
if not b.info then return end
|
|
b:SetAlpha(B.warningAlpha(b.rest))
|
|
b.rest = math.max((b.info.expirationTime or 0) - GetTime(), 0)
|
|
updateDuration(b, b.rest)
|
|
b.tooltipTimer = (b.tooltipTimer or 0) - (arg1 or 0)
|
|
if b.tooltipTimer <= 0 then
|
|
b.tooltipTimer = G.tooltip
|
|
if GameTooltip:IsOwned(b) then tooltip(b) end
|
|
end
|
|
end
|
|
|
|
local function applyType(b, auraType)
|
|
b.auraType = auraType
|
|
if auraType == "Debuff" then
|
|
ForeverUI.SetAtlas(b.DebuffBorder, TYPES.None[1])
|
|
b.DebuffBorder:Show()
|
|
b.TempEnchantBorder:Hide()
|
|
elseif auraType == "TempEnchant" then
|
|
b.DebuffBorder:Hide()
|
|
b.TempEnchantBorder:Show()
|
|
else
|
|
b.DebuffBorder:Hide()
|
|
b.TempEnchantBorder:Hide()
|
|
end
|
|
end
|
|
|
|
local function applyExpiration(b, info)
|
|
if info.expirationTime and info.expirationTime > 0 then
|
|
if durations() then b.Duration:Show() else b.Duration:Hide() end
|
|
b.rest = info.expirationTime - GetTime()
|
|
b:SetScript("OnUpdate", onUpdate)
|
|
else
|
|
b.Duration:Hide()
|
|
b:SetScript("OnUpdate", nil)
|
|
b.rest = nil
|
|
b:SetAlpha(1)
|
|
end
|
|
end
|
|
|
|
-- AuraButtonMixin:Update. info: aura data; showType: debuff border with its type icon.
|
|
function B.populate(b, info, showType)
|
|
applyType(b, info.auraType)
|
|
b.info = info
|
|
if info.auraType == "Debuff" then
|
|
local t = TYPES[info.debuffType or ""] or TYPES.None
|
|
ForeverUI.SetAtlas(b.DebuffBorder, (showType and t[2]) or t[1])
|
|
end
|
|
applyExpiration(b, info)
|
|
b.Icon:SetTexture(info.texture)
|
|
if (info.count or 0) > 1 then
|
|
b.Count:SetText(info.count)
|
|
b.Count:Show()
|
|
else
|
|
b.Count:Hide()
|
|
end
|
|
if GameTooltip:IsOwned(b) then tooltip(b) end
|
|
end
|
|
|
|
-- AuraButtonArtTemplate: 30 x 40, icon 30 on top, duration below; right-click cancels a buff.
|
|
function B.createButton(parent, name)
|
|
local b = CreateFrame("Button", name, parent)
|
|
b:SetWidth(G.width)
|
|
b:SetHeight(G.height)
|
|
b.Icon = b:CreateTexture(nil, "BACKGROUND")
|
|
b.Icon:SetWidth(G.icon)
|
|
b.Icon:SetHeight(G.icon)
|
|
b.Icon:SetPoint("TOP", b, "TOP", 0, 0)
|
|
b.Duration = b:CreateFontString(nil, "BACKGROUND", "GameFontNormalSmall")
|
|
b.Duration:SetPoint("TOP", b.Icon, "BOTTOM", 0, 0)
|
|
b.Duration:Hide()
|
|
b.DebuffBorder = b:CreateTexture(nil, "OVERLAY")
|
|
b.DebuffBorder:SetWidth(G.border)
|
|
b.DebuffBorder:SetHeight(G.border)
|
|
b.DebuffBorder:SetPoint("CENTER", b.Icon, "CENTER", 0, 0)
|
|
b.TempEnchantBorder = b:CreateTexture(nil, "OVERLAY")
|
|
b.TempEnchantBorder:SetTexture(ENCHANT_BORDER)
|
|
b.TempEnchantBorder:SetWidth(G.enchantBorder)
|
|
b.TempEnchantBorder:SetHeight(G.enchantBorder)
|
|
b.TempEnchantBorder:SetPoint("CENTER", b.Icon, "CENTER", 0, 0)
|
|
b.Count = b:CreateFontString(nil, "OVERLAY", "NumberFontNormal")
|
|
b.Count:SetPoint("BOTTOMRIGHT", b.Icon, "BOTTOMRIGHT", -2, 2)
|
|
applyType(b, nil)
|
|
b:RegisterForClicks("RightButtonUp")
|
|
b:SetScript("OnClick", function()
|
|
if this.info and this.auraType == "Buff" then
|
|
CancelPlayerBuff(this.info.index)
|
|
end
|
|
end)
|
|
b:SetScript("OnEnter", function() if this.info then tooltip(this) end end)
|
|
b:SetScript("OnLeave", function() GameTooltip:Hide() end)
|
|
b:Hide()
|
|
return b
|
|
end
|
|
|
|
-- ---------- Grid
|
|
|
|
-- Right to left, then down (AuraContainerMixin). buttons: the buttons to place.
|
|
local function arrange(container, buttons, perRow)
|
|
for i, b in ipairs(buttons) do
|
|
local col, row = math.mod(i - 1, perRow), math.floor((i - 1) / perRow)
|
|
b:ClearAllPoints()
|
|
b:SetPoint("TOPRIGHT", container, "TOPRIGHT",
|
|
-col * (G.width + G.space), -row * (G.height + G.space))
|
|
end
|
|
end
|
|
|
|
-- ---------- One bar
|
|
|
|
local function createBar(key)
|
|
local c = BARS[key]
|
|
local f = CreateFrame("Frame", c.name, UIParent)
|
|
f:SetFrameStrata("LOW")
|
|
f.key, f.c = key, c
|
|
f.container = CreateFrame("Frame", nil, f)
|
|
f.container:SetWidth(1)
|
|
f.container:SetHeight(1)
|
|
f.buttons = {}
|
|
-- the buff bar also holds the two weapon enchants, listed first
|
|
local count = c.max + ((key == "buffs") and 2 or 0)
|
|
for i = 1, count do
|
|
f.buttons[i] = B.createButton(f.container, c.name .. "Button" .. i)
|
|
end
|
|
local rows = math.ceil(count / c.perRow)
|
|
local width = (G.width + G.space) * c.perRow
|
|
if key == "buffs" then width = width + G.collapseW end
|
|
f:SetWidth(width)
|
|
f:SetHeight((G.height + G.space) * rows)
|
|
f.auras = {}
|
|
return f
|
|
end
|
|
|
|
-- Collapse button: bag-arrow, flipped when the bar is expanded. t: arrow texture.
|
|
local function orientArrow(t, flipped)
|
|
local e = ForeverUI.AtlasEntry("bag-arrow")
|
|
if not e then return end
|
|
t:SetTexture(e[1])
|
|
local u1, u2, v1, v2 = e[2], e[3], e[4], e[5]
|
|
if flipped then
|
|
t:SetTexCoord(u2, v2, u2, v1, u1, v2, u1, v1)
|
|
else
|
|
t:SetTexCoord(u1, v1, u1, v2, u2, v1, u2, v2)
|
|
end
|
|
end
|
|
|
|
function B.orientCollapse()
|
|
local r = B.buffs.collapse
|
|
-- Icons grow to the left: expanded, the arrow is rotated by pi.
|
|
local expanded = r:GetChecked() and true or false
|
|
for _, t in ipairs({ r:GetNormalTexture(), r:GetPushedTexture(), r:GetHighlightTexture() }) do
|
|
orientArrow(t, expanded)
|
|
end
|
|
end
|
|
|
|
local function createCollapse(f)
|
|
local r = CreateFrame("CheckButton", f.c.name .. "CollapseAndExpandButton", f)
|
|
r:SetWidth(G.collapseW)
|
|
r:SetHeight(G.collapseH)
|
|
r:SetPoint("TOPRIGHT", f, "TOPRIGHT", 0, 0)
|
|
local e = ForeverUI.AtlasEntry("bag-arrow")
|
|
r:SetNormalTexture(e and e[1] or "")
|
|
r:SetPushedTexture(e and e[1] or "")
|
|
r:SetHighlightTexture(e and e[1] or "")
|
|
for _, t in ipairs({ r:GetNormalTexture(), r:GetPushedTexture(), r:GetHighlightTexture() }) do
|
|
t:ClearAllPoints()
|
|
t:SetWidth(G.arrowW)
|
|
t:SetHeight(G.arrowH)
|
|
t:SetPoint("CENTER", r, "CENTER", 0, 0)
|
|
end
|
|
r:GetHighlightTexture():SetBlendMode("ADD")
|
|
r:GetHighlightTexture():SetAlpha(G.highlight)
|
|
r:SetChecked(1)
|
|
r:SetScript("OnClick", function()
|
|
B.expanded = this:GetChecked() and true or false
|
|
B.orientCollapse()
|
|
B.update()
|
|
end)
|
|
f.collapse = r
|
|
f.container:SetPoint("TOPRIGHT", r, "TOPLEFT", 0, 0)
|
|
return r
|
|
end
|
|
|
|
-- ---------- Data
|
|
|
|
-- Weapon enchants: main hand, then off hand, listed before the buffs.
|
|
local function enchantments(list)
|
|
local now = GetTime()
|
|
local hasMain, expMain, chMain, hasOff, expOff, chOff = GetWeaponEnchantInfo()
|
|
for _, e in ipairs({ { hasMain, expMain, chMain, 16 }, { hasOff, expOff, chOff, 17 } }) do
|
|
if e[1] then
|
|
local rest = (e[2] or 0) / 1000
|
|
table.insert(list, {
|
|
auraType = "TempEnchant",
|
|
texture = GetInventoryItemTexture("player", e[4]),
|
|
count = e[3] or 0,
|
|
expirationTime = now + rest,
|
|
ID = e[4],
|
|
hideable = rest > G.alertDuration,
|
|
})
|
|
end
|
|
end
|
|
end
|
|
|
|
-- Appends the player's auras of one filter to list. hideable: no duration or more than 90 s left.
|
|
local function auras(filter, max, list)
|
|
local now = GetTime()
|
|
for slot = 0, max - 1 do
|
|
local index, untilCancelled = GetPlayerBuff(slot, filter)
|
|
if not index or index < 0 then break end
|
|
local rest = (untilCancelled == 1) and 0 or GetPlayerBuffTimeLeft(index)
|
|
local info = {
|
|
auraType = (filter == "HELPFUL") and "Buff" or "Debuff",
|
|
index = index,
|
|
texture = GetPlayerBuffTexture(index),
|
|
count = GetPlayerBuffApplications(index) or 0,
|
|
debuffType = (filter == "HARMFUL") and GetPlayerBuffDispelType(index) or nil,
|
|
expirationTime = (rest and rest > 0) and (now + rest) or 0,
|
|
}
|
|
if filter == "HELPFUL" then
|
|
info.hideable = info.expirationTime == 0 or rest > G.alertDuration
|
|
end
|
|
table.insert(list, info)
|
|
end
|
|
end
|
|
|
|
-- ---------- Update
|
|
|
|
B.expanded = true
|
|
|
|
function B.updateBuffs()
|
|
local f = B.buffs
|
|
local list = {}
|
|
enchantments(list)
|
|
auras("HELPFUL", f.c.max, list)
|
|
f.auras = list
|
|
local hideableCount = 0
|
|
for _, info in ipairs(list) do
|
|
if info.hideable then hideableCount = hideableCount + 1 end
|
|
end
|
|
f.hideableCount = hideableCount
|
|
local total = table.getn(list)
|
|
local following = 1
|
|
local toPlace = {}
|
|
for _, b in ipairs(f.buttons) do
|
|
local info
|
|
while following <= total do
|
|
local candidate = list[following]
|
|
following = following + 1
|
|
if B.expanded or not candidate.hideable then
|
|
info = candidate
|
|
break
|
|
end
|
|
end
|
|
if info then
|
|
B.populate(b, info)
|
|
b:Show()
|
|
table.insert(toPlace, b)
|
|
else
|
|
b.info = nil
|
|
b:SetScript("OnUpdate", nil)
|
|
b:Hide()
|
|
end
|
|
end
|
|
arrange(f.container, toPlace, f.c.perRow)
|
|
-- Collapse button only if something can be hidden
|
|
if hideableCount > 0 then f.collapse:Show() else f.collapse:Hide() end
|
|
f.collapse:SetChecked(B.expanded and 1 or nil)
|
|
B.orientCollapse()
|
|
-- Watch for hidden buffs that drop under 90 s and return to the bar
|
|
f.pending = (not B.expanded and hideableCount > 0) and G.check or nil
|
|
end
|
|
|
|
function B.updateDebuffs()
|
|
local f = B.debuffs
|
|
local list = {}
|
|
auras("HARMFUL", f.c.max, list)
|
|
f.auras = list
|
|
local toPlace = {}
|
|
for i, b in ipairs(f.buttons) do
|
|
local info = list[i]
|
|
if info then
|
|
B.populate(b, info, f.c.showType)
|
|
b:Show()
|
|
table.insert(toPlace, b)
|
|
else
|
|
b.info = nil
|
|
b:SetScript("OnUpdate", nil)
|
|
b:Hide()
|
|
end
|
|
end
|
|
arrange(f.container, toPlace, f.c.perRow)
|
|
end
|
|
|
|
function B.update()
|
|
B.updateBuffs()
|
|
B.updateDebuffs()
|
|
end
|
|
|
|
-- ---------- Build
|
|
|
|
B.buffs = createBar("buffs")
|
|
B.debuffs = createBar("debuffs")
|
|
createCollapse(B.buffs)
|
|
B.orientCollapse()
|
|
B.debuffs.container:SetPoint("TOPRIGHT", B.debuffs, "TOPRIGHT", 0, 0)
|
|
|
|
for _, key in ipairs({ "buffs", "debuffs" }) do
|
|
local c = BARS[key]
|
|
ForeverUI.Layout.Register(B[key], key, c.caption, "TOPRIGHT", "TOPRIGHT", c.x, c.y)
|
|
end
|
|
|
|
-- The client's BuffFrame and weapon enchants
|
|
ForeverUI.Suppress(BuffFrame)
|
|
ForeverUI.Suppress(TemporaryEnchantFrame)
|
|
|
|
-- Interface Options' buff durations go through this one
|
|
ForeverUI.HookGlobal("BuffButtons_UpdatePositions", function() B.update() end)
|
|
|
|
local watcher = CreateFrame("Frame")
|
|
watcher:RegisterEvent("PLAYER_AURAS_CHANGED")
|
|
watcher:RegisterEvent("PLAYER_ENTERING_WORLD")
|
|
watcher:SetScript("OnEvent", function() B.update() end)
|
|
|
|
-- Every 0.2 s: weapon enchants (no event; the client's TemporaryEnchantFrame polls every frame)
|
|
-- and hidden buffs that return to the collapsed bar.
|
|
local function enchantsSignature()
|
|
local a, _, ca, g, _, cg = GetWeaponEnchantInfo()
|
|
return tostring(a) .. ":" .. tostring(ca) .. ":" .. tostring(GetInventoryItemTexture("player", 16))
|
|
.. "|" .. tostring(g) .. ":" .. tostring(cg) .. ":" .. tostring(GetInventoryItemTexture("player", 17))
|
|
end
|
|
|
|
watcher.clock = 0
|
|
watcher:SetScript("OnUpdate", function()
|
|
this.clock = this.clock - (arg1 or 0)
|
|
if this.clock > 0 then return end
|
|
this.clock = G.check
|
|
local s = enchantsSignature()
|
|
if s ~= this.enchants then
|
|
this.enchants = s
|
|
B.update()
|
|
return
|
|
end
|
|
local f = B.buffs
|
|
if f.pending then
|
|
local now = GetTime()
|
|
for _, info in ipairs(f.auras) do
|
|
if info.hideable and info.expirationTime and info.expirationTime > 0
|
|
and (info.expirationTime - now) <= G.alertDuration then
|
|
B.update()
|
|
return
|
|
end
|
|
end
|
|
end
|
|
end)
|
|
B.watcher = watcher
|
|
|
|
B.update()
|