Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.38 KB | None | 0 0
  1. local _, ns = ...
  2. local oUF = ns.oUF
  3.  
  4. local UnitPower = UnitPower
  5. local UnitPowerMax = UnitPowerMax
  6. local UnitPowerType = UnitPowerType
  7.  
  8. local OnUpdate = function(self, elapsed)
  9.     self.elapsed = self.elapsed + elapsed
  10.    
  11.     self:SetValue(self.elapsed)
  12.    
  13.     if (self.elapsed >= 5) then
  14.         self:Hide()
  15.     end
  16. end
  17.  
  18. local Update = function(self, event, unit)
  19.     if (unit ~= self.unit) then
  20.         return
  21.     end
  22.    
  23.     local element = self.ManaTimer
  24.    
  25.     if element then
  26.         local Type = UnitPowerType(self.unit)
  27.        
  28.         if (Type ~= 0) or (UnitPower(unit) == UnitPowerMax(unit)) then
  29.             return
  30.         end
  31.        
  32.         element.elapsed = 0
  33.        
  34.         element:Show()
  35.         element:SetScript("OnUpdate", OnUpdate)
  36.     end
  37. end
  38.  
  39. local Path = function(self, ...)
  40.     return (self.ManaTimer.Override or Update)(self, ...)
  41. end
  42.  
  43. local ForceUpdate = function(element)
  44.     return Path(element.__owner, "ForceUpdate", element.__owner.unit)
  45. end
  46.  
  47. local Enable = function(self)
  48.     local element = self.ManaTimer
  49.    
  50.     if element then
  51.         element.__owner = self
  52.         element.ForceUpdate = ForceUpdate
  53.        
  54.         element:Hide()
  55.         element:SetMinMaxValues(0, 5)
  56.         self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED", Update)
  57.     end
  58. end
  59.  
  60. local Disable = function(self)
  61.     local element = self.ManaTimer
  62.    
  63.     if element then
  64.         element:Hide()
  65.         element:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED", Update)
  66.     end
  67. end
  68.  
  69. oUF:AddElement("ManaRegen", Path, Enable, Disable)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement