Advertisement
Guest User

Untitled

a guest
May 27th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.16 KB | None | 0 0
  1. local E, L, V, P, G = unpack(select(2, ...)); --Inport: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
  2. local mod = E:GetModule('NamePlates')
  3. local LSM = LibStub("LibSharedMedia-3.0")
  4.  
  5. --Cache global variables
  6. --Lua functions
  7. local select, unpack = select, unpack
  8. local tinsert, tremove = table.insert, table.remove
  9. --WoW API / Variables
  10. local CreateFrame = CreateFrame
  11. local UnitBuff = UnitBuff
  12. local UnitDebuff = UnitDebuff
  13. local BUFF_STACKS_OVERFLOW = BUFF_STACKS_OVERFLOW
  14.  
  15. local auraCache = {}
  16.  
  17. function mod:SetAura(aura, index, name, icon, count, duration, expirationTime)
  18. aura.icon:SetTexture(icon);
  19. aura.name = name
  20. if ( count > 1 ) then
  21. local countText = count;
  22. if ( count >= 10 ) then
  23. countText = BUFF_STACKS_OVERFLOW;
  24. end
  25. aura.count:Show();
  26. aura.count:SetText(countText);
  27. else
  28. aura.count:Hide();
  29. end
  30. aura:SetID(index);
  31. if ( expirationTime and expirationTime ~= 0 ) then
  32. local startTime = expirationTime - duration;
  33. aura.cooldown:SetCooldown(startTime, duration);
  34. aura.cooldown:Show();
  35. else
  36. aura.cooldown:Hide();
  37. end
  38. aura:Show();
  39. end
  40.  
  41. function mod:HideAuraIcons(auras)
  42. for i=1, #auras.icons do
  43. auras.icons[i]:Hide()
  44. end
  45. end
  46.  
  47. --Allow certain auras with a duration of 0
  48. local durationOverride = {
  49. [146739] = true, --Absolute Corruption (Warlock)
  50. [203981] = true, --Soul fragments (Demon Hunter)
  51. }
  52.  
  53. function mod:UpdateElement_Auras(frame)
  54. local hasBuffs = false
  55. local hasDebuffs = false
  56. local auraFrame
  57. local name, icon, count, duration, expirationTime, unitCaster, spellId, isBossAura, _
  58.  
  59. --Debuffs
  60. local index = 1;
  61. local frameNum = 1;
  62. local maxAuras = #frame.Debuffs.icons;
  63. local showBoss = self.db.units[frame.UnitType].debuffs.filters.boss
  64. local showPersonal = self.db.units[frame.UnitType].debuffs.filters.personal
  65. local maxDuration = self.db.units[frame.UnitType].debuffs.filters.maxDuration
  66.  
  67. self:HideAuraIcons(frame.Debuffs)
  68. if(self.db.units[frame.UnitType].debuffs.enable and (showBoss or showPersonal)) then
  69. while ( frameNum <= maxAuras ) do
  70. name, _, icon, count, _, duration, expirationTime, unitCaster, _, _, spellId, _, isBossAura = UnitDebuff(frame.displayedUnit, index);
  71. if ( name ) then
  72. if not ( E.global.unitframe['aurafilters']['Blacklist']['spells'][spellId] ) then
  73. if (showBoss and isBossAura) or (showPersonal and (unitCaster == mod.playerUnitToken and (duration > 0 or durationOverride[spellId]) and duration <= maxDuration)) then
  74. auraFrame = frame.Debuffs.icons[frameNum];
  75. mod:SetAura(auraFrame, index, name, icon, count, duration, expirationTime)
  76. frameNum = frameNum + 1;
  77. hasDebuffs = true
  78. end
  79. end
  80. else
  81. break;
  82. end
  83. index = index + 1;
  84. end
  85. end
  86.  
  87. --Buffs
  88. index = 1
  89. frameNum = 1
  90. maxAuras = #frame.Buffs.icons
  91. showBoss = self.db.units[frame.UnitType].buffs.filters.boss
  92. showPersonal = self.db.units[frame.UnitType].buffs.filters.personal
  93. maxDuration = self.db.units[frame.UnitType].buffs.filters.maxDuration
  94.  
  95. self:HideAuraIcons(frame.Buffs)
  96. if(self.db.units[frame.UnitType].buffs.enable and (showBoss or showPersonal)) then
  97. while ( frameNum <= maxAuras ) do
  98. name, _, icon, count, _, duration, expirationTime, unitCaster, _, _, spellId, _, isBossAura = UnitBuff(frame.displayedUnit, index);
  99. if ( name ) then
  100. if (showBoss and isBossAura) or (showPersonal and (unitCaster == mod.playerUnitToken and (duration > 0 or durationOverride[spellId]) and duration <= maxDuration)) then
  101. auraFrame = frame.Buffs.icons[frameNum];
  102. mod:SetAura(auraFrame, index, name, icon, count, duration, expirationTime)
  103. frameNum = frameNum + 1;
  104. hasBuffs = true
  105. end
  106. else
  107. break;
  108. end
  109. index = index + 1;
  110. end
  111. end
  112.  
  113. local TopLevel = frame.HealthBar
  114. local TopOffset = ((self.db.units[frame.UnitType].showName and select(2, frame.Name:GetFont()) + 5) or 0)
  115. if(hasDebuffs) then
  116. TopOffset = TopOffset + 3
  117. frame.Debuffs:SetPoint("BOTTOMLEFT", TopLevel, "TOPLEFT", 0, TopOffset)
  118. frame.Debuffs:SetPoint("BOTTOMRIGHT", TopLevel, "TOPRIGHT", 0, TopOffset)
  119. TopLevel = frame.Debuffs
  120. TopOffset = 3
  121. end
  122.  
  123. if(hasBuffs) then
  124. if(not hasDebuffs) then
  125. TopOffset = TopOffset + 3
  126. end
  127. frame.Buffs:SetPoint("BOTTOMLEFT", TopLevel, "TOPLEFT", 0, TopOffset)
  128. frame.Buffs:SetPoint("BOTTOMRIGHT", TopLevel, "TOPRIGHT", 0, TopOffset)
  129. TopLevel = frame.Buffs
  130. TopOffset = 3
  131. end
  132.  
  133. if (frame.TopLevelFrame ~= TopLevel) then
  134. frame.TopLevelFrame = TopLevel
  135. frame.TopOffset = TopOffset
  136.  
  137. if (self.db.classbar.enable and self.db.classbar.position ~= "BELOW") then
  138. mod:ClassBar_Update(frame)
  139. end
  140.  
  141. if (self.db.units[frame.UnitType].detection and self.db.units[frame.UnitType].detection.enable) then
  142. mod:ConfigureElement_Detection(frame)
  143. end
  144. end
  145. end
  146.  
  147. function mod:CreateAuraIcon(parent)
  148. local aura = CreateFrame("Frame", nil, parent)
  149. self:StyleFrame(aura)
  150.  
  151. aura.icon = aura:CreateTexture(nil, "OVERLAY")
  152. aura.icon:SetAllPoints()
  153. aura.icon:SetTexCoord(unpack(E.TexCoords))
  154.  
  155. aura.cooldown = CreateFrame("Cooldown", nil, aura, "CooldownFrameTemplate")
  156. aura.cooldown:SetAllPoints(aura)
  157. aura.cooldown:SetReverse(true)
  158. aura.cooldown.SizeOverride = 10
  159. E:RegisterCooldown(aura.cooldown)
  160.  
  161. aura.count = aura:CreateFontString(nil, "OVERLAY")
  162. aura.count:SetPoint("BOTTOMRIGHT")
  163. aura.count:SetFont(LSM:Fetch("font", self.db.font), self.db.fontSize, self.db.fontOutline)
  164.  
  165. return aura
  166. end
  167.  
  168. function mod:Auras_SizeChanged(width)
  169. local numAuras = #self.icons
  170. for i=1, numAuras do
  171. self.icons[i]:SetWidth(((width - (mod.mult*numAuras)) / numAuras) - (E.private.general.pixelPerfect and 0 or 3))
  172. self.icons[i]:SetHeight((self.db.baseHeight or 18) * (self:GetParent().HealthBar.currentScale or 1))
  173. end
  174. self:SetHeight((self.db.baseHeight or 18) * (self:GetParent().HealthBar.currentScale or 1))
  175. end
  176.  
  177. function mod:UpdateAuraIcons(auras)
  178. local maxAuras = auras.db.numAuras
  179. local numCurrentAuras = #auras.icons
  180. if numCurrentAuras > maxAuras then
  181. for i = maxAuras, numCurrentAuras do
  182. tinsert(auraCache, auras.icons[i])
  183. auras.icons[i]:Hide()
  184. auras.icons[i] = nil
  185. end
  186. end
  187.  
  188. if numCurrentAuras ~= maxAuras then
  189. self.Auras_SizeChanged(auras, auras:GetWidth(), auras:GetHeight())
  190. end
  191.  
  192. for i=1, maxAuras do
  193. auras.icons[i] = auras.icons[i] or tremove(auraCache) or mod:CreateAuraIcon(auras)
  194. auras.icons[i]:SetParent(auras)
  195. auras.icons[i]:ClearAllPoints()
  196. auras.icons[i]:Hide()
  197. auras.icons[i]:SetHeight(auras.db.baseHeight or 18)
  198.  
  199. if(auras.side == "LEFT") then
  200. if(i == 1) then
  201. auras.icons[i]:SetPoint("BOTTOMLEFT", auras, "BOTTOMLEFT")
  202. else
  203. auras.icons[i]:SetPoint("LEFT", auras.icons[i-1], "RIGHT", E.Border + E.Spacing*3, 0)
  204. end
  205. else
  206. if(i == 1) then
  207. auras.icons[i]:SetPoint("BOTTOMRIGHT", auras, "BOTTOMRIGHT")
  208. else
  209. auras.icons[i]:SetPoint("RIGHT", auras.icons[i-1], "LEFT", -(E.Border + E.Spacing*3), 0)
  210. end
  211. end
  212. end
  213. end
  214.  
  215. function mod:ConstructElement_Auras(frame, side)
  216. local auras = CreateFrame("FRAME", nil, frame)
  217.  
  218. auras:SetScript("OnSizeChanged", mod.Auras_SizeChanged)
  219. auras:SetHeight(18) -- this really doesn't matter
  220. auras.side = side
  221. auras.icons = {}
  222.  
  223. return auras
  224. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement