From aa179c725b53ccde9ce5a5d9b8c3b294b07876f3 Mon Sep 17 00:00:00 2001 From: Adrian L Lange Date: Thu, 21 Nov 2024 00:26:21 +0100 Subject: [PATCH 1/3] combatindicator: Support units that affect player combat --- elements/combatindicator.lua | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/elements/combatindicator.lua b/elements/combatindicator.lua index 4717be05a..b7b8c8d57 100644 --- a/elements/combatindicator.lua +++ b/elements/combatindicator.lua @@ -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 @@ -71,12 +72,17 @@ 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) + if(unit == 'player') then + self:RegisterEvent('PLAYER_REGEN_DISABLED', Path, true) + self:RegisterEvent('PLAYER_REGEN_ENABLED', Path, true) + else + self:RegisterEvent('UNIT_COMBAT', Path) + self:RegisterEvent('UNIT_FLAGS', Path) + end if(element:IsObjectType('Texture') and not element:GetTexture()) then element:SetTexture([[Interface\CharacterFrame\UI-StateIcon]]) @@ -92,8 +98,13 @@ local function Disable(self) if(element) then element:Hide() - self:UnregisterEvent('PLAYER_REGEN_DISABLED', Path) - self:UnregisterEvent('PLAYER_REGEN_ENABLED', Path) + if(unit == 'player') then + self:UnregisterEvent('PLAYER_REGEN_DISABLED', Path, true) + self:UnregisterEvent('PLAYER_REGEN_ENABLED', Path, true) + else + self:UnregisterEvent('UNIT_COMBAT', Path) + self:UnregisterEvent('UNIT_FLAGS', Path) + end end end From 22f80c85bd2b5090ebd2f37a255f76e40177ff9e Mon Sep 17 00:00:00 2001 From: Adrian L Lange Date: Thu, 21 Nov 2024 00:49:55 +0100 Subject: [PATCH 2/3] Lint pass --- elements/combatindicator.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/combatindicator.lua b/elements/combatindicator.lua index b7b8c8d57..4158d6ee9 100644 --- a/elements/combatindicator.lua +++ b/elements/combatindicator.lua @@ -98,7 +98,7 @@ local function Disable(self) if(element) then element:Hide() - if(unit == 'player') then + if(self.unit == 'player') then self:UnregisterEvent('PLAYER_REGEN_DISABLED', Path, true) self:UnregisterEvent('PLAYER_REGEN_ENABLED', Path, true) else From e7221eadcd98940bd68bc7ddadbb6cc9cf0feb8a Mon Sep 17 00:00:00 2001 From: Adrian L Lange Date: Mon, 25 Nov 2024 17:23:21 +0100 Subject: [PATCH 3/3] One event covers everything, and update docs --- elements/combatindicator.lua | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/elements/combatindicator.lua b/elements/combatindicator.lua index 4158d6ee9..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 @@ -49,7 +49,7 @@ local function Update(self, event, unit) 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) @@ -76,13 +76,7 @@ local function Enable(self, unit) element.__owner = self element.ForceUpdate = ForceUpdate - if(unit == 'player') then - self:RegisterEvent('PLAYER_REGEN_DISABLED', Path, true) - self:RegisterEvent('PLAYER_REGEN_ENABLED', Path, true) - else - self:RegisterEvent('UNIT_COMBAT', Path) - self:RegisterEvent('UNIT_FLAGS', Path) - end + self:RegisterEvent('UNIT_FLAGS', Path) if(element:IsObjectType('Texture') and not element:GetTexture()) then element:SetTexture([[Interface\CharacterFrame\UI-StateIcon]]) @@ -98,13 +92,7 @@ local function Disable(self) if(element) then element:Hide() - if(self.unit == 'player') then - self:UnregisterEvent('PLAYER_REGEN_DISABLED', Path, true) - self:UnregisterEvent('PLAYER_REGEN_ENABLED', Path, true) - else - self:UnregisterEvent('UNIT_COMBAT', Path) - self:UnregisterEvent('UNIT_FLAGS', Path) - end + self:UnregisterEvent('UNIT_FLAGS', Path) end end