View Single Post
06-08-18, 12:19 PM   #7
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Here's my GCD addon that i've made, hope it can help!


Lua Code:
  1. local A, C, L = select(2, ...):unpack()
  2. local GCDBar = CreateFrame("Frame")
  3. local DataBars = A["DataBars"]
  4. local Panels = A["Panels"]
  5.  
  6. -- Lib Globals
  7. local select = select
  8. local unpack = unpack
  9. local floor = math.floor
  10.  
  11. -- WoW Globals
  12. local GetSpellCooldown = GetSpellCooldown
  13.  
  14. -- Locals
  15. GCDBar.StartTime = 0
  16. GCDBar.Duration = 0
  17.  
  18. function GCDBar:Check(event, unit, spell)
  19.     if not (unit == "player") then
  20.         return
  21.     end
  22.    
  23.     local StartTime, Duration = GetSpellCooldown(spell)
  24.  
  25.     if (Duration and Duration > 0 and Duration <= 1.5) then
  26.         GCDBar.StartTime = StartTime
  27.         GCDBar.Duration = Duration
  28.         self.Bar:Show()
  29.     else
  30.         self.Bar:Hide()
  31.     end
  32. end
  33.  
  34. function GCDBar:Update()
  35.     local Time = (GetTime() - GCDBar.StartTime) / GCDBar.Duration
  36.  
  37.     if (Time > 1) then
  38.         self.Bar:Hide()
  39.     else
  40.         self.Bar:SetMinMaxValues(0, 1)
  41.         self.Bar:SetValue(Time)
  42.     end
  43. end
  44.  
  45. function GCDBar:CreateBar()
  46.     local Bar = CreateFrame("StatusBar", nil, UIParent)
  47.     Bar:Size(372, 4)
  48.     Bar:Point("BOTTOM", UIParent, 0, 112)
  49.     Bar:SetStatusBarTexture(C.Media.Blank)
  50.     Bar:SetStatusBarColor(1, 0.8, 0)
  51.     Bar:CreateBackdrop()
  52.     Bar:CreateShadow()
  53.     Bar:Hide()
  54.    
  55.     Bar.Spark = Bar:CreateTexture(nil, "OVERLAY", nil)
  56.     Bar.Spark:Width(Bar:GetHeight())
  57.     Bar.Spark:Point("CENTER", Bar:GetStatusBarTexture(), "RIGHT", 0, 0)
  58.     Bar.Spark:SetTexture([[Interface\CastingBar\UI-CastingBar-Spark]])
  59.     Bar.Spark:SetBlendMode("ADD")
  60.     Bar.Spark:SetVertexColor(0.55, 0.55, 0.55, 0.8)
  61.    
  62.     local Animation = A["LibAnimSmooth"]
  63.     Animation:AddSmooth(Bar)
  64.  
  65.     self:RegisterEvent("UNIT_SPELLCAST_SENT")
  66.     self:RegisterEvent("UNIT_SPELLCAST_START")
  67.     self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
  68.     self:RegisterEvent("PLAYER_ENTERING_WORLD")
  69.     self:SetScript("OnEvent", self.Check)
  70.     self:SetScript("OnUpdate", self.Update)
  71.    
  72.     self.Bar = Bar
  73. end
  74.  
  75. function GCDBar:Enable()
  76.     if not (C.DataBars.GCDBar) then
  77.         return
  78.     end
  79.  
  80.     if not (self.IsCreated) then
  81.         self:CreateBar()
  82.         self.IsCreated = true
  83.     end
  84. end
  85.  
  86. DataBars.GCDBar = GCDBar
  Reply With Quote