Here's my GCD addon that i've made, hope it can help!
Lua Code:
local A, C, L = select(2, ...):unpack()
local GCDBar = CreateFrame("Frame")
local DataBars = A["DataBars"]
local Panels = A["Panels"]
-- Lib Globals
local select = select
local unpack = unpack
local floor = math.floor
-- WoW Globals
local GetSpellCooldown = GetSpellCooldown
-- Locals
GCDBar.StartTime = 0
GCDBar.Duration = 0
function GCDBar:Check(event, unit, spell)
if not (unit == "player") then
return
end
local StartTime, Duration = GetSpellCooldown(spell)
if (Duration and Duration > 0 and Duration <= 1.5) then
GCDBar.StartTime = StartTime
GCDBar.Duration = Duration
self.Bar:Show()
else
self.Bar:Hide()
end
end
function GCDBar:Update()
local Time = (GetTime() - GCDBar.StartTime) / GCDBar.Duration
if (Time > 1) then
self.Bar:Hide()
else
self.Bar:SetMinMaxValues(0, 1)
self.Bar:SetValue(Time)
end
end
function GCDBar:CreateBar()
local Bar = CreateFrame("StatusBar", nil, UIParent)
Bar:Size(372, 4)
Bar:Point("BOTTOM", UIParent, 0, 112)
Bar:SetStatusBarTexture(C.Media.Blank)
Bar:SetStatusBarColor(1, 0.8, 0)
Bar:CreateBackdrop()
Bar:CreateShadow()
Bar:Hide()
Bar.Spark = Bar:CreateTexture(nil, "OVERLAY", nil)
Bar.Spark:Width(Bar:GetHeight())
Bar.Spark:Point("CENTER", Bar:GetStatusBarTexture(), "RIGHT", 0, 0)
Bar.Spark:SetTexture([[Interface\CastingBar\UI-CastingBar-Spark]])
Bar.Spark:SetBlendMode("ADD")
Bar.Spark:SetVertexColor(0.55, 0.55, 0.55, 0.8)
local Animation = A["LibAnimSmooth"]
Animation:AddSmooth(Bar)
self:RegisterEvent("UNIT_SPELLCAST_SENT")
self:RegisterEvent("UNIT_SPELLCAST_START")
self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:SetScript("OnEvent", self.Check)
self:SetScript("OnUpdate", self.Update)
self.Bar = Bar
end
function GCDBar:Enable()
if not (C.DataBars.GCDBar) then
return
end
if not (self.IsCreated) then
self:CreateBar()
self.IsCreated = true
end
end
DataBars.GCDBar = GCDBar