File src/ChorusAuraButtonTemplate.lua changed (mode: 100644) (index 36d091b..6527d36) |
1 |
|
--[[-- |
|
2 |
|
@submodule chorus |
|
3 |
|
]] |
|
4 |
|
|
|
5 |
1 |
--[[-- |
--[[-- |
6 |
2 |
`ChorusAuraButtonTemplate` handles individual aura pictograms. |
`ChorusAuraButtonTemplate` handles individual aura pictograms. |
7 |
3 |
|
|
|
... |
... |
Features: |
13 |
9 |
* show aura category (Magic, Poison, Disease, Curse); |
* show aura category (Magic, Poison, Disease, Curse); |
14 |
10 |
* display tooltip on mouseover; |
* display tooltip on mouseover; |
15 |
11 |
|
|
16 |
|
@section ChorusAuraButtonTemplate |
|
|
12 |
|
@submodule chorus |
17 |
13 |
]] |
]] |
18 |
14 |
|
|
19 |
15 |
local Chorus = Chorus |
local Chorus = Chorus |
|
... |
... |
local UnitIsConnected = Chorus.test.UnitIsConnected or UnitIsConnected |
25 |
21 |
local UnitIsUnit = Chorus.test.UnitIsUnit or UnitIsUnit |
local UnitIsUnit = Chorus.test.UnitIsUnit or UnitIsUnit |
26 |
22 |
|
|
27 |
23 |
local DebuffTypeColor = DebuffTypeColor |
local DebuffTypeColor = DebuffTypeColor |
|
24 |
|
|
28 |
25 |
local GameTooltip = GameTooltip |
local GameTooltip = GameTooltip |
|
26 |
|
|
29 |
27 |
local SecureButton_GetUnit = Chorus.test.SecureButton_GetUnit or SecureButton_GetUnit |
local SecureButton_GetUnit = Chorus.test.SecureButton_GetUnit or SecureButton_GetUnit |
30 |
28 |
|
|
|
29 |
|
--[[-- |
|
30 |
|
Check given aura button is configured as expected by the rest of the template. |
|
31 |
|
|
|
32 |
|
@function auraButtonValidate |
|
33 |
|
@raise assertion exception |
|
34 |
|
@tparam frame auraButton aura button |
|
35 |
|
@return when successful, nothing; when failed, assertion exception; |
|
36 |
|
]] |
31 |
37 |
local function auraButtonValidate(auraButton) |
local function auraButtonValidate(auraButton) |
32 |
38 |
assert(auraButton ~= nil) |
assert(auraButton ~= nil) |
33 |
39 |
|
|
|
... |
... |
local function auraButtonValidate(auraButton) |
36 |
42 |
assert(auraButton.overlay ~= nil) |
assert(auraButton.overlay ~= nil) |
37 |
43 |
end |
end |
38 |
44 |
|
|
|
45 |
|
--[[-- |
|
46 |
|
Render pictogram artwork for this aura button. |
|
47 |
|
|
|
48 |
|
Fallback to a picture of a question mark if the artwork could not be loaded. |
|
49 |
|
That is, when `artworkFile` is `nil`. |
|
50 |
|
|
|
51 |
|
@function applyArtwork |
|
52 |
|
|
|
53 |
|
@tparam frame auraButton this aura button |
|
54 |
|
|
|
55 |
|
@tparam string artworkFile pathname in Windows format with escape characters; |
|
56 |
|
]] |
39 |
57 |
local function applyArtwork(auraButton, artworkFile) |
local function applyArtwork(auraButton, artworkFile) |
40 |
58 |
auraButtonValidate(auraButton) |
auraButtonValidate(auraButton) |
41 |
59 |
|
|
|
... |
... |
local function applyArtwork(auraButton, artworkFile) |
53 |
71 |
artwork:SetTexture(artworkFile) |
artwork:SetTexture(artworkFile) |
54 |
72 |
end |
end |
55 |
73 |
|
|
|
74 |
|
--[[-- |
|
75 |
|
Render sanitized and color coded border for this aura button. |
|
76 |
|
|
|
77 |
|
@see FrameXML/BuffFrame.lua:DebuffTypeColor |
|
78 |
|
|
|
79 |
|
@function applyOverlay |
|
80 |
|
|
|
81 |
|
@tparam frame auraButton this aura button |
|
82 |
|
|
|
83 |
|
@tparam string category key of `DebuffTypeColor` table |
|
84 |
|
|
|
85 |
|
@tparam string owner unit designation of caster of the given aura, used for |
|
86 |
|
color coding; in reality, either `player` or `nil` |
|
87 |
|
|
|
88 |
|
@return nothing |
|
89 |
|
]] |
56 |
90 |
local function applyOverlay(auraButton, category, owner) |
local function applyOverlay(auraButton, category, owner) |
57 |
91 |
auraButtonValidate(auraButton) |
auraButtonValidate(auraButton) |
58 |
92 |
|
|
|
... |
... |
local function applyOverlay(auraButton, category, owner) |
99 |
133 |
end |
end |
100 |
134 |
end |
end |
101 |
135 |
|
|
|
136 |
|
--[[-- |
|
137 |
|
Format the given amount of seconds into a narrow human readable string. |
|
138 |
|
|
|
139 |
|
This is inteded for aura effects. It may be used for any generic duration. |
|
140 |
|
|
|
141 |
|
@function formatDuration |
|
142 |
|
|
|
143 |
|
@tparam number durationSec positive number and not zero, the remaining seconds |
|
144 |
|
of some effect |
|
145 |
|
|
|
146 |
|
@treturn string remaining duration coerced into a string that is human |
|
147 |
|
readeable and narrow for convenient rendering |
|
148 |
|
]] |
102 |
149 |
local function formatDuration(durationSec) |
local function formatDuration(durationSec) |
103 |
150 |
assert(durationSec ~= nil) |
assert(durationSec ~= nil) |
104 |
151 |
assert('number' == type(durationSec)) |
assert('number' == type(durationSec)) |
|
... |
... |
local function formatDuration(durationSec) |
117 |
164 |
return t |
return t |
118 |
165 |
end |
end |
119 |
166 |
|
|
|
167 |
|
--[[-- |
|
168 |
|
Compute remaining aura duration for this aura button, given time instances, |
|
169 |
|
then sanitize, format and render it. |
|
170 |
|
|
|
171 |
|
@function applyDuration |
|
172 |
|
|
|
173 |
|
@tparam frame auraButton this aura button |
|
174 |
|
|
|
175 |
|
@tparam number now time instance, in the format of `function GetTime`, current |
|
176 |
|
real time |
|
177 |
|
|
|
178 |
|
@tparam number totalDurationSec positive number, the total duration in seconds |
|
179 |
|
of the aura |
|
180 |
|
|
|
181 |
|
@tparam number expirationInstance time instance, in the format of `function |
|
182 |
|
GetTime`, the instance when the aura effect ends |
|
183 |
|
|
|
184 |
|
@return nothing |
|
185 |
|
]] |
120 |
186 |
local function applyDuration(auraButton, now, totalDurationSec, expirationInstance) |
local function applyDuration(auraButton, now, totalDurationSec, expirationInstance) |
121 |
187 |
auraButtonValidate(auraButton) |
auraButtonValidate(auraButton) |
122 |
188 |
|
|
|
... |
... |
local function applyDuration(auraButton, now, totalDurationSec, expirationInstan |
160 |
226 |
end |
end |
161 |
227 |
end |
end |
162 |
228 |
|
|
|
229 |
|
--[[-- |
|
230 |
|
Sanitize, format and render the charge quantity for this aura button. |
|
231 |
|
|
|
232 |
|
@function applyChargeQuantity |
|
233 |
|
|
|
234 |
|
@tparam frame auraButton this aura button |
|
235 |
|
|
|
236 |
|
@tparam integer chargeQuantity positive integer and not zero, the remaining |
|
237 |
|
charges (stacks) of the aura |
|
238 |
|
|
|
239 |
|
@return nothing |
|
240 |
|
]] |
163 |
241 |
local function applyChargeQuantity(auraButton, chargeQuantity) |
local function applyChargeQuantity(auraButton, chargeQuantity) |
164 |
242 |
auraButtonValidate(auraButton) |
auraButtonValidate(auraButton) |
165 |
243 |
|
|
|
... |
... |
local function applyChargeQuantity(auraButton, chargeQuantity) |
182 |
260 |
label:SetText(t) |
label:SetText(t) |
183 |
261 |
end |
end |
184 |
262 |
|
|
|
263 |
|
--[[-- |
|
264 |
|
Every frame, update the remaining duration and remaining stack quantity of the |
|
265 |
|
aura, of this aura button. |
|
266 |
|
|
|
267 |
|
Update scripts like this should be optimized for performance. Update scripts |
|
268 |
|
also rely on the current real time and implicit game state. |
|
269 |
|
|
|
270 |
|
Remaining duration of an aura cannot be queried. It must be computed, given |
|
271 |
|
time instances that could be queried. This is the purpose of the update |
|
272 |
|
processor function. |
|
273 |
|
|
|
274 |
|
@see FrameXML/SecureTemplates.lua:function SecureButton_GetUnit |
|
275 |
|
@function auraButtonUpdateProcessor |
|
276 |
|
@tparam frame self aura button |
|
277 |
|
@return nothing |
|
278 |
|
]] |
185 |
279 |
local function auraButtonUpdateProcessor(self) |
local function auraButtonUpdateProcessor(self) |
186 |
280 |
local unitDesignation = SecureButton_GetUnit(self) |
local unitDesignation = SecureButton_GetUnit(self) |
187 |
281 |
local index = self.index |
local index = self.index |
|
... |
... |
local function auraButtonUpdateProcessor(self) |
197 |
291 |
applyChargeQuantity(self, chargeQuantity) |
applyChargeQuantity(self, chargeQuantity) |
198 |
292 |
end |
end |
199 |
293 |
|
|
|
294 |
|
--[[-- |
|
295 |
|
Request relevant aura details, then apply them to the aura button. |
|
296 |
|
|
|
297 |
|
@function apply |
|
298 |
|
|
|
299 |
|
@see auraButtonUpdateProcessor |
|
300 |
|
|
|
301 |
|
@tparam frame auraButton |
|
302 |
|
|
|
303 |
|
@tparam string unitDesignation corresponding unit |
|
304 |
|
|
|
305 |
|
@tparam integer auraIndex positive integer and not zero, sequantial number of a |
|
306 |
|
single aura from the list relevant to the unit |
|
307 |
|
|
|
308 |
|
@tparam string filter usually either BUFF or DEBUFF, mutually exclusive |
|
309 |
|
|
|
310 |
|
@return nothing |
|
311 |
|
]] |
200 |
312 |
local function apply(auraButton, unitDesignation, auraIndex, filter) |
local function apply(auraButton, unitDesignation, auraIndex, filter) |
201 |
313 |
auraButtonValidate(auraButton) |
auraButtonValidate(auraButton) |
202 |
314 |
|
|
|
... |
... |
local function apply(auraButton, unitDesignation, auraIndex, filter) |
216 |
328 |
assert(string.len(filter) >= 1) |
assert(string.len(filter) >= 1) |
217 |
329 |
assert(string.len(filter) <= 256) |
assert(string.len(filter) <= 256) |
218 |
330 |
|
|
|
331 |
|
--[[ @warning Aura button event processor might fail in restricted |
|
332 |
|
environment. ]]-- |
219 |
333 |
|
|
220 |
334 |
if not UnitExists(unitDesignation) or not UnitIsConnected(unitDesignation) then |
if not UnitExists(unitDesignation) or not UnitIsConnected(unitDesignation) then |
221 |
335 |
auraButton:Hide() |
auraButton:Hide() |
|
... |
... |
local function apply(auraButton, unitDesignation, auraIndex, filter) |
240 |
354 |
applyChargeQuantity(auraButton, chargeQuantity) |
applyChargeQuantity(auraButton, chargeQuantity) |
241 |
355 |
end |
end |
242 |
356 |
|
|
243 |
|
local function auraButtonEventProcessor(self, eventCategory, ...) |
|
|
357 |
|
--[[-- |
|
358 |
|
Process stream of events, filter events only relevant to the aura button. |
|
359 |
|
|
|
360 |
|
When aura is added or removed from a unit, given the aura button is assigned to |
|
361 |
|
watch that unit, then apply relevant changes to the aura button. |
|
362 |
|
|
|
363 |
|
@function auraButtonEventProcessor |
|
364 |
|
@see FrameXML/SecureTemplates.lua:function SecureButton_GetUnit |
|
365 |
|
@see apply |
|
366 |
|
@tparam frame self the aura button |
|
367 |
|
@tparam string eventCategory event category designation of the given event |
|
368 |
|
@param unitDesignation vararg, given `UNIT_AURA`, |
|
369 |
|
@return nothing |
|
370 |
|
]] |
|
371 |
|
function Chorus.auraButtonEventProcessor(self, eventCategory, ...) |
244 |
372 |
auraButtonValidate(self) |
auraButtonValidate(self) |
245 |
373 |
|
|
246 |
374 |
local u = SecureButton_GetUnit(self) or 'none' |
local u = SecureButton_GetUnit(self) or 'none' |
|
... |
... |
local function auraButtonEventProcessor(self, eventCategory, ...) |
289 |
417 |
apply(self, u, i, filter) |
apply(self, u, i, filter) |
290 |
418 |
end |
end |
291 |
419 |
|
|
|
420 |
|
--[[-- |
|
421 |
|
Process the state of given aura button, then apply the details to the native |
|
422 |
|
`GameTooltip`. |
|
423 |
|
|
|
424 |
|
@see FrameXML/GameTooltip.lua:GameTooltip |
|
425 |
|
@see FrameXML/SecureTemplates.lua:function SecureButton_GetUnit |
|
426 |
|
@function auraButtonGameTooltipShow |
|
427 |
|
@tparam frame self the aura button |
|
428 |
|
@return nothing |
|
429 |
|
]] |
292 |
430 |
function Chorus.auraButtonGameTooltipShow(self) |
function Chorus.auraButtonGameTooltipShow(self) |
293 |
431 |
GameTooltip:SetOwner(self, "ANCHOR_BOTTOMLEFT"); |
GameTooltip:SetOwner(self, "ANCHOR_BOTTOMLEFT"); |
294 |
432 |
GameTooltip:SetFrameLevel(self:GetFrameLevel() + 2); |
GameTooltip:SetFrameLevel(self:GetFrameLevel() + 2); |
|
... |
... |
function Chorus.auraButtonGameTooltipShow(self) |
304 |
442 |
end |
end |
305 |
443 |
end |
end |
306 |
444 |
|
|
|
445 |
|
--[[-- |
|
446 |
|
Hide the tooltip associated with the aura button, if necessary. |
|
447 |
|
|
|
448 |
|
Effectively, simply hides the native `GameTooltip`. |
|
449 |
|
|
|
450 |
|
@see FrameXML/GameTooltip.lua:GameTooltip |
|
451 |
|
@function auraButtonGameTooltipHide |
|
452 |
|
@return nothing |
|
453 |
|
]] |
307 |
454 |
function Chorus.auraButtonGameTooltipHide() |
function Chorus.auraButtonGameTooltipHide() |
308 |
455 |
GameTooltip:Hide(); |
GameTooltip:Hide(); |
309 |
456 |
end |
end |
310 |
457 |
|
|
|
458 |
|
--[[-- |
|
459 |
|
Initialize the aura button frame with callbacks and children. |
|
460 |
|
|
|
461 |
|
@function auraButtonMain |
|
462 |
|
@tparam frame self |
|
463 |
|
@return nothing |
|
464 |
|
]] |
311 |
465 |
function Chorus.auraButtonMain(self) |
function Chorus.auraButtonMain(self) |
312 |
466 |
local n = self:GetName() |
local n = self:GetName() |
313 |
467 |
if n then |
if n then |
|
... |
... |
function Chorus.auraButtonMain(self) |
321 |
475 |
self:RegisterEvent('UNIT_AURA') |
self:RegisterEvent('UNIT_AURA') |
322 |
476 |
auraButtonValidate(self) |
auraButtonValidate(self) |
323 |
477 |
end |
end |
324 |
|
|
|
325 |
|
Chorus.auraButtonEventProcessor = auraButtonEventProcessor |
|