From 69b06571a19f0a29b79ccf22bd0f59fe52019339 Mon Sep 17 00:00:00 2001 From: Adrian L Lange Date: Sat, 30 Nov 2024 13:34:03 +0100 Subject: [PATCH] combatindicator: Support more units (#692) --- elements/combatindicator.lua | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/elements/combatindicator.lua b/elements/combatindicator.lua index 4717be05a..cdea81603 100644 --- a/elements/combatindicator.lua +++ b/elements/combatindicator.lua @@ -1,7 +1,7 @@ --[[ # Element: Combat Indicator -Toggles the visibility of an indicator based on the player's combat status. +Toggles the visibility of an indicator based on the unit's combat status. ## Widget @@ -25,7 +25,8 @@ A default texture will be applied if the widget is a Texture and doesn't have a local _, ns = ... local oUF = ns.oUF -local function Update(self, event) +local function Update(self, event, unit) + if(not unit or self.unit ~= unit) then return end local element = self.CombatIndicator --[[ Callback: CombatIndicator:PreUpdate() @@ -37,7 +38,7 @@ local function Update(self, event) element:PreUpdate() end - local inCombat = UnitAffectingCombat('player') + local inCombat = UnitAffectingCombat(unit) if(inCombat) then element:Show() else @@ -48,7 +49,7 @@ local function Update(self, event) Called after the element has been updated. * self - the CombatIndicator element - * inCombat - indicates if the player is affecting combat (boolean) + * inCombat - indicates if the unit is affecting combat (boolean) --]] if(element.PostUpdate) then return element:PostUpdate(inCombat) @@ -71,12 +72,11 @@ end local function Enable(self, unit) local element = self.CombatIndicator - if(element and UnitIsUnit(unit, 'player')) then + if(element) then element.__owner = self element.ForceUpdate = ForceUpdate - self:RegisterEvent('PLAYER_REGEN_DISABLED', Path, true) - self:RegisterEvent('PLAYER_REGEN_ENABLED', Path, true) + self:RegisterEvent('UNIT_FLAGS', Path) if(element:IsObjectType('Texture') and not element:GetTexture()) then element:SetTexture([[Interface\CharacterFrame\UI-StateIcon]]) @@ -92,8 +92,7 @@ local function Disable(self) if(element) then element:Hide() - self:UnregisterEvent('PLAYER_REGEN_DISABLED', Path) - self:UnregisterEvent('PLAYER_REGEN_ENABLED', Path) + self:UnregisterEvent('UNIT_FLAGS', Path) end end