mirror of
https://github.com/parnic/ice-hud.git
synced 2025-06-16 06:40:13 -05:00
161 lines
3.7 KiB
Lua
161 lines
3.7 KiB
Lua
local AceOO = AceLibrary("AceOO-2.0")
|
|
local DogTag = AceLibrary("LibDogTag-2.0")
|
|
|
|
local PetMana = AceOO.Class(IceUnitBar)
|
|
|
|
-- Constructor --
|
|
function PetMana.prototype:init()
|
|
PetMana.super.prototype.init(self, "PetMana", "pet")
|
|
|
|
self:SetDefaultColor("PetMana", 62, 54, 152)
|
|
self:SetDefaultColor("PetRage", 171, 59, 59)
|
|
self:SetDefaultColor("PetEnergy", 218, 231, 31)
|
|
self:SetDefaultColor("PetFocus", 242, 149, 98)
|
|
|
|
self.scalingEnabled = true
|
|
end
|
|
|
|
|
|
-- OVERRIDE
|
|
function PetMana.prototype:GetDefaultSettings()
|
|
local settings = PetMana.super.prototype.GetDefaultSettings(self)
|
|
|
|
settings["side"] = IceCore.Side.Right
|
|
settings["offset"] = -1
|
|
settings.scale = 0.7
|
|
settings["upperText"] = ""
|
|
settings["lowerText"] = "[PercentMP:Round]"
|
|
|
|
return settings
|
|
end
|
|
|
|
|
|
-- OVERRIDE
|
|
function PetMana.prototype:CreateFrame()
|
|
PetMana.super.prototype.CreateFrame(self)
|
|
|
|
local point, relativeTo, relativePoint, xoff, yoff = self.frame.bottomUpperText:GetPoint()
|
|
if (point == "TOPLEFT") then
|
|
point = "BOTTOMLEFT"
|
|
else
|
|
point = "BOTTOMRIGHT"
|
|
end
|
|
|
|
self.frame.bottomUpperText:ClearAllPoints()
|
|
self.frame.bottomUpperText:SetPoint(point, relativeTo, relativePoint, 0, 0)
|
|
end
|
|
|
|
|
|
function PetMana.prototype:Enable(core)
|
|
PetMana.super.prototype.Enable(self, core)
|
|
|
|
self:RegisterEvent("PET_UI_UPDATE", "CheckPet");
|
|
self:RegisterEvent("PLAYER_PET_CHANGED", "CheckPet");
|
|
self:RegisterEvent("PET_BAR_CHANGED", "CheckPet");
|
|
self:RegisterEvent("UNIT_PET", "CheckPet");
|
|
|
|
self:RegisterEvent("UNIT_MANA", "Update")
|
|
self:RegisterEvent("UNIT_MAXMANA", "Update")
|
|
self:RegisterEvent("UNIT_RAGE", "Update")
|
|
self:RegisterEvent("UNIT_MAXRAGE", "Update")
|
|
self:RegisterEvent("UNIT_ENERGY", "Update")
|
|
self:RegisterEvent("UNIT_MAXENERGY", "Update")
|
|
self:RegisterEvent("UNIT_FOCUS", "Update")
|
|
self:RegisterEvent("UNIT_MAXFOCUS", "Update")
|
|
|
|
self:RegisterEvent("UNIT_DISPLAYPOWER", "ManaType")
|
|
|
|
self:CheckPet()
|
|
self:ManaType(self.unit)
|
|
end
|
|
|
|
|
|
function PetMana.prototype:CheckPet()
|
|
if (UnitExists(self.unit)) then
|
|
self.frame:Show()
|
|
self:Update(self.unit)
|
|
else
|
|
self.frame:Hide()
|
|
end
|
|
end
|
|
|
|
|
|
function PetMana.prototype:ManaType(unit)
|
|
if (unit ~= self.unit) then
|
|
return
|
|
end
|
|
|
|
self.manaType = UnitPowerType(self.unit)
|
|
self:Update(self.unit)
|
|
end
|
|
|
|
|
|
function PetMana.prototype:Update(unit)
|
|
PetMana.super.prototype.Update(self)
|
|
if (unit and (unit ~= self.unit)) then
|
|
return
|
|
end
|
|
|
|
if ((not UnitExists(unit)) or (self.maxMana == 0)) then
|
|
self.frame:Hide()
|
|
return
|
|
else
|
|
self.frame:Show()
|
|
end
|
|
|
|
local color = "PetMana"
|
|
if (self.moduleSettings.scaleManaColor) then
|
|
color = "ScaledManaColor"
|
|
end
|
|
if not (self.alive) then
|
|
color = "Dead"
|
|
else
|
|
if (self.manaType == 1) then
|
|
color = "PetRage"
|
|
elseif (self.manaType == 2) then
|
|
color = "PetFocus"
|
|
elseif (self.manaType == 3) then
|
|
color = "PetEnergy"
|
|
end
|
|
end
|
|
|
|
self:UpdateBar(self.mana/self.maxMana, color)
|
|
|
|
if self.moduleSettings.upperText ~= nil and self.moduleSettings.upperText ~= '' then
|
|
self:SetBottomText1(DogTag:Evaluate("player", self.moduleSettings.upperText))
|
|
end
|
|
if self.moduleSettings.lowerText ~= nil and self.moduleSettings.lowerText ~= '' then
|
|
self:SetBottomText2(DogTag:Evaluate("player", self.moduleSettings.lowerText))
|
|
end
|
|
end
|
|
|
|
|
|
-- OVERRIDE
|
|
function PetMana.prototype:GetOptions()
|
|
local opts = PetMana.super.prototype.GetOptions(self)
|
|
|
|
opts["scaleManaColor"] = {
|
|
type = "toggle",
|
|
name = "Color bar by mana %",
|
|
desc = "Colors the mana bar from MaxManaColor to MinManaColor based on current mana %",
|
|
get = function()
|
|
return self.moduleSettings.scaleManaColor
|
|
end,
|
|
set = function(value)
|
|
self.moduleSettings.scaleManaColor = value
|
|
self:Redraw()
|
|
end,
|
|
disabled = function()
|
|
return not self.moduleSettings.enabled
|
|
end,
|
|
order = 51
|
|
}
|
|
|
|
return opts
|
|
end
|
|
|
|
|
|
|
|
-- Load us up
|
|
IceHUD.PetMana = PetMana:new()
|