Skip to content

Commit

Permalink
combatindicator: Support more units (#692)
Browse files Browse the repository at this point in the history
  • Loading branch information
p3lim authored Nov 30, 2024
1 parent a2f006e commit 69b0657
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions elements/combatindicator.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 All @@ -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)
Expand All @@ -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]])
Expand All @@ -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

Expand Down

0 comments on commit 69b0657

Please sign in to comment.