forked from Tga123/WorldQuestTab
-
Notifications
You must be signed in to change notification settings - Fork 2
/
MapPinProvider.lua
990 lines (845 loc) · 29.5 KB
/
MapPinProvider.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
local addonName, addon = ...
local WQT = addon.WQT;
local _L = addon.L
local _V = addon.variables;
local WQT_Utils = addon.WQT_Utils;
local _pinType = {
["zone"] = 1
,["continent"] = 2
,["world"] = 3
}
local _pinTypeScales = {
[_pinType.zone] = 1
,[_pinType.continent] = 1
,[_pinType.world] = 0.5
}
local ICON_ANGLE_START = 270;
local ICON_ANGLE_DISTANCE = 50;
local ICON_CENTER_DISTANCE = 13;
local ICON_MAX_AMOUNT = floor(360/ICON_ANGLE_DISTANCE);
local PIN_FRAME_LEVEL_BASE = 2200;
local PIN_FRAME_LEVEL_FOCUS = 3000;
------------------------------------
-- Locals
------------------------------------
local function SortPinsByMapPos(a, b)
local aX, aY = a:GetNudgedPosition();
local bX, bY = b:GetNudgedPosition();
if (aX and bX) then
-- If 2 pins are close with the left being slightly higher, we still want left to be in front
if (aY ~= bY) then
return aY < bY;
else
if (aX ~= bY) then
return aX > bX;
end
end
end
return a.questID < b.questID;
end
local function OnPinRelease(pool, pin)
pin:ClearFocus();
pin.questID = nil;
pin.nudgeX = 0;
pin.nudgeY = 0;
pin.updateTime = 0;
pin.updateInterval = 1;
pin.isExpired = false;
pin.isFaded = false;
pin.timeIcon = nil;
pin:Hide();
pin:ClearAllPoints();
end
local function ShouldShowPin(questInfo, mapType, settingsZoneVisible, settingsPinContinent, settingsFilterPins, isFlightMap)
-- Don't show if not valid
if (not questInfo.isValid) then return false; end
-- Don't show if filtering and doesn't pass
if (settingsFilterPins and not questInfo.passedFilter) then return false; end
if (isFlightMap) then return true; end
if (mapType == Enum.UIMapType.Continent) then
-- Never show on continent
if (settingsPinContinent == _V["ENUM_PIN_CONTINENT"].none) then
return false;
end
-- Show only if tracked
if (settingsPinContinent == _V["ENUM_PIN_CONTINENT"].tracked and not C_QuestLog.GetQuestWatchType(questInfo.questID)) then
return false;
end
elseif (mapType >= Enum.UIMapType.Zone) then
-- Never show on zone
if (settingsZoneVisible == _V["ENUM_PIN_ZONE"].none) then
return false;
end
-- Show only if tracked
if (settingsZoneVisible == _V["ENUM_PIN_ZONE"].tracked and not C_QuestLog.GetQuestWatchType(questInfo.questID)) then
return false;
end
end
return true;
end
local function GetPinType(mapType)
if (mapType == Enum.UIMapType.Continent) then
return _pinType.continent;
end
return _pinType.zone;
end
------------------------------------
-- DataProvider
------------------------------------
WQT_PinDataProvider = {};
function WQT_PinDataProvider:Init()
self.frame = CreateFrame("FRAME");
self.frame:SetScript("OnEvent", function(frame, ...) self:OnEvent(...); end);
self.frame:RegisterEvent("SUPER_TRACKING_CHANGED");
self.frame:RegisterEvent("QUEST_WATCH_LIST_CHANGED");
self.pinPool = CreateFramePool("BUTTON", nil, "WQT_PinTemplate", OnPinRelease);
self.activePins = {};
self.pingedQuests = {};
self.hookedCanvasChanges = {};
WQT_WorldQuestFrame:RegisterCallback("UpdateQuestList", function()
self:RefreshAllData();
end, addonName);
-- Fix pings and fades when switching map
-- hooksecurefunc(WorldMapFrame, "OnMapChanged", function()
-- wipe(self.pingedQuests);
-- self:UpdateQuestPings();
-- end);
EventRegistry:RegisterCallback("MapCanvas.MapSet", function()
-- Now we do it modern way.
wipe(self.pingedQuests);
self:UpdateQuestPings();
end);
self.clusterDistance = 0.5;
self.clusterSpread = 0.2;
self.enableNudging = true;
self.pinClusters = {};
self.pinClusterLookup = {};
end
function WQT_PinDataProvider:OnEvent(event, ...)
if (event == "SUPER_TRACKING_CHANGED") then
self.pinPool:ReleaseAll();
wipe(self.activePins);
wipe(self.pinClusters);
wipe(self.pinClusterLookup);
self:PlacePins();
self:UpdateQuestPings()
elseif (event == "QUEST_WATCH_LIST_CHANGED") then
self:UpdateAllVisuals();
end
end
function WQT_PinDataProvider:RemoveAllData()
self.pinPool:ReleaseAll();
wipe(self.activePins);
wipe(self.pingedQuests);
wipe(self.pinClusters);
wipe(self.pinClusterLookup);
end
function WQT_PinDataProvider:RefreshAllData()
-- Protection against coroutines I guess.
-- TaskPOI_OnEnter can trigger this function a second time when the first one isn't done yet
if (self.isUpdating) then
return;
end
self.isUpdating = true;
self:RemoveAllData();
self:PlacePins();
self.isUpdating = false;
end
function WQT_PinDataProvider:PlacePins()
local wqp = WQT_Utils:GetMapWQProvider();
--self:RemoveAllData();
if (WQT_Utils:GetSetting("pin", "disablePoI")) then
self.isUpdating = false;
return;
end
WQT_WorldQuestFrame:HideOfficialMapPins();
local parentMapFrame;
local isFlightMap = false;
if (WorldMapFrame:IsShown()) then
parentMapFrame = WorldMapFrame;
elseif (FlightMapFrame and FlightMapFrame:IsShown()) then
isFlightMap = true;
parentMapFrame = FlightMapFrame;
end
if (not parentMapFrame) then
self.isUpdating = false;
return;
end
local mapID = parentMapFrame:GetMapID();
local settingsContinentPins = WQT_Utils:GetSetting("pin", "continentPins");
local settingsContinentVisible = WQT_Utils:GetSetting("pin", "continentVisible");
local settingsZoneVisible = WQT_Utils:GetSetting("pin", "zoneVisible");
local settingsFilterPoI = WQT_Utils:GetSetting("pin", "filterPoI");
local mapInfo = WQT_Utils:GetCachedMapInfo(mapID);
local canvas = parentMapFrame:GetCanvas();
wipe(self.activePins);
if (mapInfo.mapType >= Enum.UIMapType.Continent) then
for k, questInfo in ipairs(WQT_WorldQuestFrame.dataProvider:GetIterativeList()) do
local officialShow = true;
if (wqp.focusedQuestID) then
officialShow = C_QuestLog.IsQuestCalling(wqp.focusedQuestID) and wqp:ShouldSupertrackHighlightInfo(questInfo.questID);
end
if (officialShow and ShouldShowPin(questInfo, mapInfo.mapType, settingsZoneVisible, settingsContinentVisible, settingsFilterPoI, isFlightMap)) then
local pinType = GetPinType(mapInfo.mapType);
local posX, posY = WQT_Utils:GetQuestMapLocation(questInfo.questID, mapID);
if (posX and posX > 0 and posY > 0) then
local pin = self.pinPool:Acquire();
pin:SetParent(canvas);
tinsert(self.activePins, pin);
pin:Setup(questInfo, #self.activePins, posX, posY, pinType, parentMapFrame);
end
end
end
end
-- Slightly spread out overlapping pins
self:FixOverlaps(canvas);
self:UpdateQuestPings();
if (not self.hookedCanvasChanges[parentMapFrame]) then
hooksecurefunc(parentMapFrame, "OnCanvasScaleChanged", function()
self:FixOverlaps(canvas)
end);
self.hookedCanvasChanges[parentMapFrame] = true;
end
self.isUpdating = false;
end
function WQT_PinDataProvider:FixOverlaps(canvas)
if (not self.enableNudging or not canvas) then return; end
local canvasScale = 1/canvas:GetParent():GetCanvasScale();
local scaling = 25/(canvas:GetWidth() * canvas:GetParent():GetCanvasScale());
local canvasRatio = canvas:GetWidth() /canvas:GetHeight();
local clusterDistance = self.clusterDistance * scaling;
local clusterSpread = self.clusterSpread * scaling
local clusters = self.pinClusters;
local clusterdLookup = self.pinClusterLookup;
local cluster;
for k, pin in ipairs(self.activePins) do
pin:ResetNudge()
end
-- Put close proximity quests in a cluster.
for k1, pinA in ipairs(self.activePins) do
if (not clusterdLookup[k1]) then
for k2, pinB in ipairs(self.activePins) do
if (pinA ~= pinB) then
local aX, aY = pinA:GetNudgedPosition();
local bX, bY = pinB:GetNudgedPosition();
local distanceSquared = SquaredDistanceBetweenPoints(aX, aY, bX, bY);
if (distanceSquared < clusterDistance * clusterDistance) then
if (not cluster) then
cluster = {pinA, pinB}
else
tinsert(cluster, pinB);
end
clusterdLookup[k1] = true;
clusterdLookup[k2] = true;
local centerX, centerY = 0, 0;
for k, pin in ipairs(cluster) do
local pinX, pinY = pin:GetPosition();
centerX = centerX + pinX;
centerY = centerY + pinY;
end
centerX = centerX / #cluster;
centerY = centerY / #cluster;
for k, pin in ipairs(cluster) do
pin:SetNudge(centerX, centerY);
end
end
end
end
if (cluster) then
tinsert(clusters, cluster);
cluster = nil;
end
end
end
-- Spread out the quests in each cluster in a circle around the center point
-- Puts all quests in a circle around the center of the cluster. Works with small clusters.
local mapID = canvas:GetParent().mapID;
for kC, pins in ipairs(clusters) do
local centerX, centerY = pins[1]:GetNudgedPosition();
-- Keep pins in relatively the same localtion. This will make it so 2 pins don't switch positions once clustered
table.sort(pins, function(a, b)
local aX, aY = a:GetPosition();
local bX, bY = b:GetPosition();
-- Don't calculate same position or missing position
if (not aX or not bX or (aX == bX and aY == bY)) then
return a.questID < b.questID;
end
-- Keep in mind Y axis is inverse
local degA = math.deg(math.atan2((centerY - aY), (aX-centerX)));
local degB = math.deg(math.atan2((centerY - bY), (bX-centerX)));
degA = degA < 0 and degA+360 or degA;
degB = degB < 0 and degB+360 or degB;
return degA < degB;
end);
-- Get the rotation of the first pin. This is where we start placing them on the circle
local firstX, firstY = pins[1]:GetPosition();
local startAngle = math.deg(math.atan2((centerY - firstY), (firstX-centerX)));
local spread = clusterSpread;
-- Slightly increase spread distance based on number of pins in the cluster
if (#pins > 2) then
spread = spread + (#pins * 0.0005);
end
-- Place every pin at aqual distance
for kP, pin in ipairs(pins) do
local angle = -startAngle - (kP-1) * (360 / #pins);
local offsetX = cos(angle) * spread;
local offsetY = sin(angle) * spread * canvasRatio;
pin:SetNudge(centerX + offsetX, centerY + offsetY);
end
end
-- Sort pins to place them like dragon scales (lower is more in front)
table.sort(self.activePins, SortPinsByMapPos);
for k, pin in ipairs(self.activePins) do
pin.index = k;
pin:UpdatePlacement();
end
wipe(self.pinClusters);
wipe(self.pinClusterLookup);
end
function WQT_PinDataProvider:UpdateAllPlacements()
for pin in self.pinPool:EnumerateActive() do
pin:UpdatePlacement();
end
end
function WQT_PinDataProvider:UpdateAllVisuals()
for pin in self.pinPool:EnumerateActive() do
pin:UpdateVisuals();
end
end
function WQT_PinDataProvider:UpdateQuestPings()
local settingPinFadeOnPing = WQT_Utils:GetSetting("pin", "fadeOnPing");
local fadeOthers = false;
if (settingPinFadeOnPing) then
for pin in pairs(self.pingedQuests) do
fadeOthers = true;
break;
end
end
if (fadeOthers) then
for pin in self.pinPool:EnumerateActive() do
if (not self.pingedQuests[pin.questID])then
pin:FadeOut();
end
end
else
-- Delay until next frame to prevent freezing when quickly hovering over a lot of quests
if (not self.delayedFadeTimer) then
self.delayedFadeTimer = C_Timer.NewTicker(0, function()
self.delayedFadeTimer = nil;
if (settingPinFadeOnPing) then
for pin in pairs(self.pingedQuests) do
return;
end
end
for pin in self.pinPool:EnumerateActive() do
if (not self.pingedQuests[pin.questID])then
if (pin.isFaded) then
pin:FadeIn();
end
end
end
end, 1);
end
end
end
function WQT_PinDataProvider:SetQuestIDPinged(questID, shouldPing)
if (not questID) then return; end
self.pingedQuests[questID] = shouldPing or nil;
-- Official pins
if (WQT_Utils:GetSetting("pin", "disablePoI")) then
if (not shouldPing) then return; end
if (WorldMapFrame:IsShown()) then
local WQProvider = WQT_Utils:GetMapWQProvider();
if (WQProvider) then
WQProvider:PingQuestID(questID);
end
end
if (FlightMapFrame and FlightMapFrame:IsShown()) then
local FlightWQProvider = WQT_Utils:GetFlightWQProvider();
if (FlightWQProvider) then
FlightWQProvider:PingQuestID(questID);
end
end
return;
end
-- Custom pins
for pin in self.pinPool:EnumerateActive() do
if (pin.questID == questID) then
if (shouldPing) then
pin:Focus(true);
else
pin:ClearFocus();
end
break;
end
end
self:UpdateQuestPings();
end
------------------------------------
-- Pin
------------------------------------
WQT_PinMixin = {};
function WQT_PinMixin:OnLoad()
self.UpdateTooltip = function() WQT_Utils:ShowQuestTooltip(self, self.questInfo) end;
self:RegisterForClicks("LeftButtonUp", "RightButtonUp");
self.updateTime = 0;
self.iconPool = CreateFramePool("FRAME", self, "WQT_MiniIconTemplate", function(pool, iconFrame) iconFrame:Reset() end);
self.icons = {};
end
function WQT_PinMixin:SetupCanvasType(pinType, parentMapFrame, isWatched)
self.parentMapFrame = parentMapFrame;
self.scaleFactor = 1;
self.startScale = _pinTypeScales[pinType] or 1;
self.endScale = 1;
self.alphaFactor = 1;
self.startAlpha = 1;
self.endAlpha = 1;
if (FlightMapFrame and parentMapFrame == FlightMapFrame) then
self.alphaFactor = 2;
self.startAlpha = isWatched and 1 or 0;
self.endAlpha = 1.0;
end
end
function WQT_PinMixin:PlaceMiniIcons()
local numIcons = #self.icons;
if (numIcons > 0) then
local angle = ICON_ANGLE_START - (ICON_ANGLE_DISTANCE*(numIcons-1))/2
local numIcons = min(#self.icons, ICON_MAX_AMOUNT);
for i = 1, numIcons do
local iconFrame = self.icons[i];
iconFrame:SetPoint("CENTER", ICON_CENTER_DISTANCE * cos(angle), ICON_CENTER_DISTANCE * sin(angle));
iconFrame:Show();
angle = angle + ICON_ANGLE_DISTANCE;
end
end
end
function WQT_PinMixin:AddIcon()
local iconFrame = self.iconPool:Acquire();
tinsert(self.icons, iconFrame);
return iconFrame;
end
function WQT_PinMixin:SetIconsDesaturated(desaturate)
for k, icon in ipairs(self.icons) do
icon:SetDesaturated(desaturate);
end
end
function WQT_PinMixin:Setup(questInfo, index, x, y, pinType, parentMapFrame)
local isWatched = QuestUtils_IsQuestWatched(questInfo.questID);
self:SetupCanvasType(pinType, parentMapFrame, isWatched);
self.index = index;
self.questInfo = questInfo;
self.questID = questInfo.questID;
local scale = WQT_Utils:GetSetting("pin", "scale")
self.scale = scale
self:SetScale(scale);
self.currentScale = scale;
self:SetAlpha(self.startAlpha);
self.currentAlpha = self.startAlpha;
self:ResetNudge();
self.posX = x;
self.posY = y;
self.baseFrameLevel = PIN_FRAME_LEVEL_BASE;
self:UpdateVisuals();
WQT_WorldQuestFrame:TriggerCallback("MapPinInitialized", self);
end
function WQT_PinMixin:UpdateVisuals()
local questInfo = self.questInfo;
if (not questInfo:DataIsValid()) then return end;
local settingCenterType = WQT_Utils:GetSetting("pin", "centerType");
local _, _, _, timeStringShort = WQT_Utils:GetQuestTimeString(questInfo);
local tagInfo = questInfo:GetTagInfo();
local questQuality = tagInfo and tagInfo.quality;
local questType = tagInfo and tagInfo.worldQuestType;
local isDisliked = questInfo:IsDisliked();
local typeAtlas, typeAtlasWidth, typeAtlasHeight = WQT_Utils:GetCachedTypeIconData(questInfo);
local isWatched = QuestUtils_IsQuestWatched(questInfo.questID);
local hasWarbandBonus = questInfo:HasWarbandBonus();
-- Ring coloration
local ringType = WQT_Utils:GetSetting("pin", "ringType");
local now = time();
local r, g, b = _V["WQT_COLOR_CURRENCY"]:GetRGB();
self.RingBG:SetShown(ringType == _V["RING_TYPES"].time and 1 or 0);
self.Ring:SetCooldownUNIX(now, now);
self.Pointer:Hide();
self.Ring:Show();
self.RingBG:Show();
if (ringType == _V["RING_TYPES"].reward) then
r, g, b = questInfo:GetRewardColor():GetRGB();
elseif (questQuality and ringType == _V["RING_TYPES"].rarity) then
if (questQuality > Enum.WorldQuestQuality.Common and WORLD_QUEST_QUALITY_COLORS[questQuality]) then
r, g, b = WORLD_QUEST_QUALITY_COLORS[questQuality].color:GetRGB();
end
elseif (ringType == _V["RING_TYPES"].hide) then
self.Ring:Hide();
self.RingBG:Hide();
end
if (isDisliked) then
r, g, b = 1, 1, 1;
end
self.RingBG:SetVertexColor(r*0.25, g*0.25, b*0.25);
self.Ring:SetSwipeColor(r*.8, g*.8, b*.8);
-- Elite indicator
local isElite = tagInfo and tagInfo.isElite;
local isBoss = isElite and questQuality == Enum.WorldQuestQuality.Epic;
local settingEliteRing = WQT_Utils:GetSetting("pin", "eliteRing");
local useEliteRing = settingEliteRing and ringType ~= _V["RING_TYPES"].hide;
self.RingBG:SetTexture("Interface/Addons/WorldQuestTab/Images/PoIRing");
self.Ring:SetSwipeTexture("Interface/Addons/WorldQuestTab/Images/PoIRing");
if (useEliteRing) then
self.CustomUnderlay:SetShown(false);
if(isElite) then
self.RingBG:SetTexture("Interface/Addons/WorldQuestTab/Images/PoIRingElite");
self.Ring:SetSwipeTexture("Interface/Addons/WorldQuestTab/Images/PoIRingElite");
end
else
self.CustomUnderlay:SetShown(isElite);
end
self.CustomUnderlay:SetDesaturated(isDisliked);
-- Setup mini icons
self.iconPool:ReleaseAll();
wipe(self.icons);
-- Quest Type Icon
local typeAtlas = WQT_Utils:GetCachedTypeIconData(questInfo, false);
local showTypeIcon = WQT_Utils:GetSetting("pin", "typeIcon") and (not tagInfo or (questType and questType > 0 and questType ~= Enum.QuestTagType.Normal) or questInfo:IsSpecialType());
if (showTypeIcon and typeAtlas) then
local iconFrame = self:AddIcon();
iconFrame:SetupIcon(typeAtlas);
iconFrame:SetIconScale(questType == Enum.QuestTagType.PvP and 0.8 or 1);
end
-- Quest rarity Icon
if (questQuality and questQuality > Enum.WorldQuestQuality.Common and WQT_Utils:GetSetting("pin", "rarityIcon")) then
local color = WORLD_QUEST_QUALITY_COLORS[questQuality];
if (color) then
local iconFrame = self:AddIcon();
iconFrame:SetupIcon(_V["PATH_CUSTOM_ICONS"], 0, 0.25, 0, 0.5);
iconFrame:SetIconColor(color.color);
iconFrame:SetIconScale(1.15);
iconFrame:SetBackgroundShown(false);
end
end
-- Quest tracked icon
if (WQT_Utils:GetSetting("pin", "timeIcon")) then
local start, total, timeLeft, seconds, color, timeStringShort, timeCategory = WQT_Utils:GetPinTime(self.questInfo);
if (timeCategory >= _V["TIME_REMAINING_CATEGORY"].critical) then
local iconFrame = self:AddIcon();
iconFrame:SetupIcon(_V["PATH_CUSTOM_ICONS"], 0, 0.25, 0.5, 1);
if (timeCategory == _V["TIME_REMAINING_CATEGORY"].medium) then
iconFrame:SetIconCoords(0.25, 0.5, 0.5, 1);
elseif (timeCategory == _V["TIME_REMAINING_CATEGORY"].short) then
iconFrame:SetIconCoords(0.5, 0.75, 0.5, 1);
elseif (timeCategory == _V["TIME_REMAINING_CATEGORY"].critical) then
iconFrame:SetIconCoords(0.75, 1, 0.5, 1);
end
iconFrame:SetIconColor(color);
iconFrame:SetIconScale(1);
iconFrame:SetBackgroundShown(false);
self.timeIcon = iconFrame;
end
end
-- Reward Type Icon
local numRewardIcons = WQT_Utils:GetSetting("pin", "numRewardIcons");
for k, rewardInfo in questInfo:IterateRewards() do
if (k <= numRewardIcons) then
local iconFrame = self:AddIcon();
iconFrame:SetupRewardIcon(rewardInfo.type, rewardInfo.subType);
end
end
-- Quest tracked icon
if (isWatched) then
local iconFrame = self:AddIcon();
iconFrame:SetupIcon("worldquest-emissary-tracker-checkmark");
iconFrame:SetIconScale(1.1);
end
self:PlaceMiniIcons();
-- Main Icon
self.CustomTypeIcon:SetShown(false);
self.CustomSelectedGlow:Hide()
self.CustomBountyRing:Hide()
self.Icon:SetTexture("Interface/PETBATTLES/BattleBar-AbilityBadge-Neutral");
self.Icon:SetTexCoord(0.06, 0.93, 0.05, 0.93);
self.Icon:SetDesaturated(false);
self.Icon:SetScale(1);
self.Icon:Show();
self.InnerGlow:SetShown(false);
if(settingCenterType == _V["PIN_CENTER_TYPES"].reward) then
local rewardTexture = questInfo:GetRewardTexture();
self.Icon:SetTexture(rewardTexture);
self.Icon:SetTexCoord(0, 1, 0, 1);
elseif(settingCenterType == _V["PIN_CENTER_TYPES"].blizzard) then
self.CustomTypeIcon:SetShown(true);
local selected = questInfo.questID == C_SuperTrack.GetSuperTrackedQuestID();
local showSlectedGlow = tagInfo and questQuality ~= Enum.WorldQuestQuality.Common and selected;
local selectedBountyOnly = WQT_Utils:GetSetting("general", "bountySelectedOnly");
self.CustomBountyRing:SetShown(questInfo:IsCriteria(selectedBountyOnly));
self.CustomSelectedGlow:SetShown(showSlectedGlow);
if (tagInfo) then
self.Icon:SetTexture("Interface/WorldMap/UI-QuestPoi-NumberIcons");
if (selected) then
self.Icon:SetTexCoord(0.52, 0.605, 0.395, 0.48);
else
self.Icon:SetTexCoord(0.895, 0.98, 0.395, 0.48);
end
self.Icon:SetScale(1);
self.CustomTypeIcon:SetSize(typeAtlasWidth, typeAtlasHeight);
self.CustomTypeIcon:SetScale(1);
if questQuality == Enum.WorldQuestQuality.Epic then
self.CustomTypeIcon:SetAtlas("worldquest-questmarker-epic")
self.CustomSelectedGlow:SetAtlas("worldquest-questmarker-epic");
end
else
self.Icon:SetTexture("Interface/WorldMap/UI-QuestPoi-NumberIcons");
self.Icon:SetTexCoord(0.895, 0.98, 0.395, 0.48);
self.Icon:SetDesaturated(true);
end
-- Mimic default icon
if isBoss then
self.CustomTypeIcon:SetAtlas("worldquest-icon-boss");
else
local typeAtlas = WQT_Utils:GetCachedTypeIconData(questInfo, true);
self.CustomTypeIcon:SetAtlas(typeAtlas);
self.CustomTypeIcon:SetSize(typeAtlasWidth, typeAtlasHeight);
self.CustomTypeIcon:SetScale(1);
end
-- Add inner circle for callings
self.InnerGlow:SetShown(questInfo:IsQuestOfType(WQT_QUESTTYPE.calling));
elseif(settingCenterType == _V["PIN_CENTER_TYPES"].faction) then
local _, factionId = C_TaskQuest.GetQuestInfoByQuestID(questInfo.questID);
local factionData = WQT_Utils:GetFactionDataInternal(factionId);
self.Icon:SetTexture(factionData.texture);
elseif(settingCenterType == _V["PIN_CENTER_TYPES"].none) then
self.Icon:Hide();
end
if (isDisliked) then
self.Icon:SetDesaturated(true);
end
self.CustomTypeIcon:SetDesaturated(isDisliked);
-- Optional label
local settingPinOptionalLabel = WQT_Utils:GetSetting("pin", "optionalLabel");
if settingPinOptionalLabel == _V["OPTIONAL_LABEL_TYPES"].time then
local showTimeString = timeStringShort ~= "";
self.Time:SetShown(showTimeString);
self.TimeBG:SetShown(showTimeString);
local timeOffset = 4;
if(#self.icons > 0) then
timeOffset = (#self.icons % 2 == 0) and 2 or 0;
end
self.Time:SetPoint("TOP", self, "BOTTOM", 1, timeOffset);
elseif settingPinOptionalLabel == _V["OPTIONAL_LABEL_TYPES"].amount then
local topreward = questInfo.rewardList[1];
local showAmount = false;
if topreward and topreward.amount and topreward.amount > 1 then
local r, g, b = 1, 1, 1;
local amount = topreward.amount;
if topreward.type == WQT_REWARDTYPE.gold then
amount = floor(amount / 10000);
end
if topreward.type == WQT_REWARDTYPE.equipment then
r, g, b = topreward.textColor.r, topreward.textColor.g, topreward.textColor.b;
end
self.Time:SetText(amount);
self.Time:SetVertexColor(r, g, b);
local timeOffset = 4;
if(#self.icons > 0) then
timeOffset = (#self.icons % 2 == 0) and 2 or 0;
end
self.Time:SetPoint("TOP", self, "BOTTOM", 1, timeOffset);
showAmount = true;
end
self.Time:SetShown(showAmount);
self.TimeBG:SetShown(showAmount);
else
self.Time:Hide();
self.TimeBG:Hide();
end
-- Warband bonus icon
local settingPinWarbandBonus = WQT_Utils:GetSetting("pin", "showWarbandBonus");
if hasWarbandBonus then
self.WarbandBonusIcon:SetShown(settingPinWarbandBonus);
else
self.WarbandBonusIcon:SetShown(false);
end
self:SetIconsDesaturated(isDisliked);
self:UpdatePinTime();
self:UpdatePlacement();
end
function WQT_PinMixin:OnUpdate(elapsed)
self.updateTime = self.updateTime + elapsed;
if (self.isExpired or self.updateTime < self.updateInterval) then return; end
self.updateTime = self.updateTime - self.updateInterval;
local timeLeft = self:UpdatePinTime();
-- For the last minute we want to update every second for the time label
self.updateInterval = timeLeft > SECONDS_PER_MIN * 16 and 60 or 1;
end
function WQT_PinMixin:UpdatePinTime()
local start, total, timeLeft, seconds, color, timeStringShort, timeCategory = WQT_Utils:GetPinTime(self.questInfo);
local isDisliked = self.questInfo:IsDisliked();
if (WQT_Utils:GetSetting("pin", "ringType") == _V["RING_TYPES"].time) then
local r, g, b = color:GetRGB();
local now = time();
self.Pointer:SetShown(total > 0);
if (isDisliked) then
r, g, b = .8, .8, .8;
end
if (total > 0) then
self.Pointer:SetRotation((timeLeft)/(total)*6.2831);
self.Pointer:SetVertexColor(r*1.1, g*1.1, b*1.1);
self.Ring:SetCooldownUNIX(now-start, start + timeLeft);
else
self.Ring:SetCooldownUNIX(now, now);
end
self.RingBG:SetVertexColor(r*0.25, g*0.25, b*0.25);
self.Ring:SetSwipeColor(r*.8, g*.8, b*.8);
end
-- Time text under pin
if(WQT_Utils:GetSetting("pin", "optionalLabel") == _V["OPTIONAL_LABEL_TYPES"].time) then
self.Time:SetText(timeStringShort);
if (isDisliked) then
self.Time:SetVertexColor(1, 1, 1);
else
self.Time:SetVertexColor(color.r, color.g, color.b);
end
end
-- Small icon indicating time category
if (self.timeIcon) then
if (timeCategory == _V["TIME_REMAINING_CATEGORY"].medium) then
self.timeIcon.Icon:SetTexCoord(0.25, 0.5, 0.5, 1);
elseif (timeCategory == _V["TIME_REMAINING_CATEGORY"].short) then
self.timeIcon.Icon:SetTexCoord(0.5, 0.75, 0.5, 1);
elseif (timeCategory == _V["TIME_REMAINING_CATEGORY"].critical) then
self.timeIcon.Icon:SetTexCoord(0.75, 1, 0.5, 1);
else
self.timeIcon.Icon:SetTexCoord(0, 0.25, 0.5, 1);
end
self.timeIcon.Icon:SetVertexColor(color:GetRGB());
end
self:SetIconsDesaturated(isDisliked);
if (timeCategory == _V["TIME_REMAINING_CATEGORY"].expired) then
self.isExpired = true;
return SECONDS_PER_HOUR;
end
return timeLeft;
end
function WQT_PinMixin:UpdatePlacement(alpha)
local zoomPercent = self.parentMapFrame:GetCanvasZoomPercent();
local parentScaleFactor = self.scale / self.parentMapFrame:GetCanvasScale();
parentScaleFactor = parentScaleFactor * Lerp(self.startScale, self.endScale, Saturate(self.scaleFactor * zoomPercent));
self:SetScale(parentScaleFactor);
local startAlpha, targetAlpha = self:GetAlphas();
local newAlpha = alpha or Lerp(startAlpha, targetAlpha, Saturate(self.alphaFactor * zoomPercent));
self:SetAlpha(newAlpha);
self:SetShown(newAlpha > 0.05);
self.currentAlpha = newAlpha;
self.currentScale = parentScaleFactor;
self:ApplyScaledPosition(parentScaleFactor);
self:SetFrameLevel(self.baseFrameLevel + self.index);
WQT_WorldQuestFrame:TriggerCallback("MapPinPlaced", self);
end
function WQT_PinMixin:GetAlphas()
if (self.questInfo:IsDisliked()) then
return min(self.startAlpha,0.5), 0.5;
end
return self.startAlpha, self.endAlpha;
end
function WQT_PinMixin:OnEnter()
self:Focus();
if (self.questInfo) then
WQT_Utils:ShowQuestTooltip(self, self.questInfo);
-- Highlight quest in list
if (self.questID ~= WQT_QuestScrollFrame.PoIHoverId) then
WQT_QuestScrollFrame.PoIHoverId = self.questID;
WQT_QuestScrollFrame:DisplayQuestList();
end
end
end
function WQT_PinMixin:OnLeave()
self:ClearFocus();
GameTooltip:Hide();
WQT:HideDebugTooltip()
-- Stop highlight quest in list
WQT_QuestScrollFrame.PoIHoverId = nil;
WQT_QuestScrollFrame:DisplayQuestList();
end
function WQT_PinMixin:OnClick(button)
WQT_Utils:HandleQuestClick(self, self.questInfo, button);
end
function WQT_PinMixin:ApplyScaledPosition(manualScale)
local canvas = self:GetParent();
local scale = manualScale or self.scale / self.parentMapFrame:GetCanvasScale();
local posX, posY = self:GetNudgedPosition();
posX = (canvas:GetWidth() * posX)/scale;
posY = -(canvas:GetHeight() * posY)/scale;
self:ClearAllPoints();
self:SetPoint("CENTER", canvas, "TOPLEFT", posX, posY);
end
function WQT_PinMixin:Focus(playPing)
if (not self.questID) then return; end
local canvas = self:GetParent();
local parentScaleFactor = self.scale / self.parentMapFrame:GetCanvasScale();
self.fadeInAnim:Stop();
self.fadeOutAnim:Stop();
self.isFaded = false;
self.isFocussed = true;
self:SetAlpha(1);
self:SetScale(parentScaleFactor);
self:Show();
self:ApplyScaledPosition();
if (playPing and not self.ringAnim:IsPlaying()) then
self.Ping:Show();
self.PingStatic:Show();
self.ringAnim:Play();
self.ringAnim2:Play();
end
self.baseFrameLevel = PIN_FRAME_LEVEL_FOCUS;
self:UpdatePlacement(1);
end
function WQT_PinMixin:ClearFocus()
if (not self.questID) then return; end
self:SetAlpha(self.currentAlpha);
self:SetScale(self.currentScale);
self:SetShown(self.currentAlpha > 0.05);
self:ApplyScaledPosition(self.currentScale);
self.isFocussed = false;
if (self.ringAnim:IsPlaying()) then
self.Ping:Hide();
self.PingStatic:Hide();
self.ringAnim:Stop();
self.ringAnim2:Stop();
end
self.baseFrameLevel = PIN_FRAME_LEVEL_BASE;
self:UpdatePlacement();
end
function WQT_PinMixin:FadeIn()
if(self.fadeOutAnim:IsPlaying()) then self.fadeOutAnim:Stop(); end
self.isFaded = false;
if (not self.fadeInAnim:IsPlaying()) then
self:SetAlpha(0.5);
self.fadeInAnim.Alpha:SetFromAlpha(self:GetAlpha());
self.fadeInAnim.Alpha:SetToAlpha(self.currentAlpha);
self.fadeInAnim:Play();
end
end
function WQT_PinMixin:FadeOut()
if(self.fadeInAnim:IsPlaying()) then self.fadeInAnim:Stop(); end
self.isFaded = true;
if (not self.fadeOutAnim:IsPlaying()) then
self.fadeOutAnim.Alpha:SetFromAlpha(self:GetAlpha());
self.fadeOutAnim:Play();
end
end
function WQT_PinMixin:ResetNudge()
self.nudgeX = nil;
self.nudgeY = nil;
end
function WQT_PinMixin:GetPosition()
return self.posX, self.posY;
end
function WQT_PinMixin:GetNudgedPosition()
if (self.nudgeX and self.nudgeY)then
return self.nudgeX, self.nudgeY;
end
return self:GetPosition();
end
function WQT_PinMixin:SetNudge(x, y)
self.nudgeX = x;
self.nudgeY = y;
end