SHARE
TWEET

Untitled

a guest Sep 22nd, 2019 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
  2. local ElvUF = E.oUF
  3.  
  4. local Translit = E.Libs.Translit
  5. local translitMark = "!"
  6.  
  7. --Lua functions
  8. local _G = _G
  9. local unpack, pairs, wipe, floor = unpack, pairs, wipe, floor
  10. local gmatch, gsub, format, select = gmatch, gsub, format, select
  11. local strfind, strmatch, utf8lower, utf8sub = strfind, strmatch, string.utf8lower, string.utf8sub
  12. --WoW API / Variables
  13. local GetCVarBool = GetCVarBool
  14. local GetGuildInfo = GetGuildInfo
  15. local GetInstanceInfo = GetInstanceInfo
  16. local GetNumGroupMembers = GetNumGroupMembers
  17. local GetNumQuestLogEntries = GetNumQuestLogEntries
  18. local GetPVPTimer = GetPVPTimer
  19. local GetQuestDifficultyColor = GetQuestDifficultyColor
  20. local GetQuestGreenRange = GetQuestGreenRange
  21. local GetQuestLogTitle = GetQuestLogTitle
  22. local GetRelativeDifficultyColor = GetRelativeDifficultyColor
  23. local GetSpecialization = GetSpecialization
  24. local GetThreatStatusColor = GetThreatStatusColor
  25. local GetTime = GetTime
  26. local GetUnitSpeed = GetUnitSpeed
  27. local IsInGroup = IsInGroup
  28. local IsInRaid = IsInRaid
  29. local QuestDifficultyColors = QuestDifficultyColors
  30. local UnitAlternatePowerTextureInfo = UnitAlternatePowerTextureInfo
  31. local UnitBattlePetLevel = UnitBattlePetLevel
  32. local UnitClass = UnitClass
  33. local UnitClassification = UnitClassification
  34. local UnitDetailedThreatSituation = UnitDetailedThreatSituation
  35. local UnitExists = UnitExists
  36. local UnitGetIncomingHeals = UnitGetIncomingHeals
  37. local UnitGetTotalAbsorbs = UnitGetTotalAbsorbs
  38. local UnitGUID = UnitGUID
  39. local UnitHealth = UnitHealth
  40. local UnitHealthMax = UnitHealthMax
  41. local UnitIsAFK = UnitIsAFK
  42. local UnitIsBattlePetCompanion = UnitIsBattlePetCompanion
  43. local UnitIsConnected = UnitIsConnected
  44. local UnitIsDead = UnitIsDead
  45. local UnitIsDeadOrGhost = UnitIsDeadOrGhost
  46. local UnitIsDND = UnitIsDND
  47. local UnitIsGhost = UnitIsGhost
  48. local UnitIsPlayer = UnitIsPlayer
  49. local UnitIsPVP = UnitIsPVP
  50. local UnitIsPVPFreeForAll = UnitIsPVPFreeForAll
  51. local UnitIsUnit = UnitIsUnit
  52. local UnitIsWildBattlePet = UnitIsWildBattlePet
  53. local UnitLevel = UnitLevel
  54. local UnitPower = UnitPower
  55. local UnitPowerMax = UnitPowerMax
  56. local UnitPowerType = UnitPowerType
  57. local UnitPVPName = UnitPVPName
  58. local UnitReaction = UnitReaction
  59. local UnitStagger = UnitStagger
  60.  
  61. local ALTERNATE_POWER_INDEX = ALTERNATE_POWER_INDEX
  62. local SPEC_MONK_BREWMASTER = SPEC_MONK_BREWMASTER
  63. local SPEC_PALADIN_RETRIBUTION = SPEC_PALADIN_RETRIBUTION
  64. local UNITNAME_SUMMON_TITLE17 = UNITNAME_SUMMON_TITLE17
  65. local DEFAULT_AFK_MESSAGE = DEFAULT_AFK_MESSAGE
  66. local UNKNOWN = UNKNOWN
  67. local LEVEL = LEVEL
  68. local PVP = PVP
  69.  
  70. local C_PetJournal_GetPetTeamAverageLevel = C_PetJournal.GetPetTeamAverageLevel
  71. local SPELL_POWER_CHI = Enum.PowerType.Chi
  72. local SPELL_POWER_HOLY_POWER = Enum.PowerType.HolyPower
  73. local SPELL_POWER_MANA = Enum.PowerType.Mana
  74. local SPELL_POWER_SOUL_SHARDS = Enum.PowerType.SoulShards
  75.  
  76. -- GLOBALS: Hex, _TAGS, ElvUF
  77.  
  78. ------------------------------------------------------------------------
  79. --  Tags
  80. ------------------------------------------------------------------------
  81.  
  82. local function UnitName(unit)
  83.     local name, realm = _G.UnitName(unit)
  84.  
  85.     if (name == UNKNOWN and E.myclass == "MONK") and UnitIsUnit(unit, "pet") then
  86.         name = format(UNITNAME_SUMMON_TITLE17, _G.UnitName("player"))
  87.     end
  88.  
  89.     if realm and realm ~= "" then
  90.         return name, realm
  91.     else
  92.         return name
  93.     end
  94. end
  95.  
  96. ElvUF.Tags.Events['altpower:percent'] = "UNIT_POWER_UPDATE UNIT_MAXPOWER"
  97. ElvUF.Tags.Methods['altpower:percent'] = function(u)
  98.     local cur = UnitPower(u, ALTERNATE_POWER_INDEX)
  99.     if cur > 0 then
  100.         local max = UnitPowerMax(u, ALTERNATE_POWER_INDEX)
  101.  
  102.         return E:GetFormattedText('PERCENT', cur, max)
  103.     else
  104.         return nil
  105.     end
  106. end
  107.  
  108. ElvUF.Tags.Events['altpower:current'] = "UNIT_POWER_UPDATE"
  109. ElvUF.Tags.Methods['altpower:current'] = function(u)
  110.     local cur = UnitPower(u, ALTERNATE_POWER_INDEX)
  111.     if cur > 0 then
  112.         return cur
  113.     else
  114.         return nil
  115.     end
  116. end
  117.  
  118. ElvUF.Tags.Events['altpower:current-percent'] = "UNIT_POWER_UPDATE UNIT_MAXPOWER"
  119. ElvUF.Tags.Methods['altpower:current-percent'] = function(u)
  120.     local cur = UnitPower(u, ALTERNATE_POWER_INDEX)
  121.     if cur > 0 then
  122.         local max = UnitPowerMax(u, ALTERNATE_POWER_INDEX)
  123.  
  124.         return E:GetFormattedText('CURRENT_PERCENT', cur, max)
  125.     else
  126.         return nil
  127.     end
  128. end
  129.  
  130. ElvUF.Tags.Events['altpower:deficit'] = "UNIT_POWER_UPDATE UNIT_MAXPOWER"
  131. ElvUF.Tags.Methods['altpower:deficit'] = function(u)
  132.     local cur = UnitPower(u, ALTERNATE_POWER_INDEX)
  133.     if cur > 0 then
  134.         local max = UnitPowerMax(u, ALTERNATE_POWER_INDEX)
  135.  
  136.         return E:GetFormattedText('DEFICIT', cur, max)
  137.     else
  138.         return nil
  139.     end
  140. end
  141.  
  142. ElvUF.Tags.Events['altpower:current-max'] = "UNIT_POWER_UPDATE UNIT_MAXPOWER"
  143. ElvUF.Tags.Methods['altpower:current-max'] = function(u)
  144.     local cur = UnitPower(u, ALTERNATE_POWER_INDEX)
  145.     if cur > 0 then
  146.         local max = UnitPowerMax(u, ALTERNATE_POWER_INDEX)
  147.  
  148.         return E:GetFormattedText('CURRENT_MAX', cur, max)
  149.     else
  150.         return nil
  151.     end
  152. end
  153.  
  154. ElvUF.Tags.Events['altpower:current-max-percent'] = "UNIT_POWER_UPDATE UNIT_MAXPOWER"
  155. ElvUF.Tags.Methods['altpower:current-max-percent'] = function(u)
  156.     local cur = UnitPower(u, ALTERNATE_POWER_INDEX)
  157.     if cur > 0 then
  158.         local max = UnitPowerMax(u, ALTERNATE_POWER_INDEX)
  159.  
  160.         E:GetFormattedText('CURRENT_MAX_PERCENT', cur, max)
  161.     else
  162.         return nil
  163.     end
  164. end
  165.  
  166. ElvUF.Tags.Events['altpowercolor'] = "UNIT_POWER_UPDATE UNIT_MAXPOWER"
  167. ElvUF.Tags.Methods['altpowercolor'] = function(u)
  168.     local cur = UnitPower(u, ALTERNATE_POWER_INDEX)
  169.     if cur > 0 then
  170.         local _, r, g, b = UnitAlternatePowerTextureInfo(u, 2)
  171.  
  172.         if not r then
  173.             r, g, b = 1, 1, 1
  174.         end
  175.  
  176.         return Hex(r,g,b)
  177.     else
  178.         return nil
  179.     end
  180. end
  181.  
  182. ElvUF.Tags.Events['afk'] = 'PLAYER_FLAGS_CHANGED'
  183. ElvUF.Tags.Methods['afk'] = function(unit)
  184.     local isAFK = UnitIsAFK(unit)
  185.     if isAFK then
  186.         return format('|cffFFFFFF[|r|cffFF0000%s|r|cFFFFFFFF]|r', DEFAULT_AFK_MESSAGE)
  187.     else
  188.         return nil
  189.     end
  190. end
  191.  
  192. ElvUF.Tags.Events['healthcolor'] = 'UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH UNIT_CONNECTION PLAYER_FLAGS_CHANGED'
  193. ElvUF.Tags.Methods['healthcolor'] = function(unit)
  194.     if UnitIsDeadOrGhost(unit) or not UnitIsConnected(unit) then
  195.         return Hex(0.84, 0.75, 0.65)
  196.     else
  197.         local r, g, b = ElvUF:ColorGradient(UnitHealth(unit), UnitHealthMax(unit), 0.69, 0.31, 0.31, 0.65, 0.63, 0.35, 0.33, 0.59, 0.33)
  198.         return Hex(r, g, b)
  199.     end
  200. end
  201.  
  202. ElvUF.Tags.Events['health:current'] = 'UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH UNIT_CONNECTION PLAYER_FLAGS_CHANGED'
  203. ElvUF.Tags.Methods['health:current'] = function(unit)
  204.     local status = UnitIsDead(unit) and L["Dead"] or UnitIsGhost(unit) and L["Ghost"] or not UnitIsConnected(unit) and L["Offline"]
  205.     if (status) then
  206.         return status
  207.     else
  208.         return E:GetFormattedText('CURRENT', UnitHealth(unit), UnitHealthMax(unit))
  209.     end
  210. end
  211.  
  212. ElvUF.Tags.Events['health:deficit'] = 'UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH UNIT_CONNECTION PLAYER_FLAGS_CHANGED'
  213. ElvUF.Tags.Methods['health:deficit'] = function(unit)
  214.     local status = UnitIsDead(unit) and L["Dead"] or UnitIsGhost(unit) and L["Ghost"] or not UnitIsConnected(unit) and L["Offline"]
  215.  
  216.     if (status) then
  217.         return status
  218.     else
  219.         return E:GetFormattedText('DEFICIT', UnitHealth(unit), UnitHealthMax(unit))
  220.     end
  221. end
  222.  
  223. ElvUF.Tags.Events['health:current-percent'] = 'UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH UNIT_CONNECTION PLAYER_FLAGS_CHANGED'
  224. ElvUF.Tags.Methods['health:current-percent'] = function(unit)
  225.     local status = UnitIsDead(unit) and L["Dead"] or UnitIsGhost(unit) and L["Ghost"] or not UnitIsConnected(unit) and L["Offline"]
  226.  
  227.     if (status) then
  228.         return status
  229.     else
  230.         return E:GetFormattedText('CURRENT_PERCENT', UnitHealth(unit), UnitHealthMax(unit))
  231.     end
  232. end
  233.  
  234. ElvUF.Tags.Events['health:current-max'] = 'UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH UNIT_CONNECTION PLAYER_FLAGS_CHANGED'
  235. ElvUF.Tags.Methods['health:current-max'] = function(unit)
  236.     local status = UnitIsDead(unit) and L["Dead"] or UnitIsGhost(unit) and L["Ghost"] or not UnitIsConnected(unit) and L["Offline"]
  237.  
  238.     if (status) then
  239.         return status
  240.     else
  241.         return E:GetFormattedText('CURRENT_MAX', UnitHealth(unit), UnitHealthMax(unit))
  242.     end
  243. end
  244.  
  245. ElvUF.Tags.Events['health:current-max-percent'] = 'UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH UNIT_CONNECTION PLAYER_FLAGS_CHANGED'
  246. ElvUF.Tags.Methods['health:current-max-percent'] = function(unit)
  247.     local status = UnitIsDead(unit) and L["Dead"] or UnitIsGhost(unit) and L["Ghost"] or not UnitIsConnected(unit) and L["Offline"]
  248.  
  249.     if (status) then
  250.         return status
  251.     else
  252.         return E:GetFormattedText('CURRENT_MAX_PERCENT', UnitHealth(unit), UnitHealthMax(unit))
  253.     end
  254. end
  255.  
  256. ElvUF.Tags.Events['health:max'] = 'UNIT_MAXHEALTH'
  257. ElvUF.Tags.Methods['health:max'] = function(unit)
  258.     local max = UnitHealthMax(unit)
  259.  
  260.     return E:GetFormattedText('CURRENT', max, max)
  261. end
  262.  
  263. ElvUF.Tags.Events['health:percent'] = 'UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH UNIT_CONNECTION PLAYER_FLAGS_CHANGED'
  264. ElvUF.Tags.Methods['health:percent'] = function(unit)
  265.     local status = UnitIsDead(unit) and L["Dead"] or UnitIsGhost(unit) and L["Ghost"] or not UnitIsConnected(unit) and L["Offline"]
  266.  
  267.     if (status) then
  268.         return status
  269.     else
  270.         return E:GetFormattedText('PERCENT', UnitHealth(unit), UnitHealthMax(unit))
  271.     end
  272. end
  273.  
  274. ElvUF.Tags.Events['name:last'] = 'UNIT_NAME_UPDATE'
  275. ElvUF.Tags.Methods['name:last'] = function(unit)
  276.     local name = UnitName(unit)
  277.     if select(2, IsInInstance()) == 'party' then
  278.         local a, b, c, d, e, f = strsplit(' ', name, 5)
  279.         local unitName
  280.         if b == 'Apprentice'
  281.         or b == 'Denizen'
  282.         or b == 'Emissary'
  283.         or b == 'Howlis'
  284.         or b == 'Terror'
  285.         or b == 'Totem'
  286.         or b == 'Waycrest' then
  287.             unitName = name ~=nil and (a or b or c or d or e or f) or nil
  288.         else
  289.             unitName = name ~=nil and (f or e or d or c or b or a) or nil
  290.         end
  291.         return unitName
  292.     else
  293.         return name ~= nil and E:ShortenString(name, 15) or nil
  294.     end
  295. end
  296.  
  297. ElvUF.Tags.Events['health:percent-with-absorbs'] = 'UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH UNIT_ABSORB_AMOUNT_CHANGED UNIT_CONNECTION PLAYER_FLAGS_CHANGED'
  298. ElvUF.Tags.Methods['health:percent-with-absorbs'] = function(unit)
  299.     local status = UnitIsDead(unit) and L["Dead"] or UnitIsGhost(unit) and L["Ghost"] or not UnitIsConnected(unit) and L["Offline"]
  300.  
  301.     if (status) then
  302.         return status
  303.     end
  304.  
  305.     local absorb = UnitGetTotalAbsorbs(unit) or 0
  306.     if absorb == 0 then
  307.         return E:GetFormattedText('PERCENT', UnitHealth(unit), UnitHealthMax(unit))
  308.     end
  309.  
  310.     local healthTotalIncludingAbsorbs = UnitHealth(unit) + absorb
  311.     return E:GetFormattedText('PERCENT', healthTotalIncludingAbsorbs, UnitHealthMax(unit))
  312. end
  313.  
  314. ElvUF.Tags.Events['health:current-nostatus'] = 'UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH'
  315. ElvUF.Tags.Methods['health:current-nostatus'] = function(unit)
  316.     return E:GetFormattedText('CURRENT', UnitHealth(unit), UnitHealthMax(unit))
  317. end
  318.  
  319. ElvUF.Tags.Events['health:deficit-nostatus'] = 'UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH'
  320. ElvUF.Tags.Methods['health:deficit-nostatus'] = function(unit)
  321.     return E:GetFormattedText('DEFICIT', UnitHealth(unit), UnitHealthMax(unit))
  322. end
  323.  
  324. ElvUF.Tags.Events['health:current-percent-nostatus'] = 'UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH'
  325. ElvUF.Tags.Methods['health:current-percent-nostatus'] = function(unit)
  326.     return E:GetFormattedText('CURRENT_PERCENT', UnitHealth(unit), UnitHealthMax(unit))
  327. end
  328.  
  329. ElvUF.Tags.Events['health:current-max-nostatus'] = 'UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH'
  330. ElvUF.Tags.Methods['health:current-max-nostatus'] = function(unit)
  331.     return E:GetFormattedText('CURRENT_MAX', UnitHealth(unit), UnitHealthMax(unit))
  332. end
  333.  
  334. ElvUF.Tags.Events['health:current-max-percent-nostatus'] = 'UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH'
  335. ElvUF.Tags.Methods['health:current-max-percent-nostatus'] = function(unit)
  336.     return E:GetFormattedText('CURRENT_MAX_PERCENT', UnitHealth(unit), UnitHealthMax(unit))
  337. end
  338.  
  339. ElvUF.Tags.Events['health:percent-nostatus'] = 'UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH'
  340. ElvUF.Tags.Methods['health:percent-nostatus'] = function(unit)
  341.     return E:GetFormattedText('PERCENT', UnitHealth(unit), UnitHealthMax(unit))
  342. end
  343.  
  344. ElvUF.Tags.Events['health:deficit-percent:name'] = 'UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH UNIT_NAME_UPDATE'
  345. ElvUF.Tags.Methods['health:deficit-percent:name'] = function(unit)
  346.     local currentHealth = UnitHealth(unit)
  347.     local deficit = UnitHealthMax(unit) - currentHealth
  348.  
  349.     if (deficit > 0 and currentHealth > 0) then
  350.         return _TAGS["health:percent-nostatus"](unit)
  351.     else
  352.         return _TAGS.name(unit)
  353.     end
  354. end
  355.  
  356. ElvUF.Tags.Events['health:deficit-percent:name-long'] = 'UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH UNIT_NAME_UPDATE'
  357. ElvUF.Tags.Methods['health:deficit-percent:name-long'] = function(unit)
  358.     local currentHealth = UnitHealth(unit)
  359.     local deficit = UnitHealthMax(unit) - currentHealth
  360.  
  361.     if (deficit > 0 and currentHealth > 0) then
  362.         return _TAGS["health:percent-nostatus"](unit)
  363.     else
  364.         return _TAGS["name:long"](unit)
  365.     end
  366. end
  367.  
  368. ElvUF.Tags.Events['health:deficit-percent:name-medium'] = 'UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH UNIT_NAME_UPDATE'
  369. ElvUF.Tags.Methods['health:deficit-percent:name-medium'] = function(unit)
  370.     local currentHealth = UnitHealth(unit)
  371.     local deficit = UnitHealthMax(unit) - currentHealth
  372.  
  373.     if (deficit > 0 and currentHealth > 0) then
  374.         return _TAGS["health:percent-nostatus"](unit)
  375.     else
  376.         return _TAGS["name:medium"](unit)
  377.     end
  378. end
  379.  
  380. ElvUF.Tags.Events['health:deficit-percent:name-short'] = 'UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH UNIT_NAME_UPDATE'
  381. ElvUF.Tags.Methods['health:deficit-percent:name-short'] = function(unit)
  382.     local currentHealth = UnitHealth(unit)
  383.     local deficit = UnitHealthMax(unit) - currentHealth
  384.  
  385.     if (deficit > 0 and currentHealth > 0) then
  386.         return _TAGS["health:percent-nostatus"](unit)
  387.     else
  388.         return _TAGS["name:short"](unit)
  389.     end
  390. end
  391.  
  392. ElvUF.Tags.Events['health:deficit-percent:name-veryshort'] = 'UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH UNIT_NAME_UPDATE'
  393. ElvUF.Tags.Methods['health:deficit-percent:name-veryshort'] = function(unit)
  394.     local currentHealth = UnitHealth(unit)
  395.     local deficit = UnitHealthMax(unit) - currentHealth
  396.  
  397.     if (deficit > 0 and currentHealth > 0) then
  398.         return _TAGS["health:percent-nostatus"](unit)
  399.     else
  400.         return _TAGS["name:veryshort"](unit)
  401.     end
  402. end
  403.  
  404. ElvUF.Tags.Events['power:current'] = 'UNIT_DISPLAYPOWER UNIT_POWER_FREQUENT UNIT_MAXPOWER'
  405. ElvUF.Tags.Methods['power:current'] = function(unit)
  406.     local pType = UnitPowerType(unit)
  407.     local min = UnitPower(unit, pType)
  408.  
  409.     if min == 0 then
  410.         return nil
  411.     else
  412.         return E:GetFormattedText('CURRENT', min, UnitPowerMax(unit, pType))
  413.     end
  414. end
  415.  
  416. ElvUF.Tags.Events['power:current-max'] = 'UNIT_DISPLAYPOWER UNIT_POWER_FREQUENT UNIT_MAXPOWER'
  417. ElvUF.Tags.Methods['power:current-max'] = function(unit)
  418.     local pType = UnitPowerType(unit)
  419.     local min = UnitPower(unit, pType)
  420.  
  421.     return min == 0 and ' ' or  E:GetFormattedText('CURRENT_MAX', min, UnitPowerMax(unit, pType))
  422. end
  423.  
  424. ElvUF.Tags.Events['power:current-percent'] = 'UNIT_DISPLAYPOWER UNIT_POWER_FREQUENT UNIT_MAXPOWER'
  425. ElvUF.Tags.Methods['power:current-percent'] = function(unit)
  426.     local pType = UnitPowerType(unit)
  427.     local min = UnitPower(unit, pType)
  428.  
  429.     if min == 0 then
  430.         return nil
  431.     else
  432.         return E:GetFormattedText('CURRENT_PERCENT', min, UnitPowerMax(unit, pType))
  433.     end
  434. end
  435.  
  436. ElvUF.Tags.Events['power:current-max-percent'] = 'UNIT_DISPLAYPOWER UNIT_POWER_FREQUENT UNIT_MAXPOWER'
  437. ElvUF.Tags.Methods['power:current-max-percent'] = function(unit)
  438.     local pType = UnitPowerType(unit)
  439.     local min = UnitPower(unit, pType)
  440.  
  441.     if min == 0 then
  442.         return nil
  443.     else
  444.         return E:GetFormattedText('CURRENT_MAX_PERCENT', min, UnitPowerMax(unit, pType))
  445.     end
  446. end
  447.  
  448. ElvUF.Tags.Events['power:percent'] = 'UNIT_DISPLAYPOWER UNIT_POWER_FREQUENT UNIT_MAXPOWER'
  449. ElvUF.Tags.Methods['power:percent'] = function(unit)
  450.     local pType = UnitPowerType(unit)
  451.     local min = UnitPower(unit, pType)
  452.  
  453.     if min == 0 then
  454.         return nil
  455.     else
  456.         return E:GetFormattedText('PERCENT', min, UnitPowerMax(unit, pType))
  457.     end
  458. end
  459.  
  460. ElvUF.Tags.Events['power:deficit'] = 'UNIT_DISPLAYPOWER UNIT_POWER_FREQUENT UNIT_MAXPOWER'
  461. ElvUF.Tags.Methods['power:deficit'] = function(unit)
  462.     local pType = UnitPowerType(unit)
  463.  
  464.     return E:GetFormattedText('DEFICIT', UnitPower(unit, pType), UnitPowerMax(unit, pType))
  465. end
  466.  
  467. ElvUF.Tags.Events['power:max'] = 'UNIT_DISPLAYPOWER UNIT_MAXPOWER'
  468. ElvUF.Tags.Methods['power:max'] = function(unit)
  469.     local pType = UnitPowerType(unit)
  470.     local max = UnitPowerMax(unit, pType)
  471.  
  472.     return E:GetFormattedText('CURRENT', max, max)
  473. end
  474.  
  475. ElvUF.Tags.Methods['manacolor'] = function()
  476.     local mana = _G.PowerBarColor.MANA
  477.     local altR, altG, altB = mana.r, mana.g, mana.b
  478.     local color = ElvUF.colors.power.MANA
  479.     if color then
  480.         return Hex(color[1], color[2], color[3])
  481.     else
  482.         return Hex(altR, altG, altB)
  483.     end
  484. end
  485.  
  486. ElvUF.Tags.Events['mana:current'] = 'UNIT_POWER_FREQUENT UNIT_MAXPOWER'
  487. ElvUF.Tags.Methods['mana:current'] = function(unit)
  488.     local min = UnitPower(unit, SPELL_POWER_MANA)
  489.  
  490.     if min == 0 then
  491.         return nil
  492.     else
  493.         return E:GetFormattedText('CURRENT', min, UnitPowerMax(unit, SPELL_POWER_MANA))
  494.     end
  495. end
  496.  
  497. ElvUF.Tags.Events['mana:current-max'] = 'UNIT_POWER_FREQUENT UNIT_MAXPOWER'
  498. ElvUF.Tags.Methods['mana:current-max'] = function(unit)
  499.     local min = UnitPower(unit, SPELL_POWER_MANA)
  500.  
  501.     if min == 0 then
  502.         return nil
  503.     else
  504.         return E:GetFormattedText('CURRENT_MAX', min, UnitPowerMax(unit, SPELL_POWER_MANA))
  505.     end
  506. end
  507.  
  508. ElvUF.Tags.Events['mana:current-percent'] = 'UNIT_POWER_FREQUENT UNIT_MAXPOWER'
  509. ElvUF.Tags.Methods['mana:current-percent'] = function(unit)
  510.     local min = UnitPower(unit, SPELL_POWER_MANA)
  511.  
  512.     if min == 0 then
  513.         return nil
  514.     else
  515.         return E:GetFormattedText('CURRENT_PERCENT', min, UnitPowerMax(unit, SPELL_POWER_MANA))
  516.     end
  517. end
  518.  
  519. ElvUF.Tags.Events['mana:current-max-percent'] = 'UNIT_POWER_FREQUENT UNIT_MAXPOWER'
  520. ElvUF.Tags.Methods['mana:current-max-percent'] = function(unit)
  521.     local min = UnitPower(unit, SPELL_POWER_MANA)
  522.  
  523.     if min == 0 then
  524.         return nil
  525.     else
  526.         return E:GetFormattedText('CURRENT_MAX_PERCENT', min, UnitPowerMax(unit, SPELL_POWER_MANA))
  527.     end
  528. end
  529.  
  530. ElvUF.Tags.Events['mana:percent'] = 'UNIT_POWER_FREQUENT UNIT_MAXPOWER'
  531. ElvUF.Tags.Methods['mana:percent'] = function(unit)
  532.     local min = UnitPower(unit, SPELL_POWER_MANA)
  533.  
  534.     if min == 0 then
  535.         return nil
  536.     else
  537.         return E:GetFormattedText('PERCENT', min, UnitPowerMax(unit, SPELL_POWER_MANA))
  538.     end
  539. end
  540.  
  541. ElvUF.Tags.Events['mana:deficit'] = 'UNIT_POWER_FREQUENT UNIT_MAXPOWER'
  542. ElvUF.Tags.Methods['mana:deficit'] = function(unit)
  543.     return E:GetFormattedText('DEFICIT', UnitPower(unit), UnitPowerMax(unit, SPELL_POWER_MANA))
  544. end
  545.  
  546. ElvUF.Tags.Events['mana:max'] = 'UNIT_MAXPOWER'
  547. ElvUF.Tags.Methods['mana:max'] = function(unit)
  548.     local max = UnitPowerMax(unit, SPELL_POWER_MANA)
  549.  
  550.     return E:GetFormattedText('CURRENT', max, max)
  551. end
  552.  
  553. ElvUF.Tags.Events['difficultycolor'] = 'UNIT_LEVEL PLAYER_LEVEL_UP'
  554. ElvUF.Tags.Methods['difficultycolor'] = function(unit)
  555.     local r, g, b
  556.     if ( UnitIsWildBattlePet(unit) or UnitIsBattlePetCompanion(unit) ) then
  557.         local level = UnitBattlePetLevel(unit)
  558.  
  559.         local teamLevel = C_PetJournal_GetPetTeamAverageLevel();
  560.         if teamLevel < level or teamLevel > level then
  561.             local c = GetRelativeDifficultyColor(teamLevel, level)
  562.             r, g, b = c.r, c.g, c.b
  563.         else
  564.             local c = QuestDifficultyColors.difficult
  565.             r, g, b = c.r, c.g, c.b
  566.         end
  567.     else
  568.         local DiffColor = UnitLevel(unit) - E.mylevel
  569.         if (DiffColor >= 5) then
  570.             r, g, b = 0.69, 0.31, 0.31
  571.         elseif (DiffColor >= 3) then
  572.             r, g, b = 0.71, 0.43, 0.27
  573.         elseif (DiffColor >= -2) then
  574.             r, g, b = 0.84, 0.75, 0.65
  575.         elseif (-DiffColor <= GetQuestGreenRange()) then
  576.             r, g, b = 0.33, 0.59, 0.33
  577.         else
  578.             r, g, b = 0.55, 0.57, 0.61
  579.         end
  580.     end
  581.  
  582.     return Hex(r, g, b)
  583. end
  584.  
  585. ElvUF.Tags.Events['namecolor'] = 'UNIT_NAME_UPDATE UNIT_FACTION'
  586. ElvUF.Tags.Methods['namecolor'] = function(unit)
  587.     local unitReaction = UnitReaction(unit, 'player')
  588.     local unitPlayer = UnitIsPlayer(unit)
  589.     if (unitPlayer) then
  590.         local _, unitClass = UnitClass(unit)
  591.         local class = ElvUF.colors.class[unitClass]
  592.         if not class then return "" end
  593.         return Hex(class[1], class[2], class[3])
  594.     elseif (unitReaction) then
  595.         local reaction = ElvUF.colors.reaction[unitReaction]
  596.         return Hex(reaction[1], reaction[2], reaction[3])
  597.     else
  598.         return '|cFFC2C2C2'
  599.     end
  600. end
  601.  
  602. ElvUF.Tags.Events['smartlevel'] = 'UNIT_LEVEL PLAYER_LEVEL_UP'
  603. ElvUF.Tags.Methods['smartlevel'] = function(unit)
  604.     local level = UnitLevel(unit)
  605.     if ( UnitIsWildBattlePet(unit) or UnitIsBattlePetCompanion(unit) ) then
  606.         return UnitBattlePetLevel(unit);
  607.     elseif level == E.mylevel then
  608.         return nil
  609.     elseif(level > 0) then
  610.         return level
  611.     else
  612.         return '??'
  613.     end
  614. end
  615.  
  616. ElvUF.Tags.Events['name:veryshort'] = 'UNIT_NAME_UPDATE'
  617. ElvUF.Tags.Methods['name:veryshort'] = function(unit)
  618.     local name = UnitName(unit)
  619.     return name ~= nil and E:ShortenString(name, 5) or nil
  620. end
  621.  
  622. ElvUF.Tags.Events['name:short'] = 'UNIT_NAME_UPDATE'
  623. ElvUF.Tags.Methods['name:short'] = function(unit)
  624.     local name = UnitName(unit)
  625.     return name ~= nil and E:ShortenString(name, 10) or nil
  626. end
  627.  
  628. ElvUF.Tags.Events['name:medium'] = 'UNIT_NAME_UPDATE'
  629. ElvUF.Tags.Methods['name:medium'] = function(unit)
  630.     local name = UnitName(unit)
  631.     return name ~= nil and E:ShortenString(name, 15) or nil
  632. end
  633.  
  634. ElvUF.Tags.Events['name:long'] = 'UNIT_NAME_UPDATE'
  635. ElvUF.Tags.Methods['name:long'] = function(unit)
  636.     local name = UnitName(unit)
  637.     return name ~= nil and E:ShortenString(name, 20) or nil
  638. end
  639.  
  640. local function abbrev(name)
  641.     local letters, lastWord = '', strmatch(name, '.+%s(.+)$')
  642.     if lastWord then
  643.         for word in gmatch(name, '.-%s') do
  644.             local firstLetter = utf8sub(gsub(word, '^[%s%p]*', ''), 1, 1)
  645.             if firstLetter ~= utf8lower(firstLetter) then
  646.                 letters = format('%s%s. ', letters, firstLetter)
  647.             end
  648.         end
  649.         name = format('%s%s', letters, lastWord)
  650.     end
  651.     return name
  652. end
  653.  
  654. ElvUF.Tags.Events['name:abbrev'] = 'UNIT_NAME_UPDATE'
  655. ElvUF.Tags.Methods['name:abbrev'] = function(unit)
  656.     local name = UnitName(unit)
  657.  
  658.     if name and strfind(name, '%s') then
  659.         name = abbrev(name)
  660.     end
  661.  
  662.     return name ~= nil and E:ShortenString(name, 20) or '' --The value 20 controls how many characters are allowed in the name before it gets truncated. Change it to fit your needs.
  663. end
  664.  
  665. ElvUF.Tags.Events['name:veryshort:status'] = 'UNIT_NAME_UPDATE UNIT_CONNECTION PLAYER_FLAGS_CHANGED UNIT_HEALTH_FREQUENT'
  666. ElvUF.Tags.Methods['name:veryshort:status'] = function(unit)
  667.     local status = UnitIsDead(unit) and L["Dead"] or UnitIsGhost(unit) and L["Ghost"] or not UnitIsConnected(unit) and L["Offline"]
  668.     local name = UnitName(unit)
  669.     if (status) then
  670.         return status
  671.     else
  672.         return name ~= nil and E:ShortenString(name, 5) or nil
  673.     end
  674. end
  675.  
  676. ElvUF.Tags.Events['name:short:status'] = 'UNIT_NAME_UPDATE UNIT_CONNECTION PLAYER_FLAGS_CHANGED UNIT_HEALTH_FREQUENT'
  677. ElvUF.Tags.Methods['name:short:status'] = function(unit)
  678.     local status = UnitIsDead(unit) and L["Dead"] or UnitIsGhost(unit) and L["Ghost"] or not UnitIsConnected(unit) and L["Offline"]
  679.     local name = UnitName(unit)
  680.     if (status) then
  681.         return status
  682.     else
  683.         return name ~= nil and E:ShortenString(name, 10) or nil
  684.     end
  685. end
  686.  
  687. ElvUF.Tags.Events['name:medium:status'] = 'UNIT_NAME_UPDATE UNIT_CONNECTION PLAYER_FLAGS_CHANGED UNIT_HEALTH_FREQUENT'
  688. ElvUF.Tags.Methods['name:medium:status'] = function(unit)
  689.     local status = UnitIsDead(unit) and L["Dead"] or UnitIsGhost(unit) and L["Ghost"] or not UnitIsConnected(unit) and L["Offline"]
  690.     local name = UnitName(unit)
  691.     if (status) then
  692.         return status
  693.     else
  694.         return name ~= nil and E:ShortenString(name, 15) or nil
  695.     end
  696. end
  697.  
  698. ElvUF.Tags.Events['name:long:status'] = 'UNIT_NAME_UPDATE UNIT_CONNECTION PLAYER_FLAGS_CHANGED UNIT_HEALTH_FREQUENT'
  699. ElvUF.Tags.Methods['name:long:status'] = function(unit)
  700.     local status = UnitIsDead(unit) and L["Dead"] or UnitIsGhost(unit) and L["Ghost"] or not UnitIsConnected(unit) and L["Offline"]
  701.     local name = UnitName(unit)
  702.     if (status) then
  703.         return status
  704.     else
  705.         return name ~= nil and E:ShortenString(name, 20) or nil
  706.     end
  707. end
  708.  
  709. ElvUF.Tags.Events['name:veryshort:translit'] = 'UNIT_NAME_UPDATE'
  710. ElvUF.Tags.Methods['name:veryshort:translit'] = function(unit)
  711.     local name = Translit:Transliterate(UnitName(unit), translitMark)
  712.     return name ~= nil and E:ShortenString(name, 5) or nil
  713. end
  714.  
  715. ElvUF.Tags.Events['name:short:translit'] = 'UNIT_NAME_UPDATE'
  716. ElvUF.Tags.Methods['name:short:translit'] = function(unit)
  717.     local name = Translit:Transliterate(UnitName(unit), translitMark)
  718.     return name ~= nil and E:ShortenString(name, 10) or nil
  719. end
  720.  
  721. ElvUF.Tags.Events['name:medium:translit'] = 'UNIT_NAME_UPDATE'
  722. ElvUF.Tags.Methods['name:medium:translit'] = function(unit)
  723.     local name = Translit:Transliterate(UnitName(unit), translitMark)
  724.     return name ~= nil and E:ShortenString(name, 15) or nil
  725. end
  726.  
  727. ElvUF.Tags.Events['name:long:translit'] = 'UNIT_NAME_UPDATE'
  728. ElvUF.Tags.Methods['name:long:translit'] = function(unit)
  729.     local name = Translit:Transliterate(UnitName(unit), translitMark)
  730.     return name ~= nil and E:ShortenString(name, 20) or nil
  731. end
  732.  
  733. ElvUF.Tags.Events['realm'] = 'UNIT_NAME_UPDATE'
  734. ElvUF.Tags.Methods['realm'] = function(unit)
  735.     local _, realm = UnitName(unit)
  736.  
  737.     if realm and realm ~= "" then
  738.         return realm
  739.     else
  740.         return nil
  741.     end
  742. end
  743.  
  744. ElvUF.Tags.Events['realm:dash'] = 'UNIT_NAME_UPDATE'
  745. ElvUF.Tags.Methods['realm:dash'] = function(unit)
  746.     local _, realm = UnitName(unit)
  747.  
  748.     if realm and (realm ~= "" and realm ~= E.myrealm) then
  749.         realm = format("-%s", realm)
  750.     elseif realm == "" then
  751.         realm = nil
  752.     end
  753.  
  754.     return realm
  755. end
  756.  
  757. ElvUF.Tags.Events['realm:translit'] = 'UNIT_NAME_UPDATE'
  758. ElvUF.Tags.Methods['realm:translit'] = function(unit)
  759.     local _, realm = Translit:Transliterate(UnitName(unit), translitMark)
  760.  
  761.     if realm and realm ~= "" then
  762.         return realm
  763.     else
  764.         return nil
  765.     end
  766. end
  767.  
  768. ElvUF.Tags.Events['realm:dash:translit'] = 'UNIT_NAME_UPDATE'
  769. ElvUF.Tags.Methods['realm:dash:translit'] = function(unit)
  770.     local _, realm = Translit:Transliterate(UnitName(unit), translitMark)
  771.  
  772.     if realm and (realm ~= "" and realm ~= E.myrealm) then
  773.         realm = format("-%s", realm)
  774.     elseif realm == "" then
  775.         realm = nil
  776.     end
  777.  
  778.     return realm
  779. end
  780.  
  781.  
  782. ElvUF.Tags.Events['threat:percent'] = 'UNIT_THREAT_LIST_UPDATE GROUP_ROSTER_UPDATE'
  783. ElvUF.Tags.Methods['threat:percent'] = function(unit)
  784.     local _, _, percent = UnitDetailedThreatSituation('player', unit)
  785.     if(percent and percent > 0) and (IsInGroup() or UnitExists('pet')) then
  786.         return format('%.0f%%', percent)
  787.     else
  788.         return nil
  789.     end
  790. end
  791.  
  792. ElvUF.Tags.Events['threat:current'] = 'UNIT_THREAT_LIST_UPDATE GROUP_ROSTER_UPDATE'
  793. ElvUF.Tags.Methods['threat:current'] = function(unit)
  794.     local _, _, percent, _, threatvalue = UnitDetailedThreatSituation('player', unit)
  795.     if(percent and percent > 0) and (IsInGroup() or UnitExists('pet')) then
  796.         return E:ShortValue(threatvalue)
  797.     else
  798.         return nil
  799.     end
  800. end
  801.  
  802. ElvUF.Tags.Events['threatcolor'] = 'UNIT_THREAT_LIST_UPDATE GROUP_ROSTER_UPDATE'
  803. ElvUF.Tags.Methods['threatcolor'] = function(unit)
  804.     local _, status = UnitDetailedThreatSituation('player', unit)
  805.     if (status) and (IsInGroup() or UnitExists('pet')) then
  806.         return Hex(GetThreatStatusColor(status))
  807.     else
  808.         return nil
  809.     end
  810. end
  811.  
  812. local unitStatus = {}
  813. ElvUF.Tags.OnUpdateThrottle['statustimer'] = 1
  814. ElvUF.Tags.Methods['statustimer'] = function(unit)
  815.     if not UnitIsPlayer(unit) then return; end
  816.     local guid = UnitGUID(unit)
  817.     if (UnitIsAFK(unit)) then
  818.         if not unitStatus[guid] or unitStatus[guid] and unitStatus[guid][1] ~= 'AFK' then
  819.             unitStatus[guid] = {'AFK', GetTime()}
  820.         end
  821.     elseif(UnitIsDND(unit)) then
  822.         if not unitStatus[guid] or unitStatus[guid] and unitStatus[guid][1] ~= 'DND' then
  823.             unitStatus[guid] = {'DND', GetTime()}
  824.         end
  825.     elseif(UnitIsDead(unit)) or (UnitIsGhost(unit))then
  826.         if not unitStatus[guid] or unitStatus[guid] and unitStatus[guid][1] ~= 'Dead' then
  827.             unitStatus[guid] = {'Dead', GetTime()}
  828.         end
  829.     elseif(not UnitIsConnected(unit)) then
  830.         if not unitStatus[guid] or unitStatus[guid] and unitStatus[guid][1] ~= 'Offline' then
  831.             unitStatus[guid] = {'Offline', GetTime()}
  832.         end
  833.     else
  834.         unitStatus[guid] = nil
  835.     end
  836.  
  837.     if unitStatus[guid] ~= nil then
  838.         local status = unitStatus[guid][1]
  839.         local timer = GetTime() - unitStatus[guid][2]
  840.         local mins = floor(timer / 60)
  841.         local secs = floor(timer - (mins * 60))
  842.         return format("%s (%01.f:%02.f)", status, mins, secs)
  843.     else
  844.         return nil
  845.     end
  846. end
  847.  
  848. ElvUF.Tags.OnUpdateThrottle['pvptimer'] = 1
  849. ElvUF.Tags.Methods['pvptimer'] = function(unit)
  850.     if (UnitIsPVPFreeForAll(unit) or UnitIsPVP(unit)) then
  851.         local timer = GetPVPTimer()
  852.  
  853.         if timer ~= 301000 and timer ~= -1 then
  854.             local mins = floor((timer / 1000) / 60)
  855.             local secs = floor((timer / 1000) - (mins * 60))
  856.             return format("%s (%01.f:%02.f)", PVP, mins, secs)
  857.         else
  858.             return PVP
  859.         end
  860.     else
  861.         return nil
  862.     end
  863. end
  864.  
  865. local Harmony = {
  866.     [0] = {1, 1, 1},
  867.     [1] = {.57, .63, .35, 1},
  868.     [2] = {.47, .63, .35, 1},
  869.     [3] = {.37, .63, .35, 1},
  870.     [4] = {.27, .63, .33, 1},
  871.     [5] = {.17, .63, .33, 1},
  872.     [6] = {.17, .63, .33, 1},
  873. }
  874.  
  875. local StaggerColors = ElvUF.colors.power.STAGGER
  876. -- percentages at which the bar should change color
  877. local STAGGER_YELLOW_TRANSITION = STAGGER_YELLOW_TRANSITION
  878. local STAGGER_RED_TRANSITION = STAGGER_RED_TRANSITION
  879. -- table indices of bar colors
  880. local STAGGER_GREEN_INDEX = STAGGER_GREEN_INDEX or 1
  881. local STAGGER_YELLOW_INDEX = STAGGER_YELLOW_INDEX or 2
  882. local STAGGER_RED_INDEX = STAGGER_RED_INDEX or 3
  883.  
  884. local function GetClassPower(class)
  885.     local min, max, r, g, b = 0, 0, 0, 0, 0
  886.  
  887.     local spec = GetSpecialization()
  888.     if class == 'PALADIN' and spec == SPEC_PALADIN_RETRIBUTION then
  889.         min = UnitPower('player', SPELL_POWER_HOLY_POWER);
  890.         max = UnitPowerMax('player', SPELL_POWER_HOLY_POWER);
  891.         r, g, b = 228/255, 225/255, 16/255
  892.     elseif class == 'MONK' then
  893.         if spec == SPEC_MONK_BREWMASTER then
  894.             min = UnitStagger("player")
  895.             max = UnitHealthMax("player")
  896.             local staggerRatio = min / max
  897.             if (staggerRatio >= STAGGER_RED_TRANSITION) then
  898.                 r, g, b = unpack(StaggerColors[STAGGER_RED_INDEX])
  899.             elseif (staggerRatio >= STAGGER_YELLOW_TRANSITION) then
  900.                 r, g, b = unpack(StaggerColors[STAGGER_YELLOW_INDEX])
  901.             else
  902.                 r, g, b = unpack(StaggerColors[STAGGER_GREEN_INDEX])
  903.             end
  904.         else
  905.             min = UnitPower("player", SPELL_POWER_CHI)
  906.             max = UnitPowerMax("player", SPELL_POWER_CHI)
  907.             r, g, b = unpack(Harmony[min])
  908.         end
  909.     elseif class == 'WARLOCK' then
  910.         min = UnitPower("player", SPELL_POWER_SOUL_SHARDS)
  911.         max = UnitPowerMax("player", SPELL_POWER_SOUL_SHARDS)
  912.         r, g, b = 148/255, 130/255, 201/255
  913.     end
  914.  
  915.     return min, max, r, g, b
  916. end
  917.  
  918. ElvUF.Tags.Events['classpowercolor'] = 'UNIT_POWER_FREQUENT UNIT_DISPLAYPOWER'
  919. ElvUF.Tags.Methods['classpowercolor'] = function()
  920.     local _, _, r, g, b = GetClassPower(E.myclass)
  921.     return Hex(r, g, b)
  922. end
  923.  
  924. ElvUF.Tags.Events['classpower:current'] = 'UNIT_POWER_FREQUENT UNIT_DISPLAYPOWER'
  925. ElvUF.Tags.Methods['classpower:current'] = function()
  926.     local min, max = GetClassPower(E.myclass)
  927.     if min == 0 then
  928.         return nil
  929.     else
  930.         return E:GetFormattedText('CURRENT', min, max)
  931.     end
  932. end
  933.  
  934. ElvUF.Tags.Events['classpower:deficit'] = 'UNIT_POWER_FREQUENT UNIT_DISPLAYPOWER'
  935. ElvUF.Tags.Methods['classpower:deficit'] = function()
  936.     local min, max = GetClassPower(E.myclass)
  937.     if min == 0 then
  938.         return nil
  939.     else
  940.         return E:GetFormattedText('DEFICIT', min, max)
  941.     end
  942. end
  943.  
  944. ElvUF.Tags.Events['classpower:current-percent'] = 'UNIT_POWER_FREQUENT UNIT_DISPLAYPOWER'
  945. ElvUF.Tags.Methods['classpower:current-percent'] = function()
  946.     local min, max = GetClassPower(E.myclass)
  947.     if min == 0 then
  948.         return nil
  949.     else
  950.         return E:GetFormattedText('CURRENT_PERCENT', min, max)
  951.     end
  952. end
  953.  
  954. ElvUF.Tags.Events['classpower:current-max'] = 'UNIT_POWER_FREQUENT UNIT_DISPLAYPOWER'
  955. ElvUF.Tags.Methods['classpower:current-max'] = function()
  956.     local min, max = GetClassPower(E.myclass)
  957.     if min == 0 then
  958.         return nil
  959.     else
  960.         return E:GetFormattedText('CURRENT_MAX', min, max)
  961.     end
  962. end
  963.  
  964. ElvUF.Tags.Events['classpower:current-max-percent'] = 'UNIT_POWER_FREQUENT UNIT_DISPLAYPOWER'
  965. ElvUF.Tags.Methods['classpower:current-max-percent'] = function()
  966.     local min, max = GetClassPower(E.myclass)
  967.     if min == 0 then
  968.         return nil
  969.     else
  970.         return E:GetFormattedText('CURRENT_MAX_PERCENT', min, max)
  971.     end
  972. end
  973.  
  974. ElvUF.Tags.Events['classpower:percent'] = 'UNIT_POWER_FREQUENT UNIT_DISPLAYPOWER'
  975. ElvUF.Tags.Methods['classpower:percent'] = function()
  976.     local min, max = GetClassPower(E.myclass)
  977.     if min == 0 then
  978.         return nil
  979.     else
  980.         return E:GetFormattedText('PERCENT', min, max)
  981.     end
  982. end
  983.  
  984. if E.myclass == 'MONK' then
  985.     local events = 'UNIT_POWER_FREQUENT UNIT_DISPLAYPOWER UNIT_AURA'
  986.     ElvUF.Tags.Events['classpower:current'] = events
  987.     ElvUF.Tags.Events['classpower:deficit'] = events
  988.     ElvUF.Tags.Events['classpower:current-percent'] = events
  989.     ElvUF.Tags.Events['classpower:current-max'] = events
  990.     ElvUF.Tags.Events['classpower:current-max-percent'] = events
  991.     ElvUF.Tags.Events['classpower:percent'] = events
  992. end
  993.  
  994. ElvUF.Tags.Events['absorbs'] = 'UNIT_ABSORB_AMOUNT_CHANGED'
  995. ElvUF.Tags.Methods['absorbs'] = function(unit)
  996.     local absorb = UnitGetTotalAbsorbs(unit) or 0
  997.     if absorb == 0 then
  998.         return nil
  999.     else
  1000.         return E:ShortValue(absorb)
  1001.     end
  1002. end
  1003.  
  1004. ElvUF.Tags.Events['incomingheals:personal'] = 'UNIT_HEAL_PREDICTION'
  1005. ElvUF.Tags.Methods['incomingheals:personal'] = function(unit)
  1006.     local heal = UnitGetIncomingHeals(unit, 'player') or 0
  1007.     if heal == 0 then
  1008.         return nil
  1009.     else
  1010.         return E:ShortValue(heal)
  1011.     end
  1012. end
  1013.  
  1014. ElvUF.Tags.Events['incomingheals:others'] = 'UNIT_HEAL_PREDICTION'
  1015. ElvUF.Tags.Methods['incomingheals:others'] = function(unit)
  1016.     local personal = UnitGetIncomingHeals(unit, 'player') or 0
  1017.     local heal = UnitGetIncomingHeals(unit) or 0
  1018.     local others = heal - personal
  1019.     if others == 0 then
  1020.         return nil
  1021.     else
  1022.         return E:ShortValue(others)
  1023.     end
  1024. end
  1025.  
  1026. ElvUF.Tags.Events['incomingheals'] = 'UNIT_HEAL_PREDICTION'
  1027. ElvUF.Tags.Methods['incomingheals'] = function(unit)
  1028.     local heal = UnitGetIncomingHeals(unit) or 0
  1029.     if heal == 0 then
  1030.         return nil
  1031.     else
  1032.         return E:ShortValue(heal)
  1033.     end
  1034. end
  1035.  
  1036. local GroupUnits = {}
  1037. local f = CreateFrame("Frame")
  1038.  
  1039. f:RegisterEvent("GROUP_ROSTER_UPDATE")
  1040. f:SetScript("OnEvent", function()
  1041.     local groupType, groupSize
  1042.     wipe(GroupUnits)
  1043.  
  1044.     if IsInRaid() then
  1045.         groupType = "raid"
  1046.         groupSize = GetNumGroupMembers()
  1047.     elseif IsInGroup() then
  1048.         groupType = "party"
  1049.         groupSize = GetNumGroupMembers() - 1
  1050.         GroupUnits.player = true
  1051.     else
  1052.         groupType = "solo"
  1053.         groupSize = 1
  1054.     end
  1055.  
  1056.     for index = 1, groupSize do
  1057.         local unit = groupType..index
  1058.         if not UnitIsUnit(unit, "player") then
  1059.             GroupUnits[unit] = true
  1060.         end
  1061.     end
  1062. end)
  1063.  
  1064. ElvUF.Tags.OnUpdateThrottle['nearbyplayers:8'] = 0.25
  1065. ElvUF.Tags.Methods['nearbyplayers:8'] = function(unit)
  1066.     local unitsInRange, d = 0
  1067.     if UnitIsConnected(unit) then
  1068.         for groupUnit in pairs(GroupUnits) do
  1069.             if not UnitIsUnit(unit, groupUnit) and UnitIsConnected(groupUnit) then
  1070.                 d = E:GetDistance(unit, groupUnit)
  1071.                 if d and d <= 8 then
  1072.                     unitsInRange = unitsInRange + 1
  1073.                 end
  1074.             end
  1075.         end
  1076.     end
  1077.  
  1078.     return unitsInRange
  1079. end
  1080.  
  1081. ElvUF.Tags.OnUpdateThrottle['nearbyplayers:10'] = 0.25
  1082. ElvUF.Tags.Methods['nearbyplayers:10'] = function(unit)
  1083.     local unitsInRange, d = 0
  1084.     if UnitIsConnected(unit) then
  1085.         for groupUnit in pairs(GroupUnits) do
  1086.             if not UnitIsUnit(unit, groupUnit) and UnitIsConnected(groupUnit) then
  1087.                 d = E:GetDistance(unit, groupUnit)
  1088.                 if d and d <= 10 then
  1089.                     unitsInRange = unitsInRange + 1
  1090.                 end
  1091.             end
  1092.         end
  1093.     end
  1094.  
  1095.     return unitsInRange
  1096. end
  1097.  
  1098. ElvUF.Tags.OnUpdateThrottle['nearbyplayers:30'] = 0.25
  1099. ElvUF.Tags.Methods['nearbyplayers:30'] = function(unit)
  1100.     local unitsInRange, d = 0
  1101.     if UnitIsConnected(unit) then
  1102.         for groupUnit in pairs(GroupUnits) do
  1103.             if not UnitIsUnit(unit, groupUnit) and UnitIsConnected(groupUnit) then
  1104.                 d = E:GetDistance(unit, groupUnit)
  1105.                 if d and d <= 30 then
  1106.                     unitsInRange = unitsInRange + 1
  1107.                 end
  1108.             end
  1109.         end
  1110.     end
  1111.  
  1112.     return unitsInRange
  1113. end
  1114.  
  1115. ElvUF.Tags.OnUpdateThrottle['distance'] = 0.1
  1116. ElvUF.Tags.Methods['distance'] = function(unit)
  1117.     local d
  1118.     if UnitIsConnected(unit) and not UnitIsUnit(unit, 'player') then
  1119.         d = E:GetDistance('player', unit)
  1120.  
  1121.         if d then
  1122.             d = format("%.1f", d)
  1123.         end
  1124.     end
  1125.  
  1126.     return d or nil
  1127. end
  1128.  
  1129. local baseSpeed = BASE_MOVEMENT_SPEED
  1130. local speedText = SPEED
  1131. ElvUF.Tags.OnUpdateThrottle['speed:percent'] = 0.1
  1132. ElvUF.Tags.Methods['speed:percent'] = function(unit)
  1133.     local currentSpeedInYards = GetUnitSpeed(unit)
  1134.     local currentSpeedInPercent = (currentSpeedInYards / baseSpeed) * 100
  1135.  
  1136.     return format("%s: %d%%", speedText, currentSpeedInPercent)
  1137. end
  1138.  
  1139. ElvUF.Tags.OnUpdateThrottle['speed:percent-moving'] = 0.1
  1140. ElvUF.Tags.Methods['speed:percent-moving'] = function(unit)
  1141.     local currentSpeedInYards = GetUnitSpeed(unit)
  1142.     local currentSpeedInPercent = currentSpeedInYards > 0 and ((currentSpeedInYards / baseSpeed) * 100)
  1143.  
  1144.     if currentSpeedInPercent then
  1145.         currentSpeedInPercent = format("%s: %d%%", speedText, currentSpeedInPercent)
  1146.     end
  1147.  
  1148.     return currentSpeedInPercent or nil
  1149. end
  1150.  
  1151. ElvUF.Tags.OnUpdateThrottle['speed:percent-raw'] = 0.1
  1152. ElvUF.Tags.Methods['speed:percent-raw'] = function(unit)
  1153.     local currentSpeedInYards = GetUnitSpeed(unit)
  1154.     local currentSpeedInPercent = (currentSpeedInYards / baseSpeed) * 100
  1155.  
  1156.     return format("%d%%", currentSpeedInPercent)
  1157. end
  1158.  
  1159. ElvUF.Tags.OnUpdateThrottle['speed:percent-moving-raw'] = 0.1
  1160. ElvUF.Tags.Methods['speed:percent-moving-raw'] = function(unit)
  1161.     local currentSpeedInYards = GetUnitSpeed(unit)
  1162.     local currentSpeedInPercent = currentSpeedInYards > 0 and ((currentSpeedInYards / baseSpeed) * 100)
  1163.  
  1164.     if currentSpeedInPercent then
  1165.         currentSpeedInPercent = format("%d%%", currentSpeedInPercent)
  1166.     end
  1167.  
  1168.     return currentSpeedInPercent or nil
  1169. end
  1170.  
  1171. ElvUF.Tags.OnUpdateThrottle['speed:yardspersec'] = 0.1
  1172. ElvUF.Tags.Methods['speed:yardspersec'] = function(unit)
  1173.     local currentSpeedInYards = GetUnitSpeed(unit)
  1174.  
  1175.     return format("%s: %.1f", speedText, currentSpeedInYards)
  1176. end
  1177.  
  1178. ElvUF.Tags.OnUpdateThrottle['speed:yardspersec-moving'] = 0.1
  1179. ElvUF.Tags.Methods['speed:yardspersec-moving'] = function(unit)
  1180.     local currentSpeedInYards = GetUnitSpeed(unit)
  1181.  
  1182.     return currentSpeedInYards > 0 and format("%s: %.1f", speedText, currentSpeedInYards) or nil
  1183. end
  1184.  
  1185. ElvUF.Tags.OnUpdateThrottle['speed:yardspersec-raw'] = 0.1
  1186. ElvUF.Tags.Methods['speed:yardspersec-raw'] = function(unit)
  1187.     local currentSpeedInYards = GetUnitSpeed(unit)
  1188.     return format("%.1f", currentSpeedInYards)
  1189. end
  1190.  
  1191. ElvUF.Tags.OnUpdateThrottle['speed:yardspersec-moving-raw'] = 0.1
  1192. ElvUF.Tags.Methods['speed:yardspersec-moving-raw'] = function(unit)
  1193.     local currentSpeedInYards = GetUnitSpeed(unit)
  1194.  
  1195.     return currentSpeedInYards > 0 and format("%.1f", currentSpeedInYards) or nil
  1196. end
  1197.  
  1198. ElvUF.Tags.Events['classificationcolor'] = 'UNIT_CLASSIFICATION_CHANGED'
  1199. ElvUF.Tags.Methods['classificationcolor'] = function(unit)
  1200.     local c = UnitClassification(unit)
  1201.     if(c == 'rare' or c == 'elite') then
  1202.         return Hex(1, 0.5, 0.25) --Orange
  1203.     elseif(c == 'rareelite' or c == 'worldboss') then
  1204.         return Hex(1, 0, 0) --Red
  1205.     end
  1206. end
  1207.  
  1208. ElvUF.Tags.SharedEvents.PLAYER_GUILD_UPDATE = true
  1209.  
  1210. ElvUF.Tags.Events['guild'] = 'UNIT_NAME_UPDATE PLAYER_GUILD_UPDATE'
  1211. ElvUF.Tags.Methods['guild'] = function(unit)
  1212.     if (UnitIsPlayer(unit)) then
  1213.         return GetGuildInfo(unit) or nil
  1214.     end
  1215. end
  1216.  
  1217. ElvUF.Tags.Events['guild:brackets'] = 'PLAYER_GUILD_UPDATE'
  1218. ElvUF.Tags.Methods['guild:brackets'] = function(unit)
  1219.     local guildName = GetGuildInfo(unit)
  1220.  
  1221.     return guildName and format("<%s>", guildName) or nil
  1222. end
  1223.  
  1224. ElvUF.Tags.Events['guild:translit'] = 'UNIT_NAME_UPDATE PLAYER_GUILD_UPDATE'
  1225. ElvUF.Tags.Methods['guild:translit'] = function(unit)
  1226.     if (UnitIsPlayer(unit)) then
  1227.         return Translit:Transliterate(GetGuildInfo(unit), translitMark) or nil
  1228.     end
  1229. end
  1230.  
  1231. ElvUF.Tags.Events['guild:brackets:translit'] = 'PLAYER_GUILD_UPDATE'
  1232. ElvUF.Tags.Methods['guild:brackets:translit'] = function(unit)
  1233.     local guildName = Translit:Transliterate(GetGuildInfo(unit), translitMark)
  1234.  
  1235.     return guildName and format("<%s>", guildName) or nil
  1236. end
  1237.  
  1238. ElvUF.Tags.Events['target:veryshort'] = 'UNIT_TARGET'
  1239. ElvUF.Tags.Methods['target:veryshort'] = function(unit)
  1240.     local targetName = UnitName(unit.."target")
  1241.     return targetName ~= nil and E:ShortenString(targetName, 5) or nil
  1242. end
  1243.  
  1244. ElvUF.Tags.Events['target:short'] = 'UNIT_TARGET'
  1245. ElvUF.Tags.Methods['target:short'] = function(unit)
  1246.     local targetName = UnitName(unit.."target")
  1247.     return targetName ~= nil and E:ShortenString(targetName, 10) or nil
  1248. end
  1249.  
  1250. ElvUF.Tags.Events['target:medium'] = 'UNIT_TARGET'
  1251. ElvUF.Tags.Methods['target:medium'] = function(unit)
  1252.     local targetName = UnitName(unit.."target")
  1253.     return targetName ~= nil and E:ShortenString(targetName, 15) or nil
  1254. end
  1255.  
  1256. ElvUF.Tags.Events['target:long'] = 'UNIT_TARGET'
  1257. ElvUF.Tags.Methods['target:long'] = function(unit)
  1258.     local targetName = UnitName(unit.."target")
  1259.     return targetName ~= nil and E:ShortenString(targetName, 20) or nil
  1260. end
  1261.  
  1262. ElvUF.Tags.Events['target'] = 'UNIT_TARGET'
  1263. ElvUF.Tags.Methods['target'] = function(unit)
  1264.     local targetName = UnitName(unit.."target")
  1265.     return targetName or nil
  1266. end
  1267.  
  1268. ElvUF.Tags.Events['target:veryshort:translit'] = 'UNIT_TARGET'
  1269. ElvUF.Tags.Methods['target:veryshort:translit'] = function(unit)
  1270.     local targetName = Translit:Transliterate(UnitName(unit.."target"), translitMark)
  1271.     return targetName ~= nil and E:ShortenString(targetName, 5) or nil
  1272. end
  1273.  
  1274. ElvUF.Tags.Events['target:short:translit'] = 'UNIT_TARGET'
  1275. ElvUF.Tags.Methods['target:short:translit'] = function(unit)
  1276.     local targetName = Translit:Transliterate(UnitName(unit.."target"), translitMark)
  1277.     return targetName ~= nil and E:ShortenString(targetName, 10) or nil
  1278. end
  1279.  
  1280. ElvUF.Tags.Events['target:medium:translit'] = 'UNIT_TARGET'
  1281. ElvUF.Tags.Methods['target:medium:translit'] = function(unit)
  1282.     local targetName = Translit:Transliterate(UnitName(unit.."target"), translitMark)
  1283.     return targetName ~= nil and E:ShortenString(targetName, 15) or nil
  1284. end
  1285.  
  1286. ElvUF.Tags.Events['target:long:translit'] = 'UNIT_TARGET'
  1287. ElvUF.Tags.Methods['target:long:translit'] = function(unit)
  1288.     local targetName = Translit:Transliterate(UnitName(unit.."target"), translitMark)
  1289.     return targetName ~= nil and E:ShortenString(targetName, 20) or nil
  1290. end
  1291.  
  1292. ElvUF.Tags.Events['target:translit'] = 'UNIT_TARGET'
  1293. ElvUF.Tags.Methods['target:translit'] = function(unit)
  1294.     local targetName = Translit:Transliterate(UnitName(unit.."target"), translitMark)
  1295.     return targetName or nil
  1296. end
  1297.  
  1298. ElvUF.Tags.Events['npctitle'] = 'UNIT_NAME_UPDATE'
  1299. ElvUF.Tags.Methods['npctitle'] = function(unit)
  1300.     if (UnitIsPlayer(unit)) then
  1301.         return
  1302.     end
  1303.  
  1304.     E.ScanTooltip:SetOwner(_G.UIParent, "ANCHOR_NONE")
  1305.     E.ScanTooltip:SetUnit(unit)
  1306.     E.ScanTooltip:Show()
  1307.  
  1308.     local Title = _G[format('ElvUI_ScanTooltipTextLeft%d', GetCVarBool('colorblindmode') and 3 or 2)]:GetText()
  1309.  
  1310.     if (Title and not Title:find('^'..LEVEL)) then
  1311.         return Title
  1312.     end
  1313. end
  1314.  
  1315. ElvUF.Tags.Events['guild:rank'] = 'UNIT_NAME_UPDATE'
  1316. ElvUF.Tags.Methods['guild:rank'] = function(unit)
  1317.     if (UnitIsPlayer(unit)) then
  1318.         return select(2, GetGuildInfo(unit)) or ''
  1319.     end
  1320. end
  1321.  
  1322. ElvUF.Tags.Events['arena:number'] = 'UNIT_NAME_UPDATE'
  1323. ElvUF.Tags.Methods['arena:number'] = function(unit)
  1324.     local _, instanceType = GetInstanceInfo()
  1325.     if instanceType == 'arena' then
  1326.         for i = 1, 5 do
  1327.             if UnitIsUnit(unit, "arena"..i) then
  1328.                 return i
  1329.             end
  1330.         end
  1331.     end
  1332. end
  1333.  
  1334. ElvUF.Tags.Events['class'] = 'UNIT_NAME_UPDATE'
  1335. ElvUF.Tags.Methods['class'] = function(unit)
  1336.     return UnitClass(unit)
  1337. end
  1338.  
  1339. ElvUF.Tags.Events['name:title'] = 'UNIT_NAME_UPDATE'
  1340. ElvUF.Tags.Methods['name:title'] = function(unit)
  1341.     if (UnitIsPlayer(unit)) then
  1342.         return UnitPVPName(unit)
  1343.     end
  1344. end
  1345.  
  1346. ElvUF.Tags.SharedEvents.QUEST_LOG_UPDATE = true
  1347.  
  1348. ElvUF.Tags.Events['quest:title'] = 'QUEST_LOG_UPDATE'
  1349. ElvUF.Tags.Methods['quest:title'] = function(unit)
  1350.     if UnitIsPlayer(unit) then
  1351.         return
  1352.     end
  1353.  
  1354.     E.ScanTooltip:SetOwner(_G.UIParent, "ANCHOR_NONE")
  1355.     E.ScanTooltip:SetUnit(unit)
  1356.     E.ScanTooltip:Show()
  1357.  
  1358.     local QuestName
  1359.  
  1360.     if E.ScanTooltip:NumLines() >= 3 then
  1361.         for i = 3, E.ScanTooltip:NumLines() do
  1362.             local QuestLine = _G['ElvUI_ScanTooltipTextLeft' .. i]
  1363.             local QuestLineText = QuestLine and QuestLine:GetText()
  1364.  
  1365.             local PlayerName, ProgressText = strmatch(QuestLineText, '^ ([^ ]-) ?%- (.+)$')
  1366.  
  1367.             if not ( PlayerName and PlayerName ~= '' and PlayerName ~= UnitName('player') ) then
  1368.                 if ProgressText then
  1369.                     QuestName = _G['ElvUI_ScanTooltipTextLeft' .. i - 1]:GetText()
  1370.                 end
  1371.             end
  1372.         end
  1373.         for i = 1, GetNumQuestLogEntries() do
  1374.             local title, level, _, isHeader = GetQuestLogTitle(i)
  1375.             if not isHeader and title == QuestName then
  1376.                 local colors = GetQuestDifficultyColor(level)
  1377.                 return Hex(colors.r, colors.g, colors.b)..QuestName..'|r'
  1378.             end
  1379.         end
  1380.     end
  1381. end
  1382.  
  1383. ElvUF.Tags.Events['quest:info'] = 'QUEST_LOG_UPDATE'
  1384. ElvUF.Tags.Methods['quest:info'] = function(unit)
  1385.     if UnitIsPlayer(unit) then
  1386.         return
  1387.     end
  1388.  
  1389.     E.ScanTooltip:SetOwner(_G.UIParent, "ANCHOR_NONE")
  1390.     E.ScanTooltip:SetUnit(unit)
  1391.     E.ScanTooltip:Show()
  1392.  
  1393.     local ObjectiveCount = 0
  1394.     local QuestName
  1395.  
  1396.     if E.ScanTooltip:NumLines() >= 3 then
  1397.         for i = 3, E.ScanTooltip:NumLines() do
  1398.             local QuestLine = _G['ElvUI_ScanTooltipTextLeft' .. i]
  1399.             local QuestLineText = QuestLine and QuestLine:GetText()
  1400.  
  1401.             local PlayerName, ProgressText = strmatch(QuestLineText, '^ ([^ ]-) ?%- (.+)$')
  1402.             if (not PlayerName or PlayerName == '' or PlayerName == UnitName('player')) and ProgressText then
  1403.                 local x, y
  1404.                 if not QuestName and ProgressText then
  1405.                     QuestName = _G['ElvUI_ScanTooltipTextLeft' .. i - 1]:GetText()
  1406.                 end
  1407.                 if ProgressText then
  1408.                     x, y = strmatch(ProgressText, '(%d+)/(%d+)')
  1409.                     if x and y then
  1410.                         local NumLeft = y - x
  1411.                         if NumLeft > ObjectiveCount then -- track highest number of objectives
  1412.                             ObjectiveCount = NumLeft
  1413.                             if ProgressText then
  1414.                                 return ProgressText
  1415.                             end
  1416.                         end
  1417.                     else
  1418.                         if ProgressText then
  1419.                             return QuestName .. ': ' .. ProgressText
  1420.                         end
  1421.                     end
  1422.                 end
  1423.             end
  1424.         end
  1425.     end
  1426. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top