-
Notifications
You must be signed in to change notification settings - Fork 8
/
UI.lua
574 lines (492 loc) · 15.9 KB
/
UI.lua
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
local RaidNotifier = RaidNotifier
local Util = RaidNotifier.Util
local GetGameTimeMillis = GetGameTimeMilliseconds
local strfmt = string.format
do
local UI_FRAGMENT
local CUSTOM_ANCHORS = --for managing control position with a none-TOPLEFT anchor
{
[CENTER] = function(ctrl) return ctrl:GetCenter() end,
[TOPLEFT] = function(ctrl) return ctrl:GetLeft(), ctrl:GetTop() end,
}
local function GetSettingForControl(control)
local settings = RaidNotifier.Vars[control.category]
return settings and settings[control.key]
end
function RaidNotifier:AddFragment()
if not UI_FRAGMENT then
UI_FRAGMENT = ZO_HUDFadeSceneFragment:New(RaidNotifierUI)
end
HUD_SCENE:AddFragment(UI_FRAGMENT)
HUD_UI_SCENE:AddFragment(UI_FRAGMENT)
end
function RaidNotifier:RemoveFragment()
if not UI_FRAGMENT then
UI_FRAGMENT = ZO_HUDFadeSceneFragment:New(RaidNotifierUI)
end
HUD_SCENE:RemoveFragment(UI_FRAGMENT)
HUD_UI_SCENE:RemoveFragment(UI_FRAGMENT)
end
local function SaveElementPosition(ctrl)
local settings = GetSettingForControl(ctrl)
if settings and settings.position then -- move this to GetSettingForControl?
settings = settings.position
end
if not settings then
df("Could not find saved position for '%s'", ctrl:GetName())
else
local anchor = settings[3] or TOPLEFT
settings[1], settings[2] = CUSTOM_ANCHORS[anchor](ctrl)
end
end
local function LoadElementPosition(ctrl)
local settings = GetSettingForControl(ctrl)
if settings and settings.position then -- move this to GetSettingForControl?
settings = settings.position
end
if not settings then
df("Could not find saved position for '%s'", ctrl:GetName())
else
ctrl:ClearAnchors()
ctrl:SetAnchor(settings[3] or TOPLEFT, RaidNotifierUI, TOPLEFT, settings[1], settings[2])
end
end
local elements = {}
function RaidNotifier:RegisterElement(ctrl)
if type(ctrl) == "string" then
ctrl = RaidNotifierUI:GetNamedChild(ctrl)
end
elements[ctrl.key] = ctrl --just save by key as it probably never conflicts
ctrl:SetHandler("OnMoveStop", SaveElementPosition)
LoadElementPosition(ctrl)
return ctrl
end
function RaidNotifier:SetElementHidden(category, key, hidden)
local ctrl = elements[key]
if ctrl then
ctrl:SetHidden(hidden)
end
end
function RaidNotifier:HideAllElements()
for k, elem in pairs(elements) do
elem:SetHidden(true)
end
end
function RaidNotifier:GetElement(category, key)
return elements[key]
end
end
-- --------------------
-- -- ULTIMATE WINDOW
do --------------------
local window = nil
function RaidNotifier:InitializeUltimateWindow(control, mode)
window = self:RegisterElement(control)
-- do more with mode for initial display?
self:UpdateUltimateWindow({}, mode)
end
function RaidNotifier:UpdateUltimateWindow(sortedUlti, mode)
if not window then return end
if sortedUlti then
local text = "Ultimates:" --TODO: grab text from abilityId??
for i, data in ipairs(sortedUlti) do
local name = data.userName
local c1,c2 = "",""
if settings.useColor then
if data.percent >= 100 then
c1,c2 = "|c00ff00","|r"
elseif data.percent >= 80 then
c1,c2 = "|ccccc00","|r"
end
end
text = string.format("%s\n%s%s %d%%%s", text, c1, name, zo_min(data.percent, 100), c2)
end
window.label:SetText(text)
end
if mode ~= nil then
window:SetHidden(mode)
end
end
end
-- -------------------
-- -- RNTIMER OBJECT
do -------------------
local UPDATE_RATE = 0.05
local OnUpdate = nil --forwarding
local refCounter = Util.RefCounter:New("TimerCounter",
function() -- on getting atleast one reference
RaidNotifierUI:SetHandler("OnUpdate", OnUpdate)
end,
function() -- on reaching zero references
RaidNotifierUI:SetHandler("OnUpdate", nil)
end)
-- TODO: switch to a proper pool?
local activeTimers = {}
local nextUpdate = 0
OnUpdate = function(self, updateTime)
if (updateTime >= nextUpdate) then
for id, timer in pairs(activeTimers) do
timer:Update(updateTime)
end
nextUpdate = updateTime + UPDATE_RATE
end
end
-- Base Timer
local timerId = 1
local Timer = ZO_Object:Subclass()
function Timer:New(...)
local object = ZO_Object.New(self)
object:Initialize(...)
return object
end
function Timer:Initialize(control, formatter, onCompleteFn) -- control.type = LABEL
self.control = control
local function DefaultFormatter(remaining)
return ZO_FormatTime(remaining, TIME_FORMAT_STYLE_DESCRIPTIVE_MINIMAL_SHOW_TENTHS_SECS)
end
self.formatter = formatter or DefaultFormatter
self.onCompleteFn = onCompleteFn
self.start = 0
self.finish = 0
-- fading (ignored for base timer)
self.fadeTime = 0
self.isFading = false
self.timerId = timerId
timerId = timerId + 1
end
function Timer:SetText(text)
self.control:SetText(text)
end
function Timer:Reset()
-- placed here since there are several places that might stop the timer
refCounter:Decr()
-- remove it from active list even if it may not have been on there
activeTimers[self.timerId] = nil
-- reset base
self.start = 0
self.finish = 0
-- reset fading
self.isFading = false
self:SetFade(1)
-- additional fade reset for subclasses
self:ResetFade()
end
function Timer:OnComplete(forceStopped)
--TODO: hide control by default here?
if self.onCompleteFn then
self.onCompleteFn(self, forceStopped)
end
--self:Reset()
end
function Timer:IsActive()
return self.start > 0
end
function Timer:Start(start, finish, fadeTime)
if self:IsActive() then
self:Reset() -- TODO: reset manually instead?
end
-- increment counter for active timers
refCounter:Incr()
-- show timer
self:SetHidden(false)
-- add to active list
activeTimers[self.timerId] = self
-- base
self.start = start
self.finish = finish
-- fading (if supported)
if fadeTime ~= nil then
self:SetFadeTime(fadeTime)
end
-- use Update to setup (initial) values
self:Update(start)
end
-- Use this to force a timer to stop
function Timer:Stop(skipFade)
--only stop if we are active
if self:IsActive() then
if skipFade or self.fadeTime == 0 then
self:OnComplete()
self:Release()
else
self:SetExpired()
end
end
end
function Timer:Release()
self:SetHidden(true)
self:Reset()
end
function Timer:SetHidden(hidden)
self.control:SetHidden(hidden)
end
-- base timer cannot fade
function Timer:SetFadeTime(fadeTime)
-- do nothing
end
function Timer:SetFade(fade)
-- do nothing
end
function Timer:ResetFade()
-- do nothing
end
function Timer:SetExpired()
-- do nothing
end
-- update timer and handle fading for subclasses that support it
function Timer:Update(currentTime)
local remaining = self.finish - currentTime
if (remaining <= self.fadeTime) then -- done with timer and done with possible fading
self:OnComplete()
self:Release()
elseif (remaining <= 0) then -- handle fading, won't occur for base timer tho
if (not self.isFading) then
self:SetExpired()
end
self:SetFade(math.max(0, 1 - (remaining / self.fadeTime)))
else
self:SetText(self.formatter(remaining))
end
end
RaidNotifier.Timer = Timer
-- IconTimer: Handles a timer with a texture as control
local IconTimer = Timer:Subclass()
function IconTimer:New(...)
return Timer.New(self, ...)
end
function IconTimer:Initialize(control, formatter, onCompleteFn) -- control.type = TEXTURE
Timer.Initialize(self, control, formatter, onCompleteFn)
-- initialize additional children
self.control.timer = control:GetNamedChild("Timer")
end
-- redirect text to label
function IconTimer:SetText(text)
self.control.timer:SetText(text)
end
-- fading is supported
function IconTimer:SetFadeTime(fadeTime)
if not self.isFading then -- only when not fading already
self.fadeTime = fadeTime * -1
end
end
function IconTimer:SetFade(fade)
self.control:SetAlpha(fade)
end
function IconTimer:ResetFade() -- called by Timer:Reset()
self.control:SetDesaturation(0)
end
function IconTimer:SetExpired()
if (not self.isFading) then
self.isFading = true
-- make sure fading starts right now
self.finish = GetGameTimeMillis() / 1000
-- grey it out
self.control:SetDesaturation(1)
-- set text to 0 seconds (maybe hide text completely?)
self:SetText(self.formatter(0))
end
end
RaidNotifier.IconTimer = IconTimer
end
-- -------------------
-- -- STATUS DISPLAY
do -------------------
-- Multi-purpose status display, used in various places to show (semi)persistant effects
local display = nil -- the parent display
local iconTimer = nil -- the timer object (NOT THE ACTUAL CONTROL)
local owner = "none" -- simple string to see who is currently using the status display
--local self = RaidNotifier
function RaidNotifier:InitializeStatusDisplay(control)
display = self:RegisterElement(control)
-- set icon
display:SetTexture([[esoui/art/icons/ability_mage_065.dds]])
-- initialize additional controls
display.label = display:GetNamedChild("Label")
-- create timer object
iconTimer = RaidNotifier.IconTimer:New(display)
-- animation for flashing
if not display.flashTimeline then
display.flashTimeline = ANIMATION_MANAGER:CreateTimelineFromVirtual("RaidNotifierStatusDisplayLoop", display)
display.flashTimeline:SetPlaybackType(ANIMATION_PLAYBACK_LOOP, LOOP_INDEFINITELY) -- each loop is 1 second
end
end
-- Sanctum Ophidia: Spreading Poison
function RaidNotifier:UpdateSpreadingPoison(active, start, finish)
if not display then return end
if owner ~= "sanctum_spread_poison" then
owner = "sanctum_spread_poison"
display:SetTexture([[esoui/art/icons/death_recap_poison_aoe.dds]])
--display:SetTexture([[esoui/art/icons/ability_healer_018.dds]]) -- actual icon for ability??
display.label:SetHidden(true)
display.timer:SetHidden(false)
end
if active then
iconTimer:Start(start, finish)
else
iconTimer:Stop() -- let it fade
end
end
-- Maw of Lorkhaj: False Moon Twins
function RaidNotifier:UpdateTwinAspect(aspect) -- "none", "lunar" or "shadow"
if not self:IsDevMode() then return end -- placed here for centralization
if not display then return end
if owner ~= "mol_twins_aspect" then
owner = "mol_twins_aspect"
display.timer:SetHidden(true) -- maybe use timer when converting?
display.label:SetHidden(true) -- display aspect as text maybe?
end
local icons = -- TODO: decide which icon to use
{
["lunar"] = [[RaidNotifier/assets/aspect_lunar3.dds]],
["tolunar"] = [[RaidNotifier/assets/aspect_lunar1.dds]],
["shadow"] = [[RaidNotifier/assets/aspect_shadow3.dds]],
["toshadow"] = [[RaidNotifier/assets/aspect_shadow1.dds]],
}
local currentTime = GetGameTimeMillis() / 1000
if aspect == "none" then
iconTimer:Start(currentTime, currentTime, 0.5) -- finish time doesn't matter
iconTimer:SetExpired() -- start fading
if display.flashTimeline:IsPlaying() then
display.flashTimeline:PlayInstantlyToEnd()
display.flashTimeline:Stop()
end
else
iconTimer:Start(currentTime, currentTime+3600, 0.5) -- just for making it 'active'
display:SetTexture(icons[aspect])
if aspect == "tolunar" or aspect == "toshadow" then --these should always last 3 seconds at most
display.flashTimeline:PlayFromStart()
elseif display.flashTimeline:IsPlaying() then
display.flashTimeline:PlayInstantlyToEnd()
display.flashTimeline:Stop()
end
end
end
-- Halls of Fabrication: Hunter Pair
function RaidNotifier:UpdateSphereVenom(active, start, finish)
if not display then return end
if owner ~= "hof_venom_inject" then
owner = "hof_venom_inject"
display:SetTexture([[esoui/art/icons/death_recap_poison_ranged.dds]])
display.timer:SetHidden(false)
--display.label:SetHidden(true) --maybe display "Purge" instead?
display.label:SetHidden(false)
display.label:SetText("Purge!")
end
if active then
iconTimer:Start(start, finish)
else
iconTimer:Stop() -- let it fade
end
end
-- Halls of Fabrication: Pinnacle Factotum
function RaidNotifier:UpdateScaldedStacks(stacks, start, finish)
if not display then return end
if owner ~= "hof_scalded_debuff" then
owner = "hof_scalded_debuff"
display:SetTexture([[esoui/art/icons/ability_dragonknight_002_b.dds]])
display.timer:SetHidden(false)
display.label:SetHidden(false)
end
if (stacks > 0) then
local r,g,b = Util.HSL2RGB((10 - stacks) / 30, 1, 1.5)
display.label:SetColor(r,g,b,1)
display.label:SetText(("%d%%"):format(stacks * 10))
iconTimer:Start(start, finish, 0.5)
else
iconTimer:Stop() -- let it fade
end
end
SLASH_COMMANDS["/rnstatus"] = function(status)
local currentTime = GetGameTimeMillis() / 1000
if status == "scalded" then
local stacks = math.random(1, 10)
RaidNotifier:UpdateScaldedStacks(stacks, currentTime, currentTime + 15)
elseif status == "aspect" then
elseif status == "venom" then
RaidNotifier:UpdateSphereVenom(true, currentTime, currentTime + 8.3)
elseif status == "troll" then
RaidNotifier:UpdateSpreadingPoison(true, currentTime, currentTime + 10)
end
end
end
-- -----------------
-- -- GLYPH WINDOW
do -----------------
local window = nil -- the window itself
local glyphTimers = {} -- the glyph objects (NOT THE ACTUAL CONTROLS)
local Timer = RaidNotifier.Timer
-- GlyphTimer: handles showing and hiding of the overlay and timer
-- in addition to updating the timer itself.
local GlyphTimer = Timer:Subclass()
function GlyphTimer:New(...)
return Timer.New(self, ...)
end
function GlyphTimer:Initialize(control, formatter, onCompleteFn)
Timer.Initialize(self, control, formatter, onCompleteFn)
-- additional controls
self.control.bg = control:GetNamedChild("BG")
self.control.overlay = control:GetNamedChild("Overlay")
self.control.timer = control:GetNamedChild("Timer")
-- show overlay by default
self:SetHidden(true)
end
function GlyphTimer:Reset()
Timer.Reset(self)
-- show overlay when inactive
self.control.timer:SetHidden(true)
self.control.overlay:SetHidden(false)
end
function GlyphTimer:Start(start, finish)
Timer.Start(self, start, finish) -- will call Update()
self:SetHidden(false) -- shows timer and hides overlay
end
function GlyphTimer:SetText(text)
self.control.timer:SetText(text)
end
-- we don't hide the control themselves, only switch between timer and overlay
function GlyphTimer:SetHidden(hidden)
self.control.timer:SetHidden(hidden)
self.control.overlay:SetHidden(not hidden)
end
-- Wrapper functions
function RaidNotifier:StartGlyphTimer(index, cooldown)
if not window then return end
local glyph = glyphTimers[index]
if not glyph then return end
local currentTime = GetGameTimeMillis() / 1000
glyph:Start(currentTime, currentTime + cooldown)
end
function RaidNotifier:StopGlyphTimer(index)
if not window then return end
local glyph = glyphTimers[index]
if not glyph then return end
glyph:Stop() -- just calls OnComplete, nothing special for now
end
-- Called upon loading and when the setting is changed
function RaidNotifier:InvertGlyphs()
if not window then return end
for _, glyph in ipairs(glyphTimers) do
local _, _, _, _, offsetX, offsetY = glyph.control:GetAnchor(0)
glyph.control:SetAnchor(CENTER, nil, CENTER, -1*offsetX, -1*offsetY)
end
local label = window:GetNamedChild("Exit")
local _, point = label:GetAnchor(0)
label:ClearAnchors()
label:SetAnchor(point == TOP and BOTTOM or TOP, nil, point == TOP and BOTTOM or TOP)
end
function RaidNotifier:InitializeGlyphWindow(control, inverted)
window = self:RegisterElement(control)
glyphTimers = {}
for i=1,7 do
glyphTimers[i] = GlyphTimer:New(window:GetNamedChild("Glyph"..i))
end
-- change the textures for the magical 'player glyph'
local playerGlyph = glyphTimers[7]
playerGlyph.control.bg:SetTexture([[RaidNotifier/assets/white_circle.dds]])
playerGlyph.control.overlay:SetTexture([[RaidNotifier/assets/dummy.dds]])
-- apply inversion if set
if inverted then
self:InvertGlyphs()
end
end
end