diff --git a/elements/health.lua b/elements/health.lua index 3e834ef4..b07b20e6 100644 --- a/elements/health.lua +++ b/elements/health.lua @@ -173,16 +173,24 @@ local function Update(self, event, unit) element.cur = cur element.max = max - --[[ Callback: Health:PostUpdate(unit, cur, max) + local lossPerc = 0 + if(element.TempLoss) then + lossPerc = Clamp(GetUnitTotalModifiedMaxHealthPercent(unit), 0, 1) + + element.TempLoss:SetValue(lossPerc) + end + + --[[ Callback: Health:PostUpdate(unit, cur, max, lossPerc) Called after the element has been updated. - * self - the Health element - * unit - the unit for which the update has been triggered (string) - * cur - the unit's current health value (number) - * max - the unit's maximum possible health value (number) + * self - the Health element + * unit - the unit for which the update has been triggered (string) + * cur - the unit's current health value (number) + * max - the unit's maximum possible health value (number) + * lossPerc - the percent by which the unit's max health has been temporarily reduced (number) --]] if(element.PostUpdate) then - element:PostUpdate(unit, cur, max) + element:PostUpdate(unit, cur, max, lossPerc) end end @@ -310,6 +318,21 @@ local function Enable(self) element:Show() + if(element.TempLoss) then + self:RegisterEvent('UNIT_MAX_HEALTH_MODIFIERS_CHANGED', Path) + + if(element.TempLoss:IsObjectType('StatusBar')) then + element.TempLoss:SetMinMaxValues(0, 1) + element.TempLoss:SetValue(0) + + if(not element.TempLoss:GetStatusBarTexture()) then + element.TempLoss:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]]) + end + end + + element.TempLoss:Show() + end + return true end end @@ -325,6 +348,12 @@ local function Disable(self) self:UnregisterEvent('UNIT_FACTION', ColorPath) self:UnregisterEvent('UNIT_FLAGS', ColorPath) self:UnregisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath) + + if(element.TempLoss) then + element.TempLoss:Hide() + + self:UnregisterEvent('UNIT_MAX_HEALTH_MODIFIERS_CHANGED', Path) + end end end diff --git a/elements/healthprediction.lua b/elements/healthprediction.lua index fa484f9b..19e61c42 100644 --- a/elements/healthprediction.lua +++ b/elements/healthprediction.lua @@ -9,15 +9,12 @@ HealthPrediction - A `table` containing references to sub-widgets and options. ## Sub-Widgets -myBar - A `StatusBar` used to represent incoming heals from the player. -otherBar - A `StatusBar` used to represent incoming heals from others. -absorbBar - A `StatusBar` used to represent damage absorbs. -healAbsorbBar - A `StatusBar` used to represent heal absorbs. -tempMaxHealthLossBar - A `StatusBar` used to represent temporary max health reduction. -overAbsorb - A `Texture` used to signify that the amount of damage absorb is greater than the unit's missing - health. -overHealAbsorb - A `Texture` used to signify that the amount of heal absorb is greater than the unit's current - health. +myBar - A `StatusBar` used to represent incoming heals from the player. +otherBar - A `StatusBar` used to represent incoming heals from others. +absorbBar - A `StatusBar` used to represent damage absorbs. +healAbsorbBar - A `StatusBar` used to represent heal absorbs. +overAbsorb - A `Texture` used to signify that the amount of damage absorb is greater than the unit's missing health. +overHealAbsorb - A `Texture` used to signify that the amount of heal absorb is greater than the unit's current health. ## Notes @@ -69,19 +66,6 @@ A default texture will be applied to the Texture widgets if they don't have a te overHealAbsorb:SetPoint('RIGHT', self.Health, 'LEFT') overHealAbsorb:SetWidth(10) - local tempMaxHealthLossBar = CreateFrame('StatusBar', nil, self) - tempMaxHealthLossBar:SetHeight(20) - tempMaxHealthLossBar:SetPoint('TOP') - tempMaxHealthLossBar:SetPoint('LEFT') - tempMaxHealthLossBar:SetPoint('RIGHT') - tempMaxHealthLossBar:SetReverseFill(true) - - -- Set the status bar texture because it's needed for the next step - tempMaxHealthLossBar:SetStatusBarTexture('Interface/TargetingFrame/UI-StatusBar') - - -- Adjust relevant points of the health bar if tempMaxHealthLossBar is being used - self.Health:SetPoint('RIGHT', tempMaxHealthLossBar:GetStatusBarTexture(), 'LEFT') - -- Register with oUF self.HealthPrediction = { myBar = myBar, @@ -90,7 +74,6 @@ A default texture will be applied to the Texture widgets if they don't have a te healAbsorbBar = healAbsorbBar, overAbsorb = overAbsorb, overHealAbsorb = overHealAbsorb, - tempMaxHealthLossBar = tempMaxHealthLossBar, maxOverflow = 1.05, } --]] @@ -117,7 +100,6 @@ local function Update(self, event, unit) local allIncomingHeal = UnitGetIncomingHeals(unit) or 0 local absorb = UnitGetTotalAbsorbs(unit) or 0 local healAbsorb = UnitGetTotalHealAbsorbs(unit) or 0 - local tempMaxHealthLossPerc = Clamp(GetUnitTotalModifiedMaxHealthPercent(unit), 0, 1) local health, maxHealth = UnitHealth(unit), UnitHealthMax(unit) local otherIncomingHeal = 0 local hasOverHealAbsorb = false @@ -179,11 +161,6 @@ local function Update(self, event, unit) element.healAbsorbBar:Show() end - if(element.tempMaxHealthLossBar) then - element.tempMaxHealthLossBar:SetValue(tempMaxHealthLossPerc) - element.tempMaxHealthLossBar:Show() - end - if(element.overAbsorb) then if(hasOverAbsorb) then element.overAbsorb:Show() @@ -203,18 +180,17 @@ local function Update(self, event, unit) --[[ Callback: HealthPrediction:PostUpdate(unit, myIncomingHeal, otherIncomingHeal, absorb, healAbsorb, hasOverAbsorb, hasOverHealAbsorb) Called after the element has been updated. - * self - the HealthPrediction element - * unit - the unit for which the update has been triggered (string) - * myIncomingHeal - the amount of incoming healing done by the player (number) - * otherIncomingHeal - the amount of incoming healing done by others (number) - * absorb - the amount of damage the unit can absorb without losing health (number) - * healAbsorb - the amount of healing the unit can absorb without gaining health (number) - * hasOverAbsorb - indicates if the amount of damage absorb is higher than the unit's missing health (boolean) - * hasOverHealAbsorb - indicates if the amount of heal absorb is higher than the unit's current health (boolean) - * tempMaxHealthLossPerc - the percent by which the max health has been temporarily reduced (number) + * self - the HealthPrediction element + * unit - the unit for which the update has been triggered (string) + * myIncomingHeal - the amount of incoming healing done by the player (number) + * otherIncomingHeal - the amount of incoming healing done by others (number) + * absorb - the amount of damage the unit can absorb without losing health (number) + * healAbsorb - the amount of healing the unit can absorb without gaining health (number) + * hasOverAbsorb - indicates if the amount of damage absorb is higher than the unit's missing health (boolean) + * hasOverHealAbsorb - indicates if the amount of heal absorb is higher than the unit's current health (boolean) --]] if(element.PostUpdate) then - return element:PostUpdate(unit, myIncomingHeal, otherIncomingHeal, absorb, healAbsorb, hasOverAbsorb, hasOverHealAbsorb, tempMaxHealthLossPerc) + return element:PostUpdate(unit, myIncomingHeal, otherIncomingHeal, absorb, healAbsorb, hasOverAbsorb, hasOverHealAbsorb) end end @@ -244,7 +220,6 @@ local function Enable(self) self:RegisterEvent('UNIT_HEAL_PREDICTION', Path) self:RegisterEvent('UNIT_ABSORB_AMOUNT_CHANGED', Path) self:RegisterEvent('UNIT_HEAL_ABSORB_AMOUNT_CHANGED', Path) - self:RegisterEvent('UNIT_MAX_HEALTH_MODIFIERS_CHANGED', Path) if(not element.maxOverflow) then element.maxOverflow = 1.05 @@ -288,14 +263,6 @@ local function Enable(self) end end - if(element.tempMaxHealthLossBar) then - element.tempMaxHealthLossBar:SetMinMaxValues(0, 1) - - if(element.tempMaxHealthLossBar:IsObjectType('StatusBar') and not element.tempMaxHealthLossBar:GetStatusBarTexture()) then - element.tempMaxHealthLossBar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]]) - end - end - return true end end @@ -327,16 +294,11 @@ local function Disable(self) element.overHealAbsorb:Hide() end - if(element.tempMaxHealthLossBar) then - element.tempMaxHealthLossBar:Hide() - end - self:UnregisterEvent('UNIT_HEALTH', Path) self:UnregisterEvent('UNIT_MAXHEALTH', Path) self:UnregisterEvent('UNIT_HEAL_PREDICTION', Path) self:UnregisterEvent('UNIT_ABSORB_AMOUNT_CHANGED', Path) self:UnregisterEvent('UNIT_HEAL_ABSORB_AMOUNT_CHANGED', Path) - self:UnregisterEvent('UNIT_MAX_HEALTH_MODIFIERS_CHANGED', Path) end end