Back to Home

ESO Lua File v101037

internalingame/tribute/tributemechanic_manager.lua

[◄ back to folders ]
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
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
ZO_TRIBUTE_MECHANIC_TILE_BACKDROP_ALPHA = 0.5
ZO_TRIBUTE_MECHANIC_TILE_PORTRAIT_UI_WIDTH = 48
ZO_TRIBUTE_MECHANIC_TILE_PORTRAIT_UI_HEIGHT = 64
ZO_TRIBUTE_MECHANIC_TILE_CONTAINER_UI_WIDTH = 70
ZO_TRIBUTE_MECHANIC_TILE_CONTAINER_UI_HEIGHT = ZO_TRIBUTE_MECHANIC_TILE_PORTRAIT_UI_HEIGHT
ZO_TRIBUTE_MECHANIC_TILE_BACKDROP_UI_HEIGHT = ZO_TRIBUTE_MECHANIC_TILE_CONTAINER_UI_HEIGHT + 6
ZO_TRIBUTE_MECHANIC_TILE_UI_HEIGHT = ZO_TRIBUTE_MECHANIC_TILE_BACKDROP_UI_HEIGHT + 8
ZO_TRIBUTE_MECHANIC_TILE_UI_WIDTH = 127
ZO_TRIBUTE_MECHANIC_HISTORY_FADE_GRADIENT_HEIGHT = ZO_TRIBUTE_MECHANIC_TILE_UI_HEIGHT * 2
ZO_TRIBUTE_MECHANIC_HISTORY_HEADING_UI_WIDTH = ZO_TRIBUTE_MECHANIC_TILE_UI_WIDTH + 3
ZO_TRIBUTE_MECHANIC_CONTINUOUS_SCROLL_REGION_HEIGHT = ZO_TRIBUTE_MECHANIC_TILE_UI_HEIGHT
ZO_TRIBUTE_MECHANIC_CONTINUOUS_SCROLL_DISTANCE_PER_SECOND = ZO_TRIBUTE_MECHANIC_TILE_UI_HEIGHT * 4
local TRIBUTE_MECHANIC_TILE_PORTRAIT_DIMENSION_X = 256
local TRIBUTE_MECHANIC_TILE_PORTRAIT_DIMENSION_Y = 512
local TRIBUTE_MECHANIC_TILE_PORTRAIT_CROPPED_DIMENSION_X = 205
local TRIBUTE_MECHANIC_TILE_PORTRAIT_CROPPED_DIMENSION_Y = 274
local TRIBUTE_MECHANIC_TILE_PORTRAIT_CENTER_X = 128
local TRIBUTE_MECHANIC_TILE_PORTRAIT_CENTER_Y = 226
local TRIBUTE_MECHANIC_TILE_PORTRAIT_CENTER_X_COORD = TRIBUTE_MECHANIC_TILE_PORTRAIT_CENTER_X / TRIBUTE_MECHANIC_TILE_PORTRAIT_DIMENSION_X
local TRIBUTE_MECHANIC_TILE_PORTRAIT_CENTER_Y_COORD = TRIBUTE_MECHANIC_TILE_PORTRAIT_CENTER_Y / TRIBUTE_MECHANIC_TILE_PORTRAIT_DIMENSION_Y
local TRIBUTE_MECHANIC_TILE_PORTRAIT_HALF_X_COORD = TRIBUTE_MECHANIC_TILE_PORTRAIT_CROPPED_DIMENSION_X / TRIBUTE_MECHANIC_TILE_PORTRAIT_DIMENSION_X * 0.5
local TRIBUTE_MECHANIC_TILE_PORTRAIT_HALF_Y_COORD = TRIBUTE_MECHANIC_TILE_PORTRAIT_CROPPED_DIMENSION_Y / TRIBUTE_MECHANIC_TILE_PORTRAIT_DIMENSION_Y * 0.5
ZO_TRIBUTE_MECHANIC_TILE_PORTRAIT_BOTTOM_COORD = TRIBUTE_MECHANIC_TILE_PORTRAIT_CENTER_Y_COORD + TRIBUTE_MECHANIC_TILE_PORTRAIT_HALF_Y_COORD
ZO_TRIBUTE_MECHANIC_TILE_PORTRAIT_TOP_COORD = TRIBUTE_MECHANIC_TILE_PORTRAIT_CENTER_Y_COORD - TRIBUTE_MECHANIC_TILE_PORTRAIT_HALF_Y_COORD
ZO_TRIBUTE_MECHANIC_TILE_PORTRAIT_LEFT_COORD = TRIBUTE_MECHANIC_TILE_PORTRAIT_CENTER_X_COORD - TRIBUTE_MECHANIC_TILE_PORTRAIT_HALF_X_COORD
ZO_TRIBUTE_MECHANIC_TILE_PORTRAIT_RIGHT_COORD = TRIBUTE_MECHANIC_TILE_PORTRAIT_CENTER_X_COORD + TRIBUTE_MECHANIC_TILE_PORTRAIT_HALF_X_COORD
local PER_HISTORY_ENTRY_DELAY_MS = 375
local MECHANIC_TILE_ANIMATIONS =
{
    FOCUS_TILE =
    {
        durationMS = 150,
    },
    NEW_RESOLVED_TILE =
    {
        durationMS = 250,
    },
    NEW_UNRESOLVED_TILE =
    {
        durationMS = 250,
    },
    RESOLVE_TILE =
    {
        durationMS = 125,
    },
}
local g_BounceEase = ZO_GenerateCubicBezierEase(0.31, 1.2, 0.83, 1.1)
----------------------------
-- ZO_TributeMechanicTile --
----------------------------
ZO_TributeMechanicTile = ZO_PooledObject:Subclass()
function ZO_TributeMechanicTile:Initialize(control)
    self.control = control
    self.backdropTexture = control:GetNamedChild("Backdrop")
    self.containerControl = control:GetNamedChild("Container")
    self.mechanicControl = self.containerControl:GetNamedChild("Mechanic")
    self.mechanicFrameTexture = self.mechanicControl:GetNamedChild("Frame")
    self.mechanicTypeIconTexture = self.mechanicControl:GetNamedChild("TypeIcon")
    self.mechanicQuantityLabel = self.mechanicControl:GetNamedChild("Quantity")
    self.patronTexture = self.containerControl:GetNamedChild("Patron")
    self.portraitTexture = self.containerControl:GetNamedChild("Portrait")
    self.portraitFrameTexture = self.portraitTexture:GetNamedChild("Frame")
    self.timelines = {}
    self:Reset()
end
function ZO_TributeMechanicTile:SetSaturation(saturation)
    local quadraticEase = ZO_EaseInQuadratic(saturation)
    self.backdropTexture:SetAlpha(zo_lerp(0, 0.65, quadraticEase))
    local desaturation = zo_lerp(0.5, 0, quadraticEase)
    self.portraitFrameTexture:SetDesaturation(desaturation)
    self.mechanicFrameTexture:SetDesaturation(desaturation)
    self.mechanicTypeIconTexture:SetDesaturation(desaturation)
    self.patronTexture:SetDesaturation(desaturation)
    self.portraitTexture:SetDesaturation(desaturation)
end
function ZO_TributeMechanicTile:GetCardAndPatronDef()
    local cardDefId, patronDefId = GetTributeCardInstanceDefIds(self.cardInstanceId)
    return cardDefId, patronDefId
end
function ZO_TributeMechanicTile:GetControl()
    return self.control
end
function ZO_TributeMechanicTile:GetControlDimensions()
    return self.control:GetDimensions()
end
function ZO_TributeMechanicTile:GetIconTextureFile()
    return GetTributeMechanicIconPath(self.mechanicType, self.param1, self.param2, self.param3)
end
function ZO_TributeMechanicTile:GetQuantity()
    return self.quantity
end
function ZO_TributeMechanicTile:SetQuantity(quantity)
    self.quantity = quantity
    local quantityString = quantity
    if quantity == 0 and not self.isResolved then
        quantityString = GetString(SI_TRIBUTE_MECHANIC_ANY_QUANTITY_SYMBOL)
    end
    self.mechanicQuantityLabel:SetText(quantityString)
end
function ZO_TributeMechanicTile:IsLocalPlayerOwner()
    return self.isLocalPlayerOwner
end
function ZO_TributeMechanicTile:SetPredecessorTileControl(control)
    self.predecessorTileControl = control
end
function ZO_TributeMechanicTile:HideCardPopupAndTooltip()
    if self.cardPopup then
        self.cardPopup:ReleaseObject()
        self.cardPopup = nil
        local OFFSET_MS = 0
        local REVERSE_PLAYBACK = true
        self:PlayAnimation(MECHANIC_TILE_ANIMATIONS.FOCUS_TILE, OFFSET_MS, REVERSE_PLAYBACK)
    end
    if self.cardTooltipControlGamepad then
        self.cardTooltipControlGamepad = nil
    end
    if self.cardTooltipControlKeyboard then
        ClearTooltipImmediately(self.cardTooltipControlKeyboard)
        self.cardTooltipControlKeyboard = nil
    end
end
function ZO_TributeMechanicTile:PlayAnimation(animation, offsetMS, reversePlayback, retainAnimation)
    local timeline = self.timelines[animation]
    if not timeline then
        timeline = TRIBUTE_POOL_MANAGER:GetMechanicTileAnimationPool():AcquireObject(self, animation)
        self.timelines[animation] = timeline
    end
    local animationControl = timeline:GetFirstAnimation()
    local durationMS = animation.durationMS
    animationControl:SetDuration(durationMS)
    timeline:SetAllAnimationOffsets(offsetMS or 0)
    timeline.retainAnimation = retainAnimation
    timeline.reversePlayback = reversePlayback
    if reversePlayback then
        timeline:PlayBackward()
    else
        timeline:PlayForward()
    end
end
function ZO_TributeMechanicTile:ReleaseAnimation(animation)
    local timeline = self.timelines[animation]
    if timeline then
        self:ReleaseTimeline(animation, timeline)
    end
end
function ZO_TributeMechanicTile:ReleaseTimeline(animation, timeline)
    timeline.object = nil
    timeline:PlayInstantlyToStart()
    TRIBUTE_POOL_MANAGER:GetMechanicTileAnimationPool():ReleaseObject(timeline.key)
    self.timelines[animation] = nil
end
function ZO_TributeMechanicTile:ReleaseTimelines()
    for animation, timeline in pairs(self.timelines) do
        self:ReleaseTimeline(animation, timeline)
    end
end
function ZO_TributeMechanicTile:Reset()
    self.cardInstanceId = nil
    self.comboNumber = nil
    self.isResolved = nil
    self.mechanicIndex = nil
    self.mechanicActivationSource = nil
    self.mechanicType = nil
    self.param1 = nil
    self.param2 = nil
    self.param3 = nil
    self.triggerId = nil
    self.predecessorTileControl = nil
    self.quantity = nil
end
function ZO_TributeMechanicTile:Resolve(animationOffsetMS)
    self.isResolved = true
    self:PlayAnimation(MECHANIC_TILE_ANIMATIONS.RESOLVE_TILE, animationOffsetMS)
end
function ZO_TributeMechanicTile:SetPosition(offsetX, offsetY)
    local control = self.control
    if offsetX then
        local valid, point, relativeTo, relativePoint = control:GetAnchor(0)
        control:SetAnchor(point, relativeTo, relativePoint, offsetX, nil, ANCHOR_CONSTRAINS_X)
    end
    if offsetY then
        local valid, point, relativeTo, relativePoint = control:GetAnchor(1)
        control:SetAnchor(point, relativeTo, relativePoint, nil, offsetY, ANCHOR_CONSTRAINS_Y)
    end
end
function ZO_TributeMechanicTile:Setup(parentControl, cardInstanceId, mechanicActivationSource, mechanicIndex, isLocalPlayerOwner, quantity, isResolved)
    self.cardInstanceId = cardInstanceId
    self.isLocalPlayerOwner = isLocalPlayerOwner
    self.mechanicIndex = mechanicIndex
    self.mechanicActivationSource = mechanicActivationSource
    self.isResolved = isResolved
    self:SetQuantity(quantity)
    local cardDefId, patronDefId = self:GetCardAndPatronDef()
    local cardData = ZO_TributeCardData:New(patronDefId, cardDefId)
    local patronData = cardData:GetPatronData()
    local unusedQuantity = nil
    self.mechanicType, unusedQuantity, self.comboNumber, self.param1, self.param2, self.param3, self.triggerId = GetTributeCardMechanicInfo(cardDefId, self.mechanicActivationSource, self.mechanicIndex)
    local digitsSuffix = quantity >= 10 and "Double" or "Single"
    local activationSourceSuffix
    if mechanicActivationSource == TRIBUTE_MECHANIC_ACTIVATION_SOURCE_COMBO then
        activationSourceSuffix = "Combo"
    elseif self.triggerId ~= 0 then
        activationSourceSuffix = "Trigger"
    else
        activationSourceSuffix = "Activation"
    end
    local mechanicControlTemplate = string.format("ZO_TributeCard_MechanicContainer_Small_%sDigit_%s_Style", digitsSuffix, activationSourceSuffix)
    ApplyTemplateToControl(self.mechanicControl, mechanicControlTemplate)
    self.mechanicTypeIconTexture:SetTexture(self:GetIconTextureFile())
    if self.triggerId ~= 0 then
        self.patronTexture:SetHidden(true)
    else
        local suitAtlasImage, suitAtlasGlowImage = patronData:GetSuitAtlas(cardData:GetCardType())
        self.patronTexture:SetTexture(suitAtlasImage)
        self.patronTexture:SetHidden(false)
    end
    local portraitImage = cardData:GetPortrait()
    self.portraitTexture:SetTexture(portraitImage)
    self:SetSaturation(0)
    self.containerControl:SetScale(1)
    self.control:SetParent(parentControl)
    self.control:SetHidden(false)
end
function ZO_TributeMechanicTile:Show(animationOffsetMS, isResolved)
    if isResolved then
        self.isResolved = true
        self:PlayAnimation(MECHANIC_TILE_ANIMATIONS.NEW_RESOLVED_TILE, animationOffsetMS)
    else
        self:PlayAnimation(MECHANIC_TILE_ANIMATIONS.NEW_UNRESOLVED_TILE, animationOffsetMS)
    end
end
function ZO_TributeMechanicTile:ShowCardPopupAndTooltip()
    local isGamepadMode = TRIBUTE:IsInputStyleGamepad()
    local isMouseMode = TRIBUTE:IsInputStyleMouse()
    if not (isGamepadMode or isMouseMode) then
        return
    end
    local cardPopup = TRIBUTE_POOL_MANAGER:AcquireCardByInstanceId(self.cardInstanceId, TRIBUTE_MECHANIC_MANAGER:GetControl(), SPACE_INTERFACE)
    self.cardPopup = cardPopup
    local VERTICAL_MARGIN = 0
    local _, top = self.control:GetCenter()
    cardPopup:ShowAsPopup(ZO_TRIBUTE_MECHANIC_TILE_UI_WIDTH, top, ZO_TRIBUTE_CARD_POPUP_TYPE.MECHANIC)
    cardPopup:SetMechanicGlowHidden(self.mechanicActivationSource, self.mechanicIndex, false)
    if isMouseMode then
        local tooltipControl = ItemTooltip
        InitializeTooltip(tooltipControl, cardPopup:GetControl(), LEFT, HORIZONTAL_MARGIN, VERTICAL_MARGIN, RIGHT)
        tooltipControl:SetTributeCard(cardPopup:GetPatronDefId(), cardPopup:GetCardDefId())
        self.cardTooltipControlKeyboard = tooltipControl
    elseif isGamepadMode then
        local tooltipControl = ZO_TributeCardTooltip_Gamepad_GetControl()
        ZO_TributeCardTooltip_Gamepad_Show(cardPopup, LEFT, cardPopup:GetControl(), RIGHT, HORIZONTAL_MARGIN, VERTICAL_MARGIN)
        self.cardTooltipControlGamepad = tooltipControl
    end
    local OFFSET_MS = 0
    local FORWARD_PLAYBACK = false
    local RETAIN_ANIMATION = true
    self:PlayAnimation(MECHANIC_TILE_ANIMATIONS.FOCUS_TILE, OFFSET_MS, FORWARD_PLAYBACK, RETAIN_ANIMATION)
end
function ZO_TributeMechanicTile:OnCursorEnter()
    -- TODO Tribute: Consider highlighting the card instance on the table as well? Would require an exception for non-top-of-stack cards or a different state altogether.
end
function ZO_TributeMechanicTile:OnCursorExit()
end
function ZO_TributeMechanicTile:OnMouseEnter()
    if not IsInGamepadPreferredMode() then
        self:ShowCardPopupAndTooltip()
    end
end
function ZO_TributeMechanicTile:OnTimelineStop(timeline, completedPlaying)
    if timeline.object and not timeline.retainAnimation then
        if (not timeline.reversePlayback and completedPlaying) or (timeline.reversePlayback and not completedPlaying) then
            self.timelines[timeline] = nil
            TRIBUTE_POOL_MANAGER:GetMechanicTileAnimationPool():ReleaseObject(timeline.key)
        end
    end
end
function ZO_TributeMechanicTile:OnTimelineUpdate(timeline, progress)
    local animation = timeline.animation
    if animation == MECHANIC_TILE_ANIMATIONS.NEW_RESOLVED_TILE or animation == MECHANIC_TILE_ANIMATIONS.NEW_UNRESOLVED_TILE then
        local quadraticProgress = ZO_EaseOutQuadratic(progress)
        local control = self.control
        control:SetAlpha(quadraticProgress)
        local bouncedProgress = g_BounceEase(progress)
        local offsetX = zo_floor(ZO_TRIBUTE_MECHANIC_TILE_UI_WIDTH * bouncedProgress) - 15
        self:SetPosition(offsetX)
        if animation == MECHANIC_TILE_ANIMATIONS.NEW_UNRESOLVED_TILE then
            self.containerControl:SetScale(zo_lerp(0.2, 1.15, bouncedProgress))
            self:SetSaturation(progress)
        else
            self.containerControl:SetScale(zo_lerp(1.5, 1, bouncedProgress))
        end
        local predecessorControl = self.predecessorTileControl
        if predecessorControl then
            local predecessorProgress = zo_clamp(progress * 1.25, 0, 1)
            local offsetY = zo_floor(zo_lerp(0, ZO_TRIBUTE_MECHANIC_TILE_UI_HEIGHT, ZO_EaseOutQuadratic(predecessorProgress)))
            local CURRENT_OFFSET_X = nil
            predecessorControl.object:SetPosition(CURRENT_OFFSET_X, offsetY)
        end
    elseif animation == MECHANIC_TILE_ANIMATIONS.FOCUS_TILE then
        local minSaturation = self.isResolved and 0 or 1
        self:SetSaturation(zo_max(progress, minSaturation))
    elseif animation == MECHANIC_TILE_ANIMATIONS.RESOLVE_TILE then
        self:SetSaturation(1 - progress)
        local bouncedProgress = g_BounceEase(progress)
        self.containerControl:SetScale(zo_lerp(1.15, 1, bouncedProgress))
    end
end
--------------------------------
-- Tribute Triggered Mechanic --
--------------------------------
ZO_TributeTriggeredMechanic = ZO_InitializingObject:Subclass()
function ZO_TributeTriggeredMechanic:Initialize(mechanicActivationSource, mechanicIndex, quantity, isResolved)
    self.mechanicActivationSource = mechanicActivationSource
    self.mechanicIndex = mechanicIndex
    self.isPresenting = false
    self.isResolved = isResolved
    self.quantity = quantity
end
function ZO_TributeTriggeredMechanic:Equals(mechanicActivationSource, mechanicIndex)
    return self.mechanicActivationSource == mechanicActivationSource and self.mechanicIndex == mechanicIndex
end
function ZO_TributeTriggeredMechanic:GetMechanicActivationSourceAndIndex()
    return self.mechanicActivationSource, self.mechanicIndex
end
function ZO_TributeTriggeredMechanic:GetQuantity()
    return self.quantity
end
function ZO_TributeTriggeredMechanic:SetQuantity(quantity)
    self.quantity = quantity
end
function ZO_TributeTriggeredMechanic:IsPresenting()
    return self.isPresenting
end
function ZO_TributeTriggeredMechanic:SetIsPresenting(isPresenting)
    self.isPresenting = isPresenting
end
function ZO_TributeTriggeredMechanic:IsResolved()
    return self.isResolved
end
function ZO_TributeTriggeredMechanic:SetIsResolved(isResolved)
    self.isResolved = isResolved
end
----------------------------------
-- Tribute Mechanic Queue Entry --
----------------------------------
ZO_TributeMechanicQueueEntry = ZO_InitializingObject:Subclass()
function ZO_TributeMechanicQueueEntry:Initialize(cardInstanceId, isLocalPlayerOwner)
    self.cardInstanceId = cardInstanceId
    self.cardDefId, self.patronDefId = GetTributeCardInstanceDefIds(cardInstanceId)
    self.isLocalPlayerOwner = isLocalPlayerOwner
    self.triggeredMechanics = {}
end
function ZO_TributeMechanicQueueEntry:AddTriggeredMechanic(triggeredMechanic)
    table.insert(self.triggeredMechanics, triggeredMechanic)
end
function ZO_TributeMechanicQueueEntry:FindTriggeredMechanic(mechanicActivationSource, mechanicIndex)
    for _, triggeredMechanic in ipairs(self.triggeredMechanics) do
        if triggeredMechanic:Equals(mechanicActivationSource, mechanicIndex) then
            return triggeredMechanic
        end
    end
    return nil
end
function ZO_TributeMechanicQueueEntry:GetCardInstanceId()
    return self.cardInstanceId
end
function ZO_TributeMechanicQueueEntry:GetCardDefId()
    return self.cardDefId
end
function ZO_TributeMechanicQueueEntry:GetPatronDefId()
    return self.patronDefId
end
function ZO_TributeMechanicQueueEntry:GetTriggeredMechanics()
    return self.triggeredMechanics
end
function ZO_TributeMechanicQueueEntry:IsLocalPlayerOwner()
    return self.isLocalPlayerOwner
end
function ZO_TributeMechanicQueueEntry:IsPresenting()
    return self.isPresenting
end
function ZO_TributeMechanicQueueEntry:SetIsPresenting(isPresenting)
    self.isPresenting = isPresenting
end
------------------------------
-- Tribute Mechanic Manager --
------------------------------
ZO_TributeMechanic_Manager = ZO_InitializingCallbackObject:Subclass()
function ZO_TributeMechanic_Manager:AddMechanicHistory(cardInstanceId, mechanicActivationSource, mechanicIndex, isLocalPlayerOwner, quantity, isResolved)
    local controlPool = isLocalPlayerOwner and TRIBUTE_POOL_MANAGER:GetMechanicTilePlayerPool() or TRIBUTE_POOL_MANAGER:GetMechanicTileOpponentPool()
    local tileObject = controlPool:AcquireObject(self.scrollChildControl, cardInstanceId, mechanicActivationSource, mechanicIndex, isLocalPlayerOwner, quantity, isResolved)
    local tileControl = tileObject:GetControl()
    table.insert(self.history, tileObject)
    tileControl:ClearAnchors()
    tileControl:SetAnchor(LEFT, nil, nil, -tileControl:GetWidth(), nil, ANCHOR_CONSTRAINS_X)
    tileControl:SetAnchor(CENTER, self.scrollChildControl, TOP, nil, ZO_TRIBUTE_MECHANIC_TILE_UI_HEIGHT * 0.5 + 10, ANCHOR_CONSTRAINS_Y)
    tileControl:SetScale(1)
    if self.headAnchorControl then
        self.headAnchorControl:SetAnchor(CENTER, tileControl, CENTER, nil, nil, ANCHOR_CONSTRAINS_Y)
        tileObject:SetPredecessorTileControl(self.headAnchorControl)
    end
    self.headAnchorControl = tileControl
    local NO_ANIMATION_OFFSET_MS = 0
    tileObject:Show(NO_ANIMATION_OFFSET_MS, isResolved)
    if self:CanScrollToTop() then
        self:ScrollToTop()
    end
    self:SetHeadingHidden(false)
    self:SetLastMechanicTile(tileObject)
    if mechanicActivationSource == TRIBUTE_MECHANIC_ACTIVATION_SOURCE_COMBO then
        PlaySound(SOUNDS.TRIBUTE_COMBO_TRIGGERED)
    elseif mechanicActivationSource == TRIBUTE_MECHANIC_ACTIVATION_SOURCE_ACTIVATION then
        PlaySound(SOUNDS.TRIBUTE_TRIGGER_TRIGGERED)
    end
    return tileObject
end
do
    local LOWER_VERTICAL_SCROLL_MARGIN = 20
    function ZO_TributeMechanic_Manager:AdjustVerticalScrollOffset(offset)
        local _, currentVerticalOffset = self.scrollControl:GetScrollOffsets()
        local _, currentHeight = self.scrollControl:GetScrollExtents()
        -- Include a small margin for the lower vertical scroll boundary
        -- to allow the bottommost tile to fully scroll into view.
        local scrollMargin = 0
        if currentHeight > 0 then
            scrollMargin = LOWER_VERTICAL_SCROLL_MARGIN
        end
        local maxHeight = zo_max(0, currentHeight + scrollMargin)
        local newVerticalOffset = zo_clamp(currentVerticalOffset + offset, 0, maxHeight)
        self.scrollControl:SetVerticalScroll(newVerticalOffset)
        self:UpdateScrollFadeGradient()
    end
end
function ZO_TributeMechanic_Manager:CanScrollToTop()
    return not self.isScrollOffsetLocked
end
function ZO_TributeMechanic_Manager:GetControl()
    return self.control
end
function ZO_TributeMechanic_Manager:GetLastMechanicTile()
    return self.lastMechanicTile
end
function ZO_TributeMechanic_Manager:SetLastMechanicTile(mechanicTile)
    self.lastMechanicTile = mechanicTile
end
function ZO_TributeMechanic_Manager:Initialize(control)
    self.control = control
    control.object = self
    self.continuousScrollingDirection = 0
    self.gameState = TRIBUTE_GAME_FLOW_STATE_INACTIVE
    self.gamepadCursorX, self.gamepadCursorY = 0, 0
    self.isContinuousScrollingEnabled = false
    self.mouseCursorX, self.mouseCursorY = 0, 0
    self.history = {}
    self.queue = {}
    self:Reset()
end
function ZO_TributeMechanic_Manager:InitializeControls()
    local control = self.control
    self.headingLabel = control:GetNamedChild("Heading")
    self.showHeadingTimeline = ANIMATION_MANAGER:CreateTimelineFromVirtual("ZO_TributeMechanicHistory_ShowTimeline", self.headingLabel)
    self:SetHeadingHidden(true)
    self.scrollControl = control:GetNamedChild("Scroll")
    self.scrollChildControl = self.scrollControl:GetNamedChild("Child")
    local KEYBOARD_PLATFORM_STYLE =
    {
        headingLabel = "ZoFontWinH3",
    }
    local GAMEPAD_PLATFORM_STYLE =
    {
        headingLabel = "ZoFontGamepadBold27",
    }
    local function ApplyPlatformStyle(style)
        self.headingLabel:SetFont(style.headingLabel)
    end
    self.platformStyle = ZO_PlatformStyle:New(function(style) ApplyPlatformStyle(style) end, KEYBOARD_PLATFORM_STYLE, GAMEPAD_PLATFORM_STYLE)
end
function ZO_TributeMechanic_Manager:InitializeEvents()
    local function OnCardMechanicResolutionStateChanged(_, ...)
    end
    EVENT_MANAGER:RegisterForEvent("ZO_TributeMechanic_Manager", EVENT_TRIBUTE_CARD_MECHANIC_RESOLUTION_STATE_CHANGED, OnCardMechanicResolutionStateChanged)
    local function OnGameStateChanged(_, ...)
        self:OnGameStateChanged(...)
    end
    EVENT_MANAGER:RegisterForEvent("ZO_TributeMechanic_Manager", EVENT_TRIBUTE_GAME_FLOW_STATE_CHANGE, OnGameStateChanged)
    local function OnPlayerTurnStarted(_, ...)
        self:OnPlayerTurnStarted(...)
    end
    EVENT_MANAGER:RegisterForEvent("ZO_TributeMechanic_Manager", EVENT_TRIBUTE_PLAYER_TURN_STARTED, OnPlayerTurnStarted)
    local function OnScrollExtentsChanged(...)
        self:OnScrollExtentsChanged()
    end
    self.scrollControl:SetHandler("OnScrollExtentsChanged", OnScrollExtentsChanged)
end
function ZO_TributeMechanic_Manager:OnScrollExtentsChanged()
    local _, currentHeight = self.scrollControl:GetScrollExtents()
    local previousHeight = self.previousScrollHeight or currentHeight
    self.previousScrollHeight = currentHeight
    if self.isScrollOffsetLocked then
        local delta = currentHeight - previousHeight
        if delta ~= 0 then
            self:AdjustVerticalScrollOffset(delta)
        end
    end
end
function ZO_TributeMechanic_Manager:QueueMechanic(cardInstanceId, isLocalPlayerOwner, mechanicActivationSource, mechanicIndex, quantity, isResolved)
    if mechanicActivationSource ~= TRIBUTE_MECHANIC_ACTIVATION_SOURCE_COMBO then
        -- Only Combo Mechanic and Trigger activation tiles should appear in the history.
        local cardDefId = GetTributeCardInstanceDefIds(cardInstanceId)
        local triggerId = select(7, GetTributeCardMechanicInfo(cardDefId, mechanicActivationSource, mechanicIndex))
        if triggerId == 0 then
            return
        end
    end
    for _, queueEntry in ipairs(self.queue) do
        -- Queue unique mechanics for the same player and card instance together.
        if cardInstanceId == queueEntry:GetCardInstanceId() and isLocalPlayerOwner == queueEntry:IsLocalPlayerOwner() then
            local triggeredMechanic = queueEntry:FindTriggeredMechanic(mechanicActivationSource, mechanicIndex)
            if triggeredMechanic then
                -- This triggered mechanic has already been queued in this queue entry.
                if isResolved and not triggeredMechanic:IsResolved() then
                    -- This triggered mechanic was previously unresolved and can now be resolved with its final quantity.
                    triggeredMechanic:SetIsResolved(true)
                    triggeredMechanic:SetQuantity(quantity)
                    return
                end
            elseif not queueEntry:IsPresenting() then
                -- This queue entry has not yet begun presentation; append this triggered mechanic to the entry.
                triggeredMechanic = ZO_TributeTriggeredMechanic:New(mechanicActivationSource, mechanicIndex, quantity, isResolved)
                queueEntry:AddTriggeredMechanic(triggeredMechanic)
                return
            end
        end
    end
    -- This triggered mechanic could not be added to any existing queue entries; create a new entry and add this mechanic to the entry.
    local newQueueEntry = ZO_TributeMechanicQueueEntry:New(cardInstanceId, isLocalPlayerOwner)
    local triggeredMechanic = ZO_TributeTriggeredMechanic:New(mechanicActivationSource, mechanicIndex, quantity, isResolved)
    newQueueEntry:AddTriggeredMechanic(triggeredMechanic)
    table.insert(self.queue, newQueueEntry)
end
function ZO_TributeMechanic_Manager:Reset()
    -- Order matters
    self:ResetHistory()
    self:ResetQueue()
end
function ZO_TributeMechanic_Manager:ResetHistory()
    self.headAnchorControl = nil
    self:SetHeadingHidden(true)
    TRIBUTE_POOL_MANAGER:GetMechanicTilePlayerPool():ReleaseAllObjects()
    TRIBUTE_POOL_MANAGER:GetMechanicTileOpponentPool():ReleaseAllObjects()
    local FORCE = true
    self:ScrollToTop(FORCE)
end
function ZO_TributeMechanic_Manager:ResetQueue()
    self.nextQueueUpdateTimeMS = 0
end
function ZO_TributeMechanic_Manager:SetContinuousScrollingEnabled(enabled, direction)
    if enabled == self.isContinuousScrollingEnabled then
        return
    end
    -- Both a direction and an enabled flag are maintained in order to allow an
    -- ongoing continous scroll operation to be cancelled with the mouse wheel.
    self.isContinuousScrollingEnabled = enabled
    self.continuousScrollingDirection = enabled and direction or 0
end
function ZO_TributeMechanic_Manager:SetHeadingHidden(hidden)
    if hidden then
        self.showHeadingTimeline:PlayInstantlyToStart()
    else
        self.showHeadingTimeline:PlayForward()
    end
end
function ZO_TributeMechanic_Manager:SetVerticalScrollOffsetLocked(locked)
    if locked == self.isScrollOffsetLocked then
        return
    end
    self.isScrollOffsetLocked = locked
    self:UpdateCursors()
end
function ZO_TributeMechanic_Manager:ScrollToTop(force)
    if force or self:CanScrollToTop() then
        self.scrollControl:SetVerticalScroll(0)
    end
end
function ZO_TributeMechanic_Manager:UpdateCursors()
    local minX, minY, maxX, maxY = self.scrollControl:GetScreenRect()
    local x, y = nil, nil
    if self.isGamepadCursorActive then
        -- Check whether the Gamepad cursor is over the history scroll region.
        x, y = self.gamepadCursorX, self.gamepadCursorY
        if x and y then
            if x < minX or x > maxX or y < minY or y > maxY then
                x, y = nil, nil
            end
        end
    end
    if not x then
        -- Check whether the Mouse cursor is over the history scroll region.
        x, y = self.mouseCursorX, self.mouseCursorY
        if x < minX or x > maxX or y < minY or y > maxY then
            self:SetContinuousScrollingEnabled(false)
            self:SetVerticalScrollOffsetLocked(false)
            return
        end
    end
    local topOffset = y - minY
    if topOffset <= ZO_TRIBUTE_MECHANIC_CONTINUOUS_SCROLL_REGION_HEIGHT then
        local DIRECTION = -1
        self:SetContinuousScrollingEnabled(true, DIRECTION)
    else
        local bottomOffset = maxY - y
        if bottomOffset <= ZO_TRIBUTE_MECHANIC_CONTINUOUS_SCROLL_REGION_HEIGHT then
            local DIRECTION = 1
            self:SetContinuousScrollingEnabled(true, DIRECTION)
        else
            self:SetContinuousScrollingEnabled(false)
        end
    end
end
function ZO_TributeMechanic_Manager:UpdateMouseCursor()
    local x, y = GetUIMousePosition()
    if x ~= self.mouseCursorX or y ~= self.mouseCursorY then
        self.mouseCursorX, self.mouseCursorY = x, y
        self:UpdateCursors()
    end
end
function ZO_TributeMechanic_Manager:UpdateScrollFadeGradient()
    local USE_FADE_GRADIENT = true
    ZO_UpdateScrollFade(USE_FADE_GRADIENT, self.scrollControl, ZO_SCROLL_DIRECTION_VERTICAL, ZO_TRIBUTE_MECHANIC_HISTORY_FADE_GRADIENT_HEIGHT)
end
function ZO_TributeMechanic_Manager:OnGamepadCursorPositionChanged(x, y)
    self.gamepadCursorX, self.gamepadCursorY = x, y
    self:UpdateCursors()
end
function ZO_TributeMechanic_Manager:OnGamepadCursorStateChanged(active)
    self.gamepadCursorX, self.gamepadCursorY = nil, nil
    self.isGamepadCursorActive = active
    self:UpdateCursors()
end
function ZO_TributeMechanic_Manager:OnGameStateChanged(gameState)
    local previousState = self.gameState
    if previousState ~= gameState then
        self.gameState = gameState
        local isInactive = gameState == TRIBUTE_GAME_FLOW_STATE_INACTIVE
        self.control:SetHidden(isInactive)
        if isInactive then
            self:Reset()
        else
            if gameState == TRIBUTE_GAME_FLOW_STATE_PLAYING then
                -- Initialize the current player turn state at the onset of the game; events will subsequently maintain the turn state.
                local isLocalPlayersTurn = IsLocalTributePlayersTurn()
                self:OnPlayerTurnStarted(isLocalPlayersTurn)
            end
        end
    end
end
function ZO_TributeMechanic_Manager:OnCardMechanicResolutionStateChanged(cardInstanceId, mechanicActivationSource, mechanicIndex, quantity, isResolved)
    local ownerPlayerPerspective = GetTributeCardInstanceOwner(cardInstanceId)
    if ownerPlayerPerspective then
        local isLocalPlayerOwner = ownerPlayerPerspective == TRIBUTE_PLAYER_PERSPECTIVE_SELF
        self:QueueMechanic(cardInstanceId, isLocalPlayerOwner, mechanicActivationSource, mechanicIndex, quantity, isResolved)
    end
end
function ZO_TributeMechanic_Manager:OnMouseWheel(delta, ctrl, alt, shift)
    local offsetMultiplier = (ctrl or shift) and 2 or 1
    local offset = delta * offsetMultiplier * ZO_TRIBUTE_MECHANIC_TILE_UI_HEIGHT
    -- Receiving mouse wheel input cancels any continuous scrolling.
    self.continuousScrollingDirection = 0
end
function ZO_TributeMechanic_Manager:OnPlayerTurnStarted(isLocalPlayer)
    if not isLocalPlayer then
        -- Reset the mechanic history stream when the local player finishes their turn.
        self:ResetHistory()
        self:ResetQueue()
    end
end
function ZO_TributeMechanic_Manager:OnUpdate()
    local scrollingDirection = self.continuousScrollingDirection
    if scrollingDirection ~= 0 then
        local offset = scrollingDirection * ZO_TRIBUTE_MECHANIC_CONTINUOUS_SCROLL_DISTANCE_PER_SECOND * GetFrameDeltaTimeSeconds()
    end
    local frameTimeMS = GetFrameTimeMilliseconds()
    if self.nextQueueUpdateTimeMS > frameTimeMS then
        return
    end
    local queueEntry = self.queue[1]
    if not queueEntry then
        return
    end
    self.nextQueueUpdateTimeMS = frameTimeMS + PER_HISTORY_ENTRY_DELAY_MS
    queueEntry:SetIsPresenting(true)
    local isTriggeredMechanicResolved = false
    local triggeredMechanics = queueEntry:GetTriggeredMechanics()
    local triggeredMechanic = triggeredMechanics[1]
    if triggeredMechanic then
        if triggeredMechanic:IsPresenting() then
            -- This mechanic has been presented already but not dequeued;
            -- therefore the mechanic must have been pending resolution previously.
            if triggeredMechanic:IsResolved() then
                local mechanicTile = self:GetLastMechanicTile()
                if mechanicTile then
                    -- Resolve this mechanic tile and update its final quantity.
                    -- Order matters:
                    mechanicTile:Resolve()
                    mechanicTile:SetQuantity(triggeredMechanic:GetQuantity())
                end
                -- Dequeue the mechanic.
                isTriggeredMechanicResolved = true
            end
        else
            local cardInstanceId = queueEntry:GetCardInstanceId()
            local isLocalPlayerOwner = queueEntry:IsLocalPlayerOwner()
            local mechanicActivationSource, mechanicIndex = triggeredMechanic:GetMechanicActivationSourceAndIndex()
            local quantity = triggeredMechanic:GetQuantity()
            local isResolved = triggeredMechanic:IsResolved()
            -- Present this new mechanic.
            self:AddMechanicHistory(cardInstanceId, mechanicActivationSource, mechanicIndex, isLocalPlayerOwner, quantity, isResolved)
            if isResolved then
                -- Dequeue the mechanic.
                isTriggeredMechanicResolved = true
            else
                -- Flag this mechanic as being presented but pending resolution.
                triggeredMechanic:SetIsPresenting(true)
            end
        end
    end
    if isTriggeredMechanicResolved then
        -- Dequeue the mechanic.
        table.remove(triggeredMechanics, 1)
        if not next(triggeredMechanics) then
            -- No additional mechanics remain for this queue entry.
            table.remove(self.queue, 1)
        end
    end
end
-- Global XML
    TRIBUTE_MECHANIC_MANAGER = ZO_TributeMechanic_Manager:New(control)
end
    control.object:OnMouseWheel(...)
end
    control.object:OnUpdate()
end
    control.object = ZO_TributeMechanicTile:New(control)
end
function ZO_TributeMechanicTile_Timeline_OnStop(timeline, completedPlaying)
    if timeline.object then
        timeline.object:OnTimelineStop(timeline, completedPlaying)
    end
end
function ZO_TributeMechanicTile_Timeline_OnUpdate(timeline, progress)
    if timeline.object then
        timeline.object:OnTimelineUpdate(timeline, progress)
    end
end