-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWidgets.lua
More file actions
2321 lines (2145 loc) · 78 KB
/
Widgets.lua
File metadata and controls
2321 lines (2145 loc) · 78 KB
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 Factory, AN, T = {}, ...
local C, EV, L, U, S = C_Garrison, T.Evie, T.L, T.Util, {}
local PROGRESS_MIN_STEP = 0.2
local CovenKit = "NightFae"
local tooltipSharedPB, tooltipShopWatch
local UIBUTTON_HEIGHT = ({zhCN=24, zhTW=24, koKR=24})[GetLocale()] or 22
local CreateObject do
local skip, peekO = {SharedTooltipProgressBar=1, ObjectGroup=1, TexSlice=1, CommonHoverTooltip=1, Shadow=1}
local function peek(k)
local o = peekO and peekO[k]
return o and o.GetObjectType and o or nil
end
local function ret(otype, ...)
local a = ...
local s, nf = S[a], VPEX_OnUIObjectCreated
if a and not skip[otype] and type(nf) == "function" and (s or type(a) == "table") then
local ar = a and a.GetObjectType and a or s and s.GetObjectType and s
if ar then
peekO = s and (ar == s and a or s) or nil
securecall(nf, otype, ar, peek)
peekO = nil
end
end
return ...
end
function CreateObject(otype, ...)
return ret(otype, assert(Factory[otype], otype)(...))
end
end
T.Shadows, T.CreateObject = S, CreateObject
local function Mirror(tex, swapH, swapV)
local ulX, ulY, llX, llY, urX, urY, lrX, lrY = tex:GetTexCoord()
if swapH then
ulX, ulY, llX, llY, urX, urY, lrX, lrY = urX, urY, lrX, lrY, ulX, ulY, llX, llY
end
if swapV then
ulX, ulY, llX, llY, urX, urY, lrX, lrY = llX, llY, ulX, ulY, lrX, lrY, urX, urY
end
tex:SetTexCoord(ulX, ulY, llX, llY, urX, urY, lrX, lrY)
return tex
end
local function AugmentFollowerInfo(info)
info.autoCombatantStats = C_Garrison.GetFollowerAutoCombatStats(info.followerID)
info.autoCombatSpells = C_Garrison.GetFollowerAutoCombatSpells(info.followerID, info.level)
info.missionTimeEnd = info.missionTimeEnd or info.status == GARRISON_FOLLOWER_ON_MISSION and
(GetTime() + (C_Garrison.GetFollowerMissionTimeLeftSeconds(info.followerID) or 1)) or nil
return info
end
local GetTimeStringFromSeconds = U.GetTimeStringFromSeconds
local function HideOwnGameTooltip(self)
if GameTooltip:IsOwned(self) then
GameTooltip:Hide()
end
end
local function CommonTooltip_ShopWatch()
if not tooltipShopWatch or GameTooltip:IsForbidden() or GameTooltip:GetOwner() ~= tooltipShopWatch then
tooltipShopWatch = nil
return "remove"
end
if IsModifiedClick("COMPAREITEMS") or GetCVarBool("alwaysCompareItems") then
GameTooltip_ShowCompareItem(GameTooltip, GameTooltip)
else
GameTooltip_HideShoppingTooltips(GameTooltip)
end
end
local function CommonTooltip_ArmShopWatch(self, item)
if IsEquippableItem(item) and tooltipShopWatch ~= self then
if not tooltipShopWatch then
EV.MODIFIER_STATE_CHANGED = CommonTooltip_ShopWatch
end
tooltipShopWatch = self
end
end
local function CommonTooltip_OnEnter(self)
local showCurrencyBar = false
if self.tooltipAnchor == "ANCHOR_TRUE_LEFT" then
GameTooltip:SetOwner(self, "ANCHOR_NONE")
GameTooltip:SetPoint("RIGHT", self, "LEFT", self.tooltipXO or 0, self.tooltipYO or 0)
else
GameTooltip:SetOwner(self, self.tooltipAnchor or "ANCHOR_TOP", self.tooltipXO or 0, self.tooltipYO or 0)
end
tooltipShopWatch = not not tooltipShopWatch
if type(self.mechanicInfo) == "table" then
local ic, m = self.Icon and self.Icon:GetTexture(), self.mechanicInfo
ic = ic or m.icon
GameTooltip:SetText((ic and "|T" .. ic .. ":0:0:0:0:64:64:4:60:4:60|t " or "") .. m.name)
if (m.enemy or "") ~= "" then
GameTooltip:AddLine("|cff49C8F2" .. m.enemy)
elseif (m.description or "") ~= "" then
GameTooltip:AddLine(m.description, 1,1,1,1)
end
if type(m.ability) == "table" then
local a = m.ability
GameTooltip:AddLine(" ")
GameTooltip:AddLine((a.icon and "|T" .. a.icon .. ":0|t " or "") .. a.name)
if (a.description or "") ~= "" then
GameTooltip:AddLine(a.description, 1,1,1,1)
end
end
elseif self.itemLink then
GameTooltip:SetHyperlink(self.itemLink)
CommonTooltip_ArmShopWatch(self, self.itemLink)
elseif self.itemID then
GameTooltip:SetItemByID(self.itemID)
CommonTooltip_ArmShopWatch(self, self.itemID)
elseif self.tooltipHeader and (self.tooltipText or self.tooltipCountdownTo) then
GameTooltip:AddLine(self.tooltipHeader)
if self.tooltipCountdownTo then
GameTooltip:AddLine(GetTimeStringFromSeconds(self.tooltipCountdownTo - GetTime(), false, false, true), 1,1,1)
else
GameTooltip:AddLine(self.tooltipText, 1,1,1, self.tooltipTextNW == nil and 1 or nil)
end
showCurrencyBar = not not (self.currencyID)
elseif self.currencyID then
GameTooltip:SetCurrencyByID(self.currencyID)
if self.currencyID == 1889 then
local ci = C_CurrencyInfo.GetCurrencyInfo(self.currencyID)
local q = ci and U.GetShiftedCurrencyValue(self.currencyID, ci.quantity) or "??"
GameTooltip:AddLine("|n" .. (L"Current Progress: %s"):format("|cffffffff" .. q .. "|r"))
GameTooltip:Show()
end
elseif self.achievementID then
local self, achievementID, highlightAsset = GameTooltip, self.achievementID, self.assetID
local _, n, _points, c, _, _, _, description, _, _icon, _, _, wasEarnedByMe, _earnedBy =
GetAchievementInfo(achievementID)
self:SetText(n)
if not c or not wasEarnedByMe then
self:AddLine(ACHIEVEMENT_TOOLTIP_IN_PROGRESS:format(UnitName("player")), 0.1, 0.9, 0.1)
self:AddLine(" ")
end
self:AddLine(description, 1,1,1,1)
local nc = GetAchievementNumCriteria(achievementID)
for i=1,nc,2 do
local n1, _, c1, _, _, _, _, asid = GetAchievementCriteriaInfo(achievementID, i)
n1 = (asid == highlightAsset and "|cffffea00" or c1 and "|cff20c020" or "|cffa8a8a8") .. n1
if i == nc then
self:AddLine(n1)
else
local n2, _, c2, _, _, _, _, asid = GetAchievementCriteriaInfo(achievementID, i+1)
n2 = (asid == highlightAsset and "|cffffea00" or c2 and "|cff20c020" or "|cffa8a8a8") .. n2
self:AddDoubleLine(n1, n2)
end
end
else
GameTooltip:Hide()
return
end
if self.ShowQuantityFromWidgetText and not showCurrencyBar then
local w = self[self.ShowQuantityFromWidgetText]
local t = w and w:GetText() or ""
local c = NORMAL_FONT_COLOR
if t ~= "" then
GameTooltip:AddLine((L"Quantity: %s"):format("|cffffffff" .. t), c.r, c.g, c.b)
end
end
GameTooltip:Show()
if self.tooltipPostShow then
self.tooltipPostShow(GameTooltip, self)
end
if showCurrencyBar then
local q1, factionID, cur, max, label = self.currencyQ, C_CurrencyInfo.GetFactionGrantedByCurrency(self.currencyID)
if factionID then
if C_Reputation.IsFactionParagon(factionID) then
label, cur, max = _G["FACTION_STANDING_LABEL8" .. (UnitSex("player") ~= 2 and "_FEMALE" or "")], C_Reputation.GetFactionParagonInfo(factionID)
cur = cur % max
else
local _, _, stID, bMin, bMax, bVal = GetFactionInfoByID(factionID)
if stID and bMin then
cur, max, label = bVal - bMin, bMax-bMin, _G["FACTION_STANDING_LABEL" .. stID .. (UnitSex("player") ~= 2 and "_FEMALE" or "")]
end
end
end
if not (cur and max) then
return
end
label = label .. " - " .. BreakUpLargeNumbers(cur) .. " / " .. BreakUpLargeNumbers(max)
CreateObject("SharedTooltipProgressBar"):Activate(GameTooltip, cur, max, label, self.isRetrospective and 0 or q1)
end
end
local function CommonTooltip_DelayedRefresh_OnUpdate(self, elapsed)
local tl = self.tooltipRefreshDelay - (elapsed or 0)
if not GameTooltip:IsOwned(self) then
self:SetScript("OnUpdate", nil)
self.tooltipRefreshDelay = nil
elseif tl > 0 then
self.tooltipRefreshDelay = tl
else
self:SetScript("OnUpdate", nil)
self.tooltipRefreshDelay = nil
self:GetScript("OnEnter")(self)
end
end
local function CommonLinkable_OnClick(self)
if self.itemLink then
HandleModifiedItemClick(self.itemLink)
elseif not IsModifiedClick("CHATLINK") then
elseif self.achievementID then
ChatEdit_InsertLink(GetAchievementLink(self.achievementID))
elseif self.itemID then
local _, link = GetItemInfo(self.itemID)
if link then
ChatEdit_InsertLink(link)
end
elseif self.currencyID and self.currencyID ~= 0 then
ChatEdit_InsertLink(C_CurrencyInfo.GetCurrencyLink(self.currencyID, self.currencyAmount or 0))
end
end
local function MissionList_ScrollToward(self, obj)
if obj:GetBottom() < self:GetBottom() then
self:GetScript("OnMouseWheel")(self, -1)
elseif obj:GetTop() > self:GetTop() then
self:GetScript("OnMouseWheel")(self, 1)
end
end
local function MissionList_SpawnMissionButton(arr, i)
local prev = type(i) == "number" and rawget(arr, i-1)
if type(prev) == "table" then
local cf = CreateObject("MissionButton", prev:GetParent())
arr[i] = cf
cf:SetPoint("TOPLEFT", 292*(((i-1)%3)+1)-284, math.floor((i-1)/3) *- 196)
cf:GetParent():SetHeight(196 * (math.floor((i-1)/3) + 1))
return cf
end
end
local function MissionButton_OnClick(self)
local s = S[self]
if IsModifiedClick("CHATLINK") and s.missionID then
ChatEdit_InsertLink(C.GetMissionLink(s.missionID))
else
self:GetParent():GetParent():ScrollToward(self)
end
end
local function MissionButton_OnProgressBarClick(self)
local s = S[self:GetParent()]
if s.missionID and s.completableAfter and s.completableAfter <= GetTime() then
U.InitiateMissionCompletion(s.missionID)
end
end
local function MissionButton_OnViewClick(self)
U.ShowMission(S[self:GetParent()].missionID, self:GetParent():GetParent():GetParent():GetParent())
end
local FollowerButton_OnEnter
local function MissionButton_SetGroupPortraits(mb, g, isVeiled, altWidget)
local hasGroup = g and next(g) ~= nil or false
mb.Group:SetShown(hasGroup)
altWidget:SetShown(not hasGroup)
local s = S[mb.Group]
local vc = isVeiled and 0.85 or 1
for i=0, hasGroup and 4 or -1 do
local f = g[i]
local t = f and C_Garrison.GetFollowerPortraitIconID(f)
s[i].id = f
s[i].click:SetScript("OnEnter", function()
s[i].click.info = f and C_Garrison.GetFollowerInfo(f)
FollowerButton_OnEnter(s[i].click)
end)
local c = t and vc or 0.2
s[i]:SetTexture(t or "Interface/Masks/CircleMask")
s[i]:SetVertexColor(c, c, c)
s[5+i]:SetVertexColor(vc, vc, vc)
end
end
local function Progress_UpdateTimer(self)
local now, endTime = GetTime(), self.endTime
if endTime <= now then
self.Fill:SetWidth(math.max(0.01, self:GetWidth()))
self.Fill:SetTexCoord(0, 1, 0, 1)
self:SetScript("OnUpdate", nil)
if self.endText then
self.Text:SetText(self.endText)
end
self:SetEnabled(not not self.endClick)
self.endTime, self.duration, self.endText, self.nextUp = nil
elseif (self.nextUp or now) <= now then
local w, d = self:GetWidth(), self.duration
local secsLeft, p = endTime-now-0.5, math.min(1, 1-(endTime-now)/d)
self.Fill:SetWidth(math.max(0.01, w*p))
self.Fill:SetTexCoord(0, math.max(1/128, p), 0, 1)
self.nextUp = now + math.min(PROGRESS_MIN_STEP/w * d, 0.01 + secsLeft % (secsLeft < 100 and 1 or 60))
if self.showTimeRemaining then
self.Text:SetText(GetTimeStringFromSeconds(secsLeft, false, true))
else
self.Text:SetText("")
end
self:Disable()
end
end
local function Progress_SetProgress(self, progress)
progress = progress > 1 and 1 or progress
self.Fill:SetWidth(math.max(0.01,self:GetWidth()*progress))
self.Fill:SetTexCoord(0, math.max(1/128, progress), 0, 1)
self.endTime, self.duration, self.endText, self.endClick, self.nextUp = nil
self:SetScript("OnUpdate", nil)
end
local function Progress_SetTimer(self, endTime, duration, endText, endClick, showTimeRemaining)
self.endTime, self.duration, self.endText, self.endClick, self.showTimeRemaining, self.nextUp = endTime, duration, endText, endClick == true or nil, showTimeRemaining == true or nil, nil
self:SetScript("OnUpdate", Progress_UpdateTimer)
Progress_UpdateTimer(self)
end
local function TooltipProgressBar_Update(self)
local p = self:GetParent()
local pt, sb, pw = p:GetTop(), self:GetBottom(), p:GetWidth()
if pt and sb then
p:SetHeight(pt-sb+8)
end
if pw then
self:SetWidth(pw - 20)
end
self.Bar:SetProgress(self.pv)
self.Fill2:SetWidth(self.Bar:GetWidth()*self.v2)
end
local function TooltipProgressBar_Activate(self, tip, cur, max, label, q1)
if not (cur and max) then
return
end
self.pv = cur/max
self.v2 = math.max(0.00001, math.min(1-self.pv, (q1 or 0)/max))
self.Bar.Text:SetText(label)
self.Fill2:SetAtlas((cur+ (q1 or 0)) > max and "UI-Frame-Bar-Fill-Green" or "UI-Frame-Bar-Fill-Yellow")
local tl = (q1 or 0)/max
self.Fill2:SetTexCoord(tl, tl+self.v2, 0, 1)
self.Fill2:SetShown((q1 or 0) > 0)
self:SetParent(tip)
tip:AddLine(("|TInterface/Minimap/PartyRaidBlipsV2:5:65:0:0:64:32:62:63:0:2|t "):rep(3))
local lastLine = _G[tip:GetName() .. "TextLeft" .. (tip:NumLines()-1)]
self:SetPoint("TOPLEFT", lastLine, "BOTTOMLEFT", 0, -2)
self:Show()
tip:Show()
TooltipProgressBar_Update(self)
end
local function TooltipProgressBar_OnHide(self)
self:Hide()
self:SetParent(nil)
self:ClearAllPoints()
end
local function CountdownText_OnUpdate(self)
local now = GetTime()
if now >= self.cdtTick then
local cdTo = self.cdtTo
local secsLeft = cdTo-now
if secsLeft <= 0 then
self.CDTDisplay:SetText(self.cdtRest)
self:SetScript("OnUpdate", nil)
self.cdtTick, self.cdtTo = nil
else
self.cdtTick = secsLeft < 120 and (now + secsLeft % 0.5 + 0.01) or (now + secsLeft % 60 + 0.01)
self.CDTDisplay:SetText(self.cdtPrefix .. GetTimeStringFromSeconds(secsLeft, self.cdtShort, self.cdtRoundedUp) .. self.cdtSuffix .. self.cdtRest)
end
end
end
local function CountdownText_SetCountdown(self, prefix, expireAt, suffix, rest, isShort, isRoundUp)
prefix, suffix, rest = prefix or "", suffix or "", rest or ""
local now = GetTime()
if not (expireAt and expireAt > now) then
self.CDTDisplay:SetText(rest or "")
self:SetScript("OnUpdate", nil)
else
self.cdtTick, self.cdtPrefix, self.cdtTo, self.cdtSuffix, self.cdtRest, self.cdtShort, self.cdtRoundedUp = now, prefix, expireAt, suffix, rest, isShort, isRoundUp == true
self:SetScript("OnUpdate", CountdownText_OnUpdate)
CountdownText_OnUpdate(self)
end
end
local function ResizedButton_SetText(self, text)
(self.Text or self):SetText(text)
self:SetWidth((self.Text or self):GetStringWidth()+26)
end
local function ResourceButton_Update(self, _event, currencyID)
if currencyID == self.currencyID then
local ci = C_CurrencyInfo.GetCurrencyInfo(currencyID)
local quant = ci and U.GetShiftedCurrencyValue(currencyID, ci.quantity)
if quant then
self.Text:SetText(BreakUpLargeNumbers(quant))
self:SetWidth(self.Text:GetStringWidth()+26)
end
if GameTooltip:IsOwned(self) and GameTooltip:IsShown() then
self:GetScript("OnEnter")(self)
end
end
end
local function ResourceButton_OnClick(self)
if IsModifiedClick("CHATLINK") then
ChatEdit_InsertLink(C_CurrencyInfo.GetCurrencyLink(self.currencyID, 42))
end
end
local function SetRarityBorder(b, r, atlas)
r = type(r) == "number" and r or 2
local vc = (atlas or r >= 1) and 1 or 0.65
b:SetAtlas(atlas
or r <= 1 and "loottoast-itemborder-gold"
or r == 2 and "loottoast-itemborder-green"
or r == 3 and "loottoast-itemborder-blue"
or r == 4 and "loottoast-itemborder-purple"
or r == 9 and "loottoast-itemborder-gold"
or "loottoast-itemborder-orange")
b:SetDesaturated(r <= 1 and not atlas)
b:SetVertexColor(vc, vc, vc)
end
local RewardButton_SetReward do
local baseXPReward = {title=L"Follower XP", tooltip=L"Awarded even if the adventurers are defeated.", icon="Interface/Icons/XP_Icon", qualityAtlas="loottoast-itemborder-purple"}
function RewardButton_SetReward(self, rew, isOvermax, pw)
if rew == "xp" then
baseXPReward.followerXP = isOvermax
return RewardButton_SetReward(self, baseXPReward)
end
self:SetShown(not not rew)
if not rew then
return
end
local q, tooltipTitle, tooltipText, cq = rew.quantity, rew.title
if rew.icon then
self.Icon:SetTexture(rew.icon)
elseif rew.itemID then
self.Icon:SetTexture(GetItemIcon(rew.itemID))
end
self.RarityBorder:SetDesaturated(false)
self.RarityBorder:SetVertexColor(1,1,1)
if rew.currencyID then
if rew.currencyID == 0 then
q = math.floor(rew.quantity / 1e4)
tooltipText = GetMoneyString(rew.quantity)
SetRarityBorder(self.RarityBorder, 9)
else
local ci = C_CurrencyInfo.GetCurrencyContainerInfo(rew.currencyID, rew.quantity)
if ci then
self.Icon:SetTexture(ci.icon)
tooltipTitle = (ci.quality and "|c" .. (select(4,GetItemQualityColor(ci.quality)) or "ff00ffff") or "") .. ci.name
tooltipText = NORMAL_FONT_COLOR_CODE .. (ci.description or "")
end
local ci2 = C_CurrencyInfo.GetCurrencyInfo(rew.currencyID)
SetRarityBorder(self.RarityBorder, ci and ci.quality or ci2 and ci2.quality)
cq = (isOvermax and pw and pw.currencyID == rew.currencyID and pw.currencyQ or 0) + q
end
elseif rew.itemID then
q = rew.quantity == 1 and "" or rew.quantity or ""
local r = select(3,GetItemInfo(rew.itemLink or rew.itemID)) or select(3,GetItemInfo(rew.itemID)) or 2
SetRarityBorder(self.RarityBorder, r)
elseif rew.followerXP then
q, tooltipTitle, tooltipText = BreakUpLargeNumbers(rew.followerXP), rew.title, rew.tooltip
SetRarityBorder(self.RarityBorder, 2, rew.qualityAtlas)
end
self.currencyID, self.currencyAmount, self.currencyQ = rew.currencyID, rew.quantity, cq
self.itemID, self.itemLink = rew.itemID, rew.itemLink
self.tooltipHeader, self.tooltipText = tooltipTitle, tooltipText
self.Quantity:SetText(q == 1 and "" or q or "")
end
end
local function RewardBlock_SetRewards(self, xp, rw)
local nc = xp and (self[1]:SetReward("xp", xp) and nil or 2) or 1
nc = nc + (self[nc]:SetReward(rw and rw[1]) and nil or 1)
nc = nc + (self[nc]:SetReward(rw and rw[2]) and nil or 1)
for i=nc, #self do self[i]:SetReward() end
if self.Container then
self.Container:SetWidth((self[1]:GetWidth()+4)*((xp and 1 or 0) + (rw and #rw or 0))-2)
elseif self.Label then
self[1]:GetParent():SetWidth(self.Label:GetStringWidth()+16+32*(1+(rw and #rw or 0)))
end
end
local function FollowerButton_OnDragStart(self)
if self:IsEnabled() then
local fa = CovenantMissionFrame.MissionTab.MissionPage.Board.framesByBoardIndex
local fid = self.info.followerID
if not self.info.isAutoTroop then
for i=0,4 do
local f = fa[i]
if f:IsShown() and f:GetFollowerGUID() == fid then
return
end
end
end
CovenantMissionFrame:OnDragStartFollowerButton(CovenantMissionFrame:GetPlacerFrame(), self, 24);
end
end
local function FollowerButton_OnDragStop(self)
if self:IsEnabled() then
CovenantMissionFrame:OnDragStopFollowerButton(CovenantMissionFrame:GetPlacerFrame());
end
end
local function GetAltModifierKeyText(ex)
local m = GetModifiedClick(ex)
return m and m:match("ALT") and CTRL_KEY_TEXT or ALT_KEY_TEXT
end
local function IsAltModifiedClick(ex)
local m = GetModifiedClick(ex)
if m and m:match("ALT") then
return IsControlKeyDown()
else
return IsAltKeyDown()
end
end
local function FollowerButton_OnClick(self, b)
if b == "LeftButton" and not self.info.isAutoTroop then
if IsAltModifiedClick("CHATLINK") then
local gid = self.info.garrFollowerID
U.FollowerSetFavorite(gid, not U.FollowerIsFavorite(gid))
GameTooltip:Hide()
self:GetParent():Refresh()
return
elseif self.info and IsShiftKeyDown() then
U.ReleaseTentativeFollower(self.info.followerID)
self:GetParent():Refresh()
end
elseif b == "RightButton" then
local fa = CovenantMissionFrame.MissionTab.MissionPage.Board.framesByBoardIndex
local fid = self.info.followerID
for i=0,self.info.isAutoTroop and -1 or 4 do
if fa[i]:GetFollowerGUID() == fid then
CovenantMissionFrame:RemoveFollowerFromMission(fa[i], true)
return
end
end
CovenantMissionFrame.MissionTab.MissionPage:AddFollower(fid)
elseif b == "LeftButton" and IsModifiedClick("CHATLINK") then
ChatEdit_InsertLink(C.GetFollowerLink(self.info.followerID))
end
self:GetParent():SyncToBoard()
end
function FollowerButton_OnEnter(self)
local info = self.info
if not info then return end
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
U.SetFollowerInfo(GameTooltip, info, info.autoCombatSpells, nil, nil, nil, nil, true)
local tmid = U.FollowerHasTentativeGroup(info.followerID)
if info.status == GARRISON_FOLLOWER_ON_MISSION and info.missionTimeEnd then
local tl = math.max(0, info.missionTimeEnd-GetTime())
GameTooltip:AddLine(" ")
GameTooltip:AddLine(tl > 0 and COVENANT_MISSIONS_ON_ADVENTURE_DURATION:format(GetTimeStringFromSeconds(tl, false, true, true)) or COVENANT_FOLLOWER_MISSION_COMPLETE, 1, 0.4, 0)
GameTooltip:Show()
elseif tmid and C_Garrison.GetMissionTimes(tmid) then
local tn = C_Garrison.GetMissionName(tmid)
GameTooltip:AddLine(" ")
GameTooltip:AddLine((L"In Tentative Party - %s"):format(tn or "??"), 1, 0.4, 0)
GameTooltip:AddLine("Shift".."+|TInterface\\TUTORIALFRAME\\UI-TUTORIAL-FRAME:0:0:0:-1:512:512:2:78:240:316|t:" .." to remove from Tentative Group")
GameTooltip:Show()
end
if not (info.isAutoTroop or info.missionTimeEnd) then
local act = U.FollowerIsFavorite(info.garrFollowerID) and BATTLE_PET_UNFAVORITE or BATTLE_PET_FAVORITE
local short = GetAltModifierKeyText("CHATLINK") .. "+|TInterface\\TUTORIALFRAME\\UI-TUTORIAL-FRAME:0:0:0:-1:512:512:2:78:240:316|t: "
GameTooltip:AddLine(" ")
GameTooltip:AddLine(short .. act, 0.5, 0.8, 1)
GameTooltip:Show()
end
end
local function FollowerButton_GetInfo(self)
return self.info
end
local function FollowerButton_GetFollowerGUID(self)
return self.info.followerID
end
local function FollowerButton_SetInfo(self, info)
local s = S[self]
local onMission = info.status == GARRISON_FOLLOWER_ON_MISSION
local inTG = not info.isAutoTroop and U.FollowerHasTentativeGroup(info.followerID)
local vc, dc = inTG and 0.55 or onMission and 0.25 or 1, onMission and 0.65 or 1
local mc = onMission and DISABLED_FONT_COLOR or NORMAL_FONT_COLOR
local mtl = info.missionTimeEnd and GetTimeStringFromSeconds(math.max(0, info.missionTimeEnd-GetTime()), 2, true, true) or ""
self.info = info
s.Portrait:SetTexture(info.portraitIconID)
s.Portrait:SetDesaturated(onMission and true or false)
s.Portrait2:SetTexture(info.portraitIconID)
s.Portrait2:SetDesaturated(onMission and true or false)
s.TextLabel:SetText(onMission and mtl or info.level)
s.TextLabel:SetTextColor(mc.r, mc.g, mc.b)
s.PortraitR:SetVertexColor(dc, dc, dc)
s.PortraitR:SetDesaturated(onMission and true or false)
s.PortraitT:SetShown(inTG)
s.Portrait:SetVertexColor(vc, vc, vc)
s.PortraitT:SetDesaturated(onMission and true or false)
s.Portrait2:SetShown(inTG or onMission)
s.Favorite:SetShown(not info.isAutoTroop and not (onMission and inTG) and (info.soFavorite or 0) > 0)
if inTG then
s.Portrait2:SetVertexColor(0.6, 0, 0)
else
s.Portrait2:SetVertexColor(1, 1, 1)
end
local ir = info.role
s.Role:SetAtlas(ir == 1 and "adventures-dps" or ir == 4 and "adventures-healer" or ir == 5 and "adventures-tank" or "adventures-dps-ranged")
s.Role:SetDesaturated(onMission and true or false)
self:SetEnabled(not onMission)
s.Health:SetShown(not onMission)
local cs = info.autoCombatantStats
s.Health:SetWidth(s.HealthBG:GetWidth()*math.min(1, cs and (cs.currentHealth/cs.maxHealth)+0.001 or 0.001))
s.ExtraTex:SetDesaturated(onMission)
if info.missionTimeEnd then
local t = GetTime()
local tl = info.missionTimeEnd-t
local te = tl > 1 and (t+tl%60+0.05)
if te and te < (self:GetParent().nextUpdate or 0) then
self:GetParent().nextUpdate = te
end
end
local ns = info.autoCombatSpells and #info.autoCombatSpells or 0
for i=1,ns do
local sp = info.autoCombatSpells[i]
s.Abilities[i]:SetTexture(sp.icon)
s.Abilities[i]:SetDesaturated(onMission and true or false)
s.Abilities[i]:Show()
s.AbilitiesB[i]:Show()
end
for i=ns+1, #s.Abilities do
s.Abilities[i]:Hide()
s.AbilitiesB[i]:Hide()
end
if onMission then
s.HealthBG:SetGradient("VERTICAL", 0.1,0.1,0.1, 0.2,0.2, 0.2)
else
s.HealthBG:SetGradient("VERTICAL", 0.07,0.07,0.07, 0.14,0.14,0.14)
end
end
local SortFollowerList, CompareFollowerXP do
local preferLowHealth, uiOrder
local function FollowerList_Compare(a,b)
local ac, bc = a.missionTimeEnd, b.missionTimeEnd
if ac ~= bc then
if ac and bc then
return ac < bc
else
return not ac
end
end
ac, bc = not a.inTentativeGroup, not b.inTentativeGroup
if ac ~= bc then
return ac
end
local uiFree = uiOrder and not (a.missionTimeEnd or a.inTentativeGroup)
if uiFree and a.soFavorite ~= b.soFavorite then
ac, bc = a.soFavorite, b.soFavorite
else
ac, bc = a.level, b.level
end
if preferLowHealth and ac == bc then
ac, bc = a.autoCombatantStats, b.autoCombatantStats
ac, bc = ac and -ac.currentHealth/ac.maxHealth or 0, bc and -bc.currentHealth/bc.maxHealth or 0
end
if uiFree and ac == bc then
ac, bc = #(a.autoCombatSpells or "1"), #(b.autoCombatSpells or "1")
end
if ac == bc then
ac, bc = a.xp, b.xp
end
if ac == bc then
ac, bc = a.autoCombatantStats, b.autoCombatantStats
ac, bc = ac and ac.maxHealth or 0, bc and bc.maxHealth or 0
end
if ac == bc then
ac, bc = b.name, a.name
end
return ac > bc
end
function CompareFollowerXP(a,b)
local ac, bc = a.level, b.level
if ac == bc then
ac, bc = a.xp, b.xp
end
if ac == bc then
ac, bc = a.name, b.name
end
return ac > bc
end
function SortFollowerList(list, preferLowHP, forUI)
preferLowHealth, uiOrder = preferLowHP, forUI
for i=1,#list do
list[i].inTentativeGroup = U.FollowerHasTentativeGroup(list[i].followerID)
list[i].soFavorite = forUI and U.FollowerIsFavorite(list[i].garrFollowerID) and 1 or 0
end
table.sort(list, FollowerList_Compare)
end
end
local function FollowerList_GetTroopHint(ft)
local o
if #ft > 0 then
table.sort(ft, CompareFollowerXP)
local m = (#ft + #ft%2)/2
local ml = ft[m].level
if #ft % 2 == 0 then
local fi = ft[m+1]
o = "|cffa0a0a0[" .. fi.level .. "]|r |cffffffff" .. fi.name .. "|r"
ml = (ml+fi.level)/2
end
for i=ft[m].level == 60 and 0 or m, 1, -1 do
local fi = ft[i]
o = "|cffa0a0a0[" .. fi.level .. "]|r |cffffffff" .. fi.name .. "|r" .. (o and "\n" .. o or "")
if i == 1 or ft[i].level ~= ft[i-1].level then
break
end
end
local mlc = ("%s%.3g|r"):format(NORMAL_FONT_COLOR_CODE, ml)
o = (L"Your troop level is the median level of your companions (%s), rounded down. It does not decrease when you recruit additional companions."):format(mlc)
.. (ml < 60 and "\n\n" .. NORMAL_FONT_COLOR_CODE .. L"These companions currently affect your troop level:" .. "|r\n" .. o or "")
end
return COVENANT_MISSIONS_TUTORIAL_TROOPS .. (o and ("\n\n" .. o) or "")
end
local function FollowerList_SyncToBoard(self)
local fa = CovenantMissionFrame.MissionTab.MissionPage.Board.framesByBoardIndex
local ca = S[self].companions
for i=1, #ca do
local c = ca[i]
local isInMission = false
for i=0, c:IsShown() and 4 or -1 do
local f = fa[i]
if f and f.name and f:IsShown() and f.info and f.info.followerID == c.info.followerID then
isInMission = true
break
end
end
if S[c].EC then
S[c].EC:SetShown(isInMission)
end
end
end
local function FollowerList_SyncXPGain(self, setXPGain)
local ca = S[self].companions
local xpGain = type(setXPGain) == "number" and setXPGain or self.xpGain or -1
self.xpGain = xpGain
for i=1,#ca do
local w = ca[i]
local info = w.info
local isAway = (info and info.status == GARRISON_FOLLOWER_ON_MISSION)
local willLevel = (info and not info.isAutoTroop and not info.isMaxLevel and info.xp and info.levelXP and (info.levelXP-info.xp) <= xpGain)
S[w].Blip:SetShown(willLevel and not isAway)
end
end
local function FollowerList_Refresh(self, setXPGain)
local s = S[self]
local wt, wf = s.troops, s.companions
if self.noRefresh == nil then
local fl = C_Garrison.GetFollowers(123)
local ft = C_Garrison.GetAutoTroops(123)
for i=1,#ft do
FollowerButton_SetInfo(wt[i], AugmentFollowerInfo(ft[i]))
end
for i=1,#fl do
AugmentFollowerInfo(fl[i])
end
s.TroopInfo.tooltipText = FollowerList_GetTroopHint(fl)
SortFollowerList(fl, false, true)
local numActiveFollowers = 0
local numColumns = 5
local width, height = wf[1]:GetSize()
local followerOffset = 0
--Follower buttons are now split into two list: List One = available, List Two = on misson or in tentative group
for i = 1, 24 do
local followerInfo = fl[i]
local followerButton = wf[i]
if followerInfo then
FollowerButton_SetInfo(followerButton, followerInfo)
local posIndex = i-1
if followerInfo.status ~= GARRISON_FOLLOWER_ON_MISSION and not U.FollowerHasTentativeGroup(followerInfo.followerID) then
numActiveFollowers = numActiveFollowers + 1
else
posIndex = (math.ceil(numActiveFollowers / numColumns) * numColumns) + (posIndex - numActiveFollowers)
end
local X = ((posIndex % numColumns + 1)* (width + 4))
local Y = math.floor(posIndex / numColumns + 1) * (height + 2) + 5
followerButton:ClearAllPoints()
followerButton:SetPoint("BottomRight", followerButton.t, "BottomLeft", X, -Y)
followerButton:Show()
else
followerButton:Hide()
end
end
self.noRefresh = true
end
FollowerList_SyncToBoard(self)
FollowerList_SyncXPGain(self, setXPGain)
end
local function FollowerList_OnUpdate(self)
local t = GetTime()
self.noRefresh = nil
if t >= (self.nextUpdate or 0) then
self.nextUpdate = t+60
self:Refresh()
local mf = GetMouseFocus()
if mf and mf:GetParent() == self and GameTooltip:IsOwned(mf) then
local f = mf:GetScript("OnEnter")
if f then f(mf) end
end
end
end
local function DoomRun_OnEnter(self)
local ft, g, gn = C_Garrison.GetFollowers(123), {}, 0
SortFollowerList(ft, true, false)
for i=#ft,1,-1 do
local fi = ft[i]
if fi.isCollected and not fi.isMaxLevel and fi.status ~= GARRISON_FOLLOWER_ON_MISSION
and not U.FollowerHasTentativeGroup(fi.followerID)
and C_Garrison.GetFollowerAutoCombatStats(fi.followerID).currentHealth > 0 then
g[gn], gn = i, gn + 1
if gn == 5 then
break
end
end
end
local xpR = S[self:GetParent()].baseXPReward
local xpT = "|cff00ff00" .. GARRISON_REWARD_XP_FORMAT:format(BreakUpLargeNumbers(xpR)) .. "|r"
GameTooltip:SetOwner(self, "ANCHOR_TOP")
GameTooltip:SetText(L"Doomed Run")
GameTooltip:AddLine(L("Failing this mission grants %s to each companion."):format(xpT), 1,1,1,1)
if gn > 0 then
GameTooltip:AddLine(" ")
for i=0, gn-1 do
local fi = ft[g[i]]
local willLevelUp = fi.levelXP and fi.xp and fi.levelXP - fi.xp <= xpR or false
local upTex = willLevelUp and " |A:bags-greenarrow:0:0|a" or ""
GameTooltip:AddLine("|cffa0a0a0[" .. fi.level .. "]|r " .. fi.name .. upTex, 1,1,1)
g[i] = fi.followerID
end
GameTooltip:AddLine(L"Tentatively assign these rookies to this adventure.", 0.2,1,0.2, 1)
GameTooltip:AddLine("|TInterface/TUTORIALFRAME/UI-TUTORIAL-FRAME:14:12:0:-1:512:512:10:70:330:410|t " .. L"Start the adventure", 0.5, 0.8, 1)
end
self.group = gn > 0 and g or nil
GameTooltip:Show()
end
local function DoomRun_OnClick(self, button)
local mid = S[self:GetParent()].missionID
local g, st = self.group, self.showTime
local inShowCooldown = (GetTime()-st < 0.25)
if not (mid and g and st) or inShowCooldown then return end
if GameTooltip:IsOwned(self) then
GameTooltip:Hide()
end
if button == "RightButton" then
U.StartMissionWithDelay(mid, g)
else
U.StoreMissionGroup(mid, g)
PlaySound(SOUNDKIT.U_CHAT_SCROLL_BUTTON)
end
EV("I_MISSION_LIST_UPDATE")
end
local function DoomRun_OnShow(self)
self.showTime = GetTime()
end
local function TentativeGroupClear_OnClick(self)
local mid = S[self:GetParent()].missionID
U.StoreMissionGroup(mid, nil)
PlaySound(SOUNDKIT.U_CHAT_SCROLL_BUTTON)
end
local function getWastedRewards(r)
local o
for i=1, r and #r or 0 do
local ri = r[i]
local cid = ri and ri.currencyID
if cid and cid ~= 0 and ri.quantity then
local ci = C_CurrencyInfo.GetCurrencyInfo(cid)
local wq = ci and (ci.maxQuantity or 0) > 0 and ci.quantity and math.min(ci.quantity, ci.quantity + ri.quantity - ci.maxQuantity) or 0
if wq > 0 then
o = (o and o .. " " or "") .. wq .. " |T" .. (ci.iconFileID or "Interface/Icons/Temp") .. ":0|t"
end
end
end
return o
end
local function UButton_SetStartMode(self)
local tco = 0
for mid, nt in U.EnumerateTentativeGroups() do
tco = tco + nt + (C_Garrison.GetMissionCost(mid) or 0)
end
local anima = C_CurrencyInfo.GetCurrencyInfo(1813)
self.mode = anima and anima.quantity and anima.quantity >= tco and "start-send" or "start-cost"
end
local function UButton_Sync(self)
local ps = S[self:GetParent()]
if self == ps.StartButton then
return UButton_Sync(ps.UnButton)
end
local idm = U.HasDelayedStartMissions()
local ism = U.IsStartingMissions()
local icm = U.IsCompletingMissions()
local tg = U.HaveTentativeGroups()
self:Show()
if ism then
self:SetFormattedText(L"%d |4party:parties; remaining...", ism)
self.mode = "stop-send"
elseif idm then
self:SetFormattedText(L"Starting soon...")
self.mode = "stop-delayed-send"
elseif icm then
self:SetFormattedText(L"%d |4adventure:adventures; remaining...", icm)
self.mode = "stop-complete"
elseif ps and ps.hasCompletedMissions then
self:SetText(L"Complete All")
self.mode = "start-complete"
elseif tg then
self:SetText(L"Send Tentative Parties")
UButton_SetStartMode(self)
else
self.mode, self.clickWithEscape = nil, nil
self:Hide()
end
local ocwe = self.clickWithEscape
self.clickKey = self.mode ~= "start-send" and "SPACE" or nil
self.clickWithEscape = self.mode and self.mode:match("^stop%-") and true or nil
self.eatEscapeUntil = math.max(self.eatEscapeUntil or -math.huge, ocwe and self.clickWithEscape ~= ocwe and GetTime()+0.5 or -math.huge)
self.Glow:SetShown(self.mode == "stop-delayed-send")
if GameTooltip:IsOwned(self) then
local oe = self:GetScript("OnEnter")
if not self:IsVisible() then
GameTooltip:Hide()
elseif oe then
oe(self)
end
end
if self.mode == "start-complete" and tg then
UButton_SetStartMode(ps.StartButton)
ps.StartButton:Show()
else
ps.StartButton:Hide()
end
end
local function UButton_OnEnter(self)
local m = self.mode
if m == "start-send" or m == "stop-send" or m == "start-cost" then
GameTooltip:SetOwner(self, "ANCHOR_BOTTOM")
GameTooltip:AddLine(L"Send Tentative Parties")
local cb = C_CurrencyInfo.GetBasicCurrencyInfo(1813)
local curIco = cb and cb.icon and " |T" .. cb.icon .. ":0|t" or ""
local hadZH, hourglass = false, "|Tinterface/common/mini-hourglass:0:0:0:0:1:1:0:1:0:1:255:80:0|t "
local tco, ng = 0,0
for mid, nt, zeroHealth in U.EnumerateTentativeGroups() do
local co = C_Garrison.GetMissionCost(mid) or 0
hadZH = hadZH or zeroHealth
GameTooltip:AddDoubleLine((zeroHealth and hourglass or "") .. C_Garrison.GetMissionName(mid), (co+nt) .. curIco, 1,1,1, 1,1,1)
tco, ng = tco + co + nt, ng + 1
end
if ng > 1 then
local nc, ac = NORMAL_FONT_COLOR, m == "start-cost" and RED_FONT_COLOR or HIGHLIGHT_FONT_COLOR
GameTooltip:AddDoubleLine(TOTAL, tco .. curIco, nc.r, nc.g, nc.b, ac.r, ac.g, ac.b)
end
GameTooltip:AddLine(" ")
if m == "start-cost" then
GameTooltip:AddLine(L"Insufficient anima", 1, 0.5, 0)
end
if hadZH then
GameTooltip:AddLine(hourglass .. "|cffff8000" .. COVENANT_MISSIONS_COMPANIONS_MISSING_HEALTH, 1, 0.5, 0)
self.tooltipRefreshDelay = 10
self:SetScript("OnUpdate", CommonTooltip_DelayedRefresh_OnUpdate)
end
GameTooltip:AddLine("|TInterface/TUTORIALFRAME/UI-TUTORIAL-FRAME:14:12:0:-1:512:512:10:70:330:410|t " .. L"Clear all tentative parties", 0.5, 0.8, 1)
GameTooltip:Show()