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

http://github.com/Asphyxia/Tukui · Lua · 125 lines · 104 code · 21 blank · 0 comment · 29 complexity · a19f705acbb288aba82a8d4e41e55dda MD5 · raw file

  1. local parent, ns = ...
  2. local oUF = ns.oUF
  3. local _TIMERS = {}
  4. local ReadyCheckFrame
  5. local removeEntry = function(icon)
  6. _TIMERS[icon] = nil
  7. if(not next(_TIMERS)) then
  8. return ReadyCheckFrame:Hide()
  9. end
  10. end
  11. local Start = function(self)
  12. removeEntry(self)
  13. self:SetTexture(READY_CHECK_WAITING_TEXTURE)
  14. self.state = 'waiting'
  15. self:SetAlpha(1)
  16. self:Show()
  17. end
  18. local Confirm = function(self, ready)
  19. removeEntry(self)
  20. if(ready) then
  21. self:SetTexture(READY_CHECK_READY_TEXTURE)
  22. self.state = 'ready'
  23. else
  24. self:SetTexture(READY_CHECK_NOT_READY_TEXTURE)
  25. self.state = 'notready'
  26. end
  27. self:SetAlpha(1)
  28. self:Show()
  29. end
  30. local Finish = function(self)
  31. if(self.state == 'waiting') then
  32. self:SetTexture(READY_CHECK_AFK_TEXTURE)
  33. self.state = 'afk'
  34. end
  35. self.finishedTimer = self.finishedTime or 10
  36. self.fadeTimer = self.fadeTime or 1.5
  37. _TIMERS[self] = true
  38. ReadyCheckFrame:Show()
  39. end
  40. local OnUpdate = function(self, elapsed)
  41. for icon in next, _TIMERS do
  42. if(icon.finishedTimer) then
  43. icon.finishedTimer = icon.finishedTimer - elapsed
  44. if(icon.finishedTimer <= 0) then
  45. icon.finishedTimer = nil
  46. end
  47. elseif(icon.fadeTimer) then
  48. icon.fadeTimer = icon.fadeTimer - elapsed
  49. icon:SetAlpha(icon.fadeTimer / (icon.fadeTime or 1.5))
  50. if(icon.fadeTimer <= 0) then
  51. icon:Hide()
  52. removeEntry(icon)
  53. end
  54. end
  55. end
  56. end
  57. local Update = function(self, event)
  58. local unit = self.unit
  59. local readyCheck = self.ReadyCheck
  60. if(event == 'READY_CHECK_FINISHED') then
  61. Finish(readyCheck)
  62. else
  63. local status = GetReadyCheckStatus(unit)
  64. if(UnitExists(unit) and status) then
  65. if(status == 'ready') then
  66. Confirm(readyCheck, 1)
  67. elseif(status == 'notready') then
  68. Confirm(readyCheck)
  69. else
  70. Start(readyCheck)
  71. end
  72. end
  73. end
  74. end
  75. local Path = function(self, ...)
  76. return (self.ReadyCheck.Override or Update) (self, ...)
  77. end
  78. local ForceUpdate = function(element)
  79. return Path(element.__owner, 'ForceUpdate')
  80. end
  81. local Enable = function(self, unit)
  82. local readyCheck = self.ReadyCheck
  83. if(readyCheck and (unit and (unit:sub(1, 5) == 'party' or unit:sub(1,4) == 'raid'))) then
  84. readyCheck.__owner = self
  85. readyCheck.ForceUpdate = ForceUpdate
  86. if(not ReadyCheckFrame) then
  87. ReadyCheckFrame = CreateFrame'Frame'
  88. ReadyCheckFrame:SetScript('OnUpdate', OnUpdate)
  89. end
  90. self:RegisterEvent('READY_CHECK', Path)
  91. self:RegisterEvent('READY_CHECK_CONFIRM', Path)
  92. self:RegisterEvent('READY_CHECK_FINISHED', Path)
  93. return true
  94. end
  95. end
  96. local Disable = function(self)
  97. local readyCheck = self.ReadyCheck
  98. if(readyCheck) then
  99. self:UnregisterEvent('READY_CHECK', Path)
  100. self:UnregisterEvent('READY_CHECK_CONFIRM', Path)
  101. self:UnregisterEvent('READY_CHECK_FINISHED', Path)
  102. end
  103. end
  104. oUF:AddElement('ReadyCheck', Path, Enable, Disable)