146 lines
5.4 KiB
Lua
146 lines
5.4 KiB
Lua
-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
|
|
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
|
|
-- Timer bars and the centre warning icon, drawn with Blizzard's own textures and fonts.
|
|
local BM = OctoBossMods
|
|
local Bars = {active = {}, pool = {}}
|
|
BM.Bars = Bars
|
|
|
|
local WIDTH, HEIGHT, GAP = 220, 18, 3
|
|
local anchor = CreateFrame("Frame", "OctoBossModsAnchor", UIParent, "BackdropTemplate")
|
|
anchor:SetSize(WIDTH + HEIGHT, HEIGHT)
|
|
anchor:SetMovable(true)
|
|
anchor:SetClampedToScreen(true)
|
|
anchor:RegisterForDrag("LeftButton")
|
|
anchor:SetScript("OnDragStart", anchor.StartMoving)
|
|
anchor:SetBackdrop({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
|
|
edgeSize = 12, insets = {left = 3, right = 3, top = 3, bottom = 3}})
|
|
anchor:SetBackdropColor(0, 0, 0, 0.6)
|
|
local label = anchor:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
|
|
label:SetPoint("CENTER")
|
|
label:SetText("Boss Mods bars (drag, /obm lock)")
|
|
anchor:Hide()
|
|
|
|
function Bars:Init(db)
|
|
self.db = db
|
|
db.anchor = db.anchor or {"CENTER", "CENTER", 300, -120}
|
|
local a = db.anchor
|
|
anchor:ClearAllPoints()
|
|
anchor:SetPoint(a[1], UIParent, a[2], a[3], a[4])
|
|
anchor:SetScript("OnDragStop", function(f)
|
|
f:StopMovingOrSizing()
|
|
local p, _, rp, x, y = f:GetPoint()
|
|
db.anchor = {p, rp, x, y}
|
|
end)
|
|
end
|
|
function Bars:SetLocked(locked)
|
|
anchor:EnableMouse(not locked)
|
|
anchor:SetShown(not locked)
|
|
end
|
|
|
|
local function texture(icon)
|
|
if type(icon) == "number" then
|
|
-- A spell ID when the client knows it as one, otherwise a file data ID (70334 has no global GetSpellTexture).
|
|
local tex = C_Spell and C_Spell.GetSpellTexture and C_Spell.GetSpellTexture(icon)
|
|
return tex or icon
|
|
end
|
|
if type(icon) == "string" and not strfind(icon, "\\", 1, true) then return "Interface\\Icons\\" .. icon end
|
|
return icon or 134400
|
|
end
|
|
|
|
local function layout()
|
|
local list = {}
|
|
for _, bar in pairs(Bars.active) do list[#list + 1] = bar end
|
|
table.sort(list, function(a, b) return a.ends < b.ends end)
|
|
for i, bar in ipairs(list) do
|
|
bar:ClearAllPoints()
|
|
bar:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", HEIGHT, -(i - 1) * (HEIGHT + GAP) - GAP)
|
|
end
|
|
end
|
|
|
|
local function update(bar)
|
|
local left = bar.ends - GetTime()
|
|
if left <= 0 then Bars:Stop(bar.text) return end
|
|
bar:SetValue(left)
|
|
if bar.low and left > bar.duration - bar.low then
|
|
bar.time:SetFormattedText("%.1f-%.1f", left - (bar.duration - bar.low), left)
|
|
else
|
|
bar.time:SetText(left < 10 and format("%.1f", left) or SecondsToClock and SecondsToClock(left) or format("%d", left))
|
|
end
|
|
end
|
|
|
|
local function acquire()
|
|
local bar = tremove(Bars.pool)
|
|
if bar then return bar end
|
|
bar = CreateFrame("StatusBar", nil, UIParent, "BackdropTemplate")
|
|
bar:SetSize(WIDTH, HEIGHT)
|
|
bar:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
|
|
bar:SetBackdrop({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background"})
|
|
bar:SetBackdropColor(0, 0, 0, 0.5)
|
|
bar.icon = bar:CreateTexture(nil, "ARTWORK")
|
|
bar.icon:SetSize(HEIGHT, HEIGHT)
|
|
bar.icon:SetPoint("RIGHT", bar, "LEFT", 0, 0)
|
|
bar.icon:SetTexCoord(0.07, 0.93, 0.07, 0.93)
|
|
bar.label = bar:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
|
|
bar.label:SetPoint("LEFT", 4, 0)
|
|
bar.label:SetPoint("RIGHT", -40, 0)
|
|
bar.label:SetJustifyH("LEFT")
|
|
bar.time = bar:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
|
|
bar.time:SetPoint("RIGHT", -4, 0)
|
|
bar:SetScript("OnUpdate", update)
|
|
return bar
|
|
end
|
|
|
|
function Bars:Start(text, seconds, icon, color, low, persist)
|
|
if not text or not seconds or seconds <= 0 then return end
|
|
self:Stop(text)
|
|
local bar = acquire()
|
|
bar.text, bar.duration, bar.low, bar.persist = text, seconds, low, persist
|
|
bar.ends = GetTime() + seconds
|
|
bar:SetMinMaxValues(0, seconds)
|
|
bar:SetStatusBarColor(color[1], color[2], color[3])
|
|
bar.icon:SetTexture(texture(icon))
|
|
bar.label:SetText(text)
|
|
bar:Show()
|
|
self.active[text] = bar
|
|
update(bar)
|
|
layout()
|
|
end
|
|
function Bars:Stop(text)
|
|
local bar = self.active[text]
|
|
if not bar then return end
|
|
self.active[text] = nil
|
|
bar:Hide()
|
|
tinsert(self.pool, bar)
|
|
layout()
|
|
end
|
|
function Bars:StopAll()
|
|
-- Respawn timers outlive the encounter that started them.
|
|
local stop = {}
|
|
for text, bar in pairs(self.active) do if not bar.persist then stop[#stop + 1] = text end end
|
|
for _, text in ipairs(stop) do self:Stop(text) end
|
|
if self.sign then self.sign:Hide() end
|
|
end
|
|
|
|
-- Centre warning icon (Octo BigWigs WarningSign).
|
|
function Bars:Sign(icon, seconds, text)
|
|
local sign = self.sign
|
|
if not sign then
|
|
sign = CreateFrame("Frame", nil, UIParent)
|
|
sign:SetSize(96, 96)
|
|
sign:SetPoint("CENTER", 0, 150)
|
|
sign.tex = sign:CreateTexture(nil, "ARTWORK")
|
|
sign.tex:SetAllPoints()
|
|
sign.text = sign:CreateFontString(nil, "OVERLAY", "GameFontNormalHuge")
|
|
sign.text:SetPoint("TOP", sign, "BOTTOM", 0, -6)
|
|
self.sign = sign
|
|
end
|
|
sign.icon = icon
|
|
sign.tex:SetTexture(texture(icon))
|
|
sign.text:SetText(text or "")
|
|
sign:Show()
|
|
BM:Schedule("\1sign", seconds or 1, function() sign:Hide() end)
|
|
end
|
|
function Bars:Unsign(icon)
|
|
if self.sign and (icon == nil or self.sign.icon == icon) then self.sign:Hide() BM:Cancel("\1sign") end
|
|
end
|