-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInProgressMissions.lua
1622 lines (1464 loc) · 54.5 KB
/
InProgressMissions.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 _TOCVERSION = select(4, GetBuildInfo())
local ADDON_NAME, addon = ...
_G[ADDON_NAME] = addon
addon.frame = addon.frame or CreateFrame("Frame", nil, _G.WorldFrame)
addon.events = addon.events or {}
local MISSION_BUTTON_HEIGHT = 37
local MISSION_ICON_SIZE = MISSION_BUTTON_HEIGHT - 4
local MISSION_REWARD_SIZE = MISSION_BUTTON_HEIGHT * 0.78
local COVENANTMISSION_BUTTONHEIGHT = 64
local FORMAT_DURATION_DAYS = _G.GARRISON_DURATION_DAYS:gsub("([^|]*)|4[^:]+:([^;]+);(.*)", "%1%2%3"):gsub("%%d", "%%.1f")
local FORMAT_DURATION_HOURS = _G.GARRISON_DURATION_HOURS:gsub("([^|]*)|4[^:]+:([^;]+);(.*)", "%1%2%3"):gsub("%%d", "%%.1f")
local FORMAT_DURATION_MINUTES = _G.GARRISON_DURATION_MINUTES
local FORMAT_DURATION_SECONDS = _G.GARRISON_DURATION_SECONDS
local FORMAT_TOOLTIP_LEVEL = _G.GARRISON_MISSION_LEVEL_TOOLTIP or _G.GARRISON_BUILDING_LEVEL_LABEL_TOOLTIP
local FORMAT_TOOLTIP_ITEMLEVEL = _G.GARRISON_MISSION_LEVEL_ITEMLEVEL_TOOLTIP
local FORMAT_ICONINTEXT = "|T%s:0:0:0:0:64:64:5:59:5:59|t"
local FORMAT_LEVEL = "[%d]"
local FORMAT_REWARDNUMS = "%.1f"
local FORMAT_REWARD_DIFFICULTY = ITEM_QUALITY_COLORS[2].hex.." (%s)"..FONT_COLOR_CODE_CLOSE
local FOLLOWER_XP_THRESHOLD = 5000
local TIME_COLORS
local TITLE_COLOR_NORMAL = {0.93, 0.93, 0.9}
local TITLE_COLOR_ALT = {0.65, 0.65, 0.55}
local ORDERHALL_ADDONS = {
["GarrisonMissionManager"] = false,
["OrderHallCommander"] = false,
["RENovate"] = false,
}
local tinsert = tinsert
local GFT = Enum.GarrisonFollowerType
local GarrisonLandingPageReport
local GarrisonLandingPageReportList
local TEXT_LEGION_MISSIONS = _G.EXPANSION_NAME6.." ".._G.GARRISON_MISSIONS
local TEXT_BFA_MISSIONS = _G.EXPANSION_NAME7.." ".._G.GARRISON_MISSIONS
local events = addon.events
function addon:InitDB()
if type(IPMDB) ~= "table" then
IPMDB = {}
end
if IPMDB.enableGarrisonMissions == nil then
IPMDB.enableGarrisonMissions = true
end
if IPMDB.enableLegionMissions == nil then
IPMDB.enableLegionMissions = IPMDB.enableGarrisonMissions
end
if IPMDB.enableBfaMissions == nil then
IPMDB.enableBfaMissions = IPMDB.enableLegionMissions
end
-- if IPMDB.improveCovenantMissionUI == nil then
-- IPMDB.improveCovenantMissionUI = false
-- end
if type(IPMDB.profiles) ~= "table" then
IPMDB.profiles = {}
end
if type(IPMDB.ignores) ~= "table" then
IPMDB.ignores = {}
end
if type(IPMDB.profiles[self.profileName]) ~= "table" then
IPMDB.profiles[self.profileName] = {}
end
end
function addon:SaveInProgressMissions()
self.saved = true
self:InitDB()
if C_Garrison.GetLandingPageGarrisonType() == 0 then
IPMDB.profiles[self.profileName] = nil
return
end
local profile = wipe(IPMDB.profiles[self.profileName])
self:GetMissions(GFT.FollowerType_9_0_GarrisonFollower, profile)
if self.delayedSave then
self.delayedSave = nil
elseif not next(profile) then
self.delayedSave = true
self:QueueSaveInProgressMissions(1.0)
end
self:GetMissions(GFT.FollowerType_8_0_GarrisonFollower, profile)
self:GetMissions(GFT.FollowerType_7_0_GarrisonFollower, profile)
self:GetMissions(GFT.FollowerType_6_0_Boat, profile)
self:GetMissions(GFT.FollowerType_6_0_GarrisonFollower, profile)
if not next(profile) then
IPMDB.profiles[self.profileName] = nil
end
end
local function GetMissionFollowerAbilitiesInfo(mission)
local isAutoCombatant = mission.followerTypeID == GFT.FollowerType_9_0_GarrisonFollower -- Shadowlands
local result = {}
for i, id in ipairs(mission.followers) do
local info = C_Garrison.GetFollowerInfo(id)
if info then
info.abilities = {}
if isAutoCombatant then
local spells = C_Garrison.GetFollowerAutoCombatSpells(info.followerID, info.level or 1)
for k, spell in ipairs(spells or {}) do
tinsert(info.abilities, 1, spell.icon)
end
else
for k, ability in ipairs(C_Garrison.GetFollowerAbilities(info.followerID)) do
tinsert(info.abilities, ability.id)
end
end
result[id] = info
end
end
return result
end
do
local function GetCharName(charText)
local name, realm = charText:match("([^%p]+)|?r?-?(.*)", 11)
return name or _G.UNKNOWN, realm or _G.FRIENDS_LIST_REALM
end
local function CompareMissionName(m1, m2)
local name1, realm1 = GetCharName(m1.charText)
local name2, realm2 = GetCharName(m2.charText)
if name1 == name2 then
if realm1 == realm2 then
if m1.missionEndTime == m2.missionEndTime then
return m1.name < m2.name
-- return strcmputf8i(m1.name, m2.name) < 0
else
return (m1.missionEndTime or 0) < (m2.missionEndTime or 0)
end
else
return realm1 < realm2
-- return strcmputf8i(realm1, realm2) < 0
end
else
return name1 < name2
-- return strcmputf8i(name1, name2) < 0
end
end
local function CompareMissionTime(m1, m2)
if (m1.followerTypeID == m2.followerTypeID) and (m1.followerTypeID > GFT.FollowerType_6_0_Boat) then
if (m1.missionEndTime or 0) == (m2.missionEndTime or 0) then
return CompareMissionName(m1, m2)
else
return (m1.missionEndTime or 0) < (m2.missionEndTime or 0)
end
elseif (m1.followerTypeID < GFT.FollowerType_7_0_GarrisonFollower) and (m2.followerTypeID < GFT.FollowerType_7_0_GarrisonFollower) then
return (m1.missionEndTime or 0) < (m2.missionEndTime or 0)
else
return m1.followerTypeID > m2.followerTypeID
end
end
function addon:UpdateMissions()
local garrisonType = C_Garrison.GetLandingPageGarrisonType()
wipe(self.missions)
if garrisonType == Enum.GarrisonType.Type_9_0_Garrison then
self:GetMissions(GFT.FollowerType_9_0_GarrisonFollower, self.missions, true)
end
if garrisonType == Enum.GarrisonType.Type_8_0_Garrison or IPMDB.enableBfaMissions or C_Garrison.IsPlayerInGarrison(Enum.GarrisonType.Type_8_0_Garrison) then
self:GetMissions(GFT.FollowerType_8_0_GarrisonFollower, self.missions, true)
end
if garrisonType == Enum.GarrisonType.Type_7_0_Garrison or IPMDB.enableLegionMissions or C_Garrison.IsPlayerInGarrison(Enum.GarrisonType.Type_7_0_Garrison) then
self:GetMissions(GFT.FollowerType_7_0_GarrisonFollower, self.missions, true)
end
if garrisonType == Enum.GarrisonType.Type_6_0_Garrison or IPMDB.enableGarrisonMissions or C_Garrison.IsPlayerInGarrison(Enum.GarrisonType.Type_6_0_Garrison) then
self:GetMissions(GFT.FollowerType_6_0_Boat, self.missions, true)
self:GetMissions(GFT.FollowerType_6_0_GarrisonFollower, self.missions, true)
end
self:UpdateInProgressTabText()
end
function addon:UpdateAltMissions()
self.altMissions = wipe(self.altMissions or {})
for name, missions in pairs(IPMDB.profiles) do
if name ~= self.profileName and not IPMDB.ignores[name] then
for i, mission in ipairs(missions) do
mission.followerTypeID = mission.followerTypeID or 0
if mission.followerTypeID >= GFT.FollowerType_9_0_GarrisonFollower or (mission.followerTypeID == GFT.FollowerType_8_0_GarrisonFollower and IPMDB.enableBfaMissions) or (mission.followerTypeID == GFT.FollowerType_7_0_GarrisonFollower and IPMDB.enableLegionMissions) or (mission.followerTypeID < GFT.FollowerType_7_0_GarrisonFollower and IPMDB.enableGarrisonMissions) then
if type(mission) == "table" and type(mission.charText) == "string" then
tinsert(self.altMissions, mission)
end
end
end
end
end
table.sort(self.altMissions, IPMDB.sortMethod == "time" and CompareMissionTime or CompareMissionName)
self:UpdateInProgressTabText()
end
function addon:GetMissions(followerType, dest, sort)
local isAutoCombatant = followerType == GFT.FollowerType_9_0_GarrisonFollower -- Shadowlands
local temp = C_Garrison.GetInProgressMissions(followerType)
if not temp then return end
for k, mission in pairs(temp) do
if type(mission) == "table" then
mission.isAltMission = false
mission.description = ""
mission.charText = self.playerNameText.."-"..GetRealmName()
mission.followerInfo = GetMissionFollowerAbilitiesInfo(mission)
-- mission.followerInfo = {}
-- for i, id in ipairs(mission.followers) do
-- local info = C_Garrison.GetFollowerInfo(id)
-- if info then
-- info.abilities = {}
-- if isAutoCombatant then
-- local spells = C_Garrison.GetFollowerAutoCombatSpells(info.followerID, info.level or 1)
-- for k, spell in ipairs(spells or {}) do
-- tinsert(info.abilities, 1, spell.icon)
-- end
-- else
-- for k, ability in ipairs(C_Garrison.GetFollowerAbilities(info.followerID)) do
-- tinsert(info.abilities, ability.id)
-- end
-- end
-- mission.followerInfo[id] = info
-- end
-- end
mission.successChance = C_Garrison.GetMissionSuccessChance(mission.missionID)
if isAutoCombatant then
mission.encounterIconInfo = C_Garrison.GetMissionEncounterIconInfo(mission.missionID)
end
end
end
if sort then
table.sort(temp, type(sort) == "function" and sort or CompareMissionTime)
end
for k, mission in ipairs(temp) do
tinsert(dest, mission)
end
end
end
local function FormatRewardNumbers(value)
if value > 999 then
value = FORMAT_REWARDNUMS:format(value / 1000)
if string.sub(value, -2) == ".0" then
value = string.sub(value, 1, -3)
end
value = value.."k"
end
return value
--return BreakUpLargeNumbers(value)
end
local function Reward_Update(Reward, info)
Reward.Quantity:Hide()
Reward.IconBorder:Hide()
Reward.Success:Hide()
Reward.bonusAbilityID = info.bonusAbilityID
Reward.title = nil
Reward.tooltip = nil
Reward.itemID = nil
Reward.itemLink = nil
Reward.currencyID = nil
Reward.currencyQuantity = nil
if (info.itemID or info.itemLink) then
Reward.itemID = info.itemID
Reward.itemLink = info.itemLink
local itemTexture = select(10, GetItemInfo(info.itemID))
Reward.Icon:SetTexture(itemTexture)
if ( info.quantity > 1 ) then
Reward.Quantity:SetText(info.quantity)
Reward.Quantity:Show()
else
local quality, itemLevel = select(3, GetItemInfo(info.itemLink or info.itemID))
if ( itemLevel and itemLevel > 500 ) then
Reward.Quantity:SetText(ITEM_QUALITY_COLORS[quality].hex..itemLevel..FONT_COLOR_CODE_CLOSE)
Reward.Quantity:Show()
end
end
--Reward.tooltip = nil
local quality = select(3, GetItemInfo(info.itemLink or info.itemID))
local c = BAG_ITEM_QUALITY_COLORS[quality] or BAG_ITEM_QUALITY_COLORS[1]
Reward.IconBorder:SetVertexColor(c.r, c.g, c.b)
Reward.IconBorder:Show()
else
Reward.Icon:SetTexture(info.icon)
Reward.title = info.title
if (info.currencyID and info.quantity) then
if (info.currencyID == 0) then
Reward.tooltip = GetMoneyString(info.quantity)
Reward.Quantity:SetText(BreakUpLargeNumbers(math.floor(info.quantity / COPPER_PER_GOLD)))
Reward.Quantity:Show()
else
Reward.currencyID = info.currencyID
Reward.tooltip = info.tooltip
Reward.currencyQuantity = info.quantity
-- local currencyTexture = C_CurrencyInfo.GetBasicCurrencyInfo(info.currencyID).icon
local currencyName, currencyTexture, currencyQuantity, currencyQuality = CurrencyContainerUtil.GetCurrencyContainerInfo(info.currencyID, info.quantity, info.title, info.icon, nil)
Reward.tooltip = BreakUpLargeNumbers(info.quantity).." |T"..currencyTexture..":0:0:0:-1|t "
Reward.Quantity:SetText(info.quantity)
local c = BAG_ITEM_QUALITY_COLORS[currencyQuality]
if c then
Reward.IconBorder:SetVertexColor(c.r, c.g, c.b)
Reward.IconBorder:Show()
end
Reward.Quantity:Show()
end
elseif (info.bonusAbilityID) then
Reward.bonusAbilityID = info.bonusAbilityID
Reward.bonusAbilityDuration = info.duration
Reward.bonusAbilityIcon = info.icon
Reward.bonusAbilityName = info.name
Reward.bonusAbilityDescription = info.description
Reward.duration = info.duration
Reward.icon = info.icon
Reward.name = info.name
Reward.description = info.description
else
Reward.tooltip = info.tooltip
if ( info.followerXP ) then
Reward.Quantity:SetText(ITEM_QUALITY_COLORS[info.followerXP >= FOLLOWER_XP_THRESHOLD and 2 or 1].hex..FormatRewardNumbers(info.followerXP)..FONT_COLOR_CODE_CLOSE)
Reward.Quantity:Show()
end
end
end
end
local function Rewards_Update(button, item)
local rewardIndex = 0
if item.overmaxRewards and item.hasBonusEffect then
if item.successChance and item.successChance > 100 then
for rewardId, reward in pairs(item.overmaxRewards) do
rewardIndex = rewardIndex + 1
local Reward = button.Rewards[rewardIndex]
Reward_Update(Reward, reward)
Reward.Success:SetFormattedText("%d%%", item.successChance - 100)
Reward.Success:Show()
Reward:Show()
-- Reward:SetAlpha((item.successChance - 100) / 100)
end
end
end
if item.rewards then
for rewardId, reward in pairs(item.rewards) do
rewardIndex = rewardIndex + 1
local Reward = button.Rewards[rewardIndex]
Reward_Update(Reward, reward)
Reward:Show()
-- Reward:SetAlpha(1)
end
end
for i = (rewardIndex + 1), #button.Rewards do
button.Rewards[i]:Hide()
end
return rewardIndex
end
local function GetFollowerIndicator(item)
if not item.numFollowers then return end
local result = ""
local id, info
for i = 1, item.numFollowers do
id = item.followers[i]
info = nil
if id and type(item.followerInfo) == "table" then
info = item.followerInfo[id]
elseif id then
info = C_Garrison.GetFollowerInfo(id)
end
if info and info.quality ~= 4 and not info.isTroop then
result = result..ITEM_QUALITY_COLORS[info.quality or 1].hex.._G.RANGE_INDICATOR..FONT_COLOR_CODE_CLOSE
else
result = result.._G.RANGE_INDICATOR
end
end
return result
end
local function MissionButton_SetLayout(button, isTabProgress)
if isTabProgress then
button.Reward1:SetPoint("RIGHT", -68, 0)
button.Status:SetPoint("BOTTOMRIGHT", -8, 3)
else
button.CompletedCheck:Hide()
button.CompletedOverlay:Hide()
button.NumFollowers:Hide()
button.Reward1:SetPoint("RIGHT", -5, 0)
button.Title:SetTextColor(unpack(TITLE_COLOR_NORMAL))
button.Level:SetTextColor(unpack(TITLE_COLOR_NORMAL))
button.BG:SetVertexColor(1, 1, 1)
end
end
local function MissionButton_Update(button, item)
local baseTime = GetServerTime()
local stopUpdate = true
if item.missionEndTime then
item.isComplete = (item.missionEndTime - baseTime) < 0
end
local bgName
if (item.isBuilding) then
bgName = "GarrLanding-Building-"
button.Status:SetText(GARRISON_LANDING_STATUS_BUILDING)
elseif (item.followerTypeID == GFT.FollowerType_6_0_Boat) then
bgName = "GarrLanding-ShipMission-"
else
bgName = "GarrLanding-Mission-"
button.Status:SetText(nil)
end
button.Status:SetShown(item.isBuilding and not item.isComplete)
bgName = bgName.."InProgress"
button.Title:SetText(item.name)
if (item.isComplete) then
button.CompletedCheck:Show()
button.CompletedOverlay:Show()
if item.isBuilding then
button.MissionType:SetText(GARRISON_LANDING_BUILDING_COMPLEATE)
else
button.MissionType:SetText(item.isAltMission and (item.charText or _G.UNKNOWN) or addon.playerNameText)
end
button.Title:SetWidth(290)
else -- in progress
button.CompletedCheck:Hide()
button.CompletedOverlay:Hide()
if (item.isBuilding) then
button.MissionType:SetText(GARRISON_BUILDING_IN_PROGRESS.." - "..GARRISON_BUILDING_LEVEL_LABEL_TOOLTIP:format(item.buildingLevel))
button.TimeLeft:SetText(item.timeLeft)
button.TimeLeft:SetTextColor(unpack(TIME_COLORS[4]))
else
button.MissionType:SetText(item.isAltMission and (item.charText or _G.UNKNOWN) or addon.playerNameText)
t = (item.missionEndTime or 0) - baseTime
if t > 107999 then -- 30hr
button.TimeLeft:SetFormattedText(FORMAT_DURATION_DAYS, t / 86400)
elseif t > 5459 then
button.TimeLeft:SetFormattedText(FORMAT_DURATION_HOURS, t / 3600)
elseif t > 59 then
button.TimeLeft:SetFormattedText(FORMAT_DURATION_MINUTES, t / 60)
else
button.TimeLeft:SetFormattedText(FORMAT_DURATION_SECONDS, t)
end
button.TimeLeft:SetTextColor(unpack(TIME_COLORS[not t and 1 or t > 18000 and 2 or t > 5459 and 3 or t > 599 and 4 or t > 59 and 5 or 6]))
end
button.Title:SetWidth(322 - button.TimeLeft:GetWidth())
stopUpdate = false
end
button.TimeLeft:SetShown(not item.isComplete)
if item.followerTypeID == GFT.FollowerType_8_0_GarrisonFollower then
button.Level:SetText(item.level)
elseif item.followerTypeID == GFT.FollowerType_9_0_GarrisonFollower then
button.Level:SetText(nil)
else
button.Level:SetText(item.iLevel and item.iLevel > 0 and item.iLevel or item.followerTypeID ~= GFT.FollowerType_6_0_Boat and item.level or nil)
end
if item.typeAtlas then
button.MissionTypeIcon:SetAtlas(item.typeAtlas)
elseif item.typeIcon then
button.MissionTypeIcon:SetTexture(item.typeIcon)
else
button.MissionTypeIcon:SetTexture(nil)
end
button.MissionTypeIcon:SetShown(not item.isBuilding and item.followerTypeID < GFT.FollowerType_9_0_GarrisonFollower)
if item.followerTypeID == GFT.FollowerType_9_0_GarrisonFollower then
button.NumFollowers:Hide()
else
button.NumFollowers:SetText(GetFollowerIndicator(item))
button.NumFollowers:Show()
end
button.EncounterIcon:SetShown(item.followerTypeID == GFT.FollowerType_9_0_GarrisonFollower)
if item.followerTypeID == GFT.FollowerType_9_0_GarrisonFollower then
if item.encounterIconInfo then
button.EncounterIcon:SetEncounterInfo(item.encounterIconInfo)
else
button.EncounterIcon:SetEncounterInfo(C_Garrison.GetMissionEncounterIconInfo(item.missionID))
end
end
button.BG:SetAtlas(bgName, true)
if item.isAltMission then
button.Title:SetTextColor(unpack(TITLE_COLOR_ALT))
button.Level:SetTextColor(unpack(TITLE_COLOR_ALT))
else
button.Title:SetTextColor(unpack(TITLE_COLOR_NORMAL))
button.Level:SetTextColor(unpack(TITLE_COLOR_NORMAL))
end
if item.followerTypeID == GFT.FollowerType_6_0_Boat then
button.BG:SetVertexColor(0.9, 0.9, 1)
else
button.BG:SetVertexColor(1, 1, 1)
end
Rewards_Update(button, item)
end
local function GarrisonLandingPageReport_SetElementInitializer()
local view = GarrisonLandingPageReportList.ScrollBox:GetView()
view:GetPadding():SetRight(GarrisonLandingPageReportList.ScrollBar:GetWidth())
-- view.templateInfos["GarrisonLandingPageReportMissionTemplate"] = nil
view.elementExtent = nil
view:SetElementInitializer("GarrisonLandingPageReportMissionTemplateIPM", function(button, elementData)
if GarrisonLandingPageReport.selectedTab == GarrisonLandingPageReport.InProgress then
MissionButton_Update(button, elementData)
else
GarrisonLandingPageReportList_InitButtonAvailable(button, elementData)
if _G.MasterPlan then
button.Status:Hide()
else
local reward = (button.Reward3:IsShown() and button.Reward3) or (button.Reward2:IsShown() and button.Reward2) or (button.Reward1:IsShown() and button.Reward1)
button.Status:SetPoint("BOTTOMRIGHT", reward, "BOTTOMLEFT", -4, 0)
button.Status:SetText(elementData.offerEndTime and RAID_INSTANCE_EXPIRES:format(elementData.offerTimeRemaining) or nil)
button.Status:Show()
end
end
end)
end
local function GarrisonLandingPageReportList_Update(fullUpdate)
local items = GarrisonLandingPageReportList.items
if not items then return end
if #items == 0 then
local emptyMissionText = GarrisonLandingPage.garrTypeID == Enum.GarrisonType.Type_9_0_Garrison and COVENANT_MISSIONS_EMPTY_IN_PROGRESS or GARRISON_EMPTY_IN_PROGRESS_LIST;
GarrisonLandingPageReportList.EmptyMissionText:SetText(emptyMissionText);
else
GarrisonLandingPageReportList.EmptyMissionText:SetText(nil);
end
local dataProvider = addon.scrollBox:GetDataProvider();
if fullUpdate or not dataProvider or #items ~= dataProvider:GetSize() then
dataProvider = CreateDataProvider(items);
addon.scrollBox:SetDataProvider(dataProvider, ScrollBoxConstants.RetainScrollPosition);
else
for _, button in pairs(addon.scrollBox:GetView():GetFrames()) do
MissionButton_Update(button, button:GetMission())
end
end
end
local function GarrisonLandingPageReportList_UpdateItems()
addon:UpdateMissions()
local isTabProgress = GarrisonLandingPageReport.selectedTab == GarrisonLandingPageReport.InProgress
if isTabProgress then
else
addon:HideMenu()
end
local garrTypeID = GarrisonLandingPage.garrTypeID;
if not garrTypeID then return end
local availableMissions = C_Garrison.GetAvailableMissions(GetPrimaryGarrisonFollowerType(garrTypeID));
GarrisonLandingPageReportList.AvailableItems = GarrisonLandingPageReportMission_FilterOutCombatAllyMissions(availableMissions);
Garrison_SortMissions(GarrisonLandingPageReportList.AvailableItems);
local items = GarrisonLandingPageReportList.items or {}
wipe(items)
for _, mission in ipairs(addon.missions) do
tinsert(items, CopyTable(mission, true))
end
for _, mission in ipairs(addon.altMissions) do
mission.isAltMission = true
tinsert(items, CopyTable(mission, true))
end
GarrisonLandingPageReportList.items = items;
local availableString = garrTypeID == Enum.GarrisonType.Type_9_0_Garrison and COVENANT_MISSIONS_AVAILABLE or GARRISON_LANDING_AVAILABLE;
GarrisonLandingPageReport.Available.Text:SetFormattedText(availableString, #GarrisonLandingPageReportList.AvailableItems);
if ( GarrisonLandingPageReport.selectedTab == GarrisonLandingPageReport.InProgress ) then
GarrisonLandingPageReportList_Update(true);
else
GarrisonLandingPageReportList_UpdateAvailable();
end
end
local function MakeIcon(icon, rightText)
local result = FORMAT_ICONINTEXT:format(icon or 134400)
if rightText then
return result.." "..rightText
else
return result
end
end
local function AddIcon(text1, icon, text2)
if text1 then
return text1.." "..MakeIcon(icon, text2)
else
return MakeIcon(icon, text2)
end
end
local function QualityColorText(text, quality)
if quality then
return ITEM_QUALITY_COLORS[quality].hex..text..FONT_COLOR_CODE_CLOSE
else
return text
end
end
local function AddRewardText(item, rewardType)
for id, reward in pairs(item[rewardType]) do
if (reward.quality) then
GameTooltip:AddLine(QualityColorText(reward.title or _G.UNKNOWN, reward.quality + 1))
elseif (reward.itemID) then
local itemName, _, itemQuality, _, _, _, _, _, _, itemTexture = GetItemInfo(reward.itemID)
if itemName then
itemName = MakeIcon(itemTexture, QualityColorText(itemName, itemQuality))
-- local difficulty = itemDifficulty[reward.itemID]
-- if difficulty then
-- itemName = itemName..FORMAT_REWARD_DIFFICULTY:format(difficulty)
-- end
local quantity = reward.quantity and reward.quantity > 1 and FLAG_COUNT_TEMPLATE:format(reward.quantity) or ""
if quantity then
itemName = itemName.." "..quantity
end
GameTooltip:AddLine(itemName, 1, 1, 1)
end
elseif (reward.followerXP) then
GameTooltip:AddLine(QualityColorText(GARRISON_REWARD_XP_FORMAT:format(BreakUpLargeNumbers(reward.followerXP)), reward.followerXP >= FOLLOWER_XP_THRESHOLD and 2 or 1))
elseif (reward.currencyID and reward.quantity) then
if (reward.currencyID == 0) then
GameTooltip:AddLine(GetMoneyString(reward.quantity), 1, 1, 1)
else
local currencyInfo = C_CurrencyInfo.GetBasicCurrencyInfo(reward.currencyID)
if currencyInfo then
GameTooltip:AddLine(MakeIcon(currencyInfo.icon)..QualityColorText(" "..currencyInfo.name.." ", currencyInfo.quality or 1)..FLAG_COUNT_TEMPLATE:format(reward.quantity), 1, 1, 1)
else
GameTooltip:AddLine(_G.UNKNOWN.." ".._G.CURRENCY.." ("..reward.currencyID..") "..FLAG_COUNT_TEMPLATE:format(reward.quantity), 1, 1, 1)
end
end
else
GameTooltip:AddLine(reward.title, 1, 1, 1)
end
end
end
local function SetupMissionInfoTooltip(item, anchorFrame)
if _G.CovenantMissionFrame and _G.CovenantMissionFrameFollowers:IsVisible() then
return
end
if anchorFrame then
GameTooltip:SetOwner(anchorFrame, "ANCHOR_BOTTOMRIGHT", 2, anchorFrame:GetHeight() * 2)
GameTooltip:ClearLines()
else
GameTooltip:ClearLines()
end
if ( item.isBuilding ) then
GameTooltip:SetText(item.name);
GameTooltip:AddLine(string.format(GARRISON_BUILDING_LEVEL_LABEL_TOOLTIP, item.buildingLevel), 1, 1, 1);
if(item.isComplete) then
GameTooltip:AddLine(COMPLETE, 1, 1, 1);
else
GameTooltip:AddLine(tostring(item.timeLeft), 1, 1, 1);
end
GameTooltip:Show();
return;
end
local isAutoCombatant = item.followerTypeID == GFT.FollowerType_9_0_GarrisonFollower -- Shadowlands
GameTooltip:SetText(item.isComplete and ERR_QUEST_OBJECTIVE_COMPLETE_S:format(item.name) or item.name)
-- level
local color = item.isRare and ITEM_QUALITY_COLORS[3] or ITEM_QUALITY_COLORS[1]
if isAutoCombatant then
GameTooltip:AddLine(format(FORMAT_TOOLTIP_LEVEL, item.missionScalar), color.r, color.g, color.b)
elseif item.followerTypeID == GFT.FollowerType_6_0_Boat then
else
if item.iLevel and item.iLevel > 0 then
GameTooltip:AddLine(format(FORMAT_TOOLTIP_ITEMLEVEL, item.level, item.iLevel), color.r, color.g, color.b)
elseif item.level then
GameTooltip:AddLine(format(FORMAT_TOOLTIP_LEVEL, item.level), color.r, color.g, color.b)
end
end
-- time
if item.isComplete then
if item.missionEndTime then
GameTooltip:AddLine(DATE_COMPLETED:format(date("%a,%H:%M", item.missionEndTime)), 1, 1, 1)
end
else
if item.missionEndTime then
GameTooltip:AddLine(COMPLETE..": "..date("%a,%H:%M", item.missionEndTime), 1, 1, 1)
end
end
local successChance = item.successChance or item.missionID and C_Garrison.GetMissionSuccessChance(item.missionID)
if next(item.rewards) then
GameTooltip:AddLine(" ")
local caption = REWARDS
if not isAutoCombatant and successChance then
caption = caption..(" (%d%%)"):format(math.min(successChance, 100))
end
GameTooltip:AddLine(caption)
AddRewardText(item, "rewards")
if item.overmaxRewards and next(item.overmaxRewards) and item.hasBonusEffect then
local caption = BONUS_REWARDS
if successChance and successChance > 100 then
caption = caption..(" (%d%%)"):format(successChance - 100)
end
GameTooltip:AddLine(caption)
AddRewardText(item, "overmaxRewards")
end
end
if (item.followers ~= nil) then
GameTooltip:AddLine(" ");
GameTooltip:AddLine(isAutoCombatant and _G.COVENANT_MISSIONS_FOLLOWERS or item.followerTypeID == GFT.FollowerType_6_0_Boat and _G.GARRISON_SHIPYARD_FOLLOWERS or _G.GARRISON_FOLLOWERS)
local id, info
local leftText, rightText
local icon
local followerInfo = item.followerInfo or GetMissionFollowerAbilitiesInfo(item)
for i = 1, #(item.followers) do
id = item.followers[i]
info = type(followerInfo) == "table" and followerInfo[id] or nil
if type(info) == "table" then
leftText = nil
rightText = nil
if isAutoCombatant then
leftText = MakeIcon(info.portraitIconID)..QualityColorText(FORMAT_LEVEL:format(info.level), info.quality or 2).." "..info.name
for i, icon in ipairs(info.abilities) do
rightText = AddIcon(rightText, icon)
end
elseif (info.followerTypeID >= GFT.FollowerType_7_0_GarrisonFollower) and info.abilities then
leftText = MakeIcon(info.portraitIconID)
if info.isTroop then
leftText = leftText.." "..QualityColorText(info.name, info.quality)
else
if info.iLevel then
leftText = leftText..QualityColorText(FORMAT_LEVEL:format(info.iLevel), info.quality or 2)
end
leftText = AddIcon(leftText, C_Garrison.GetFollowerAbilityIcon(info.abilities[1]), info.name)
end
for i = 2, 6 do
if info.abilities[i] then
icon = C_Garrison.GetFollowerAbilityIcon(info.abilities[i])
if icon then
rightText = AddIcon(rightText, icon)
end
end
end
elseif info.followerTypeID == GFT.FollowerType_6_0_Boat then
leftText = ""
if type(info.abilities) == "table" then
for k, abilityID in ipairs(info.abilities) do
if C_Garrison.GetFollowerAbilityIsTrait(abilityID) then
leftText = leftText..MakeIcon(C_Garrison.GetFollowerAbilityIcon(abilityID))
else
rightText = AddIcon(rightText, C_Garrison.GetFollowerAbilityIcon(abilityID))
end
end
end
leftText = leftText.." "..QualityColorText(info.name, info.quality or 2)
else
leftText = MakeIcon(info.portraitIconID)..QualityColorText(FORMAT_LEVEL:format(info.iLevel or info.level or 0), info.quality or 2).." "..info.name
if type(info.abilities) == "table" then
for k, abilityID in ipairs(info.abilities) do
if type(abilityID) == "number" and not C_Garrison.GetFollowerAbilityIsTrait(abilityID) then
rightText = MakeIcon(select(3, C_Garrison.GetFollowerAbilityCounterMechanicInfo(abilityID)), rightText)
end
end
end
end
GameTooltip:AddDoubleLine(leftText or _G.UNKNOWN, rightText or "", 1, 1, 1, 1, 1, 1)
else
GameTooltip:AddLine(_G.UNKNOWN.."."..id, 1, 1, 1)
end
end
end
return true
-- GameTooltip:Show();
end
local function GarrisonMissionButton_SetInProgressTooltip(missionInfo, showRewards)
SetupMissionInfoTooltip(missionInfo)
end
local function FlipTexture(texture, horizontal)
local ULx,ULy,LLx,LLy,URx,URy,LRx,LRy = texture:GetTexCoord()
if horizontal then
texture:SetTexCoord(URx, URy, LRx, LRy, ULx, ULy, LLx, LLy)
else
texture:SetTexCoord(LLx, LLy,ULx, ULy, LRx, LRy, URx, URy)
end
end
-- local function ListScroll_OnScroll(self)
-- if GameTooltip:IsVisible() then
-- GameTooltip:Hide()
-- for k, button in pairs(addon.listScroll.buttons) do
-- if button:IsVisible() and button:IsMouseOver() then
-- GarrisonLandingPageReportMission_OnEnter(button)
-- break
-- end
-- end
-- end
-- end
local function CreateQuantityFont()
if not _G.GarrisonReportFontRewardQuantity then
local font = CreateFont("GarrisonReportFontRewardQuantity")
local name, height, flags = _G.NumberFontNormalSmall:GetFont()
if flags then
local t = {}
for w in string.gmatch(flags, "%s*(%a+),?") do
if w ~= "MONOCHROME" then tinsert(t, w) end
end
flags = table.concat(t, ", ")
end
font:SetFont(name, 11.5, flags)
end
end
local function MissionButton_GetMission(button)
return button:GetElementData()
-- local elementData = button:GetElementData()
-- if type(elementData) == "number" then
-- return GarrisonLandingPageReportList.items[elementData]
-- else
-- return elementData
-- end
end
local function MissionButton_OnShow(button)
MissionButton_SetLayout(button, GarrisonLandingPageReport.selectedTab == GarrisonLandingPageReport.InProgress)
end
local function MissionButton_OnEnter(button, mouseButton)
if GarrisonLandingPageReport.selectedTab ~= GarrisonLandingPageReport.InProgress then
return GarrisonLandingPageReportMission_OnEnter(button, mouseButton)
end
local item = button:GetMission()
if not item then return end
if SetupMissionInfoTooltip(item, button) then
if button.UpdateTooltip then
button.UpdateTooltip = nil
else
button.UpdateTooltip = MissionButton_OnEnter
end
GameTooltip:Show()
end
end
local function MissionButton_OnClick(button, mouseButton)
if mouseButton == "LeftButton" and IsModifiedClick("CHATLINK") then
local item = button:GetMission()
if not item then return end
local missionLink = C_Garrison.GetMissionLink(item.missionID);
if missionLink then
ChatEdit_InsertLink(missionLink);
end
end
end
local function MissionButton_OnMouseUp(button, mouseButton)
if GarrisonLandingPageReport.selectedTab ~= GarrisonLandingPageReport.InProgress then return end
if mouseButton == "RightButton" then
addon:CreateMenu()
local anchor = addon.scrollBox
local uiScale, x, y = _G.UIParent:GetEffectiveScale(), GetCursorPosition()
ToggleDropDownMenu(1, nil, addon.menu, anchor:GetName(), x / uiScale - 35, y / uiScale - 5)
end
end
local function MissionButtonReward_OnEnter(frame)
if (frame.bonusAbilityID) then
frame.UpdateTooltip = nil;
local tooltip = GarrisonBonusAreaTooltip;
GarrisonBonusArea_Set(tooltip.BonusArea, GARRISON_BONUS_EFFECT_TIME_ACTIVE, frame.bonusAbilityDuration, frame.bonusAbilityIcon, frame.bonusAbilityName, frame.bonusAbilityDescription);
tooltip:ClearAllPoints();
tooltip:SetPoint("BOTTOMLEFT", frame, "TOPRIGHT");
tooltip:SetHeight(tooltip.BonusArea:GetHeight());
tooltip:Show();
return;
end
local info = frame.info or frame
if info then
GameTooltip:SetOwner(frame, "ANCHOR_RIGHT")
frame.UpdateTooltip = MissionButtonReward_OnEnter
if info.itemLink then
GameTooltip:SetHyperlink(info.itemLink)
elseif info.itemID then
GameTooltip:SetItemByID(info.itemID)
elseif info.currencyID then
if info.currencyID > 0 then
GameTooltip:SetCurrencyByID(info.currencyID)
else -- Money
GameTooltip:SetText(info.title)
GameTooltip:AddLine(GetMoneyString(info.quantity), 1, 1, 1)
GameTooltip:Show()
end
else
if info.title then
GameTooltip:SetText(info.title)
end
if info.tooltip then
GameTooltip:AddLine(info.tooltip, 1, 1, 1, true)
end
GameTooltip:Show()
end
end
end
local function MissionButtonReward_OnLeave(frame)
frame.UpdateTooltip = nil
GarrisonBonusAreaTooltip:Hide()
GameTooltip:Hide()
end
function addon:MissionButton_OnLoad(button)
-- button.MissionTypeBG = button:CreateTexture(nil, "BACKGROUND", "Spellbook-TextBackground", 1)
button.MissionTypeBG = button:CreateTexture(nil, "BACKGROUND")
button.MissionTypeBG:ClearAllPoints()
button.MissionTypeBG:SetPoint("TOPLEFT", button.MissionType, -5, 4)
button.MissionTypeBG:SetPoint("BOTTOMLEFT", button.MissionType, -5, -2)
button.MissionTypeBG:SetWidth(130)
button.MissionTypeBG:SetBlendMode("BLEND")
button.MissionTypeBG:SetVertexColor(0, 0, 0, 0.6)
for i, reward in ipairs(button.Rewards) do
reward:SetScript("OnEnter", MissionButtonReward_OnEnter)
reward:SetScript("OnLeave", MissionButtonReward_OnLeave)
end
FlipTexture(button.MissionTypeBG)
CreateQuantityFont()
for i, reward in ipairs(button.Rewards) do
reward.Quantity:SetFontObject("GarrisonReportFontRewardQuantity")
reward.Success:SetFontObject("GarrisonReportFontRewardQuantity")
end
button.GetMission = MissionButton_GetMission
button:SetScript("OnShow", MissionButton_OnShow)
button:SetScript("OnEnter", MissionButton_OnEnter)
button:SetScript("OnLeave", MissionButtonReward_OnLeave)
button:SetScript("OnMouseUp", MissionButton_OnMouseUp)
button:SetScript("OnClick", MissionButton_OnClick)
end
local function UpdateItemInfoHandler(self, ...)
if addon.scrollBox:IsVisible() then
addon:RegisterEvent("GET_ITEM_INFO_RECEIVED")
else
addon:UnregisterEvent("GET_ITEM_INFO_RECEIVED")
end
end
function addon:UpdateInProgressTabText()
if GarrisonLandingPageReport then
local text = GarrisonLandingPageReport.InProgress.Text
text:SetText((_G.GARRISON_LANDING_IN_PROGRESS.." (%d)"):format(#self.missions, #self.altMissions))
end
end
function addon:Refresh()
if GarrisonLandingPageReport and GarrisonLandingPageReport:IsVisible() then
GarrisonLandingPageReportList_UpdateItems()
end
end
do
function addon:HideMenu()
if _G.UIDROPDOWNMENU_OPEN_MENU == addon.menu then
--GameTooltip:Hide()
CloseDropDownMenus()
end
end
local function IgnoreProfile_OnClick(self, name, arg2, checked)
addon:HideMenu()
if name then
IPMDB.ignores[name] = not checked or nil
addon:UpdateAltMissions()
addon:Refresh()
end
end
local function SortMethod_OnClick(self, name)
addon:HideMenu()
if name then
IPMDB.sortMethod = name
addon:UpdateAltMissions()
addon:Refresh()
end