Skip to content

Commit

Permalink
health: Add temp max health loss sub-widget
Browse files Browse the repository at this point in the history
We decided to move it from health prediction.
  • Loading branch information
ls- committed May 16, 2024
1 parent 6d8a058 commit 3593356
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 59 deletions.
41 changes: 35 additions & 6 deletions elements/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 178 in elements/health.lua

View workflow job for this annotation

GitHub Actions / lint

accessing undefined variable 'Clamp'

Check warning on line 178 in elements/health.lua

View workflow job for this annotation

GitHub Actions / lint

accessing undefined variable 'GetUnitTotalModifiedMaxHealthPercent'

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

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
68 changes: 15 additions & 53 deletions elements/healthprediction.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
}
--]]
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 3593356

Please sign in to comment.