-- MOVE TO TAGS FILE
local Truncate = function(num)
if num > 1e6 then
return format('%.1fM', num / 1e6)
elseif num > 1e4 then
return format('%.1fK', num / 1e3)
end
return num
end
oUF.TagEvents['[Indulgent.CurHP]'] = 'UNIT_HEALTH'
oUF.Tags['[Indulgent.CurHP]'] = function(unit)
return Truncate(UnitHealth(unit))
end
oUF.TagEvents['[Indulgent.PercHP]'] = 'UNIT_HEALTH UNIT_HEALTH_MAX'
oUF.Tags['[Indulgent.PercHP]'] = function(unit)
local percent = UnitHealth(unit) / UnitHealthMax(unit)
local r, g, b = oUF.ColorGradient(percent, unpack(oUF.colors.smooth))
return format('|cff%02x%02x%02x%d%%|r', r * 255, g * 255, b * 255, percent * 100)
end
oUF.TagEvents['[Indulgent.Name]'] = 'UNIT_NAME UNIT_FACTION_UPDATE'
oUF.Tags['[Indulgent.Name]'] = function(unit)
local r, g, b = 1, 1, 1
if UnitIsPlayer(unit) then
r, g, b = unpack(oUF.colors.class[select(2, UnitClass(unit))])
else
if not UnitIsFriend(unit, 'player') and UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) then
r, g, b = unpack(oUF.colors.disconnected)
else
if UnitReaction(unit, 'player') then
r, g, b = unpack(oUF.colors.reaction[UnitReaction(unit, 'player')])
end
end
end
return format('|cff%02x%02x%02x%s|r', r * 255, g * 255, b * 255, UnitName(unit))
end
------------------
local Px = 1024 / GetScreenWidth() / GetCVar('UIScale') * .7
local Texture1 = [[Interface\AddOns\oUF_Indulgent\HalF]] -- Health texture
local Texture2 = [[Interface\AddOns\oUF_Indulgent\Ish00]] -- Power and misc. texture
local Backdrop = {bgFile = [[Interface\ChatFrame\ChatFrameBackground]], insets = {left = -Px, right = -Px, top = -Px, bottom = -Px}}
local Colors = setmetatable({
power = setmetatable({
MANA = {.38, .4, .72},
ENERGY = {.72, .72, .38},
RUNIC_POWER = {.38, .72, .69},
RAGE = {.72, .38, .38},
}, {__index = oUF.colors.power})
}, {__index = oUF.colors})
local Factory = function(self, unit)
self:SetAttribute('initial-height', 24)
self:SetAttribute('initial-width', 180)
self:SetBackdrop(Backdrop)
self:SetBackdropColor(0, 0, 0)
self.colors = Colors
-- I've created the frames in order of draw layer, from lowest to highest
-- It's not necessary but I think it improves readability.
self.Power = CreateFrame('StatusBar', nil, self)
self.Power.frequentUpdates = true
self.Power.colorPower = true
self.Power:SetStatusBarTexture(Texture2)
self.Power:SetAllPoints()
self.Power.bg = self.Power:CreateTexture(nil, 'BACKGROUND')
self.Power.bg:SetTexture(Texture2)
self.Power.bg:SetVertexColor(.4, .4, .4)
self.Power.bg:SetAllPoints()
self.HealthBackdrop = CreateFrame('Frame', nil, self)
self.HealthBackdrop:SetFrameLevel(3)
self.HealthBackdrop:SetBackdrop(Backdrop)
self.HealthBackdrop:SetBackdropColor(0, 0, 0)
self.HealthBackdrop:SetPoint('TOPLEFT', Px * 2, -Px * 2)
self.HealthBackdrop:SetPoint('BOTTOMRIGHT', -Px * 2, Px * 2)
self.Health = CreateFrame('StatusBar', nil, self.HealthBackdrop)
self.Health:SetStatusBarTexture(Texture1)
self.Health:SetStatusBarColor(.18, .18, .18)
self.Health:SetAllPoints()
self.Health.bg = self.Health:CreateTexture(nil, 'BACKGROUND')
self.Health.bg.multiplier = .5
self.Health.bg:SetTexture(Texture1)
self.Health.bg:SetVertexColor(.25, .25, .25)
self.Health.bg:SetAllPoints()
if unit == 'player' then
elseif unit == 'target' then
self.Health.perc = self.Health:CreateFontString(nil, 'ARTWORK', 'GameFontNormalLarge')
self.Health.perc:SetPoint('RIGHT', -1, 1)
self:Tag(self.Health.perc, '[Indulgent.PercHP]')
self.Header = CreateFrame('Frame', nil, self)
self.Header:SetPoint('BOTTOMLEFT', self, 'TOPLEFT', 0, Px * 3)
self.Header:SetPoint('TOPRIGHT', 0, 16)
self.Header:SetBackdrop(Backdrop)
self.Header:SetBackdropColor(0, 0, 0)
self.Header.bg = self.Header:CreateTexture(nil, 'LOW')
self.Header.bg:SetTexture(Texture2)
self.Header.bg:SetVertexColor(.15, .15, .15)
self.Header.bg:SetAllPoints()
self.Name = self.Header:CreateFontString(nil, 'ARTWORK', 'GameFontNormalSmall')
self.Name:SetPoint('LEFT', 2, 1)
self:Tag(self.Name, '[Indulgent.Name]')
end
end
oUF:RegisterStyle('Indulgent', Factory)
oUF:SetActiveStyle('Indulgent')
oUF:Spawn('player', 'oUF_Indulgent_Player'):SetPoint('CENTER', -230, -200)
oUF:Spawn('target', 'oUF_Indulgent_Target'):SetPoint('CENTER', 0, -200)