local FormatTime = function(seconds)
local day, hour, minute = 86400, 3600, 60
if (seconds >= day) then
return format("%dd", floor(seconds/day + 0.5)), seconds % day
elseif (seconds >= hour) then
return format("%dh", floor(seconds/hour + 0.5)), seconds % hour
elseif (seconds >= minute) then
if (seconds <= minute * 5) then
return format("%d:%02d", floor(seconds/60), seconds % minute), seconds - floor(seconds)
end
return format("%dm", floor(seconds/minute + 0.5)), seconds % minute
elseif (seconds >= minute / 12) then
return floor(seconds + 0.5), (seconds * 100 - floor(seconds * 100)) / 100
end
return format("%.1f", seconds), (seconds * 100 - floor(seconds * 100)) / 100
end
local CreateAuraTimer = function(self, elapsed)
if (self.timeLeft) then
self.elapsed = (self.elapsed or 0) + elapsed
if (self.elapsed >= 0.1) then
if (not self.first) then
self.timeLeft = self.timeLeft - self.elapsed
else
self.timeLeft = self.timeLeft - GetTime()
self.first = false
end
if (self.timeLeft > 0) then
local time = FormatTime(self.timeLeft)
self.remaining:SetText(time)
if (self.timeLeft < 5) then
self.remaining:SetTextColor(0.69, 0.31, 0.31)
else
self.remaining:SetTextColor(0.84, 0.75, 0.65)
end
else
self.remaining:Hide()
self:SetScript("OnUpdate", nil)
end
self.elapsed = 0
end
end
end
local SortAuras = function(a, b)
if (a and b and a.timeLeft and b.timeLeft) then
return a.timeLeft > b.timeLeft
end
end
local PostCreateIcon = function(Icons, icon)
-- remove OmniCC and CooldownCount timers
icon.cd.noOCC = true
icon.cd.noCooldownCount = true
icon.count:SetPoint("BOTTOMRIGHT", 1, 1.5)
icon.count:SetFont(ns.media.FONT, 8, "OUTLINE")
icon.count:SetTextColor(0.84, 0.75, 0.65)
icon.count:SetJustifyH("RIGHT")
icon.icon:SetTexCoord(0.1, 0.9, 0.1, 0.9)
icon.overlay:SetTexture(ns.media.BTNTEXTURE)
icon.overlay:SetPoint("TOPLEFT", -3.5, 3.5)
icon.overlay:SetPoint("BOTTOMRIGHT", 3.5, -3.5)
icon.overlay:SetTexCoord(0, 1, 0, 1)
icon.remaining = PutFontString(icon, ns.media.FONT, 8, "OUTLINE", "LEFT")
icon.remaining:SetPoint("TOP", 0, 1)
end
local PreSetPosition = function(Auras)
table.sort(Auras, SortAuras)
end
local PostUpdateIcon
do
local playerUnits = {
player = true,
pet = true,
vehicle = true,
}
PostUpdateIcon = function(icons, unit, icon, index, offset)
local _, _, _, _, _, duration, expirationTime, caster, _ = UnitAura(unit, index, icon.filter)
if (not playerUnits[caster]) then
if ((UnitCanAttack("player", unit) and icon.isDebuff)
or (UnitIsFriend("player", unit) and not icon.isDebuff)) then
icon.icon:SetDesaturated(true)
icon.overlay:SetVertexColor(0.5, 0.5, 0.5)
end
end
if (duration and duration > 0) then
icon.remaining:Show()
icon.timeLeft = expirationTime
icon:SetScript("OnUpdate", CreateAuraTimer)
else
icon.remaining:Hide()
icon.timeLeft = math.huge
icon:SetScript("OnUpdate", nil)
end
icon.first = true
end
end
local AddBuffs = function(self, unit)
self.Buffs = CreateFrame("Frame", self:GetName().."_Buffs", self)
self.Buffs.spacing = 6
self.Buffs.size = (230 - 9 * self.Buffs.spacing) / 10
self.Buffs.disableCooldown = true
self.Buffs.showType = true
self.Buffs.onlyShowPlayer = ns.cfg.onlyShowPlayerBuffs
self.Buffs.PreSetPosition = PreSetPosition -- sort auras by time remaining
self.Buffs.PostCreateIcon = PostCreateIcon -- set overlay, cd, count, timer font
self.Buffs.PostUpdateIcon = PostUpdateIcon -- set icon saturation and update timer
if (unit == "player" or unit == "target") then
self.Buffs:SetSize(self.Buffs.size * 10 + 9 * self.Buffs.spacing, 4 * self.Buffs.size + 3 * self.Buffs.spacing)
self.Buffs["growth-y"] = "DOWN"
if (unit == "player") then
self.Buffs:SetPoint("TOPRIGHT", self, "TOPLEFT", -9, -1)
self.Buffs.initialAnchor = "TOPRIGHT"
self.Buffs["growth-x"] = "LEFT"
else
self.Buffs:SetPoint("TOPLEFT", self, "TOPRIGHT", 9, -1)
self.Buffs.initialAnchor = "TOPLEFT"
self.Buffs["growth-x"] = "RIGHT"
end
end
if (unit == "pet") then
self.Buffs:SetPoint("RIGHT", self.Debuffs, "LEFT", -5, 0)
self.Buffs.num = 6
self.Buffs:SetSize(self.Buffs.num * self.Buffs.size + (self.Buffs.num - 1) * self.Buffs.spacing, self.Buffs.size)
self.Buffs.initialAnchor = "RIGHT"
self.Buffs["growth-x"] = "LEFT"
end
if (unit:match("boss%d")) then
self.Buffs:SetPoint("TOPLEFT", self, "TOPRIGHT", 15, 0)
self.Buffs.num = 6
self.Buffs:SetSize(self.Buffs.num * self.Buffs.size + (self.Buffs.num - 1) * self.Buffs.spacing, self.Buffs.size)
self.Buffs.initialAnchor = "LEFT"
self.Buffs["growth-x"] = "RIGHT"
end
end
ns.AddBuffs = AddBuffs