--[[ Element: Embers
Toggles the visibility of icons depending on the player's class and
specialization.
Widget
Embers - An array consisting of five UI Textures.
Notes
Warlock - Embers
Examples
local Embers = {}
for index = 1, 5 do
local Icon = self:CreateTexture(nil, 'BACKGROUND')
-- Position and size.
Icon:SetSize(16, 16)
Icon:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', index * Icon:GetWidth(), 0)
Embers[index] = Icon
end
-- Register with oUF
self.Embers = Embers
]]
local parent, ns = ...
local oUF = ns.oUF
local PlayerClass = select(2, UnitClass'player')
-- Holds the class specific stuff.
local ClassPowerType, ClassPowerTypes
local ClassPowerEnable, ClassPowerDisable
local RequireSpec, RequireSpell
local UpdateTexture = function(element)
local red, green, blue, desaturated
if(PlayerClass == 'WARLOCK') then
red, green, blue = 1, .49, .05
desaturated = false
end
for i=1, 5 do
if(element[i].SetDesaturated) then
element[i]:SetDesaturated(desaturated)
end
element[i]:SetVertexColor(red, green, blue)
end
end
local ToggleVehicle = function(self, state)
local element = self.Embers
for i=1, 5 do
element[i]:Hide()
end
(element.UpdateTexture or UpdateTexture) (element)
if(state) then
ClassPowerDisable(self)
else
ClassPowerEnable(self)
end
end
local Update = function(self, event, unit, powerType)
local element = self.Embers
local hasVehicle = UnitHasVehicleUI('player')
if(element.__inVehicle ~= hasVehicle) then
element.__inVehicle = hasVehicle
ToggleVehicle(self, hasVehicle)
-- Continue the update if we left a vehicle.
if(hasVehicle) then return end
end
if((unit and unit ~= 'player') or (powerType and not ClassPowerTypes[powerType])) then
return
end
if(element.PreUpdate) then
element:PreUpdate()
end
local cur = UnitPower('player', ClassPowerType)
local max = UnitPowerMax('player', ClassPowerType)
for i=1, max do
if(i <= cur) then
element[i]:Show()
else
element[i]:Hide()
end
end
local oldMax = element.__max
if(max ~= element.__max) then
if(max < element.__max) then
for i=max + 1, element.__max do
element[i]:Hide()
end
end
element.__max = max
end
if(element.PostUpdate) then
return element:PostUpdate(cur, max, oldMax ~= max)
end
end
local Path = function(self, ...)
return (self.Embers.Override or Update) (self, ...)
end
local Visibility = function(self, event, unit)
local element = self.Embers
if((RequireSpell and not IsPlayerSpell(RequireSpell))) then
for i=1, 5 do
element[i]:Hide()
end
ClassPowerDisable(self)
else
ClassPowerEnable(self)
return Path(self, 'UpdateVisibility')
end
end
local ForceUpdate = function(element)
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
end
do
if(PlayerClass == 'WARLOCK') then
ClassPowerType = SPELL_POWER_BURNING_EMBERS
ClassPowerTypes = {
BURNING_EMBERS = true,
}
RequireSpell = WARLOCK_BURNING_EMBERS
ClassPowerEnable = function(self)
local element = self.Embers
self:RegisterEvent('UNIT_DISPLAYPOWER', Update)
self:RegisterEvent('UNIT_POWER_FREQUENT', Update)
end
ClassPowerDisable = function(self)
self:UnregisterEvent('UNIT_DISPLAYPOWER', Update)
self:UnregisterEvent('UNIT_POWER_FREQUENT', Update)
end
end
end
local Enable = function(self, unit)
local element = self.Embers
if(not element) then return end
element.__owner = self
element.__max = 0
element.ForceUpdate = ForceUpdate
if(ClassPowerEnable) then
if(PlayerClass == 'WARLOCK') then
self:RegisterEvent('SPELLS_CHANGED', Visibility, true)
end
ClassPowerEnable(self)
for i=1, 5 do
local icon = element[i]
if(icon:IsObjectType'Texture' and not icon:GetTexture()) then
icon:SetTexCoord(0.45703125, 0.60546875, 0.44531250, 0.73437500)
icon:SetTexture([[Interface\PlayerFrame\Priest-ShadowUI]])
end
end
(element.UpdateTexture or UpdateTexture) (element)
return true
end
end
local Disable = function(self)
local element = self.Embers
if(not element) then return end
self:UnregisterEvent('SPELLS_CHANGED', Visibility)
self:UnregisterEvent('PLAYER_TALENT_UPDATE', Visibility)
ClassPowerDisable(self)
end
oUF:AddElement('Embers', Update, Enable, Disable)