Небольшой набор функций для формата времени и хуки для анимации кулдауна с последующим выводом текста (похожий внешний вид имеет omnicc и аналоги). Именно эти функции и будут использованы мной далее. Возможно пополнение.
PHP код:
local addon, ns = ...
ns.FormatValue = function(value)
if (value >= 1e6) then
return format('%.1f', value/1e6)..'m'
elseif (value >= 1e3) then
return format('%.1f', value/1e3)..'k'
else
return value
end
end
local FormatTime
do
FormatTime = function(s)
local day, hour, minute = 86400, 3600, 60
local ceil, format = ceil, format
if s >= day then
return format("%dd", ceil(s / hour))
elseif s >= hour then
return format("%dh", ceil(s / hour))
elseif s >= minute then
return format("%dm", ceil(s / minute))
elseif s >= minute / 12 then
return floor(s)
end
return format("%.1f", s)
end
ns.FormatTime = FormatTime
end
local HandleCD
do
local OnUpdate = function(self)
local endTime = self.timeLeft - GetTime()
-- print(endTime)
if endTime > 0 then
-- print(endTime)
local Remaining = self.Remaining
if endTime > 2 then
Remaining:SetTextColor(1,1,1)
else
Remaining:SetTextColor(1,0,0)
end
Remaining:SetText(FormatTime(endTime))
else
self.Remaining:Hide()
end
end
local OnSetCooldown = function(self, start, duration)
self.timeLeft = start + duration
self.duration = duration
if duration > 0 then
self.Remaining:Show()
end
return self.__SetCooldown(self, start, duration)
end
local OnSetCooldownMin = function(self, start, duration)
self.timeLeft = start + duration
self.duration = duration
if duration > 2 then
self.Remaining:Show()
end
return self.__SetCooldown(self, start, duration)
end
HandleCD = function(cd, size, minduration)
local Remaining = cd:CreateFontString(nil, 'ARTWORK')
Remaining:SetFont("Fonts/FRIZQT__.ttf", size, 'OUTLINE')
Remaining:Hide()
Remaining:SetJustifyH("CENTER")
Remaining:SetShadowOffset(0, 0)
Remaining:SetPoint('CENTER', cd, 0, 0)
cd.Remaining = Remaining
cd.__SetCooldown = cd.SetCooldown
if minduration then
cd.SetCooldown = OnSetCooldownMin
else
cd.SetCooldown = OnSetCooldown
end
cd:SetScript("OnUpdate", OnUpdate)
end
ns.HandleCD = HandleCD
end