--BobHUD, an extremely simple HUD addon
local _, cfg = ... --export config
local addon, ns = ... --get addon namespace
local f = CreateFrame("Button","BobPlayerHUD",UIParent,"SecureUnitButtonTemplate")
f.unit = "player" --change to unit you want to track
--Make the Health Bar
--background texture
f.back = f:CreateTexture(nil,"BACKGROUND")
f.back:SetSize(unpack(cfg.barsize))
f.back:SetPoint("CENTER",UIParent,cfg.healthx,cfg.healthy)
f.back:SetTexture("Interface\\Addons\\BobHUD\\media\\healthbar")
f.back:SetVertexColor(0,0,0,0.5)
--health bar
f.hp = CreateFrame("StatusBar",nil,f,"TextStatusBar")
f.hp:SetSize(unpack(cfg.barsize))
f.hp:SetPoint("CENTER",UIParent,cfg.healthx,cfg.healthy)
f.hp:SetStatusBarTexture("Interface\\Addons\\BobHUD\\media\\healthbar")
f.hp:SetStatusBarColor(0,.8,0)
f.hp:SetMinMaxValues(0,1)
f.hp:SetOrientation("VERTICAL")
f.hp:EnableMouse(0)
f.hp:SetAlpha(cfg.alpha)
--health fontstring
f.HealthText = f:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
f.HealthText:SetPoint("BOTTOM",f.hp,2,0)
--percent
f.HealthText2 = f:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
f.HealthText2:SetPoint("BOTTOM",f.hp,28,12)
--Make the Mana Bar
f:SetAttribute("unit",f.unit)
f:SetAttribute("type","target")
--background texture
f.back2 = f:CreateTexture(nil,"BACKGROUND")
f.back2:SetSize(unpack(cfg.barsize))
f.back2:SetPoint("CENTER",UIParent,cfg.powerx,cfg.powery)
f.back2:SetTexture("Interface\\Addons\\BobHUD\\media\\powerbar")
f.back2:SetVertexColor(0,0,0,0.5)
--mana bar
f.mp = CreateFrame("StatusBar",nil,f,"TextStatusBar")
f.mp:SetSize(unpack(cfg.barsize))
f.mp:SetPoint("CENTER",UIParent,cfg.powerx,cfg.powery)
f.mp:SetStatusBarTexture("Interface\\Addons\\BobHUD\\media\\powerbar")
f.mp:SetStatusBarColor(0,0,1)
f.mp:SetMinMaxValues(0,1)
f.mp:SetOrientation("VERTICAL")
f.mp:EnableMouse(0)
f.mp:SetAlpha(cfg.alpha)
--power fontstring
f.PowerText = f:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
f.PowerText:SetPoint("BOTTOM",f.mp,-2,0)
--percent
f.PowerText2 = f:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
f.PowerText2:SetPoint("BOTTOM",f.mp,-28,12)
--Updates the status bar to new health
f:SetScript("OnEvent", function(self, event, unit)
if event == "UNIT_HEALTH" or event == "PLAYER_ENTERING_WORLD" then
--update health
self.hp:SetValue(UnitHealth(f.unit)/UnitHealthMax(f.unit))
local currentHealth, maxHealth = UnitHealth(f.unit), UnitHealthMax(f.unit)
local percentHealth = currentHealth / maxHealth * 100
self.HealthText:SetFormattedText("%d/%d", currentHealth, maxHealth, percentHealth)
self.HealthText2:SetFormattedText("%d%%", percentHealth)
end
if event == "UNIT_POWER" or event == "PLAYER_ENTERING_WORLD" then
--update powa
self.mp:SetValue(UnitPower(f.unit)/UnitPowerMax(f.unit))
local currentPower, maxPower = UnitPower(f.unit), UnitPowerMax(f.unit)
local percentPower = currentPower / maxPower * 100
self.PowerText:SetFormattedText("%d/%d", currentPower, maxPower, percentPower)
self.PowerText2:SetFormattedText("%d%%", percentPower)
end
end)
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:RegisterUnitEvent("UNIT_HEALTH", f.unit)
f:RegisterUnitEvent("UNIT_POWER", f.unit)