Advertisement
Guest User

Untitled

a guest
Oct 15th, 2011
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.67 KB | None | 0 0
  1. --[[
  2. Kui Nameplates
  3. Kesava-Auchindoun
  4. As part of Kui
  5.  
  6. TODO try to use default cast bar
  7. TODO add options to change the cast bar's uninterruptible glow/bar colour
  8. ]]
  9.  
  10. if select(1, UnitFactionGroup("player")) == "Horde" then playerFaction = 1 else playerFaction = 0 end
  11.  
  12. local exclass = {}
  13.  
  14. exclass.WARRIOR = true
  15. exclass.DEATHKNIGHT = true
  16. exclass.MAGE = true
  17. exclass.WARLOCK = true
  18. exclass.ROGUE = true
  19. exclass.HUNTER = true
  20.  
  21. local lastcheck = 0
  22. local t = CreateFrame("Frame")
  23.  
  24.  
  25. local function CheckHealers(self, elapsed)
  26. lastcheck = lastcheck + elapsed
  27. if lastcheck > 30 then
  28. lastcheck = 0
  29. heallist = { }
  30. for i = 1, GetNumBattlefieldScores() do
  31.  
  32.  
  33. local name, killingBlows, honorableKills, deaths, honorGained, faction, race, class, classToken, damageDone, healingDone, bgRating, ratingChange = GetBattlefieldScore(i);
  34.  
  35. if (healingDone > damageDone*1.2) and faction == playerFaction then
  36. name = name:match("(.+)%-.+") or name
  37. heallist[name] = classToken
  38.  
  39. end
  40. end
  41. end
  42.  
  43. end
  44.  
  45. local function checkloc(self, event)
  46. if (event == "PLAYER_ENTERING_WORLD") or (event == "PLAYER_ENTERING_BATTLEGROUND") then
  47. local isin, instype = IsInInstance()
  48. if isin and instype == "pvp" then
  49. t:SetScript("OnUpdate", CheckHealers)
  50. else
  51. heallist = {}
  52. t:SetScript("OnUpdate", nil)
  53. end
  54.  
  55. end
  56. end
  57. t:RegisterEvent("PLAYER_ENTERING_WORLD")
  58. t:RegisterEvent("PLAYER_ENTERING_BATTLEGROUND")
  59. t:SetScript("OnEvent", checkloc)
  60.  
  61.  
  62. local addon, ns = ...
  63. local np, loadedGUIDs, loadedNames, targetExists
  64. = ns.np, {}, {}
  65.  
  66. -- Custom reaction colours
  67. np.r = {
  68. { .7, .2, .1 }, -- hated
  69. { 1, .8, 0 }, -- neutral
  70. { .2, .6, .1 }, -- friendly
  71. }
  72.  
  73. -- combat log events to listen to for cast warnings/healing
  74. local castEvents = {
  75. ['SPELL_CAST_START'] = true,
  76. ['SPELL_CAST_SUCCESS'] = true,
  77. ['SPELL_INTERRUPT'] = true,
  78. ['SPELL_HEAL'] = true,
  79. ['SPELL_PERIODIC_HEAL'] = true
  80. }
  81.  
  82. ------------------------------------------------------------- Frame functions --
  83. -- set colour of health bar according to reaction/threat
  84. local function SetHealthColour(self)
  85. if self.hasThreat then
  86. self.health.reset = true
  87. self.health:SetStatusBarColor(unpack(np.kui:getSaved('tank', 'barcolour')), 1)
  88. return
  89. end
  90.  
  91. local r, g, b = self.oldHealth:GetStatusBarColor()
  92. if self.health.reset or
  93. r ~= self.health.r or
  94. g ~= self.health.g or
  95. b ~= self.health.b
  96. then
  97. -- store the default colour
  98. self.health.r, self.health.g, self.health.b = r, g, b
  99. self.health.reset, self.friend = nil, nil
  100.  
  101. if g > .9 and r == 0 and b == 0 then
  102. -- friendly NPC
  103. self.friend = true
  104. r, g, b = unpack(np.r[3])
  105. elseif b > .9 and r == 0 and g == 0 then
  106. -- friendly player
  107. self.friend = true
  108. r, g, b = 0, .3, .6
  109. elseif r > .9 and g == 0 and b == 0 then
  110. -- enemy NPC
  111. r, g, b = unpack(np.r[1])
  112. elseif (r + g) > 1.8 and b == 0 then
  113. -- neutral NPC
  114. r, g, b = unpack(np.r[2])
  115. end
  116. -- enemy player, use default UI colour
  117.  
  118. self.health:SetStatusBarColor(r, g, b)
  119. end
  120. end
  121.  
  122. local function SetGlowColour(self, r, g, b, a)
  123. if not r then
  124. -- set default colour
  125. r, g, b = 0, 0, 0
  126. end
  127.  
  128. if not a then
  129. a = .85
  130. end
  131.  
  132. self.bg:SetVertexColor(r, g, b, a)
  133. end
  134.  
  135. local function SetCastWarning(self, spellName, spellSchool)
  136. self.castWarning.ag:Stop()
  137.  
  138. if spellName == nil then
  139. -- hide the warning instantly when interrupted
  140. self.castWarning:SetAlpha(0)
  141. else
  142. local col = COMBATLOG_DEFAULT_COLORS.schoolColoring[spellSchool] or
  143. {r = 1, g = 1, b = 1}
  144.  
  145. self.castWarning:SetText(spellName)
  146. self.castWarning:SetTextColor(col.r, col.g, col.b)
  147. self.castWarning:SetAlpha(1)
  148.  
  149. self.castWarning.ag:Play()
  150. end
  151. end
  152.  
  153. local function SetIncomingWarning(self, amount)
  154. if amount == 0 then return end
  155. self.incWarning.ag:Stop()
  156.  
  157. if amount > 0 then
  158. -- healing
  159. amount = '+'..amount
  160. self.incWarning:SetTextColor(0, 1, 0)
  161. else
  162. -- damage (nyi)
  163. self.incWarning:SetTextColor(1, 0, 0)
  164. end
  165.  
  166. self.incWarning:SetText(amount)
  167.  
  168. self.incWarning:SetAlpha(1)
  169. self.incWarning.ag.fade:SetEndDelay(.5)
  170.  
  171. self.incWarning.ag:Play()
  172. end
  173.  
  174. -- Show the frame's castbar if it is casting
  175. -- TODO update this for other units (party1target etc)
  176. local function IsFrameCasting(self)
  177. if not self.castbar or not self.target then return end
  178.  
  179. local name = UnitCastingInfo('target')
  180. local channel = false
  181.  
  182. if not name then
  183. name = UnitChannelInfo('target')
  184. channel = true
  185. end
  186.  
  187. if name then
  188. -- if they're casting or channeling, try to show a castbar
  189. np.UNIT_SPELLCAST_START(self, 'target', channel)
  190. end
  191. end
  192.  
  193. local function StoreFrameGUID(self, guid)
  194. if not guid then return end
  195. if self.guid and loadedGUIDs[self.guid] then
  196. if self.guid ~= guid then
  197. -- the currently stored guid is incorrect
  198. loadedGUIDs[self.guid] = nil
  199. else
  200. return
  201. end
  202. end
  203.  
  204. self.guid = guid
  205. loadedGUIDs[guid] = self
  206.  
  207. if loadedNames[self.name.text] == self then
  208. loadedNames[self.name.text] = nil
  209. end
  210. end
  211.  
  212. --------------------------------------------------------- Update combo points --
  213. local function ComboPointsUpdate(self)
  214. if self.points and self.points > 0 then
  215. local size = (13 + ((18 - 13) / 5) * self.points)
  216. local blue = (1 - (1 / 5) * self.points)
  217.  
  218. self:SetText(self.points)
  219. self:SetFont("Fonts\\ARIALN.TTF", size, 'OUTLINE')
  220. self:SetTextColor(1, 1, blue)
  221. elseif self:GetText() then
  222. self:SetText('')
  223. end
  224. end
  225.  
  226. ----------------------------------------------------- Castbar script handlers --
  227. local function OnCastbarUpdate(bar, elapsed)
  228. if bar.channel then
  229. bar.progress = bar.progress - elapsed
  230. else
  231. bar.progress = bar.progress + elapsed
  232. end
  233.  
  234. if not bar.duration or
  235. ((not bar.channel and bar.progress >= bar.duration) or
  236. (bar.channel and bar.progress <= 0))
  237. then
  238. -- hide the castbar bg
  239. bar:GetParent():Hide()
  240. bar.progress = 0
  241. return
  242. end
  243.  
  244. -- display progress
  245. if bar.max then
  246. bar.curr:SetText(string.format("%.1f", bar.progress))
  247.  
  248. if bar.delay == 0 or not bar.delay then
  249. bar.max:SetText(string.format("%.1f", bar.duration))
  250. else
  251. -- display delay
  252. if bar.channel then
  253. -- time is removed
  254. bar.max:SetText(string.format("%.1f", bar.duration)..
  255. '|cffff0000-'..string.format("%.1f", bar.delay)..'|r')
  256. else
  257. -- time is added
  258. bar.max:SetText(string.format("%.1f", bar.duration)..
  259. '|cffff0000+'..string.format("%.1f", bar.delay)..'|r')
  260. end
  261. end
  262. end
  263.  
  264. bar:SetValue(bar.progress/bar.duration)
  265. end
  266.  
  267. ---------------------------------------------------- Update health bar & text --
  268. -- TODO: holy memory usage batman
  269. local function OnHealthValueChanged(oldBar, curr)
  270. local frame = oldBar:GetParent()
  271. local min, max = oldBar:GetMinMaxValues()
  272. local deficit, isHpMax = max - curr, curr == max
  273. local canShowPrecise, big, sml
  274.  
  275. frame.health:SetMinMaxValues(min, max)
  276. frame.health:SetValue(curr)
  277.  
  278. -- display conditions
  279. if np.kui:getSaved('hp', 'precise') then
  280. canShowPrecise = frame.friend
  281. else
  282. canShowPrecise = true
  283. end
  284.  
  285. local canShowDeficit, canShowMax =
  286. canShowPrecise and not isHpMax,
  287. canShowPrecise and isHpMax
  288.  
  289. if np.kui:getSaved('hp', 'deficit') and canShowDeficit then
  290. big = "-" .. kui.num(deficit)
  291. sml = kui.num(curr)
  292. elseif np.kui:getSaved('hp', 'max') and canShowMax then
  293. big = kui.num(max)
  294. sml = ''
  295. elseif np.kui:getSaved('hp', 'current') and canShowDeficit then
  296. big = kui.num(curr)
  297. sml = kui.num(max)
  298. elseif np.kui:getSaved('hp', 'percent') and not isHpMax then
  299. big = floor(curr / max * 100)
  300. sml = kui.num(curr)
  301. else
  302. big = ''
  303. sml = ''
  304. end
  305.  
  306. frame.health.p:SetText(big and big or '')
  307.  
  308. if frame.health.mo then
  309. frame.health.mo:SetText(sml and sml or '')
  310. end
  311. end
  312.  
  313. ------------------------------------------------------- Frame script handlers --
  314. local function OnFrameShow(self)
  315.  
  316.  
  317. -- reset name
  318. self.name.text = self.oldName:GetText()
  319. self.name:SetText(self.name.text)
  320.  
  321.  
  322.  
  323. if (heallist[self.name.text]) then
  324. if exclass[heallist[self.name.text]] then
  325. self.HPHeal:Hide()
  326. else
  327. self.HPHeal:Show()
  328. end
  329. else
  330. self.HPHeal:Hide()
  331. end
  332.  
  333. if np.kui:getSaved('hp', 'mouseover') then
  334. -- force run un-highlight code
  335. self.highlighted = true
  336. end
  337.  
  338. -- classifications
  339. if self.boss:IsVisible() then
  340. self.level:SetText(" ")
  341. self.level:SetTextColor(1, 0, 0)
  342. self.level:Show()
  343. elseif self.state:IsVisible() then
  344. if self.state:GetTexture() == "Interface\\Tooltips\\EliteNameplateIcon"
  345. then
  346. self.level:SetText(self.level:GetText())
  347. else
  348. self.level:SetText(self.level:GetText())
  349. end
  350. end
  351.  
  352. if self.state:IsVisible() then
  353. -- hide the elite/rare dragon
  354. self.state:Hide()
  355. end
  356.  
  357. if np.kui:getSaved('cast', 'usenames') and
  358. not loadedNames[self.name.text] and
  359. not self.guid
  360. then
  361. -- store this frame's name
  362. loadedNames[self.name.text] = self
  363. end
  364.  
  365. self:UpdateFrame()
  366. self:UpdateFrameCritical()
  367. self:SetGlowColour()
  368. self:IsCasting()
  369. end
  370.  
  371. local function OnFrameHide(self)
  372. if self.guid then
  373. -- remove guid from the store and unset it
  374. loadedGUIDs[self.guid] = nil
  375. self.guid = nil
  376.  
  377. if self.cp then
  378. self.cp.points = nil
  379. self.cp:Update()
  380. end
  381. end
  382.  
  383. if loadedNames[self.name.text] == self then
  384. -- remove name from store
  385. -- if there are name duplicates, this will be recreated in an onupdate
  386. loadedNames[self.name.text] = nil
  387. end
  388.  
  389. self.lastAlpha = 0
  390. self.fadingTo = nil
  391. self.hasThreat = nil
  392. self.target = nil
  393.  
  394. -- unset stored health bar colours
  395. self.health.r, self.health.g, self.health.b, self.health.reset
  396. = nil, nil, nil, nil
  397.  
  398. if self.castbar then
  399. -- reset cast bar
  400. self.castbar.duration = nil
  401. self.castbar.id = nil
  402. self.castbarbg:Hide()
  403. end
  404.  
  405. if self.castWarning then
  406. -- reset cast warning
  407. self.castWarning:SetText()
  408. self.castWarning.ag:Stop()
  409. self.incWarning:SetText()
  410. end
  411. end
  412.  
  413. local function OnFrameEnter(self)
  414. if self.highlight then
  415. self.highlight:Show()
  416. end
  417.  
  418. self:StoreGUID(UnitGUID('mouseover'))
  419.  
  420. if np.kui:getSaved('hp', 'mouseover') then
  421. self.health.p:Show()
  422. if self.health.mo then self.health.mo:Show() end
  423. end
  424. end
  425.  
  426. local function OnFrameLeave(self)
  427. if self.highlight then
  428. self.highlight:Hide()
  429. end
  430.  
  431. if not self.target and np.kui:getSaved('hp', 'mouseover') then
  432. self.health.p:Hide()
  433. if self.health.mo then self.health.mo:Hide() end
  434. end
  435. end
  436.  
  437. local function OnFrameUpdate(self, e)
  438.  
  439. self.elapsed = self.elapsed + e
  440. self.critElap = self.critElap + e
  441.  
  442. self.defaultAlpha = self:GetAlpha()
  443. ------------------------------------------------------------------- Alpha --
  444. if self.currentAlpha and self.defaultAlpha ~= self.currentAlpha then
  445. -- ignore default UI's alpha changes
  446. self:SetAlpha(self.currentAlpha)
  447. end
  448.  
  449. if ( self.defaultAlpha == 1 and
  450. targetExists) or
  451. ( np.kui:getSaved('gen', 'fademouse') and
  452. self.highlighted)
  453. then
  454. self.currentAlpha = 1
  455. elseif targetExists or np.kui:getSaved('gen', 'fadeall') then
  456. self.currentAlpha = np.kui:getSaved('gen', 'fadedalpha') or .6
  457. else
  458. self.currentAlpha = 1
  459. end
  460.  
  461. ------------------------------------------------------------------ Fading --
  462. if np.kui:getSaved('gen', 'fade') then
  463. -- track changes in the alpha level and intercept them
  464. if self.currentAlpha ~= self.lastAlpha then
  465. if not self.fadingTo or self.fadingTo ~= self.currentAlpha then
  466. if kui.frameIsFading(self) then
  467. kui.frameFadeRemoveFrame(self)
  468. end
  469.  
  470. -- fade to the new value
  471. self.fadingTo = self.currentAlpha
  472. local alphaChange = (self.fadingTo - (self.lastAlpha or 0))
  473.  
  474. kui.frameFade(self, {
  475. mode = alphaChange < 0 and 'OUT' or 'IN',
  476. timeToFade = abs(alphaChange),
  477. startAlpha = self.lastAlpha or 0,
  478. endAlpha = self.fadingTo,
  479. finishedFunc = function()
  480. self.fadingTo = nil
  481. end,
  482. })
  483. end
  484.  
  485. self.lastAlpha = self.currentAlpha
  486. end
  487. end
  488.  
  489. -- call delayed updates
  490. if self.elapsed > 1 then
  491. self.elapsed = 0
  492. self:UpdateFrame()
  493. end
  494.  
  495. if self.critElap > .1 then
  496. self.critElap = 0
  497. self:UpdateFrameCritical()
  498. end
  499. end
  500.  
  501. -- stuff that can be updated less often
  502. local function UpdateFrame(self)
  503. if np.kui:getSaved('cast', 'usenames') and
  504. not loadedNames[self.name.text] and
  505. not self.guid
  506. then
  507. -- ensure a frame is still stored for this name, as name conflicts cause
  508. -- it to be erased when another might still exist
  509. -- also ensure that if this frame is targeted, this is the stored frame
  510. -- for its name
  511. loadedNames[self.name.text] = self
  512. end
  513.  
  514. -- Health bar colour
  515. self:SetHealthColour()
  516.  
  517. -- force health update (as self.friend is managed by SetHealthColour)
  518. OnHealthValueChanged(self.oldHealth, self.oldHealth:GetValue())
  519.  
  520. if self.cp then
  521. -- combo points
  522. self.cp:Update()
  523. end
  524. end
  525.  
  526. -- stuff that needs to be updated often
  527. local function UpdateFrameCritical(self)
  528. ------------------------------------------------------------------ Threat --
  529. if self.glow:IsVisible() then
  530. self.glow.wasVisible = true
  531.  
  532. self.glow.r, self.glow.g, self.glow.b = self.glow:GetVertexColor()
  533. self:SetGlowColour(self.glow.r, self.glow.g, self.glow.b)
  534.  
  535. if not self.friend and np.kui:getSaved('tank', 'toggle') then
  536. -- in tank mode; is the default glow is red (are we tanking)?
  537. self.hasThreat = (self.glow.g + self.glow.b) < .1
  538.  
  539. if self.hasThreat then
  540. -- tanking; recolour bar & glow
  541. local r, g, b = unpack(np.kui:getSaved('tank', 'glowcolour'))
  542. self:SetGlowColour(r, g, b)
  543. self:SetHealthColour()
  544. end
  545. end
  546. elseif self.glow.wasVisible then
  547. self.glow.wasVisible = nil
  548.  
  549. -- restore shadow glow colour
  550. self:SetGlowColour()
  551.  
  552. if self.hasThreat then
  553. -- lost threat
  554. self.hasThreat = nil
  555. self:SetHealthColour()
  556. end
  557. end
  558. ------------------------------------------------------------ Target stuff --
  559. if targetExists and
  560. self.defaultAlpha == 1 and
  561. self.name.text == UnitName('target')
  562. then
  563. -- this frame is targetted
  564. if not self.target then
  565. -- the frame just became targetted
  566. self.target = true
  567. self:StoreGUID(UnitGUID('target'))
  568.  
  569. if np.kui:getSaved('hp', 'mouseover') then
  570. self.health.p:Show()
  571. if self.health.mo then self.health.mo:Show() end
  572. end
  573.  
  574. -- check if the frame is casting
  575. self:IsCasting()
  576. end
  577. elseif self.target then
  578. self.target = nil
  579.  
  580. if not self.highlighted and np.kui:getSaved('hp', 'mouseover') then
  581. self.health.p:Hide()
  582. if self.health.mo then self.health.mo:Hide() end
  583. end
  584. end
  585. --------------------------------------------------------------- Mouseover --
  586. if self.oldHighlight:IsShown() then
  587. if not self.highlighted then
  588. self.highlighted = true
  589. OnFrameEnter(self)
  590. end
  591. elseif self.highlighted then
  592. self.highlighted = false
  593. OnFrameLeave(self)
  594. end
  595.  
  596. -- [debug]
  597. --[[
  598. if self.guid and loadedGUIDs[self.guid] == self then
  599. self.guidtext:SetText(self.guid)
  600. else
  601. self.guidtext:SetText(nil)
  602. end
  603.  
  604. if self.name.text and loadedNames[self.name.text] == self then
  605. self.nametext:SetText('Has name')
  606. else
  607. self.nametext:SetText(nil)
  608. end
  609. ]]
  610. end
  611.  
  612. --------------------------------------------------------------- KNP functions --
  613. function np:GetNameplate(guid, name)
  614. local gf, nf = loadedGUIDs[guid], loadedNames[name]
  615.  
  616. if gf then
  617. return gf
  618. elseif nf then
  619. return nf
  620. else
  621. return nil
  622. end
  623. end
  624.  
  625. function np:IsNameplate(frame)
  626. if frame:GetName() and not string.find(frame:GetName(), "^NamePlate") then
  627. return false
  628. end
  629.  
  630. local overlayRegion = select(2, frame:GetRegions())
  631. return (overlayRegion and
  632. overlayRegion:GetObjectType() == "Texture" and
  633. overlayRegion:GetTexture() == "Interface\\Tooltips\\Nameplate-Border")
  634. end
  635.  
  636. function np:InitFrame(frame)
  637. -- TODO: this is just a tad long
  638. frame.init = true
  639.  
  640. local healthBar, castBar = frame:GetChildren()
  641. local _, castbarOverlay, shieldedRegion, spellIconRegion
  642. = castBar:GetRegions()
  643.  
  644. local
  645. glowRegion, overlayRegion, highlightRegion, nameTextRegion,
  646. levelTextRegion, bossIconRegion, raidIconRegion, stateIconRegion
  647. = frame:GetRegions()
  648.  
  649. highlightRegion:SetTexture(nil)
  650. shieldedRegion:SetTexture(nil)
  651. castbarOverlay:SetTexture(nil)
  652. glowRegion:SetTexture(nil)
  653.  
  654. -- disable default cast bar
  655. castBar:SetParent(nil)
  656. castbarOverlay.Show = function() return end
  657. castBar:SetScript('OnShow', function() castBar:Hide() end)
  658.  
  659. frame.bg = overlayRegion
  660. frame.glow = glowRegion
  661. frame.boss = bossIconRegion
  662. frame.state = stateIconRegion
  663. frame.level = levelTextRegion
  664. frame.ricon = raidIconRegion
  665.  
  666. if np.kui:getSaved('cast', 'spellicon') then
  667. frame.spell = spellIconRegion
  668. end
  669.  
  670. frame.oldHealth = healthBar
  671. frame.oldHealth:Hide()
  672.  
  673. frame.oldName = nameTextRegion
  674. frame.oldName:Hide()
  675.  
  676. frame.oldHighlight = highlightRegion
  677.  
  678. ---------------------------------------------------------- Frame functions--
  679. frame.UpdateFrame = UpdateFrame
  680. frame.UpdateFrameCritical = UpdateFrameCritical
  681. frame.SetHealthColour = SetHealthColour
  682. frame.SetGlowColour = SetGlowColour
  683. frame.IsCasting = IsFrameCasting
  684. frame.StoreGUID = StoreFrameGUID
  685.  
  686.  
  687. ------------------------------------------------------------------ Layout --
  688. -- boss icon ---------------------------------------------------------------
  689.  
  690. frame.boss:SetWidth(10)
  691. frame.boss:SetHeight(10)
  692.  
  693. -- health bar --------------------------------------------------------------
  694. -- size & point are set OnFrameShow
  695. frame.health = CreateFrame('StatusBar', nil, frame)
  696. frame.health:SetStatusBarTexture(kui.m.t.bar)
  697.  
  698. frame.health:SetWidth(100)
  699. frame.health:SetHeight(5)
  700.  
  701. frame.health:ClearAllPoints()
  702. frame.health:SetPoint("CENTER")
  703.  
  704. -- so i suppose I have to make sure it's in front of itself
  705. frame.health:SetFrameLevel(frame:GetFrameLevel()+1)
  706.  
  707. -- frame background --------------------------------------------------------
  708. -- this also provides the shadow & threat glow
  709. frame.bg:SetTexture('Interface\\AddOns\\Kui_Nameplates\\FrameGlow')
  710. frame.bg:SetTexCoord(0, .5625, 0, 0)
  711. frame.bg:SetVertexColor(0, 0, 0, .85)
  712.  
  713. frame.bg:SetPoint('TOPLEFT', frame.health, -7, 7)
  714. frame.bg:SetPoint('BOTTOMRIGHT', frame.health, 7, -7)
  715. ------------------------------------------------------------------- Raidicon --
  716.  
  717.  
  718. frame.ricon:SetPoint("TOPRIGHT", frame.health, "TOPLEFT", 63, 60)
  719.  
  720.  
  721. -- health background -------------------------------------------------------
  722. frame.health.bg = frame:CreateTexture(nil, 'ARTWORK')
  723. frame.health.bg:SetDrawLayer('ARTWORK', 1) -- (1 sub-layer above .bg)
  724. frame.health.bg:SetTexture(kui.m.t.solid)
  725. frame.health.bg:SetVertexColor(0, 0, 0, .70)
  726. frame.health.bg:SetPoint('TOPLEFT', frame.health, 0, 13) -- <<<<<<<< HÖHE DES HINTERGRUNDES !!
  727. frame.health.bg:SetPoint('BOTTOMRIGHT', frame.health, 0, 0)
  728.  
  729. -- overlay (text is parented to this) --------------------------------------
  730. frame.overlay = CreateFrame('Frame', nil, frame)
  731. frame.overlay:SetAllPoints(frame.health)
  732.  
  733. frame.overlay:SetFrameLevel(frame.health:GetFrameLevel()+1)
  734.  
  735. -- highlight ---------------------------------------------------------------
  736. if np.kui:getSaved('gen', 'highlight') then
  737. frame.highlight = frame.overlay:CreateTexture(nil, 'ARTWORK')
  738. frame.highlight:SetTexture(kui.m.t.innerShade)
  739.  
  740. frame.highlight:SetAllPoints(frame.health.bg)
  741.  
  742. frame.highlight:SetVertexColor(1, 1, 0)
  743. frame.highlight:SetAlpha(.2)
  744. frame.highlight:Hide()
  745. end
  746.  
  747. -- health text -------------------------------------------------------------
  748. frame.health.p = kui.CreateFontString(frame.overlay, {
  749. font = "Fonts\\ARIALN.TTF", size = 7, outline = "NIL" })
  750.  
  751. --frame.health.p:SetJustifyH('CENTER')
  752. frame.health.p:SetPoint('BOTTOMRIGHT', frame.health, 0, 0)
  753.  
  754. if np.kui:getSaved('hp', 'showalt') then
  755. frame.health.mo = kui.CreateFontString(frame.overlay, {
  756. font = "Fonts\\ARIALN.TTF", size = 8, outline = "NIL" })
  757. -- frame.health.mo:SetJustifyH('CENTER')
  758.  
  759. -- frame.health.mo:SetPoint('BOTTOMRIGHT', frame.health, -2, -2)
  760. -- frame.health.mo:SetAlpha(.5)
  761. end
  762.  
  763. -- level text --------------------------------------------------------------
  764. frame.level = kui.CreateFontString(frame.level, { reset = true,
  765. font = "Fonts\\ARIALN.TTF", size = 9, outline = 'NIL' })
  766. frame.level:SetParent(frame.overlay)
  767.  
  768. frame.level:ClearAllPoints()
  769. frame.level:SetPoint('BOTTOMLEFT', frame.health, 'TOPLEFT', 2, 2)
  770.  
  771. -- name text ---------------------------------------------------------------
  772. frame.name = kui.CreateFontString(frame.overlay, {
  773. font = "Fonts\\ARIALN.TTF", size = 9, outline = 'NIL' })
  774. frame.name:SetJustifyH('LEFT')
  775.  
  776. frame.name:SetHeight(8)
  777.  
  778. frame.name:SetPoint('LEFT', frame.level, 'RIGHT', 1, 0) -- << HÖHE DER SCHRIFT FÜR NAME , x
  779. frame.name:SetPoint('RIGHT', frame.health.p, 'LEFT')
  780.  
  781. -- combo point text --------------------------------------------------------
  782. if np.kui:getSaved('gen', 'combopoints') then
  783. frame.cp = kui.CreateFontString(frame.health,
  784. { font = "Fonts\\ARIALN.TTF", size = 13, outline = 'OUTLINE', shadow = true })
  785. frame.cp:SetPoint('LEFT', frame.health, 'RIGHT', 5, 1)
  786.  
  787. frame.cp.Update = ComboPointsUpdate
  788. end
  789.  
  790.  
  791. -- healer icon ----------------------------------------------------------------
  792.  
  793.  
  794. frame.HPHeal = frame:CreateTexture(nil, 'BACKGROUND')
  795. frame.HPHeal:SetHeight(40)
  796. frame.HPHeal:SetWidth(40)
  797. frame.HPHeal:SetPoint("BOTTOM", frame.health.bg, "TOP", 0, 10)
  798. frame.HPHeal:SetTexture("Interface\\LFGFrame\\UI-LFG-ICON-RoleS")
  799. frame.HPHeal:SetTexCoord(GetTexCoordsForRole("HEALER"))
  800. frame.HPHeal:Hide()
  801.  
  802.  
  803. if np.kui:getSaved('cast', 'toggle') then
  804. -- TODO move this (and similar things) into functions
  805. -- cast bar background -------------------------------------------------
  806. frame.castbarbg = CreateFrame("Frame", nil, frame)
  807. frame.castbarbg:SetFrameStrata('BACKGROUND');
  808. frame.castbarbg:SetBackdrop({
  809. bgFile = kui.m.t.solid, edgeFile = kui.m.t.shadow,
  810. edgeSize = 5, insets = {
  811. top = 5, left = 5, bottom = 5, right = 5
  812. }
  813. })
  814.  
  815. frame.castbarbg:SetBackdropColor(0, 0, 0, .85)
  816. frame.castbarbg:SetBackdropBorderColor(1, .2, .1, 0)
  817. frame.castbarbg:SetHeight(15)
  818.  
  819. frame.castbarbg:SetPoint('TOPLEFT', frame.health.bg, 'BOTTOMLEFT', -5, 4)
  820. frame.castbarbg:SetPoint('TOPRIGHT', frame.health.bg, 'BOTTOMRIGHT', 5, 0)
  821.  
  822. frame.castbarbg:Hide()
  823.  
  824. -- cast bar ------------------------------------------------------------
  825. frame.castbar = CreateFrame("StatusBar", nil, frame.castbarbg)
  826. frame.castbar:SetStatusBarTexture(kui.m.t.bar)
  827.  
  828. frame.castbar:SetPoint('TOPLEFT', frame.castbarbg, 'TOPLEFT', 6, -6)
  829. frame.castbar:SetPoint('BOTTOMLEFT', frame.castbarbg, 'BOTTOMLEFT', 6, 6)
  830. frame.castbar:SetPoint('RIGHT', frame.castbarbg, 'RIGHT', -6, 0)
  831.  
  832. frame.castbar:SetMinMaxValues(0, 1)
  833.  
  834. -- cast bar text -------------------------------------------------------
  835. if np.kui:getSaved('cast', 'spellname') then
  836. frame.castbar.name = kui.CreateFontString(frame.castbar, {
  837. font = "Fonts\\ARIALN.TTF", size = 9, outline = "OUTLINE" })
  838. frame.castbar.name:SetPoint('TOPLEFT', frame.castbar, 'BOTTOMLEFT', 2, -1)
  839. end
  840.  
  841. if np.kui:getSaved('cast', 'casttime') then
  842. frame.castbar.max = kui.CreateFontString(frame.castbar, {
  843. font = "Fonts\\ARIALN.TTF", size = 9, outline = "OUTLINE" })
  844. frame.castbar.max:SetPoint('TOPRIGHT', frame.castbar, 'BOTTOMRIGHT', -2, -1)
  845.  
  846. frame.castbar.curr = kui.CreateFontString(frame.castbar, {
  847. font = "Fonts\\ARIALN.TTF", size = 8, outline = "OUTLINE" })
  848. frame.castbar.curr:SetAlpha(.5)
  849. frame.castbar.curr:SetPoint('TOPRIGHT', frame.castbar.max, 'TOPLEFT', -1, -1)
  850. end
  851.  
  852. if frame.spell then
  853. -- cast bar icon background ----------------------------------------
  854. frame.spellbg = frame.castbarbg:CreateTexture(nil, 'BACKGROUND')
  855. frame.spellbg:SetTexture(kui.m.t.solid)
  856. frame.spellbg:SetSize(18, 18)
  857.  
  858. frame.spellbg:SetVertexColor(0, 0, 0, .85)
  859.  
  860. frame.spellbg:SetPoint('TOPRIGHT', frame.health.bg, 'TOPLEFT', -1, 0)
  861.  
  862. -- cast bar icon ---------------------------------------------------
  863. frame.spell:ClearAllPoints()
  864. frame.spell:SetParent(frame.castbarbg)
  865. frame.spell:SetSize(16, 16)
  866.  
  867. frame.spell:SetPoint('TOPRIGHT', frame.spellbg, -1, -1)
  868.  
  869. frame.spell:SetTexCoord(.1, .9, .1, .9)
  870. end
  871.  
  872. -- scripts -------------------------------------------------------------
  873. frame.castbar:HookScript('OnShow', function(bar)
  874. if bar.interruptible then
  875. bar:SetStatusBarColor(unpack(np.kui:getSaved('cast', 'barcolour')))
  876. bar:GetParent():SetBackdropBorderColor(0, 0, 0, .3)
  877. else
  878. bar:SetStatusBarColor(.8, .1, .1)
  879. bar:GetParent():SetBackdropBorderColor(1, .1, .2, .5)
  880. end
  881. end)
  882.  
  883. frame.castbar:SetScript('OnUpdate', OnCastbarUpdate)
  884. end
  885.  
  886. -- cast warning ------------------------------------------------------------
  887. if np.kui:getSaved('cast', 'warnings') then
  888. -- casting spell name
  889. frame.castWarning = kui.CreateFontString(frame.overlay, {
  890. font = "Fonts\\ARIALN.TTF", size = 10, outline = 'OUTLINE' })
  891. frame.castWarning:SetPoint('BOTTOMLEFT', frame.level, 'TOPLEFT', 0, 1)
  892. frame.castWarning:Hide()
  893.  
  894. frame.castWarning.ag = frame.castWarning:CreateAnimationGroup()
  895. frame.castWarning.fade = frame.castWarning.ag:CreateAnimation('Alpha')
  896. frame.castWarning.fade:SetSmoothing('IN')
  897. frame.castWarning.fade:SetDuration(2)
  898. frame.castWarning.fade:SetChange(-1)
  899.  
  900. frame.castWarning.ag:SetScript('OnPlay', function(self)
  901. self:GetParent():Show()
  902. end)
  903.  
  904. frame.castWarning.ag:SetScript('OnFinished', function(self)
  905. self:GetParent():Hide()
  906. end)
  907.  
  908. -- incoming healing
  909. frame.incWarning = kui.CreateFontString(frame.overlay, {
  910. font = "Fonts\\ARIALN.TTF", size = 8, outline = 'OUTLINE' })
  911. frame.incWarning:SetPoint('BOTTOMRIGHT', frame.health.p, 'TOPRIGHT', 1)
  912. frame.incWarning:Hide()
  913.  
  914. frame.incWarning.ag = frame.incWarning:CreateAnimationGroup()
  915. frame.incWarning.ag.fade = frame.incWarning.ag:CreateAnimation('Alpha')
  916. frame.incWarning.ag.fade:SetSmoothing('IN')
  917. frame.incWarning.ag.fade:SetDuration(.5)
  918. frame.incWarning.ag.fade:SetChange(-.5)
  919.  
  920. frame.incWarning.ag:SetScript('OnPlay', function(self)
  921. self:GetParent():Show()
  922. end)
  923.  
  924. frame.incWarning.ag:SetScript('OnFinished', function(self)
  925. if self.fade:GetEndDelay() > 0 then
  926. -- fade out fully
  927. self:GetParent():SetAlpha(.5)
  928. self.fade:SetEndDelay(0)
  929. self:Play()
  930. else
  931. self:GetParent():Hide()
  932. end
  933. end)
  934.  
  935. -- handlers
  936. frame.SetCastWarning = SetCastWarning
  937. frame.SetIncomingWarning = SetIncomingWarning
  938. end
  939.  
  940. ----------------------------------------------------------------- Scripts --
  941. frame:SetScript('OnShow', OnFrameShow)
  942. frame:SetScript('OnHide', OnFrameHide)
  943. frame:SetScript('OnUpdate', OnFrameUpdate)
  944.  
  945. frame.oldHealth:SetScript('OnValueChanged', OnHealthValueChanged)
  946.  
  947. -- [debug]
  948. --[[
  949. frame:SetBackdrop({bgFile=kui.m.t.solid})
  950. frame:SetBackdropColor(1, 1, 1, .5)
  951.  
  952. frame.guidtext = kui.CreateFontString(frame, {
  953. font = kui.m.f.yanone, size = 10, outline = "OUTLINE" })
  954. frame.guidtext:SetPoint('TOP', frame, 'BOTTOM')
  955.  
  956. frame.nametext = kui.CreateFontString(frame, {
  957. font = kui.m.f.yanone, size = 10, outline = "OUTLINE" })
  958. frame.nametext:SetPoint('TOP', frame.guidtext, 'BOTTOM')
  959. ]]
  960.  
  961. ------------------------------------------------------------ Finishing up --
  962. frame.elapsed = 0
  963. frame.critElap = 0
  964.  
  965. -- force OnShow
  966. OnFrameShow(frame)
  967. end
  968.  
  969. ---------------------------------------------------------------------- Events --
  970. function np:UNIT_COMBO_POINTS()
  971. local target = UnitGUID('target')
  972. if not target or not loadedGUIDs[target] then return end
  973. target = loadedGUIDs[target]
  974.  
  975. if target.cp then
  976. target.cp.points = GetComboPoints('player', 'target')
  977. target.cp:Update()
  978. end
  979.  
  980. -- clear points on other frames
  981. for guid, frame in pairs(loadedGUIDs) do
  982. if frame.cp and guid ~= target.guid then
  983. frame.cp.points = nil
  984. frame.cp:Update()
  985. end
  986. end
  987. end
  988.  
  989. function np:PLAYER_TARGET_CHANGED()
  990. targetExists = UnitExists('target')
  991. end
  992.  
  993. -- automatic toggling of enemy frames
  994. function np:PLAYER_REGEN_ENABLED()
  995. SetCVar('nameplateShowEnemies', 0)
  996. end
  997. function np:PLAYER_REGEN_DISABLED()
  998. SetCVar('nameplateShowEnemies', 1)
  999. end
  1000.  
  1001. -- custom cast bar events ------------------------------------------------------
  1002. function np.UNIT_SPELLCAST_START(frame, unit, channel)
  1003. local cb = frame.castbar
  1004. local
  1005. name, _, text, texture, startTime, endTime, _, castID,
  1006. notInterruptible
  1007.  
  1008. if channel then
  1009. name, _, text, texture, startTime, endTime, _, castID, notInterruptible
  1010. = UnitChannelInfo(unit)
  1011. else
  1012. name, _, text, texture, startTime, endTime, _, castID, notInterruptible
  1013. = UnitCastingInfo(unit)
  1014. end
  1015.  
  1016. if not name then
  1017. frame.castbarbg:Hide()
  1018. return
  1019. end
  1020.  
  1021. cb.id = castID
  1022. cb.channel = channel
  1023. cb.interruptible = not notInterruptible
  1024. cb.duration = (endTime/1000) - (startTime/1000)
  1025. cb.delay = 0
  1026.  
  1027. if frame.spell then
  1028. frame.spell:SetTexture(texture)
  1029. end
  1030.  
  1031. if cb.name then
  1032. cb.name:SetText(name)
  1033. end
  1034.  
  1035. if cb.channel then
  1036. cb.progress = (endTime/1000) - GetTime()
  1037. else
  1038. cb.progress = GetTime() - (startTime/1000)
  1039. end
  1040.  
  1041. frame.castbarbg:Show()
  1042. end
  1043.  
  1044. function np.UNIT_SPELLCAST_DELAYED(frame, unit, channel)
  1045. local cb = frame.castbar
  1046. local _, name, startTime, endTime
  1047.  
  1048. if channel then
  1049. name, _, _, _, startTime, endTime = UnitChannelInfo(unit)
  1050. else
  1051. name, _, _, _, startTime, endTime = UnitCastingInfo(unit)
  1052. end
  1053.  
  1054. if not name then
  1055. return
  1056. end
  1057.  
  1058. local newProgress
  1059. if cb.channel then
  1060. newProgress = (endTime/1000) - GetTime()
  1061. else
  1062. newProgress = GetTime() - (startTime/1000)
  1063. end
  1064.  
  1065. cb.delay = (cb.delay or 0) + cb.progress - newProgress
  1066. cb.progress = newProgress
  1067. end
  1068.  
  1069. function np.UNIT_SPELLCAST_CHANNEL_START(frame, unit)
  1070. np.UNIT_SPELLCAST_START(frame, unit, true)
  1071. end
  1072. function np.UNIT_SPELLCAST_CHANNEL_UPDATE(frame, unit)
  1073. np.UNIT_SPELLCAST_DELAYED(frame, unit, true)
  1074. end
  1075.  
  1076. function np.UNIT_SPELLCAST_STOP(frame, unit)
  1077. --print("UNIT_SPELLCAST_STOP")
  1078. frame.castbarbg:Hide()
  1079. end
  1080. function np.UNIT_SPELLCAST_FAILED(frame, unit)
  1081. --print("UNIT_SPELLCAST_FAILED")
  1082. frame.castbarbg:Hide()
  1083. end
  1084. function np.UNIT_SPELLCAST_INTERRUPTED(frame, unit)
  1085. --print("UNIT_SPELLCAST_INTERRUPTED")
  1086. frame.castbarbg:Hide()
  1087. end
  1088. function np.UNIT_SPELLCAST_CHANNEL_STOP(frame, unit)
  1089. --print("UNIT_SPELLCAST_CHANNEL_STOP")
  1090. frame.castbarbg:Hide()
  1091. end
  1092.  
  1093. -- custom cast bar event handler -----------------------------------------------
  1094. function np.UnitCastEvent(e, unit, ...)
  1095. if unit == 'player' then return end
  1096. local guid, name, f = UnitGUID(unit), GetUnitName(unit), nil
  1097. --guid, name = UnitGUID('target'), GetUnitName('target')
  1098.  
  1099. -- fetch the unit's nameplate
  1100. f = np:GetNameplate(guid, name)
  1101. if f then
  1102. if not f.castbar then return end
  1103. if e == 'UNIT_SPELLCAST_STOP' or
  1104. e == 'UNIT_SPELLCAST_FAILED' or
  1105. e == 'UNIT_SPELLCAST_INTERRUPTED'
  1106. then
  1107. -- these occasionally fire after a new _START
  1108. local _, _, castID = ...
  1109. if f.castbar.id ~= castID then
  1110. return
  1111. end
  1112. end
  1113.  
  1114. np[e](f, unit)
  1115. end
  1116. end
  1117.  
  1118. -- cast warning handler --------------------------------------------------------
  1119. function np.CastWarningEvent(_, ...)
  1120. -- _ = COMBAT_LOG_EVENT_UNFILTERED
  1121. local castTime, event, _, guid, name, _, _, targetGUID, targetName
  1122. = ...
  1123.  
  1124. if castEvents[event] then
  1125. if event == 'SPELL_HEAL' or
  1126. event == 'SPELL_PERIODIC_HEAL'
  1127. then
  1128. -- fetch the spell's target's nameplate
  1129. guid, name = targetGUID, targetName
  1130. end
  1131.  
  1132. local f = np:GetNameplate(guid, name)
  1133. if f then
  1134. if not f.SetIncomingWarning then return end
  1135. local spName, spSch = select(13, ...)
  1136.  
  1137. if event == 'SPELL_HEAL' or
  1138. event == 'SPELL_PERIODIC_HEAL'
  1139. then
  1140. -- display heal warning
  1141. local amount = select(15, ...)
  1142. f:SetIncomingWarning(amount)
  1143. elseif event == 'SPELL_INTERRUPT' then
  1144. -- hide the warning
  1145. f:SetCastWarning(nil)
  1146. else
  1147. -- or display it for this spell
  1148. f:SetCastWarning(spName, spSch)
  1149. end
  1150. end
  1151. end
  1152. end
  1153.  
  1154. ---------------------------------------------------------------- Kui handlers --
  1155. local WorldFrame = WorldFrame
  1156.  
  1157. np.frames = 0
  1158. function np:OnUpdate()
  1159. local i, f, frames
  1160. frames = select('#', WorldFrame:GetChildren())
  1161.  
  1162. if frames ~= np.frames then
  1163. for i = 1, frames do
  1164. f = select(i, WorldFrame:GetChildren())
  1165.  
  1166. if self:IsNameplate(f) and not f.init then
  1167. self:InitFrame(f)
  1168. end
  1169. end
  1170.  
  1171. np.frames = frames
  1172. end
  1173. end
  1174.  
  1175. np.kui:addEvent('PLAYER_TARGET_CHANGED')
  1176. np.kui:addTask(.1)
  1177.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement