mirror of
https://github.com/parnic/ice-hud.git
synced 2025-06-16 06:40:13 -05:00
Version 0.9
- New round bar texture - Standalone druid mana bar - Lots of stuff I can't remember
This commit is contained in:
@ -1,11 +1,14 @@
|
||||
local AceOO = AceLibrary("AceOO-2.0")
|
||||
|
||||
local DruidMana = AceOO.Class(IceUnitBar)
|
||||
local gratuity = AceLibrary("Gratuity-2.0")
|
||||
|
||||
DruidMana.prototype.inForms = nil
|
||||
DruidMana.prototype.mode = nil
|
||||
DruidMana.prototype.druidMana = nil
|
||||
DruidMana.prototype.druidMaxMana = nil
|
||||
DruidMana.prototype.druidManaMax = nil
|
||||
DruidMana.prototype.lastCast = nil
|
||||
DruidMana.prototype.baseMana = nil
|
||||
|
||||
local intMod = 14
|
||||
|
||||
|
||||
-- Constructor --
|
||||
@ -30,32 +33,16 @@ end
|
||||
function DruidMana.prototype:Enable(core)
|
||||
DruidMana.super.prototype.Enable(self, core)
|
||||
|
||||
if (IsAddOnLoaded("SoleManax")) then
|
||||
self.mode = "SoleManax"
|
||||
SoleManax:AddUser(self.UpdateSoleManax, TRUE, self)
|
||||
self:UpdateSoleManax(SoleManax:GetPlayerMana())
|
||||
|
||||
elseif (IsAddOnLoaded("DruidBar")) then
|
||||
self.mode = "DruidBar"
|
||||
self:ScheduleRepeatingEvent("DruidBar", self.UpdateDruidBarMana, 0.2, self)
|
||||
end
|
||||
self:FormsChanged(self.unit)
|
||||
|
||||
self:RegisterEvent("UNIT_DISPLAYPOWER", "FormsChanged")
|
||||
|
||||
self:FormsChanged(self.unit)
|
||||
self:RegisterEvent("UNIT_MANA", "UpdateMana")
|
||||
self:RegisterEvent("UNIT_MAXMANA", "UpdateManaMax")
|
||||
end
|
||||
|
||||
|
||||
function DruidMana.prototype:Disable(core)
|
||||
DruidMana.super.prototype.Disable(self, core)
|
||||
|
||||
if (IsAddOnLoaded("SoleManax")) then
|
||||
SoleManax.DelUser(self.UpdateSoleManax)
|
||||
end
|
||||
|
||||
if (IsAddOnLoaded("DruidBar")) then
|
||||
self:CancelScheduledEvent("DruidBar")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -63,50 +50,124 @@ function DruidMana.prototype:FormsChanged(unit)
|
||||
if (unit ~= self.unit) then
|
||||
return
|
||||
end
|
||||
|
||||
local forms = (UnitPowerType(self.unit) ~= 0)
|
||||
|
||||
if (forms) then
|
||||
self.lastCast = GetTime()
|
||||
|
||||
if (not self.druidMana) then
|
||||
return
|
||||
end
|
||||
|
||||
-- deduct the shapeshift cost from last known mana value
|
||||
-- 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
|
||||
|
||||
self.druidMana = self.druidMana - (manaCost or 0)
|
||||
|
||||
SetCVar("UberTooltips", uberTooltips)
|
||||
else
|
||||
-- always update with actual mana values when shifting out
|
||||
self:UpdateMana(self.unit)
|
||||
self:UpdateManaMax(self.unit)
|
||||
|
||||
local _, intellect, _, _ = UnitStat(self.unit, 4)
|
||||
self.baseMana = UnitMana(self.unit) - (intellect * intMod)
|
||||
end
|
||||
|
||||
self.inForms = (UnitPowerType(self.unit) ~= 0)
|
||||
self:Update()
|
||||
end
|
||||
|
||||
|
||||
function DruidMana.prototype:UpdateSoleManax(mana, maxMana)
|
||||
function DruidMana.prototype:UpdateMana(unit)
|
||||
if (unit ~= self.unit) then
|
||||
return
|
||||
end
|
||||
|
||||
local forms = (UnitPowerType(self.unit) ~= 0)
|
||||
|
||||
if (forms) then
|
||||
if (not self.druidMana or not self.lastCast) then
|
||||
return
|
||||
end
|
||||
|
||||
local time = GetTime()
|
||||
local normal, casting = GetManaRegen()
|
||||
|
||||
if (time - self.lastCast > 5) then
|
||||
self.druidMana = self.druidMana + (normal * 2)
|
||||
else
|
||||
self.druidMana = self.druidMana + (casting * 2)
|
||||
end
|
||||
|
||||
-- sanity check, the tick can be off a little sometimes
|
||||
if (self.druidMana > self.druidManaMax) then
|
||||
self.druidMana = self.druidManaMax
|
||||
end
|
||||
else
|
||||
self.druidMana = UnitMana(self.unit)
|
||||
end
|
||||
|
||||
self:Update()
|
||||
self.druidMana = mana
|
||||
self.druidMaxMana = maxMana
|
||||
end
|
||||
|
||||
|
||||
function DruidMana.prototype:UpdateDruidBarMana()
|
||||
function DruidMana.prototype:UpdateManaMax(unit)
|
||||
if (unit ~= self.unit) then
|
||||
return
|
||||
end
|
||||
|
||||
local forms = (UnitPowerType(self.unit) ~= 0)
|
||||
|
||||
if (forms) then
|
||||
if not (self.baseMana) then
|
||||
return
|
||||
end
|
||||
|
||||
local _, intellect, _, _ = UnitStat(self.unit, 4)
|
||||
|
||||
self.druidManaMax = self.baseMana + (intellect * intMod)
|
||||
|
||||
if (self.druidMana > self.druidManaMax) then
|
||||
self.druidMana = self.druidManaMax
|
||||
end
|
||||
else
|
||||
self.druidManaMax = UnitManaMax(self.unit)
|
||||
end
|
||||
|
||||
self:Update()
|
||||
self.druidMana = DruidBarKey.keepthemana
|
||||
self.druidMaxMana = DruidBarKey.maxmana
|
||||
end
|
||||
|
||||
|
||||
function DruidMana.prototype:Update()
|
||||
DruidMana.super.prototype.Update(self)
|
||||
if ((not self.alive) or (not self.inForms)) then
|
||||
|
||||
local forms = (UnitPowerType(self.unit) ~= 0)
|
||||
|
||||
if (not self.alive or not forms or not self.druidMana or not self.druidManaMax) then
|
||||
self.frame:Hide()
|
||||
return
|
||||
else
|
||||
self.frame:Show()
|
||||
end
|
||||
|
||||
if (not self.druidMana or not self.druidMaxMana) then
|
||||
return
|
||||
end
|
||||
|
||||
self:UpdateBar(self.druidMana / self.druidMaxMana, "DruidMana")
|
||||
self:UpdateBar(self.druidMana / self.druidManaMax, "DruidMana")
|
||||
|
||||
local percentage = (self.druidMana / self.druidMaxMana) * 100
|
||||
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.druidMaxMana)), "DruidMana")
|
||||
self:SetBottomText2(self:GetFormattedText(string.format("%.0f", self.druidMana),
|
||||
string.format("%.0f", self.druidManaMax)), "DruidMana")
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- Load us up (if we are a druid)
|
||||
local _, unitClass = UnitClass("player")
|
||||
if (unitClass == "DRUID" and (IsAddOnLoaded("SoleManax") or IsAddOnLoaded("DruidBar"))) then
|
||||
DruidMana:new()
|
||||
if (unitClass == "DRUID") then
|
||||
IceHUD.DruidMana = DruidMana:new()
|
||||
end
|
||||
|
Reference in New Issue
Block a user