/
achievements.lua
executable file
·2015 lines (1646 loc) · 76.8 KB
/
achievements.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
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
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local SUMMARY_CATEGORY_BAR_HEIGHT = 16
local SUMMARY_CATEGORY_PADDING = 50
local SUMMARY_STATUS_BAR_WIDTH = 240
local ACHIEVEMENT_PADDING = 0
local ACHIEVEMENT_ICON_STYLE_PADDING = 20
local ACHIEVEMENT_WIDTH = 550
local ACHIEVEMENT_COLLAPSED_HEIGHT = 88
local ACHIEVEMENT_DESC_COLLAPSED_HEIGHT = 45
local ACHIEVEMENT_DESC_WIDTH = 380
local ACHIEVEMENT_INITIAL_CRITERIA_OFFSET = 10
local ACHIEVEMENT_LINE_PADDING = 5
local ACHIEVEMENT_LINE_PADDING_VERTICAL = 8
local ACHIEVEMENT_CRITERIA_PADDING = 10
local ACHIEVEMENT_REWARD_PADDING = 5
local ACHIEVEMENT_LINE_THUMB_WIDTH = 45
local ACHIEVEMENT_LINE_THUMB_HEIGHT = 68
local ACHIEVEMENT_STATUS_BAR_WIDTH = 345
local ACHIEVEMENT_STATUS_BAR_HEIGHT = 20
local ACHIEVEMENT_REWARD_LABEL_WIDTH = 230
local ACHIEVEMENT_REWARD_LABEL_HEIGHT = 20
local ACHIEVEMENT_REWARD_ICON_HEIGHT = 45
local ACHIEVEMENT_DATE_LABEL_EXPECTED_WIDTH = 60
local NUM_RECENT_ACHIEVEMENTS_TO_SHOW = 6
local SAVE_EXPANDED = true
local PREFIX_LABEL = 1
local HEADER_LABEL = 2
local FORCE_HIDE_PROGRESS_TEXT = true
ZO_ACHIEVEMENT_DISABLED_COLOR = ZO_ColorDef:New(0.6, 0.6, 0.6)
ZO_ACHIEVEMENT_DISABLED_DESATURATION = 0.5
local function GetTextColor(enabled, normalColor, disabledColor)
if enabled then
return (normalColor or ZO_NORMAL_TEXT):UnpackRGBA()
end
return (disabledColor or ZO_ACHIEVEMENT_DISABLED_COLOR):UnpackRGBA()
end
function ZO_Achievements_ApplyTextColorToLabel(label, ...)
label:SetColor(GetTextColor(...))
end
local function GetLastCompletedAchievementInLine(achievementId)
local lastCompleted = achievementId
while achievementId ~= 0 do
local _, _, _, _, completed, _, _= GetAchievementInfo(achievementId)
if not completed then
return lastCompleted
end
lastCompleted = achievementId
achievementId = GetNextAchievementInLine(achievementId)
end
return lastCompleted
end
--[[ Achievement ]]--
Achievement = ZO_InitializingObject:Subclass()
function Achievement:Initialize(control, checkPool, statusBarPool, rewardLabelPool, rewardIconPool, lineThumbPool, dyeSwatchPool, characterFrameBorderControlPool)
control.achievement = self
self.control = control
ZO_InventorySlot_SetType(self.control, SLOT_TYPE_ACHIEVEMENT_REWARD)
self.checkPool = checkPool
self.statusBarPool = statusBarPool
self.rewardLabelPool = rewardLabelPool
self.rewardIconPool = rewardIconPool
self.lineThumbPool = lineThumbPool
self.dyeSwatchPool = dyeSwatchPool
self.characterFrameBorderControlPool = characterFrameBorderControlPool
self.checkBoxes = {}
self.progressBars = {}
self.rewardIcons = {}
self.rewardLabels = {}
self.headerLabels = {}
self.lineThumbs = {}
self.dyeSwatches = {}
self.collapsed = true
self.title = control:GetNamedChild("Title")
self.highlight = control:GetNamedChild("Highlight")
self.description = control:GetNamedChild("Description")
self.icon = control:GetNamedChild("Icon")
self.points = control:GetNamedChild("Points")
self.date = control:GetNamedChild("Date")
self.rewardThumb = control:GetNamedChild("RewardThumb")
self.expandedStateIcon = control:GetNamedChild("ExpandedState")
self.anchoredToAchievement = nil
self.dependentAnchoredAchievement = nil
if self.highlight then
self.highlight:SetHeight(ACHIEVEMENT_COLLAPSED_HEIGHT)
end
self:InitializeKeybindDescriptors()
end
function Achievement:InitializeKeybindDescriptors()
self.keybindStripDescriptor =
{
{
alignment = KEYBIND_STRIP_ALIGN_CENTER,
name = function()
if GetSkyshardAchievementZoneId(self.achievementId) ~= 0 then
return GetString(SI_ZONE_STORY_OPEN_FROM_ACHIEVEMENT_ACTION)
else
return GetString(SI_ACHIEVEMENT_TO_LORE_LIBRARY_ACTION)
end
end,
keybind = "UI_SHORTCUT_SECONDARY",
callback = function()
local zoneId = GetSkyshardAchievementZoneId(self.achievementId)
if zoneId ~= 0 then
KEYBIND_STRIP:RemoveKeybindButtonGroup(self.keybindStripDescriptor)
ZONE_STORIES_MANAGER:ShowZoneStoriesScene(zoneId)
else
local bookCollectionId = GetAchievementLinkedBookCollectionId(self.achievementId)
KEYBIND_STRIP:RemoveKeybindButtonGroup(self.keybindStripDescriptor)
LORE_LIBRARY:SetCollectionIdToSelect(bookCollectionId)
MAIN_MENU_KEYBOARD:ShowScene("loreLibrary")
end
end,
visible = function()
return GetSkyshardAchievementZoneId(self.achievementId) ~= 0 or GetAchievementLinkedBookCollectionId(self.achievementId) ~= 0
end
},
}
end
function Achievement:GetId()
return self.achievementId
end
function Achievement:GetAchievementInfo(achievementId)
return GetAchievementInfo(achievementId)
end
function Achievement:GetIndex()
return self.index
end
function Achievement:SetIndex(index)
self.index = index
end
function Achievement:Show(achievementId)
self.achievementId = achievementId
local name, description, points, icon, completed, date, time = self:GetAchievementInfo(achievementId)
local titleText
local persistenceLevel = GetAchievementPersistenceLevel(achievementId)
self.isCharacterPersistent = persistenceLevel == ACHIEVEMENT_PERSISTENCE_CHARACTER
if self.isCharacterPersistent then
local titleIcon = zo_iconFormatInheritColor("EsoUI/Art/Miscellaneous/Gamepad/gp_charNameIcon.dds", "100%", "100%")
titleText = zo_strformat(SI_ACHIEVEMENT_TITLE_CHARACTER_LEVEL, titleIcon, name)
local frameColor = completed and ZO_SECOND_SELECTED_TEXT or ZO_SECOND_NORMAL_TEXT
local iconFrameBorder
if self.control.iconFrameBorderKey then
iconFrameBorder = self.characterFrameBorderControlPool:AcquireObject(self.control.iconFrameBorderKey)
else
local iconFrameBorderKey
iconFrameBorder, iconFrameBorderKey = self.characterFrameBorderControlPool:AcquireObject()
iconFrameBorder:SetParent(self.control:GetNamedChild("Icon"))
iconFrameBorder:SetAnchor(TOPLEFT, nil, TOPLEFT, -6, -6)
iconFrameBorder:SetAnchor(BOTTOMRIGHT, nil, BOTTOMRIGHT, 6, 6)
self.control.iconFrameBorderKey = iconFrameBorderKey
end
iconFrameBorder:SetColor(frameColor:UnpackRGBA())
else
titleText = zo_strformat(name)
if self.control.iconFrameBorderKey then
self.characterFrameBorderControlPool:ReleaseObject(self.control.iconFrameBorderKey)
self.control.iconFrameBorderKey = nil
end
end
self.title:SetText(titleText)
self.description:SetText(zo_strformat(description))
self.icon:SetTexture(icon)
self.points:SetHidden(points == ACHIEVEMENT_POINT_LEGENDARY_DEED)
self.points:SetText(tostring(points))
local titleNormalColor = self.isCharacterPersistent and ZO_SECOND_SELECTED_TEXT or ZO_SELECTED_TEXT
local titleDisabledColor = self.isCharacterPersistent and ZO_SECOND_NORMAL_TEXT or NO_DISABLED_COLOR
ZO_Achievements_ApplyTextColorToLabel(self.points, completed, ZO_SELECTED_TEXT)
ZO_Achievements_ApplyTextColorToLabel(self.title, completed, titleNormalColor, titleDisabledColor)
ZO_Achievements_ApplyTextColorToLabel(self.description, completed)
if self.highlight then
local highlightColor
if completed then
highlightColor = ZO_DEFAULT_ENABLED_COLOR
else
highlightColor = ZO_ACHIEVEMENT_DISABLED_COLOR
end
self.highlight:GetNamedChild("Top"):SetColor(highlightColor:UnpackRGBA())
self.highlight:GetNamedChild("Middle"):SetColor(highlightColor:UnpackRGBA())
self.highlight:GetNamedChild("Bottom"):SetColor(highlightColor:UnpackRGBA())
end
self.completed = completed
if completed then
self.date:SetHidden(false)
self.date:SetText(date)
self.icon:SetDesaturation(0)
else
self.date:SetHidden(true)
self.icon:SetDesaturation(ZO_ACHIEVEMENT_DISABLED_DESATURATION)
end
-- Date strings might overlap the description, so apply dimension constraints after setting the completion date
self:ApplyCollapsedDescriptionConstraints()
--Whether we need to expand partly depends on if the description will be truncated in collapsed mode which depends on its constraints being set above.
self.isExpandable = self:IsExpandable()
self:SetRewardThumb(achievementId)
self:UpdateExpandedStateIcon()
self.control:SetHidden(false)
end
function Achievement:SetRewardThumb(achievementId)
local hasReward, completedReward = self:HasTangibleReward() -- achievements always award points, account for that
self.rewardThumb:SetHidden(not hasReward)
if hasReward then
if completedReward then
self.rewardThumb:SetTexture("EsoUI/Art/Achievements/achievements_reward_earned.dds")
else
self.rewardThumb:SetTexture("EsoUI/Art/Achievements/achievements_reward_unearned.dds")
end
end
end
do
local function LayoutLineSection(controls, yOffset, parent, controlWidth, controlHeight)
local numControls = #controls
if numControls > 0 then
local previous
for i = 1, numControls do
if previous then
controls[i]:SetAnchor(LEFT, previous, RIGHT, ACHIEVEMENT_LINE_PADDING, 0)
else
local totalLineWidth = (numControls * (controlWidth + ACHIEVEMENT_LINE_PADDING)) - ACHIEVEMENT_LINE_PADDING
local startX = (ACHIEVEMENT_WIDTH - totalLineWidth) / 2
controls[i]:SetAnchor(TOPLEFT, parent, TOPLEFT, startX, yOffset)
end
previous = controls[i]
end
yOffset = yOffset + controlHeight + ACHIEVEMENT_LINE_PADDING_VERTICAL
end
return yOffset
end
local function LayoutCriteriaSection(controls, yOffset, parent, controlHeight)
local useFunctionToGetHeight = type(controlHeight) == "function"
local numControls = #controls
if numControls > 0 then
for i, control in ipairs(controls) do
yOffset = yOffset + (control.additionalVerticalPadding or 0)
control:SetAnchor(TOPLEFT, parent, TOPLEFT, 90, yOffset)
local currentHeight = controlHeight
if useFunctionToGetHeight then
currentHeight = currentHeight(control)
end
yOffset = yOffset + ACHIEVEMENT_CRITERIA_PADDING + currentHeight
end
end
return yOffset
end
local function LayoutRewardSection(controls, yOffset, parent, controlHeight)
local numControls = #controls
if numControls > 0 then
local numRewards = 0
for i, control in ipairs(controls) do
if not control.isHeader then
if control.prefix then
control:SetAnchor(LEFT, control.prefix, RIGHT, 5, 0)
else
numRewards = numRewards + 1
local padding = 0
if numRewards > 1 then
padding = ACHIEVEMENT_REWARD_PADDING
end
control:SetAnchor(TOPLEFT, parent, TOPLEFT, 90, yOffset + padding)
yOffset = yOffset + padding + controlHeight
end
end
end
yOffset = yOffset + ACHIEVEMENT_REWARD_PADDING
end
return yOffset
end
local function AddSectionPadding(controls, yOffset, padAmount)
if #controls > 0 then
return yOffset + padAmount
end
return yOffset
end
local function GetCriteriaHeightCheckBox(control)
local labelHeight = select(2, control.label:GetTextDimensions())
return zo_max(control:GetHeight(), labelHeight)
end
function Achievement:HasAnyVisibleCriteriaOrRewards()
return (#self.lineThumbs + #self.progressBars + #self.checkBoxes + #self.rewardLabels + #self.rewardIcons + #self.dyeSwatches) > 0
end
function Achievement:PerformExpandedLayout()
local controlTop = self.control:GetTop()
local yOffset = self.description:GetBottom() - controlTop -- always try to start right after the bottom of the description
local footerPad = self.title:GetTop() - controlTop
if self:HasAnyVisibleCriteriaOrRewards() then
-- If you have other things in the expanded view, pad out a little after the description
yOffset = yOffset + ACHIEVEMENT_INITIAL_CRITERIA_OFFSET
else
-- If you don't have anything else to show, at least show the full description, but if the full description
-- fits in the collapsed view, don't expand the window at all.
yOffset = zo_max(ACHIEVEMENT_COLLAPSED_HEIGHT, yOffset + footerPad)
end
yOffset = LayoutCriteriaSection(self.progressBars, yOffset, self.control, ACHIEVEMENT_STATUS_BAR_HEIGHT)
yOffset = AddSectionPadding(self.progressBars, yOffset, ACHIEVEMENT_CRITERIA_PADDING)
yOffset = LayoutCriteriaSection(self.checkBoxes, yOffset, self.control, GetCriteriaHeightCheckBox)
yOffset = LayoutLineSection(self.lineThumbs, yOffset, self.control, ACHIEVEMENT_LINE_THUMB_WIDTH, ACHIEVEMENT_LINE_THUMB_HEIGHT)
local hasRewards = #self.rewardLabels > 0 or #self.rewardIcons > 0 or #self.dyeSwatches > 0
if hasRewards then
yOffset = yOffset + 15 -- push down a little from the criteria
self.yOffsetWhereRewardsStart = yOffset
yOffset = LayoutRewardSection(self.rewardLabels, yOffset, self.control, ACHIEVEMENT_REWARD_LABEL_HEIGHT)
yOffset = LayoutRewardSection(self.rewardIcons, yOffset, self.control, ACHIEVEMENT_REWARD_ICON_HEIGHT)
yOffset = LayoutRewardSection(self.dyeSwatches, yOffset, self.control, ACHIEVEMENT_REWARD_ICON_HEIGHT)
end
footerPad = hasRewards and footerPad or 0
self.control:SetHeight(yOffset + footerPad)
end
end
function Achievement:AddProgressBar(description, numCompleted, numRequired, showBarDescription)
local bar, key = self.statusBarPool:AcquireObject()
bar.key = key
bar.label:SetText(showBarDescription and zo_strformat(SI_ACHIEVEMENT_CRITERION_FORMAT, description) or "")
ZO_Achievements_ApplyTextColorToLabel(bar.label, numCompleted == numRequired, ZO_SELECTED_TEXT)
local numCompletedAsString = ZO_CommaDelimitNumber(numCompleted)
local numRequiredAsString = ZO_CommaDelimitNumber(numRequired)
bar.additionalVerticalPadding = select(2, bar.label:GetTextDimensions()) + 4 -- add for for the anchor offset of the label from the bar
bar.progress:SetText(zo_strformat(SI_JOURNAL_PROGRESS_BAR_PROGRESS, numCompletedAsString, numRequiredAsString))
bar:SetMinMax(0, numRequired)
bar:SetValue(numCompleted)
bar:SetParent(self.control)
bar:SetHidden(false)
table.insert(self.progressBars, bar)
end
function Achievement:AddCheckBox(description, checked)
local check, key = self.checkPool:AcquireObject()
check.key = key
ZO_Achievements_ApplyTextColorToLabel(check.label, checked, ZO_SELECTED_TEXT)
check.label:SetText(zo_strformat(SI_ACHIEVEMENT_CRITERION_FORMAT, description))
check:SetParent(self.control)
check:SetAlpha(checked and 1 or 0)
check:SetHidden(false)
self.checkBoxes[#self.checkBoxes + 1] = check
end
function Achievement:AddIconReward(name, icon, displayQuality, rewardIndex)
local iconControl, key = self.rewardIconPool:AcquireObject()
iconControl.key = key
iconControl.icon:SetTexture(icon)
iconControl:SetHidden(false)
iconControl.rewardIndex = rewardIndex
iconControl.owner = self
iconControl:SetParent(self.control)
ZO_Inventory_BindSlot(iconControl, SLOT_TYPE_ACHIEVEMENT_REWARD, rewardIndex, self.achievementId)
iconControl.label:SetText(name) -- Already localized
iconControl.label:SetColor(GetInterfaceColor(INTERFACE_COLOR_TYPE_ITEM_QUALITY_COLORS, displayQuality))
table.insert(self.rewardIcons, iconControl)
end
function Achievement:GetPooledLabel(labelType, completed)
local label, key = self.rewardLabelPool:AcquireObject()
label.key = key
label:SetParent(self.control)
label:SetDimensions(ACHIEVEMENT_REWARD_LABEL_WIDTH, ACHIEVEMENT_REWARD_LABEL_HEIGHT)
if labelType == PREFIX_LABEL then
label:SetDimensions(0, ACHIEVEMENT_REWARD_LABEL_HEIGHT)
end
ZO_Achievements_ApplyTextColorToLabel(label, completed)
label.prefix = nil
label.isHeader = labelType == HEADER_LABEL
label:SetMouseEnabled(false)
label:SetHidden(false)
table.insert(self.rewardLabels, label)
return label
end
function Achievement:AddTitleReward(name, completed)
local title = self:GetPooledLabel(nil, completed)
title:SetText(name) -- already localized
local titlePrefix = self:GetPooledLabel(PREFIX_LABEL, completed)
titlePrefix:SetText(GetString(SI_ACHIEVEMENTS_TITLE))
title.prefix = titlePrefix
end
function Achievement:AddDyeReward(dyeId, completed)
local dyeName, known, rarity, hueCategory, achievementId, r, g, b, sortKey = GetDyeInfoById(dyeId)
local dyeSwatch, key = self.dyeSwatchPool:AcquireObject()
dyeSwatch.key = key
dyeSwatch.icon:SetColor(1, r, g, b)
local dyeNamePrefix = self:GetPooledLabel(PREFIX_LABEL, completed)
dyeNamePrefix:SetText(GetString(SI_ACHIEVEMENTS_DYE))
dyeSwatch.prefix = dyeNamePrefix
dyeSwatch:SetHidden(false)
dyeSwatch.owner = self
dyeSwatch:SetParent(self.control)
dyeSwatch.label:SetText(zo_strformat(SI_DYEING_SWATCH_TOOLTIP_TITLE, dyeName))
ZO_Achievements_ApplyTextColorToLabel(dyeSwatch.label, completed)
table.insert(self.dyeSwatches, dyeSwatch)
end
function Achievement:AddCollectibleReward(collectibleId, completed)
local collectibleNameLabel = self:GetPooledLabel(nil, completed)
local collectibleData = ZO_COLLECTIBLE_DATA_MANAGER:GetCollectibleDataById(collectibleId)
collectibleNameLabel:SetText(collectibleData:GetFormattedName())
local collectiblePrefixLabel = self:GetPooledLabel(PREFIX_LABEL, completed)
collectiblePrefixLabel:SetText(zo_strformat(SI_ACHIEVEMENTS_COLLECTIBLE_CATEGORY, collectibleData:GetCategoryTypeDisplayName()))
collectibleNameLabel.prefix = collectiblePrefixLabel
end
do
local ORDER_PREFIX = 1
local ORDER_POSTFIX = 2
local function AddAchievementLineThumb(owner, achievementId, lineThumbPool, lineThumbs, queryFunction, order)
if achievementId == 0 then return end
if order == ORDER_PREFIX then
AddAchievementLineThumb(owner, queryFunction(achievementId), lineThumbPool, lineThumbs, queryFunction, order)
end
local points, icon, completed = select(3, GetAchievementInfo(achievementId))
local lineThumb, key = lineThumbPool:AcquireObject()
lineThumb.key = key
lineThumb.icon:SetTexture(icon)
lineThumb.label:SetText(points)
lineThumb.achievementId = achievementId
lineThumb.owner = owner
if completed then
lineThumb.icon:SetDesaturation(0)
lineThumb.label:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA())
else
lineThumb.icon:SetDesaturation(ZO_ACHIEVEMENT_DISABLED_DESATURATION)
lineThumb.label:SetColor(ZO_ACHIEVEMENT_DISABLED_COLOR:UnpackRGBA())
end
lineThumb:SetHidden(false)
lineThumbs[#lineThumbs + 1] = lineThumb
if order == ORDER_POSTFIX then
AddAchievementLineThumb(owner, queryFunction(achievementId), lineThumbPool, lineThumbs, queryFunction, order)
end
end
function Achievement:RefreshExpandedLineView()
local lineThumbPool = self.lineThumbPool
local lineThumbs = self.lineThumbs
local achievementId = self.achievementId
local previousInLine = GetPreviousAchievementInLine(achievementId)
local nextInLine = GetNextAchievementInLine(achievementId)
local shouldAddSelfAsLine = (previousInLine ~= 0) or (nextInLine ~= 0)
AddAchievementLineThumb(self, previousInLine, lineThumbPool, lineThumbs, GetPreviousAchievementInLine, ORDER_PREFIX)
if shouldAddSelfAsLine then
AddAchievementLineThumb(self, achievementId, lineThumbPool, lineThumbs)
end
AddAchievementLineThumb(self, nextInLine, lineThumbPool, lineThumbs, GetNextAchievementInLine, ORDER_POSTFIX)
end
end
function Achievement:WouldShowLines()
local achievementId = self.achievementId
return GetPreviousAchievementInLine(achievementId) ~= 0 or GetNextAchievementInLine(achievementId) ~= 0
end
function Achievement:WouldHaveVisibleCriteria()
local numCriteria = GetAchievementNumCriteria(self.achievementId)
if numCriteria > 1 then
return true
end
if numCriteria == 0 then
return false
end
local _, _, numRequired = GetAchievementCriterion(self.achievementId, 1)
-- This would be the only checkbox, it doesn't count as a visible criteria
if numRequired == 1 then
return false
end
return true
end
function Achievement:HasTangibleReward()
local hasReward = GetAchievementNumRewards(self.achievementId) > 1
local hasCompleted = self.completed
local prevAchievement = GetPreviousAchievementInLine(self.achievementId)
while prevAchievement ~= 0 do
hasReward = hasReward or GetAchievementNumRewards(prevAchievement) > 1
hasCompleted = hasCompleted or select(5, GetAchievementInfo(prevAchievement))
prevAchievement = GetPreviousAchievementInLine(prevAchievement)
end
local nextAchievement = GetNextAchievementInLine(self.achievementId)
while nextAchievement ~= 0 do
hasReward = hasReward or GetAchievementNumRewards(nextAchievement) > 1
hasCompleted = hasCompleted or select(5, GetAchievementInfo(nextAchievement))
nextAchievement = GetNextAchievementInLine(nextAchievement)
end
return hasReward, hasCompleted
end
function Achievement:IsExpandable()
return self.description:WasTruncated() or self:WouldHaveVisibleCriteria() or self:HasTangibleReward() or self:WouldShowLines()
end
function Achievement:RefreshExpandedCriteria()
local numCriteria = GetAchievementNumCriteria(self.achievementId)
local hasMultipleCriteria = (numCriteria > 1)
local showProgressBarDescriptions = hasMultipleCriteria
for i = 1, numCriteria do
local description, numCompleted, numRequired = GetAchievementCriterion(self.achievementId, i)
if numRequired > 1 then
self:AddProgressBar(description, numCompleted, numRequired, showProgressBarDescriptions)
elseif hasMultipleCriteria and (numRequired == 1) then
self:AddCheckBox(description, numCompleted == 1)
end
end
end
local function AddRewards(self, achievementId)
local completed = select(5, GetAchievementInfo(achievementId))
-- get item reward
local hasRewardItem, itemName, iconTextureName, displayQuality = GetAchievementRewardItem(achievementId)
if hasRewardItem then
self:AddIconReward(itemName, iconTextureName, displayQuality, 1)
end
-- get title reward
local hasRewardTitle, titleName = GetAchievementRewardTitle(achievementId)
if hasRewardTitle then
self:AddTitleReward(titleName, completed)
end
-- get dye reward
local hasRewardDye, dyeId = GetAchievementRewardDye(achievementId)
if hasRewardDye then
self:AddDyeReward(dyeId, completed)
end
-- get collectible reward
local hasRewardCollectible, collectibleId = GetAchievementRewardCollectible(achievementId)
if hasRewardCollectible then
self:AddCollectibleReward(collectibleId, completed)
end
end
function Achievement:RefreshExpandedRewards()
local numLineThumbs = #self.lineThumbs
if numLineThumbs > 0 then
for _, lineThumb in ipairs(self.lineThumbs) do
local achievementId = lineThumb.achievementId
AddRewards(self, lineThumb.achievementId)
end
else
AddRewards(self, self.achievementId)
end
end
function Achievement:RefreshRewardThumb()
if self.rewardThumb and self.yOffsetWhereRewardsStart then
self.rewardThumb:ClearAnchors()
self.rewardThumb:SetAnchor(TOPLEFT, self.control, TOPLEFT, 42, self.yOffsetWhereRewardsStart - 6)
end
end
function Achievement:RefreshExpandedView()
if self.collapsed then return end
self:ReleaseSharedControls()
self:RefreshExpandedCriteria()
self:RefreshExpandedLineView()
self:RefreshExpandedRewards()
self:PerformExpandedLayout()
self:RefreshRewardThumb()
end
function Achievement:PlayExpandCollapseSound()
if not self.isExpandable then
return
end
if self.collapsed then
PlaySound(SOUNDS.ACHIEVEMENT_COLLAPSED)
else
PlaySound(SOUNDS.ACHIEVEMENT_EXPANDED)
end
end
function Achievement:UpdateExpandedStateIcon()
if self.expandedStateIcon then
if self.isExpandable then
if self.collapsed then
ZO_ToggleButton_SetState(self.expandedStateIcon, TOGGLE_BUTTON_CLOSED)
else
ZO_ToggleButton_SetState(self.expandedStateIcon, TOGGLE_BUTTON_OPEN)
end
else
self.expandedStateIcon:SetHidden(true)
end
end
end
function Achievement:CalculateDescriptionWidth()
local descriptionWidth = ACHIEVEMENT_DESC_WIDTH
if self.completed then
local widthModifier = zo_max(0, self.date:GetWidth() - ACHIEVEMENT_DATE_LABEL_EXPECTED_WIDTH)
if widthModifier ~= 0 then
descriptionWidth = descriptionWidth - widthModifier
end
end
return descriptionWidth
end
function Achievement:Expand()
if self.collapsed then
self.collapsed = false
self:RemoveCollapsedDescriptionConstraints()
self:RefreshExpandedView()
self:UpdateExpandedStateIcon()
self:PlayExpandCollapseSound()
end
end
function Achievement:ApplyCollapsedDescriptionConstraints()
if self.title:DidLineWrap() then
self.description:SetDimensionConstraints(0, 0, self:CalculateDescriptionWidth(), ACHIEVEMENT_DESC_COLLAPSED_HEIGHT / 2)
else
self.description:SetDimensionConstraints(0, 0, self:CalculateDescriptionWidth(), ACHIEVEMENT_DESC_COLLAPSED_HEIGHT)
end
end
function Achievement:RemoveCollapsedDescriptionConstraints()
self.description:SetDimensionConstraints(0, 0, self:CalculateDescriptionWidth(), 0)
end
function Achievement:Collapse()
if not self.collapsed then
self.collapsed = true
if self.rewardThumb then
self.rewardThumb:ClearAnchors()
self.rewardThumb:SetAnchor(TOPLEFT, self.control, TOPLEFT, 42, 58)
end
self:ApplyCollapsedDescriptionConstraints()
self.control:SetHeight(ACHIEVEMENT_COLLAPSED_HEIGHT)
self:UpdateExpandedStateIcon()
self:PlayExpandCollapseSound()
self:ReleaseSharedControls()
end
end
do
local function ReleaseControls(pool, controls)
for i = #controls, 1, -1 do
pool:ReleaseObject(controls[i].key)
controls[i] = nil
end
end
function Achievement:ReleaseSharedControls()
ReleaseControls(self.checkPool, self.checkBoxes)
ReleaseControls(self.statusBarPool, self.progressBars)
ReleaseControls(self.rewardIconPool, self.rewardIcons)
ReleaseControls(self.rewardLabelPool, self.rewardLabels)
ReleaseControls(self.lineThumbPool, self.lineThumbs)
ReleaseControls(self.dyeSwatchPool, self.dyeSwatches)
ReleaseControls(self.characterFrameBorderControlPool, {})
self.rewardLabel = nil
end
end
function Achievement:SetAnchoredToAchievement(previous)
self.control:ClearAnchors()
-- This ensures that we can't have orphans, but it also means that we must do things in the proper order
-- So whenever moving an achievement in the list, you must move the achievement to its new spot BEFORE closing the gap
if self.anchoredToAchievement then
self.anchoredToAchievement:SetDependentAnchoredAchievement(nil)
self.anchoredToAchievement = nil
end
if previous then
self.control:SetAnchor(TOP, previous:GetControl(), BOTTOM, 0, ACHIEVEMENT_PADDING)
previous:SetDependentAnchoredAchievement(self)
self.anchoredToAchievement = previous
else
self.control:SetAnchor(TOPLEFT, nil, TOPLEFT)
end
end
function Achievement:GetAnchoredToAchievement()
return self.anchoredToAchievement
end
function Achievement:SetDependentAnchoredAchievement(dependentAchievement)
self.dependentAnchoredAchievement = dependentAchievement
end
function Achievement:GetDependentAnchoredAchievement()
return self.dependentAnchoredAchievement
end
function Achievement:GetControl()
return self.control
end
function Achievement:ToggleCollapse()
if self.collapsed then
self:Expand()
else
self:Collapse()
end
end
function Achievement:Reset()
self.control:SetHidden(true)
self:SetHighlightHidden(true)
self:Collapse()
self.rewardLabel = nil
self:SetIndex(nil)
if self.control.iconFrameBorderKey then
self.characterFrameBorderControlPool:ReleaseObject(self.control.iconFrameBorderKey)
self.control.iconFrameBorderKey = nil
end
self.anchoredToAchievement = nil
self:SetDependentAnchoredAchievement(nil)
end
function Achievement:SetHighlightHidden(hidden)
if self.highlight then
self.highlight:SetHidden(false) -- let alpha take care of the actual hiding
if not self.highlightAnimation then
self.highlightAnimation = ANIMATION_MANAGER:CreateTimelineFromVirtual("AchievementHighlightAnimation_Keyboard", self.highlight)
end
if hidden then
self.highlightAnimation:PlayBackward()
else
self.highlightAnimation:PlayForward()
end
end
end
function Achievement:OnMouseEnter(control)
self:SetHighlightHidden(false)
self:RefreshTooltip(control)
KEYBIND_STRIP:AddKeybindButtonGroup(control.achievement.keybindStripDescriptor)
end
function Achievement:OnMouseExit(control)
self:SetHighlightHidden(true)
ClearTooltip(InformationTooltip)
KEYBIND_STRIP:RemoveKeybindButtonGroup(control.achievement.keybindStripDescriptor)
end
function Achievement:RefreshTooltip(control)
ClearTooltip(InformationTooltip)
if self.collapsed or #self.lineThumbs == 0 then
if self.completed and not self.isCharacterPersistent then
local completeByCharId = GetCharIdForCompletedAchievement(self.achievementId)
if completeByCharId then
local characterName = GetCharacterNameById(completeByCharId)
if characterName ~= "" then
local colorizedCharacterName = ZO_SELECTED_TEXT:Colorize(characterName)
InitializeTooltip(InformationTooltip, control, RIGHT, -5, 0)
SetTooltipText(InformationTooltip, zo_strformat(SI_ACHIEVEMENT_EARNED_FORMATTER, colorizedCharacterName))
end
end
end
end
end
function Achievement:OnClicked(button)
if button == MOUSE_BUTTON_INDEX_LEFT then
self:ToggleCollapse()
self:RefreshTooltip(self.control)
elseif button == MOUSE_BUTTON_INDEX_RIGHT and IsChatSystemAvailableForCurrentPlatform() then
ClearMenu()
AddMenuItem(GetString(SI_ITEM_ACTION_LINK_TO_CHAT), function() ZO_LinkHandler_InsertLink(ZO_LinkHandler_CreateChatLink(GetAchievementLink, self:GetId())) end)
ShowMenu(self.control)
end
end
--[[ Achievement Container ]]--
AchievementContainer = Achievement:Subclass()
function AchievementContainer:Initialize(parentControl, ...)
self.parentControl = parentControl
local achievementControl = parentControl:GetNamedChild("Achievement")
Achievement.Initialize(self, achievementControl, ...)
self.highlight = nil --don't want any highlights on the popup
end
function AchievementContainer:PerformExpandedLayout()
Achievement.PerformExpandedLayout(self)
self.parentControl:SetHeight(self.control:GetDesiredHeight())
end
function AchievementContainer:Show(id, progress, timestamp)
self.parentControl:SetHidden(false)
self.parentControl:BringWindowToTop()
self.progress = progress
self.timestamp = timestamp
Achievement.Show(self, id)
if self.collapsed then
self:Expand()
else
self:RefreshExpandedView()
end
end
function AchievementContainer:Hide()
self.parentControl:SetHidden(true)
self:Reset()
end
--[[ Popup Achievement ]]--
PopupAchievement = AchievementContainer:Subclass()
function PopupAchievement:Initialize(parentControl, ...)
AchievementContainer.Initialize(self, parentControl, ...)
self.parentControl:SetHandler("OnHide", function()
self.lastShownLink = nil
end)
end
function PopupAchievement:GetAchievementInfo(achievementId)
local name, description, points, icon = GetAchievementInfo(achievementId)
--use the data from the link instead
local completed = tonumber(self.timestamp) ~= 0
local date, time = FormatAchievementLinkTimestamp(self.timestamp)
return name, description, points, icon, completed, date, time
end
function PopupAchievement:RefreshExpandCriteriaFromDataLink(...)
local numCriteria = select("#", ...)
local showProgressDescriptions = numCriteria > 1
for i = 1, numCriteria do
local description, numCompleted, numRequired = GetAchievementCriterion(self.achievementId, i)
--overwrite with data from the link
numCompleted = select(i, ...)
if numRequired > 1 then
self:AddProgressBar(description, numCompleted, numRequired, showProgressDescriptions)
elseif numRequired == 1 and showProgressDescriptions then
--We only show basic steps if there's more than one step, otherwise the step is just the achievement
self:AddCheckBox(description, numCompleted == 1)
end
end
end
function PopupAchievement:RefreshExpandedCriteria()
self:RefreshExpandCriteriaFromDataLink(GetAchievementProgressFromLinkData(self.achievementId, self.progress))
end
function PopupAchievement:RefreshExpandedLineView()
--Do nothing, popup achievements don't show their line information
end
function PopupAchievement:HasTangibleReward()
local hasReward = GetAchievementNumRewards(self.achievementId) > 1
local hasCompleted = self.completed
return hasReward, hasCompleted
end
--[[ Icon Achievement ]]--
local IconAchievement = ZO_InitializingObject:Subclass()
function IconAchievement:Initialize(control)
self.control = control
self.icon = control:GetNamedChild("Icon")
control.achievement = self
end
function IconAchievement:Show(achievementId)
self.achievementId = achievementId
local name, description, points, icon, completed, date, time = GetAchievementInfo(achievementId)
self.name = name
self.icon:SetTexture(icon)
self.control:SetHidden(false)
end
function IconAchievement:Reset()
self.control:SetHidden(true)
self.achievementId = nil
self.name = nil
end
function IconAchievement:SetAnchor(previous)
self.control:ClearAnchors()
if previous then
self.control:SetAnchor(TOPLEFT, previous.control, TOPRIGHT, ACHIEVEMENT_ICON_STYLE_PADDING, 0)
else
self.control:SetAnchor(BOTTOMLEFT, nil, BOTTOMLEFT, 0, -32)
end
end