forked from LanceDH/WorldQuestTab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapPinProvider.lua
More file actions
1245 lines (1053 loc) · 35.4 KB
/
Copy pathMapPinProvider.lua
File metadata and controls
1245 lines (1053 loc) · 35.4 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.L
local _V = addon.variables;
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 = 2300;
local PIN_FRAME_LEVEL_FOCUS = 3000;
local LABEL_OFFSET = 2;
------------------------------------
-- Locals
------------------------------------
local function OnPinRelease(pool, pin)
pin:ClearFocus();
pin:ClearTimer();
pin.questID = nil;
pin.nudgeX = 0;
pin.nudgeY = 0;
pin.isExpired = false;
pin.isFaded = false;
pin.timeIcon = nil;
pin:ReleaseMiniIcons();
pin:ResetInRangePins();
pin:ResetNudge();
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 continent
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.frame:RegisterEvent("CVAR_UPDATE");
self.miniIconPool = CreateFramePool("FRAME", nil, "WQT_MiniIconTemplate", function(pool, iconFrame) iconFrame:Reset() end);
self.pinPool = CreateFramePool("FRAME", nil, "WQT_PinTemplate", OnPinRelease, nil, function(pin)
pin:Init(self);
end);
self.activePins = {};
self.pingedQuests = {};
self.hookedCanvasChanges = {};
WQT_CallbackRegistry:RegisterCallback(
"WQT.DataProvider.FilteredListUpdated",
function()
self:RefreshAllData();
end,
self);
WQT_CallbackRegistry:RegisterCallback("WQT.SettingChanged",
function(_, categoryID)
if (categoryID == "MAPPINS"
or categoryID == "MAPPINS_MINIICONS") then
self:RefreshAllData();
end
end,
self);
-- Remove pins on changing map. Quest info being processed will trigger showing them if they are needed.
EventRegistry:RegisterCallback(
"MapCanvas.MapSet",
function()
self:RemoveAllData();
end,
self);
WQT_CallbackRegistry:RegisterCallback(
"WQT.MapButton.HidePins",
function(callback, hidePins)
if (self.hidePinsByMapButton == hidePins) then return; end
self.hidePinsByMapButton = hidePins;
self:RefreshAllData();
end,
self);
WQT_PinDataProvider:HookPinHidingToMapFrame(WorldMapFrame);
end
local function HideOfficialPin(pin)
if (WQT.settings.pin.disablePoI) then return; end
pin:Hide();
end
function WQT_PinDataProvider:HookPinHidingToMapFrame(mapFrame)
if (not self.hookedPins) then
self.hookedPins = {};
end
if (not mapFrame.RegisterPin) then return; end
local templatedToSuppress = {
["BonusObjectivePinTemplate"] = true;
[WorldMap_WorldQuestDataProviderMixin:GetPinTemplate()] = true;
};
if(FlightMap_WorldQuestDataProviderMixin) then
templatedToSuppress[FlightMap_WorldQuestDataProviderMixin:GetPinTemplate()] = true;
end
hooksecurefunc(mapFrame, "RegisterPin", function(_, pin)
if (templatedToSuppress[pin.pinTemplate]) then
local isHooked = self.hookedPins[pin];
if (not isHooked) then
self.hookedPins[pin] = true;
pin:HookScript("OnShow", HideOfficialPin);
pin:Hide();
end
end
end);
end
function WQT_PinDataProvider:OnEvent(event, ...)
if (event == "SUPER_TRACKING_CHANGED") then
self:RefreshAllData();
elseif (event == "QUEST_WATCH_LIST_CHANGED") then
self:UpdateAllVisuals();
elseif (event == "CVAR_UPDATE") then
local cvar, value = ...;
if (cvar == "questPOIWQ") then
self:RefreshAllData();
end
end
end
function WQT_PinDataProvider:RemoveAllData()
self.pinPool:ReleaseAll();
wipe(self.activePins);
wipe(self.pingedQuests);
end
function WQT_PinDataProvider:AcquireMiniIcon()
local icon = self.miniIconPool:Acquire();
return icon
end
function WQT_PinDataProvider:ReleaseMiniIcon(frame)
frame:SetParent(nil);
self.miniIconPool:Release(frame);
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()
if (self.hidePinsByMapButton) then return; end
if (not C_CVar.GetCVarBool("questPOIWQ")) then return; end
if (WQT_Utils:GetSetting("pin", "disablePoI")) then
self.isUpdating = false;
return;
end
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 mapInfo = WQT_Utils:GetCachedMapInfo(mapID);
if (not mapInfo) then return; end
local settingsContinentVisible = WQT_Utils:GetSetting("pin", "continentVisible");
local settingsZoneVisible = WQT_Utils:GetSetting("pin", "zoneVisible");
local settingsFilterPoI = WQT_Utils:GetSetting("pin", "filterPoI");
local canvas = parentMapFrame:GetCanvas();
wipe(self.activePins);
if (mapInfo.mapType >= Enum.UIMapType.Continent) then
for k, questInfo in ipairs(WQT_WorldQuestFrame.dataProvider.fitleredQuestsList) do
if (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
local PIN_CLUSTER_RANGE = 0.5;
local PIN_REPOSITION_DISTANCE = 0.42;
local COS_45_DEG = 0.7071;
local function SortPinsByXPos(pinA, pinB)
local ax = pinA:GetPosition();
local bx = pinB:GetPosition();
if (ax and bx and ax ~= bx) then
return ax < bx;
end
return pinA.questID < pinB.questID;
end
local function SortPinsByNudgedPos(pinA, pinB)
local aX, aY = pinA:GetNudgedPosition();
local bX, bY = pinB:GetNudgedPosition();
if (aY and aY and aY ~= bY) then
return aY < bY;
end
return pinA.questID < pinB.questID;
end
local function SortPinNumInRange(pinA, pinB)
local numA = pinA:GetNumInRangePins();
local numB = pinB:GetNumInRangePins();
if (numA ~= numB) then
return numA > numB;
end
return SortPinsByXPos(pinA, pinB);
end
function WQT_PinDataProvider:FixOverlaps(canvas)
if (not canvas) then return; end
local pinSize = 0;
for k, pin in ipairs(self.activePins) do
pin:ResetNudge();
pin:ResetInRangePins();
if (pinSize == 0) then
pinSize = pin:GetButton():GetSize();
end
end
if (pinSize > 0) then
local pinScale = WQT_Utils:GetSetting("pin", "scale");
pinSize = pinSize * pinScale;
local canvasScale = canvas:GetParent():GetCanvasScale();
local pinLengthX = pinSize / (canvas:GetWidth() * canvasScale) ;
local pinLengthY = pinSize / (canvas:GetHeight() * canvasScale);
local pinLengthRatio = pinLengthX / pinLengthY;
local scaling = (canvas:GetWidth() * canvas:GetParent():GetCanvasScale()) / canvas:GetParent():GetWidth();
scaling = 1 / scaling;
local clusterDistance = pinLengthX * PIN_CLUSTER_RANGE;
local cluserDistanceSqd = clusterDistance * clusterDistance;
-- Link nearby pins
local hasLinkedPins = false;
table.sort(self.activePins, SortPinsByXPos);
for indexA = 1, #self.activePins, 1 do
local pinA = self.activePins[indexA];
local ax, ay = pinA:GetPosition();
ay = ay * pinLengthRatio;
for indexB = 1, #self.activePins, 1 do
if (indexA < indexB) then
local pinB = self.activePins[indexB];
local bx, by = pinB:GetPosition();
local xdiff = indexB > indexA and ax - bx or bx-ax;
if (xdiff > -clusterDistance) then
if (xdiff > clusterDistance) then
break;
end
by = by * pinLengthRatio;
local distanceSquared = SquaredDistanceBetweenPoints(ax, ay, bx, by);
if(distanceSquared < cluserDistanceSqd) then
pinA:AddInRangePin(pinB);
pinB:AddInRangePin(pinA);
hasLinkedPins = true;
end
end
end
end
end
if (hasLinkedPins) then
-- Cluster pins in their groups
table.sort(self.activePins, SortPinNumInRange);
local spreadx = pinLengthX * PIN_REPOSITION_DISTANCE;
local spreadY = pinLengthY * PIN_REPOSITION_DISTANCE;
local columnOffset = spreadx * COS_45_DEG;
local alreadyClusteredPins = {};
local validPins = {};
for _, sourcePin in ipairs(self.activePins) do
local numInRange = sourcePin:GetNumInRangePins();
if (numInRange == 0) then break; end
wipe(validPins);
if (not alreadyClusteredPins[sourcePin]) then
tinsert(validPins, sourcePin);
alreadyClusteredPins[sourcePin] = true;
local centerX, centerY = sourcePin:GetPosition();
for k2, inRangePin in sourcePin:IterateInRangePins() do
if (not alreadyClusteredPins[inRangePin]) then
local pinX, pinY = inRangePin:GetPosition();
centerX = centerX + pinX;
centerY = centerY + pinY;
tinsert(validPins, inRangePin);
alreadyClusteredPins[inRangePin] = true;
end
end
local numPassedPins = #validPins;
if (numPassedPins >= 2) then
local numColumns = ceil(sqrt(numPassedPins));
local numRows = ceil(numPassedPins / numColumns);
local xWidth = (numColumns-1) * columnOffset;
centerX = centerX / numPassedPins;
centerX = centerX - xWidth * 0.5;
centerY = centerY / numPassedPins;
centerY = centerY - (numRows-1) * spreadY * 0.5;
local placedCount = 0;
for k, pin in ipairs(validPins) do
local mathIndex = k-1;
local column = mathIndex % numColumns;
local x = centerX + column * columnOffset;
local row = floor(mathIndex / numColumns) ;
local y = centerY + row * spreadY;
-- Shift every other column down slightly
y = y + (column%2) * spreadY * 0.5 * COS_45_DEG;
pin:SetNudge(x, y);
placedCount = placedCount + 1;
end
end
end
end
end
end
-- Placement time
table.sort(self.activePins, SortPinsByNudgedPos);
for k, pin in ipairs(self.activePins) do
pin.index = k;
pin:UpdatePlacement();
end
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();
pin:UpdatePinTime();
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 or InCombatLockdown()) 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 Label
------------------------------------
WQT_PinLabelMixin = {};
function WQT_PinLabelMixin:GetLabelText()
return self.LabelText;
end
function WQT_PinLabelMixin:UpdateVisuals(questInfo)
-- Label
local settingPinTimeLabel = WQT_Utils:GetSetting("pin", "label");
local labelColor = _V["WQT_WHITE_FONT_COLOR"];
local labelFontString = self:GetLabelText();
local _, _, _, timeStringShort = WQT_Utils:GetQuestTimeString(questInfo);
local showLabel = settingPinTimeLabel == _V["ENUM_PIN_LABEL"].time and timeStringShort ~= "";
-- Only setting up for reward amount. Time label is done in UpdateTime()
if (settingPinTimeLabel == _V["ENUM_PIN_LABEL"].amount) then
local questCanWarmode = C_QuestLog.QuestCanHaveWarModeBonus(questInfo.questID);
local mainReward = questInfo:GetReward(1);
showLabel = mainReward and true or false;
if (mainReward) then
local amountString, rawAmount = WQT_Utils:GetDisplayRewardAmount(mainReward, questCanWarmode);
showLabel = rawAmount > 1;
labelFontString:SetText(amountString);
if (WQT_Utils:GetSetting("pin", "labelColors")) then
local _, textColor = WQT_Utils:GetRewardTypeColorIDs(mainReward.type);
labelColor = textColor;
end
end
end
labelFontString:SetVertexColor(labelColor:GetRGB());
self:SetShown(showLabel);
end
function WQT_PinLabelMixin:UpdateTime(timeString, color)
if (WQT_Utils:GetSetting("pin", "label") ~= _V["ENUM_PIN_LABEL"].time) then
return;
end
if (not WQT_Utils:GetSetting("pin", "labelColors")) then
color = _V["WQT_WHITE_FONT_COLOR"];
end
local labelFontString = self:GetLabelText();
labelFontString:SetText(timeString);
labelFontString:SetVertexColor(color:GetRGB());
end
------------------------------------
-- Pin Icon
------------------------------------
WQT_PinButtonMixin = {};
function WQT_PinButtonMixin:OnLoad()
self.UpdateTooltip = function() WQT_Utils:ShowQuestTooltip(self, self.questInfo) end;
end
function WQT_PinButtonMixin:OnEnter()
self:GetParent():Focus();
if (self.questInfo) then
WQT_Utils:ShowQuestTooltip(self, self.questInfo);
-- Highlight quest in list
if (self.questID ~= WQT_ListContainer.PoIHoverId) then
WQT_ListContainer.PoIHoverId = self.questID;
WQT_ListContainer:DisplayQuestList();
end
end
end
function WQT_PinButtonMixin:OnLeave()
self:GetParent():ClearFocus();
GameTooltip:Hide();
WQT:HideDebugTooltip()
-- Stop highlight quest in list
WQT_ListContainer.PoIHoverId = nil;
WQT_ListContainer:DisplayQuestList();
end
function WQT_PinButtonMixin:OnClick(button)
WQT_Utils:HandleQuestClick(self, self.questInfo, button);
end
function WQT_PinButtonMixin:GetIcon()
return self.Icon;
end
function WQT_PinButtonMixin:GetRingBG()
return self.RingBG;
end
function WQT_PinButtonMixin:GetRing()
return self.Ring;
end
function WQT_PinButtonMixin:GetPointer()
return self.Pointer;
end
function WQT_PinButtonMixin:GetCustomUnderlay()
return self.CustomUnderlay;
end
function WQT_PinButtonMixin:GetCustomTypeIcon()
return self.CustomTypeIcon;
end
function WQT_PinButtonMixin:GetCustomSelectedGlow()
return self.CustomSelectedGlow;
end
function WQT_PinButtonMixin:GetCustomBountyRing()
return self.CustomBountyRing;
end
function WQT_PinButtonMixin:GetMiniPins()
return self.pinRoot.miniIcons;
end
function WQT_PinButtonMixin:PlaceMiniIcons()
local icons = self:GetMiniPins();
local numIcons = #icons;
if (numIcons > 0) then
local angle = ICON_ANGLE_START - (ICON_ANGLE_DISTANCE*(numIcons-1))/2
local numIcons = min(#icons, ICON_MAX_AMOUNT);
for i = 1, numIcons do
local iconFrame = icons[i];
local posX = ICON_CENTER_DISTANCE * cos(angle);
local posY = ICON_CENTER_DISTANCE * sin(angle);
PixelUtil.SetPoint(iconFrame, "CENTER", self, "CENTER", posX, posY);
iconFrame:Show();
angle = angle + ICON_ANGLE_DISTANCE;
end
end
end
function WQT_PinButtonMixin:IterateMiniIcons()
return ipairs(self:GetMiniPins());
end
function WQT_PinButtonMixin:AddIcon()
local icon = self.pinRoot:AcquireMiniIcon();
icon:SetParent(self);
return icon;
end
function WQT_PinButtonMixin:SetIconsDesaturated(desaturate)
for k, icon in self:IterateMiniIcons() do
icon:SetDesaturated(desaturate);
end
end
function WQT_PinButtonMixin:GetIconBottomDifference()
local maxBottomDiff = 0;
local selfBottom = self:GetBottom();
for k, icon in self:IterateMiniIcons() do
local diff = selfBottom - icon:GetBottom();
maxBottomDiff = max(maxBottomDiff, diff);
end
return maxBottomDiff;
end
function WQT_PinButtonMixin:UpdateTime(start, timeLeft, total, color, timeCategory)
if (WQT_Utils:GetSetting("pin", "ringType") ~= _V["RING_TYPES"].time) then
return;
end
local ringBGTexture = self:GetRingBG();
local ringCooldown = self:GetRing();
local pointerTexture = self:GetPointer();
local r, g, b = color:GetRGB();
local now = time();
pointerTexture:SetShown(total > 0);
if (total > 0) then
pointerTexture:SetRotation((timeLeft) / (total) * 6.2831);
pointerTexture:SetVertexColor(r * 1.1, g * 1.1, b * 1.1);
ringCooldown:SetCooldownUNIX(now - start, start + timeLeft);
else
ringCooldown:SetCooldownUNIX(now, now);
end
ringBGTexture:SetVertexColor(r, g, b);
ringCooldown:SetSwipeColor(r, g, b);
-- 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
end
function WQT_PinButtonMixin:UpdateVisuals(questInfo)
if (not questInfo) then return; end
self.questInfo = questInfo;
local questQuality = questInfo:GetTagInfoQuality();
local isDisliked = questInfo:IsDisliked();
local tagInfo = questInfo:GetTagInfo();
local typeAtlas, typeAtlasWidth, typeAtlasHeight = WQT_Utils:GetCachedTypeIconData(questInfo);
local isTracked = QuestUtils_IsQuestWatched(questInfo.questID);
local isSuperTracked = questInfo.questID == C_SuperTrack.GetSuperTrackedQuestID();
-- Ring coloration
local ringType = WQT_Utils:GetSetting("pin", "ringType");
local now = time();
local ringBGTexture = self:GetRingBG();
local ringCooldown = self:GetRing();
local pointerTexture = self:GetPointer();
local r, g, b = _V["WQT_COLOR_CURRENCY"]:GetRGB();
ringBGTexture:SetShown(ringType == _V["RING_TYPES"].time and 1 or 0);
ringCooldown:SetCooldownUNIX(now, now);
pointerTexture:Hide();
ringCooldown:Show();
ringBGTexture: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
ringCooldown:Hide();
ringBGTexture:Hide();
end
if (isDisliked) then
r, g, b = 1, 1, 1;
end
ringBGTexture:SetVertexColor(r, g, b);
ringCooldown:SetSwipeColor(r, g, b);
-- Elite indicator
local customUnderlayTexture = self:GetCustomUnderlay();
local isElite = tagInfo and tagInfo.isElite;
local settingEliteRing = WQT_Utils:GetSetting("pin", "eliteRing");
local useEliteRing = settingEliteRing and ringType ~= _V["RING_TYPES"].hide;
ringBGTexture:SetTexture("Interface/Addons/WorldQuestTab/Images/PoIRingBG");
ringCooldown:SetSwipeTexture("Interface/Addons/WorldQuestTab/Images/PoIRingBar");
if (useEliteRing) then
customUnderlayTexture:SetShown(false);
if(isElite) then
ringBGTexture:SetTexture("Interface/Addons/WorldQuestTab/Images/PoIRingBGElite");
ringCooldown:SetSwipeTexture("Interface/Addons/WorldQuestTab/Images/PoIRingBarElite");
end
else
customUnderlayTexture:SetShown(isElite);
end
customUnderlayTexture:SetDesaturated(isDisliked);
-- Main Icon
local settingCenterType = WQT_Utils:GetSetting("pin", "centerType");
local customTypeIconTexture = self:GetCustomTypeIcon();
local customSelectedGlowTexture = self:GetCustomSelectedGlow();
local customBountyRingTexture = self:GetCustomBountyRing();
customTypeIconTexture:SetShown(false);
customSelectedGlowTexture:Hide()
customBountyRingTexture:Hide()
local iconTexture = self:GetIcon();
iconTexture:SetTexture("Interface/PETBATTLES/BattleBar-AbilityBadge-Neutral");
iconTexture:SetTexCoord(0.06, 0.93, 0.05, 0.93);
iconTexture:SetDesaturated(false);
iconTexture:SetScale(1);
iconTexture:Show();
local hasIcon = true;
if(settingCenterType == _V["PIN_CENTER_TYPES"].reward) then
local rewardTexture = questInfo:GetRewardTexture();
iconTexture:SetTexture(rewardTexture);
iconTexture:SetTexCoord(0, 1, 0, 1);
hasIcon = questInfo:GetRewardType() ~= WQT_REWARDTYPE.none;
elseif(settingCenterType == _V["PIN_CENTER_TYPES"].blizzard) then
customTypeIconTexture:SetShown(true);
local showSlectedGlow = tagInfo and questQuality ~= Enum.WorldQuestQuality.Common and isSuperTracked;
local selectedBountyOnly = WQT_Utils:GetSetting("general", "bountySelectedOnly");
customBountyRingTexture:SetShown(questInfo:IsCriteria(selectedBountyOnly));
customSelectedGlowTexture:SetShown(showSlectedGlow);
if (tagInfo) then
if (questQuality == Enum.WorldQuestQuality.Rare) then
iconTexture:SetAtlas("worldquest-questmarker-rare");
customSelectedGlowTexture:SetAtlas("worldquest-questmarker-rare");
elseif (questQuality == Enum.WorldQuestQuality.Epic) then
iconTexture:SetAtlas("worldquest-questmarker-epic")
customSelectedGlowTexture:SetAtlas("worldquest-questmarker-epic");
else
iconTexture:SetTexture("Interface/WorldMap/UI-QuestPoi-NumberIcons");
if (isSuperTracked) then
iconTexture:SetTexCoord(0.52, 0.605, 0.395, 0.48);
else
iconTexture:SetTexCoord(0.895, 0.98, 0.395, 0.48);
end
iconTexture:SetScale(1.1);
end
else
iconTexture:SetTexture("Interface/WorldMap/UI-QuestPoi-NumberIcons");
iconTexture:SetTexCoord(0.895, 0.98, 0.395, 0.48);
iconTexture:SetDesaturated(true);
end
-- Mimic default icon
customTypeIconTexture:SetAtlas(typeAtlas);
customTypeIconTexture:SetSize(typeAtlasWidth, typeAtlasHeight);
customTypeIconTexture:SetScale(.8);
elseif(settingCenterType == _V["PIN_CENTER_TYPES"].faction) then
local factionData = WQT_Utils:GetFactionDataInternal(questInfo.factionID);
iconTexture:SetTexture(factionData.texture);
elseif(settingCenterType == _V["PIN_CENTER_TYPES"].none) then
iconTexture:Hide();
end
iconTexture:SetAlpha(hasIcon and 1.0 or 0.7);
if (isDisliked) then
iconTexture:SetDesaturated(true);
end
customTypeIconTexture:SetDesaturated(isDisliked);
-- Setup mini icons
local questType = tagInfo and tagInfo.worldQuestType;
self.timeIcon = nil;
-- Quest Type Icon
if (typeAtlas and typeAtlas ~= "Worldquest-icon" and WQT_Utils:GetSetting("pin", "typeIcon") ) 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
-- Time Icon
if (WQT_Utils:GetSetting("pin", "timeIcon")) then
local _, _, color, _, _, timeCategory = WQT_Utils:GetQuestTimeString(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
-- Warband icon
if (questInfo.hasWarbandBonus and WQT_Utils:GetSetting("pin", "warbandIcon")) then
local iconFrame = self:AddIcon();
iconFrame:SetupIcon("warbands-icon");
iconFrame:SetIconScale(1.3);
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 Tracking
if (isTracked) then
local iconFrame = self:AddIcon();
iconFrame:SetupIcon(isSuperTracked and "Waypoint-MapPin-Minimap-Tracked" or "Waypoint-MapPin-Minimap-Untracked");
iconFrame:SetIconScale(1.7);
end
self:PlaceMiniIcons();
self:SetIconsDesaturated(isDisliked);
end
------------------------------------
-- Pin Core
------------------------------------
WQT_PinMixin = {};
function WQT_PinMixin:ClearTimer()
if (self.timer) then
self.timer:Cancel();
self.timer = nil;
end
end
function WQT_PinMixin:GetButton()
return self.Button;
end
function WQT_PinMixin:GetLabel()
return self.Label;
end
function WQT_PinMixin:GetPing()
return self:GetButton().Ping;
end
function WQT_PinMixin:GetPingStatic()
return self:GetButton().PingStatic;
end
function WQT_PinMixin:GetFadeInAnim()
return self.fadeInAnim;
end
function WQT_PinMixin:GetFadeOutAnim()
return self.fadeOutAnim;
end
function WQT_PinMixin:GetRingAnim()
return self:GetButton().ringAnim;
end
function WQT_PinMixin:GetRingAnim2()
return self:GetButton().ringAnim2;
end
function WQT_PinMixin:Init(dataProvider)
self.dataProvider = dataProvider;
self.miniIcons = {};
local button = self:GetButton();
button.pinRoot = self;
self.inRangePins = {};
self.inRangePinsLookup = {};
end
function WQT_PinMixin:ResetInRangePins()
wipe(self.inRangePinsLookup);
wipe(self.inRangePins);
end
function WQT_PinMixin:AddInRangePin(pin)
if (self.inRangePinsLookup[pin]) then return; end
self.inRangePinsLookup[pin] = true;
tinsert(self.inRangePins, pin);
end
function WQT_PinMixin:GetNumInRangePins()
return #self.inRangePins;
end
function WQT_PinMixin:IterateInRangePins()