All pastes #80517 Raw Edit

Industrial

public lua v1 · immutable
·published 2006-07-06 14:25 UTC
rendered paste body
idUnitframes = AceLibrary('AceAddon-2.0'):new('AceDB-2.0', 'AceEvent-2.0', 'AceHook-2.0')idUnitframes.Frames = {}function idUnitframes:OnEnable()    idUnitframes.Constants = {        Global = {            Scale = 1,            Alpha = 1        },        Background = {            Padding = 5,        },        Bar = {            Width = 150,            Height = 15,            Texture = 'Interface\\AddOns\\idUnitframes\\textures\\bar'        },        Healthbar = {            Color = {                r = 49/255,                g = 227/255,                b = 37/255            }        },        Powerbar = {            Color = {                Druid   = {r = 49/255,  g = 37/255, b = 227/255},                Hunter  = {r = 1.00,    g = 1.00,   b = 34/255},                Mage    = {r = 49/255,  g = 37/255, b = 227/255},                Paladin = {r = 49/255,  g = 37/255, b = 227/255},                Priest  = {r = 49/255,  g = 37/255, b = 227/255},                Rogue   = {r = 1.00,    g = 1.00,   b = 34/255},                Warlock = {r = 49/255,  g = 37/255, b = 227/255},                Warrior = {r = 255/255, g = 0,      b = 0}            }        },        Nametext = {            Class = {                Druid = 'Dru',                Hunter = 'Hun',                Mage = 'Mag',                Paladin = 'Pal',                Priest = 'Pri',                Rogue = 'Rog',                Shaman = 'Shm',                Warlock = 'Wlk',                Warrior = 'War'            }        },        Buff = {            Width = 40,            Height = 40        }    }    self:createPlayerframe()    --self:createPetframe()    --self:createTargetframe()    --self:createTargettargetframe()    self.Frames.player:SetPoint('BOTTOM', UIParent, 'BOTTOM', 0, 110)    PlayerFrame:Hide()    self.Frames.player:Show()    --self.Frames.Pet:Show()    --self.Frames.target:SetPoint('BOTTOM', self.Frames.player, 'TOP', 0, 0)    --TargetFrame:Hide()    --self.Frames.Target:Show()    --self.Frames.Targettarget:Show()endfunction idUnitframes:OnDisable()    self.Constants = nilendfunction idUnitframes:createPlayerframe()    self.Frames.player = self:newFrame()    self.Frames.player:ClearAllPoints()    self.Frames.player:SetPoint('CENTER', UIParent, 'CENTER')    self:updateHealth('player')    self:updatePower('player')    self.Frames.player.Healthbar.Background:SetVertexColor(self.Constants.Healthbar.Color.r/5, self.Constants.Healthbar.Color.g/5, self.Constants.Healthbar.Color.b/5, 1)    self.Frames.player.Powerbar.Background:SetVertexColor(self.Constants.Powerbar.Color[UnitClass('player')].r/5, self.Constants.Powerbar.Color[UnitClass('player')].g/5, self.Constants.Powerbar.Color[UnitClass('player')].b/5, 1)    self:updateBuffs('player')    self:updateDebuffs('player')    self:RegisterEvent('UNIT_HEALTH', function()        if arg1 == 'player' then            self:updateHealth('player')        end    end)    self:RegisterEvent('UNIT_MAX_HEALTH', function()        if arg1 == 'player' then            self:updateHealth('player')        end    end)    self:RegisterEvent('UNIT_MANA', function()        if arg1 == 'player' then            self:updatePower('player')        end    end)    self:RegisterEvent('UNIT_MAXMANA', function()        if arg1 == 'player' then            self:updatePower('player')        end    end)    self:RegisterEvent('UNIT_RAGE', function()        if arg1 == 'player' then            self:updatePower('player')        end    end)    self:RegisterEvent('UNIT_MAXRAGE', function()        if arg1 == 'player' then            self:updatePower('player')        end    end)    self:RegisterEvent('UNIT_AURA', function()        if arg1 == 'player' then            self:updateBuffs('player')            self:updateDebuffs('player')        end    end)endfunction idUnitframes:createTargetframe()    self.Frames.target = self:newFrame()    self.Frames.target:ClearAllPoints()    self.Frames.target:SetPoint('CENTER', UIParent, 'CENTER')    self:updateHealth('target')    self:updatePower('target')    self.Frames.target.Healthbar.Background:SetVertexColor(self.Constants.Healthbar.Color.r/5, self.Constants.Healthbar.Color.g/5, self.Constants.Healthbar.Color.b/5, 1)    self.Frames.target.Powerbar.Background:SetVertexColor(self.Constants.Powerbar.Color[UnitClass('target')].r/5, self.Constants.Powerbar.Color[UnitClass('target')].g/5, self.Constants.Powerbar.Color[UnitClass('target')].b/5, 1)    self:updateBuffs('target')    self:updateDebuffs('target')    self:RegisterEvent('UNIT_HEALTH', function()        if arg1 == 'target' then            self:updateHealth('target')        end    end)    self:RegisterEvent('UNIT_MAX_HEALTH', function()        if arg1 == 'target' then            self:updateHealth('target')        end    end)    self:RegisterEvent('UNIT_MANA', function()        if arg1 == 'target' then            self:updatePower('target')        end    end)    self:RegisterEvent('UNIT_MAXMANA', function()        if arg1 == 'target'            then self:updatePower('target')        end    end)    self:RegisterEvent('UNIT_RAGE', function()        if arg1 == 'target' then            self:updatePower('target')        end    end)    self:RegisterEvent('UNIT_MAXRAGE', function()        if arg1 == 'target' then            self:updatePower('target') end        end)    self:RegisterEvent('UNIT_AURA', function()        if arg1 == 'target' then            self:updateBuffs('target')            self:updateDebuffs('target')        end    end)endfunction idUnitframes:newFrame()    local Font, _, _ = GameFontHighlightSmall:GetFont()    local Background = CreateFrame('Frame', name, UIParent)    local Healthbar = CreateFrame('StatusBar', nil, Background)    Healthbar.Background = Healthbar:CreateTexture(nil, 'BACKGROUND')    local Powerbar = CreateFrame('StatusBar', nil, Background)    Powerbar.Background = Powerbar:CreateTexture(nil, 'BACKGROUND')    local Name = Background:CreateFontString(nil, 'OVERLAY')    local Debuffs = CreateFrame('Frame', nil, Background)    local Buffs = CreateFrame('Frame', nil, Background)    Healthbar:SetWidth(self.Constants.Bar.Width)    Healthbar:SetHeight(self.Constants.Bar.Height)    Healthbar:SetScale(self.Constants.Global.Scale)    Healthbar:SetAlpha(self.Constants.Global.Aplha)    Healthbar:SetStatusBarTexture(self.Constants.Bar.Texture)    Healthbar:SetStatusBarColor(self.Constants.Healthbar.Color.r, self.Constants.Healthbar.Color.g, self.Constants.Healthbar.Color.b)    Healthbar.Background:SetTexture('Interface\\Tooltips\\UI-Tooltip-Background')    Healthbar.Background:SetAllPoints(Healthbar)    Powerbar:SetWidth(self.Powerbarwidth)    Powerbar:SetHeight(self.Powerbarheight)    Powerbar:SetScale(self.Constants.Global.Scale)    Powerbar:SetAlpha(self.Constants.Global.Aplha)    Powerbar:SetStatusBarTexture(self.Powerbartexture)    Powerbar:SetStatusBarColor(self.Constants.Powerbar.Color.r, self.Constants.Powerbar.Color.g, self.Constants.Powerbar.Color.b)    Powerbar.Background:SetTexture('Interface\\Tooltips\\UI-Tooltip-Background')    Powerbar.Background:SetAllPoints(Powerbar)    Background:SetWidth(self.Backgroundpadding*3 + self.Constants.Bar.Width + self.Powerbarwidth)    Background:SetHeight(self.Backgroundpadding*2 + self.Constants.Bar.Height)    Background:SetScale(self.Constants.Global.Scale)    Background:SetAlpha(self.Constants.Global.Aplha)    Background:SetBackdrop({        bgFile = 'Interface\\Tooltips\\UI-Tooltip-Background',        edgeFile = '',        edgeSize = 0,        tile = true,        tileSize = 16,        insets = {left = 0, right = 0, top = 0, bottom = 0}    })    Background:SetBackdropColor(0,0,0,0.6)    Name:SetFontObject(GameFontNormal)    Name:SetFont(Font, 11)    Name:SetHeight(Background:GetHeight())    Name:SetWidth(Healthbar:GetWidth())    Name:SetTextColor(1, 1, 1)    Name:SetJustifyH('RIGHT')    Name:SetJustifyV('CENTER')    Name:SetText(string.format('%s %s %s', UnitName('player'), UnitLevel('player'), self.Classnames[UnitClass('player')]))    Debuffs[1] = CreateFrame('Button', nil, Debuffs)    Debuffs[1].Icon = Debuffs[1]:CreateTexture(nil, 'BACKGROUND')    Debuffs[1]:SetWidth(0) -- buffs fill in from the right    Debuffs[1]:SetHeight(Background:GetHeight())    Debuffs[1]:ClearAllPoints()    Debuffs[1]:SetPoint('LEFT', Debuffs, 'LEFT')    Debuffs[1].Icon:SetAllPoints(Debuffs[1])    Buffs[1] = CreateFrame('Button', nil, Buffs)    Buffs[1].Icon = Buffs[1]:CreateTexture(nil, 'BACKGROUND')    Buffs[1]:SetWidth(0) -- buffs fill in from the right    Buffs[1]:SetHeight(Background:GetHeight())    Buffs[1]:ClearAllPoints()    Buffs[1]:SetPoint('LEFT', Buffs, 'LEFT')    Buffs[1].Icon:SetAllPoints(Buffs[1])    for i=2,16 do        Debuffs[i] = CreateFrame('Button', nil, Debuffs)        Debuffs[i].Icon = Debuffs[i]:CreateTexture(nil, 'BACKGROUND')        Debuffs[i]:SetWidth(0) -- buffs fill in from the right        Debuffs[i]:SetHeight(Background:GetHeight())        Debuffs[i]:ClearAllPoints()        Debuffs[i]:SetPoint('LEFT', Debuffs[i-1], 'RIGHT')        Debuffs[i].Icon:SetAllPoints(Debuffs[i])        Debuffs[i]:Show()        Buffs[i] = CreateFrame('Button', nil, Buffs)        Buffs[i].Icon = Buffs[i]:CreateTexture(nil, 'BACKGROUND')        Buffs[i]:SetWidth(0) -- buffs fill in from the right        Buffs[i]:SetHeight(Background:GetHeight())        Buffs[i]:ClearAllPoints()        Buffs[i]:SetPoint('LEFT', Buffs[i-1], 'RIGHT')        Buffs[i].Icon:SetAllPoints(Buffs[i])        Buffs[i]:Show()    end    Debuffs:SetHeight(Background:GetHeight())    Debuffs:ClearAllPoints()    Debuffs:SetPoint('LEFT', Background, 'RIGHT', self.Backgroundpadding, 0)    Buffs:SetHeight(Background:GetHeight())    Buffs:ClearAllPoints()    Buffs:SetPoint('LEFT', Debuffs, 'RIGHT', self.Backgroundpadding, 0)    Healthbar:SetPoint('TOPLEFT', Background, 'TOPLEFT', self.Backgroundpadding, -self.Backgroundpadding)    Powerbar:SetPoint('LEFT', Healthbar, 'RIGHT', self.Backgroundpadding, 0)    Name:SetPoint('RIGHT', Background, 'LEFT', -self.Backgroundpadding, 0)    Background.Healthbar = Healthbar    Background.Powerbar = Powerbar    Background.Name = Name    Background.Debuffs = Debuffs    Background.Buffs = Buffs    return Backgroundendfunction idUnitframes:updateHealth(Unit)    local Health = UnitHealth(Unit)    local Maxhealth = UnitHealthMax(Unit)    local r,g,b = self.Constants.Healthbar.Color.r, self.Constants.Healthbar.Color.g, self.Constants.Healthbar.Color.b    self.Frames[Unit].Healthbar:SetStatusBarColor(r, g, b, 1)    self.Frames[Unit].Healthbar:SetMinMaxValues(0, Maxhealth)    self.Frames[Unit].Healthbar:SetValue(Health)endfunction idUnitframes:updatePower(Unit)    local Health = UnitMana(Unit)    local Maxhealth = UnitManaMax(Unit)    local r = self.Constants.Powerbar.Color[UnitClass(Unit)].r    local g = self.Constants.Powerbar.Color[UnitClass(Unit)].g    local b = self.Constants.Powerbar.Color[UnitClass(Unit)].b    self.Frames[Unit].Powerbar:SetStatusBarColor(r, g, b, 1)    self.Frames[Unit].Powerbar:SetMinMaxValues(0, Maxhealth)    self.Frames[Unit].Powerbar:SetValue(Health)endfunction idUnitframes:updateBuffs(Unit)    local Buff    local Buffslength = 0    for i = 1, 16 do        Buff = UnitBuff(Unit, i)        if (Buff) then            self.Frames[Unit].Buffs[i]:SetWidth(self.Frames[Unit]:GetHeight())            self.Frames[Unit].Buffs[i].Icon:SetTexture(Buff)            self.Frames[Unit].Buffs[i].index = i            Buffslength = Buffslength + self.Frames[Unit].Buffs[i]:GetWidth()        else            self.Frames[Unit].Buffs[i].Icon:SetTexture(nil)            self.Frames[Unit].Buffs[i].index = nil            self.Frames[Unit].Buffs[i]:SetWidth(0)        end        Buff = nil    end    self.Frames[Unit].Buffs:SetWidth(self.Backgroundpadding+Buffslength)endfunction idUnitframes:updateDebuffs(Unit)    local Buff    local Buffslength = 0    for i = 1, 16 do        Buff = UnitDebuff(Unit, i)        if (Buff) then            self.Frames[Unit].Debuffs[i]:SetWidth(self.Frames[Unit]:GetHeight())            self.Frames[Unit].Debuffs[i].Icon:SetTexture(Buff)            self.Frames[Unit].Debuffs[i].index = i            Buffslength = Buffslength + self.Frames[Unit].Debuffs[i]:GetWidth()        else            self.Frames[Unit].Debuffs[i].Icon:SetTexture(nil)            self.Frames[Unit].Debuffs[i].index = nil            self.Frames[Unit].Debuffs[i]:SetWidth(0)        end        Buff = nil    end    if Buffslength > 0 then        self.Frames[Unit].Buffs:ClearAllPoints()        self.Frames[Unit].Buffs:SetPoint('LEFT', self.Frames[Unit].Debuffs, 'RIGHT', self.Backgroundpadding, 0)        self.Frames[Unit].Debuffs:Show()        self.Frames[Unit].Debuffs:SetWidth(Buffslength)    else        self.Frames[Unit].Buffs:ClearAllPoints()        self.Frames[Unit].Buffs:SetPoint('LEFT', self.Frames[Unit], 'RIGHT', self.Backgroundpadding, 0)        self.Frames[Unit].Debuffs:Hide()    endend