Hello!
I've got a problem with oUF that i just can't get my head around. Basically its a absorb bar that goes from 0-100% of a units hp, anchored to the health. It's mostly working fine, but if the unit have an absorb on itself when the unitframe is first viewed after a login, it maxes out. If i have opened the unitframe before they get an absorb however, it works fine.
Creating the bars:
Lua Code:
-- Absorb bar
local TotalAbsorb = CreateFrame('StatusBar', nil, self.Health)
TotalAbsorb:SetStatusBarTexture(config.absorbtexture, "OVERLAY")
TotalAbsorb:SetFrameLevel(self:GetFrameLevel() - 1)
TotalAbsorb:SetStatusBarColor(1,1,1,1)
TotalAbsorb:SetAllPoints(self.Health)
TotalAbsorb:Hide()
local spark = TotalAbsorb:CreateTexture(nil, 'ARTWORK', "OverAbsorbGlowTemplate")
spark:SetSize(20,5)
spark:Hide()
TotalAbsorb.spark = spark
-- Incoming Heals
local incHeals = ns.CreateStatusBar(self.Health)
incHeals:SetPoint('TOPLEFT', self.Health:GetStatusBarTexture(), 'TOPRIGHT')
incHeals:SetPoint('BOTTOMRIGHT')
incHeals:SetFrameLevel(self:GetFrameLevel() - 1)
incHeals:SetStatusBarColor(0, 1, 0, 0.5)
incHeals:SetFrameStrata('MEDIUM')
incHeals:Hide()
-- Absorbing Heals
local necroHeals = ns.CreateStatusBar(self.Health, 'OVERLAY')
necroHeals:SetFrameLevel(self:GetFrameLevel() - 1)
necroHeals:SetStatusBarColor(1, 0, 0, 0.3)
necroHeals:SetReverseFill(true)
necroHeals:SetPoint('TOPLEFT')
necroHeals:SetPoint('BOTTOMRIGHT', self.Health:GetStatusBarTexture(), 'BOTTOMRIGHT')
self.HealPrediction = {
incHeals = incHeals,
necroHeals = necroHeals,
TotalAbsorb = TotalAbsorb,
Override = ns.UpdateIncHeals,
}
And the update function:
Lua Code:
function ns.UpdateIncHeals(self, event, unit)
if (self.unit ~= unit) then return end
local hp = self.HealPrediction
local curHP, _, maxHP = self.Health:GetValue(), self.Health:GetMinMaxValues()
local incHeal = UnitGetIncomingHeals(unit) or 0
local healAbsorb = UnitGetTotalHealAbsorbs(unit) or 0
if ( healAbsorb > 0) then
hp.necroHeals:SetMinMaxValues(0, curHP)
hp.necroHeals:SetValue(math.min(healAbsorb, curHP))
hp.necroHeals:Show()
else
hp.necroHeals:Hide()
end
if ((incHeal - healAbsorb) <= 0) or (curHP == maxHP) then
hp.incHeals:Hide()
else
hp.incHeals:SetMinMaxValues(0, maxHP - curHP)
hp.incHeals:SetValue(incHeal - healAbsorb)
hp.incHeals:Show()
end
if (hp.TotalAbsorb) then
local absorb = UnitGetTotalAbsorbs(unit) or 0
if (absorb == 0) then
hp.TotalAbsorb.spark:Hide()
hp.TotalAbsorb:Hide()
else
hp.TotalAbsorb:SetMinMaxValues(0, maxHP)
hp.TotalAbsorb:SetValue(math.min(absorb, maxHP))
hp.TotalAbsorb:Show()
hp.TotalAbsorb.spark:ClearAllPoints()
hp.TotalAbsorb.spark:SetPoint('BOTTOM', hp.TotalAbsorb:GetStatusBarTexture(),'BOTTOMRIGHT', 0, -1)
hp.TotalAbsorb.spark:Show()
end
print(unit, self.unit, absorb,"VALUE:",math.min(absorb, maxHP),"MAXHP", maxHP,"POINTS",hp.TotalAbsorb:GetPoint())
end
end