mirror of
https://github.com/parnic/ice-hud.git
synced 2025-06-16 14:50:13 -05:00
- changed DruidMana module to (optionally) work with LibDruidMana/DogTag for simplicity/compatibility purposes
This commit is contained in:
@ -1,43 +1,66 @@
|
||||
local AceOO = AceLibrary("AceOO-2.0")
|
||||
|
||||
local DruidMana = AceOO.Class(IceUnitBar)
|
||||
local gratuity = AceLibrary("Gratuity-2.0")
|
||||
|
||||
DruidMana.prototype.druidMana = nil
|
||||
DruidMana.prototype.druidManaMax = nil
|
||||
DruidMana.prototype.lastCast = nil
|
||||
DruidMana.prototype.baseMana = nil
|
||||
|
||||
local gratuity = nil
|
||||
local LibDruidMana = nil
|
||||
|
||||
local intMod = 14
|
||||
|
||||
|
||||
-- Constructor --
|
||||
function DruidMana.prototype:init()
|
||||
DruidMana.super.prototype.init(self, "DruidMana", "player")
|
||||
|
||||
self.side = IceCore.Side.Right
|
||||
self.offset = 0
|
||||
|
||||
self:SetDefaultColor("DruidMana", 87, 82, 141)
|
||||
|
||||
if AceLibrary:HasInstance("LibDogTag-3.0") and AceLibrary:HasInstance("LibDruidMana-1.0") then
|
||||
LibDruidMana = AceLibrary("LibDruidMana-1.0")
|
||||
else
|
||||
gratuity = AceLibrary("Gratuity-2.0")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function DruidMana.prototype:GetDefaultSettings()
|
||||
local settings = DruidMana.super.prototype.GetDefaultSettings(self)
|
||||
|
||||
settings["side"] = IceCore.Side.Right
|
||||
settings["offset"] = 0
|
||||
settings["textVisible"] = {upper = true, lower = false}
|
||||
|
||||
if LibDruidMana then
|
||||
settings["upperText"] = "[PercentDruidMP:Round]"
|
||||
settings["lowerText"] = "[FractionalDruidMP:Color('3071bf'):Bracket]"
|
||||
end
|
||||
|
||||
return settings
|
||||
end
|
||||
|
||||
|
||||
function DruidMana.prototype:Enable(core)
|
||||
DruidMana.super.prototype.Enable(self, core)
|
||||
|
||||
self:FormsChanged(self.unit)
|
||||
|
||||
self:RegisterEvent("UNIT_DISPLAYPOWER", "FormsChanged")
|
||||
self:RegisterEvent("UNIT_MANA", "UpdateMana")
|
||||
self:RegisterEvent("UNIT_MAXMANA", "UpdateManaMax")
|
||||
|
||||
if not LibDruidMana then
|
||||
self:FormsChanged(self.unit)
|
||||
|
||||
self:RegisterEvent("UNIT_DISPLAYPOWER", "FormsChanged")
|
||||
self:RegisterEvent("UPDATE_SHAPESHIFT_FORM", "FormsChanged")
|
||||
self:RegisterEvent("UNIT_MANA", "UpdateMana")
|
||||
self:RegisterEvent("UNIT_MAXMANA", "UpdateManaMax")
|
||||
else
|
||||
self:RegisterEvent("UPDATE_SHAPESHIFT_FORM", "Update")
|
||||
self:RegisterEvent("UNIT_MANA", "Update")
|
||||
self:RegisterEvent("UNIT_MAXMANA", "Update")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -45,7 +68,7 @@ function DruidMana.prototype:Disable(core)
|
||||
DruidMana.super.prototype.Disable(self, core)
|
||||
end
|
||||
|
||||
|
||||
-- Only called if the user doesn't have LibDruidMana installed
|
||||
function DruidMana.prototype:FormsChanged(unit)
|
||||
if (unit ~= self.unit) then
|
||||
return
|
||||
@ -56,7 +79,7 @@ function DruidMana.prototype:FormsChanged(unit)
|
||||
if (forms) then
|
||||
self.lastCast = GetTime()
|
||||
|
||||
if (not self.druidMana) then
|
||||
if (not self.druidMana or not gratuity) then
|
||||
return
|
||||
end
|
||||
|
||||
@ -64,7 +87,7 @@ function DruidMana.prototype:FormsChanged(unit)
|
||||
-- when we shift to forms
|
||||
local uberTooltips = GetCVar("UberTooltips")
|
||||
SetCVar("UberTooltips", 1)
|
||||
|
||||
|
||||
gratuity:SetShapeshift(1) -- 1 = bear form, rawr
|
||||
local _, _, manaCost = gratuity:Find("(%d+)", 2, 2) -- 2 = mana cost line
|
||||
|
||||
@ -83,7 +106,7 @@ function DruidMana.prototype:FormsChanged(unit)
|
||||
self:Update()
|
||||
end
|
||||
|
||||
|
||||
-- Only called if the user doesn't have LibDruidMana installed
|
||||
function DruidMana.prototype:UpdateMana(unit)
|
||||
if (unit ~= self.unit) then
|
||||
return
|
||||
@ -116,7 +139,7 @@ function DruidMana.prototype:UpdateMana(unit)
|
||||
self:Update()
|
||||
end
|
||||
|
||||
|
||||
-- Only called if the user doesn't have LibDruidMana installed
|
||||
function DruidMana.prototype:UpdateManaMax(unit)
|
||||
if (unit ~= self.unit) then
|
||||
return
|
||||
@ -146,22 +169,30 @@ end
|
||||
|
||||
function DruidMana.prototype:Update()
|
||||
DruidMana.super.prototype.Update(self)
|
||||
|
||||
|
||||
local forms = (UnitPowerType(self.unit) ~= 0)
|
||||
|
||||
if (not self.alive or not forms or not self.druidMana or not self.druidManaMax) then
|
||||
|
||||
if LibDruidMana then
|
||||
self.druidMana = LibDruidMana:GetCurrentMana()
|
||||
self.druidManaMax = LibDruidMana:GetMaximumMana()
|
||||
end
|
||||
|
||||
if (not self.alive or not forms or not self.druidMana or not self.druidManaMax or self.druidManaMax == 0) then
|
||||
self:Show(false)
|
||||
return
|
||||
else
|
||||
self:Show(true)
|
||||
end
|
||||
|
||||
|
||||
self:UpdateBar(self.druidMana / self.druidManaMax, "DruidMana")
|
||||
|
||||
local percentage = (self.druidMana / self.druidManaMax) * 100
|
||||
self:SetBottomText1(math.floor(percentage))
|
||||
self:SetBottomText2(self:GetFormattedText(string.format("%.0f", self.druidMana),
|
||||
string.format("%.0f", self.druidManaMax)), "DruidMana")
|
||||
if not LibDruidMana then
|
||||
local percentage = (self.druidMana / self.druidManaMax) * 100
|
||||
|
||||
self:SetBottomText1(math.floor(percentage))
|
||||
self:SetBottomText2(self:GetFormattedText(string.format("%.0f", self.druidMana),
|
||||
string.format("%.0f", self.druidManaMax)), "DruidMana")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user