Files
pfUI/modules/lossofcontrol.lua
T
Brues 001e09c1b7 Pick cooldown timers per feature with one dropdown
Each feature's settings page now picks its own timers - None, Numbers,
Sweep, or Numbers And Sweep - in place of the "Show Numbers On", "Show
Sweep On" and "Reverse Sweep On" lists on Settings -> Cooldown. Unit
frames get theirs per frame again ("Buff And Debuff Timers" and
"Indicator Timers"), so party and pet can drop their numbers while the
target keeps them. The other dropdowns sit on Action Bars, Bags & Bank,
Buff/Debuff Icons, Totem Icons, Tooltip and Nameplates.

Settings -> Cooldown keeps the shared font, size, threshold, tenths and
colors, plus the timers of Spellbook And Character, Loss Of Control and
Other Addons, which have no page of their own.

CreateCooldown(parent, kind, config, key, name) reads its mode from
config[key]. The kind says only what it times: "spell" hides numbers on
the global cooldown, "aura" drains its sweep, "timer" fills it. The
reverse option is gone; the direction follows the kind.

The migration carries every old setting into its timers: the
C.cooldown kind tables, appearance.cd's foreign and Blizzard toggles,
the buff frame's sweep, the nameplate debuff options, and each unit
frame's timer text, sweep and "Show Time Left" from before the kinds,
so frames that had their own settings keep them. Reverse options are
dropped.
2026-11-02 16:07:41 -06:00

89 lines
3.2 KiB
Lua

pfUI:RegisterModule("lossofcontrol", function ()
-- 5.x's loss of control alert. ClassicAPI's C_LossOfControl builds the
-- effects from the player's debuffs and from the school lockout of an
-- interrupt.
local strings = L["lossofcontrol"]
-- how much each effect takes away; the alert shows the strongest one
local PRIORITY = {
STUN = 3, FEAR = 3, CONFUSE = 3, CHARM = 3, POSSESS = 3, PACIFYSILENCE = 3,
SILENCE = 2, SCHOOL_INTERRUPT = 2, PACIFY = 2,
DISARM = 1, ROOT = 1,
}
-- the lockout packet does not name the interrupting spell
local INTERRUPT_ICON = "Interface\\Icons\\Ability_Kick"
local function IsStronger(data, best)
local priority, bestPriority = PRIORITY[data.locType], PRIORITY[best.locType]
if priority ~= bestPriority then return priority > bestPriority end
return (data.timeRemaining or math.huge) > (best.timeRemaining or math.huge)
end
local frame = CreateFrame("Frame", "pfLossOfControl", UIParent)
frame:SetSize(220, 48)
frame:SetPoint("CENTER", 0, 120)
frame:SetFrameStrata("HIGH")
frame:Hide()
frame.icon = CreateFrame("Frame", nil, frame)
frame.icon:SetSize(48, 48)
frame.icon:SetPoint("LEFT", 0, 0)
CreateBackdrop(frame.icon, nil, true)
frame.icon.tex = frame.icon:CreateTexture(nil, "ARTWORK")
HandleIcon(frame.icon, frame.icon.tex)
frame.cd = CreateCooldown(frame.icon, "timer", C.cooldown, "lossofcontrol_timers")
frame.cd:SetAllPoints(frame.icon.tex)
frame.label = frame:CreateFontString(nil, "OVERLAY")
frame.label:SetFont(pfUI.font_default, 20, "OUTLINE")
frame.label:SetTextColor(NORMAL_FONT_COLOR:GetRGB())
frame.label:SetPoint("LEFT", frame.icon, "RIGHT", 8, 0)
frame.Refresh = function(self)
local best
for i = 1, C_LossOfControl.GetActiveLossOfControlDataCount() do
local data = C_LossOfControl.GetActiveLossOfControlData(i)
if not best or IsStronger(data, best) then best = data end
end
if not best then
if pfUI.unlock and pfUI.unlock:IsShown() then return end
self:Hide()
return
end
if best.locType == "SCHOOL_INTERRUPT" then
self.label:SetText(format(strings.LOSS_OF_CONTROL_DISPLAY_INTERRUPT_SCHOOL, C_Spell.GetSchoolString(best.lockoutSchool)))
self.icon.tex:SetTexture(INTERRUPT_ICON)
else
self.label:SetText(strings["LOSS_OF_CONTROL_DISPLAY_" .. best.locType])
self.icon.tex:SetTexture(best.iconTexture)
end
CooldownFrame_SetTimer(self.cd, best.startTime or 0, best.duration or 0, best.startTime and 1 or 0)
self:Show()
end
-- a refreshed debuff (UNIT_AURA_DELTA) or a second kick on the same school
-- (SPELL_UPDATE_COOLDOWN) changes the timer without a loss of control event
frame:SetScript("OnShow", function()
this:RegisterUnitEvent("UNIT_AURA_DELTA", "player")
this:RegisterEvent("SPELL_UPDATE_COOLDOWN")
end)
frame:SetScript("OnHide", function()
this:UnregisterAllEvents()
end)
frame:SetScript("OnEvent", function()
this:Refresh()
end)
pfUI.events:RegisterFrameEventAndCallback("LOSS_OF_CONTROL_ADDED", function() frame:Refresh() end)
pfUI.events:RegisterFrameEventAndCallback("LOSS_OF_CONTROL_UPDATE", function() frame:Refresh() end)
UpdateMovable(frame)
pfUI.lossofcontrol = frame
end)