Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local _, ns = ...
- local oUF = ns.oUF or oUF
- assert(oUF, 'oUF_AuraBars was unable to locate oUF install.')
- local function Round(number, decimalPlaces)
- if decimalPlaces and decimalPlaces > 0 then
- local mult = 10^decimalPlaces
- return math.floor(number * mult + .5) / mult
- end
- return math.floor(num + .5)
- end
- local function FormatTime(timeInSec)
- local h = math.floor(timeInSec / 3600)
- local m = math.floor((timeInSec - (3600 * h)) / 60)
- local s = math.floor(timeInSec - ((3600 * h) + (60 * m)))
- if h > 0 then
- return h .. ":" .. m .. " h"
- elseif m > 0 then
- return m .. " m"
- else
- return s .. " s"
- end
- end
- local framebd = function(parent, anchor)
- local frame = CreateFrame("Frame", nil, parent)
- frame:SetFrameStrata("BACKGROUND")
- frame:SetPoint("TOPLEFT", anchor, "TOPLEFT", -4, 4)
- frame:SetPoint("BOTTOMRIGHT", anchor, "BOTTOMRIGHT", 4, -4)
- frame:SetBackdrop({
- edgeFile = "Interface\\AddOns\\oUF_Skaarj\\Media\\glowTex", edgeSize = 5,
- bgFile = [=[Interface\ChatFrame\ChatFrameBackground]=],
- insets = {left = 4, right = 4, top = 4, bottom = 4}})
- frame:SetBackdropColor(0.8941176470588235, 0.9215686274509803, 0.8784313725490196,0.5)
- frame:SetBackdropBorderColor(0, 0, 0, 0)
- return frame
- end
- local function UpdateTooltip(self)
- GameTooltip:SetUnitAura(self.__unit, self:GetParent().aura.name, self:GetParent().aura.rank, self:GetParent().aura.filter)
- end
- local function OnEnter(self)
- if(not self:IsVisible()) then return end
- GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT")
- self:UpdateTooltip()
- end
- local function OnLeave(self)
- GameTooltip:Hide()
- end
- local function SetAnchors(self)
- local bars = self.bars
- for index = 1, #bars do
- local frame = bars[index]
- local anchor = frame.anchor
- frame:SetWidth(198)
- frame:ClearAllPoints()
- if self.down == true then
- if self == anchor then
- frame:SetPoint('TOPLEFT', anchor, 'BOTTOMLEFT', 15, 0)
- else
- frame:SetPoint('TOPLEFT', anchor, 'BOTTOMLEFT', 0, 0)
- end
- else
- if self == anchor then
- frame:SetPoint('BOTTOMLEFT', anchor, 'TOPLEFT', 15, 0)
- else
- frame:SetPoint('BOTTOMLEFT', anchor, 'TOPLEFT', 0, 0)
- end
- end
- end
- end
- local function CreateAuraBar(oUF, anchor)
- local auraBarParent = oUF.BuffBars or oUF.DebuffBars
- local frame = CreateFrame("Frame", nil, auraBarParent)
- frame:SetHeight(15)
- frame:SetWidth(198)
- frame.anchor = anchor
- local statusBar = CreateFrame("StatusBar", nil, frame)
- statusBar:SetStatusBarTexture("Interface\\AddOns\\oUF_Skaarj\\Media\\texture")
- statusBar:SetAlpha(.95)
- statusBar.bd = framebd(statusBar, statusBar)
- statusBar:SetAllPoints(frame)
- frame.statusBar = statusBar
- if auraBarParent.down == true then
- if auraBarParent == anchor then
- frame:SetPoint('TOPLEFT', anchor, 'BOTTOMLEFT', 0, 0)
- else
- frame:SetPoint('TOPLEFT', anchor, 'BOTTOMLEFT', 0, 0)
- end
- else
- if auraBarParent == anchor then
- frame:SetPoint('BOTTOMLEFT', anchor, 'TOPLEFT', 0, 0)
- else
- frame:SetPoint('BOTTOMLEFT', anchor, 'TOPLEFT', 0, 0)
- end
- end
- statusBar.iconHolder = CreateFrame('Button', nil, statusBar)
- statusBar.iconHolder:SetHeight(frame:GetHeight())
- statusBar.iconHolder:SetWidth(frame:GetHeight())
- statusBar.iconHolder:SetPoint('BOTTOMRIGHT', frame, 'BOTTOMLEFT', 0, 0)
- statusBar.iconHolder.bd = framebd(statusBar.iconHolder, statusBar.iconHolder)
- statusBar.iconHolder.__unit = oUF.unit
- statusBar.iconHolder:SetScript('OnEnter', OnEnter)
- statusBar.iconHolder:SetScript('OnLeave', OnLeave)
- statusBar.iconHolder.UpdateTooltip = UpdateTooltip
- statusBar.icon = statusBar.iconHolder:CreateTexture(nil, 'BACKGROUND')
- statusBar.icon:SetTexCoord(.07, .93, .07, .93)
- statusBar.icon:SetAllPoints()
- statusBar.spelltime = statusBar:CreateFontString(nil, 'ARTWORK')
- statusBar.spelltime:SetFont("Interface\\AddOns\\oUF_Skaarj\\Media\\pixel.ttf", 9, "Outlinemonochrome")
- statusBar.spelltime:SetTextColor(1 ,1, 1)
- statusBar.spelltime:SetJustifyH'RIGHT'
- statusBar.spelltime:SetJustifyV'CENTER'
- statusBar.spelltime:SetPoint'RIGHT'
- statusBar.spellname = statusBar:CreateFontString(nil, 'ARTWORK')
- statusBar.spellname:SetFont("Interface\\AddOns\\oUF_Skaarj\\Media\\pixel.ttf", 8, "Outlinemonochrome")
- statusBar.spellname:SetTextColor(1, 1, 1)
- statusBar.spellname:SetJustifyH'LEFT'
- statusBar.spellname:SetJustifyV'CENTER'
- statusBar.spellname:SetPoint('LEFT', 2, 0)
- statusBar.spellname:SetPoint('RIGHT', statusBar.spelltime, 'LEFT')
- return frame
- end
- local function UpdateBars(auraBars)
- local bars = auraBars.bars
- local timenow = GetTime()
- for index = 1, #bars do
- local frame = bars[index]
- local bar = frame.statusBar
- if not frame:IsVisible() then
- break
- end
- if bar.aura.noTime then --something weird here
- bar.spelltime:SetText()
- else
- local timeleft = bar.aura.expirationTime - timenow
- bar:SetValue(timeleft)
- bar.spelltime:SetText(FormatTime(timeleft))
- end
- end
- end
- local sort = function(a, b)
- local compa, compb = a.noTime and math.huge or a.expirationTime, b.noTime and math.huge or b.expirationTime
- return compa > compb
- end
- local buffs = {}
- local function UpdateBuff(self, event, unit)
- if self.unit ~= unit then return end
- local BuffBars = self.BuffBars
- local numBuffs = 0
- for i = 1, 40 do
- local name, rank, icon, count, debuffType, duration, expirationTime, unitCaster, isStealable, shouldConsolidate, spellID = UnitBuff(unit, i)
- if not name then break end
- if BuffBars.filter(self, unit, name, rank, icon, count, debuffType, duration, expirationTime, unitCaster, isStealable, shouldConsolidate, spellID) then
- local t = buffs[i] or {}
- t.name = name
- t.rank = rank
- t.icon = icon
- t.count = count
- t.debuffType = debuffType
- t.duration = duration
- t.expirationTime = expirationTime
- t.unitCaster = unitCaster
- t.isStealable = isStealable
- t.noTime = (duration == 0 and expirationTime == 0)
- t.filter = BuffBars.friendlyAuraType
- t.shouldConsolidate = shouldConsolidate
- t.spellID = spellID
- buffs[i] = t
- numBuffs = i
- end
- end
- for i = numBuffs + 1, #buffs do
- buffs[i] = nil
- end
- if BuffBars.sort then
- table.sort(buffs, type(BuffBars.sort) == 'function' and BuffBars.sort or nil) -- no need to pass the global "sort"
- end
- local bars = BuffBars.bars
- for i = 1, #buffs do
- if BuffBars:GetWidth() == 0 then
- break
- end
- local frame = bars[i]
- if not frame then
- frame = CreateAuraBar(self, i == 1 and BuffBars or bars[i - 1])
- bars[i] = frame
- end
- local bar = frame.statusBar
- frame.i = i
- local aura = buffs[i]
- bar.aura = aura
- if aura.noTime then
- bar:SetMinMaxValues(0, 1)
- bar:SetValue(1)
- else
- if BuffBars.scaleTime then
- local maxvalue = math.min(BuffBars.scaleTime, bar.aura.duration)
- bar:SetMinMaxValues(0, maxvalue)
- bar:SetWidth((maxvalue/BuffBars.scaleTime)*((BuffBars.auraBarWidth or BuffBars:GetWidth())-(bar:GetHeight()+(BuffBars.gap or 0))))-- icon size + gap
- else
- bar:SetMinMaxValues(0, aura.duration)
- end
- bar:SetValue(aura.expirationTime - GetTime())
- end
- bar.icon:SetTexture(aura.icon)
- bar.spellname:SetText(aura.count > 1 and string.format("%s [%d]", bar.aura.name, aura.count) or aura.name)
- bar.spelltime:SetText(not bar.noTime and FormatTime(aura.expirationTime-GetTime()))
- bar:SetStatusBarColor(.05, .05, .05)
- frame:Show()
- end
- for i = #buffs + 1, #bars do
- bars[i]:Hide()
- end
- end
- local debuffs = {}
- local function UpdateDebuff(self, event, unit)
- if self.unit ~= unit then return end
- local DebuffBars = self.DebuffBars
- local numDebuffs = 0
- for i = 1, 40 do
- local name, rank, icon, count, debuffType, duration, expirationTime, unitCaster, isStealable, shouldConsolidate, spellID = UnitDebuff(unit, i)
- if not name then break end
- if DebuffBars.filter(self, unit, name, rank, icon, count, debuffType, duration, expirationTime, unitCaster, isStealable, shouldConsolidate, spellID) then
- local t = debuffs[i] or {}
- t.name = name
- t.rank = rank
- t.icon = icon
- t.count = count
- t.debuffType = debuffType
- t.duration = duration
- t.expirationTime = expirationTime
- t.unitCaster = unitCaster
- t.isStealable = isStealable
- t.noTime = (duration == 0 and expirationTime == 0)
- t.filter = DebuffBars.enemyAuraType
- t.shouldConsolidate = shouldConsolidate
- t.spellID = spellID
- debuffs[i] = t
- numDebuffs = i
- end
- end
- for i = numDebuffs + 1, #debuffs do
- debuffs[i] = nil
- end
- if DebuffBars.sort then
- table.sort(debuffs, type(DebuffBars.sort) == 'function' and DebuffBars.sort or nil)
- end
- local bars = DebuffBars.bars
- for i = 1, #debuffs do
- if DebuffBars:GetWidth() == 0 then
- break
- end
- local frame = bars[i]
- if not frame then
- frame = CreateAuraBar(self, i == 1 and DebuffBars or bars[i - 1])
- bars[i] = frame
- end
- local bar = frame.statusBar
- frame.i = i
- local aura = debuffs[i]
- bar.aura = aura
- if aura.noTime then -- something weird here
- bar:SetMinMaxValues(0, 1)
- bar:SetValue(1)
- else
- if DebuffBars.scaleTime then
- local maxvalue = math.min(DebuffBars.scaleTime, bar.aura.duration)
- bar:SetMinMaxValues(0, maxvalue)
- bar:SetWidth((maxvalue/DebuffBars.scaleTime)*((DebuffBars.auraBarWidth or DebuffBars:GetWidth())-(bar:GetHeight()+(DebuffBars.gap or 0))))-- icon size + gap
- else
- bar:SetMinMaxValues(0, aura.duration)
- end
- bar:SetValue(aura.expirationTime - GetTime())
- end
- bar.icon:SetTexture(aura.icon)
- bar.spellname:SetText(aura.count > 1 and string.format("%s [%d]", bar.aura.name, aura.count) or aura.name)
- bar.spelltime:SetText(not bar.noTime and FormatTime(aura.expirationTime-GetTime()))
- local debuffType = bar.aura.debuffType and bar.aura.debuffType or 'none'
- r, g, b = DebuffTypeColor[debuffType].r, DebuffTypeColor[debuffType].g, DebuffTypeColor[debuffType].b
- if DebuffBars.debuffColor then
- r, g, b = unpack(DebuffBars.debuffColor)
- end
- bar:SetStatusBarColor(r, g, b)
- frame:Show()
- end
- for i = #debuffs + 1, #bars do
- bars[i]:Hide()
- end
- end
- local function EnableBuff(self)
- if self.BuffBars then
- self:RegisterEvent('UNIT_AURA', UpdateBuff)
- self.BuffBars:SetHeight(15)
- self.BuffBars.bars = self.BuffBars.bars or {}
- self.BuffBars.SetAnchors = SetAnchors
- self.BuffBars:SetScript('OnUpdate', UpdateBars)
- return true
- end
- end
- local function EnableDebuff(self)
- if self.DebuffBars then
- self:RegisterEvent('UNIT_AURA', UpdateDebuff)
- self.DebuffBars:SetHeight(15)
- self.DebuffBars.bars = self.DebuffBars.bars or {}
- self.DebuffBars.SetAnchors = SetAnchors
- self.DebuffBars:SetScript('OnUpdate', UpdateBars)
- return true
- end
- end
- local function DisableBuff(self)
- local auraFrame = self.BuffBars
- if auraFrame then
- self:UnregisterEvent('UNIT_AURA', UpdateBuff)
- auraFrame:SetScript('OnUpdate', nil)
- end
- end
- local function DisableDebuff(self)
- local auraFrame = self.DebuffBars
- if auraFrame then
- self:UnregisterEvent('UNIT_AURA', UpdateDebuff)
- auraFrame:SetScript('OnUpdate', nil)
- end
- end
- oUF:AddElement('BuffBars', UpdateBuff, EnableBuff, DisableBuff)
- oUF:AddElement('DebuffBars', UpdateDebuff, EnableDebuff, DisableDebuff)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement