-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathTemplates.lua
More file actions
1359 lines (1131 loc) · 39.7 KB
/
Copy pathTemplates.lua
File metadata and controls
1359 lines (1131 loc) · 39.7 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 addonName, addon = ...
local WQT = addon.WQT;
local _L = addon.loca;
local _V = addon.variables;
local WQT_Profiles = addon.WQT_Profiles;
--------------------------------
-- WQT_TooltipMixin
--------------------------------
WQT_TooltipMixin = {};
function WQT_TooltipMixin:SetTooltip(func)
self.tooltipFunc = func;
end
function WQT_TooltipMixin:OnEnter()
if (self.tooltipFunc) then
WQT_ActiveGameTooltip:SetOwner(self, "ANCHOR_RIGHT");
self.tooltipFunc(WQT_ActiveGameTooltip);
WQT_ActiveGameTooltip:Show();
end
end
function WQT_TooltipMixin:OnLeave()
WQT_ActiveGameTooltip:Hide();
end
--------------------------------
-- WQT_MiniIconMixin
--------------------------------
WQT_MiniIconMixin = {};
function WQT_MiniIconMixin:Reset()
self:Hide();
self.Icon:Show();
self.Icon:SetTexture(nil);
self.Icon:SetScale(1);
self.Icon:SetSize(10, 10);
self.Icon:SetTexCoord(0, 1, 0, 1);
self.Icon:SetVertexColor(1, 1, 1);
self.Icon:SetDesaturated(false);
self.BG:Show();
self.BG:SetTexture("Interface/GLUES/Models/UI_MainMenu_Legion/UI_Legion_Shadow");
self.BG:SetScale(1);
self.BG:SetVertexColor(1, 1, 1);
self.BG:SetAlpha(0.75);
self.texure = "";
self.scale = 1;
self.left = nil;
self.right = nil;
self.top = nil;
self.bottom = nil;
self.isDesaturated = false;
self.hasCustomColor = false;
self.r = 1;
self.g = 1;
self.b = 1;
end
function WQT_MiniIconMixin:SetIconColor(color)
self:SetIconColorRGBA(color:GetRGB());
end
function WQT_MiniIconMixin:SetIconColorRGBA(r, g, b, a)
self.r = r;
self.g = g;
self.b = b;
self.hasCustomColor = true;
self:Update();
end
function WQT_MiniIconMixin:SetDesaturated(desaturate)
self.isDesaturated = desaturate;
self:Update();
end
function WQT_MiniIconMixin:SetIconCoords(left, right, top, bottom)
self.left = left;
self.right = right;
self.top = top;
self.bottom = bottom;
self:Update();
end
function WQT_MiniIconMixin:SetIconScale(scale)
self.scale = scale;
self:Update();
end
function WQT_MiniIconMixin:SetIconSize(width, height)
self.Icon:SetSize(width, height);
end
function WQT_MiniIconMixin:SetBackgroundScale(scale)
self.BG:SetScale(scale);
end
function WQT_MiniIconMixin:SetBackgroundShown(value)
self.BG:SetShown(value);
end
function WQT_MiniIconMixin:SetupIcon(texture, left, right, top, bottom)
self:Reset();
if (not texture) then return; end
self.texture = texture;
self.left = left;
self.right = right;
self.top = top;
self.bottom = bottom;
self:Update();
self:Show();
end
function WQT_MiniIconMixin:SetupRewardIcon(rewardType, subType)
self:Reset();
local rewardTypeAtlas = _V:GetRewardIconAtlas(rewardType, subType);
if not (rewardTypeAtlas) then
return;
end
self.texture = rewardTypeAtlas.texture;
self.left = rewardTypeAtlas.l;
self.right = rewardTypeAtlas.r;
self.top = rewardTypeAtlas.t;
self.bottom = rewardTypeAtlas.b;
self.scale = rewardTypeAtlas.scale;
if (rewardTypeAtlas.color) then
self.r, self.g, self.b = rewardTypeAtlas.color:GetRGB();
end
self:Update();
self:Show();
end
function WQT_MiniIconMixin:Update()
if (self.left) then
self.Icon:SetTexture(self.texture);
self.Icon:SetTexCoord(self.left, self.right, self.top, self.bottom);
else
self.Icon:SetTexCoord(0, 1, 0, 1);
self.Icon:SetAtlas(self.texture);
end
self.Icon:SetScale(self.scale);
local r, g, b = 1, 1, 1;
self.Icon:SetDesaturated(false);
if (self.isDesaturated) then
if(self.hasCustomColor) then
r, g, b = self.r, self.g, self.b;
elseif (self.left) then
r, g, b = 0.8, 0.8, 0.8;
else
self.Icon:SetDesaturated(true);
end
else
if (self.r) then
r, g, b = self.r, self.g, self.b;
end
end
self.Icon:SetVertexColor(r, g, b);
end
----------------------------
-- Containers
----------------------------
WQT_ContainerButtonMixin = {};
function WQT_ContainerButtonMixin:OnClick()
self:SetSelected(not self.isSelected);
end
function WQT_ContainerButtonMixin:SetSelected(isSelected)
self.isSelected = isSelected;
if (self.container) then
self.container:SetShown(self.isSelected);
if (self.Arrow) then
self.Arrow:SetAtlas(self.isSelected and "common-icon-backarrow" or "common-icon-forwardarrow");
end
if (self.ActiveTexture) then
self.ActiveTexture:SetShown(self.isSelected);
end
end
end
function WQT_ContainerButtonMixin:OnMouseDown()
if (not self.Icons) then return end
local offset = self.pressOffset or 2;
for k, frame in ipairs(self.Icons) do
frame:AdjustPointsOffset(offset, -offset);
end
end
function WQT_ContainerButtonMixin:OnMouseUp()
if (not self.Icons) then return end
local offset = self.pressOffset or 2;
for k, frame in ipairs(self.Icons) do
frame:AdjustPointsOffset(-offset, offset);
end
end
local _, addonTitle = C_AddOns.GetAddOnInfo(addonName);
function WQT_ContainerButtonMixin:OnEnter()
WQT_ActiveGameTooltip:SetOwner(self, "ANCHOR_RIGHT");
WQT_ActiveGameTooltip:SetText(addonTitle);
WQT_ActiveGameTooltip:Show();
end
function WQT_ContainerButtonMixin:OnLeave()
WQT_ActiveGameTooltip:Hide();
end
WQT_WorldMapContainerButtonMixin = CreateFromMixins(WQT_ContainerButtonMixin);
function WQT_WorldMapContainerButtonMixin:Refresh() end
----------------------------
-- WQT_MiniIconOverlayMixin
----------------------------
WQT_MiniIconOverlayMixin = {};
function WQT_MiniIconOverlayMixin:Init(anchor, startAngle, distance, spacingAngle)
self.miniIconPool = CreateFramePool("FRAME", anchor, "WQT_MiniIconTemplate");
self.anchor = anchor;
self.startAngle = startAngle or 270;
self.distance = distance or 20;
self.spacingAngle = spacingAngle or 32;
self.activeIcons = {};
end
function WQT_MiniIconOverlayMixin:Reset()
self.miniIconPool:ReleaseAll();
wipe(self.activeIcons);
end
function WQT_MiniIconOverlayMixin:Create()
local icon = self.miniIconPool:Acquire();
tinsert(self.activeIcons, icon);
icon:Show();
self:UpdatePlacement();
return icon;
end
function WQT_MiniIconOverlayMixin:UpdatePlacement()
local numIcons = self.miniIconPool:GetNumActive();
-- Counters
local offsetAngle = self.spacingAngle;
local startAngle = self.startAngle;
-- position of first counter
startAngle = startAngle - offsetAngle * (numIcons -1) /2
for k, icon in ipairs(self.activeIcons) do
local x = cos(startAngle) * self.distance;
local y = sin(startAngle) * self.distance;
icon:SetPoint("CENTER", self.anchor, "CENTER", x, y);
icon:SetParent(self.anchor);
icon:Show();
-- Offset next counter
startAngle = startAngle + offsetAngle;
end
end
----------------------------
-- Layout Frames
----------------------------
local function IsLayoutFrame(frame)
return frame.IsLayoutFrame and frame:IsLayoutFrame();
end
local noTableGetLayoutChildrenMixin = {}
-- Replace GetLayout to not create a table every time
function noTableGetLayoutChildrenMixin:GetLayoutChildren()
if (not self.children) then
self.children = {};
end
wipe(self.children);
local children = self.children;
self:AddLayoutChildren(children, self:GetChildren());
self:AddLayoutChildren(children, self:GetRegions());
self:AddLayoutChildren(children, self:GetAdditionalRegions());
if not self:IgnoreLayoutIndex() then
table.sort(children, LayoutIndexComparator);
end
return children;
end
WQT_HorizontalLayoutMixin = CreateFromMixins(HorizontalLayoutMixin, noTableGetLayoutChildrenMixin);
-- Arranges children right to left bottom to top with 'stride' children per column
-- A child's strideSize determines how many spaces it will take up per column
-- This is bare minimum for a for a specific use case
WQT_GridLayoutMixin = CreateFromMixins(LayoutMixin, noTableGetLayoutChildrenMixin);
function WQT_GridLayoutMixin:GetChildStrideSize(child)
return child.strideSize or 1;
end
function WQT_GridLayoutMixin:GetStride()
return self.stride or 1;
end
function WQT_GridLayoutMixin:LayoutChildren(children, expandToWidth, expandToHeight)
local frameLeftPadding, frameRightPadding, frameTopPadding, frameBottomPadding = self:GetPadding();
local spacing = self.spacing or 0;
local stride = self:GetStride();
local childrenWidth, childrenHeight = 0, 0;
local hasExpandableChild = false;
local totalStride = 0;
local columnMax = 0;
local columCurrent = 0;
local rightOffset = 0;
local columnHeight = 0;
local columnWidth = 0;
for i, child in ipairs(children) do
if (not self.skipChildLayout and IsLayoutFrame(child)) then
child:Layout();
end
local leftPadding, rightPadding, topPadding, bottomPadding = self:GetChildPadding(child);
local childWidth, childHeight = self:GetChildSize(child);
local strideSize = min(self:GetChildStrideSize(child), stride);
if (totalStride % stride == 0) then
childrenWidth = childrenWidth + columnWidth;
rightOffset = childrenWidth;
columnHeight = 0;
columnWidth = 0;
end
columnWidth = max(columnWidth, childWidth + leftPadding + rightPadding);
child:ClearAllPoints();
child:SetPoint("BOTTOMRIGHT", self, -rightOffset - frameRightPadding - rightPadding, columnHeight + bottomPadding);
columnHeight = columnHeight + childHeight + bottomPadding + topPadding;
childrenHeight = max(childrenHeight, columnHeight);
columnMax = max(columnMax, columCurrent)
totalStride = totalStride + strideSize;
end
childrenWidth = childrenWidth + columnWidth;
return childrenWidth, childrenHeight, hasExpandableChild;
end
-- Allow children to spread across the space left over in the parent's size
-- If a parent has size 150, a child with size 30, a child with flexSize 2, and a child with flexSize 3
-- The children would end up with sizes 30, 48 (2/5*120), 72 (3/5*120)
local flexLayoutFrame = CreateFromMixins(LayoutMixin, noTableGetLayoutChildrenMixin);
function flexLayoutFrame:GetChildFlexSize(child)
return child.flexSize or 0;
end
WQT_HorizontalFlexLayoutMixin = CreateFromMixins(flexLayoutFrame);
function WQT_HorizontalFlexLayoutMixin:LayoutChildren(children, expandToWidth, expandToHeight)
local frameLeftPadding, frameRightOffset, frameTopPadding, frameBottomPadding = self:GetPadding();
local width = self:GetWidth() - frameLeftPadding - frameRightOffset;
local height = self:GetHeight() - frameTopPadding - frameBottomPadding;
local spacing = self.spacing or 0;
local hasExpandableChild = false;
local availableFlexSpace = width;
local totalflexSize = 0;
for i, child in ipairs(children) do
if (not self.skipChildLayout and IsLayoutFrame(child)) then
child:Layout();
end
local flexSize = self:GetChildFlexSize(child);
if (flexSize > 0) then
totalflexSize = totalflexSize + self:GetChildFlexSize(child);
else
availableFlexSpace = availableFlexSpace - self:GetChildWidth(child);
end
local leftPadding, rightPadding, topPadding, bottomPadding = self:GetChildPadding(child);
availableFlexSpace = availableFlexSpace - leftPadding - rightPadding;
if (i > 1) then
availableFlexSpace = availableFlexSpace - spacing;
end
end
local flexSpaceChunk = totalflexSize > 1 and availableFlexSpace / totalflexSize or availableFlexSpace;
for i, child in ipairs(children) do
local leftPadding, rightPadding, topPadding, bottomPadding = self:GetChildPadding(child);
local childWidth, childHeight = self:GetChildSize(child);
if (child.expand) then
hasExpandableChild = true;
if expandToHeight then
childHeight = expandToHeight - topPadding - bottomPadding - frameTopPadding - frameBottomPadding;
child:SetHeight(childHeight);
local ignoreRectYes = true;
childWidth = self:GetChildWidth(child, ignoreRectYes);
end
end
local flexSize = self:GetChildFlexSize(child);
if (flexSize > 0) then
childWidth = flexSize * flexSpaceChunk;
child:SetWidth(childWidth);
if (IsLayoutFrame(child)) then
child:SetFixedWidth(childWidth);
if (not self.skipChildLayout) then
child:Layout();
end
end
end
child:ClearAllPoints();
frameLeftPadding = frameLeftPadding + leftPadding;
if (child.align == "bottom") then
local bottomOffset = frameBottomPadding + bottomPadding;
child:SetPoint("BOTTOMLEFT", frameLeftPadding, bottomOffset);
elseif (child.align == "center") then
local topOffset = (frameTopPadding - frameBottomPadding + topPadding - bottomPadding) / 2;
child:SetPoint("LEFT", frameLeftPadding, -topOffset);
else
local topOffset = frameTopPadding + topPadding;
child:SetPoint("TOPLEFT", frameLeftPadding, -topOffset);
end
frameLeftPadding = frameLeftPadding + childWidth + rightPadding + spacing;
end
return width, height, hasExpandableChild;
end
WQT_VerticalFlexLayoutMixin = CreateFromMixins(flexLayoutFrame);
function WQT_VerticalFlexLayoutMixin:LayoutChildren(children, expandToWidth, expandToHeight)
local frameLeftPadding, frameRightPadding, frameTopPadding, frameBottomPadding = self:GetPadding();
local width = self:GetWidth() - frameLeftPadding - frameRightPadding;
local height = self:GetHeight() - frameTopPadding - frameBottomPadding;
local spacing = self.spacing or 0;
local hasExpandableChild = false;
local availableFlexSpace = height;
local totalflexSize = 0;
for i, child in ipairs(children) do
if (not self.skipChildLayout and IsLayoutFrame(child)) then
child:Layout();
end
local flexSize = self:GetChildFlexSize(child);
if (flexSize > 0) then
totalflexSize = totalflexSize + self:GetChildFlexSize(child);
else
availableFlexSpace = availableFlexSpace - self:GetChildHeight(child);
end
local _, _, topPadding, bottomPadding = self:GetChildPadding(child);
availableFlexSpace = availableFlexSpace - topPadding - bottomPadding;
if (i > 1) then
availableFlexSpace = availableFlexSpace - spacing;
end
end
local flexSpaceChunk = totalflexSize > 1 and availableFlexSpace / totalflexSize or availableFlexSpace;
for i, child in ipairs(children) do
local leftPadding, rightPadding, topPadding, bottomPadding = self:GetChildPadding(child);
local childWidth, childHeight = self:GetChildSize(child);
if (child.expand) then
hasExpandableChild = true;
if (expandToWidth) then
childWidth = expandToWidth - leftPadding - rightPadding - frameLeftPadding - frameRightPadding;
child:SetWidth(childWidth);
local ignoreRectYes = true;
childHeight = self:GetChildHeight(child, ignoreRectYes);
end
end
local flexSize = self:GetChildFlexSize(child);
if (flexSize > 0) then
childHeight = flexSize * flexSpaceChunk;
child:SetHeight(childHeight);
if (IsLayoutFrame(child)) then
child:SetFixedHeight(childHeight);
if (not self.skipChildLayout) then
child:Layout();
end
end
end
child:ClearAllPoints();
frameTopPadding = frameTopPadding + topPadding;
if (child.align == "right") then
local rightOffset = frameRightPadding + rightPadding;
child:SetPoint("TOPRIGHT", -rightOffset, -frameTopPadding);
elseif (child.align == "center") then
local leftOffset = (frameLeftPadding - frameRightPadding + leftPadding - rightPadding) / 2;
child:SetPoint("TOP", leftOffset, -frameTopPadding);
else
local leftOffset = frameLeftPadding + leftPadding;
child:SetPoint("TOPLEFT", leftOffset, -frameTopPadding);
end
-- Determine topOffset for next frame
frameTopPadding = frameTopPadding + childHeight + bottomPadding + spacing;
end
return width, height, hasExpandableChild;
end
----------------------------
-- Utilities
----------------------------
local cachedTypeData = {};
local function stringVersionToNumber(s)
local a, b, c = strmatch(s, "(%d+)%.(%d+)%.(%d+)");
if (not a) then return 0; end
return tonumber(a) * 10000 + tonumber(b) * 100 + tonumber(c);
end
function WQT_Utils:GetAddonVersion()
local version = C_AddOns.GetAddOnMetadata(addonName, "version");
return stringVersionToNumber(version);
end
function WQT_Utils:GetSettingsVersion()
local version = WQT.db.global.versionCheck or 0;
if (type(version) == "string") then
local number = stringVersionToNumber(version);
return number, version;
end
return version;
end
function WQT_Utils:GetSetting(...)
local settings = WQT.settings;
local index = 1;
local param = select(index, ...);
while (param ~= nil) do
if(settings[param] == nil) then
return nil
end;
settings = settings[param];
index = index + 1;
param = select(index, ...);
end
if (type(settings) == "table") then
return nil
end;
return settings;
end
function WQT_Utils:GetCachedTypeIconData(questInfo)
local tagInfo = questInfo:GetTagInfo();
-- If there is no tag info, it's a bonus objective
if (questInfo.isBonusQuest or not tagInfo) then
return "Bonus-Objective-Star", 16, 16, false;
end
local tagID = tagInfo.tagID or 0;
local cachedData = cachedTypeData[tagID];
if (not cachedData) then
-- creating basetype
cachedData = {};
local atlasTexture, sizeX, sizeY = QuestUtil.GetWorldQuestAtlasInfo(questInfo.questID, tagInfo);
cachedData.texture = atlasTexture;
cachedData.x = sizeX;
cachedData.y = sizeY;
cachedTypeData[tagID] = cachedData;
end
return cachedData.texture or "", cachedData.x or 0, cachedData.y or 0;
end
function WQT_Utils:GetQuestTimeString(questInfo, fullString, unabreviated)
local timeLeftMinutes = 0
local timeLeftSeconds = 0
local timeString = "";
local timeStringShort = "";
local color = WQT_Utils:GetColor("timeNone");
local enumTimeRemaining = _V:GetTimeRemainingEnum();
local category = enumTimeRemaining.none;
if (not questInfo or not questInfo.questID) then return timeLeftSeconds, timeString, color ,timeStringShort, timeLeftMinutes, category end
-- Time ran out, waiting for an update
if (questInfo:IsExpired()) then
timeString = RAID_INSTANCE_EXPIRES_EXPIRED;
timeStringShort = "Exp."
color = GRAY_FONT_COLOR;
return 0, timeString, color,timeStringShort , 0, enumTimeRemaining.expired;
end
timeLeftMinutes = C_TaskQuest.GetQuestTimeLeftMinutes(questInfo.questID) or 0;
timeLeftSeconds = C_TaskQuest.GetQuestTimeLeftSeconds(questInfo.questID) or 0;
if ( timeLeftSeconds and timeLeftSeconds > 0) then
local displayTime = timeLeftSeconds
if (displayTime < SECONDS_PER_HOUR and displayTime >= SECONDS_PER_MIN ) then
displayTime = displayTime + SECONDS_PER_MIN ;
end
if ( timeLeftSeconds < WORLD_QUESTS_TIME_CRITICAL_MINUTES * SECONDS_PER_MIN ) then
color = WQT_Utils:GetColor("timeCritical");
timeString = SecondsToTime(displayTime, displayTime > SECONDS_PER_MIN and (not fullString) or false, unabreviated);
category = enumTimeRemaining.critical;
elseif displayTime < SECONDS_PER_HOUR then
timeString = SecondsToTime(displayTime, not fullString, unabreviated);
color = WQT_Utils:GetColor("timeShort");
category = enumTimeRemaining.short
elseif displayTime < SECONDS_PER_DAY then
if (fullString) then
timeString = SecondsToTime(displayTime, true, unabreviated);
else
timeString = D_HOURS:format(displayTime / SECONDS_PER_HOUR);
end
color = WQT_Utils:GetColor("timeMedium");
category = enumTimeRemaining.medium;
else
if (fullString) then
timeString = SecondsToTime(displayTime, true, unabreviated);
else
timeString = D_DAYS:format(displayTime / SECONDS_PER_DAY );
end
local tagInfo = questInfo:GetTagInfo();
local isWeek = tagInfo and tagInfo.isElite and tagInfo.quality == Enum.WorldQuestQuality.Epic
if (isWeek) then
color = WQT_Utils:GetColor("timeVeryLong");
category = enumTimeRemaining.veryLong;
else
color = WQT_Utils:GetColor("timeLong");
category = enumTimeRemaining.long;
end
end
end
-- start with default, for CN and KR
timeStringShort = timeString;
local t, str = string.match(timeString:gsub(" |4", ""), '(%d+)(%a)');
if t and str then
timeStringShort = t..str;
end
return timeLeftSeconds, timeString, color, timeStringShort ,timeLeftMinutes, category;
end
function WQT_Utils:GetPinTime(questInfo)
local seconds, _, color, timeStringShort, _, category = WQT_Utils:GetQuestTimeString(questInfo);
local start = 0;
local timeLeft = seconds;
local total = 0;
local maxTime, offset;
if (timeLeft > 0) then
if timeLeft >= 1440*60 then
maxTime = 5760*60;
offset = -720*60;
local tagInfo = questInfo:GetTagInfo();
if (timeLeft > maxTime or (tagInfo and tagInfo.isElite and tagInfo.quality == Enum.WorldQuestQuality.Epic)) then
maxTime = 1440 * 7*60;
offset = 0;
end
elseif timeLeft >= 60*59 then --Minute display doesn't start until 59min left
maxTime = 1440*60;
offset = 60*60;
elseif timeLeft >= 15*60 then
maxTime= 60*60;
offset = -10*60;
else
maxTime = 15*60;
offset = 0;
end
start = (maxTime - timeLeft);
total = (maxTime + offset);
timeLeft = (timeLeft + offset);
end
return start, total, timeLeft, seconds, color, timeStringShort, category;
end
function WQT_Utils:TimeLeftToUpdateTime(timeLeft, showingSecondary)
if (timeLeft and timeLeft > 0) then
local minutesForUpdatePerSecond = showingSecondary and 60 or 2;
return timeLeft > SECONDS_PER_MIN * minutesForUpdatePerSecond and SECONDS_PER_MIN or 1;
end
return 0;
end
function WQT_Utils:ShowQuestTooltip(button, questInfo, style, xOffset, yOffset)
style = style or _V:GetTooltipStyle("default");
WQT:ShowDebugTooltipForQuest(questInfo, button);
if (not button.UpdateTooltip) then
button.UpdateTooltip = function() self:ShowQuestTooltip(button, questInfo, style, xOffset, yOffset) end;
end
WQT_ActiveGameTooltip:SetOwner(button, "ANCHOR_RIGHT", xOffset or 0, yOffset or 0);
-- In case we somehow don't have data on this quest, even through that makes no sense at this point
if (not questInfo.questID or not HaveQuestData(questInfo.questID)) then
GameTooltip_SetTitle(WQT_ActiveGameTooltip, RETRIEVING_DATA, RED_FONT_COLOR);
GameTooltip_SetTooltipWaitingForData(WQT_ActiveGameTooltip, true);
WQT_ActiveGameTooltip:Show();
return;
end
local title, factionID, capped = C_TaskQuest.GetQuestInfoByQuestID(questInfo.questID);
local tagInfo = questInfo:GetTagInfo();
local qualityColor = WORLD_QUEST_QUALITY_COLORS[tagInfo and tagInfo.quality or Enum.WorldQuestQuality.Common];
-- title
GameTooltip_SetTitle(WQT_ActiveGameTooltip, title, qualityColor.color, true);
-- fml
if (WQT_ActiveGameTooltip == WQT_GameTooltip) then
local text = "WQT anti-error tooltip|nCan be turned off in the settings";
GameTooltip_AddColoredLine(WQT_ActiveGameTooltip, text, GRAY_FONT_COLOR);
end
-- type
if (not style.hideType) then
if (tagInfo and tagInfo.worldQuestType) then
QuestUtils_AddQuestTypeToTooltip(WQT_ActiveGameTooltip, questInfo.questID, NORMAL_FONT_COLOR);
end
end
-- faction
if ( factionID ) then
local factionData = C_Reputation.GetFactionDataByID(factionID)
local factionName = factionData and factionData.name;
if ( factionName ) then
if (capped) then
WQT_ActiveGameTooltip:AddLine(factionName, GRAY_FONT_COLOR:GetRGB());
else
WQT_ActiveGameTooltip:AddLine(factionName);
end
end
end
-- Add time
local seconds, timeString, timeColor, _, _, category = WQT_Utils:GetQuestTimeString(questInfo, true, true);
local enumTimeRemaining = _V:GetTimeRemainingEnum();
if (seconds > 0 or category == enumTimeRemaining.expired) then
timeColor = seconds <= SECONDS_PER_HOUR and timeColor or HIGHLIGHT_FONT_COLOR;
timeString = timeColor:WrapTextInColorCode(timeString);
GameTooltip_AddNormalLine(WQT_ActiveGameTooltip, MAP_TOOLTIP_TIME_LEFT:format(timeString));
end
if (not style.hideObjectives) then
local numObjectives = C_QuestLog.GetNumQuestObjectives(questInfo.questID);
for objectiveIndex = 1, numObjectives do
local objectiveText, objectiveType, finished = GetQuestObjectiveInfo(questInfo.questID, objectiveIndex, false);
if ( objectiveText and #objectiveText > 0 ) then
local objectiveColor = finished and GRAY_FONT_COLOR or HIGHLIGHT_FONT_COLOR;
WQT_ActiveGameTooltip:AddLine(QUEST_DASH .. objectiveText, objectiveColor.r, objectiveColor.g, objectiveColor.b, true);
end
-- Add a progress bar if that's the type
if(objectiveType == "progressbar") then
local percent = GetQuestProgressBarPercent(questInfo.questID);
GameTooltip_ShowProgressBar(WQT_ActiveGameTooltip, 0, 100, percent, PERCENTAGE_STRING:format(percent));
end
end
end
if (questInfo.reward.type == WQT_REWARDTYPE.missing) then
WQT_ActiveGameTooltip:AddLine(RETRIEVING_DATA, RED_FONT_COLOR.r, RED_FONT_COLOR.g, RED_FONT_COLOR.b);
elseif (questInfo:GetReward(1)) then
GameTooltip_AddBlankLinesToTooltip(WQT_ActiveGameTooltip, style.prefixBlankLineCount);
if style.headerText and style.headerColor then
GameTooltip_AddColoredLine(WQT_ActiveGameTooltip, style.headerText, style.headerColor, style.wrapHeaderText);
end
GameTooltip_AddBlankLinesToTooltip(WQT_ActiveGameTooltip, style.postHeaderBlankLineCount);
QuestUtils_AddQuestRewardsToTooltip(WQT_ActiveGameTooltip, questInfo.questID, style);
end
WQT_ActiveGameTooltip:Show();
end
function WQT_Utils:HideQuestTooltip(button)
button.UpdateTooltip = nil;
WQT_ActiveGameTooltip:Hide();
WQT_ActiveGameTooltip.ItemTooltip:Hide();
WQT:HideDebugTooltip();
end
-- Climb map parents until the first continent type map it can find.
function WQT_Utils:GetContinentForMap(mapId)
local info = _V:GetCachedMapInfo(mapId);
if not info then return mapId; end
local parent = info.parentMapID;
if not parent or info.mapType <= Enum.UIMapType.Continent then
return mapId, info.mapType
end
return self:GetContinentForMap(parent);
end
function WQT_Utils:GetMapWQProvider()
if WQT.mapWQProvider then return WQT.mapWQProvider; end
for k in pairs(WorldMapFrame.dataProviders) do
for k1 in pairs(k) do
if k1=="IsMatchingWorldMapFilters" then
WQT.mapWQProvider = k;
break;
end
end
end
return WQT.mapWQProvider;
end
function WQT_Utils:GetFlightWQProvider()
if (WQT.FlightmapPins) then return WQT.FlightmapPins; end
if (not FlightMapFrame) then return nil; end
local wqPinTemplate = FlightMap_WorldQuestDataProviderMixin:GetPinTemplate();
for k in pairs(FlightMapFrame.dataProviders) do
if (k.GetPinTemplate and k:GetPinTemplate() == wqPinTemplate) then
WQT.FlightmapPins = k;
break;
end
end
return WQT.FlightmapPins;
end
function WQT_Utils:QuestIncorrectlyCounts(questLogIndex)
local questInfo = C_QuestLog.GetInfo(questLogIndex);
if (not questInfo or questInfo.isHeader or questInfo.isTask or questInfo.isBounty) then
return false, questInfo.isHidden;
end
local tagInfo = C_QuestLog.GetQuestTagInfo(questInfo.questID);
if (tagInfo and tagInfo.tagID == 102) then
return true, questInfo.isHidden;
end
end
function WQT_Utils:QuestIsWatchedManual(questId)
return questId and C_QuestLog.GetQuestWatchType(questId) == Enum.QuestWatchType.Manual;
end
function WQT_Utils:QuestIsWatchedAutomatic(questId)
return questId and C_QuestLog.GetQuestWatchType(questId) == Enum.QuestWatchType.Automatic;
end
function WQT_Utils:GetQuestMapLocation(questInfo, mapID)
local x, y = C_TaskQuest.GetQuestLocation(questInfo.questID, mapID);
if (x and y) then
return x, y;
end
local childData, boundryZoneID = _V:GetMostRelevantMapCoordinates(questInfo.mapID, mapID);
local clusterData = childData and childData.pinClusterData;
if (clusterData) then
if (clusterData.NudgeFunction) then
-- Cluster data with its own function gets handled in pin placement
return childData.x, childData.y, clusterData;
else
local selfx, selfy = C_TaskQuest.GetQuestLocation(questInfo.questID, boundryZoneID);
if (not selfx) then
-- We know there is a map link, but don't have coordinates on this map
-- Just put it in the center as any more precice checking is a waste here
selfx = 0.5;
selfy = 0.5;
end
x = clusterData.xMin + selfx * (clusterData.xMax - clusterData.xMin);
y = clusterData.yMin + selfy * (clusterData.yMax - clusterData.yMin);
return x, y;
end
end
-- Could not get a position
return 0, 0;
end
function WQT_Utils:CalculateWarmodeAmount(rewardInfo)
if (not rewardInfo) then return 0; end
local amount = rewardInfo.amount or 1;
if (not C_PvP.IsWarModeDesired()) then
return amount;
end
local isCurrencyType = rewardInfo.type == WQT_REWARDTYPE.currency or rewardInfo.type == WQT_REWARDTYPE.artifact;
local isWarmodeRewardType = isCurrencyType or rewardInfo.type == WQT_REWARDTYPE.gold or rewardInfo.type == WQT_REWARDTYPE.currency;
if (not isWarmodeRewardType) then
return amount;
end
if (isCurrencyType and rewardInfo.id
and (not C_CurrencyInfo.DoesWarModeBonusApply(rewardInfo.id)
or C_CurrencyInfo.GetFactionGrantedByCurrency(rewardInfo.id))) then
return amount;
end
return amount + floor(amount * C_PvP.GetWarModeRewardBonus() / 100);
end
function WQT_Utils:DeepWipeTable(t)
for k, v in pairs(t) do
if (type(v) == "table") then
self:DeepWipeTable(v)
end
end
wipe(t);
t = nil;
end
function WQT_Utils:RegisterExternalSettings(key, defaults)
return WQT_Profiles:RegisterExternalSettings(key, defaults);
end
local function AddInstructionTooltipToDropdownItem(item, text)
item:SetOnEnter(function(button)
WQT_ActiveGameTooltip:SetOwner(button, "ANCHOR_RIGHT");
GameTooltip_AddInstructionLine(WQT_ActiveGameTooltip, text);
WQT_ActiveGameTooltip:Show();
end);
item:SetOnLeave(function(button)
WQT_ActiveGameTooltip:Hide();
end);
end
local function QuestContextSetup(frame, rootDescription, questInfo)
rootDescription:SetTag("WQT_QUEST_CONTEXTMENU", questInfo);
-- Title
rootDescription:CreateTitle(questInfo.title);
-- Tracking here
if (questInfo.tagInfo and questInfo.tagInfo.worldQuestType) then
local title = ""
local func = nil;
if (QuestUtils_IsQuestWatched(questInfo.questID)) then
title = UNTRACK_QUEST;
func = function()
C_QuestLog.RemoveWorldQuestWatch(questInfo.questID);
if WQT_WorldQuestFrame:GetAlpha() > 0 then
WQT_ListContainer:DisplayQuestList();
end
end
else
title = TRACK_QUEST;
func = function()
C_QuestLog.AddWorldQuestWatch(questInfo.questID, Enum.QuestWatchType.Manual);
C_SuperTrack.SetSuperTrackedQuestID(questInfo.questID);
if WQT_WorldQuestFrame:GetAlpha() > 0 then
WQT_ListContainer:DisplayQuestList();
end
end
end
local trackBtn = rootDescription:CreateButton(title, func);
AddInstructionTooltipToDropdownItem(trackBtn, _L:Get("SHORTCUT_TRACK"));
end
-- 9.0 waypoint
local waypointBtn = rootDescription:CreateButton(
_L:Get("PLACE_MAP_PIN"),