You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
3.2 KiB
109 lines
3.2 KiB
local modf = math.modf;
|
|
local After = C_Timer.After;
|
|
local GetTime = GetTime;
|
|
|
|
local framePool = {};
|
|
|
|
|
|
-----------------------------------------------------------------------
|
|
NarciItemCooldownUtil = {};
|
|
|
|
local function AccquireFrame(parentItemButton)
|
|
local frame;
|
|
for i = 1, #framePool do
|
|
frame = framePool[i];
|
|
if not frame.isActive then
|
|
frame:ClearAllPoints();
|
|
frame:SetParent(parentItemButton);
|
|
frame:SetPoint("CENTER", parentItemButton, "CENTER", 0, 0);
|
|
return framePool[i]
|
|
end
|
|
end
|
|
frame = CreateFrame("Frame", nil, parentItemButton, "NarciItemCooldownFrameTemplate");
|
|
frame:SetPoint("CENTER", parentItemButton, "CENTER", 0, 0);
|
|
return frame
|
|
end
|
|
|
|
local function GetFrameCount()
|
|
local numTotal = #framePool;
|
|
local numActive = 0;
|
|
for i = 1, numTotal do
|
|
if framePool[i].isActive then
|
|
numActive = numActive + 1;
|
|
end
|
|
end
|
|
print("Total: "..numTotal);
|
|
print("Active: "..numActive);
|
|
end
|
|
|
|
|
|
NarciItemCooldownUtil.AccquireFrame = AccquireFrame;
|
|
NarciItemCooldownUtil.GetFrameCount = GetFrameCount;
|
|
|
|
|
|
-----------------------------------------------------------------------
|
|
NarciItemCooldownFrameMixin = {};
|
|
|
|
function NarciItemCooldownFrameMixin:SetCooldown(start, duration)
|
|
--start ~ timestamp \ duration ~ full duration
|
|
local timestamp = GetTime();
|
|
local activeDuration = timestamp - start;
|
|
self.Cooldown:SetCooldown(start, duration);
|
|
self.Cooldown:SetHideCountdownNumbers(false);
|
|
self.ClockFrame:Start(duration, activeDuration);
|
|
self.IconOverlay:Show();
|
|
|
|
--Synchronize blip animation to the countdown
|
|
local remainTime = (duration - activeDuration);
|
|
if start ~= self.startTime then
|
|
self.startTime = start;
|
|
self.BlipTexture:Hide();
|
|
self.BlipTexture.Blip:Stop();
|
|
local _, r = modf(remainTime);
|
|
After(r, function()
|
|
self.BlipTexture.Blip:Stop();
|
|
self.BlipTexture.Blip:Play();
|
|
self.BlipTexture:Show();
|
|
end)
|
|
|
|
After(0, function()
|
|
self.ClockFrame.Pointer:SetVertexColor(unpack(self:GetParent().itemNameColor));
|
|
end);
|
|
end
|
|
|
|
self.isActive = true;
|
|
end
|
|
|
|
function NarciItemCooldownFrameMixin:Clear()
|
|
if self.isActive then
|
|
self.isActive = nil;
|
|
self.IconOverlay:Hide();
|
|
self.BlipTexture:Hide();
|
|
self.BlipTexture.Blip:Stop();
|
|
self.Cooldown:Hide();
|
|
self.Cooldown:Clear();
|
|
self.ClockFrame:Hide();
|
|
self.startTime = 0;
|
|
end
|
|
end
|
|
|
|
function NarciItemCooldownFrameMixin:OnLoad()
|
|
self.ClockFrame:SetPointerTexture("Interface\\AddOns\\Narcissus\\Art\\Cooldown\\ProgressPointer-Polygon");
|
|
tinsert(framePool, self);
|
|
|
|
self:SetScript("OnLoad", nil);
|
|
self.OnLoad = nil;
|
|
end
|
|
|
|
function NarciItemCooldownFrameMixin:OnHide()
|
|
self:Clear();
|
|
self.ReadyBling:Hide();
|
|
end
|
|
|
|
function NarciItemCooldownFrameMixin:OnCooldownDone()
|
|
local bling = self.ReadyBling;
|
|
bling:SetVertexColor(self:GetParent().Name:GetTextColor());
|
|
bling:Show();
|
|
bling.Shine:Play();
|
|
self:Clear();
|
|
end
|
|
|