/Tukui/modules/nameplates/nameplates.lua

http://github.com/Asphyxia/Tukui · Lua · 699 lines · 597 code · 64 blank · 38 comment · 94 complexity · 432dd9ac7db903b35af6d28b13de6ff6 MD5 · raw file

  1. local T, C, L = unpack(select(2, ...)) -- Import Functions/Constants/Variables, Config, Locales
  2. --Base code by Dawn (dNameplates), Rewritten by Elv22
  3. if not C["nameplate"].enable == true then return end
  4. local TEXTURE = C["media"].normTex
  5. local FONT = C["media"].pixelfont
  6. local FONTSIZE = 10
  7. local FONTFLAG = "MONOCHROMEOUTLINE"
  8. local hpHeight = 12
  9. local hpWidth = 110
  10. local iconSize = 25 --Size of all Icons, RaidIcon/ClassIcon/Castbar Icon
  11. local cbHeight = 5
  12. local cbWidth = 110
  13. local blankTex = C["media"].blank
  14. local OVERLAY = [=[Interface\TargetingFrame\UI-TargetingFrame-Flash]=]
  15. local numChildren = -1
  16. local frames = {}
  17. local noscalemult = T.mult * C["general"].uiscale
  18. --Change defaults if we are showing health text or not
  19. if C["nameplate"].showhealth ~= true then
  20. hpHeight = 7
  21. iconSize = 20
  22. end
  23. local NamePlates = CreateFrame("Frame", nil, UIParent)
  24. NamePlates:SetScript("OnEvent", function(self, event, ...) self[event](self, ...) end)
  25. if C["nameplate"].trackdebuffs == true or C["nameplate"].trackcc == true then
  26. NamePlates:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  27. end
  28. local function QueueObject(parent, object)
  29. parent.queue = parent.queue or {}
  30. parent.queue[object] = true
  31. end
  32. local function HideObjects(parent)
  33. for object in pairs(parent.queue) do
  34. if(object:GetObjectType() == 'Texture') then
  35. object:SetTexture(nil)
  36. object.SetTexture = T.dummy
  37. elseif (object:GetObjectType() == 'FontString') then
  38. object.ClearAllPoints = T.dummy
  39. object.SetFont = T.dummy
  40. object.SetPoint = T.dummy
  41. object:Hide()
  42. object.Show = T.dummy
  43. object.SetText = T.dummy
  44. object.SetShadowOffset = T.dummy
  45. else
  46. object:Hide()
  47. object.Show = T.dummy
  48. end
  49. end
  50. end
  51. --Create a fake backdrop frame using textures
  52. local function CreateVirtualFrame(parent, point)
  53. if point == nil then point = parent end
  54. if point.backdrop then return end
  55. parent.backdrop = parent:CreateTexture(nil, "BORDER")
  56. parent.backdrop:SetDrawLayer("BORDER", -8)
  57. parent.backdrop:SetPoint("TOPLEFT", point, "TOPLEFT", -noscalemult*3, noscalemult*3)
  58. parent.backdrop:SetPoint("BOTTOMRIGHT", point, "BOTTOMRIGHT", noscalemult*3, -noscalemult*3)
  59. parent.backdrop:SetTexture(0, 0, 0, 1)
  60. parent.backdrop2 = parent:CreateTexture(nil, "BORDER")
  61. parent.backdrop2:SetDrawLayer("BORDER", -7)
  62. parent.backdrop2:SetAllPoints(point)
  63. parent.backdrop2:SetTexture(unpack(C["media"].backdropcolor))
  64. parent.bordertop = parent:CreateTexture(nil, "BORDER")
  65. parent.bordertop:SetPoint("TOPLEFT", point, "TOPLEFT", -noscalemult*2, noscalemult*2)
  66. parent.bordertop:SetPoint("TOPRIGHT", point, "TOPRIGHT", noscalemult*2, noscalemult*2)
  67. parent.bordertop:SetHeight(noscalemult)
  68. parent.bordertop:SetTexture(unpack(C["media"].bordercolor))
  69. parent.bordertop:SetDrawLayer("BORDER", -7)
  70. parent.borderbottom = parent:CreateTexture(nil, "BORDER")
  71. parent.borderbottom:SetPoint("BOTTOMLEFT", point, "BOTTOMLEFT", -noscalemult*2, -noscalemult*2)
  72. parent.borderbottom:SetPoint("BOTTOMRIGHT", point, "BOTTOMRIGHT", noscalemult*2, -noscalemult*2)
  73. parent.borderbottom:SetHeight(noscalemult)
  74. parent.borderbottom:SetTexture(unpack(C["media"].bordercolor))
  75. parent.borderbottom:SetDrawLayer("BORDER", -7)
  76. parent.borderleft = parent:CreateTexture(nil, "BORDER")
  77. parent.borderleft:SetPoint("TOPLEFT", point, "TOPLEFT", -noscalemult*2, noscalemult*2)
  78. parent.borderleft:SetPoint("BOTTOMLEFT", point, "BOTTOMLEFT", noscalemult*2, -noscalemult*2)
  79. parent.borderleft:SetWidth(noscalemult)
  80. parent.borderleft:SetTexture(unpack(C["media"].bordercolor))
  81. parent.borderleft:SetDrawLayer("BORDER", -7)
  82. parent.borderright = parent:CreateTexture(nil, "BORDER")
  83. parent.borderright:SetPoint("TOPRIGHT", point, "TOPRIGHT", noscalemult*2, noscalemult*2)
  84. parent.borderright:SetPoint("BOTTOMRIGHT", point, "BOTTOMRIGHT", -noscalemult*2, -noscalemult*2)
  85. parent.borderright:SetWidth(noscalemult)
  86. parent.borderright:SetTexture(unpack(C["media"].bordercolor))
  87. parent.borderright:SetDrawLayer("BORDER", -7)
  88. end
  89. local function SetVirtualBorder(parent, r, g, b)
  90. parent.bordertop:SetTexture(r, g, b)
  91. parent.borderbottom:SetTexture(r, g, b)
  92. parent.borderleft:SetTexture(r, g, b)
  93. parent.borderright:SetTexture(r, g, b)
  94. end
  95. --OnUpdate function for all nameplates, we use this to update threat, health, and anything else that may require rapid updates.
  96. local goodR, goodG, goodB = unpack(C["nameplate"].goodcolor)
  97. local badR, badG, badB = unpack(C["nameplate"].badcolor)
  98. local transitionR, transitionG, transitionB = unpack(C["nameplate"].transitioncolor)
  99. local function UpdateThreat(frame, elapsed)
  100. frame.hp:Show()
  101. if frame.hasClass == true then return end
  102. if C["nameplate"].enhancethreat ~= true then
  103. if(frame.region:IsShown()) then
  104. local _, val = frame.region:GetVertexColor()
  105. if(val > 0.7) then
  106. SetVirtualBorder(frame.hp, transitionR, transitionG, transitionB)
  107. else
  108. SetVirtualBorder(frame.hp, badR, badG, badB)
  109. end
  110. else
  111. SetVirtualBorder(frame.hp, unpack(C["media"].bordercolor))
  112. end
  113. else
  114. if not frame.region:IsShown() then
  115. if InCombatLockdown() and frame.isFriendly ~= true then
  116. --No Threat
  117. if T.Role == "Tank" then
  118. frame.hp:SetStatusBarColor(badR, badG, badB)
  119. frame.hp.hpbg:SetTexture(badR, badG, badB, 0.25)
  120. else
  121. frame.hp:SetStatusBarColor(goodR, goodG, goodB)
  122. frame.hp.hpbg:SetTexture(goodR, goodG, goodB, 0.25)
  123. end
  124. else
  125. --Set colors to their original, not in combat
  126. frame.hp:SetStatusBarColor(frame.hp.rcolor, frame.hp.gcolor, frame.hp.bcolor)
  127. frame.hp.hpbg:SetTexture(frame.hp.rcolor, frame.hp.gcolor, frame.hp.bcolor, 0.25)
  128. end
  129. else
  130. --Ok we either have threat or we're losing/gaining it
  131. local r, g, b = frame.region:GetVertexColor()
  132. if g + b == 0 then
  133. --Have Threat
  134. if T.Role == "Tank" then
  135. frame.hp:SetStatusBarColor(goodR, goodG, goodB)
  136. frame.hp.hpbg:SetTexture(goodR, goodG, goodB, 0.25)
  137. else
  138. frame.hp:SetStatusBarColor(badR, badG, badB)
  139. frame.hp.hpbg:SetTexture(badR, badG, badB, 0.25)
  140. end
  141. else
  142. --Losing/Gaining Threat
  143. frame.hp:SetStatusBarColor(transitionR, transitionG, transitionB)
  144. frame.hp.hpbg:SetTexture(transitionR, transitionG, transitionB, 0.25)
  145. end
  146. end
  147. end
  148. end
  149. --Create our Aura Icons
  150. local function CreateAuraIcon(parent)
  151. local button = CreateFrame("Frame",nil,parent)
  152. button:SetWidth(20)
  153. button:SetHeight(20)
  154. button.bg = button:CreateTexture(nil, "BACKGROUND")
  155. button.bg:SetTexture(unpack(C["media"].backdropcolor))
  156. button.bg:SetAllPoints(button)
  157. button.bord = button:CreateTexture(nil, "BORDER")
  158. button.bord:SetTexture(unpack(C["media"].bordercolor))
  159. button.bord:SetPoint("TOPLEFT",button,"TOPLEFT", noscalemult,-noscalemult)
  160. button.bord:SetPoint("BOTTOMRIGHT",button,"BOTTOMRIGHT",-noscalemult,noscalemult)
  161. button.bg2 = button:CreateTexture(nil, "ARTWORK")
  162. button.bg2:SetTexture(unpack(C["media"].backdropcolor))
  163. button.bg2:SetPoint("TOPLEFT",button,"TOPLEFT", noscalemult*2,-noscalemult*2)
  164. button.bg2:SetPoint("BOTTOMRIGHT",button,"BOTTOMRIGHT",-noscalemult*2,noscalemult*2)
  165. button.icon = button:CreateTexture(nil, "OVERLAY")
  166. button.icon:SetPoint("TOPLEFT",button,"TOPLEFT", noscalemult*3,-noscalemult*3)
  167. button.icon:SetPoint("BOTTOMRIGHT",button,"BOTTOMRIGHT",-noscalemult*3,noscalemult*3)
  168. button.icon:SetTexCoord(0.1, 0.9, 0.1, 0.9)
  169. button.cd = CreateFrame("Cooldown",nil,button)
  170. button.cd:SetAllPoints(button)
  171. button.cd:SetReverse(true)
  172. button.count = button:CreateFontString(nil,"OVERLAY")
  173. button.count:SetFont(FONT, 10, FONTFLAG)
  174. button.count:SetShadowColor(0, 0, 0, 0.4)
  175. button.count:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", 0, 2)
  176. return button
  177. end
  178. --Update an Aura Icon
  179. local function UpdateAuraIcon(button, unit, index, filter)
  180. local name,_,icon,count,debuffType,duration,expirationTime,_,_,_,spellID = UnitAura(unit,index,filter)
  181. button.icon:SetTexture(icon)
  182. button.cd:SetCooldown(expirationTime-duration,duration)
  183. button.expirationTime = expirationTime
  184. button.duration = duration
  185. button.spellID = spellID
  186. if count > 1 then
  187. button.count:SetText(count)
  188. else
  189. button.count:SetText("")
  190. end
  191. button.cd:SetScript("OnUpdate", function(self) if not button.cd.timer then self:SetScript("OnUpdate", nil) return end button.cd.timer.text:SetFont(FONT,10,FONTFLAG) button.cd.timer.text:SetShadowColor(0, 0, 0, 0.4) end)
  192. button:Show()
  193. end
  194. --Filter auras on nameplate, and determine if we need to update them or not.
  195. local function OnAura(frame, unit)
  196. if not frame.icons or not frame.unit then return end
  197. local i = 1
  198. for index = 1,40 do
  199. if i > 5 then return end
  200. local match
  201. local name,_,_,_,_,duration,_,caster,_,_,spellid = UnitAura(frame.unit,index,"HARMFUL")
  202. if C["nameplate"].trackdebuffs == true then
  203. if caster == "player" then match = true end
  204. end
  205. if C["nameplate"].trackcc == true then
  206. if T.DebuffWhiteList[name] then match = true end
  207. end
  208. if duration and match == true then
  209. if not frame.icons[i] then frame.icons[i] = CreateAuraIcon(frame) end
  210. local icon = frame.icons[i]
  211. if i == 1 then icon:SetPoint("RIGHT",frame.icons,"RIGHT") end
  212. if i ~= 1 and i <= 5 then icon:SetPoint("RIGHT", frame.icons[i-1], "LEFT", -2, 0) end
  213. i = i + 1
  214. UpdateAuraIcon(icon, frame.unit, index, "HARMFUL")
  215. end
  216. end
  217. for index = i, #frame.icons do frame.icons[index]:Hide() end
  218. end
  219. --Color the castbar depending on if we can interrupt or not,
  220. --also resize it as nameplates somehow manage to resize some frames when they reappear after being hidden
  221. local function UpdateCastbar(frame)
  222. frame:ClearAllPoints()
  223. frame:SetSize(cbWidth, cbHeight)
  224. frame:SetPoint('TOP', frame:GetParent().hp, 'BOTTOM', 0, -8)
  225. frame:GetStatusBarTexture():SetHorizTile(true)
  226. if(frame.shield:IsShown()) then
  227. frame:SetStatusBarColor(0.78, 0.25, 0.25, 1)
  228. end
  229. end
  230. --Determine whether or not the cast is Channelled or a Regular cast so we can grab the proper Cast Name
  231. local function UpdateCastText(frame, curValue)
  232. local minValue, maxValue = frame:GetMinMaxValues()
  233. if UnitChannelInfo("target") then
  234. frame.time:SetFormattedText("%.1f ", curValue)
  235. frame.name:SetText(select(1, (UnitChannelInfo("target"))))
  236. end
  237. if UnitCastingInfo("target") then
  238. frame.time:SetFormattedText("%.1f ", maxValue - curValue)
  239. frame.name:SetText(select(1, (UnitCastingInfo("target"))))
  240. end
  241. end
  242. --Sometimes castbar likes to randomly resize
  243. local OnValueChanged = function(self, curValue)
  244. UpdateCastText(self, curValue)
  245. if self.needFix then
  246. UpdateCastbar(self)
  247. self.needFix = nil
  248. end
  249. end
  250. --Sometimes castbar likes to randomly resize
  251. local OnSizeChanged = function(self)
  252. self.needFix = true
  253. end
  254. --We need to reset everything when a nameplate it hidden, this is so theres no left over data when a nameplate gets reshown for a differant mob.
  255. local function OnHide(frame)
  256. frame.hp:SetStatusBarColor(frame.hp.rcolor, frame.hp.gcolor, frame.hp.bcolor)
  257. frame.overlay:Hide()
  258. frame.cb:Hide()
  259. frame.unit = nil
  260. frame.guid = nil
  261. frame.hasClass = nil
  262. frame.isFriendly = nil
  263. frame.hp.rcolor = nil
  264. frame.hp.gcolor = nil
  265. frame.hp.bcolor = nil
  266. if frame.icons then
  267. for _,icon in ipairs(frame.icons) do
  268. icon:Hide()
  269. end
  270. end
  271. frame:SetScript("OnUpdate",nil)
  272. end
  273. --Color the nameplate to 'Our' style instead of using blizzards ugly colors.
  274. local function Colorize(frame)
  275. local r,g,b = frame.healthOriginal:GetStatusBarColor()
  276. for class, color in pairs(RAID_CLASS_COLORS) do
  277. local r, g, b = floor(r*100+.5)/100, floor(g*100+.5)/100, floor(b*100+.5)/100
  278. if RAID_CLASS_COLORS[class].r == r and RAID_CLASS_COLORS[class].g == g and RAID_CLASS_COLORS[class].b == b then
  279. frame.hasClass = true
  280. frame.isFriendly = false
  281. frame.hp:SetStatusBarColor(unpack(T.oUF_colors.class[class]))
  282. return
  283. end
  284. end
  285. if g+b == 0 then -- hostile
  286. r,g,b = unpack(T.oUF_colors.reaction[1])
  287. frame.isFriendly = false
  288. elseif r+b == 0 then -- friendly npc
  289. r,g,b = unpack(T.oUF_colors.power["MANA"])
  290. frame.isFriendly = true
  291. elseif r+g > 1.95 then -- neutral
  292. r,g,b = unpack(T.oUF_colors.reaction[4])
  293. frame.isFriendly = false
  294. elseif r+g == 0 then -- friendly player
  295. r,g,b = unpack(T.oUF_colors.reaction[5])
  296. frame.isFriendly = true
  297. else -- enemy player
  298. frame.isFriendly = false
  299. end
  300. frame.hasClass = false
  301. frame.hp:SetStatusBarColor(r,g,b)
  302. end
  303. --HealthBar OnShow, use this to set variables for the nameplate, also size the healthbar here because it likes to lose it's
  304. --size settings when it gets reshown
  305. local function UpdateObjects(frame)
  306. local frame = frame:GetParent()
  307. local r, g, b = frame.hp:GetStatusBarColor()
  308. --Have to reposition this here so it doesnt resize after being hidden
  309. frame.hp:ClearAllPoints()
  310. frame.hp:SetSize(hpWidth, hpHeight)
  311. frame.hp:SetPoint('TOP', frame, 'TOP', 0, -15)
  312. frame.hp:GetStatusBarTexture():SetHorizTile(true)
  313. --Match values
  314. frame.hp:SetMinMaxValues(frame.healthOriginal:GetMinMaxValues())
  315. frame.hp:SetValue(frame.healthOriginal:GetValue())
  316. frame.healthOriginal:SetScript("OnValueChanged", function()
  317. frame.hp:SetMinMaxValues(frame.healthOriginal:GetMinMaxValues())
  318. frame.hp:SetValue(frame.healthOriginal:GetValue())
  319. end)
  320. --Colorize Plate
  321. Colorize(frame)
  322. frame.hp.rcolor, frame.hp.gcolor, frame.hp.bcolor = frame.hp:GetStatusBarColor()
  323. frame.hp.hpbg:SetTexture(frame.hp.rcolor, frame.hp.gcolor, frame.hp.bcolor, 0.25)
  324. SetVirtualBorder(frame.hp, unpack(C["media"].bordercolor))
  325. if C["nameplate"].enhancethreat == true then
  326. frame.hp.name:SetTextColor(frame.hp.rcolor, frame.hp.gcolor, frame.hp.bcolor)
  327. end
  328. --Set the name text
  329. frame.hp.name:SetText(frame.hp.oldname:GetText())
  330. --Setup level text
  331. local level, elite, mylevel = tonumber(frame.hp.oldlevel:GetText()), frame.hp.elite:IsShown(), UnitLevel("player")
  332. frame.hp.level:ClearAllPoints()
  333. if C["nameplate"].showhealth == true then
  334. frame.hp.level:SetPoint("RIGHT", frame.hp, "RIGHT", 2, 1)
  335. else
  336. frame.hp.level:SetPoint("RIGHT", frame.hp, "LEFT", -1, 1)
  337. end
  338. frame.hp.level:SetTextColor(frame.hp.oldlevel:GetTextColor())
  339. if frame.hp.boss:IsShown() then
  340. frame.hp.level:SetText("??")
  341. frame.hp.level:SetTextColor(0.8, 0.05, 0)
  342. frame.hp.level:Show()
  343. elseif not elite and level == mylevel then
  344. frame.hp.level:Hide()
  345. else
  346. frame.hp.level:SetText(level..(elite and "+" or ""))
  347. frame.hp.level:Show()
  348. end
  349. frame.overlay:ClearAllPoints()
  350. frame.overlay:SetAllPoints(frame.hp)
  351. -- Aura tracking
  352. if C["nameplate"].trackdebuffs == true or C["nameplate"].trackcc == true then
  353. if frame.icons then return end
  354. frame.icons = CreateFrame("Frame",nil,frame)
  355. frame.icons:SetPoint("BOTTOMRIGHT",frame.hp,"TOPRIGHT", 0, FONTSIZE+5)
  356. frame.icons:SetWidth(20 + hpWidth)
  357. frame.icons:SetHeight(25)
  358. frame.icons:SetFrameLevel(frame.hp:GetFrameLevel()+2)
  359. frame:RegisterEvent("UNIT_AURA")
  360. frame:HookScript("OnEvent", OnAura)
  361. end
  362. HideObjects(frame)
  363. end
  364. --This is where we create most 'Static' objects for the nameplate, it gets fired when a nameplate is first seen.
  365. local function SkinObjects(frame)
  366. local oldhp, cb = frame:GetChildren()
  367. local threat, hpborder, overlay, oldname, oldlevel, bossicon, raidicon, elite = frame:GetRegions()
  368. local _, cbborder, cbshield, cbicon = cb:GetRegions()
  369. --Health Bar
  370. frame.healthOriginal = oldhp
  371. local hp = CreateFrame("Statusbar", nil, frame)
  372. hp:SetFrameLevel(oldhp:GetFrameLevel())
  373. hp:SetFrameStrata(oldhp:GetFrameStrata())
  374. hp:SetStatusBarTexture(TEXTURE)
  375. CreateVirtualFrame(hp)
  376. --Create Level
  377. hp.level = hp:CreateFontString(nil, "OVERLAY")
  378. hp.level:SetFont(FONT, FONTSIZE, FONTFLAG)
  379. hp.level:SetShadowColor(0, 0, 0, 0.4)
  380. hp.level:SetTextColor(1, 1, 1)
  381. hp.level:SetShadowOffset(T.mult, -T.mult)
  382. hp.oldlevel = oldlevel
  383. hp.boss = bossicon
  384. hp.elite = elite
  385. --Create Health Text
  386. if C["nameplate"].showhealth == true then
  387. hp.value = hp:CreateFontString(nil, "OVERLAY")
  388. hp.value:SetFont(FONT, FONTSIZE, FONTFLAG)
  389. hp.value:SetShadowColor(0, 0, 0, 0.4)
  390. hp.value:SetPoint("CENTER", 0, 1)
  391. hp.value:SetTextColor(1,1,1)
  392. hp.value:SetShadowOffset(T.mult, -T.mult)
  393. end
  394. --Create Name Text
  395. hp.name = hp:CreateFontString(nil, 'OVERLAY')
  396. hp.name:SetPoint('BOTTOMLEFT', hp, 'TOPLEFT', -10, 3)
  397. hp.name:SetPoint('BOTTOMRIGHT', hp, 'TOPRIGHT', 10, 3)
  398. hp.name:SetFont(FONT, FONTSIZE, FONTFLAG)
  399. hp.name:SetShadowColor(0, 0, 0, 0.4)
  400. hp.name:SetShadowOffset(T.mult, -T.mult)
  401. hp.oldname = oldname
  402. hp.hpbg = hp:CreateTexture(nil, 'BORDER')
  403. hp.hpbg:SetAllPoints(hp)
  404. hp.hpbg:SetTexture(1,1,1,0.25)
  405. hp:HookScript('OnShow', UpdateObjects)
  406. frame.hp = hp
  407. --Cast Bar
  408. cb:SetFrameLevel(1)
  409. cb:SetStatusBarTexture(TEXTURE)
  410. CreateVirtualFrame(cb)
  411. --Create Cast Time Text
  412. cb.time = cb:CreateFontString(nil, "ARTWORK")
  413. cb.time:SetPoint("RIGHT", cb, "LEFT", -1, 0)
  414. cb.time:SetFont(FONT, FONTSIZE, FONTFLAG)
  415. cb.time:SetShadowColor(0, 0, 0, 0.4)
  416. cb.time:SetTextColor(1, 1, 1)
  417. cb.time:SetShadowOffset(T.mult, -T.mult)
  418. --Create Cast Name Text
  419. cb.name = cb:CreateFontString(nil, "ARTWORK")
  420. cb.name:SetPoint("TOP", cb, "BOTTOM", 0, -3)
  421. cb.name:SetFont(FONT, FONTSIZE, FONTFLAG)
  422. cb.name:SetTextColor(1, 1, 1)
  423. cb.name:SetShadowColor(0, 0, 0, 0.4)
  424. cb.name:SetShadowOffset(T.mult, -T.mult)
  425. --Setup CastBar Icon
  426. cbicon:ClearAllPoints()
  427. cbicon:SetPoint("TOPLEFT", hp, "TOPRIGHT", 8, 0)
  428. cbicon:SetSize(iconSize, iconSize)
  429. cbicon:SetTexCoord(.07, .93, .07, .93)
  430. cbicon:SetDrawLayer("OVERLAY")
  431. cb.icon = cbicon
  432. CreateVirtualFrame(cb, cb.icon)
  433. cb.shield = cbshield
  434. cbshield:ClearAllPoints()
  435. cbshield:SetPoint("TOP", cb, "BOTTOM")
  436. cb:HookScript('OnShow', UpdateCastbar)
  437. cb:HookScript('OnSizeChanged', OnSizeChanged)
  438. cb:HookScript('OnValueChanged', OnValueChanged)
  439. frame.cb = cb
  440. --Highlight
  441. overlay:SetTexture(1,1,1,0.15)
  442. overlay:SetAllPoints(hp)
  443. frame.overlay = overlay
  444. --Reposition and Resize RaidIcon
  445. raidicon:ClearAllPoints()
  446. raidicon:SetPoint("BOTTOM", hp, "TOP", 0, 16)
  447. raidicon:SetSize(iconSize*1.4, iconSize*1.4)
  448. raidicon:SetTexture([[Interface\AddOns\Tukui\medias\textures\raidicons.blp]])
  449. frame.raidicon = raidicon
  450. --Hide Old Stuff
  451. QueueObject(frame, oldhp)
  452. QueueObject(frame, oldlevel)
  453. QueueObject(frame, threat)
  454. QueueObject(frame, hpborder)
  455. QueueObject(frame, cbshield)
  456. QueueObject(frame, cbborder)
  457. QueueObject(frame, oldname)
  458. QueueObject(frame, bossicon)
  459. QueueObject(frame, elite)
  460. UpdateObjects(hp)
  461. UpdateCastbar(cb)
  462. frame:HookScript('OnHide', OnHide)
  463. frames[frame] = true
  464. end
  465. --Create our blacklist for nameplates, so prevent a certain nameplate from ever showing
  466. local function CheckBlacklist(frame, ...)
  467. if T.PlateBlacklist[frame.hp.name:GetText()] then
  468. frame:SetScript("OnUpdate", function() end)
  469. frame.hp:Hide()
  470. frame.cb:Hide()
  471. frame.overlay:Hide()
  472. frame.hp.oldlevel:Hide()
  473. end
  474. end
  475. --When becoming intoxicated blizzard likes to re-show the old level text, this should fix that
  476. local function HideDrunkenText(frame, ...)
  477. if frame and frame.hp.oldlevel and frame.hp.oldlevel:IsShown() then
  478. frame.hp.oldlevel:Hide()
  479. end
  480. end
  481. --Force the name text of a nameplate to be behind other nameplates unless it is our target
  482. local function AdjustNameLevel(frame, ...)
  483. if UnitName("target") == frame.hp.name:GetText() and frame:GetAlpha() == 1 then
  484. frame.hp.name:SetDrawLayer("OVERLAY")
  485. else
  486. frame.hp.name:SetDrawLayer("BORDER")
  487. end
  488. end
  489. --Health Text, also border coloring for certain plates depending on health
  490. local function ShowHealth(frame, ...)
  491. -- show current health value
  492. local minHealth, maxHealth = frame.healthOriginal:GetMinMaxValues()
  493. local valueHealth = frame.healthOriginal:GetValue()
  494. local d =(valueHealth/maxHealth)*100
  495. if C["nameplate"].showhealth == true then
  496. frame.hp.value:SetText(T.ShortValue(valueHealth).." - "..(string.format("%d%%", math.floor((valueHealth/maxHealth)*100))))
  497. end
  498. --Setup frame shadow to change depending on enemy players health, also setup targetted unit to have white shadow
  499. if frame.hasClass == true or frame.isFriendly == true then
  500. if(d <= 50 and d >= 20) then
  501. SetVirtualBorder(frame.hp, 1, 1, 0)
  502. elseif(d < 20) then
  503. SetVirtualBorder(frame.hp, 1, 0, 0)
  504. else
  505. SetVirtualBorder(frame.hp, unpack(C["media"].bordercolor))
  506. end
  507. elseif (frame.hasClass ~= true and frame.isFriendly ~= true) and C["nameplate"].enhancethreat == true then
  508. SetVirtualBorder(frame.hp, unpack(C["media"].bordercolor))
  509. end
  510. end
  511. --Scan all visible nameplate for a known unit.
  512. local function CheckUnit_Guid(frame, ...)
  513. --local numParty, numRaid = GetNumPartyMembers(), GetNumRaidMembers()
  514. if UnitExists("target") and frame:GetAlpha() == 1 and UnitName("target") == frame.hp.name:GetText() then
  515. frame.guid = UnitGUID("target")
  516. frame.unit = "target"
  517. OnAura(frame, "target")
  518. elseif frame.overlay:IsShown() and UnitExists("mouseover") and UnitName("mouseover") == frame.hp.name:GetText() then
  519. frame.guid = UnitGUID("mouseover")
  520. frame.unit = "mouseover"
  521. OnAura(frame, "mouseover")
  522. else
  523. frame.unit = nil
  524. end
  525. end
  526. --Attempt to match a nameplate with a GUID from the combat log
  527. local function MatchGUID(frame, destGUID, spellID)
  528. if not frame.guid then return end
  529. if frame.guid == destGUID then
  530. for _,icon in ipairs(frame.icons) do
  531. if icon.spellID == spellID then
  532. icon:Hide()
  533. end
  534. end
  535. end
  536. end
  537. --Run a function for all visible nameplates, we use this for the blacklist, to check unitguid, and to hide drunken text
  538. local function ForEachPlate(functionToRun, ...)
  539. for frame in pairs(frames) do
  540. if frame:IsShown() then
  541. functionToRun(frame, ...)
  542. end
  543. end
  544. end
  545. --Check if the frames default overlay texture matches blizzards nameplates default overlay texture
  546. local select = select
  547. local function HookFrames(...)
  548. for index = 1, select('#', ...) do
  549. local frame = select(index, ...)
  550. local region = frame:GetRegions()
  551. if(not frames[frame] and (frame:GetName() and frame:GetName():find("NamePlate%d")) and region and region:GetObjectType() == 'Texture' and region:GetTexture() == OVERLAY) then
  552. SkinObjects(frame)
  553. frame.region = region
  554. end
  555. end
  556. end
  557. --Core right here, scan for any possible nameplate frames that are Children of the WorldFrame
  558. CreateFrame('Frame'):SetScript('OnUpdate', function(self, elapsed)
  559. if(WorldFrame:GetNumChildren() ~= numChildren) then
  560. numChildren = WorldFrame:GetNumChildren()
  561. HookFrames(WorldFrame:GetChildren())
  562. end
  563. if(self.elapsed and self.elapsed > 0.2) then
  564. ForEachPlate(UpdateThreat, self.elapsed)
  565. ForEachPlate(AdjustNameLevel)
  566. self.elapsed = 0
  567. else
  568. self.elapsed = (self.elapsed or 0) + elapsed
  569. end
  570. ForEachPlate(ShowHealth)
  571. ForEachPlate(CheckBlacklist)
  572. ForEachPlate(HideDrunkenText)
  573. ForEachPlate(CheckUnit_Guid)
  574. end)
  575. function NamePlates:COMBAT_LOG_EVENT_UNFILTERED(_, event, _, _, sourceName, _, destGUID, _, _, spellID)
  576. if event == "SPELL_AURA_REMOVED" then
  577. ForEachPlate(MatchGUID, destGUID, spellID)
  578. end
  579. end
  580. --Only show nameplates when in combat
  581. if C["nameplate"].combat == true then
  582. NamePlates:RegisterEvent("PLAYER_REGEN_ENABLED")
  583. NamePlates:RegisterEvent("PLAYER_REGEN_DISABLED")
  584. function NamePlates:PLAYER_REGEN_ENABLED()
  585. SetCVar("nameplateShowEnemies", 0)
  586. end
  587. function NamePlates:PLAYER_REGEN_DISABLED()
  588. SetCVar("nameplateShowEnemies", 1)
  589. end
  590. end
  591. NamePlates:RegisterEvent("PLAYER_ENTERING_WORLD")
  592. function NamePlates:PLAYER_ENTERING_WORLD()
  593. if C["nameplate"].combat == true then
  594. if InCombatLockdown() then
  595. SetCVar("nameplateShowEnemies", 1)
  596. else
  597. SetCVar("nameplateShowEnemies", 0)
  598. end
  599. end
  600. if C["nameplate"].enable == true and C["nameplate"].enhancethreat == true then
  601. SetCVar("threatWarning", 3)
  602. end
  603. SetCVar("bloatthreat", 0)
  604. SetCVar("bloattest", 0)
  605. SetCVar("bloatnameplates", 0)
  606. if T.eyefinity then
  607. SetCVar("nameplateMotion", "0")
  608. InterfaceOptionsNamesPanelUnitNameplatesMotionDropDown:Kill()
  609. end
  610. end