local name = ... local rebirth = 20484 local f = CreateFrame("Button", name.."Button", UIParent, BackdropTemplateMixin and "ActionButtonTemplate BackdropTemplate" or "ActionButtonTemplate") f:RegisterEvent("ADDON_LOADED") f:SetMovable(true) f:SetScript("OnMouseDown", function(self) self:StartMoving() end) f:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing() end) f:SetScript("OnLeave", function() GameTooltip:Hide() end) f:SetScript("OnEnter", function(self) GameTooltip:SetOwner(self,"ANCHOR_CURSOR") GameTooltip:ClearLines() GameTooltip:SetSpellByID(rebirth) GameTooltip:Show() end) local nm = f:GetName() local ct = _G[format("%sCount",nm)] local cd = _G[format("%sCooldown",nm)] cd:SetReverse(true) function f:Reset() self:SetSize(36,36) self:ClearAllPoints() self:SetPoint("CENTER",UIParent,"CENTER") self:SetAttribute("type","spell") self:SetAttribute("spell",rebirth) local spellInfo = {GetSpellInfo(rebirth)} _G[format("%sIcon",self:GetName())]:SetTexture(spellInfo[3]) spellInfo = nil self:Show() end function f:Update() local currentCharges, maxCharges, cooldownStart, cooldownDuration = GetSpellCharges(rebirth) self:Hide() if(currentCharges) then if(cooldownStart) then CooldownFrame_Set(cd, cooldownStart, cooldownDuration,1) else CooldownFrame_Set(cd,0,0,0) end ct:SetText(currentCharges and currentCharges or 0) self:Show() end end f:SetScript("OnEvent", function(self,event,arg1,...) if(event=="ADDON_LOADED" and name==arg1) then self:UnregisterEvent(event) self:RegisterEvent("PLAYER_REGEN_ENABLED") self:RegisterEvent("PLAYER_REGEN_DISABLED") self:Reset() elseif(event=="PLAYER_REGEN_ENABLED") then self:UnregisterEvent("SPELL_UPDATE_CHARGES") elseif(event=="PLAYER_REGEN_DISABLED") then self:RegisterEvent("SPELL_UPDATE_CHARGES") end self:Update() end)