idUnitframes = AceLibrary('AceAddon-2.0'):new('AceDB-2.0', 'AceEvent-2.0', 'AceHook-2.0') idUnitframes.Frames = {} function idUnitframes:OnEnable() -- Some vars self.Globalscale = 1 self.Globalalpha = 1 self.Backgroundpadding = 5 self.Backgroundposition = { x = 100, y = 100 } self.Healthbarwidth = 150 self.Healthbarheight = 15 self.Healthbartexture = 'Interface\\AddOns\\idUnitframes\\textures\\bar' self.Healthbarcolor = { r1 = 49/255, g1 = 227/255, b1 = 37/255 } self.Powerbarwidth = 150 self.Powerbarheight = 15 self.Powerbartexture = 'Interface\\AddOns\\idUnitframes\\textures\\bar' self.Powerbarcolor = { Druid = {r1 = 49/255, g1 = 37/255, b1 = 227/255}, Hunter = {r1 = 1.00, g1 = 1.00, b1 = 34/255}, Mage = {r1 = 49/255, g1 = 37/255, b1 = 227/255}, Paladin = {r1 = 49/255, g1 = 37/255, b1 = 227/255}, Priest = {r1 = 49/255, g1 = 37/255, b1 = 227/255}, Rogue = {r1 = 1.00, g1 = 1.00, b1 = 34/255}, Warlock = {r1 = 49/255, g1 = 37/255, b1 = 227/255}, Warrior = {r1 = 255/255, g1 = 0, b1 = 0} } self.Classnames = { Druid = 'Dru', Hunter = 'Hun', Mage = 'Mag', Paladin = 'Pal', Priest = 'Pri', Rogue = 'Rog', Shaman = 'Shm', Warlock = 'Wlk', Warrior = 'War' } self.Buffwidth = 40 self.Buffheight = 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() end function idUnitframes:OnDisable() end function 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.Healthbarcolor.r1/5, self.Healthbarcolor.g1/5, self.Healthbarcolor.b1/5, 1) self.Frames.player.Powerbar.Background:SetVertexColor(self.Powerbarcolor[UnitClass('player')].r1/5, self.Powerbarcolor[UnitClass('player')].g1/5, self.Powerbarcolor[UnitClass('player')].b1/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) end function 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.Healthbarcolor.r1/5, self.Healthbarcolor.g1/5, self.Healthbarcolor.b1/5, 1) self.Frames.target.Powerbar.Background:SetVertexColor(self.Powerbarcolor[UnitClass('target')].r1/5, self.Powerbarcolor[UnitClass('target')].g1/5, self.Powerbarcolor[UnitClass('target')].b1/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) end function 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.Healthbarwidth) Healthbar:SetHeight(self.Healthbarheight) Healthbar:SetScale(self.Globalscale) Healthbar:SetAlpha(self.Globalalpha) Healthbar:SetStatusBarTexture(self.Healthbartexture) Healthbar:SetStatusBarColor(self.Healthbarcolor.r1, self.Healthbarcolor.g1, self.Healthbarcolor.b1) Healthbar.Background:SetTexture('Interface\\Tooltips\\UI-Tooltip-Background') Healthbar.Background:SetAllPoints(Healthbar) Powerbar:SetWidth(self.Powerbarwidth) Powerbar:SetHeight(self.Powerbarheight) Powerbar:SetScale(self.Globalscale) Powerbar:SetAlpha(self.Globalalpha) Powerbar:SetStatusBarTexture(self.Powerbartexture) Powerbar:SetStatusBarColor(self.Powerbarcolor.r1, self.Powerbarcolor.g1, self.Powerbarcolor.b1) Powerbar.Background:SetTexture('Interface\\Tooltips\\UI-Tooltip-Background') Powerbar.Background:SetAllPoints(Powerbar) Background:SetWidth(self.Backgroundpadding*3 + self.Healthbarwidth + self.Powerbarwidth) Background:SetHeight(self.Backgroundpadding*2 + self.Healthbarheight) Background:SetScale(self.Globalscale) Background:SetAlpha(self.Globalalpha) 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 Background end function idUnitframes:updateHealth(Unit) local Health = UnitHealth(Unit) local Maxhealth = UnitHealthMax(Unit) local r1,g1,b1 = self.Healthbarcolor.r1, self.Healthbarcolor.g1, self.Healthbarcolor.b1 self.Frames[Unit].Healthbar:SetStatusBarColor(r1, g1, b1, 1) self.Frames[Unit].Healthbar:SetMinMaxValues(0, Maxhealth) self.Frames[Unit].Healthbar:SetValue(Health) end function idUnitframes:updatePower(Unit) local Health = UnitMana(Unit) local Maxhealth = UnitManaMax(Unit) local r1 = self.Powerbarcolor[UnitClass(Unit)].r1 local g1 = self.Powerbarcolor[UnitClass(Unit)].g1 local b1 = self.Powerbarcolor[UnitClass(Unit)].b1 self.Frames[Unit].Powerbar:SetStatusBarColor(r1, g1, b1, 1) self.Frames[Unit].Powerbar:SetMinMaxValues(0, Maxhealth) self.Frames[Unit].Powerbar:SetValue(Health) end function 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) end function 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() end end