Skip to content

Commit

Permalink
healthprediction: Add optional element size adjustment
Browse files Browse the repository at this point in the history
It's needed due to the nature of the element, but if layout devs want to
do something else they can always override the whole thing 😵
  • Loading branch information
ls- committed Jun 15, 2024
1 parent 9d2fea3 commit 1f1a6a2
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions elements/healthprediction.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,30 @@ A default texture will be applied to the Texture widgets if they don't have a te
local _, ns = ...
local oUF = ns.oUF

local function UpdateSize(self, event, unit)
if(not self.Health or self.unit ~= unit) then return end

local element = self.HealthPrediction
local isHoriz = self.Health:GetOrientation() == 'HORIZONTAL'
local newSize = self.Health[isHoriz and 'GetWidth' or 'GetHeight'](self.Health)

if(element.myBar) then
element.myBar[isHoriz and 'SetWidth' or 'SetHeight'](element.myBar, newSize)
end

if(element.otherBar) then
element.otherBar[isHoriz and 'SetWidth' or 'SetHeight'](element.otherBar, newSize)
end

if(element.absorbBar) then
element.absorbBar[isHoriz and 'SetWidth' or 'SetHeight'](element.absorbBar, newSize)
end

if(element.healAbsorbBar) then
element.healAbsorbBar[isHoriz and 'SetWidth' or 'SetHeight'](element.healAbsorbBar, newSize)
end
end

local function Update(self, event, unit)
if(self.unit ~= unit) then return end

Expand Down Expand Up @@ -194,15 +218,19 @@ local function Update(self, event, unit)
end
end

local function Path(self, ...)
local function Path(self, event, ...)
if(event == 'UpdateAllElements' or event == 'UNIT_MAX_HEALTH_MODIFIERS_CHANGED') then
(self.HealthPrediction.UpdateSize or UpdateSize) (self, event, ...)
end

--[[ Override: HealthPrediction.Override(self, event, unit)
Used to completely override the internal update function.
* self - the parent object
* event - the event triggering the update (string)
* unit - the unit accompanying the event
--]]
return (self.HealthPrediction.Override or Update) (self, ...)
return (self.HealthPrediction.Override or Update) (self, event, ...)
end

local function ForceUpdate(element)
Expand All @@ -220,6 +248,7 @@ 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 @@ -299,6 +328,7 @@ local function Disable(self)
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 1f1a6a2

Please sign in to comment.