-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadycheckindicator.lua
More file actions
191 lines (152 loc) · 5.42 KB
/
readycheckindicator.lua
File metadata and controls
191 lines (152 loc) · 5.42 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
--[[
# Element: Ready Check Indicator
Handles the visibility and updating of an indicator based on the unit's ready check status.
## Widget
ReadyCheckIndicator - A `Texture` representing ready check status.
## Notes
This element updates by changing the texture.
Default textures will be applied if the layout does not provide custom ones. See Options.
## Options
.finishedTime - For how many seconds the icon should stick after a check has completed. Defaults to 10 (number).
.fadeTime - For how many seconds the icon should fade away after the stick duration has completed. Defaults to
1.5 (number).
.useAtlasSize - Makes the element use preprogrammed atlas' size instead of its set dimensions (boolean)
## Attributes
.status - the unit's ready check status (string?)['ready', 'noready', 'waiting']
## Examples
-- Position and size
local ReadyCheckIndicator = self:CreateTexture(nil, 'OVERLAY')
ReadyCheckIndicator:SetSize(16, 16)
ReadyCheckIndicator:SetPoint('TOP')
-- Register with oUF
self.ReadyCheckIndicator = ReadyCheckIndicator
--]]
local _, ns = ...
local oUF = ns.oUF
local Private = oUF.Private
local unitExists = Private.unitExists
local function OnFinished(self)
local element = self:GetParent()
element:Hide()
--[[ Callback: ReadyCheckIndicator:PostUpdateFadeOut()
Called after the element has been faded out.
* self - the ReadyCheckIndicator element
--]]
if(element.PostUpdateFadeOut) then
element:PostUpdateFadeOut()
end
end
local function Update(self, event)
local element = self.ReadyCheckIndicator
local unit = self.unit
--[[ Callback: ReadyCheckIndicator:PreUpdate()
Called before the element has been updated.
* self - the ReadyCheckIndicator element
--]]
if(element.PreUpdate) then
element:PreUpdate()
end
local status = GetReadyCheckStatus(unit)
if(unitExists(unit) and status) then
if(status == 'ready') then
if(element.readyTexture) then
element:SetTexture(element.readyTexture) -- DEPRECATED
else
element:SetAtlas('UI-LFG-ReadyMark-Raid', element.useAtlasSize)
end
elseif(status == 'notready') then
if(element.notReadyTexture) then
element:SetTexture(element.notReadyTexture) -- DEPRECATED
else
element:SetAtlas('UI-LFG-DeclineMark-Raid', element.useAtlasSize)
end
else
if(element.waitingTexture) then
element:SetTexture(element.waitingTexture) -- DEPRECATED
else
element:SetAtlas('UI-LFG-PendingMark-Raid', element.useAtlasSize)
end
end
element.status = status
element:Show()
-- Apply visual ready check glow effect using ObjectPool
local addon = _G.SimpleUnitFrames
if addon and addon.IndicatorPoolManager then
if status == 'ready' then
addon.IndicatorPoolManager:ApplyCustomGlow(self, 0.2, 1, 0.2, 0.7) -- Green glow for ready
elseif status == 'notready' then
addon.IndicatorPoolManager:ApplyCustomGlow(self, 1, 0.2, 0.2, 0.7) -- Red glow for not ready
else
addon.IndicatorPoolManager:ApplyCustomGlow(self, 1, 1, 0.2, 0.7) -- Yellow glow for waiting
end
end
elseif(event ~= 'READY_CHECK_FINISHED') then
element.status = nil
element:Hide()
-- Release ready check glow when not checking
local addon = _G.SimpleUnitFrames
if addon and addon.IndicatorPoolManager then
addon.IndicatorPoolManager:Release(self, "custom_glow")
end
end
if(event == 'READY_CHECK_FINISHED') then
if(element.status == 'waiting') then
if(element.notReadyTexture) then
element:SetTexture(element.notReadyTexture) -- DEPRECATED
else
element:SetAtlas('UI-LFG-DeclineMark-Raid', element.useAtlasSize)
end
end
element.Animation:Play()
end
--[[ Callback: ReadyCheckIndicator:PostUpdate(status)
Called after the element has been updated.
* self - the ReadyCheckIndicator element
* status - the unit's ready check status (string?)['ready', 'notready', 'waiting']
--]]
if(element.PostUpdate) then
return element:PostUpdate(status)
end
end
local function Path(self, ...)
--[[ Override: ReadyCheckIndicator.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.ReadyCheckIndicator.Override or Update) (self, ...)
end
local function ForceUpdate(element)
return Path(element.__owner, 'ForceUpdate')
end
local function Enable(self, unit)
local element = self.ReadyCheckIndicator
unit = unit and unit:match('(%a+)%d*$')
if(element and (unit == 'party' or unit == 'raid')) then
element.__owner = self
element.ForceUpdate = ForceUpdate
local AnimationGroup = element:CreateAnimationGroup()
AnimationGroup:SetScript('OnFinished', OnFinished)
element.Animation = AnimationGroup
local Animation = AnimationGroup:CreateAnimation('Alpha')
Animation:SetFromAlpha(1)
Animation:SetToAlpha(0)
Animation:SetDuration(element.fadeTime or 1.5)
Animation:SetStartDelay(element.finishedTime or 10)
self:RegisterEvent('READY_CHECK', Path, true)
self:RegisterEvent('READY_CHECK_CONFIRM', Path, true)
self:RegisterEvent('READY_CHECK_FINISHED', Path, true)
return true
end
end
local function Disable(self)
local element = self.ReadyCheckIndicator
if(element) then
element:Hide()
self:UnregisterEvent('READY_CHECK', Path)
self:UnregisterEvent('READY_CHECK_CONFIRM', Path)
self:UnregisterEvent('READY_CHECK_FINISHED', Path)
end
end
oUF:AddElement('ReadyCheckIndicator', Path, Enable, Disable)