PageRenderTime 35ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/Tukui/modules/unitframes/core/oUF/elements/druidmana.lua

http://github.com/Asphyxia/Tukui
Lua | 114 lines | 87 code | 22 blank | 5 comment | 17 complexity | 49d7c9f9a47cc39fce90820c0d2a8f43 MD5 | raw file
  1. -- Druid Mana Bar for Cat and Bear forms
  2. -- Authors: Califpornia aka Ennie // some code taken from oUF`s EclipseBar element
  3. if(select(2, UnitClass('player')) ~= 'DRUID') then return end
  4. local _, ns = ...
  5. local oUF = ns.oUF
  6. local function Update(self, event, unit, powertype)
  7. --only the player frame will have this unit enabled
  8. --i mainly place this check for UNIT_DISPLAYPOWER and entering a vehicle
  9. if(unit ~= 'player' or (powertype and powertype ~= 'MANA')) then return end
  10. local druidmana = self.DruidMana
  11. if(druidmana.PreUpdate) then druidmana:PreUpdate(unit) end
  12. --check form
  13. if(UnitPowerType('player') == SPELL_POWER_MANA) then
  14. return druidmana:Hide()
  15. else
  16. druidmana:Show()
  17. end
  18. local min, max = UnitPower('player', SPELL_POWER_MANA), UnitPowerMax('player', SPELL_POWER_MANA)
  19. druidmana:SetMinMaxValues(0, max)
  20. druidmana:SetValue(min)
  21. local r, g, b, t
  22. if(druidmana.colorClass) then
  23. t = self.colors.class['DRUID']
  24. elseif(druidmana.colorSmooth) then
  25. r, g, b = self.ColorGradient(min / max, unpack(druidmana.smoothGradient or self.colors.smooth))
  26. elseif(druidmana.colorPower) then
  27. t = self.colors.power['MANA']
  28. end
  29. if(t) then
  30. r, g, b = t[1], t[2], t[3]
  31. end
  32. if(b) then
  33. druidmana:SetStatusBarColor(r, g, b)
  34. local bg = druidmana.bg
  35. if(bg) then
  36. local mu = bg.multiplier or 1
  37. bg:SetVertexColor(r * mu, g * mu, b * mu)
  38. end
  39. end
  40. if(druidmana.PostUpdate) then
  41. return druidmana:PostUpdate(unit, min, max)
  42. end
  43. end
  44. local function Path(self, ...)
  45. return (self.DruidMana.Override or Update) (self, ...)
  46. end
  47. local function ForceUpdate(element)
  48. return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
  49. end
  50. local OnDruidManaUpdate
  51. do
  52. local UnitPower = UnitPower
  53. OnDruidManaUpdate = function(self)
  54. local unit = self.__owner.unit
  55. local mana = UnitPower(unit, SPELL_POWER_MANA)
  56. if(mana ~= self.min) then
  57. self.min = mana
  58. return Path(self.__owner, 'OnDruidManaUpdate', unit)
  59. end
  60. end
  61. end
  62. local Enable = function(self, unit)
  63. local druidmana = self.DruidMana
  64. if(druidmana and unit == 'player') then
  65. druidmana.__owner = self
  66. druidmana.ForceUpdate = ForceUpdate
  67. if(druidmana.frequentUpdates) then
  68. druidmana:SetScript('OnUpdate', OnDruidManaUpdate)
  69. else
  70. self:RegisterEvent('UNIT_POWER', Path)
  71. end
  72. self:RegisterEvent('UNIT_DISPLAYPOWER', Path)
  73. self:RegisterEvent('UNIT_MAXPOWER', Path)
  74. if(not druidmana:GetStatusBarTexture()) then
  75. druidmana:SetStatusBarTexture[[Interface\TargetingFrame\UI-StatusBar]]
  76. end
  77. return true
  78. end
  79. end
  80. local Disable = function(self)
  81. local druidmana = self.DruidMana
  82. if(druidmana) then
  83. if(druidmana:GetScript'OnUpdate') then
  84. druidmana:SetScript("OnUpdate", nil)
  85. else
  86. self:UnregisterEvent('UNIT_POWER', Path)
  87. end
  88. self:UnregisterEvent('UNIT_DISPLAYPOWER', Path)
  89. self:UnregisterEvent('UNIT_MAXPOWER', Path)
  90. end
  91. end
  92. oUF:AddElement('DruidMana', Path, Enable, Disable)