Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2013
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.47 KB | None | 0 0
  1. -- CONFIG? CONFIG.
  2. local shortennames = false  -- Shorten names to a set number of characters (truncating)
  3. local namelength = 10       -- Number of characters
  4. local lowercapsname = false -- Makes names lowercaps only
  5.  
  6. -- No touchy, it's sensitive
  7. local addon, ns = ...
  8. local oUF = ns.oUF or oUF
  9.  
  10. --[[
  11.     Shortens values, thanks to p3lim
  12.     For example
  13.         13822hp = 13.8k
  14.         138222 = 138k
  15.         1382222 = 1.38m
  16.    
  17.     1e3 = 1*10^3 = 1'000
  18.     1e4 = 1*10^4 = 10'000
  19.     1e5 = 1*10^5 = 100'000
  20.     1e6 = 1*10^6 = 1'000'000
  21. ]]--
  22. local function ShortValue(value)
  23.     if(value >= 1e6) then
  24.         return ('%.2fm'):format(value / 1e6)
  25.     elseif(value >= 1e5) then
  26.         return ('%.0fk'):format(value / 1e3)
  27.     elseif(value >= 1e4) then
  28.         return ('%.1fk'):format(value / 1e3)
  29.     else
  30.         return value
  31.     end
  32. end
  33.  
  34. --[[
  35.     Outputs a string depending on the status of the unit
  36.     If unit is disconnected it'll show "Offline" etc.
  37. ]]--
  38. local function Status(unit)
  39.     if(not UnitIsConnected(unit)) then
  40.         return 'Offline'
  41.     elseif(UnitIsGhost(unit)) then
  42.         return 'Ghost'
  43.     elseif(UnitIsDead(unit)) then
  44.         return 'Dead'
  45.     end
  46. end
  47.  
  48. -- Simple tag that shows status differences based on the function at line 38
  49. oUF.Tags.Methods['opstatus'] = Status
  50. oUF.Tags.Events['opstatus'] = 'UNIT_CONNECTION'
  51.  
  52. --[[
  53.     Stolen from Zork, colors nametags mostly
  54.     Changed name of tag to avoid confusion if errors show up
  55.    
  56.    
  57. --]]
  58. local function RGBPercToHex(r, g, b)
  59.     r = r <= 1 and r >= 0 and r or 1
  60.     g = g <= 1 and g >= 0 and g or 1
  61.     b = b <= 1 and b >= 0 and b or 1
  62.     return format("%02x%02x%02x", r*255, g*255, b*255)
  63. end
  64. oUF.Tags.Methods["opcolor"] = function(unit)
  65.     local color = { r=1, g=1, b=1, }
  66.     if UnitIsPlayer(unit) then
  67.         color = RAID_CLASS_COLORS[select(2, UnitClass(unit))]
  68.     elseif UnitIsUnit(unit, "target") and UnitIsTapped("target") and not UnitIsTappedByPlayer("target") then
  69.         color = {r = 0.5, g = 0.5, b = 0.5}
  70.     else
  71.         color = FACTION_BAR_COLORS[UnitReaction(unit, "player")]
  72.     end
  73.     if color then
  74.         return RGBPercToHex(color.r,color.g,color.b)
  75.     else
  76.         return "ffffff"
  77.     end
  78. end
  79.  
  80. --[[
  81.     HP output
  82.         Starts with two variables that determine current health and max health (just to make it simpler)
  83.         Then check if current health is less than max health
  84.             if it is then output current health in shortened form via the function on line 22 and percent hp
  85.             if it isnt then output max health in shortened form via the function on line 22
  86.            
  87.     Can be made shorter by just returning cur, but keeping as is for easy changing down the road
  88. --]]
  89. oUF.Tags.Methods['ophealth'] = function(unit)
  90.     local cur, max = UnitHealth(unit), UnitHealthMax(unit)
  91.    
  92.     if(not UnitIsDeadOrGhost(unit)) then
  93.         if(UnitHealth(unit) ~= max) then
  94.             return ('%s (%s)'):format(ShortValue(cur), oUF.Tags.Methods["perhp"](unit)..'%')
  95.         else
  96.             return ('%s'):format(ShortValue(max))
  97.         end
  98.     end
  99. end
  100. oUF.Tags.Events['ophealth'] = 'UNIT_HEALTH UNIT_MAXHEALTH'
  101.  
  102. --[[
  103.     HP output for player only
  104.     Starts with two variables that determine current health and max health (just to make it simpler)
  105.         Then check if current health is less than max health
  106.             if it is then output current health in shortened form via the function on line 22
  107.             if it isnt then show nothing
  108. --]]
  109. oUF.Tags.Methods['opphealth'] = function(unit)
  110.     local cur, max = UnitHealth(unit), UnitHealthMax(unit)
  111.    
  112.     if(UnitHealth(unit) ~= max and not UnitIsDeadOrGhost(unit)) then
  113.         return ('%s (%s)'):format(ShortValue(cur), oUF.Tags.Methods["perhp"](unit)..'%')
  114.     else
  115.         return
  116.     end
  117. end
  118. oUF.Tags.Events['opphealth'] = 'UNIT_HEALTH UNIT_MAXHEALTH'
  119.  
  120. --[[
  121.     Power output (Mana, Energy etc)
  122.    
  123.     if max power return nothing
  124.     if not max power then check power type
  125.         if power type is mana then return current mana in shortened form
  126.         if power type is not mana then return current power colored by type
  127. --]]
  128. oUF.Tags.Methods['oppower'] = function(unit)
  129.     local power = UnitPower(unit)
  130.     if(power > 0 and not UnitIsDeadOrGhost(unit)) then
  131.         if power == UnitPowerMax(unit) then
  132.             return
  133.         else
  134.             local _, type = UnitPowerType(unit)
  135.             local colors = _COLORS.power
  136.             if type == 'MANA' then
  137.                 return ('%s'):format(ShortValue(power))
  138.             else
  139.                 return ('%s%d|r'):format(Hex(colors[type] or colors['RUNES']), power)
  140.             end
  141.         end
  142.     end
  143. end
  144. oUF.Tags.Events['oppower'] = 'UNIT_POWER UNIT_MAXPOWER'
  145.  
  146. --[[
  147.     Name output
  148. ]]--
  149. oUF.Tags.Methods['opname'] = function(unit)
  150.     local name = UnitName(unit)
  151.     local lowername = string.lower(name)
  152.     local color = oUF.Tags.Methods["opcolor"](unit)
  153.    
  154.     if shortennames == true and lowercapsname == true then
  155.         return ('%s'):format('|cff'..color..(string.sub(lowername, 1, namelength))..'|r')
  156.     elseif shortennames == false and lowercapsname == true then
  157.         return ('%s'):format('|cff'..color..(lowername)..'|r')
  158.     elseif shortennames == true and lowercapsname == false then
  159.         return ('%s'):format('|cff'..color..(string.sub(name, 1, namelength))..'|r')
  160.     else
  161.         return '|cff'..color..(name or '')..'|r'
  162.     end
  163. end
  164. oUF.Tags.Events['opname'] = 'UNIT_NAME'
  165.  
  166. --[[
  167.     Party outputs
  168. ]]--
  169. oUF.Tags.Methods['oppartyhp'] = function(unit)
  170.     local cur, max = UnitHealth(unit), UnitHealthMax(unit)
  171.    
  172.     if(cur ~= max and not UnitIsDeadOrGhost(unit)) then
  173.         return ('|cffff0000-%s|r'):format(ShortValue(max - cur))
  174.     else
  175.         return ('%s'):format(ShortValue(max))
  176.     end
  177. end
  178.  
  179. oUF.Tags.Methods['oppartypp'] = function(unit)
  180.     local cur, max = UnitPower(unit), UnitPowerMax(unit)
  181.    
  182.     if(not UnitIsDeadOrGhost(unit)) then
  183.         return ('%s'):format(oUF.Tags.Methods["perhp"](unit))
  184.     end
  185. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement