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

http://github.com/Asphyxia/Tukui · Lua · 110 lines · 92 code · 13 blank · 5 comment · 14 complexity · 2bc84fead28bd24df91f41dbf54de8f4 MD5 · raw file

  1. --[[ Runebar:
  2. Authors: Zariel, Haste
  3. ]]
  4. if select(2, UnitClass("player")) ~= "DEATHKNIGHT" then return end
  5. local parent, ns = ...
  6. local oUF = ns.oUF
  7. oUF.colors.runes = {
  8. {1, 0, 0};
  9. {0, .5, 0};
  10. {0, 1, 1};
  11. {.9, .1, 1};
  12. }
  13. local OnUpdate = function(self, elapsed)
  14. local duration = self.duration + elapsed
  15. if(duration >= self.max) then
  16. return self:SetScript("OnUpdate", nil)
  17. else
  18. self.duration = duration
  19. return self:SetValue(duration)
  20. end
  21. end
  22. local UpdateType = function(self, event, rune, alt)
  23. local colors = self.colors.runes[GetRuneType(rune) or alt]
  24. local rune = self.Runes[rune]
  25. local r, g, b = colors[1], colors[2], colors[3]
  26. rune:SetStatusBarColor(r, g, b)
  27. if(rune.bg) then
  28. local mu = rune.bg.multiplier or 1
  29. rune.bg:SetVertexColor(r * mu, g * mu, b * mu)
  30. end
  31. end
  32. local UpdateRune = function(self, event, rid)
  33. local rune = self.Runes[rid]
  34. if(rune) then
  35. local start, duration, runeReady = GetRuneCooldown(rune:GetID())
  36. if(runeReady) then
  37. rune:SetMinMaxValues(0, 1)
  38. rune:SetValue(1)
  39. rune:SetScript("OnUpdate", nil)
  40. else
  41. rune.duration = GetTime() - start
  42. rune.max = duration
  43. rune:SetMinMaxValues(1, duration)
  44. rune:SetScript("OnUpdate", OnUpdate)
  45. end
  46. end
  47. end
  48. local Update = function(self, event)
  49. for i=1, 6 do
  50. UpdateRune(self, event, i)
  51. end
  52. end
  53. local ForceUpdate = function(element)
  54. return Update(element.__owner, 'ForceUpdate')
  55. end
  56. local Enable = function(self, unit)
  57. local runes = self.Runes
  58. if(runes and unit == 'player') then
  59. runes.__owner = self
  60. runes.ForceUpdate = ForceUpdate
  61. for i=1, 6 do
  62. local rune = runes[i]
  63. rune:SetID(i)
  64. -- From my minor testing this is a okey solution. A full login always remove
  65. -- the death runes, or at least the clients knowledge about them.
  66. UpdateType(self, nil, i, math.floor((i+1)/2))
  67. if(not rune:GetStatusBarTexture()) then
  68. rune:SetStatusBarTexture[[Interface\TargetingFrame\UI-StatusBar]]
  69. end
  70. end
  71. self:RegisterEvent("RUNE_POWER_UPDATE", UpdateRune)
  72. self:RegisterEvent("RUNE_TYPE_UPDATE", UpdateType)
  73. runes:Show()
  74. -- oUF leaves the vehicle events registered on the player frame, so
  75. -- buffs and such are correctly updated when entering/exiting vehicles.
  76. --
  77. -- This however makes the code also show/hide the RuneFrame.
  78. RuneFrame.Show = RuneFrame.Hide
  79. RuneFrame:Hide()
  80. return true
  81. end
  82. end
  83. local Disable = function(self)
  84. self.Runes:Hide()
  85. RuneFrame.Show = nil
  86. RuneFrame:Show()
  87. self:UnregisterEvent("RUNE_POWER_UPDATE", UpdateRune)
  88. self:UnregisterEvent("RUNE_TYPE_UPDATE", UpdateType)
  89. end
  90. oUF:AddElement("Runes", Update, Enable, Disable)