-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcore.lua
More file actions
1452 lines (1266 loc) · 44.2 KB
/
core.lua
File metadata and controls
1452 lines (1266 loc) · 44.2 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
-- if WOW_PROJECT_ID ~= WOW_PROJECT_MAINLINE then
-- return
-- end
---@alias CandyBucketsModuleName "brewfest"|"hallow"|"lunar"|"midsummer"
---@class CandyBucketsNS : table
---@field public modules table<CandyBucketsModuleName, CandyBucketsModule>
---@class CandyBucketsQuest : table
---@field public quest number
---@field public side number `1` = Alliance, `2` = Horde, `3` = Neutral
---@field public extra? number
---@field public style? number `1` = Circle (Default), `2` = No Border and Plain Icon
---@field public waypoint? boolean
---@field public module? CandyBucketsModule
---@class CandyBucketsModule
---@field public event CandyBucketsModuleName
---@field public texture string[]
---@field public title string[]
---@field public quests CandyBucketsQuest[]
---@field public patterns string[]
---@field public loaded? boolean
---@class CandyBucketsMapCanvas : Frame
---@field public GetMap fun(): CandyBucketsMapPosition
---@field public GetMapID fun(): number
---@field public RemoveAllPinsByTemplate fun(self: CandyBucketsMapCanvas, template: string)
---@field public AcquirePin fun(self: CandyBucketsMapCanvas, template: string, ...)
---@field public RefreshAllData fun(self: CandyBucketsMapCanvas, fromOnShow?: boolean)
---@field public GetNumActivePinsByTemplate fun(self: CandyBucketsMapCanvas, template: string): number
---@class CandyBucketsMapPosition : CandyBucketsMapCanvas
---@field public name string
---@field public quest? CandyBucketsQuest
---@field public GetPosition fun(): x: number, y: number
---@field public SetPosition fun(self: CandyBucketsMapPosition, x: number, y: number)
---@class CandyBucketsWaypointAddOn
---@field public name string
---@field public standard? boolean
---@field public canUse? fun(self: CandyBucketsWaypointAddOn): boolean
---@field public func fun(self: CandyBucketsWaypointAddOn, poi: CandyBucketsMapPosition, wholeModule?: boolean): boolean|string
---@field public funcAll fun(self: CandyBucketsWaypointAddOn, module: CandyBucketsModule): boolean|string
---@field public funcRemove? fun(self: CandyBucketsWaypointAddOn, questID: number): boolean
---@field public funcClosest? fun(self: CandyBucketsWaypointAddOn): boolean
---@class CandyBucketsDataProvider : CandyBucketsMapCanvas
---@class CandyBucketsPin : CandyBucketsMapPosition
---@field public SetScalingLimits fun(self: CandyBucketsPin, scaleFactor: number, startScale: number, endScale: number)
---@field public UseFrameLevelType fun(self: CandyBucketsPin, template: string, level: number)
---@field public HighlightTexture Texture
---@field public Texture Texture
---@field public Border Texture
---@class CandyBucketsStats : CandyBucketsPin
---@field public Text FontString
---@class CandyBucketsEvalPositionQuestInfo
---@field public module? CandyBucketsModule
---@field public quest? CandyBucketsEvalPositionQuestInfo
---@field public side? number `1` = Alliance, `2` = Horde, `3` = Neutral
---@field public missing? boolean
---@field public error? string
---@field public warning? string
---@field public success? string
---@field public name? string
---@field public uiMapID? number
---@field public x? number
---@field public y? number
---@field public distance? number
---@class CandyBucketsEvalPositionRetInfo
---@field public has? boolean
---@field public success? boolean
---@field public data? CandyBucketsEvalPositionQuestInfo
local addonName = ... ---@type string
local ns = select(2, ...) ---@class CandyBucketsNS
local _issecretvalue = issecretvalue
---@param value any
local function issecretvalue(value)
return _issecretvalue and _issecretvalue(value)
end
--
-- Debug
--
local DEBUG_MODULE = false
local DEBUG_FACTION = false
local DEBUG_LOCATION = false
--
-- Chat output
--
-- Outputs to the chat frame. Takes the same arguments as `format`.
---@param fmt string
---@param ... any
local function Output(fmt, ...)
local text = format(fmt, ...)
DEFAULT_CHAT_FRAME:AddMessage(text, 1, 1, 0)
end
--
-- Session
--
ns.FACTION = 0 --- `1` = Alliance, `2` = Horde, `3` = Neutral
ns.QUESTS = {} ---@type CandyBucketsQuest[]
ns.PROVIDERS = {} ---@type table<CandyBucketsDataProvider, true?>
---@type table<number, boolean>
ns.COMPLETED_QUESTS = setmetatable({}, {
__index = function(self, questID)
local isCompleted = C_QuestLog.IsQuestFlaggedCompleted(questID)
if isCompleted then
self[questID] = isCompleted
end
return isCompleted
end
})
--
-- Map
--
ns.PARENT_MAP = {} ---@type table<number, table<number, boolean>>
do
-- TODO: PR #39
---@param uiParentMapID number
---@param uiChildMapID number
local function AddParentChildMapIDs(uiParentMapID, uiChildMapID)
local temp = ns.PARENT_MAP[uiParentMapID]
if not temp then
temp = { [uiParentMapID] = true }
ns.PARENT_MAP[uiParentMapID] = temp
end
temp[uiChildMapID] = true
end
---@param uiMapID number
---@param getChildren fun(uiMapID: number): UiMapDetails[]?
---@param depthRemaining number
---@param uiParentMapIDs? table<number, boolean>
local function CheckMapRecursively(uiMapID, getChildren, depthRemaining, uiParentMapIDs)
if not uiMapID or not getChildren then return end
if not depthRemaining then depthRemaining = 1 end
if depthRemaining < 1 then return end
if not uiParentMapIDs then uiParentMapIDs = {} end
for uiParentMapID, _ in pairs(uiParentMapIDs) do
AddParentChildMapIDs(uiParentMapID, uiMapID)
end
uiParentMapIDs[uiMapID] = true
local children = getChildren(uiMapID)
if children and type(children) == "table" then
for _, uiChildMapID in pairs(children) do
if type(uiChildMapID) == "table" then
uiChildMapID = uiChildMapID.mapID ---@diagnostic disable-line: cast-local-type
end
if type(uiChildMapID) == "number" then
AddParentChildMapIDs(uiMapID, uiChildMapID)
CheckMapRecursively(uiChildMapID, getChildren, depthRemaining - 1, uiParentMapIDs)
end
end
end
end
---@return UiMapDetails[]?
local function GetChildren(uiMapID)
return C_Map.GetMapChildrenInfo(uiMapID, nil, true) -- Enum.UIMapType.Zone
end
for _, uiMapID in ipairs({
12, -- Kalimdor
13, -- Eastern Kingdoms
101, -- Outland
113, -- Northrend
127, -- Crystalsong Forest
203, -- Vashj'ir
224, -- Stranglethorn Vale
390, -- Vale of Eternal Blossoms
424, -- Pandaria
572, -- Draenor
619, -- Broken Isles
862, -- Zuldazar
875, -- Zandalar
876, -- Kul Tiras
895, -- Tiragarde Sound
947, -- Azeroth (CPU hog, but it's not too bad?)
948, -- The Maelstrom
1165, -- Dazar'alor
1550, -- The Shadowlands
1978, -- Dragon Isles
2274, -- Khaz Algar
}) do
CheckMapRecursively(uiMapID, GetChildren, 10)
end
AddParentChildMapIDs(108, 111) -- Terokkar Forest -> Shattrath City
AddParentChildMapIDs(539, 582) -- Shadowmoon Valley -> Lunarfall
AddParentChildMapIDs(525, 590) -- Frostfire Ridge -> Frostwall
AddParentChildMapIDs(1978, 2151) -- Dragon Isles -> The Forbidden Reach
AddParentChildMapIDs(947, 2151) -- Azeroth -> The Forbidden Reach
end
---@type table<number, number>
ns.PARENT_MAP_TAXI = setmetatable({}, {
__index = function (self, uiMapID)
local mapInfo = C_Map.GetMapInfo(uiMapID)
for uiParentMapID, childUiMapIDs in pairs(ns.PARENT_MAP) do
for childUiMapID, _ in pairs(childUiMapIDs) do
local childMapInfo = C_Map.GetMapInfo(childUiMapID)
if mapInfo.mapType == childMapInfo.mapType and mapInfo.name == childMapInfo.name then
uiMapID = childMapInfo.mapID
self[uiMapID] = uiMapID
return uiMapID
end
end
end
self[uiMapID] = uiMapID
return uiMapID
end,
})
---@param uiMapID number
---@param x number
---@param y number
---@return number uiMapID, number x, number y
local function GetLowestLevelMapFromMapID(uiMapID, x, y)
if not uiMapID or not x or not y then
return uiMapID, x, y
end
local child = C_Map.GetMapInfoAtPosition(uiMapID, x, y)
if not child or not child.mapID then
return uiMapID, x, y
end
local continentID, worldPos = C_Map.GetWorldPosFromMapPos(uiMapID, { x = x, y = y })
if not continentID or not worldPos then
return uiMapID, x, y
end
local _, mapPos = C_Map.GetMapPosFromWorldPos(continentID, worldPos, child.mapID)
if mapPos and mapPos.x and mapPos.y then
return child.mapID, mapPos.x, mapPos.y
end
return uiMapID, x, y
end
---@return number? uiMapID, Vector2DMixin? pos
local function GetPlayerMapAndPosition()
local unit = "player"
local uiMapID = C_Map.GetBestMapForUnit(unit)
if not uiMapID then
return
end
local pos = C_Map.GetPlayerMapPosition(uiMapID, unit)
if not pos or not pos.x or not pos.y then
return uiMapID
end
return uiMapID, pos
end
---@param map CandyBucketsMapPosition
local function IsTaxiMap(map)
return map == FlightMapFrame
end
--
-- Waypoint
--
-- ns:GetWaypointAddon()
-- ns:AutoWaypoint(poi, wholeModule, silent)
do
---@class TomTomWaypointOptionsPolyfill
---@field public quest? CandyBucketsQuest
---@field public from string
---@field public title string
---@field public minimap boolean
---@field public crazy boolean
---@class TomTomWaypointPolyfill
---@field public profile { arrow: { arrival: number } }
---@field public waypoints table<string, table<string, TomTomWaypointOptionsPolyfill>>
---@field public AddWaypoint fun(self: TomTomWaypointPolyfill, mapID: number, x: number, y: number, options?: TomTomWaypointOptionsPolyfill)
---@field public RemoveWaypoint fun(self: TomTomWaypointPolyfill, options: TomTomWaypointOptionsPolyfill)
---@field public SetClosestWaypoint fun(self: TomTomWaypointPolyfill)
---@field public GetClosestWaypoint fun(self: TomTomWaypointPolyfill): TomTomWaypointOptionsPolyfill?
---@field public SetCrazyArrow fun(self: TomTomWaypointPolyfill, options: TomTomWaypointOptionsPolyfill, arrival: number, title: string)
-- TomTom (v4.0.17)
---@type CandyBucketsWaypointAddOn
local tomtomWaypointAddon = {
name = "TomTom",
func = function(self, poi, wholeModule)
---@type TomTomWaypointPolyfill
local TomTom = TomTom ---@diagnostic disable-line: undefined-global
if wholeModule then
self:funcAll(poi.quest.module)
TomTom:SetClosestWaypoint()
return true
end
local uiMapID = poi:GetMap():GetMapID()
local x, y = poi:GetPosition()
local childUiMapID, childX, childY = GetLowestLevelMapFromMapID(uiMapID, x, y)
local mapInfo = C_Map.GetMapInfo(childUiMapID)
---@type TomTomWaypointOptionsPolyfill
local options = {
from = addonName,
quest = poi.quest,
title = format("%s (%s, %d)", poi.name, mapInfo.name or format("Map %d", childUiMapID), poi.quest.quest),
minimap = true,
crazy = true,
}
TomTom:AddWaypoint(childUiMapID, childX, childY, options)
return true
end,
funcAll = function(self, module)
---@type TomTomWaypointPolyfill
local TomTom = TomTom ---@diagnostic disable-line: undefined-global
for i = 1, #ns.QUESTS do
local quest = ns.QUESTS[i]
if quest.module == module and quest.waypoint ~= false then
for uiMapID, coords in pairs(quest) do
if type(uiMapID) == "number" and type(coords) == "table" then
local name = module.title[quest.extra or 1]
local mapInfo = C_Map.GetMapInfo(uiMapID)
---@type TomTomWaypointOptionsPolyfill
local options = {
from = addonName,
quest = quest,
title = format("%s (%s, %d)", name, mapInfo.name or format("Map %d", uiMapID), quest.quest),
minimap = true,
crazy = true,
}
TomTom:AddWaypoint(uiMapID, coords[1]/100, coords[2]/100, options)
end
end
end
end
return true
end,
funcRemove = function(self, questID)
---@type TomTomWaypointPolyfill
local TomTom = TomTom ---@diagnostic disable-line: undefined-global
local remove ---@type table<TomTomWaypointOptionsPolyfill, true>?
for _, mapWaypoints in pairs(TomTom.waypoints) do
for _, waypoint in pairs(mapWaypoints) do
if waypoint.from == addonName and type(waypoint.quest) == "table" and waypoint.quest.quest == questID then
if not remove then
remove = {}
end
remove[waypoint] = true
end
end
end
if not remove then
return false
end
for waypoint, _ in pairs(remove) do
TomTom:RemoveWaypoint(waypoint)
end
return true
end,
funcClosest = function(self)
---@type TomTomWaypointPolyfill
local TomTom = TomTom ---@diagnostic disable-line: undefined-global
local waypoint = TomTom:GetClosestWaypoint()
if not waypoint then
return false
end
TomTom:SetCrazyArrow(waypoint, TomTom.profile.arrow.arrival, waypoint.title)
return true
end,
}
---@class MapPinEnhancedOptionsPolyfill
---@field public mapID number
---@field public x number
---@field public y number
---@field public title string
---@field public setTracked? boolean
---@class MapPinEnhancedPolyfill
---@field public AddPin fun(self: MapPinEnhancedPolyfill, options: MapPinEnhancedOptionsPolyfill)
-- MapPinEnhanced (v3.0.12)
---@type CandyBucketsWaypointAddOn
local mpeWaypointAddon = {
name = "MapPinEnhanced",
func = function(self, poi, wholeModule)
if wholeModule then
self:funcAll(poi.quest.module)
return true
end
---@type MapPinEnhancedPolyfill
local MapPinEnhanced = MapPinEnhanced ---@diagnostic disable-line: undefined-global
local uiMapID = poi:GetMap():GetMapID()
local x, y = poi:GetPosition()
local childUiMapID, childX, childY = GetLowestLevelMapFromMapID(uiMapID, x, y)
local mapInfo = C_Map.GetMapInfo(childUiMapID)
MapPinEnhanced:AddPin({
mapID = childUiMapID,
x = childX,
y = childY,
title = format("%s (%s, %d)", poi.name, mapInfo.name or format("Map %d", childUiMapID), poi.quest.quest),
setTracked = true,
})
return true
end,
funcAll = function(self, module)
---@type MapPinEnhancedPolyfill
local MapPinEnhanced = MapPinEnhanced ---@diagnostic disable-line: undefined-global
for i = 1, #ns.QUESTS do
local quest = ns.QUESTS[i]
if quest.module == module and quest.waypoint ~= false then
for uiMapID, coords in pairs(quest) do
if type(uiMapID) == "number" and type(coords) == "table" then
local name = module.title[quest.extra or 1]
local mapInfo = C_Map.GetMapInfo(uiMapID)
MapPinEnhanced:AddPin({
mapID = uiMapID,
x = coords[1]/100,
y = coords[2]/100,
title = format("%s (%s, %d)", name, mapInfo.name or format("Map %d", uiMapID), quest.quest),
setTracked = true,
})
end
end
end
end
return true
end,
}
-- C_Map.SetUserWaypoint (9.0.1)
---@type CandyBucketsWaypointAddOn
local standardWaypointAddon = {
name = "Waypoint",
standard = true,
canUse = function(self)
return WOW_PROJECT_ID == WOW_PROJECT_MAINLINE
end,
func = function(self, poi, wholeModule)
if wholeModule then
self:funcAll(poi.quest.module)
return true
end
local uiMapID = poi:GetMap():GetMapID()
local x, y = poi:GetPosition()
local childUiMapID, childX, childY = GetLowestLevelMapFromMapID(uiMapID, x, y)
local mapInfo = C_Map.GetMapInfo(childUiMapID)
if not C_Map.CanSetUserWaypointOnMap(childUiMapID) then
return format("Can't make a waypoint to %s. Enter the continent then try again.", mapInfo.name)
end
C_Map.SetUserWaypoint({ uiMapID = childUiMapID, position = { x = childX, y = childY } })
return true
end,
funcAll = function(self, module)
for i = 1, #ns.QUESTS do
local quest = ns.QUESTS[i]
if quest.module == module and quest.waypoint ~= false then
for uiMapID, coords in pairs(quest) do
if type(uiMapID) == "number" and type(coords) == "table" then
if C_Map.CanSetUserWaypointOnMap(uiMapID) then
C_Map.SetUserWaypoint({ uiMapID = uiMapID, position = { x = coords[1]/100, y = coords[2]/100 } })
return true
end
end
end
end
end
return "Can't make a waypoint to any destination."
end,
funcRemove = function(self, questID)
local waypoint = C_Map.GetUserWaypoint()
if not waypoint then
return false
end
for i = 1, #ns.QUESTS do
local quest = ns.QUESTS[i]
if quest.quest == questID then
for uiMapID, coords in pairs(quest) do
if type(uiMapID) == "number" and type(coords) == "table" then
if waypoint.uiMapID == uiMapID and waypoint.position.x == coords[1] and waypoint.position.y == coords[2] then
C_Map.ClearUserWaypoint()
return true
end
end
end
end
end
return false
end,
}
---@type CandyBucketsWaypointAddOn[]
local waypointAddons = {
tomtomWaypointAddon,
mpeWaypointAddon,
standardWaypointAddon
}
local supportedAddons = {} ---@type string[]
local supportedAddonsWarned = false
for k, v in ipairs(waypointAddons) do if not v.standard then supportedAddons[k] = v.name end end
supportedAddons = table.concat(supportedAddons, " ") ---@diagnostic disable-line: cast-local-type
---@return CandyBucketsWaypointAddOn? waypoint
function ns:GetWaypointAddon()
for i = 1, #waypointAddons do
local waypoint = waypointAddons[i]
if waypoint.standard or C_AddOns.IsAddOnLoaded(waypoint.name) then
if not waypoint.canUse or waypoint:canUse() then
return waypoint
end
end
end
end
---@param poi CandyBucketsMapPosition
---@param wholeModule? boolean
---@param silent? boolean
---@return boolean success
function ns:AutoWaypoint(poi, wholeModule, silent)
local waypoint = ns:GetWaypointAddon()
if not waypoint then
if not silent then
if not supportedAddonsWarned and supportedAddons ~= "" then
supportedAddonsWarned = true
Output("You need to install one of these supported waypoint addons: %s", supportedAddons)
end
end
return false
end
local status, err = pcall(function() return waypoint:func(poi, wholeModule) end)
if not status or err ~= true then
if not silent then
Output("Unable to set waypoint%s%s", waypoint.standard and "" or format(" using %s", waypoint.name), type(err) == "string" and format(": %s", err) or ".")
end
return false
end
return true
end
---@param questID number
---@return boolean success
function ns:RemoveQuestWaypoint(questID)
local waypoint = ns:GetWaypointAddon()
if not waypoint then
return false
end
if not waypoint.funcRemove then
return false
end
local status, err = pcall(function() return waypoint:funcRemove(questID) end)
if not status or err ~= true then
return false
end
return true
end
---@return boolean success
function ns:AutoWaypointClosest()
local waypoint = ns:GetWaypointAddon()
if not waypoint then
return false
end
if not waypoint.funcClosest then
return false
end
local status, err = pcall(function() return waypoint:funcClosest() end)
if not status or err ~= true then
return false
end
return true
end
end
--
-- Mixin
--
---@class CandyBucketsDataProvider
CandyBucketsDataProviderMixin = CreateFromMixins(MapCanvasDataProviderMixin)
function CandyBucketsDataProviderMixin:OnShow()
end
function CandyBucketsDataProviderMixin:OnHide()
end
---@param event WowEvent
---@param ... any
function CandyBucketsDataProviderMixin:OnEvent(event, ...)
-- self:RefreshAllData()
end
function CandyBucketsDataProviderMixin:RemoveAllData()
local map = self:GetMap()
map:RemoveAllPinsByTemplate("CandyBucketsPinTemplate")
map:RemoveAllPinsByTemplate("CandyBucketsStatsTemplate")
end
---@param fromOnShow boolean?
function CandyBucketsDataProviderMixin:RefreshAllData(fromOnShow)
self:RemoveAllData()
local map = self:GetMap()
local isTaxiMap = IsTaxiMap(map)
local uiMapID = map:GetMapID()
local childUiMapIDs = ns.PARENT_MAP[uiMapID]
local tempVector = { x = 0, y = 0 } ---@type Vector2DMixin
local questPOIs ---@type table<CandyBucketsQuest, Vector2DMixin>?
if isTaxiMap then
uiMapID = ns.PARENT_MAP_TAXI[uiMapID]
childUiMapIDs = ns.PARENT_MAP[uiMapID]
end
if IsModifierKeyDown() then
questPOIs = {}
end
for i = 1, #ns.QUESTS do
local quest = ns.QUESTS[i]
local poi ---@type Vector2DMixin?
local poi2 ---@type Vector2DMixin?
if not childUiMapIDs then
poi = quest[uiMapID] ---@type Vector2DMixin?
else
for childUiMapID, _ in pairs(childUiMapIDs) do
poi = quest[childUiMapID] ---@type Vector2DMixin?
if poi then
local translateKey = format("%s,%s", uiMapID, childUiMapID)
if poi[translateKey] ~= nil then
poi = poi[translateKey]
else
tempVector.x, tempVector.y = poi[1]/100, poi[2]/100
local continentID, worldPos = C_Map.GetWorldPosFromMapPos(childUiMapID, tempVector)
poi, poi2 = nil, poi
if continentID and worldPos then
local _, mapPos = C_Map.GetMapPosFromWorldPos(continentID, worldPos, uiMapID)
if mapPos then
poi = mapPos
poi2[translateKey] = mapPos
end
end
if not poi then
poi2[translateKey] = false
end
end
break
end
end
end
if poi then
map:AcquirePin("CandyBucketsPinTemplate", quest, poi, isTaxiMap)
if questPOIs then
questPOIs[quest] = poi
end
end
end
if questPOIs and next(questPOIs) then
map:AcquirePin("CandyBucketsStatsTemplate", questPOIs)
end
end
--
-- Pin
--
local PIN_BORDER_TRANSPARENT = 918860
local PIN_BORDER_COLOR = {
[0] = "Interface\\Buttons\\GREYSCALERAMP64",
[1] = "Interface\\Buttons\\BLUEGRAD64",
[2] = "Interface\\Buttons\\REDGRAD64",
[3] = "Interface\\Buttons\\YELLOWORANGE64",
}
---@class CandyBucketsPin
---@field public quest? any
---@field public name? string
---@field public description? string
---@class CandyBucketsPin
CandyBucketsPinMixin = CreateFromMixins(MapCanvasPinMixin)
function CandyBucketsPinMixin:OnLoad()
self:SetScalingLimits(1, 1.0, 1.2)
self.HighlightTexture:Hide()
self.hasTooltip = true
self:EnableMouse(self.hasTooltip)
self.Texture:ClearAllPoints()
self.Texture:SetAllPoints()
end
---@param texture number|string
---@param border number|string
---@param noBorderPlainIcon? boolean
function CandyBucketsPinMixin:SetTextureAndBorder(texture, border, noBorderPlainIcon)
if noBorderPlainIcon then
self.Texture:SetMask("")
self.Border:SetMask("")
self.Border:Hide()
else
self.Texture:SetMask("Interface\\CharacterFrame\\TempPortraitAlphaMask")
self.Border:SetMask("Interface\\CharacterFrame\\TempPortraitAlphaMask")
self.Border:Show()
end
self.Texture:SetTexture(texture)
self.Border:SetTexture(border)
end
---@param quest CandyBucketsQuest
---@param poi Vector2DMixin
---@param isTaxiMap boolean
function CandyBucketsPinMixin:OnAcquired(quest, poi, isTaxiMap)
self.quest = quest
local map = self:GetMap()
self:UseFrameLevelType("PIN_FRAME_LEVEL_CANDY_BUCKET_ICON", map:GetNumActivePinsByTemplate("CandyBucketsPinTemplate"))
self:SetSize(12, 12)
self:EnableMouse(not isTaxiMap)
local texture = quest.module.texture[quest.extra or 1]
if quest.style == 2 then
self:SetTextureAndBorder(texture, PIN_BORDER_TRANSPARENT, true)
else
self:SetTextureAndBorder(texture, PIN_BORDER_COLOR[quest.side or 0])
end
self.name = quest.module.title[quest.extra or 1]
if poi.GetXY then
self:SetPosition(poi:GetXY())
else
self:SetPosition(poi[1]/100, poi[2]/100)
end
local uiMapID = map:GetMapID()
if not uiMapID then
return
end
local x, y = self:GetPosition()
local childUiMapID, childX, childY = GetLowestLevelMapFromMapID(uiMapID, x, y)
local mapInfo = C_Map.GetMapInfo(childUiMapID)
if mapInfo and mapInfo.name and childX and childY then
self.description = format("%s (%.2f, %.2f)", mapInfo.name, childX * 100, childY * 100)
end
end
function CandyBucketsPinMixin:OnReleased()
self.quest = nil
self.name = nil
self.description = nil
end
function CandyBucketsPinMixin:OnMouseEnter()
if not self.hasTooltip then return end
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
self.UpdateTooltip = self.OnMouseEnter
GameTooltip_SetTitle(GameTooltip, self.name)
if self.description and self.description ~= "" then
GameTooltip_AddNormalLine(GameTooltip, self.description, true)
end
GameTooltip_AddNormalLine(GameTooltip, format("Quest ID: %s", self.quest.quest), false)
if ns:GetWaypointAddon() then
GameTooltip_AddNormalLine(GameTooltip, "<Click to show waypoint.>", false)
end
GameTooltip:Show()
end
function CandyBucketsPinMixin:OnMouseLeave()
if not self.hasTooltip then return end
GameTooltip:Hide()
end
function CandyBucketsPinMixin:OnClick(button)
if button ~= "LeftButton" then return end
ns:AutoWaypoint(self, IsModifierKeyDown())
end
--
-- Stats
--
---@class CandyBucketsStats
---@field public hasTooltip boolean
---@field public name? string
---@field public description? string
---@class CandyBucketsStats
CandyBucketsStatsMixin = CreateFromMixins(MapCanvasPinMixin)
function CandyBucketsStatsMixin:OnLoad()
self:SetScalingLimits(1, 1.0, 1.2)
self.HighlightTexture:Hide()
self.hasTooltip = false
self:EnableMouse(self.hasTooltip)
self.Texture:Hide()
end
---@param questPOIs table<CandyBucketsQuest, Vector2DMixin>
function CandyBucketsStatsMixin:OnAcquired(questPOIs)
local map = self:GetMap()
self:UseFrameLevelType("PIN_FRAME_LEVEL_CANDY_BUCKET_STATS", map:GetNumActivePinsByTemplate("CandyBucketsStatsTemplate"))
self:SetSize(map:GetSize())
self:SetPosition(.5, .5)
--self:ClearAllPoints()
--self:SetPoint("TOPLEFT", map:GetCanvasContainer(), "TOPLEFT", 0, 0)
self.name = nil
self.description = nil
local text
local i = 0
local uiMapID = map:GetMapID()
if uiMapID then
text = {}
for quest, poi in pairs(questPOIs) do
local x, y
if poi.GetXY then
x, y = poi:GetXY()
else
x, y = poi[1]/100, poi[2]/100
end
local childUiMapID, childX, childY = GetLowestLevelMapFromMapID(uiMapID, x, y)
if childX > 0 and childX < 1 and childY > 0 and childY < 1 then
local mapInfo = C_Map.GetMapInfo(childUiMapID)
i = i + 1
if mapInfo and mapInfo.name then
text[i] = format("%s (%.2f, %.2f)", mapInfo.name, childX * 100, childY * 100)
else
text[i] = format("#%d", quest.quest)
end
end
end
table.sort(text)
text = table.concat(text, "\r\n")
end
self.Text:SetText(text)
end
function CandyBucketsStatsMixin:OnReleased()
self.name = nil
self.description = nil
end
function CandyBucketsStatsMixin:OnMouseEnter()
if not self.hasTooltip then return end
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
self.UpdateTooltip = self.OnMouseEnter
GameTooltip_SetTitle(GameTooltip, self.name)
if self.description and self.description ~= "" then
GameTooltip_AddNormalLine(GameTooltip, self.description, true)
end
GameTooltip:Show()
end
function CandyBucketsStatsMixin:OnMouseLeave()
if not self.hasTooltip then return end
GameTooltip:Hide()
end
function CandyBucketsStatsMixin:OnClick(button)
if button ~= "LeftButton" then return end
-- TODO: ?
end
--
-- Modules
--
ns.modules = ns.modules or {}
---@type table<number, CandyBucketsModuleName>
local MODULE_FROM_TEXTURE = {
[235461] = "hallow",
[235462] = "hallow",
[235460] = "hallow",
[235470] = "lunar",
[235471] = "lunar",
[235469] = "lunar",
[235473] = "midsummer",
[235474] = "midsummer",
[235472] = "midsummer",
[235442] = "brewfest",
[235441] = "brewfest",
[235440] = "brewfest",
}
--
-- Addon
--
local addon = CreateFrame("Frame") ---@class CandyBucketsAddOn : Frame
addon:SetScript("OnEvent", function(addon, event, ...) addon[event](addon, event, ...) end)
addon:RegisterEvent("ADDON_LOADED")
addon:RegisterEvent("PLAYER_LOGIN")
---@type fun(): boolean
local InjectDataProviders do
local loadedWorldMap = false
local loadedFlightMap = false
local function OnLoad(self)
local dataProvider = CreateFromMixins(CandyBucketsDataProviderMixin)
ns.PROVIDERS[dataProvider] = true
self:AddDataProvider(dataProvider)
local pinFrameLevelsManager = self:GetPinFrameLevelsManager()
pinFrameLevelsManager:AddFrameLevel("PIN_FRAME_LEVEL_CANDY_BUCKET_ICON", 500)
pinFrameLevelsManager:AddFrameLevel("PIN_FRAME_LEVEL_CANDY_BUCKET_STATS")
end
function InjectDataProviders()
if WorldMapFrame and not loadedWorldMap then
loadedWorldMap = true
hooksecurefunc(WorldMapMixin, "OnLoad", OnLoad)
OnLoad(WorldMapFrame)
end
if FlightMapFrame and not loadedFlightMap then
loadedFlightMap = true
hooksecurefunc(FlightMapMixin, "OnLoad", OnLoad)
OnLoad(FlightMapFrame)
end
return loadedWorldMap and loadedFlightMap
end
end
---@param onlyShownMaps boolean
---@param fromOnShow? boolean
function addon:RefreshAllWorldMaps(onlyShownMaps, fromOnShow)
for dataProvider, _ in pairs(ns.PROVIDERS) do
if not onlyShownMaps or dataProvider:GetMap():IsShown() then
dataProvider:RefreshAllData(fromOnShow)
end
end
end
---@param questID number
function addon:RemoveQuestPois(questID)
local removed = 0
for i = #ns.QUESTS, 1, -1 do
local quest = ns.QUESTS[i]
if quest.quest == questID then
removed = removed + 1
table.remove(ns.QUESTS, i)
end
end
return removed > 0
end
---@param name CandyBucketsModuleName
function addon:CanLoadModule(name)
return type(ns.modules[name]) == "table" and ns.modules[name].loaded ~= true
end
---@param name CandyBucketsModuleName
function addon:CanUnloadModule(name)
return type(ns.modules[name]) == "table" and ns.modules[name].loaded == true
end
---@param name CandyBucketsModuleName
function addon:LoadModule(name)
local module = ns.modules[name]
module.loaded = true
local i = #ns.QUESTS
for j = 1, #module.quests do
local quest = module.quests[j]
if (not quest.side or quest.side == 3 or quest.side == ns.FACTION or DEBUG_FACTION) and not ns.COMPLETED_QUESTS[quest.quest] then
quest.module = module
i = i + 1