PHP код:
local backdrop = {
bgFile = [=[Interface\Buttons\WHITE8X8]=],
}
local RAID_CLASS_COLORS = PowerBarColor
local addon, ns = ...;
local unit = "player"
local class = select(2, UnitClass(unit))
local bar = CreateFrame("frame", nil, UIParent)
bar:SetSize(150, 50)
bar:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
bar:SetBackdrop(backdrop)
bar:SetBackdropColor(0, 0, 0, .5)
local hp = CreateFrame("statusbar", nil, bar)
hp:SetPoint("TOPLEFT", bar, 0, 0)
hp:SetPoint("BOTTOMRIGHT", bar, 0, 30)
hp:SetBackdrop(backdrop)
hp:SetBackdropColor(0,0,0,1)
hp:SetStatusBarTexture([=[Interface\Buttons\WHITE8X8]=])
hp:SetStatusBarColor(0, 1, .25)
hp:SetMinMaxValues(0, 100)
hp._cur = 0
hp._max = 0
hp:SetScript("OnUpdate", function(self, elspsed)
local _cur = UnitHealth(unit)
local _max = UnitHealthMax(unit)
if (self._max ~= _max) then
self:SetMinMaxValues(0, _max)
self._max = _max
end
if (self._cur ~= cur) then
self:SetValue(_cur)
self._cur = _cur
end
end)
local pwr = CreateFrame("statusbar", nil, bar)
pwr:SetPoint("BOTTOMLEFT", bar, 0, 0)
pwr:SetPoint("TOPRIGHT", bar, 0, -30)
pwr:SetBackdrop(backdrop)
pwr:SetBackdropColor(0, 0, 0, 1)
pwr:SetStatusBarTexture([=[Interface\Buttons\WHITE8X8]=])
pwr:SetMinMaxValues(0, 100)
pwr._cur = 0
pwr._max = 0
pwr:SetScript("OnUpdate", function(self, elspsed)
local _cur = UnitPower(unit)
local _max = UnitPowerMax(unit)
if (self._max ~= _max) then
local powerType, powerToken, altR, altG, altB = UnitPowerType(unit)
local info = PowerBarColor[powerToken]
if ( info ) then
self:SetStatusBarColor(info.r, info.g, info.b)
end
self:SetMinMaxValues(0, _max)
self._max = _max
end
if (self._cur ~= cur) then
self:SetValue(_cur)
self._cur = _cur
end
end)