Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- CONFIG? CONFIG.
- local shortennames = false -- Shorten names to a set number of characters (truncating)
- local namelength = 10 -- Number of characters
- local lowercapsname = false -- Makes names lowercaps only
- -- No touchy, it's sensitive
- local addon, ns = ...
- local oUF = ns.oUF or oUF
- --[[
- Shortens values, thanks to p3lim
- For example
- 13822hp = 13.8k
- 138222 = 138k
- 1382222 = 1.38m
- 1e3 = 1*10^3 = 1'000
- 1e4 = 1*10^4 = 10'000
- 1e5 = 1*10^5 = 100'000
- 1e6 = 1*10^6 = 1'000'000
- ]]--
- local function ShortValue(value)
- if(value >= 1e6) then
- return ('%.2fm'):format(value / 1e6)
- elseif(value >= 1e5) then
- return ('%.0fk'):format(value / 1e3)
- elseif(value >= 1e4) then
- return ('%.1fk'):format(value / 1e3)
- else
- return value
- end
- end
- --[[
- Outputs a string depending on the status of the unit
- If unit is disconnected it'll show "Offline" etc.
- ]]--
- local function Status(unit)
- if(not UnitIsConnected(unit)) then
- return 'Offline'
- elseif(UnitIsGhost(unit)) then
- return 'Ghost'
- elseif(UnitIsDead(unit)) then
- return 'Dead'
- end
- end
- -- Simple tag that shows status differences based on the function at line 38
- oUF.Tags.Methods['opstatus'] = Status
- oUF.Tags.Events['opstatus'] = 'UNIT_CONNECTION'
- --[[
- Stolen from Zork, colors nametags mostly
- Changed name of tag to avoid confusion if errors show up
- --]]
- local function RGBPercToHex(r, g, b)
- r = r <= 1 and r >= 0 and r or 1
- g = g <= 1 and g >= 0 and g or 1
- b = b <= 1 and b >= 0 and b or 1
- return format("%02x%02x%02x", r*255, g*255, b*255)
- end
- oUF.Tags.Methods["opcolor"] = function(unit)
- local color = { r=1, g=1, b=1, }
- if UnitIsPlayer(unit) then
- color = RAID_CLASS_COLORS[select(2, UnitClass(unit))]
- elseif UnitIsUnit(unit, "target") and UnitIsTapped("target") and not UnitIsTappedByPlayer("target") then
- color = {r = 0.5, g = 0.5, b = 0.5}
- else
- color = FACTION_BAR_COLORS[UnitReaction(unit, "player")]
- end
- if color then
- return RGBPercToHex(color.r,color.g,color.b)
- else
- return "ffffff"
- end
- end
- --[[
- HP output
- Starts with two variables that determine current health and max health (just to make it simpler)
- Then check if current health is less than max health
- if it is then output current health in shortened form via the function on line 22 and percent hp
- if it isnt then output max health in shortened form via the function on line 22
- Can be made shorter by just returning cur, but keeping as is for easy changing down the road
- --]]
- oUF.Tags.Methods['ophealth'] = function(unit)
- local cur, max = UnitHealth(unit), UnitHealthMax(unit)
- if(not UnitIsDeadOrGhost(unit)) then
- if(UnitHealth(unit) ~= max) then
- return ('%s (%s)'):format(ShortValue(cur), oUF.Tags.Methods["perhp"](unit)..'%')
- else
- return ('%s'):format(ShortValue(max))
- end
- end
- end
- oUF.Tags.Events['ophealth'] = 'UNIT_HEALTH UNIT_MAXHEALTH'
- --[[
- HP output for player only
- Starts with two variables that determine current health and max health (just to make it simpler)
- Then check if current health is less than max health
- if it is then output current health in shortened form via the function on line 22
- if it isnt then show nothing
- --]]
- oUF.Tags.Methods['opphealth'] = function(unit)
- local cur, max = UnitHealth(unit), UnitHealthMax(unit)
- if(UnitHealth(unit) ~= max and not UnitIsDeadOrGhost(unit)) then
- return ('%s (%s)'):format(ShortValue(cur), oUF.Tags.Methods["perhp"](unit)..'%')
- else
- return
- end
- end
- oUF.Tags.Events['opphealth'] = 'UNIT_HEALTH UNIT_MAXHEALTH'
- --[[
- Power output (Mana, Energy etc)
- if max power return nothing
- if not max power then check power type
- if power type is mana then return current mana in shortened form
- if power type is not mana then return current power colored by type
- --]]
- oUF.Tags.Methods['oppower'] = function(unit)
- local power = UnitPower(unit)
- if(power > 0 and not UnitIsDeadOrGhost(unit)) then
- if power == UnitPowerMax(unit) then
- return
- else
- local _, type = UnitPowerType(unit)
- local colors = _COLORS.power
- if type == 'MANA' then
- return ('%s'):format(ShortValue(power))
- else
- return ('%s%d|r'):format(Hex(colors[type] or colors['RUNES']), power)
- end
- end
- end
- end
- oUF.Tags.Events['oppower'] = 'UNIT_POWER UNIT_MAXPOWER'
- --[[
- Name output
- ]]--
- oUF.Tags.Methods['opname'] = function(unit)
- local name = UnitName(unit)
- local lowername = string.lower(name)
- local color = oUF.Tags.Methods["opcolor"](unit)
- if shortennames == true and lowercapsname == true then
- return ('%s'):format('|cff'..color..(string.sub(lowername, 1, namelength))..'|r')
- elseif shortennames == false and lowercapsname == true then
- return ('%s'):format('|cff'..color..(lowername)..'|r')
- elseif shortennames == true and lowercapsname == false then
- return ('%s'):format('|cff'..color..(string.sub(name, 1, namelength))..'|r')
- else
- return '|cff'..color..(name or '')..'|r'
- end
- end
- oUF.Tags.Events['opname'] = 'UNIT_NAME'
- --[[
- Party outputs
- ]]--
- oUF.Tags.Methods['oppartyhp'] = function(unit)
- local cur, max = UnitHealth(unit), UnitHealthMax(unit)
- if(cur ~= max and not UnitIsDeadOrGhost(unit)) then
- return ('|cffff0000-%s|r'):format(ShortValue(max - cur))
- else
- return ('%s'):format(ShortValue(max))
- end
- end
- oUF.Tags.Methods['oppartypp'] = function(unit)
- local cur, max = UnitPower(unit), UnitPowerMax(unit)
- if(not UnitIsDeadOrGhost(unit)) then
- return ('%s'):format(oUF.Tags.Methods["perhp"](unit))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement