118 lines
3.0 KiB
Lua
118 lines
3.0 KiB
Lua
local name, addon = ...
|
|
|
|
local buttons = {}
|
|
local btnfuncs = {}
|
|
|
|
function btnfuncs:Show()
|
|
|
|
end
|
|
function btnfuncs:Hide()
|
|
|
|
end
|
|
function btnfuncs:OnEnter()
|
|
GameTooltip:SetOwner(self,"ANCHOR_CURSOR")
|
|
GameTooltip:ClearLines()
|
|
GameTooltip:SetSpellByID(self.spellID)
|
|
GameTooltip:Show()
|
|
end
|
|
function btnfuncs:OnLeave()
|
|
GameTooltip:Hide()
|
|
end
|
|
local last
|
|
local function update()
|
|
local vis = 1
|
|
for num, btn in pairs(buttons) do
|
|
-- print(num, btn:GetName())
|
|
btn:ClearAllPoints()
|
|
if(btn:IsVisible()) then
|
|
if(vis == 1) then
|
|
vis = 2
|
|
if(addon.scrollframe:IsVisible()) then
|
|
btn:SetPoint("TOPLEFT", addon.scrollframe, "BOTTOMLEFT",10,0)
|
|
else
|
|
btn:SetPoint("TOPLEFT", addon.scrollframe, "TOPLEFT",10,-4)
|
|
end
|
|
else
|
|
btn:SetPoint("LEFT", last, "RIGHT",10,0)
|
|
end
|
|
last = btn
|
|
end
|
|
end
|
|
end
|
|
addon.UpdateInfoButtons = update
|
|
local function NewInfoButton(spellID)
|
|
buttons[#buttons + 1] = CreateFrame("Button", name.."Button"..(#buttons + 1), UIParent, "ActionButtonTemplate")
|
|
return buttons[#buttons]
|
|
end
|
|
function addon:AddInfoButton(spellID, ttshow, tthide)
|
|
if(spellID) then
|
|
local f = NewInfoButton(spellID)
|
|
f:SetSize(36,36)
|
|
f:SetScale(0.75)
|
|
f.spellID = spellID
|
|
f:SetFrameStrata("LOW")
|
|
f:SetScript("OnHide", update)
|
|
f:SetScript("OnShow", update)
|
|
f:SetScript("OnEnter", type(ttshow)=='function' and ttshow or btnfuncs.OnEnter)
|
|
f:SetScript("OnLeave", type(tthide)=='function' and tthide or btnfuncs.OnLeave)
|
|
-- f:SetAttribute("type","spell")
|
|
-- f:SetAttribute("spell",f.spellID)
|
|
local spellInfo = {GetSpellInfo(f.spellID)}
|
|
_G[format("%sIcon",f:GetName())]:SetTexture(spellInfo[3])
|
|
spellInfo = nil
|
|
f.Update = update
|
|
f:Show()
|
|
update()
|
|
return f
|
|
end
|
|
end
|
|
local rebirth = {}
|
|
function rebirth:Update()
|
|
local nm = self:GetName()
|
|
local ct = _G[format("%sCount",nm)]
|
|
local cd = _G[format("%sCooldown",nm)]
|
|
if(not cd or not ct) then return end
|
|
cd:SetReverse(true)
|
|
local currentCharges, maxCharges, cooldownStart, cooldownDuration = GetSpellCharges(self.spellID)
|
|
if(currentCharges) then
|
|
if(cooldownStart) then
|
|
CooldownFrame_Set(cd, cooldownStart, cooldownDuration,1)
|
|
else
|
|
CooldownFrame_Set(cd,0,0,0)
|
|
end
|
|
end
|
|
ct:SetText(currentCharges and currentCharges or 0)
|
|
end
|
|
addon.inits[#addon.inits + 1] = function()
|
|
local rb = addon:AddInfoButton(20484)
|
|
rb.Update = rebirth.Update
|
|
rb:RegisterEvent("PLAYER_REGEN_ENABLED")
|
|
rb:RegisterEvent("PLAYER_REGEN_DISABLED")
|
|
rb:RegisterEvent("PLAYER_DEAD")
|
|
rb:RegisterEvent("GROUP_ROSTER_UPDATE")
|
|
rb:HookScript("OnEvent", function(self, event, ...)
|
|
if(event=="PLAYER_REGEN_ENABLED") then
|
|
self:UnregisterEvent("SPELL_UPDATE_CHARGES")
|
|
elseif(event=="GROUP_ROSTER_UPDATE") then
|
|
if(IsInGroup()) then
|
|
self:Show()
|
|
else
|
|
self:Hide()
|
|
end
|
|
elseif(event=="PLAYER_DEAD") then
|
|
if(not self:IsEventRegistered("SPELL_UPDATE_CHARGES")) then
|
|
self:RegisterEvent("SPELL_UPDATE_CHARGES")
|
|
end
|
|
elseif(event=="PLAYER_REGEN_DISABLED") then
|
|
self:RegisterEvent("SPELL_UPDATE_CHARGES")
|
|
end
|
|
self:Update()
|
|
end)
|
|
if(IsInGroup()) then
|
|
rb:Show()
|
|
else
|
|
rb:Hide()
|
|
end
|
|
update()
|
|
end
|