View Single Post
05-25-13, 11:58 PM   #1
Aerials
A Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 92
The way I address the lack of Burning Embers support in classicons.lua

I doubt this is anything close to perfect, but it works (step 1).
All I did was modify the code of classicons.lua slightly... It's as a separate file / element though, as it didn't seem to work otherwise.

Is there something that I missed in oUF that makes this unnecessary?

embers.lua

Lua Code:
  1. --[[ Element: Embers
  2.  Toggles the visibility of icons depending on the player's class and
  3.  specialization.
  4.  
  5.  Widget
  6.  
  7.  Embers - An array consisting of five UI Textures.
  8.  
  9.  Notes
  10.  Warlock - Embers
  11.  
  12.  Examples
  13.  
  14.    local Embers = {}
  15.    for index = 1, 5 do
  16.       local Icon = self:CreateTexture(nil, 'BACKGROUND')
  17.    
  18.       -- Position and size.
  19.       Icon:SetSize(16, 16)
  20.       Icon:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', index * Icon:GetWidth(), 0)
  21.    
  22.       Embers[index] = Icon
  23.    end
  24.    
  25.    -- Register with oUF
  26.    self.Embers = Embers
  27. ]]
  28.  
  29. local parent, ns = ...
  30. local oUF = ns.oUF
  31.  
  32. local PlayerClass = select(2, UnitClass'player')
  33.  
  34. -- Holds the class specific stuff.
  35. local ClassPowerType, ClassPowerTypes
  36. local ClassPowerEnable, ClassPowerDisable
  37. local RequireSpec, RequireSpell
  38.  
  39. local UpdateTexture = function(element)
  40.     local red, green, blue, desaturated
  41.     if(PlayerClass == 'WARLOCK') then
  42.         red, green, blue = 1, .49, .05
  43.         desaturated = false
  44.     end
  45.  
  46.     for i=1, 5 do
  47.         if(element[i].SetDesaturated) then
  48.             element[i]:SetDesaturated(desaturated)
  49.         end
  50.  
  51.         element[i]:SetVertexColor(red, green, blue)
  52.     end
  53. end
  54.  
  55. local ToggleVehicle = function(self, state)
  56.     local element = self.Embers
  57.     for i=1, 5 do
  58.         element[i]:Hide()
  59.     end
  60.  
  61.     (element.UpdateTexture or UpdateTexture) (element)
  62.  
  63.     if(state) then
  64.         ClassPowerDisable(self)
  65.     else
  66.         ClassPowerEnable(self)
  67.     end
  68. end
  69.  
  70. local Update = function(self, event, unit, powerType)
  71.     local element = self.Embers
  72.     local hasVehicle = UnitHasVehicleUI('player')
  73.     if(element.__inVehicle ~= hasVehicle) then
  74.         element.__inVehicle = hasVehicle
  75.         ToggleVehicle(self, hasVehicle)
  76.  
  77.         -- Continue the update if we left a vehicle.
  78.         if(hasVehicle) then return end
  79.     end
  80.  
  81.     if((unit and unit ~= 'player') or (powerType and not ClassPowerTypes[powerType])) then
  82.         return
  83.     end
  84.  
  85.     if(element.PreUpdate) then
  86.         element:PreUpdate()
  87.     end
  88.  
  89.     local cur = UnitPower('player', ClassPowerType)
  90.     local max = UnitPowerMax('player', ClassPowerType)
  91.  
  92.     for i=1, max do
  93.         if(i <= cur) then
  94.             element[i]:Show()
  95.         else
  96.             element[i]:Hide()
  97.         end
  98.     end
  99.  
  100.     local oldMax = element.__max
  101.     if(max ~= element.__max) then
  102.         if(max < element.__max) then
  103.             for i=max + 1, element.__max do
  104.                 element[i]:Hide()
  105.             end
  106.         end
  107.  
  108.         element.__max = max
  109.     end
  110.  
  111.     if(element.PostUpdate) then
  112.         return element:PostUpdate(cur, max, oldMax ~= max)
  113.     end
  114. end
  115.  
  116. local Path = function(self, ...)
  117.     return (self.Embers.Override or Update) (self, ...)
  118. end
  119.  
  120. local Visibility = function(self, event, unit)
  121.     local element = self.Embers
  122.     if((RequireSpell and not IsPlayerSpell(RequireSpell))) then
  123.         for i=1, 5 do
  124.             element[i]:Hide()
  125.         end
  126.         ClassPowerDisable(self)
  127.     else
  128.         ClassPowerEnable(self)
  129.         return Path(self, 'UpdateVisibility')
  130.     end
  131. end
  132.  
  133. local ForceUpdate = function(element)
  134.     return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
  135. end
  136.  
  137. do
  138.     if(PlayerClass == 'WARLOCK') then
  139.         ClassPowerType = SPELL_POWER_BURNING_EMBERS
  140.         ClassPowerTypes = {
  141.             BURNING_EMBERS = true,
  142.         }
  143.         RequireSpell = WARLOCK_BURNING_EMBERS
  144.         ClassPowerEnable = function(self)
  145.             local element = self.Embers
  146.  
  147.             self:RegisterEvent('UNIT_DISPLAYPOWER', Update)
  148.             self:RegisterEvent('UNIT_POWER_FREQUENT', Update)
  149.         end
  150.  
  151.         ClassPowerDisable = function(self)
  152.             self:UnregisterEvent('UNIT_DISPLAYPOWER', Update)
  153.             self:UnregisterEvent('UNIT_POWER_FREQUENT', Update)
  154.         end
  155.     end
  156. end
  157.  
  158. local Enable = function(self, unit)
  159.     local element = self.Embers
  160.     if(not element) then return end
  161.  
  162.     element.__owner = self
  163.     element.__max = 0
  164.     element.ForceUpdate = ForceUpdate
  165.  
  166.     if(ClassPowerEnable) then
  167.         if(PlayerClass == 'WARLOCK') then
  168.             self:RegisterEvent('SPELLS_CHANGED', Visibility, true)
  169.         end
  170.         ClassPowerEnable(self)
  171.  
  172.         for i=1, 5 do
  173.             local icon = element[i]
  174.             if(icon:IsObjectType'Texture' and not icon:GetTexture()) then
  175.                 icon:SetTexCoord(0.45703125, 0.60546875, 0.44531250, 0.73437500)
  176.                 icon:SetTexture([[Interface\PlayerFrame\Priest-ShadowUI]])
  177.             end
  178.         end
  179.  
  180.         (element.UpdateTexture or UpdateTexture) (element)
  181.  
  182.         return true
  183.     end
  184. end
  185.  
  186. local Disable = function(self)
  187.     local element = self.Embers
  188.     if(not element) then return end
  189.  
  190.     self:UnregisterEvent('SPELLS_CHANGED', Visibility)
  191.     self:UnregisterEvent('PLAYER_TALENT_UPDATE', Visibility)
  192.     ClassPowerDisable(self)
  193. end
  194.  
  195. oUF:AddElement('Embers', Update, Enable, Disable)

then in oUF.xml, add:
Code:
<Script file='elements\embers.lua' />
  Reply With Quote