Skip to content

Commit

Permalink
live toggle for GCD ticker
Browse files Browse the repository at this point in the history
  • Loading branch information
ffainy committed Apr 6, 2022
1 parent eec05c1 commit 9c6c48a
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 28 deletions.
46 changes: 18 additions & 28 deletions modules/unitframe/gcd.lua
Original file line number Diff line number Diff line change
@@ -1,44 +1,34 @@
local F, C = unpack(select(2, ...))
local UNITFRAME = F:GetModule('UnitFrame')

local function OnUpdate(self)
local start, duration = GetSpellCooldown(61304)
if start > 0 and duration > 0 then
if self.duration ~= duration then
self:SetMinMaxValues(0, duration)
self.duration = duration
end
self:SetValue(GetTime() - start)
self.spark:Show()
else
self.spark:Hide()
end
end

function UNITFRAME:CreateGCDTicker(self)
local bar = CreateFrame('StatusBar', nil, self)
bar:SetFrameLevel(self.Health:GetFrameLevel() + 1)
bar:SetStatusBarTexture(C.Assets.Texture.Backdrop)
bar:GetStatusBarTexture():SetAlpha(0)
bar:SetAllPoints()

local spark = bar:CreateTexture(nil, 'OVERLAY')
spark:SetTexture(C.Assets.Texture.Spark)
spark:SetBlendMode('ADD')
spark:SetPoint('TOPLEFT', bar:GetStatusBarTexture(), 'TOPRIGHT', -10, 10)
spark:SetPoint('BOTTOMRIGHT', bar:GetStatusBarTexture(), 'BOTTOMRIGHT', 10, -10)
bar.spark = spark
bar.spark = bar:CreateTexture(nil, 'OVERLAY')
bar.spark:SetTexture(C.Assets.Texture.Spark)
bar.spark:SetBlendMode('ADD')
bar.spark:SetPoint('TOPLEFT', bar:GetStatusBarTexture(), 'TOPRIGHT', -10, 10)
bar.spark:SetPoint('BOTTOMRIGHT', bar:GetStatusBarTexture(), 'BOTTOMRIGHT', 10, -10)

bar:SetScript('OnUpdate', OnUpdate)
self.GCDTicker = bar
self.GCD = bar
end

function UNITFRAME:UpdateGCDTicker()
local player = _G.oUF_Player
local bar = player and player.GCDTicker
if not bar then
return
local frame = _G.oUF_Player
if C.DB.Unitframe.GCDIndicator then
if not frame:IsElementEnabled('GCD') then
frame:EnableElement('GCD')
if frame.GCD then
frame.GCD:ForceUpdate()
end
end
else
if frame:IsElementEnabled('GCD') then
frame:DisableElement('GCD')
end
end

bar:SetShown(C.DB.Unitframe.GCDIndicator)
end
62 changes: 62 additions & 0 deletions modules/unitframe/plugins/gcd.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
local F = unpack(select(2, ...))
local oUF = F.Libs.oUF

local function Update(self, event, unit)
local spark = self.spark
local start, duration = GetSpellCooldown(61304)
if start > 0 and duration > 0 then
if self.duration ~= duration then
self:SetMinMaxValues(0, duration)
self.duration = duration
end
self:SetValue(GetTime() - start)

if spark then
self.spark:Show()
end
else
if spark then
self.spark:Hide()
end
end
end

local function Path(self, ...)
return (self.GCD.Override or Update)(self, ...)
end

local function ForceUpdate(element)
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
end

local function Enable(self, unit)
local element = self.GCD
if (element and UnitIsUnit(unit, 'player')) then
element.__owner = self
element.ForceUpdate = ForceUpdate

element:SetScript('OnUpdate', Update)

if (element:IsObjectType('StatusBar') and not element:GetStatusBarTexture()) then
element:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
end

local spark = element.spark
if (spark and spark:IsObjectType('Texture') and not spark:GetTexture()) then
spark:SetTexture([[Interface\CastingBar\UI-CastingBar-Spark]])
end

element:Show()

return true
end
end

local function Disable(self)
local element = self.GCD
if (element) then
element:Hide()
end
end

oUF:AddElement('GCD', Path, Enable, Disable)
1 change: 1 addition & 0 deletions modules/unitframe/plugins/plugins.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<Ui xmlns='http://www.blizzard.com/wow/ui/'>
<Script file='fader.lua'/>
<Script file='gcd.lua'/>
<Script file='partywatcher.lua'/>
<Script file='debuffwatcher.lua'/>
<Script file='rangecheck.lua'/>
Expand Down

0 comments on commit 9c6c48a

Please sign in to comment.