/Tukui/modules/blizzard/mirror.lua

http://github.com/Asphyxia/Tukui · Lua · 161 lines · 121 code · 37 blank · 3 comment · 16 complexity · e3ac9ec888e7e0a27635d26ef8d7809a MD5 · raw file

  1. local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2. ---------------------------------------------------------------------
  3. -- original by haste, edited for tukui :)
  4. ---------------------------------------------------------------------
  5. local _, settings = ...
  6. local _DEFAULTS = {
  7. width = T.Scale(220),
  8. height = T.Scale(18),
  9. texture = C["media"].normTex,
  10. position = {
  11. ["BREATH"] = 'TOP#UIParent#TOP#0#-96';
  12. ["EXHAUSTION"] = 'TOP#UIParent#TOP#0#-119';
  13. ["FEIGNDEATH"] = 'TOP#UIParent#TOP#0#-142';
  14. };
  15. colors = {
  16. EXHAUSTION = {1, .9, 0};
  17. BREATH = {0.31, 0.45, 0.63};
  18. DEATH = {1, .7, 0};
  19. FEIGNDEATH = {1, .7, 0};
  20. };
  21. }
  22. do
  23. settings = setmetatable(settings, {__index = _DEFAULTS})
  24. for k,v in next, settings do
  25. if(type(v) == 'table') then
  26. settings[k] = setmetatable(settings[k], {__index = _DEFAULTS[k]})
  27. end
  28. end
  29. end
  30. local Spawn, PauseAll
  31. do
  32. local barPool = {}
  33. local loadPosition = function(self)
  34. local pos = settings.position[self.type]
  35. local p1, frame, p2, x, y = strsplit("#", pos)
  36. return self:Point(p1, frame, p2, x, y)
  37. end
  38. local OnUpdate = function(self, elapsed)
  39. if(self.paused) then return end
  40. self:SetValue(GetMirrorTimerProgress(self.type) / 1e3)
  41. end
  42. local Start = function(self, value, maxvalue, scale, paused, text)
  43. if(paused > 0) then
  44. self.paused = 1
  45. elseif(self.paused) then
  46. self.paused = nil
  47. end
  48. self.text:SetText(text)
  49. self:SetMinMaxValues(0, maxvalue / 1e3)
  50. self:SetValue(value / 1e3)
  51. if(not self:IsShown()) then self:Show() end
  52. end
  53. function Spawn(type)
  54. if(barPool[type]) then return barPool[type] end
  55. local frame = CreateFrame('StatusBar', nil, UIParent)
  56. frame:SetScript("OnUpdate", OnUpdate)
  57. local r, g, b = unpack(settings.colors[type])
  58. local bg = frame:CreateTexture(nil, 'BACKGROUND')
  59. bg:SetAllPoints(frame)
  60. bg:SetTexture(settings.texture)
  61. bg:SetVertexColor(r * .5, g * .5, b * .5)
  62. local border = CreateFrame("Frame", nil, frame)
  63. border:Point("TOPLEFT", frame, -2, 2)
  64. border:Point("BOTTOMRIGHT", frame, 2, -2)
  65. border:SetTemplate("Default")
  66. border:SetFrameLevel(0)
  67. local text = frame:CreateFontString(nil, 'OVERLAY')
  68. text:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
  69. text:SetJustifyH'CENTER'
  70. text:SetTextColor(1, 1, 1)
  71. text:SetPoint('LEFT', frame)
  72. text:SetPoint('RIGHT', frame)
  73. text:SetPoint('TOP', frame)
  74. text:SetPoint('BOTTOM', frame)
  75. frame:SetSize(settings.width, settings.height)
  76. frame:SetStatusBarTexture(settings.texture)
  77. frame:SetStatusBarColor(r, g, b)
  78. frame.type = type
  79. frame.text = text
  80. frame.Start = Start
  81. frame.Stop = Stop
  82. loadPosition(frame)
  83. barPool[type] = frame
  84. return frame
  85. end
  86. function PauseAll(val)
  87. for _, bar in next, barPool do
  88. bar.paused = val
  89. end
  90. end
  91. end
  92. local frame = CreateFrame'Frame'
  93. frame:SetScript('OnEvent', function(self, event, ...)
  94. return self[event](self, ...)
  95. end)
  96. function frame:ADDON_LOADED(addon)
  97. if(addon == 'Tukui') then
  98. UIParent:UnregisterEvent'MIRROR_TIMER_START'
  99. self:UnregisterEvent'ADDON_LOADED'
  100. self.ADDON_LOADED = nil
  101. end
  102. end
  103. frame:RegisterEvent'ADDON_LOADED'
  104. function frame:PLAYER_ENTERING_WORLD()
  105. for i=1, MIRRORTIMER_NUMTIMERS do
  106. local type, value, maxvalue, scale, paused, text = GetMirrorTimerInfo(i)
  107. if(type ~= 'UNKNOWN') then
  108. Spawn(type):Start(value, maxvalue, scale, paused, text)
  109. end
  110. end
  111. end
  112. frame:RegisterEvent'PLAYER_ENTERING_WORLD'
  113. function frame:MIRROR_TIMER_START(type, value, maxvalue, scale, paused, text)
  114. return Spawn(type):Start(value, maxvalue, scale, paused, text)
  115. end
  116. frame:RegisterEvent'MIRROR_TIMER_START'
  117. function frame:MIRROR_TIMER_STOP(type)
  118. return Spawn(type):Hide()
  119. end
  120. frame:RegisterEvent'MIRROR_TIMER_STOP'
  121. function frame:MIRROR_TIMER_PAUSE(duration)
  122. return PauseAll((duration > 0 and duration) or nil)
  123. end
  124. frame:RegisterEvent'MIRROR_TIMER_PAUSE'