- -- Start config
- local font = [=[Interface\AddOns\oUF_Test\media\Simple.TTF]=]
- local texture = [=[Interface\AddOns\oUF_Test\media\Statusbar]=]
- local font_size = 11
- local font_style = 'THINOUTLINE'
- local sfix = CreateFrame("Frame")
- sfix:RegisterEvent("PLAYER_LOGIN")
- sfix:SetScript("OnEvent", function()
- SetCVar("useUiScale", 1)
- SetCVar("uiScale", 768/string.match(({GetScreenResolutions()})[GetCurrentResolution()], "%d+x(%d+)"))
- end)
- _G["BuffFrame"]:Hide()
- _G["BuffFrame"]:UnregisterAllEvents()
- _G["BuffFrame"]:SetScript("OnUpdate", nil)
- local backdrop = {
- bgFile = [=[Interface\Buttons\WHITE8x8]=],
- edgeFile = [=[Interface\Buttons\WHITE8x8]=], edgeSize = 1,
- insets = {top = 0, bottom = 0, right = 0, left = 0}
- }
- local CreateBackdrop = function(parent)
- local bg = CreateFrame("Frame", nil, parent)
- bg:SetPoint('TOPLEFT', parent, 'TOPLEFT', -1, 1)
- bg:SetPoint('BOTTOMRIGHT', parent, 'BOTTOMRIGHT', 1, -1)
- bg:SetFrameLevel(parent:GetFrameLevel() - 1)
- bg:SetBackdrop(backdrop)
- bg:SetBackdropColor(0, 0, 0, 0.6)
- bg:SetBackdropBorderColor(0, 0, 0, 1)
- return bg
- end
- local CreateFontString = function(frame, fsize, fstyle, sfont)
- local fstring = frame:CreateFontString(nil, 'OVERLAY')
- fstring:SetFont(font, font_size, font_style)
- fstring:SetShadowColor(0, 0, 0, 0)
- return fstring
- end
- local menu = function(self)
- local unit = self.unit:gsub("(.)", string.upper, 1)
- if _G[unit.."FrameDropDown"] then
- ToggleDropDownMenu(1, nil, _G[unit.."FrameDropDown"], "cursor")
- elseif self.unit:match("party") then
- ToggleDropDownMenu(1, nil, _G["PartyMemberFrame"..self.id.."DropDown"], "cursor")
- else
- FriendsDropDown.unit = self.unit
- FriendsDropDown.id = self.id
- FriendsDropDown.initialize = RaidFrameDropDown_Initialize
- ToggleDropDownMenu(1, nil, FriendsDropDown, "cursor")
- end
- end
- local SetColors = setmetatable({
- power = setmetatable({
- ["MANA"] = {0.31, 0.45, 0.63},
- ["RAGE"] = {0.69, 0.31, 0.31},
- ["FOCUS"] = {0.71, 0.43, 0.27},
- ["ENERGY"] = {0.65, 0.63, 0.35},
- ["HAPPINESS"] = {0.19, 0.58, 0.58},
- ["RUNES"] = {0.55, 0.57, 0.61},
- ["RUNIC_POWER"] = {0, 0.82, 1},
- }, {__index = oUF.colors.power}),
- reaction = setmetatable({
- [1] = {0.85, 0.27, 0.27}, -- Hated
- [2] = {0.85, 0.27, 0.27}, -- Hostile
- [3] = {0.85, 0.27, 0.27}, -- Unfriendly
- [4] = {0.85, 0.77, 0.36}, -- Neutral
- [5] = {0.33, 0.59, 0.33}, -- Friendly
- [6] = {0.33, 0.59, 0.33}, -- Honored
- [7] = {0.33, 0.59, 0.33}, -- Revered
- [8] = {0.33, 0.59, 0.33}, -- Exalted
- }, {__index = oUF.colors.reaction}),
- }, {__index = oUF.colors})
- local FormatTime = function(s)
- local DAY, HOUR, MINUTE = 86400, 3600, 60
- if s >= DAY then
- return format('%dd', floor(s/DAY + 0.5)), s % DAY
- elseif s >= HOUR then
- return format('%dh', floor(s/HOUR + 0.5)), s % HOUR
- elseif s >= MINUTE then
- return format('%dm', floor(s/MINUTE + 0.5)), s % MINUTE
- end
- return floor(s + 0.5), s - floor(s)
- end
- UpdateAuraTimer = function(self, elapsed)
- if self.timeLeft then
- self.elapsed = (self.elapsed or 0) + elapsed
- if self.elapsed >= 0.1 then
- if not self.first then
- self.timeLeft = self.timeLeft - self.elapsed
- else
- self.timeLeft = self.timeLeft - GetTime()
- self.first = false
- end
- if self.timeLeft > 0 then
- local time = FormatTime(self.timeLeft)
- self.remaining:SetText(time)
- if self.timeLeft < 5 then
- self.remaining:SetTextColor(1, 0.2, 0.2)
- else
- self.remaining:SetTextColor(1, 1, 1)
- end
- else
- self.remaining:Hide()
- self:SetScript("OnUpdate", nil)
- end
- self.elapsed = 0
- end
- end
- end
- CreateAuraTimer = function(icon, duration, expTime)
- icon.first = true
- if duration and duration > 0 then
- icon.remaining:Show()
- icon.timeLeft = expTime
- icon:SetScript("OnUpdate", UpdateAuraTimer)
- else
- icon.remaining:Hide()
- icon.timeLeft = 0
- icon:SetScript("OnUpdate", nil)
- end
- end
- PostUpdateDebuff = function(self, unit, icon, index)
- local name, _, _, _, dtype, duration, expTime = UnitAura(unit, index, icon.filter)
- local c = DebuffTypeColor[dtype] or DebuffTypeColor.none
- icon.bg:SetBackdropBorderColor(c.r, c.g, c.b)
- icon.icon:SetDesaturated(true)
- CreateAuraTimer(icon, duration, expTime)
- end
- PostUpdateBuff = function(self, unit, icon, index)
- local name, _, _, _, dtype, duration, expTime = UnitAura(unit, index, icon.filter)
- CreateAuraTimer(icon, duration, expTime)
- end
- local CancelAura = function(self, button)
- if button == "RightButton" and not self.debuff then
- CancelUnitBuff("player", self:GetID())
- end
- end
- PostCreateAuraIcon = function(self, button)
- button.icon:SetTexCoord(0.07, 0.93, 0.07, 0.93)
- button.icon:SetDrawLayer('ARTWORK')
- button.overlay:SetTexture(nil)
- button.remaining = CreateFontString(button)
- button.remaining:SetPoint('CENTER', 1, 1)
- button.count:SetFont(font, font_size, font_style)
- button.count:SetPoint('TOPRIGHT', button, 3, 19)
- button.bg = CreateBackdrop(button)
- if unit == "player" then
- button:SetScript("OnMouseUp", CancelAura)
- end
- end
- local ShortValue = function(value)
- if value >= 10000000 then
- return string.format('%.1fm', value / 1000000)
- elseif value >= 1000000 then
- return string.format('%.2fm', value / 1000000)
- elseif value >= 100000 then
- return string.format('%.0fk', value / 1000)
- elseif value >= 10000 then
- return string.format('%.1fk', value / 1000)
- else
- return value
- end
- end
- local PostUpdateHealthBar = function(health, unit, min, max)
- if not UnitIsConnected(unit) or UnitIsGhost(unit) or UnitIsDead(unit) then
- if not UnitIsConnected(unit) then
- health.value:SetText("|cffD7BEA5".."Offline".."|r")
- elseif UnitIsDead(unit) then
- health.value:SetText("|cffD7BEA5".."Dead".."|r")
- elseif UnitIsGhost(unit) then
- health.value:SetText("|cffD7BEA5".."Ghost".."|r")
- end
- else
- local r, g, b
- if min ~= max then
- r, g, b = oUF.ColorGradient(min/max, 0.69, 0.31, 0.31, 0.65, 0.63, 0.35, 0.33, 0.59, 0.33)
- if unit == "player" and health:GetAttribute("normalUnit") ~= "pet" then
- health.value:SetFormattedText("|cffAF5050%d|r |cffD7BEA5-|r |cff%02x%02x%02x%s%%|r", min, r * 255, g * 255, b * 255, math.floor(min /max*100+.5))
- elseif unit == "pet" then
- health.value:SetFormattedText("|cff%02x%02x%02x%s|r", r * 255, g * 255, b * 255, ShortValue(min))
- else
- health.value:SetFormattedText("|cffAF5050%s|r |cffD7BEA5-|r |cff%02x%02x%02x%s%%|r", ShortValue(min), r * 255, g * 255, b * 255, math.floor(min /max*100+.5))
- end
- else
- if unit ~= "player" and unit ~= "pet" then
- health.value:SetText("|cff559655"..ShortValue(max).."|r")
- else
- health.value:SetText("|cff559655"..max.."|r")
- end
- end
- end
- end
- PreUpdatePower = function(power, unit)
- local _, pType = UnitPowerType(unit)
- local color = SetColors.power[pType]
- if color then
- power:SetStatusBarColor(color[1], color[2], color[3])
- end
- end
- PostUpdatePower = function(power, unit, min, max)
- local self = power:GetParent()
- local pType, pToken = UnitPowerType(unit)
- local color = SetColors.power[pToken]
- if color then
- power.value:SetTextColor(color[1], color[2], color[3])
- end
- if not UnitIsPlayer(unit) and not UnitPlayerControlled(unit) or not UnitIsConnected(unit) then
- power.value:SetText()
- elseif UnitIsDead(unit) or UnitIsGhost(unit) then
- power.value:SetText()
- else
- if min ~= max then
- if pType == 0 then
- if unit == "target" then
- power.value:SetText(ShortValue(min))
- elseif unit == "player" and power:GetAttribute("normalUnit") == "pet" then
- power.value:SetFormattedText("%%s%%", math.floor(min /max*100+.5))
- elseif unit == "player" then
- power.value:SetFormattedText("%s%% |cffD7BEA5-|r %d", math.floor(min /max*100+.5), min)
- else
- power.value:SetText(min)
- end
- else
- power.value:SetText(min)
- end
- else
- if unit == "player" or unit == 'arena' then
- power.value:SetText(min)
- else
- power.value:SetText(ShortValue(min))
- end
- end end
- end
- local CreateStyle = function(self, unit)
- self:RegisterForClicks('AnyUp')
- self:SetScript('OnEnter', UnitFrame_OnEnter)
- self:SetScript('OnLeave', UnitFrame_OnLeave)
- self.colors = SetColors
- self:SetAttribute('type2', 'menu')
- self.menu = menu
- self.Health = CreateFrame('StatusBar', nil, self)
- self.Health:SetStatusBarTexture(texture)
- self.Health:SetHeight(25)
- self.Health:SetPoint('TOPLEFT')
- self.Health:SetPoint('TOPRIGHT')
- self.Health.PostUpdate = PostUpdateHealthBar
- self.Health.frequentUpdates = true
- self.Health.colorTapping = true
- self.Health.colorClass = true
- self.Health.colorReaction = true
- self.Health.bg = self.Health:CreateTexture(nil, 'BORDER')
- self.Health.bg:SetAllPoints()
- self.Health.bg:SetTexture(texture)
- self.Health.bg.multiplier = 0.25
- self.Health.background = CreateBackdrop(self.Health)
- self.Health.value = CreateFontString(self.Health)
- if unit == 'player' or unit == 'target' then
- self.Health.value:SetPoint('RIGHT', 0, 4)
- elseif unit == 'pet' or unit == 'focus' or unit == 'targettarget' then
- self.Health.value:SetPoint('LEFT', 0, 1)
- end
- self.Power = CreateFrame('StatusBar', nil, self)
- self.Power:SetStatusBarTexture(texture)
- self.Power:SetHeight(4)
- self.Power:SetFrameLevel(10)
- self.Power:SetPoint('TOPRIGHT', self.Health, 'BOTTOMRIGHT', 0, 0)
- self.Power:SetPoint('TOPLEFT', self.Health, 'BOTTOMLEFT', 0, 0)
- self.Power.PreUpdate = PreUpdatePower
- self.Power.PostUpdate = PostUpdatePower
- self.Power.bg = self.Power:CreateTexture(nil, 'BORDER')
- self.Power.bg:SetAllPoints()
- self.Power.bg:SetTexture(texture)
- self.Power.bg.multiplier = 0.3
- self.Power.background = CreateBackdrop(self.Power)
- self.Power.frequentUpdates = true
- self.Power.colorDisconnected = true
- self.Power.colorTapping = true
- self.Power.colorPower = true
- self.Power.value = CreateFontString(self.Power)
- if unit == 'player' or unit == 'target' then
- self.Power.value:SetPoint('RIGHT', 0, 3)
- end
- self.Info = CreateFontString(self.Health)
- if unit == 'target' then
- self.Info:SetPoint('LEFT', 0, 4)
- self:Tag(self.Info, '[difficulty][level][shortclassification] [raidcolor][name]')
- elseif (not unit == 'player') or unit == 'pet' or unit == 'focus' or unit == 'targettarget' then
- self.Info:SetPoint('RIGHT', 0, 1)
- self:Tag(self.Info, '[raidcolor][name]')
- end
- if unit == 'player' or unit == 'target' then
- self:SetAttribute('initial-height', 25)
- self:SetAttribute('initial-width', 205)
- elseif unit == 'pet' or unit == 'focus' or unit == 'targettarget' then
- self:SetAttribute('initial-height', 15)
- self:SetAttribute('initial-width', 130)
- self.Health:SetHeight(15)
- self.Power:SetHeight(2)
- end
- self.Resting = self.Health:CreateTexture(nil, "OVERLAY")
- self.Resting:SetHeight(20)
- self.Resting:SetWidth(20)
- self.Resting:SetPoint('RIGHT', self, 0, 4)
- self.Combat = self.Health:CreateTexture(nil, "OVERLAY")
- self.Combat:SetHeight(20)
- self.Combat:SetWidth(20)
- self.Combat:SetPoint('LEFT', self, 0, 4)
- self.Leader = self.Health:CreateTexture(nil, 'OVERLAY')
- self.Leader:SetPoint('TOPLEFT', self, 0, 5)
- self.Leader:SetHeight(12)
- self.Leader:SetWidth(12)
- self.RaidIcon = self.Health:CreateTexture(nil, 'OVERLAY')
- self.RaidIcon:SetPoint('TOPRIGHT', self, 0, 5)
- self.RaidIcon:SetHeight(12)
- self.RaidIcon:SetWidth(12)
- self.Assistant = self.Health:CreateTexture(nil, "OVERLAY")
- self.Assistant:SetPoint('TOPLEFT', 0, 5)
- self.Assistant:SetHeight(12)
- self.Assistant:SetWidth(12)
- self.MasterLooter = self.Health:CreateTexture(nil, "OVERLAY")
- self.MasterLooter:SetPoint('TOP', 0, 5)
- self.MasterLooter:SetHeight(12)
- self.MasterLooter:SetWidth(12)
- self.Portrait = CreateFrame("PlayerModel", nil, self)
- self.Portrait:SetWidth(29)
- self.Portrait:SetHeight(29)
- if unit == 'player' then
- self.Portrait:SetPoint('LEFT', self.Health, 'LEFT', -32, -2)
- elseif unit == 'target' then
- self.Portrait:SetPoint('RIGHT', self.Health, 'RIGHT', 32, -2)
- end
- self.Portrait.bg = CreateBackdrop(self.Portrait)
- if unit == 'player' then
- self.Buffs = CreateFrame("Frame", nil, self)
- self.Buffs:SetPoint('TOPRIGHT', UIParent, 'TOPRIGHT', -150, -9)
- self.Buffs.initialAnchor = 'TOPRIGHT'
- self.Buffs["growth-y"] = 'DOWN'
- self.Buffs["growth-x"] = 'LEFT'
- self.Buffs:SetHeight(55)
- self.Buffs:SetWidth(450)
- self.Buffs.spacing = 3
- self.Buffs.size = 26
- self.Buffs.num = 32
- self.Buffs.disableCooldown = true
- self.Buffs.PostCreateIcon = PostCreateAuraIcon
- self.Buffs.PostUpdateIcon = PostUpdateBuff
- self.Debuffs = CreateFrame("Frame", nil, self)
- self.Debuffs:SetPoint('TOPRIGHT', UIParent, 'TOPRIGHT', -150, -116)
- self.Debuffs.initialAnchor = 'TOPRIGHT'
- self.Debuffs["growth-x"] = 'LEFT'
- self.Debuffs["growth-y"] = 'DOWN'
- self.Debuffs:SetHeight(55)
- self.Debuffs:SetWidth(450)
- self.Debuffs.spacing = 3
- self.Debuffs.size = 26
- self.Debuffs.num = 32
- self.Debuffs.disableCooldown = true
- self.Debuffs.PostCreateIcon = PostCreateAuraIcon
- self.Debuffs.PostUpdateIcon = PostUpdateDebuff
- elseif unit == 'target' then
- self.Auras = CreateFrame("Frame", nil, self)
- self.Auras:SetPoint('BOTTOMLEFT', self, 'TOPLEFT', 0, 3)
- self.Auras.initialAnchor = 'BOTTOMLEFT'
- self.Auras["growth-x"] = 'RIGHT'
- self.Auras["growth-y"] = 'UP'
- self.Auras.numDebuffs = 16
- self.Auras.numBuffs = 32
- self.Auras:SetHeight(165)
- self.Auras:SetWidth(221)
- self.Auras.spacing = 3
- self.Auras.size = 23
- self.Auras.gap = true
- self.Auras.disableCooldown = true
- self.Auras.PostCreateIcon = PostCreateAuraIcon
- self.Auras.PostUpdateIcon = PostUpdateBuff
- end
- self.Castbar = CreateFrame("StatusBar", nil, self)
- self.Castbar:SetStatusBarTexture(texture)
- self.Castbar:SetStatusBarColor(0.31, 0.45, 0.63)
- self.Castbar.bg = CreateBackdrop(self.Castbar)
- self.Castbar.Text = CreateFontString(self.Castbar)
- self.Castbar.Text:SetPoint('LEFT', 0, 1)
- self.Castbar.Time = CreateFontString(self.Castbar)
- self.Castbar.Time:SetPoint('RIGHT', 0, 1)
- self.Castbar.Button = CreateFrame('Frame', nil, self.Castbar)
- self.Castbar.Button:SetHeight(18)
- self.Castbar.Button:SetWidth(18)
- if unit == 'player' then
- self.Castbar.Button:SetPoint('BOTTOMRIGHT', self.Castbar, 'BOTTOMLEFT', -3, 0)
- elseif unit == 'target' then
- self.Castbar.Button:SetPoint('BOTTOMLEFT', self.Castbar, 'BOTTOMRIGHT', 3, 0)
- end
- self.Castbar.Button.bg = CreateBackdrop(self.Castbar.Button)
- self.Castbar.Icon = self.Castbar.Button:CreateTexture(nil, 'ARTWORK')
- self.Castbar.Icon:SetAllPoints(self.Castbar.Button)
- self.Castbar.Icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
- if unit == 'player' or unit == 'target' then
- self.Castbar:SetWidth(205)
- self.Castbar:SetHeight(15)
- self.Castbar:SetPoint('BOTTOM', self.Health, 0, -22)
- end
- end
- oUF:Factory(function(self)
- oUF:RegisterStyle('Alt', CreateStyle)
- self:SetActiveStyle('Alt')
- local player = self:Spawn('player')
- player:SetPoint('BOTTOM', UIParent, -150, 300)
- local target = self:Spawn('target')
- target:SetPoint('BOTTOM', UIParent, 150, 300)
- local focus = self:Spawn('focus')
- focus:SetPoint('BOTTOM', UIParent, 321, 310)
- local pet = self:Spawn('pet')
- pet:SetPoint('BOTTOM', UIParent, -187, 260)
- local targettarget = self:Spawn('targettarget')
- targettarget:SetPoint('BOTTOM', UIParent, 188, 260)
- end)
oUF Layout