/
Blizzard_EncounterJournal.lua
3456 lines (2938 loc) · 111 KB
/
Blizzard_EncounterJournal.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
--FILE CONSTANTS
local HEADER_INDENT = 15;
local MAX_CREATURES_PER_ENCOUNTER = 9;
local SECTION_BUTTON_OFFSET = 6;
local SECTION_DESCRIPTION_OFFSET = 27;
local EJ_STYPE_ITEM = 0;
local EJ_STYPE_ENCOUNTER = 1;
local EJ_STYPE_CREATURE = 2;
local EJ_STYPE_SECTION = 3;
local EJ_STYPE_INSTANCE = 4;
local EJ_HTYPE_OVERVIEW = 3;
local EJ_NUM_INSTANCE_PER_ROW = 4;
local EJ_MAX_SECTION_MOVE = 320;
local EJ_TIER_INDEX_SHADOWLANDS = 9;
AJ_MAX_NUM_SUGGESTIONS = 3;
-- Priority list for *not my spec*
local overviewPriorities = {
[1] = "DAMAGER",
[2] = "HEALER",
[3] = "TANK",
[4] = "NONE",
}
local NONE_FLAG = -1;
local flagsByRole = {
["DAMAGER"] = 1,
["HEALER"] = 2,
["TANK"] = 0,
["NONE"] = NONE_FLAG,
}
local EJ_Tabs = {};
EJ_Tabs[1] = {frame="overviewScroll", button="overviewTab"};
EJ_Tabs[2] = {frame="LootContainer", button="lootTab"};
EJ_Tabs[3] = {frame="detailsScroll", button="bossTab"};
EJ_Tabs[4] = {frame="model", button="modelTab"};
local EJ_section_openTable = {};
local EJ_LINK_INSTANCE = 0;
local EJ_LINK_ENCOUNTER = 1;
local EJ_LINK_SECTION = 3;
local EJ_DIFFICULTIES = {
DifficultyUtil.ID.DungeonNormal,
DifficultyUtil.ID.DungeonHeroic,
DifficultyUtil.ID.DungeonMythic,
DifficultyUtil.ID.DungeonChallenge,
DifficultyUtil.ID.DungeonTimewalker,
DifficultyUtil.ID.RaidLFR,
DifficultyUtil.ID.Raid10Normal,
DifficultyUtil.ID.Raid10Heroic,
DifficultyUtil.ID.Raid25Normal,
DifficultyUtil.ID.Raid25Heroic,
DifficultyUtil.ID.PrimaryRaidLFR,
DifficultyUtil.ID.PrimaryRaidNormal,
DifficultyUtil.ID.PrimaryRaidHeroic,
DifficultyUtil.ID.PrimaryRaidMythic,
DifficultyUtil.ID.RaidTimewalker,
};
local function IsEJDifficulty(difficultyID)
return tContains(EJ_DIFFICULTIES, difficultyID);
end
local function GetEJDifficultySize(difficultyID)
if difficultyID ~= DifficultyUtil.ID.RaidTimewalker and not DifficultyUtil.IsPrimaryRaid(difficultyID) then
return DifficultyUtil.GetMaxPlayers(difficultyID);
end
return nil;
end
local function GetEJDifficultyString(difficultyID)
local name = DifficultyUtil.GetDifficultyName(difficultyID);
local size = GetEJDifficultySize(difficultyID);
if size then
return string.format(ENCOUNTER_JOURNAL_DIFF_TEXT, size, name);
else
return name;
end
end
local EJ_TIER_DATA =
{
[1] = { backgroundAtlas = "UI-EJ-Classic", r = 1.0, g = 0.8, b = 0.0 },
[2] = { backgroundAtlas = "UI-EJ-BurningCrusade", r = 0.6, g = 0.8, b = 0.0 },
[3] = { backgroundAtlas = "UI-EJ-WrathoftheLichKing", r = 0.2, g = 0.8, b = 1.0 },
[4] = { backgroundAtlas = "UI-EJ-Cataclysm", r = 1.0, g = 0.4, b = 0.0 },
[5] = { backgroundAtlas = "UI-EJ-MistsofPandaria", r = 0.0, g = 0.6, b = 0.2 },
[6] = { backgroundAtlas = "UI-EJ-WarlordsofDraenor", r = 0.82, g = 0.55, b = 0.1 },
[7] = { backgroundAtlas = "UI-EJ-Legion", r = 0.0, g = 0.6, b = 0.2 },
[8] = { backgroundAtlas = "UI-EJ-BattleforAzeroth", r = 0.8, g = 0.4, b = 0.0 },
[9] = { backgroundAtlas = "UI-EJ-Shadowlands", r = 0.278, g = 0.471, b = .937 },
[10] = { backgroundAtlas = "UI-EJ-Dragonflight", r = 0.2, g = 0.8, b = 1.0 },
[11] = { backgroundAtlas = "UI-EJ-Dragonflight", r = 0.2, g = 0.8, b = 1.0 },
}
EJButtonMixin = {}
function EJButtonMixin:OnLoad()
local l, t, _, b, r = self.UpLeft:GetTexCoord();
self.UpLeft:SetTexCoord(l, l + (r-l)/2, t, b);
l, t, _, b, r = self.UpRight:GetTexCoord();
self.UpRight:SetTexCoord(l + (r-l)/2, r, t, b);
l, t, _, b, r = self.DownLeft:GetTexCoord();
self.DownLeft:SetTexCoord(l, l + (r-l)/2, t, b);
l, t, _, b, r = self.DownRight:GetTexCoord();
self.DownRight:SetTexCoord(l + (r-l)/2, r, t, b);
l, t, _, b, r = self.HighLeft:GetTexCoord();
self.HighLeft:SetTexCoord(l, l + (r-l)/2, t, b);
l, t, _, b, r = self.HighRight:GetTexCoord();
self.HighRight:SetTexCoord(l + (r-l)/2, r, t, b);
end
function EJButtonMixin:OnMouseDown(button)
self.UpLeft:Hide();
self.UpRight:Hide();
self.DownLeft:Show();
self.DownRight:Show();
end
function EJButtonMixin:OnMouseUp(button)
self.UpLeft:Show();
self.UpRight:Show();
self.DownLeft:Hide();
self.DownRight:Hide();
end
function GetEJTierData(tier)
return EJ_TIER_DATA[tier] or EJ_TIER_DATA[1];
end
ExpansionEnumToEJTierDataTableId = {
[LE_EXPANSION_CLASSIC] = 1,
[LE_EXPANSION_BURNING_CRUSADE] = 2,
[LE_EXPANSION_WRATH_OF_THE_LICH_KING] = 3,
[LE_EXPANSION_CATACLYSM] = 4,
[LE_EXPANSION_MISTS_OF_PANDARIA] = 5,
[LE_EXPANSION_WARLORDS_OF_DRAENOR] = 6,
[LE_EXPANSION_LEGION] = 7,
[LE_EXPANSION_BATTLE_FOR_AZEROTH] = 8,
[LE_EXPANSION_SHADOWLANDS] = 9,
[LE_EXPANSION_DRAGONFLIGHT] = 10,
}
function GetEJTierDataTableID(expansion)
local data = ExpansionEnumToEJTierDataTableId[expansion];
if data then
return data;
end
return ExpansionEnumToEJTierDataTableId[LE_EXPANSION_CLASSIC];
end
local SlotFilterToSlotName = {
[Enum.ItemSlotFilterType.Head] = INVTYPE_HEAD,
[Enum.ItemSlotFilterType.Neck] = INVTYPE_NECK,
[Enum.ItemSlotFilterType.Shoulder] = INVTYPE_SHOULDER,
[Enum.ItemSlotFilterType.Cloak] = INVTYPE_CLOAK,
[Enum.ItemSlotFilterType.Chest] = INVTYPE_CHEST,
[Enum.ItemSlotFilterType.Wrist] = INVTYPE_WRIST,
[Enum.ItemSlotFilterType.Hand] = INVTYPE_HAND,
[Enum.ItemSlotFilterType.Waist] = INVTYPE_WAIST,
[Enum.ItemSlotFilterType.Legs] = INVTYPE_LEGS,
[Enum.ItemSlotFilterType.Feet] = INVTYPE_FEET,
[Enum.ItemSlotFilterType.MainHand] = INVTYPE_WEAPONMAINHAND,
[Enum.ItemSlotFilterType.OffHand] = INVTYPE_WEAPONOFFHAND,
[Enum.ItemSlotFilterType.Finger] = INVTYPE_FINGER,
[Enum.ItemSlotFilterType.Trinket] = INVTYPE_TRINKET,
[Enum.ItemSlotFilterType.Other] = EJ_LOOT_SLOT_FILTER_OTHER,
}
local BOSS_LOOT_BUTTON_HEIGHT = 45;
local INSTANCE_LOOT_BUTTON_HEIGHT = 64;
EncounterJournalItemMixin = {};
function EncounterJournalItemMixin:Init(elementData)
local index = elementData.index;
if (EncounterJournal.encounterID) then
self:SetHeight(BOSS_LOOT_BUTTON_HEIGHT);
self.boss:Hide();
self.bossTexture:Hide();
self.bosslessTexture:Show();
else
self:SetHeight(INSTANCE_LOOT_BUTTON_HEIGHT);
self.boss:Show();
self.bossTexture:Show();
self.bosslessTexture:Hide();
end
self.index = index;
local itemInfo = C_EncounterJournal.GetLootInfoByIndex(self.index);
if ( itemInfo and itemInfo.name ) then
self.name:SetText(WrapTextInColorCode(itemInfo.name, itemInfo.itemQuality));
self.icon:SetTexture(itemInfo.icon);
if itemInfo.handError then
self.slot:SetText(INVALID_EQUIPMENT_COLOR:WrapTextInColorCode(itemInfo.slot));
else
self.slot:SetText(itemInfo.slot);
end
if itemInfo.weaponTypeError then
self.armorType:SetText(INVALID_EQUIPMENT_COLOR:WrapTextInColorCode(itemInfo.armorType));
else
self.armorType:SetText(itemInfo.armorType);
end
local numEncounters = EJ_GetNumEncountersForLootByIndex(self.index);
if ( numEncounters == 1 ) then
self.boss:SetFormattedText(BOSS_INFO_STRING, EJ_GetEncounterInfo(itemInfo.encounterID));
elseif ( numEncounters == 2) then
local itemInfoSecond = C_EncounterJournal.GetLootInfoByIndex(self.index, 2);
local secondEncounterID = itemInfoSecond and itemInfoSecond.encounterID;
if ( itemInfo.encounterID and secondEncounterID ) then
self.boss:SetFormattedText(BOSS_INFO_STRING_TWO, EJ_GetEncounterInfo(itemInfo.encounterID), EJ_GetEncounterInfo(secondEncounterID));
end
elseif ( numEncounters > 2 ) then
self.boss:SetFormattedText(BOSS_INFO_STRING_MANY, EJ_GetEncounterInfo(itemInfo.encounterID));
end
local itemName, _, quality = GetItemInfo(itemInfo.link);
SetItemButtonQuality(self, quality, itemInfo.link);
else
self.name:SetText(RETRIEVING_ITEM_INFO);
self.icon:SetTexture("Interface\\Icons\\INV_Misc_QuestionMark");
self.slot:SetText("");
self.armorType:SetText("");
self.boss:SetText("");
end
self.encounterID = itemInfo and itemInfo.encounterID;
self.itemID = itemInfo and itemInfo.itemID;
self.link = itemInfo and itemInfo.link;
if self.showingTooltip then
GameTooltip:SetAnchorType("ANCHOR_RIGHT");
local useSpec = true;
EncounterJournal_SetTooltipWithCompare(GameTooltip, self.link, useSpec);
end
end
EncounterJournalItemHeaderMixin = {};
function EncounterJournalItemHeaderMixin:Init(elementData)
self.name:SetText(elementData.text);
if elementData.helpText then
self.TipButton.elementData = elementData;
self.TipButton:Show();
else
self.TipButton:Hide();
end
end
EncounterBossButtonMixin = {};
function EncounterBossButtonMixin:Init(elementData)
local index = elementData.index;
local name, description, bossID, rootSectionID, link = EJ_GetEncounterInfoByIndex(index);
self.link = link;
self:SetText(name);
self.encounterID = bossID;
--Use the boss' first creature as the button icon
local bossImage = select(5, EJ_GetCreatureInfo(1, bossID)) or "Interface\\EncounterJournal\\UI-EJ-BOSS-Default";
self.creature:SetTexture(bossImage);
if (EncounterJournal.encounterID == bossID) then
self:LockHighlight();
else
self:UnlockHighlight();
end
EncounterJournalBossButton_UpdateDifficultyOverlay(self);
end
MonthlyActivitiesTabButtonMixin = CreateFromMixins(PanelTabButtonMixin);
function MonthlyActivitiesTabButtonMixin:OnEnter()
if not C_PlayerInfo.IsTravelersLogAvailable() then
GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
local factionGroup = UnitFactionGroup("player");
local tradingPostLocation = factionGroup == "Alliance" and MONTHLY_ACTIVITIES_TRADING_POST_ALLIANCE or MONTHLY_ACTIVITIES_TRADING_POST_HORDE;
GameTooltip_AddErrorLine(GameTooltip, MONTHLY_ACTIVITIES_UNAVAILABLE_TOOLTIP:format(tradingPostLocation));
if AreMonthlyActivitiesRestricted() then
GameTooltip_AddBlankLineToTooltip(GameTooltip);
GameTooltip_AddErrorLine(GameTooltip, MONTHLY_ACTIVITIES_RESTRICTED_TOOLTIP);
end
GameTooltip:Show();
end
end
function EncounterJournal_OnLoad(self)
self:SetTitle(ADVENTURE_JOURNAL);
self:SetPortraitToAsset([[Interface\EncounterJournal\UI-EJ-PortraitIcon]]);
self:RegisterEvent("EJ_LOOT_DATA_RECIEVED");
self:RegisterEvent("EJ_DIFFICULTY_UPDATE");
self:RegisterEvent("UNIT_PORTRAIT_UPDATE");
self:RegisterEvent("PORTRAITS_UPDATED");
self:RegisterEvent("SEARCH_DB_LOADED");
self:RegisterEvent("UI_MODEL_SCENE_INFO_UPDATED");
self.encounter.freeHeaders = {};
self.encounter.usedHeaders = {};
self.encounter.overviewFrame = self.encounter.info.overviewScroll.child;
self.encounter.overviewFrame.isOverview = true;
self.encounter.overviewFrame.overviews = {};
self.encounter.info.overviewScroll.ScrollBar.scrollStep = 30;
self.encounter.infoFrame = self.encounter.info.detailsScroll.child;
self.encounter.info.detailsScroll.ScrollBar.scrollStep = 30;
self.encounter.info.overviewTab:Click();
-- Bosses
do
local info = self.encounter.info;
local scrollBox = info.BossesScrollBox;
local scrollBar = info.BossesScrollBar;
local view = CreateScrollBoxListLinearView();
view:SetElementInitializer("EncounterBossButtonTemplate", function(button, elementData)
button:Init(elementData);
end);
view:SetPadding(10,0,0,20,15);
ScrollUtil.InitScrollBoxListWithScrollBar(scrollBox, scrollBar, view);
end
-- Items
do
local view = CreateScrollBoxListLinearView();
view:SetElementExtentCalculator(function(dataIndex, elementData)
if elementData.header then
return BOSS_LOOT_BUTTON_HEIGHT;
elseif EncounterJournal.encounterID then
return BOSS_LOOT_BUTTON_HEIGHT;
else
return INSTANCE_LOOT_BUTTON_HEIGHT;
end
end);
view:SetElementFactory(function(factory, elementData)
if elementData.header then
factory("EncounterItemDividerTemplate", function(button, elementData)
button:Init(elementData);
end);
else
factory("EncounterItemTemplate", function(button, elementData)
button:Init(elementData);
end);
end
end);
local lootContainer = self.encounter.info.LootContainer;
local scrollBox = lootContainer.ScrollBox;
local scrollBar = lootContainer.ScrollBar;
ScrollUtil.InitScrollBoxListWithScrollBar(scrollBox, scrollBar, view);
UIDropDownMenu_Initialize(lootContainer.lootFilter, EncounterJournal_InitLootFilter, "MENU");
UIDropDownMenu_Initialize(lootContainer.lootSlotFilter, EncounterJournal_InitLootSlotFilter, "MENU");
end
-- Search
do
local view = CreateScrollBoxListLinearView();
view:SetElementInitializer("EncounterSearchLGTemplate", function(button, elementData)
button:Init(elementData);
end);
local scrollBox = EncounterJournal.searchResults.ScrollBox;
local scrollBar = EncounterJournal.searchResults.ScrollBar;
local panExtent = buttonHeight;
ScrollUtil.InitScrollBoxListWithScrollBar(scrollBox, scrollBar, view);
end
-- Dungeons/Raids
do
local Pad = 0;
local Spacing = 15;
local view = CreateScrollBoxListGridView(4, Pad, Pad, Pad, Pad, Spacing, Spacing);
local function Initializer(button, elementData)
button.name:SetText(elementData.name);
button.bgImage:SetTexture(elementData.buttonImage);
button.instanceID = elementData.instanceID;
button.tooltipTitle = elementData.name;
button.tooltipText = elementData.description;
button.link = elementData.link;
button:Show();
if ( EncounterJournal.localizeInstanceButton ) then
EncounterJournal.localizeInstanceButton(button);
end
local modifiedInstanceInfo = C_ModifiedInstance.GetModifiedInstanceInfoFromMapID(elementData.mapID)
if (modifiedInstanceInfo) then
button.ModifiedInstanceIcon.info = modifiedInstanceInfo;
button.ModifiedInstanceIcon.name = name;
local atlas = button.ModifiedInstanceIcon:GetIconTextureAtlas();
button.ModifiedInstanceIcon.Icon:SetAtlas(atlas, true)
button.ModifiedInstanceIcon:SetSize(button.ModifiedInstanceIcon.Icon:GetSize());
button.ModifiedInstanceIcon:Show();
end
end
view:SetElementInitializer("EncounterInstanceButtonTemplate", Initializer);
ScrollUtil.InitScrollBoxWithScrollBar(self.instanceSelect.ScrollBox, self.instanceSelect.ScrollBar, view);
end
-- Dungeons/Raids description
do
local instance = self.encounter.instance;
local loreScrollingFont = instance.LoreScrollingFont;
loreScrollingFont:SetTextColor(CreateColor(.13, .07, .01));
local scrollBox = loreScrollingFont:GetScrollBox();
local scrollBar = instance.LoreScrollBar;
ScrollUtil.RegisterScrollBoxWithScrollBar(scrollBox, scrollBar);
end
do
EncounterJournal.searchBox:SetSearchResultsFrame(EncounterJournal.searchResults);
EncounterJournal.searchBox:SetScript("OnTextChanged", EncounterJournalSearchBox_OnTextChanged);
EncounterJournal.searchBox:SetScript("OnEditFocusGained", EncounterJournalSearchBox_OnEditFocusGained);
EncounterJournal.searchBox:SetScript("OnHide", EncounterJournalSearchBox_OnHide);
EncounterJournal.searchBox.searchProgress.bar:SetScript("OnUpdate",
EncounterJournalSearchBoxSearchProgressBar_OnUpdate);
end
local homeData = {
name = HOME,
OnClick = function()
if self.selectedTab then
EJ_ContentTab_Select(self.selectedTab);
else
MonthlyActivitiesFrame_OpenFrame();
end
end,
}
NavBar_Initialize(self.navBar, "NavButtonTemplate", homeData, self.navBar.home, self.navBar.overflow);
-- initialize tabs
local instanceSelect = self.instanceSelect;
PanelTemplates_SetNumTabs(self, 5);
EJ_ContentTab_OnClick(self.MonthlyActivitiesTab);
self.maxTabWidth = self:GetWidth() / #self.Tabs;
local tierName = EJ_GetTierInfo(EJ_GetCurrentTier());
UIDropDownMenu_SetText(instanceSelect.tierDropDown, tierName);
-- check if tabs are active
local dungeonInstanceID = EJ_GetInstanceByIndex(1, false);
if( not dungeonInstanceID ) then
EJ_ContentTab_SetEnabled(self.dungeonsTab, false);
end
local raidInstanceID = EJ_GetInstanceByIndex(1, true);
if( not raidInstanceID ) then
EJ_ContentTab_SetEnabled(self.raidsTab, false);
end
-- set the monthly activities frame to open by default if available, or default to Suggested Content
if C_PlayerInfo.IsTravelersLogAvailable() then
MonthlyActivitiesFrame_OpenFrame();
else
EJSuggestFrame_OpenFrame();
end
-- add lock icon to tab if necessary
if AreMonthlyActivitiesRestricted() then
self.MonthlyActivitiesTab:SetText(CreateAtlasMarkup("activities-icon-lock", 17, 22) .. MONTHLY_ACTIVITIES_TAB);
end
end
function EncounterItemTemplate_DividerFrameTipOnEnter(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
GameTooltip:SetText(self.elementData.text, 1, 1, 1);
GameTooltip:AddLine(self.elementData.helpText, nil, nil, nil, true);
GameTooltip:Show();
end
function EncounterJournal_GetLootJournalView()
return EncounterJournal.lootJournalView;
end
function EncounterJournal_SetLootJournalView(view)
local self = EncounterJournal;
local activeViewPanel, inactiveViewPanel = EncounterJournal_GetLootJournalPanels(view);
self.LootJournalViewDropDown:SetParent(activeViewPanel);
self.LootJournalViewDropDown:SetPoint("TOPLEFT", 15, -9);
UIDropDownMenu_SetText(self.LootJournalViewDropDown, view);
-- if no previous view then it's the init, no need to change which frame is shown
if self.lootJournalView then
activeViewPanel:Show();
inactiveViewPanel:Hide();
end
self.lootJournalView = view;
end
function EncounterJournal_GetLootJournalPanels(view)
local self = EncounterJournal;
if not view then
view = self.lootJournalView;
end
if view == LOOT_JOURNAL_POWERS then
return self.LootJournal, self.LootJournalItems;
else
return self.LootJournalItems, self.LootJournal;
end
end
function EncounterJournal_EnableTierDropDown()
local tierName = EJ_GetTierInfo(EJ_GetCurrentTier());
UIDropDownMenu_SetText(EncounterJournal.instanceSelect.tierDropDown, tierName);
UIDropDownMenu_EnableDropDown(EncounterJournal.instanceSelect.tierDropDown);
end
function EncounterJournal_DisableTierDropDown(removeText)
UIDropDownMenu_DisableDropDown(EncounterJournal.instanceSelect.tierDropDown);
if ( removeText ) then
UIDropDownMenu_SetText(EncounterJournal.instanceSelect.tierDropDown, nil);
else
local tierName = EJ_GetTierInfo(EJ_GetCurrentTier());
UIDropDownMenu_SetText(EncounterJournal.instanceSelect.tierDropDown, tierName);
end
end
function EncounterJournal_HasChangedContext(instanceID, instanceType, difficultyID)
if ( instanceType == "none" ) then
-- we've gone from a dungeon to the open world
return EncounterJournal.lastInstance ~= nil;
elseif ( instanceID ~= 0 and (instanceID ~= EncounterJournal.lastInstance or EncounterJournal.lastDifficulty ~= difficultyID) ) then
-- dungeon or difficulty has changed
return true;
end
return false;
end
function EncounterJournal_ResetDisplay(instanceID, instanceType, difficultyID)
if ( instanceType == "none" ) then
EncounterJournal.lastInstance = nil;
EncounterJournal.lastDifficulty = nil;
MonthlyActivitiesFrame_OpenFrame();
else
EJ_ContentTab_Select(EncounterJournal.dungeonsTab:GetID());
EncounterJournal_DisplayInstance(instanceID);
EncounterJournal.lastInstance = instanceID;
-- try to set difficulty to current instance difficulty
if ( EJ_IsValidInstanceDifficulty(difficultyID) ) then
EJ_SetDifficulty(difficultyID);
end
EncounterJournal.lastDifficulty = difficultyID;
end
end
function EncounterJournal_OnShow(self)
self:RegisterEvent("SPELL_TEXT_UPDATE");
if ( tonumber(GetCVar("advJournalLastOpened")) == 0 ) then
SetCVar("advJournalLastOpened", GetServerTime() );
end
MainMenuMicroButton_HideAlert(EJMicroButton);
MicroButtonPulseStop(EJMicroButton);
UpdateMicroButtons();
PlaySound(SOUNDKIT.IG_CHARACTER_INFO_OPEN);
EncounterJournal_LootUpdate();
C_EncounterJournal.OnOpen();
if not self.lootJournalView then
EncounterJournal_SetLootJournalView(LOOT_JOURNAL_POWERS);
end
local instanceSelect = EncounterJournal.instanceSelect;
--automatically navigate to the current dungeon if you are in one;
local mapID = C_Map.GetBestMapForUnit("player");
local instanceID = mapID and EJ_GetInstanceForMap(mapID) or 0;
local _, instanceType, difficultyID = GetInstanceInfo();
if ( EncounterJournal_HasChangedContext(instanceID, instanceType, difficultyID) ) then
EncounterJournal_ResetDisplay(instanceID, instanceType, difficultyID);
EncounterJournal.queuedPortraitUpdate = nil;
elseif ( self.encounter.overviewFrame:IsShown() and EncounterJournal.overviewDefaultRole and not EncounterJournal.encounter.overviewFrame.linkSection ) then
local spec, role;
spec = GetSpecialization();
if (spec) then
role = GetSpecializationRole(spec);
else
role = "DAMAGER";
end
if ( EncounterJournal.overviewDefaultRole ~= role ) then
EncounterJournal_ToggleHeaders(EncounterJournal.encounter.overviewFrame);
end
end
if ( EncounterJournal.queuedPortraitUpdate ) then
-- fixes portraits when switching between fullscreen and windowed mode
EncounterJournal.queuedPortraitUpdate = false;
EncounterJournal_UpdatePortraits();
end
local tierData = GetEJTierData(EJ_GetCurrentTier());
if ( not EncounterJournal.suggestTab:IsEnabled() or EncounterJournal.suggestFrame:IsShown() ) then
tierData = GetEJTierData(EJSuggestTab_GetPlayerTierIndex());
end
instanceSelect.bg:SetAtlas(tierData.backgroundAtlas, true);
local shouldShowPowerTab, powerID = EJMicroButton:ShouldShowPowerTab();
if shouldShowPowerTab then
self.LootJournal:SetPendingPowerID(powerID);
EJ_ContentTab_Select(EncounterJournal.LootJournalTab:GetID());
SetCVarBitfield("closedInfoFrames", LE_FRAME_TUTORIAL_FIRST_RUNEFORGE_LEGENDARY_POWER, true);
elseif EncounterJournal.instanceSelect:IsShown() then
EJ_ContentTab_Select(self.selectedTab);
end
EncounterJournal_CheckAndDisplayLootTab();
EncounterJournal_CheckAndDisplayTradingPostTab();
-- Request raid locks to show the defeated overlay for bosses the player has killed this week.
RequestRaidInfo();
end
function EncounterJournal_CheckAndDisplayTradingPostTab()
EncounterJournal.suggestTab:ClearAllPoints();
if C_PlayerInfo.IsTradingPostAvailable() then
PanelTemplates_ShowTab(EncounterJournal, EncounterJournal.MonthlyActivitiesTab:GetID());
PanelTemplates_SetTabEnabled(EncounterJournal, EncounterJournal.MonthlyActivitiesTab:GetID(), C_PlayerInfo.IsTravelersLogAvailable());
EncounterJournal.suggestTab:SetPoint("LEFT", EncounterJournal.MonthlyActivitiesTab, "RIGHT", 3, 0);
else
PanelTemplates_HideTab(EncounterJournal, EncounterJournal.MonthlyActivitiesTab:GetID());
EncounterJournal.suggestTab:SetPoint("LEFT", EncounterJournal.MonthlyActivitiesTab, "LEFT");
end
end
function EncounterJournal_CheckAndDisplayLootTab()
local instanceSelect = EncounterJournal.instanceSelect;
if EJ_GetCurrentTier() == EJ_TIER_INDEX_SHADOWLANDS then
PanelTemplates_ShowTab(EncounterJournal, EncounterJournal.LootJournalTab:GetID());
else
PanelTemplates_HideTab(EncounterJournal, EncounterJournal.LootJournalTab:GetID());
end
end
function EncounterJournal_OnHide(self)
self:UnregisterEvent("SPELL_TEXT_UPDATE");
UpdateMicroButtons();
PlaySound(SOUNDKIT.IG_CHARACTER_INFO_CLOSE);
self.searchBox:Clear();
EJ_EndSearch();
self.shouldDisplayDifficulty = nil;
C_EncounterJournal.OnClose();
end
function EncounterJournal_IsSuggestTabSelected(self)
return self.selectedTab == self.suggestTab:GetID();
end
function EncounterJournal_IsDungeonTabSelected(self)
return self.selectedTab == self.dungeonsTab:GetID();
end
function EncounterJournal_IsRaidTabSelected(self)
return self.selectedTab == self.raidsTab:GetID();
end
function EncounterJournal_IsLootTabSelected(self)
return self.selectedTab == self.LootJournalTab:GetID();
end
local function EncounterJournal_IsHeaderTypeOverview(headerType)
return headerType == EJ_HTYPE_OVERVIEW;
end
local function EncounterJournal_GetRootAfterOverviews(rootSectionID)
local nextSectionID = rootSectionID;
repeat
local info = C_EncounterJournal.GetSectionInfo(nextSectionID);
local isOverview = info and EncounterJournal_IsHeaderTypeOverview(info.headerType);
if isOverview then
nextSectionID = info.siblingSectionID;
end
until not isOverview;
return nextSectionID;
end
local function EncounterJournal_CheckForOverview(rootSectionID)
local sectionInfo = C_EncounterJournal.GetSectionInfo(rootSectionID);
return sectionInfo and EncounterJournal_IsHeaderTypeOverview(sectionInfo.headerType);
end
local function EncounterJournal_SearchForOverview(instanceID)
local bossIndex = 1;
local _, _, bossID = EJ_GetEncounterInfoByIndex(bossIndex);
while bossID do
local _, _, _, rootSectionID = EJ_GetEncounterInfo(bossID);
if (EncounterJournal_CheckForOverview(rootSectionID)) then
return true;
end
bossIndex = bossIndex + 1;
_, _, bossID = EJ_GetEncounterInfoByIndex(bossIndex);
end
return false;
end
local function EncounterJournal_UpdateSpellText(self, spellID)
if self.encounter.encounterID then
local rootSectionID = select(4, EJ_GetEncounterInfo(self.encounter.encounterID));
if (EncounterJournal_CheckForOverview(rootSectionID)) then
if self.encounter.overviewFrame.spellID == spellID then
local sectionInfo = C_EncounterJournal.GetSectionInfo(rootSectionID);
EncounterJournal_SetBullets(self.encounter.overviewFrame.overviewDescription, sectionInfo.description, false);
end
end
end
-- Overview frames
for overviewIndex, overview in ipairs(self.encounter.overviewFrame.overviews) do
if overview.spellID == spellID then
local sectionInfo = C_EncounterJournal.GetSectionInfo(overview.sectionID);
EncounterJournal_SetDescriptionWithBullets(overview, sectionInfo.description);
end
end
-- Section info
EncounterJournal.encounter.infoFrame.updatingSpells = true;
for headerIndex, header in ipairs(self.encounter.usedHeaders) do
if header.spellID == spellID then
local sectionInfo = C_EncounterJournal.GetSectionInfo(header.myID);
local description = sectionInfo.description:gsub("\|cffffffff(.-)\|r", "%1");
header.description:SetText(description);
if EJ_section_openTable[header.myID] then
EncounterJournal_ToggleHeaders(header);
EncounterJournal_ToggleHeaders(header);
end
end
end
EncounterJournal.encounter.infoFrame.updatingSpells = nil;
end
function EncounterJournal_OnEvent(self, event, ...)
if event == "EJ_LOOT_DATA_RECIEVED" then
local itemID = ...
if itemID and not EJ_IsLootListOutOfDate() then
EncounterJournal_LootCallback(itemID);
if EncounterJournal.searchResults:IsShown() then
EncounterJournal_SearchUpdate();
elseif EncounterJournal.searchBox:IsSearchPreviewShown() then
EncounterJournal_UpdateSearchPreview();
end
else
EncounterJournal_LootUpdate();
end
elseif event == "EJ_DIFFICULTY_UPDATE" then
--fix the difficulty buttons
EncounterJournal_UpdateDifficulty(...);
elseif event == "UNIT_PORTRAIT_UPDATE" then
local unit = ...;
if not unit then
EncounterJournal_UpdatePortraits();
end
elseif event == "PORTRAITS_UPDATED" then
EncounterJournal_UpdatePortraits();
elseif event == "SEARCH_DB_LOADED" then
EncounterJournal_RestartSearchTracking();
elseif event == "UI_MODEL_SCENE_INFO_UPDATED" then
local forceUpdate = true;
EncounterJournal_ShowCreatures(forceUpdate);
elseif event == "SPELL_TEXT_UPDATE" then
local spellID = ...;
EncounterJournal_UpdateSpellText(self, spellID);
end
end
function EncounterJournal_UpdateDifficulty(newDifficultyID)
if IsEJDifficulty(newDifficultyID) then
local difficultyStr = GetEJDifficultyString(newDifficultyID);
EncounterJournal.encounter.info.difficulty:SetText(difficultyStr);
EncounterJournal_Refresh();
end
end
function EncounterJournal_GetCreatureButton(index)
if index > MAX_CREATURES_PER_ENCOUNTER then
return nil;
end
local self = EncounterJournal.encounter.info;
local button = self.creatureButtons[index];
if (not button) then
button = CreateFrame("BUTTON", nil, self, "EncounterCreatureButtonTemplate");
button:SetPoint("TOPLEFT", self.creatureButtons[index-1], "BOTTOMLEFT", 0, 8);
self.creatureButtons[index] = button;
end
return button;
end
function EncounterJournal_FindCreatureButtonForDisplayInfo(displayInfo)
for index, button in ipairs(EncounterJournal.encounter.info.creatureButtons) do
if button.displayInfo == displayInfo then
return button;
end
end
return nil;
end
function EncounterJournal_UpdatePortraits()
if ( EncounterJournal:IsShown() ) then
local creatures = EncounterJournal.encounter.info.creatureButtons;
for i = 1, #creatures do
local button = creatures[i];
if ( button and button:IsShown() ) then
SetPortraitTextureFromCreatureDisplayID(button.creature, button.displayInfo);
else
break;
end
end
local usedHeaders = EncounterJournal.encounter.usedHeaders;
for _, header in pairs(usedHeaders) do
if ( header.button.portrait.displayInfo ) then
SetPortraitTextureFromCreatureDisplayID(header.button.portrait.icon, header.button.portrait.displayInfo);
end
end
else
EncounterJournal.queuedPortraitUpdate = true;
end
end
local infiniteLoopPolice = false; --design might make a tier that has no instances at all sigh
function EncounterJournal_ListInstances()
local instanceSelect = EncounterJournal.instanceSelect;
local tierName = EJ_GetTierInfo(EJ_GetCurrentTier());
UIDropDownMenu_SetText(instanceSelect.tierDropDown, tierName);
NavBar_Reset(EncounterJournal.navBar);
EncounterJournal.encounter:Hide();
instanceSelect:Show();
local dataIndex = 1;
local showRaid = EncounterJournal_IsRaidTabSelected(EncounterJournal);
local instanceID, name, description, _, buttonImage, _, _, _, link, _, mapID = EJ_GetInstanceByIndex(dataIndex, showRaid);
--No instances in this tab
if not instanceID and not infiniteLoopPolice then
--disable this tab and select the other one.
infiniteLoopPolice = true;
if ( showRaid ) then
EJ_ContentTab_SetEnabled(EncounterJournal.raidsTab, false);
EJ_ContentTab_Select(EncounterJournal.dungeonsTab:GetID());
else
EJ_ContentTab_SetEnabled(EncounterJournal.dungeonsTab, false);
EJ_ContentTab_Select(EncounterJournal.raidsTab:GetID());
end
return;
end
infiniteLoopPolice = false;
local dataProvider = CreateDataProvider();
while instanceID ~= nil do
dataProvider:Insert({
instanceID = instanceID,
name = name,
description = description,
buttonImage = buttonImage,
link = link,
mapID = mapID,
});
dataIndex = dataIndex + 1;
instanceID, name, description, _, buttonImage, _, _, _, link = EJ_GetInstanceByIndex(dataIndex, showRaid);
end
EncounterJournal.instanceSelect.ScrollBox:SetDataProvider(dataProvider);
--check if the other tab is empty
local otherInstanceID = EJ_GetInstanceByIndex(1, not showRaid);
--No instances in the other tab
if not otherInstanceID then
--disable the other tab.
if ( showRaid ) then
EJ_ContentTab_SetEnabled(EncounterJournal.dungeonsTab, false);
else
EJ_ContentTab_SetEnabled(EncounterJournal.raidsTab, false);
end
end
end
function EncounterJournalInstanceButton_OnClick(self)
NavBar_Reset(EncounterJournal.navBar);
EncounterJournal_DisplayInstance(EncounterJournal.instanceID);
end
local function EncounterJournal_SetupIconFlags(sectionID, infoHeaderButton)
local iconFlags = C_EncounterJournal.GetSectionIconFlags(sectionID);
local textRightAnchor;
for index, icon in ipairs(infoHeaderButton.icons) do
local iconFlag = iconFlags and iconFlags[index];
icon:SetShown(iconFlag ~= nil);
if iconFlag then
textRightAnchor = icon;
icon:Show();
icon.tooltipTitle = _G["ENCOUNTER_JOURNAL_SECTION_FLAG"..iconFlag];
icon.tooltipText = _G["ENCOUNTER_JOURNAL_SECTION_FLAG_DESCRIPTION"..iconFlag];
EncounterJournal_SetFlagIcon(icon.icon, iconFlag);
end
end
if textRightAnchor then
infoHeaderButton.title:SetPoint("RIGHT", textRightAnchor, "LEFT", -5, 0);
else
infoHeaderButton.title:SetPoint("RIGHT", infoHeaderButton, "RIGHT", -5, 0);
end
end
local function UpdateDifficultyAnchoring(difficultyFrame)
local infoFrame = difficultyFrame:GetParent();
infoFrame.reset:ClearAllPoints();
if difficultyFrame:IsShown() then
infoFrame.reset:SetPoint("RIGHT", difficultyFrame, "LEFT", -10, 0);
else
infoFrame.reset:SetPoint("TOPRIGHT", infoFrame, "TOPRIGHT", -19, -13);
end
end
local function UpdateDifficultyVisibility()
local shouldDisplayDifficulty = select(9, EJ_GetInstanceInfo());
-- As long as the current tab isn't the model tab, which always suppresses the difficulty, then update the shown state.
local info = EncounterJournal.encounter.info;
info.difficulty:SetShown(shouldDisplayDifficulty and (info.tab ~= 4));
UpdateDifficultyAnchoring(info.difficulty);
end
local IconIndexByDifficulty = {
[15] = 3, -- Heroic
[16] = 12, -- Mythic
};
local function GetIconIndexForDifficultyID(difficultyID)
return IconIndexByDifficulty[difficultyID];
end
function EncounterJournal_DisplayInstance(instanceID, noButton)
EJ_HideNonInstancePanels();
local difficultyID = EJ_GetDifficulty();
local self = EncounterJournal.encounter;
EncounterJournal.instanceSelect:Hide();
EncounterJournal.encounter:Show();
EncounterJournal.creatureDisplayID = 0;
EncounterJournal.instanceID = instanceID;
EncounterJournal.encounterID = nil;
EJ_SelectInstance(instanceID);
EncounterJournal_LootUpdate();
EncounterJournal_ClearDetails();
local instanceName, description, bgImage, _, loreImage, buttonImage, dungeonAreaMapID = EJ_GetInstanceInfo();
self.instance.title:SetText(instanceName);
self.instance.titleBG:SetWidth(self.instance.title:GetStringWidth() + 80);
self.instance.loreBG:SetTexture(loreImage);
self.info.instanceTitle:ClearAllPoints();
local iconIndex = GetIconIndexForDifficultyID(difficultyID);