Advertisement
Guest User

Orange

a guest
Feb 21st, 2020
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.76 KB | None | 0 0
  1. local addonName, addonTable = ...
  2.  
  3. setmetatable(addonTable, {__index = getfenv() })
  4. setfenv(1, addonTable)
  5.  
  6. EFrame.newClass("SpinningCountdown", EFrame.Image)
  7.  
  8. SpinningCountdown:attach("time")
  9. SpinningCountdown:attach("looping")
  10. SpinningCountdown:attach("duration")
  11. SpinningCountdown:attach("remaning")
  12. SpinningCountdown:attach("showTime")
  13. SpinningCountdown:attach("message")
  14. SpinningCountdown.__time = 0
  15. SpinningCountdown.__remaning = 0
  16. SpinningCountdown.__duration = 0
  17. SpinningCountdown.__message = ""
  18.  
  19. function SpinningCountdown:new(parent)
  20. EFrame.Image.new(self, parent)
  21. self.source = "Interface\\AddOns\\"..addonName.."\\Textures\\SpinningCountdownRing"
  22. self.implicitWidth = 32
  23. self.implicitHeight = 32
  24. self.head = EFrame.Image(self)
  25. self.head.source = "Interface\\AddOns\\"..addonName.."\\Textures\\SpinningCountdownHead"
  26. self.head.implicitWidth = EFrame.bind(function() return self.width end)
  27. self.head.implicitHeight = EFrame.bind(function() return self.height end)
  28. self.head.voffset = -2
  29. self.head.anchorCenter = self.top
  30. self._headColor = EFrame.bind(function() return self.head.color end)
  31. self.head.color = EFrame.bind(function() return self.color end)
  32. self.animation = EFrame.PropertyAnimation(self)
  33. self.animation.property = "remaning"
  34. self.animation.from = EFrame.bind(function() return self.time - GetTime() end)
  35. self.animation.duration = EFrame.bind(function() return self.time - GetTime() end)
  36. self.animation.to = 0
  37. self.label = EFrame.Label(self)
  38. self.label.anchorCenter = self.center
  39. self.label.text = EFrame.bind(function() return math.max(0, math.ceil(self.remaning)) end)
  40. self.label.visible = EFrame.bind(self, "showTime")
  41. self.rotation = EFrame.bind(function ()
  42. return self.duration > 0 and (self.duration - self.remaning) / self.duration * 2 * math.pi or 0
  43. end)
  44. self.animation:connect("finished", function ()
  45. if self.looping then
  46. self:restart(self.duration)
  47. else
  48. self.flashing.running = true
  49. end
  50. end)
  51. self.flashing = EFrame.PropertyAnimation(self)
  52. self.flashing.from = 1
  53. self.flashing.to = 0
  54. self.flashing.duration = 1.125
  55. self.flashing.property = "opacity"
  56. self.flashing.looping = true
  57. self.mouse = EFrame.MouseArea(self)
  58. self.mouse.anchorFill = self
  59. self.mouse.hoverEnabled = true
  60. self.mouse:connect("containsMouseChanged", function (c)
  61. if c then
  62. GameTooltip:SetOwner(self.mouse.frame, "ANCHOR_BOTTOM")
  63. self:refreshTooltip()
  64. EFrame.root:connect("update", self, "refreshTooltip")
  65. GameTooltip:Show()
  66. elseif GameTooltip:IsOwned(self.mouse.frame) then
  67. EFrame.root:disconnect("update", self, "refreshTooltip")
  68. GameTooltip:Hide()
  69. end
  70. end)
  71. self.mouse:connect("clicked", function (c)
  72. if self.time - GetTime() >= 0 then
  73. local t = math.max(0, math.ceil(self.time - GetTime()))
  74. SendChatMessage(format("%s in: %d:%02d", self.message , math.floor(t/60), t%60), "INSTANCE_CHAT")
  75. end
  76. end)
  77. self.mouse.enabled = EFrame.bind(function() return self.animation.running or self.flashing.running end)
  78. end
  79.  
  80. function SpinningCountdown:refreshTooltip()
  81. if not GameTooltip:IsOwned(self.mouse.frame) then
  82. return EFrame.root:disconnect("update", self, "refreshTooltip")
  83. end
  84. if self.time - GetTime() >= 0 then
  85. local t = math.max(0, math.ceil(self.time - GetTime()))
  86. GameTooltip:SetText(format("%s in: %d:%02d", self.message , math.floor(t/60), t%60))
  87. else
  88. GameTooltip:SetText(self.message)
  89. end
  90. end
  91.  
  92. function SpinningCountdown:restart(r,d)
  93. self.animation.running = false
  94. d = d or r
  95. self.duration = d
  96. self.time = GetTime() + r
  97. self.opacity = 1
  98. self.flashing.running = false
  99. self.animation.running = true
  100. end
  101.  
  102. function SpinningCountdown:stop()
  103. self.animation.running = false
  104. self.flashing.running = false
  105. self.opacity = 0
  106. end
  107.  
  108. EFrame.newClass("FlagFrame", EFrame.Item)
  109.  
  110. FlagFrame:attach("flag")
  111.  
  112. local classIdx = {
  113. WARRIOR = 0,
  114. MAGE = 1,
  115. ROGUE = 2,
  116. DRUID = 3,
  117. HUNTER = 4,
  118. SHAMAN = 5,
  119. PRIEST = 6,
  120. WARLOCK = 7,
  121. PALADIN = 8
  122. }
  123.  
  124. function FlagFrame:new(bg, faction)
  125. EFrame.Item.new(self)
  126. self.faction = faction
  127. self.bar = EFrame.ProgressBar(self)
  128. self.label = EFrame.Label(self)
  129. self.icon = EFrame.Image(self)
  130. self.button = EFrame.Item(self, _G["StrategosSecureBtn"..faction] or CreateFrame("Button", "StrategosSecureBtn"..faction, nil, "SecureActionButtonTemplate"), false)
  131. _G["StrategosSecureBtn" .. faction]:Show()
  132. self.button.frame:SetParent(self.frame)
  133. self.button:attach("actual")
  134. self.button.frame:SetAttribute("type1","macro")
  135. bg.carriers[faction]:connect("nameChanged", self, "updateSecureButton").nocombat = true
  136. self.timer = SpinningCountdown(self)
  137. self.label.color = EFrame.bind(function() return self.button.actual == bg.carriers[faction].name and (faction == Alliance and {1,0.3,0,1} or {1,0.3,0,1}) or {1,0.3,0,1} end)
  138. self.label.text = EFrame.bind(function ()
  139. local flag = bg.flags[3-faction]
  140. if flag.status == Flag.Carried then
  141. return flag.carrier.name or "????"
  142. elseif flag.status == Flag.Ground then
  143. return "__GROUND__"
  144. end
  145. end)
  146. self.bar.anchorLeft = self.left
  147. self.bar.anchorRight = self.icon.left
  148. self.bar.marginRight = 6
  149. self.bar.from = 0
  150. self.bar.to = 100
  151. self.bar.texture = "Interface\\TargetingFrame\\UI-StatusBar"
  152. self.bar.color = {0,1,0,1}
  153. self.bar.implicitWidth = EFrame.bind(function() return math.max(self.label.implicitWidth, 92) + 8 end)
  154. self.bar:setNoCombat("implicitWidth")
  155. self.bar.height = EFrame.bind(function() return self.height end)
  156. self.bar.value = EFrame.bind(function() return bg.carriers[faction].health or 0 end)
  157. self.label.z = 2
  158. self.label.anchorFill = self.bar
  159.  
  160. self.button.margins = -4
  161. self.button.anchorFill = self.bar
  162. self.button.flat = true
  163. self.button.backdrop = {
  164. bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16,
  165. edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 16,
  166. insets = { left = 4, right = 4, top = 4, bottom = 4 }
  167. }
  168. self.button.backdropColor = faction == Alliance and {0,0,1,.25} or {1,0,0,.25}
  169.  
  170. self.icon.marginRight = 2
  171. self.icon.anchorRight = self.timer.left
  172. self.icon.source = "Interface\\Glues\\CharacterCreate\\UI-CharacterCreate-Classes.blp"
  173. self.icon.height = EFrame.bind(function() return self.height end)
  174. self.icon.width = EFrame.bind(function() return self.height end)
  175. bg.carriers[faction]:connect("classChanged", function (class)
  176. local idx = classIdx[class]
  177. if idx then
  178. local sx, sy = mod(idx,4), floor(idx/4)
  179. self.icon:setCoords(sx/4, (sx +1)/4, sy/4, (sy +1)/4)
  180. end
  181. end)
  182. self.icon.opacity = EFrame.bind(function() return bg.flags[3-faction].status == Flag.Carried and 1 or 0 end)
  183. self.timer.anchorRight = self.right
  184. self.timer.height = EFrame.bind(function() return self.height end)
  185. self.timer.width = EFrame.bind(function() return self.height end)
  186. bg.flags[3-faction]:connect("placed", self.timer, "stop")
  187. bg.flags[3-faction]:connect("picked", self.timer, "stop")
  188. self.timer.message = "Resetting"
  189. self.timer.opacity = 0
  190. bg.flags[3-faction]:connect("resetting", self.timer, "restart")
  191. self.implicitWidth = EFrame.bind(function() return self.bar.implicitWidth + self.icon.width + self.timer.width + 8 end)
  192. self.opacity = EFrame.bind(function() local status = bg.flags[3-faction].status return status and status ~= Flag.Resetting and 1 or 0.15 end)
  193. end
  194.  
  195. function FlagFrame:destroy()
  196. EFrame.Item.destroy(self)
  197. EFrame:invokeNoCombat(_G["StrategosSecureBtn" .. self.faction].Hide, _G["StrategosSecureBtn" .. self.faction])
  198. end
  199.  
  200. function FlagFrame:updateSecureButton(v)
  201. if v then
  202. self.button.frame:SetAttribute("macrotext1", "/target "..v)
  203. else
  204. self.button.frame:SetAttribute("macrotext1", nil)
  205. end
  206. self.button.actual = v
  207. end
  208.  
  209. EFrame.newClass("SpiritHealerIndicator", EFrame.ProgressBar)
  210.  
  211. SpiritHealerIndicator:attach("node")
  212.  
  213. function SpiritHealerIndicator:new(parent)
  214. EFrame.ProgressBar.new(self, parent)
  215. self.marginTop = 14 * UIParent:GetScale()
  216. self.anim = EFrame.PropertyAnimation(self)
  217. self.bl = EFrame.Label(self)
  218. self.bl.anchorFill = self
  219. self.height = 0
  220. self.from = 0
  221. self.to = math.ceil(tresstime)
  222. self.width = 0 * UIParent:GetScale()
  223. self.anim.from = EFrame.bind(function() return (1-tresstime%1) + tresstime - self.anim.duration end)
  224. self.anim.to = math.ceil(tresstime)
  225. self.anim.property = "value"
  226. self.anim:connect("runningChanged", function (v)
  227. if not v then
  228. self.anim.duration = self.node:spiritHealerTime()
  229. self.anim.running = true
  230. end
  231. end)
  232. self.br = EFrame.Rectangle(self)
  233. self.br.anchorFill = self
  234. self.br.margins = -4
  235. self.br.color = {0,0,0,0}
  236. self.br.borderWidth = 2
  237. self.br.borderColor = {0,0,0,1}
  238. self.opacity = EFrame.bind(function() return 0.33 + self.value/resstime * 0.66 end)
  239. self.label = EFrame.Label(self)
  240. self.label.anchorTop = self.br.bottom
  241. self.label.text = EFrame.bind(function() return self.node and self.node.name or "" end)
  242. end
  243.  
  244. function SpiritHealerIndicator:restart(node)
  245. self.anim.running = false
  246. self.anim.duration = node:spiritHealerTime()
  247. self.node = node
  248. self.anim.running = true
  249. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement