/Interface/AddOns/oUF_Neav/castbar.lua

http://github.com/renstrom/NeavUI · Lua · 276 lines · 220 code · 51 blank · 5 comment · 56 complexity · de0ae7637ad8117269ea1186180900c1 MD5 · raw file

  1. local _, ns = ...
  2. local function CreateAnchor(unit, text)
  3. local config = ns.Config.units[ns.cUnit(unit)].castbar
  4. local width = (config.width + config.height) * config.scale
  5. local height = config.height * config.scale
  6. local anchorFrame = CreateFrame("Frame", "oUF_Neav "..unit.."_Castbar_Anchor", UIParent)
  7. anchorFrame:SetSize(width, height)
  8. anchorFrame:SetScale(1.193)
  9. anchorFrame:SetPoint(unpack(config.position))
  10. anchorFrame:SetFrameStrata("HIGH")
  11. anchorFrame:SetMovable(true)
  12. anchorFrame:SetClampedToScreen(true)
  13. anchorFrame:SetUserPlaced(true)
  14. anchorFrame:SetBackdrop({bgFile="Interface\\MINIMAP\\TooltipBackdrop-Background",})
  15. anchorFrame:CreateBeautyBorder(11)
  16. anchorFrame:SetBeautyBorderPadding(2.66)
  17. anchorFrame:EnableMouse(true)
  18. anchorFrame:RegisterForDrag("LeftButton")
  19. anchorFrame:Hide()
  20. anchorFrame.text = anchorFrame:CreateFontString(nil, "OVERLAY")
  21. anchorFrame.text:SetAllPoints(anchorFrame)
  22. anchorFrame.text:SetFont(STANDARD_TEXT_FONT, 13)
  23. anchorFrame.text:SetText(text.." Castbar Anchor")
  24. anchorFrame:SetScript("OnDragStart", function(self)
  25. self:StartMoving()
  26. end)
  27. anchorFrame:SetScript("OnDragStop", function(self)
  28. self:StopMovingOrSizing()
  29. end)
  30. return anchorFrame
  31. end
  32. local playerCastbarHolder = CreateAnchor("player","Player")
  33. local targetCastbarHolder = CreateAnchor("target","Target")
  34. local petCastbarHolder = CreateAnchor("pet","Pet")
  35. -- Create the castbars
  36. function ns.CreateCastbars(self, unit)
  37. local config = ns.Config.units[ns.cUnit(unit)].castbar
  38. if ns.MultiCheck(unit, "player", "target", "focus", "pet") and config and config.show then
  39. self.Castbar = CreateFrame("StatusBar", self:GetName().."Castbar", self)
  40. self.Castbar:SetStatusBarTexture(ns.Config.media.statusbar)
  41. self.Castbar:SetSize(config.width, config.height)
  42. self.Castbar:SetScale(config.scale)
  43. self.Castbar.castColor = config.castColor
  44. self.Castbar.channeledColor = config.channeledColor
  45. self.Castbar.nonInterruptibleColor = config.nonInterruptibleColor
  46. self.Castbar.failedCastColor = config.failedCastColor
  47. self.Castbar.unit = unit
  48. self.Castbar.timeToHold = 1
  49. if unit == "focus" then
  50. self.Castbar:SetPoint("BOTTOM", self, "TOP", 0, 25)
  51. elseif unit == "player" then
  52. self.Castbar:SetPoint("BOTTOMRIGHT", playerCastbarHolder)
  53. elseif unit == "target" then
  54. self.Castbar:SetPoint("BOTTOMRIGHT", targetCastbarHolder)
  55. elseif unit == "pet" then
  56. self.Castbar:SetPoint("BOTTOMRIGHT", petCastbarHolder)
  57. end
  58. self.Castbar.Background = self.Castbar:CreateTexture("$parentBackground", "BACKGROUND")
  59. self.Castbar.Background:SetTexture("Interface\\Buttons\\WHITE8x8")
  60. self.Castbar.Background:SetAllPoints(self.Castbar)
  61. if unit == "player" then
  62. if config.classcolor then
  63. local playerColor = RAID_CLASS_COLORS[select(2, UnitClass("player"))]
  64. self.Castbar.castColor = {playerColor.r, playerColor.g, playerColor.b}
  65. self.Castbar.channeledColor = {playerColor.r, playerColor.g, playerColor.b}
  66. end
  67. if config.showSafezone then
  68. self.Castbar.SafeZone = self.Castbar:CreateTexture("$parentSafeZoneTexture", "BORDER")
  69. self.Castbar.SafeZone:SetColorTexture(unpack(config.safezoneColor))
  70. end
  71. if config.showLatency then
  72. self.Castbar.Latency = self.Castbar:CreateFontString("$parentLatency", "OVERLAY")
  73. self.Castbar.Latency:SetFont(ns.Config.font.normal, ns.Config.font.normalSize - 1)
  74. self.Castbar.Latency:SetShadowOffset(1, -1)
  75. self.Castbar.Latency:SetVertexColor(0.6, 0.6, 0.6, 1)
  76. end
  77. end
  78. self.Castbar:CreateBeautyBorder(11)
  79. self.Castbar:SetBeautyBorderPadding(2.66)
  80. ns.CreateCastbarStrings(self)
  81. if config.icon.show then
  82. self.Castbar.Icon = self.Castbar:CreateTexture("$parentIcon", "ARTWORK")
  83. self.Castbar.Icon:SetSize(config.height + 2, config.height + 2)
  84. self.Castbar.Icon:SetTexCoord(0.1, 0.9, 0.1, 0.9)
  85. if config.icon.position == "LEFT" then
  86. self.Castbar.Icon:SetPoint("RIGHT", self.Castbar, "LEFT", (config.icon.positionOutside and -8) or 0, 0)
  87. else
  88. self.Castbar.Icon:SetPoint("LEFT", self.Castbar, "RIGHT", (config.icon.positionOutside and 8) or 0, 0)
  89. end
  90. if config.icon.positionOutside then
  91. self.Castbar.IconOverlay = CreateFrame("Frame", "$parentIconOverlay", self.Castbar)
  92. self.Castbar.IconOverlay:SetAllPoints(self.Castbar.Icon)
  93. self.Castbar.IconOverlay:CreateBeautyBorder(10)
  94. self.Castbar.IconOverlay:SetBeautyBorderPadding(2)
  95. else
  96. if config.icon.position == "LEFT" then
  97. self.Castbar:SetBeautyBorderPadding(4 + config.height, 3, 3, 3, 4 + config.height, 3, 3, 3, 3)
  98. else
  99. self.Castbar:SetBeautyBorderPadding(3, 3, 4 + config.height, 3, 3, 3, 4 + config.height, 3, 3)
  100. end
  101. end
  102. end
  103. -- Interrupt indicator
  104. self.Castbar.PostCastStart = function(self, unit)
  105. ns.UpdateCastbarColor(self)
  106. if unit == "player" then
  107. if self.Latency then
  108. local down, up, lagHome, lagWorld = GetNetStats()
  109. local avgLag = (lagHome + lagWorld) / 2
  110. self.Latency:ClearAllPoints()
  111. self.Latency:SetPoint("RIGHT", self, "BOTTOMRIGHT", -1, -2)
  112. self.Latency:SetText(string.format("%.0f", avgLag).."ms")
  113. end
  114. end
  115. -- Hide some special spells like waterbold or firebold (pets) because it gets really spammy
  116. if ns.Config.units.pet.castbar.ignoreSpells then
  117. if unit == "pet" then
  118. self:SetAlpha(1)
  119. for _, spellID in pairs(ns.Config.units.pet.castbar.ignoreList) do
  120. if UnitCastingInfo("pet") == GetSpellInfo(spellID) then
  121. self:SetAlpha(0)
  122. end
  123. end
  124. end
  125. end
  126. end
  127. self.Castbar.PostChannelStart = function(self, unit)
  128. ns.UpdateCastbarColor(self)
  129. if unit == "player" then
  130. if self.Latency then
  131. local down, up, lagHome, lagWorld = GetNetStats()
  132. local avgLag = (lagHome + lagWorld) / 2
  133. self.Latency:ClearAllPoints()
  134. self.Latency:SetPoint("LEFT", self, "BOTTOMLEFT", 1, -2)
  135. self.Latency:SetText(string.format("%.0f", avgLag).."ms")
  136. end
  137. end
  138. if ns.Config.units.pet.castbar.ignoreSpells then
  139. if unit == "pet" and self:GetAlpha() == 0 then
  140. self:SetAlpha(1)
  141. end
  142. end
  143. end
  144. self.Castbar.PostCastInterrupted = function(self, unit)
  145. self:SetStatusBarColor(unpack(self.failedCastColor))
  146. self.Background:SetVertexColor(self.failedCastColor[1]*0.3, self.failedCastColor[2]*0.3, self.failedCastColor[3]*0.3)
  147. end
  148. self.Castbar.PostCastInterruptible = ns.UpdateCastbarColor
  149. self.Castbar.PostCastNotInterruptible = ns.UpdateCastbarColor
  150. self.Castbar.CustomDelayText = ns.CustomDelayText
  151. self.Castbar.CustomTimeText = ns.CustomTimeText
  152. end
  153. end
  154. -- Mirror timers
  155. for i = 1, MIRRORTIMER_NUMTIMERS do
  156. local bar = _G["MirrorTimer"..i]
  157. bar:SetParent(UIParent)
  158. bar:SetScale(1.132)
  159. bar:SetSize(220, 18)
  160. bar:CreateBeautyBorder(11)
  161. bar:SetBeautyBorderPadding(3)
  162. if i > 1 then
  163. local p1, p2, p3, p4, p5 = bar:GetPoint()
  164. bar:SetPoint(p1, p2, p3, p4, p5 - 15)
  165. end
  166. local statusbar = _G["MirrorTimer"..i.."StatusBar"]
  167. statusbar:SetStatusBarTexture(ns.Config.media.statusbar)
  168. statusbar:SetAllPoints(bar)
  169. local backdrop = select(1, bar:GetRegions())
  170. backdrop:SetTexture("Interface\\Buttons\\WHITE8x8")
  171. backdrop:SetVertexColor(0, 0, 0, 0.5)
  172. backdrop:SetAllPoints(bar)
  173. local border = _G["MirrorTimer"..i.."Border"]
  174. border:Hide()
  175. local text = _G["MirrorTimer"..i.."Text"]
  176. text:SetFont(ns.Config.font.normal, ns.Config.font.normalSize)
  177. text:ClearAllPoints()
  178. text:SetPoint("CENTER", bar)
  179. end
  180. -- Battleground timer
  181. local f = CreateFrame("Frame")
  182. f:RegisterEvent("START_TIMER")
  183. f:SetScript("OnEvent", function(self, event)
  184. for _, b in pairs(TimerTracker.timerList) do
  185. if not b["bar"].beautyBorder then
  186. local bar = b["bar"]
  187. bar:SetScale(1.132)
  188. bar:SetSize(220, 18)
  189. for i = 1, select("#", bar:GetRegions()) do
  190. local region = select(i, bar:GetRegions())
  191. if region and region:GetObjectType() == "Texture" then
  192. region:SetTexture(nil)
  193. end
  194. if region and region:GetObjectType() == "FontString" then
  195. region:ClearAllPoints()
  196. region:SetPoint("CENTER", bar)
  197. region:SetFont(ns.Config.font.normal, ns.Config.font.normalSize)
  198. end
  199. end
  200. bar:CreateBeautyBorder(11)
  201. bar:SetBeautyBorderPadding(3)
  202. bar:SetStatusBarTexture(ns.Config.media.statusbar)
  203. local backdrop = select(1, bar:GetRegions())
  204. backdrop:SetTexture("Interface\\Buttons\\WHITE8x8")
  205. backdrop:SetVertexColor(0, 0, 0, 0.5)
  206. backdrop:SetAllPoints(bar)
  207. end
  208. end
  209. end)
  210. SlashCmdList["oUF_Neav_Castbar_AnchorToggle"] = function()
  211. if InCombatLockdown() then
  212. print("oUF_Neav: You cant do this in combat!")
  213. return
  214. end
  215. if not playerCastbarHolder:IsShown() then
  216. playerCastbarHolder:Show()
  217. targetCastbarHolder:Show()
  218. petCastbarHolder:Show()
  219. else
  220. playerCastbarHolder:Hide()
  221. targetCastbarHolder:Hide()
  222. petCastbarHolder:Hide()
  223. end
  224. end
  225. SLASH_oUF_Neav_Castbar_AnchorToggle1 = "/neavcast"