Files
ice-hud/modules/PlayerHealth.lua
Parnic ced858b06a - bump toc
- added the ability to scale most health/power bars by the amount they're filled up with a customizable max/min color (health can go green to red, for example)
- updated from SharedMedia-1.0 to LibSharedMedia-2.0
2008-01-19 01:26:18 +00:00

175 lines
4.0 KiB
Lua

local AceOO = AceLibrary("AceOO-2.0")
local PlayerHealth = AceOO.Class(IceUnitBar)
PlayerHealth.prototype.resting = nil
-- Constructor --
function PlayerHealth.prototype:init()
PlayerHealth.super.prototype.init(self, "PlayerHealth", "player")
self:SetDefaultColor("PlayerHealth", 37, 164, 30)
end
function PlayerHealth.prototype:GetDefaultSettings()
local settings = PlayerHealth.super.prototype.GetDefaultSettings(self)
settings["side"] = IceCore.Side.Left
settings["offset"] = 1
settings["hideBlizz"] = true
return settings
end
function PlayerHealth.prototype:Enable(core)
PlayerHealth.super.prototype.Enable(self, core)
self:RegisterEvent("UNIT_HEALTH", "Update")
self:RegisterEvent("UNIT_MAXHEALTH", "Update")
self:RegisterEvent("PLAYER_UPDATE_RESTING", "Resting")
self:RegisterEvent("PLAYER_ENTERING_WORLD", "Resting")
if (self.moduleSettings.hideBlizz) then
self:HideBlizz()
end
self:Resting()
--self:Update(self.unit)
end
-- OVERRIDE
function PlayerHealth.prototype:GetOptions()
local opts = PlayerHealth.super.prototype.GetOptions(self)
opts["classColor"] = {
type = "toggle",
name = "Class color bar",
desc = "Use class color as the bar color instead of default color",
get = function()
return self.moduleSettings.classColor
end,
set = function(value)
self.moduleSettings.classColor = value
self:Update(self.unit)
end,
disabled = function()
return not self.moduleSettings.enabled
end,
order = 40
}
opts["hideBlizz"] = {
type = "toggle",
name = "Hide Blizzard Frame",
desc = "Hides Blizzard Player frame and disables all events related to it",
get = function()
return self.moduleSettings.hideBlizz
end,
set = function(value)
self.moduleSettings.hideBlizz = value
if (value) then
self:HideBlizz()
else
self:ShowBlizz()
end
end,
disabled = function()
return not self.moduleSettings.enabled
end,
order = 41
}
opts["scaleHealthColor"] = {
type = "toggle",
name = "Color bar by health %",
desc = "Colors the health bar from MaxHealthColor to MinHealthColor based on current health %",
get = function()
return self.moduleSettings.scaleHealthColor
end,
set = function(value)
self.moduleSettings.scaleHealthColor = value
self:Redraw()
end,
disabled = function()
return not self.moduleSettings.enabled
end,
order = 42
}
return opts
end
function PlayerHealth.prototype:Resting()
self.resting = IsResting()
self:Update(self.unit)
end
function PlayerHealth.prototype:Update(unit)
PlayerHealth.super.prototype.Update(self)
if (unit and (unit ~= self.unit)) then
return
end
local color = "PlayerHealth"
if (self.moduleSettings.classColor) then
color = self.unitClass
end
if (self.moduleSettings.scaleHealthColor) then
color = "ScaledHealthColor"
end
if not (self.alive) then
color = "Dead"
end
local textColor = color
if (self.resting) then
textColor = "Text"
end
self:UpdateBar(self.health/self.maxHealth, color)
self:SetBottomText1(self.healthPercentage)
self:SetBottomText2(self:GetFormattedText(self.health, self.maxHealth), textColor)
end
function PlayerHealth.prototype:ShowBlizz()
PlayerFrame:Show()
PlayerFrame:RegisterEvent("UNIT_LEVEL");
PlayerFrame:RegisterEvent("UNIT_COMBAT");
PlayerFrame:RegisterEvent("UNIT_FACTION");
PlayerFrame:RegisterEvent("UNIT_MAXMANA");
PlayerFrame:RegisterEvent("PLAYER_ENTERING_WORLD");
PlayerFrame:RegisterEvent("PLAYER_ENTER_COMBAT");
PlayerFrame:RegisterEvent("PLAYER_LEAVE_COMBAT");
PlayerFrame:RegisterEvent("PLAYER_REGEN_DISABLED");
PlayerFrame:RegisterEvent("PLAYER_REGEN_ENABLED");
PlayerFrame:RegisterEvent("PLAYER_UPDATE_RESTING");
PlayerFrame:RegisterEvent("PARTY_MEMBERS_CHANGED");
PlayerFrame:RegisterEvent("PARTY_LEADER_CHANGED");
PlayerFrame:RegisterEvent("PARTY_LOOT_METHOD_CHANGED");
PlayerFrame:RegisterEvent("RAID_ROSTER_UPDATE");
PlayerFrame:RegisterEvent("PLAYTIME_CHANGED");
end
function PlayerHealth.prototype:HideBlizz()
PlayerFrame:Hide()
PlayerFrame:UnregisterAllEvents()
end
-- Load us up
IceHUD.PlayerHealth = PlayerHealth:new()