local addonName, addon = ...
addon:RegisterDefaultSetting("hudShow", true)
addon:RegisterDefaultSetting("hudWidth", 100)
addon:RegisterDefaultSetting("hudHeight", 100)
addon:RegisterDefaultSetting("hudScale", 1)
local GHudMain = CreateFrame("Frame", "GHudMain", UIParent)
GHudMain:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
GHudMain:SetHeight(3)
GHudMain:SetWidth(3)
GHudMain:RegisterEvent("PLAYER_TARGET_CHANGED")
GHudMain:RegisterEvent("UNIT_PET", "player")
GHudMain:SetScript("OnEvent", function(event)
addon:SetHudBackgrounds()
end)
function addon:SetupGHud()
if addon.settings.hudShow then
GHudMain:Show()
else
GHudMain:Hide()
end
end
function addon:GHudScale()
GHudMain:SetScale(addon.settings.hudScale)
end
--[[-----------------------------------------------------------------------------
The IMPORTANT PART! Bar fill function, dont f with this.
-------------------------------------------------------------------------------]]
function addon:SetBarValue(bar,val1,val2, topoff, bottomoff, rightoff, leftoff, flipH,flipV)-- Accepts 3 values, bar texture, start value, and end value
-- Keep the values within a 0-1 range
val1=math.min(math.max(val1,0),1);
val2=math.min(math.max(val2,0),1);
-- Sometimes textures glitch when trying to set a width or height of 0, so handle it here
if val1==val2 then
bar:Hide();
return;
else
bar:Show();
end
-- Set our low and high values
local low,high = math.min(val1,val2),math.max(val1,val2);
if bottomoff ~= 0 then
--low = math.min(val1-bottomoff,val2-bottomoff)
end
if topoff ~= 0 then
--high = math.max(val1-topoff,val2-topoff);
end
if rightoff ~= 0 then
end
if leftoff ~= 0 then
end
-- Find our parent width and height
local parent=bar:GetParent();
local w,h=parent:GetWidth(),parent:GetHeight();
-- Get our point set, we'll use this to get our bar orientation
local point=bar:GetPoint(1);
if not point then return; end-- Handle if point isn't set, perhaps cleared?
-- These are our temp origin variables (note one of these pairs can have both vars nil, just use default texcoords for those)
local origL=point:find("LEFT$");
local origR=point:find("RIGHT$");
local origT=point:find("^TOP");
local origB=point:find("^BOTTOM");
-- Reset point (logic nightmare)
bar:SetPoint(point
,(origL or origR) and (origL and low*w or -low*w) or 0-- X offset
,(origT or origB) and (origB and low*h or -low*h) or 0-- Y offset
);
-- Texcoord/Size set (this is actually the easy part)
local l,r,t,b = 0,1,0,1;-- Texcoords are in the range of 0-1 with their origin at top left
if origL then
l,r = low, high;
elseif origR then
l,r = 1-high,1-low;
end
if origT then
t,b = low,high;
elseif origB then
t,b = 1-high,1-low;
end
-- Process flip (affects which side the bar piece is drawn from too)
if flipH then l,r=1-l,1-r; end
if flipV then t,b=1-t,1-b; end
bar:SetTexCoord(l,r,t,b);
bar:SetWidth(w*math.abs(r-l));
--bar:SetWidth(w*(r-l));
bar:SetHeight(h*math.abs(b-t));
--bar:SetHeight(h*(b-t));
end
--[[-----------------------------------------------------------------------------
Main Bar Creations
-------------------------------------------------------------------------------]]
local PlayerHBar = CreateFrame("Frame",nil, GHudMain);
local PlayerMBar = CreateFrame("Frame",nil, GHudMain);
local TargetHBar = CreateFrame("Frame",nil, GHudMain);
local TargetMBar = CreateFrame("Frame",nil, GHudMain);
local PPetHBar = CreateFrame("Frame",nil, GHudMain);
local PPetMBar = CreateFrame("Frame",nil, GHudMain);
function addon:LayoutHudBars()
PlayerHBar:ClearAllPoints()
PlayerHBar:SetPoint("RIGHT", GHudMain, "LEFT", - addon.settings.hudWidth, addon.settings.hudHeight);-- Place frame wherever
PlayerMBar:ClearAllPoints()
PlayerMBar:SetPoint("LEFT", GHudMain, "RIGHT", addon.settings.hudWidth, addon.settings.hudHeight);
TargetHBar:ClearAllPoints()
TargetHBar:SetPoint("RIGHT", GHudMain, "LEFT", - addon.settings.hudWidth, addon.settings.hudHeight);-- Place frame wherever
TargetMBar:ClearAllPoints()
TargetMBar:SetPoint("LEFT", GHudMain, "RIGHT", addon.settings.hudWidth, addon.settings.hudHeight);
PPetHBar:ClearAllPoints()
PPetHBar:SetPoint("RIGHT", GHudMain, "LEFT", - addon.settings.hudWidth, addon.settings.hudHeight);-- Place frame wherever
PPetMBar:ClearAllPoints()
PPetMBar:SetPoint("LEFT", GHudMain, "RIGHT", addon.settings.hudWidth, addon.settings.hudHeight);
end
PlayerHBar:SetWidth(128);--Width
PlayerHBar:SetHeight(256);--Height
PlayerMBar:SetWidth(128);--Width
PlayerMBar:SetHeight(256);--Height
TargetHBar:SetWidth(128);--Width
TargetHBar:SetHeight(256);--Height
TargetMBar:SetWidth(128);--Width
TargetMBar:SetHeight(256);--Height
PPetHBar:SetWidth(128);--Width
PPetHBar:SetHeight(256);--Height
PPetMBar:SetWidth(128);--Width
PPetMBar:SetHeight(256);--Height
-- Note: It's generally a good idea to use the same dimensions as your image file for your frame size
function addon:SetHudBackgrounds()
if UnitExists("target") then
if UnitExists("pet") then
PlayerHBar.Background:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\bg_21p");-- Your bar image
PlayerMBar.Background:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\bg_21p");--Your bar image
else
PlayerHBar.Background:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\bg_21");-- Your bar image
PlayerMBar.Background:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\bg_21");--Your bar image
end
else
if UnitExists("pet") then
PlayerHBar.Background:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\bg_1p");-- Your bar image
PlayerMBar.Background:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\bg_1p");--Your bar image
else
PlayerHBar.Background:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\bg_1");-- Your bar image
PlayerMBar.Background:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\bg_1");--Your bar image
end
end
end
--Left Side
-- Background texture
PlayerHBar.Background = PlayerHBar:CreateTexture(nil,"BACKGROUND");
PlayerHBar.Background:SetAllPoints(PlayerHBar);--We want the texture spread to match the dimensions of the frame.
PlayerHBar.Background:SetAlpha(0.25)--Special suprize (black background at a quarter alpha)
--Right Side
-- Background texture
PlayerMBar.Background = PlayerMBar:CreateTexture(nil,"BACKGROUND");
PlayerMBar.Background:SetAllPoints(PlayerMBar);--We want the texture spread to match the dimensions of the frame.
PlayerMBar.Background:SetAlpha(0.25)
PlayerMBar.Background:SetTexCoord(1,0,0,1)
--[[-----------------------------------------------------------------------------
Player Bars
-------------------------------------------------------------------------------]]
PlayerHBar.HealthBar = PlayerHBar:CreateTexture(nil,"ARTWORK");--Notice the change in layers, this makes the bar draw on top of the background
PlayerHBar.HealthBar:SetPoint("BOTTOM");--We need only one point set, in this example, the bar fills toward the right, so we need it left-aligned
PlayerHBar.HealthBar:SetWidth(128);--Match frame width for now
PlayerHBar.HealthBar:SetHeight(256);--Match frame height for now
PlayerHBar.HealthBar:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\1");--Be sure to use the same image or one derived from the background
-- Player Mana Texture
PlayerMBar.ManaBar = PlayerMBar:CreateTexture(nil,"ARTWORK");--Notice the change in layers, this makes the bar draw on top of the background
PlayerMBar.ManaBar:SetPoint("BOTTOM");--We need only one point set, in this example, the bar fills toward the right, so we need it left-aligned
PlayerMBar.ManaBar:SetWidth(128);--Match frame width for now
PlayerMBar.ManaBar:SetHeight(256);--Match frame height for now
PlayerMBar.ManaBar:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\1");--Be sure to use the same image or one derived from the background
-- Heal prediction texture (this'll be my example of a partial bar)
PlayerHBar.HealBar = PlayerHBar:CreateTexture(nil,"ARTWORK");-- Use the same layer as Healthbar
PlayerHBar.HealBar:SetPoint("BOTTOM");-- Use the same point for the HealthBar
PlayerHBar.HealBar:SetWidth(128);-- Match frame width for now
PlayerHBar.HealBar:SetHeight(256);-- Match frame height for now
PlayerHBar.HealBar:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\1");-- Be sure to use the same image or one derived from the background
PlayerHBar:RegisterEvent("PLAYER_ENTERING_WORLD");
PlayerHBar:RegisterEvent("UNIT_HEALTH", "player");
PlayerHBar:RegisterEvent("UNIT_HEALTH_PREDICTION");
PlayerHBar:SetScript("OnEvent",function(self,event)
-- Stop handler if unit not player
--if not UnitIsUnit(unit,"player") then return; end
local hcur,hmax,heal=UnitHealth("player"),UnitHealthMax("player"),UnitGetIncomingHeals("player") or 0;-- UnitGetIncomingHeals() can return nil for unsupported units
local hppcnt=hcur/math.max(1,hmax);
local healpcnt=heal/math.max(1,hmax);
-- Set our bars (notice the HealBar is a partial bar since it has a start value greater than zero)
addon:SetBarValue(self.HealthBar,0,hppcnt, 0, 0, 0, 0);
addon:SetBarValue(self.HealBar,hppcnt,hppcnt+healpcnt, 0, 0, 0, 0);
-- Color HealthBar (we're keeping HealBar white)
-- This color formula ranges in color from green, to yellow, to red
self.HealthBar:SetVertexColor(math.min(2-2*hppcnt,1),math.min(2*hppcnt,1),0);
end)
PlayerMBar:RegisterEvent("PLAYER_ENTERING_WORLD");
PlayerMBar:RegisterEvent("UNIT_POWER", "player");
PlayerMBar:SetScript("OnEvent",function(self,event)
local pcur, pmax, ptype = UnitPower("player"), UnitPowerMax("player"), UnitPowerType("player");
local mppcnt = pcur/math.max(1,pmax);
-- Set our bars (notice the HealBar is a partial bar since it has a start value greater than zero)
addon:SetBarValue(self.ManaBar,0,mppcnt, 0, 0, 0, 0, "flipH");
-- Color HealthBar (we're keeping HealBar white)
if ptype == 0 then
self.ManaBar:SetVertexColor(.556, .556, .921, 1)
elseif ptype == 1 or 2 or 3 or 6 then
self.ManaBar:SetVertexColor(.656, .456, .456, 1)
end
end)
--[[-----------------------------------------------------------------------------
Target Bars
-------------------------------------------------------------------------------]]
TargetHBar.HealthBar = TargetHBar:CreateTexture(nil,"ARTWORK");--Notice the change in layers, this makes the bar draw on top of the background
TargetHBar.HealthBar:SetPoint("BOTTOM");--We need only one point set, in this example, the bar fills toward the right, so we need it left-aligned
TargetHBar.HealthBar:SetWidth(128);--Match frame width for now
TargetHBar.HealthBar:SetHeight(256);--Match frame height for now
TargetHBar.HealthBar:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\2");--Be sure to use the same image or one derived from the background
-- Player Mana Texture
TargetMBar.ManaBar = TargetMBar:CreateTexture(nil,"ARTWORK");
TargetMBar.ManaBar:SetPoint("BOTTOM");--We need only one point set, in this example, the bar fills toward the right, so we need it left-aligned
TargetMBar.ManaBar:SetWidth(128);--Match frame width for now
TargetMBar.ManaBar:SetHeight(256);--Match frame height for now
TargetMBar.ManaBar:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\2");--Be sure to use the same image or one derived from the background
TargetHBar:RegisterEvent("PLAYER_ENTERING_WORLD");
TargetHBar:RegisterEvent("PLAYER_TARGET_CHANGED");
TargetHBar:RegisterEvent("UNIT_HEALTH", "target");
TargetHBar:RegisterEvent("UNIT_HEALTH_PREDICTION", "target");
TargetHBar:SetScript("OnEvent",function(self,event)
-- Stop handler if unit not player
--if not UnitIsUnit(unit,"player") then return; end
local hcur,hmax,heal=UnitHealth("target"),UnitHealthMax("target"),UnitGetIncomingHeals("target") or 0;-- UnitGetIncomingHeals() can return nil for unsupported units
local hppcnt=hcur/math.max(1,hmax);
local healpcnt=heal/math.max(1,hmax);
-- Set our bars (notice the HealBar is a partial bar since it has a start value greater than zero)
addon:SetBarValue(self.HealthBar,0,hppcnt, 0, 0, 0, 0);
--addon:SetBarValue(self.HealBar,hppcnt,hppcnt+healpcnt);
self.HealthBar:SetVertexColor(math.min(2-2*hppcnt,1),math.min(2*hppcnt,1),0);
end)
TargetMBar:RegisterEvent("PLAYER_ENTERING_WORLD");
TargetMBar:RegisterEvent("PLAYER_TARGET_CHANGED");
TargetMBar:RegisterEvent("UNIT_POWER", "target");
TargetMBar:SetScript("OnEvent",function(self,event)
local pcur, pmax, ptype = UnitPower("target"), UnitPowerMax("target"), UnitPowerType("target");
local mppcnt = pcur/math.max(1,pmax);
-- Set our bars (notice the HealBar is a partial bar since it has a start value greater than zero)
addon:SetBarValue(self.ManaBar,0,mppcnt, 0, 0, 0, 0, "flipH");
-- Color HealthBar (we're keeping HealBar white)
if ptype == 0 then
self.ManaBar:SetVertexColor(.556, .556, .921, 1)
elseif ptype == 1 or 2 or 3 or 6 then
self.ManaBar:SetVertexColor(.656, .456, .456, 1)
end
end)
--[[-----------------------------------------------------------------------------
Pet Bars
-------------------------------------------------------------------------------]]
PPetHBar.HealthBar = PPetHBar:CreateTexture(nil,"ARTWORK");--Notice the change in layers, this makes the bar draw on top of the background
PPetHBar.HealthBar:SetPoint("BOTTOM");--We need only one point set, in this example, the bar fills toward the right, so we need it left-aligned
PPetHBar.HealthBar:SetWidth(128);--Match frame width for now
PPetHBar.HealthBar:SetHeight(256);--Match frame height for now
PPetHBar.HealthBar:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\p1");--Be sure to use the same image or one derived from the background
-- Player Mana Texture
PPetMBar.ManaBar = PPetMBar:CreateTexture(nil,"ARTWORK");
PPetMBar.ManaBar:SetPoint("BOTTOM");--We need only one point set, in this example, the bar fills toward the right, so we need it left-aligned
PPetMBar.ManaBar:SetWidth(128);--Match frame width for now
PPetMBar.ManaBar:SetHeight(256);--Match frame height for now
PPetMBar.ManaBar:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\p1");--Be sure to use the same image or one derived from the background
PPetHBar:RegisterEvent("PLAYER_ENTERING_WORLD");
PPetHBar:RegisterEvent("PLAYER_TARGET_CHANGED");
PPetHBar:RegisterEvent("UNIT_HEALTH", "pet")
PPetHBar:RegisterEvent("UNIT_LEVEL", "pet")
PPetHBar:RegisterEvent("UNIT_AURA", "pet")
PPetHBar:RegisterEvent("UNIT_MAXHEALTH", "pet")
PPetHBar:RegisterEvent("PLAYER_PET_CHANGED")
PPetHBar:RegisterEvent("UNIT_PET", "player")
PPetHBar:RegisterEvent("UNIT_HEALTH_PREDICTION", "pet");
PPetHBar:SetScript("OnEvent",function(self,event)
-- Stop handler if unit not player
--if not UnitIsUnit(unit,"player") then return; end
local hcur,hmax,heal=UnitHealth("pet"),UnitHealthMax("pet"),UnitGetIncomingHeals("pet") or 0;-- UnitGetIncomingHeals() can return nil for unsupported units
local hppcnt=hcur/math.max(1,hmax);
local healpcnt=heal/math.max(1,hmax);
-- Set our bars (notice the HealBar is a partial bar since it has a start value greater than zero)
addon:SetBarValue(self.HealthBar,0,hppcnt, 175, 25, 0, 0);
--addon:SetBarValue(self.HealBar,hppcnt,hppcnt+healpcnt);
self.HealthBar:SetVertexColor(math.min(2-2*hppcnt,1),math.min(2*hppcnt,1),0);
end)
PPetMBar:RegisterEvent("PLAYER_ENTERING_WORLD");
PPetMBar:RegisterEvent("UNIT_HEALTH", "pet")
PPetMBar:RegisterEvent("UNIT_LEVEL", "pet")
PPetMBar:RegisterEvent("UNIT_MANA", "pet")
PPetMBar:RegisterEvent("UNIT_AURA", "pet")
PPetMBar:RegisterEvent("UNIT_DISPLAYPOWER", "pet")
PPetMBar:RegisterEvent("UNIT_ENERGY", "pet")
PPetMBar:RegisterEvent("UNIT_MAXENERGY", "pet")
PPetMBar:RegisterEvent("UNIT_MAXMANA", "pet")
PPetMBar:RegisterEvent("PET_UI_UPDATE");
PPetMBar:RegisterEvent("PLAYER_TARGET_CHANGED");
PPetMBar:RegisterEvent("UNIT_POWER", "pet");
PPetMBar:SetScript("OnEvent",function(self,event)
local pcur, pmax, ptype = UnitPower("pet"), UnitPowerMax("pet"), UnitPowerType("pet");
local mppcnt = pcur/math.max(1,pmax);
-- Set our bars (notice the HealBar is a partial bar since it has a start value greater than zero)
addon:SetBarValue(self.ManaBar,0,mppcnt, 175, 25, 0, 0,"flipH");
-- Color HealthBar (we're keeping HealBar white)
if ptype == 0 then
self.ManaBar:SetVertexColor(.556, .556, .921, 1)
elseif ptype == 1 or 2 or 3 or 6 then
self.ManaBar:SetVertexColor(.656, .456, .456, 1)
end
end)
--[[-----------------------------------------------------------------------------
Addon Loaded Initialize
-------------------------------------------------------------------------------]]
addon.RegisterEvent("HUD-Initialize", 'ADDON_LOADED', function(self, event)
addon.UnregisterEvent(self, event)
addon:SetupGHud()
addon:LayoutHudBars()
addon:SetupGHud()
addon:SetHudBackgrounds()
end)