Skip to content

Commit

Permalink
combatindicator: Support units that affect player combat
Browse files Browse the repository at this point in the history
  • Loading branch information
p3lim committed Nov 20, 2024
1 parent 91d0de9 commit aa179c7
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions elements/combatindicator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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]])
Expand All @@ -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

Check warning on line 101 in elements/combatindicator.lua

View workflow job for this annotation

GitHub Actions / lint

accessing undefined variable 'unit'
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

Expand Down

0 comments on commit aa179c7

Please sign in to comment.