local A, C, L = select(2, ...):unpack()
local RuneBar = CreateFrame("Frame")
local DataBars = A["DataBars"]
local Panels = A["Panels"]
-- Lib Globals
local select = select
local unpack = unpack
-- WoW Globals
local GetRuneCooldown = GetRuneCooldown
local GetTime = GetTime
local UnitClass = UnitClass
local GetSpecialization = GetSpecialization
-- Locals
local Class = select(2, UnitClass("player"))
-- Color Tabels
local Mult = 2.5
local BloodColor = { 1 * Mult, 0, 0 }
local FrostColor = { 0, 0.35 * Mult, 1 * Mult }
local UnholyColor = { 0.25 * Mult, 0.55 * Mult, 0.10 * Mult }
function RuneBar:OnUpdate(Elapsed)
local Duration = self.Duration + Elapsed
self.Duration = Duration
self:SetValue(Duration)
end
function RuneBar:Update()
for i = 1, 6 do
local Start, Duration, RuneIsReady = GetRuneCooldown(i)
if (Start) then
self.RunesBars[i].Duration = GetTime() - Start
self.RunesBars[i]:SetMinMaxValues(0, Duration)
self.RunesBars[i]:SetScript("OnUpdate", self.OnUpdate)
else
self.RunesBars[i]:SetMinMaxValues(0, 1)
self.RunesBars[i]:SetValue(1)
self.RunesBars[i]:SetScript("OnUpdate", nil)
end
end
end
function RuneBar:UpdateSpec()
for i = 1, 6 do
local GetSpecialization = GetSpecialization()
if (GetSpecialization == 1) then
self.RunesBars[i]:SetStatusBarColor(unpack(BloodColor))
elseif (GetSpecialization == 2) then
self.RunesBars[i]:SetStatusBarColor(unpack(FrostColor))
elseif (GetSpecialization == 3) then
self.RunesBars[i]:SetStatusBarColor(unpack(UnholyColor))
end
end
end
function RuneBar:OnEvent(event)
if (event == "RUNE_POWER_UPDATE") then
self:Update()
elseif (event == "PLAYER_ENTERING_WORLD" or event == "PLAYER_SPECIALIZATION_CHANGED" or event == "PLAYER_TALENT_UPDATE") then
self:UpdateSpec()
end
end
function RuneBar:CreateBar()
local Bar = CreateFrame("StatusBar", nil, UIParent)
Bar:Size(220, 12)
Bar:Point("TOP", Panels.ActionBarPanelMiddle, 0, 32)
local RunesBars = {}
for i = 1, 6 do
local Bars = CreateFrame("StatusBar", nil, Bar)
Bars:Size(210/6, 12)
Bars:SetStatusBarTexture(C.Media.Texture)
Bars:CreateBackdrop()
Bars:CreateShadow()
if (i == 1) then
Bars:Point("LEFT", Bar, 2, 0)
else
Bars:Point("LEFT", RunesBars[i-1], "RIGHT", 2, 0)
end
RunesBars[i] = Bars
end
RegisterStateDriver(Bar, "visibility", "[vehicleui][petbattle] hide; show")
self:RegisterEvent("RUNE_POWER_UPDATE")
self:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED")
self:RegisterEvent("PLAYER_TALENT_UPDATE")
self:RegisterEvent("PLAYER_REGEN_ENABLED")
self:RegisterEvent("PLAYER_REGEN_DISABLED")
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:SetScript("OnEvent", self.OnEvent)
self.Bar = Bar
self.RunesBars = RunesBars
end
function RuneBar:Enable()
if not (C.DataBars.RuneBar) or (Class ~= "DEATHKNIGHT") then
return
end
self:CreateBar()
end
DataBars.RuneBar = RuneBar