-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombatindicator.lua
More file actions
99 lines (74 loc) · 2.24 KB
/
Copy pathcombatindicator.lua
File metadata and controls
99 lines (74 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
--[[
# Element: Combat Indicator
Toggles the visibility of an indicator based on the unit's combat status.
## Widget
CombatIndicator - Any UI widget.
## Notes
A default texture will be applied if the widget is a Texture and doesn't have a texture or a color set.
## Examples
-- Position and size
local CombatIndicator = self:CreateTexture(nil, 'OVERLAY')
CombatIndicator:SetSize(16, 16)
CombatIndicator:SetPoint('TOP', self)
-- Register it with oUF
self.CombatIndicator = CombatIndicator
--]]
local _, ns = ...
local oUF = ns.oUF
local Private = oUF.Private
local function Update(self, event, unit)
if(not unit or self.unit ~= unit) then return end
local element = self.CombatIndicator
--[[ Callback: CombatIndicator:PreUpdate()
Called before the element has been updated.
* self - the CombatIndicator element
--]]
if(element.PreUpdate) then
element:PreUpdate()
end
local inCombat = UnitAffectingCombat(unit)
if(inCombat) then
element:Show()
else
element:Hide()
end
--[[ Callback: CombatIndicator:PostUpdate(inCombat)
Called after the element has been updated.
* self - the CombatIndicator element
* inCombat - indicates if the unit is affecting combat (boolean)
--]]
if(element.PostUpdate) then
return element:PostUpdate(inCombat)
end
end
local function Path(self, ...)
--[[ Override: CombatIndicator.Override(self, event)
Used to completely override the internal update function.
* self - the parent object
* event - the event triggering the update (string)
--]]
return (self.CombatIndicator.Override or Update) (self, ...)
end
local function ForceUpdate(element)
return Path(element.__owner, 'ForceUpdate')
end
local function Enable(self, unit)
local element = self.CombatIndicator
if(element) then
element.__owner = self
element.ForceUpdate = ForceUpdate
Private.SmartRegisterUnitEvent(self, 'UNIT_FLAGS', self.unit, Path)
if(element:IsObjectType('Texture') and not element:GetTexture()) then
element:SetAtlas('UI-HUD-UnitFrame-Player-CombatIcon')
end
return true
end
end
local function Disable(self)
local element = self.CombatIndicator
if(element) then
element:Hide()
self:UnregisterEvent('UNIT_FLAGS', Path)
end
end
oUF:AddElement('CombatIndicator', Path, Enable, Disable)