-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphaseindicator.lua
More file actions
158 lines (119 loc) · 4.06 KB
/
phaseindicator.lua
File metadata and controls
158 lines (119 loc) · 4.06 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
--[[
# Element: Phasing Indicator
Toggles the visibility of an indicator based on the unit's phasing relative to the player.
## Widget
PhaseIndicator - Any UI widget.
## Sub-Widgets
.Icon - A `Texture` to represent the phased status.
## Notes
A default texture will be applied if the widget is a Texture and doesn't have a texture or a color set.
OnEnter and OnLeave script handlers will be set to display a Tooltip if the widget is mouse enabled and does not have
OnEnter and/or OnLeave handlers.
## Examples
-- Position and size
local PhaseIndicator = CreateFrame('Frame', nil, self)
PhaseIndicator:SetSize(16, 16)
PhaseIndicator:SetPoint('TOPLEFT', self)
PhaseIndicator:EnableMouse(true)
local Icon = PhaseIndicator:CreateTexture(nil, 'OVERLAY')
Icon:SetAllPoints()
PhaseIndicator.Icon = Icon
-- Register it with oUF
self.PhaseIndicator = PhaseIndicator
--]]
local _, ns = ...
local oUF = ns.oUF
local Private = oUF.Private
--[[ Override: PhaseIndicator:UpdateTooltip()
Used to populate the tooltip when the widget is hovered.
* self - the PhaseIndicator widget
--]]
local function UpdateTooltip(element)
local text = PartyUtil.GetPhasedReasonString(element.reason, element.__owner.unit)
if(text) then
GameTooltip:SetText(text, nil, nil, nil, nil, true)
GameTooltip:Show()
end
end
local function onEnter(element)
if(GameTooltip:IsForbidden() or not element:IsVisible()) then return end
if(element.reason) then
GameTooltip:SetOwner(element, 'ANCHOR_BOTTOMRIGHT')
element:UpdateTooltip()
end
end
local function onLeave()
if(GameTooltip:IsForbidden()) then return end
GameTooltip:Hide()
end
local function Update(self, event, unit)
if(self.unit ~= unit) then return end
local element = self.PhaseIndicator
--[[ Callback: PhaseIndicator:PreUpdate()
Called before the element has been updated.
* self - the PhaseIndicator element
--]]
if(element.PreUpdate) then
element:PreUpdate()
end
-- BUG: UnitPhaseReason returns wrong data for friendly NPCs in phased scenarios like WM or Chromie Time
-- https://github.com/Stanzilla/WoWUIBugs/issues/49
local phaseReason = UnitIsPlayer(unit) and UnitIsConnected(unit) and UnitPhaseReason(unit) or nil
if(phaseReason) then
element:Show()
else
element:Hide()
end
element.reason = phaseReason
--[[ Callback: PhaseIndicator:PostUpdate(isInSamePhase, phaseReason)
Called after the element has been updated.
* self - the PhaseIndicator element
* isInSamePhase - indicates whether the unit is in the same phase as the player (boolean)
* phaseReason - the reason why the unit is in a different phase (number?)
--]]
if(element.PostUpdate) then
return element:PostUpdate(not phaseReason, phaseReason)
end
end
local function Path(self, ...)
--[[ Override: PhaseIndicator.Override(self, event, ...)
Used to completely override the internal update function.
* self - the parent object
* event - the event triggering the update (string)
* ... - the arguments accompanying the event
--]]
return (self.PhaseIndicator.Override or Update) (self, ...)
end
local function ForceUpdate(element)
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
end
local function Enable(self)
local element = self.PhaseIndicator
if(element) then
element.__owner = self
element.ForceUpdate = ForceUpdate
Private.SmartRegisterUnitEvent(self, 'UNIT_PHASE', self.unit, Path)
local icon = (element.Icon or element)
if(icon:IsObjectType('Texture') and not icon:GetTexture()) then
icon:SetAtlas('RaidFrame-Icon-Phasing')
end
if(element.IsMouseEnabled and element:IsMouseEnabled()) then
if(not element:GetScript('OnEnter')) then
element:SetScript('OnEnter', onEnter)
end
if(not element:GetScript('OnLeave')) then
element:SetScript('OnLeave', onLeave)
end
element.UpdateTooltip = element.UpdateTooltip or UpdateTooltip
end
return true
end
end
local function Disable(self)
local element = self.PhaseIndicator
if(element) then
element:Hide()
self:UnregisterEvent('UNIT_PHASE', Path)
end
end
oUF:AddElement('PhaseIndicator', Path, Enable, Disable)