Harden cooldown text overlays and timer updates

This commit is contained in:
Dusk-92
2026-08-24 21:32:50 +02:00
parent f8ab936025
commit f7c8205b9c
+22 -14
View File
@@ -17,18 +17,25 @@ local module = ShaguTweaks:register({
local function CooldownOnUpdate() local function CooldownOnUpdate()
-- hide frames without parent -- hide frames without parent
local parent = this:GetParent() local parent = this:GetParent()
if not parent then this:Hide() end if not parent then
this:Hide()
return
end
if not this.tick then this.tick = GetTime() + .1 end -- Text only needs tenth-of-a-second precision. Accumulate the frame elapsed
if this.tick > GetTime() then return end -- time instead of calling GetTime() several times on every rendered frame.
this.tick = GetTime() + .1 this.elapsed = (this.elapsed or 0) + arg1
if this.elapsed < .1 then return end
this.elapsed = 0
local now = GetTime()
-- fix own alpha value (should be inherited, but somehow isn't always) -- fix own alpha value (should be inherited, but somehow isn't always)
this:SetAlpha(parent:GetAlpha()) this:SetAlpha(parent:GetAlpha())
if this.start < GetTime() then if this.start < now then
-- calculating remaining time as it should be -- calculating remaining time as it should be
local remaining = this.duration - (GetTime() - this.start) local remaining = this.duration - (now - this.start)
if remaining > 0 then if remaining > 0 then
this.text:SetText(TimeConvert(remaining)) this.text:SetText(TimeConvert(remaining))
else else
@@ -37,13 +44,13 @@ local function CooldownOnUpdate()
else else
-- I have absolutely no idea, but it works: -- I have absolutely no idea, but it works:
-- https://github.com/Stanzilla/WoWUIBugs/issues/47 -- https://github.com/Stanzilla/WoWUIBugs/issues/47
local time = time() local walltime = time()
local startupTime = time - GetTime() local startupTime = walltime - now
-- just a simplification of: ((2^32) - (start * 1000)) / 1000 -- just a simplification of: ((2^32) - (start * 1000)) / 1000
local cdTime = (2 ^ 32) / 1000 - this.start local cdTime = (2 ^ 32) / 1000 - this.start
local cdStartTime = startupTime - cdTime local cdStartTime = startupTime - cdTime
local cdEndTime = cdStartTime + this.duration local cdEndTime = cdStartTime + this.duration
local remaining = cdEndTime - time local remaining = cdEndTime - walltime
if remaining >= 0 then if remaining >= 0 then
this.text:SetText(TimeConvert(remaining)) this.text:SetText(TimeConvert(remaining))
@@ -60,13 +67,13 @@ local function CreateCoolDown(cooldown, start, duration)
-- skip already set debuff timers -- skip already set debuff timers
if cooldown.readable then return end if cooldown.readable then return end
local parentname = parent and parent.GetName and parent:GetName() -- These helpers are owned directly by their cooldown and never need global
parentname = parentname or "UnknownCooldownFrame" -- names. Anonymous objects avoid collisions for cooldowns with anonymous
-- parents while preserving the exact same visual hierarchy.
cooldown.cooldowntext = CreateFrame("Frame", parentname .. "CooldownText", cooldown) cooldown.cooldowntext = CreateFrame("Frame", nil, cooldown)
cooldown.cooldowntext:SetAllPoints(cooldown) cooldown.cooldowntext:SetAllPoints(cooldown)
cooldown.cooldowntext:SetFrameLevel(parent:GetFrameLevel() + 1) cooldown.cooldowntext:SetFrameLevel(parent:GetFrameLevel() + 1)
cooldown.cooldowntext.text = cooldown.cooldowntext:CreateFontString(parentname .. "CooldownTextFont", "OVERLAY") cooldown.cooldowntext.text = cooldown.cooldowntext:CreateFontString(nil, "OVERLAY")
-- detect dynamic font size -- detect dynamic font size
local size = parent:GetHeight() or 0 local size = parent:GetHeight() or 0
@@ -102,6 +109,7 @@ local function SetCooldown(this, start, duration, enable)
if this.cooldowntext then if this.cooldowntext then
if start > 0 and duration > 0 and (not enable or enable > 0) then if start > 0 and duration > 0 and (not enable or enable > 0) then
this.cooldowntext.elapsed = 0
this.cooldowntext:Show() this.cooldowntext:Show()
else else
this.cooldowntext:Hide() this.cooldowntext:Hide()