-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmap.lua
More file actions
2019 lines (1797 loc) · 74.6 KB
/
Copy pathmap.lua
File metadata and controls
2019 lines (1797 loc) · 74.6 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
-- multi api compat
local compat = pfQuestCompat
-- Performance: cache frequently-used globals
local pairs, ipairs, next = pairs, ipairs, next
local strfind, strlower, strsub = strfind, strlower, strsub
local format = string.format
local min, max, abs = math.min, math.max, math.abs
local sqrt, sin, cos = sqrt or math.sqrt, sin or math.sin, cos or math.cos
local floor, ceil = floor or math.floor, ceil or math.ceil
local getn, insert = table.getn, table.insert
local tostring, tonumber, type, unpack = tostring, tonumber, type, unpack
local GetTime = GetTime
local MouseIsOver = MouseIsOver
-- fake the pfQuest minimap node names to Gatherer names,
-- if any minimap-breaking addon collector is found.
local nodename = "pfMiniMapPin"
local minimapbreakers = {
["ElvUI_MinimapButtons"] = true,
["MBB"] = true,
}
local compatnamefake = CreateFrame("Frame")
compatnamefake:RegisterEvent("PLAYER_ENTERING_WORLD")
compatnamefake:SetScript("OnEvent", function()
-- only run once on login
this:UnregisterAllEvents()
-- scan through all addons to identify button collectors
for i = 1, GetNumAddOns() do
local name, title, notes, enabled = GetAddOnInfo(i)
if enabled and minimapbreakers[name] then
nodename = "GatherNoteCompatFake"
end
end
end)
-- checking for control key is very time expensive in 1.12
-- Poll IsControlKeyDown() frequently enough that Ctrl feels responsive.
-- Always clear when the map is not shown to avoid sticky state from a
-- previous session (e.g. Ctrl released while mouse was off the map).
local controlkey = CreateFrame("Frame", "pfQuestControlKey", UIParent)
controlkey:SetScript("OnUpdate", function()
if (this.throttle or 0.05) > GetTime() then
return
else
this.throttle = GetTime() + 0.05
end
if WorldMapFrame:IsShown() and MouseIsOver(WorldMapFrame) then
controlkey.pressed = IsControlKeyDown()
elseif MouseIsOver(pfMap.drawlayer) then
controlkey.pressed = IsControlKeyDown()
else
controlkey.pressed = nil
end
end)
-- mainmap_inversescale separates two distinct scale events on the world map:
-- * MAP MODE change (windowed/questlist/fullmap): Blizzard scales BOTH
-- WorldMapDetailFrame and WorldMapButton by WORLDMAP_SETTINGS.size.
-- Their LOCAL scales stay equal -> ratio = 1 -> no compensation, pins
-- scale naturally with the map.
-- * ZOOM addons (Magnify): scale ONLY WorldMapDetailFrame while keeping
-- WorldMapButton.local at 1 (Magnify reparents Button under DetailFrame).
-- Local ratio diverges -> we compensate so pins keep a constant screen
-- pixel size through the zoom.
-- Formula: mainmap_inversescale = WorldMapButton:GetScale() / WorldMapDetailFrame:GetScale()
-- Global (no `local`) so pfQuest-epoch's continent pins can read the same value.
mainmap_inversescale = 1.0
local validmaps = setmetatable({}, { __mode = "kv" })
local rgbcache = setmetatable({}, { __mode = "kv" })
local minimap_sizes = pfDB["minimap"]
local minimap_zoom = {
[0] = {
[0] = 300,
[1] = 240,
[2] = 180,
[3] = 120,
[4] = 80,
[5] = 50,
},
[1] = {
[0] = 466 + 2 / 3,
[1] = 400,
[2] = 333 + 1 / 3,
[3] = 266 + 2 / 6,
[4] = 200,
[5] = 133 + 1 / 3,
},
}
local unifiedcache = {}
-- used to store/cache combined meta data across nodes of
-- the same kind to avoid duplicating data for each pin
-- the objects here get directly attached to the pfMap nodes
local similar_nodes = {}
-- Coordinate parse cache (shared between UpdateNodes and UpdateMinimap)
local coord_cache = {}
local function IsEmpty(tabl)
for k, v in pairs(tabl) do
return false
end
return true
end
-- Ensure pfQuestConfig.path exists (fallback if config.lua failed)
local addon_path = (pfQuestConfig and pfQuestConfig.path) or "Interface\\AddOns\\pfQuest"
local layers = {
-- regular icons
[addon_path .. "\\img\\available"] = 1,
[addon_path .. "\\img\\available_c"] = 2,
[addon_path .. "\\img\\complete"] = 3,
[addon_path .. "\\img\\complete_c"] = 4,
[addon_path .. "\\img\\icon_vendor"] = 5,
[addon_path .. "\\img\\fav"] = 6,
-- cluster textures
[addon_path .. "\\img\\cluster_item"] = 9,
[addon_path .. "\\img\\cluster_mob"] = 9,
[addon_path .. "\\img\\cluster_misc"] = 9,
[addon_path .. "\\img\\cluster_mob_mono"] = 9,
[addon_path .. "\\img\\cluster_item_mono"] = 9,
[addon_path .. "\\img\\cluster_misc_mono"] = 9,
}
-- Pre-computed texture paths (avoid string concatenation in hot paths)
local TEX_NODECUT = addon_path .. "\\img\\nodecut"
local TEX_NODE = addon_path .. "\\img\\node"
local function GetLayerByTexture(tex)
if layers[tex] then
return layers[tex]
else
return 1
end
end
-- Reforged: the indoor/outdoor probe below CHANGES the minimap zoom twice to
-- disambiguate, and it used to run on every UpdateMinimap pass -- up to ~20
-- times a second while moving. Any addon that hooks Minimap.SetZoom therefore
-- got hammered: ElvUI's "reset zoom" feature hooks exactly that and re-arms a
-- timer which forces the zoom back, so pfQuest's cached zoom and the real one
-- drift apart and every node is culled as out-of-range -- an empty minimap
-- while the world map is fine (issue #15). The state only changes when the
-- player moves indoors/outdoors or the zoom actually changes, so compute it on
-- those events instead and cache it. Also removes ~40 SetZoom calls a second.
-- ... except it did not, until the guard below. The probe detects indoor/outdoor
-- by NUDGING the minimap zoom and reading it back, and Minimap:SetZoom fires
-- MINIMAP_UPDATE_ZOOM, which is one of the events that dirties this cache. So
-- the probe invalidated itself, re-ran on the very next call, and kept the ~40
-- SetZoom calls a second it was written to remove. Worse than wasted work: every
-- one of those is an event other minimap addons react to, and with ElvUI loaded
-- the result was a minimap that only showed its pins for the split second after
-- a zone change (issue #15). Ignore the events the probe causes itself.
local indoorstate, indoordirty, indoorprobing = 1, true, nil
local indoorwatch = CreateFrame("Frame")
indoorwatch:RegisterEvent("PLAYER_ENTERING_WORLD")
indoorwatch:RegisterEvent("ZONE_CHANGED")
indoorwatch:RegisterEvent("ZONE_CHANGED_INDOORS")
indoorwatch:RegisterEvent("ZONE_CHANGED_NEW_AREA")
indoorwatch:RegisterEvent("MINIMAP_UPDATE_ZOOM")
indoorwatch:SetScript("OnEvent", function()
if indoorprobing then
return
end
indoordirty = true
end)
-- GetMinimapShape is an addon convention rather than a client API: square
-- minimap addons (ElvUI, and pfUI through its own flag above) define this
-- global so pin addons can widen the round cull to the corners. Guarded call,
-- because nothing defines it on a stock client.
local function squareminimap()
if type(GetMinimapShape) ~= "function" then return nil end
local ok, shape = pcall(GetMinimapShape)
return ok and shape and shape ~= "ROUND" and true or nil
end
local function minimap_indoor_probe()
local state = 1
-- remember the real zoom rather than trying to undo the nudge by arithmetic:
-- SetZoom clamps to 0..5, so stepping off either end and adding the step back
-- left the minimap one level away from where it started, every probe.
local zoom = pfMap.drawlayer:GetZoom()
indoorprobing = true
if GetCVar("minimapZoom") == GetCVar("minimapInsideZoom") then
-- the two CVars are equal, so the zoom alone cannot say which one is in
-- effect: nudge one step, in whichever direction stays in range
pfMap.drawlayer:SetZoom(zoom > 0 and zoom - 1 or zoom + 1)
end
if GetCVar("minimapInsideZoom") + 0 == pfMap.drawlayer:GetZoom() then
state = 0
end
pfMap.drawlayer:SetZoom(zoom)
indoorprobing = nil
return state
end
local function minimap_indoor()
if indoordirty then
indoordirty = nil
indoorstate = minimap_indoor_probe()
end
return indoorstate
end
local function str2rgb(text)
if not text then
return 1, 1, 1
end
if pfQuest_colors[text] then
return unpack(pfQuest_colors[text])
end
if rgbcache[text] then
return unpack(rgbcache[text])
end
local counter = 1
local l = string.len(text)
for i = 1, l, 3 do
counter = compat.mod(counter * 8161, 4294967279)
+ (string.byte(text, i) * 16776193)
+ ((string.byte(text, i + 1) or (l - i + 256)) * 8372226)
+ ((string.byte(text, i + 2) or (l - i + 256)) * 3932164)
end
local hash = compat.mod(compat.mod(counter, 4294967291), 16777216)
local r = (hash - (compat.mod(hash, 65536))) / 65536
local g = ((hash - r * 65536) - (compat.mod((hash - r * 65536), 256))) / 256
local b = hash - r * 65536 - g * 256
rgbcache[text] = { r / 255, g / 255, b / 255 }
return unpack(rgbcache[text])
end
local fpsmod, step
local function NodeAnimate(self, zoom, alpha, fps)
local cur_zoom = self:GetWidth()
local cur_alpha = self:GetAlpha()
local change = nil
self:EnableMouse(true)
fpsmod = math.min(2 / fps, 2)
step = fpsmod / 10
-- update size
if math.abs(cur_zoom - zoom) < 3 then
self:SetWidth(zoom)
self:SetHeight(zoom)
elseif cur_zoom < zoom then
self:SetWidth(cur_zoom + fpsmod)
self:SetHeight(cur_zoom + fpsmod)
change = true
elseif cur_zoom > zoom then
self:SetWidth(cur_zoom - fpsmod)
self:SetHeight(cur_zoom - fpsmod)
change = true
end
-- update alpha
if math.abs(cur_alpha - alpha) < step then
self:SetAlpha(alpha)
-- disable mouse on hidden
if alpha < 0.1 then
self:EnableMouse(nil)
end
elseif cur_alpha < alpha then
self:SetAlpha(cur_alpha + step)
change = true
elseif cur_alpha > alpha then
self:SetAlpha(cur_alpha - step)
change = true
end
return change
end
-- put player position above everything on worldmap
for k, v in pairs({ WorldMapFrame:GetChildren() }) do
if v:IsObjectType("Model") and not v:GetName() then
if string.find(strlower(v:GetModel()), "interface\\minimap\\minimaparrow") then
v:SetFrameLevel(255)
break
end
end
end
pfMap = CreateFrame("Frame", "pfQuestMap", WorldFrame)
pfMap.str2rgb = str2rgb
pfMap.tooltips = {}
pfMap.nodes = {}
pfMap.pins = {}
pfMap.mpins = {}
pfMap.drawlayer = Minimap
pfMap.unifiedcache = unifiedcache
-- Reverse indexes for O(1) DeleteNode lookups.
-- titleIndex[addon][title][map][coords] = true — set by AddNode
-- tooltipIndex[title][spawn] = true — set by AddNode
pfMap.titleIndex = {}
pfMap.tooltipIndex = {}
-- Set of node tables that have been modified since the last UpdateNodes call.
-- Keyed by node table reference so the node table itself stays clean.
-- AddNode/DeleteNode insert here; UpdateNodes reads and clears entries.
pfMap.dirtyNodes = {}
-- Set of map IDs that have at least one dirty node table.
-- Keyed by zone map ID (integer). Allows WORLD_MAP_UPDATE to cheaply check
-- whether the current zone has pending writes without scanning all dirtyNodes.
pfMap.dirtyMaps = {}
pfMap.minimap_indoor = minimap_indoor
pfMap.minimap_zoom = minimap_zoom
pfMap.minimap_sizes = minimap_sizes
pfMap.tooltip = CreateFrame("Frame", "pfMapTooltip", GameTooltip)
pfMap.tooltip:SetScript("OnShow", function()
local focus = GetMouseFocus()
-- abort on pfQuest nodes
if focus and focus.title then
return
end
-- abort on quest timers
if focus and focus.GetName and strsub((focus:GetName() or ""), 0, 10) == "QuestTimer" then
return
end
-- abort if tooltips are disabled
if pfQuest_config.showtooltips == "0" then
return
end
local name = getglobal("GameTooltipTextLeft1") and getglobal("GameTooltipTextLeft1"):GetText() or "__NONE__"
local zone = pfMap:GetMapID(GetCurrentMapContinent(), GetCurrentMapZone())
-- remove all colors from received tooltip text
name = string.gsub(name, "|c%x%x%x%x%x%x%x%x", "")
name = string.gsub(name, "|r", "")
if pfMap.tooltips[name] and pfMap.tooltips[name] then
for title, obj in pairs(pfMap.tooltips[name]) do
if obj[zone] then
pfMap:ShowTooltip(obj[zone], GameTooltip)
GameTooltip:Show()
end
end
end
end)
-- dummy function that can be used by extensions
-- to avoid drawing the minimap at some locations
function pfMap:HasMinimap()
return true
end
function pfMap.tooltip:GetColor(min, max)
local max = max or 1
local min = min or max or 1
local perc = min / max
local r1, g1, b1, r2, g2, b2
if perc <= 0.5 then
perc = perc * 2
r1, g1, b1 = 1, 0, 0
r2, g2, b2 = 1, 1, 0
else
perc = perc * 2 - 1
r1, g1, b1 = 1, 1, 0
r2, g2, b2 = 0, 1, 0
end
r = r1 + (r2 - r1) * perc
g = g1 + (g2 - g1) * perc
b = b1 + (b2 - b1) * perc
return r, g, b
end
function pfMap:HexDifficultyColor(level, force)
if force and UnitLevel("player") < level then
return "|cffff5555"
else
local c = pfQuestCompat.GetDifficultyColor(level)
return string.format("|cff%02x%02x%02x", c.r * 255, c.g * 255, c.b * 255)
end
end
function pfMap:ShowTooltip(meta, tooltip)
local catch = nil
local catch_obj = nil
local tooltip = tooltip or GameTooltip
-- add quest data
if meta["quest"] then
-- scan all quest entries for matches
for qid = 1, GetNumQuestLogEntries() do
local qtitle, _, _, _, _, complete = compat.GetQuestLogTitle(qid)
if meta["quest"] == qtitle then
-- handle active quests
local objectives = GetNumQuestLeaderBoards(qid)
catch = true
local symbol = (complete or objectives == 0) and "|cff555555[|cffffcc00?|cff555555]|r "
or "|cff555555[|cffffcc00!|cff555555]|r "
tooltip:AddLine(symbol .. meta["quest"], 1, 1, 0)
if objectives then
for i = 1, objectives, 1 do
local text, type, finished = GetQuestLogLeaderBoard(i, qid)
if type == "monster" then
-- kill
local i, j, monsterName, objNum, objNeeded =
strfind(text, pfUI.api.SanitizePattern(QUEST_MONSTERS_KILLED))
if monsterName and meta["spawn"] == monsterName then
catch_obj = true
local r, g, b = pfMap.tooltip:GetColor(objNum, objNeeded)
tooltip:AddLine("|cffaaaaaa- |r" .. monsterName .. ": " .. objNum .. "/" .. objNeeded, r, g, b)
end
elseif table.getn(meta["item"]) > 0 and type == "item" and meta["droprate"] then
-- loot
local i, j, itemName, objNum, objNeeded = strfind(text, pfUI.api.SanitizePattern(QUEST_OBJECTS_FOUND))
for mid, item in pairs(meta["item"]) do
if item == itemName then
catch_obj = true
local r, g, b = pfMap.tooltip:GetColor(objNum, objNeeded)
local dr, dg, db = pfMap.tooltip:GetColor(tonumber(meta["droprate"]), 100)
local lootcolor = string.format("%02x%02x%02x", dr * 255, dg * 255, db * 255)
tooltip:AddLine(
"|cffaaaaaa- |r"
.. itemName
.. ": "
.. objNum
.. "/"
.. objNeeded
.. " |cff555555[|cff"
.. lootcolor
.. meta["droprate"]
.. "%|cff555555]",
r,
g,
b
)
end
end
elseif table.getn(meta["item"]) > 0 and type == "item" and meta["sellcount"] then
-- vendor
local i, j, itemName, objNum, objNeeded = strfind(text, pfUI.api.SanitizePattern(QUEST_OBJECTS_FOUND))
for mid, item in pairs(meta["item"]) do
if item == itemName then
catch_obj = true
local r, g, b = pfMap.tooltip:GetColor(objNum, objNeeded)
local sellcount = tonumber(meta["sellcount"]) > 0
and " |cff555555[|cffcccccc" .. meta["sellcount"] .. "x" .. "|cff555555]"
or ""
tooltip:AddLine(
"|cffaaaaaa- |r"
.. pfQuest_Loc["Buy"]
.. ": "
.. itemName
.. ": "
.. objNum
.. "/"
.. objNeeded
.. sellcount,
r,
g,
b
)
end
end
end
end
end
end
end
if not catch then
tooltip:AddLine("|cff555555[|cffffcc00!|cff555555]|r " .. meta["quest"], 1, 1, 0.7)
end
if not catch_obj then
-- handle inactive quests
local catchFallback = nil
if meta["item"] and meta["item"][1] and meta["droprate"] then
for mid, item in pairs(meta["item"]) do
catchFallback = true
local dr, dg, db = pfMap.tooltip:GetColor(tonumber(meta["droprate"]), 100)
local lootcolor = string.format("%02x%02x%02x", dr * 255, dg * 255, db * 255)
tooltip:AddLine(
"|cffaaaaaa- |r" .. item .. " |cff555555[|cff" .. lootcolor .. meta["droprate"] .. "%|cff555555]",
0.7,
0.7,
0.7
)
end
end
if meta["item"] and meta["item"][1] and meta["sellcount"] then
for mid, item in pairs(meta["item"]) do
catchFallback = true
local sellcount = tonumber(meta["sellcount"]) > 0
and " |cff555555[|cffcccccc" .. meta["sellcount"] .. "x" .. "|cff555555]"
or ""
tooltip:AddLine("|cffaaaaaa- |r" .. pfQuest_Loc["Buy"] .. ": " .. item .. sellcount, 0.7, 0.7, 0.7)
end
end
if not catchFallback and meta["spawn"] and not meta["texture"] then
catchFallback = true
tooltip:AddLine(
"|cffaaaaaa- |r"
.. (meta["spawntype"] and meta["spawntype"] == "Trigger" and pfQuest_Loc["Explore"] or meta["spawn"]),
0.7,
0.7,
0.7
)
end
if not catchFallback and meta["texture"] and meta["qlvl"] then
local texts = meta["questid"] and pfDB["quests"]["loc"][meta["questid"]] or nil
if texts and texts["O"] and texts["O"] ~= "" then
tooltip:AddLine(pfDatabase:FormatQuestText(texts["O"]), 1, 1, 0.9, true)
end
local qlvlstr = pfQuest_Loc["Level"] .. ": " .. pfMap:HexDifficultyColor(meta["qlvl"]) .. meta["qlvl"] .. "|r"
local qminstr = meta["qmin"]
and " / " .. pfQuest_Loc["Required"] .. ": " .. pfMap:HexDifficultyColor(meta["qmin"], true) .. meta["qmin"] .. "|r"
or ""
tooltip:AddLine("|cffaaaaaa- |r" .. qlvlstr .. qminstr, 0.8, 0.8, 0.8)
end
end
else
-- handle non-quest objects
if meta["item"][1] and meta["itemid"] and not meta["itemlink"] then
local _, _, itemQuality = GetItemInfo(meta["itemid"])
if itemQuality then
local itemColor = "|c"
.. string.format(
"%02x%02x%02x%02x",
255,
ITEM_QUALITY_COLORS[itemQuality].r * 255,
ITEM_QUALITY_COLORS[itemQuality].g * 255,
ITEM_QUALITY_COLORS[itemQuality].b * 255
)
meta["itemlink"] = itemColor .. "|Hitem:" .. meta["itemid"] .. ":0:0:0|h[" .. meta["item"][1] .. "]|h|r"
end
end
if meta["sellcount"] then
local item = meta["itemlink"] or "[" .. meta["item"][1] .. "]"
local sellcount = tonumber(meta["sellcount"]) > 0
and " |cff555555[|cffcccccc" .. meta["sellcount"] .. "x" .. "|cff555555]"
or ""
tooltip:AddLine(pfQuest_Loc["Vendor"] .. ": " .. item .. sellcount, 1, 1, 1)
elseif meta["item"][1] then
local item = meta["itemlink"] or "[" .. meta["item"][1] .. "]"
local r, g, b = pfMap.tooltip:GetColor(tonumber(meta["droprate"]), 100)
tooltip:AddLine(
"|cffffffff" .. pfQuest_Loc["Loot"] .. ": " .. item .. " |cff555555[|r" .. meta["droprate"] .. "%|cff555555]",
r,
g,
b
)
end
end
tooltip:Show()
end
function pfMap:GetMapNameByID(id)
id = tonumber(id)
return pfDB["zones"]["loc"][id] or nil
end
function pfMap:GetMapIDByName(search)
for id, name in pairs(pfDB["zones"]["loc"]) do
if name == search then
return id
end
end
end
function pfMap:ShowMapID(map)
if map then
if ToggleWorldMap then
-- vanilla & tbc
if not WorldMapFrame:IsShown() then
ToggleWorldMap()
end
else
-- wotlk
WorldMapFrame:Show()
end
pfMap:SetMapByID(map)
pfMap:UpdateNodes()
return true
end
return nil
end
function pfMap:SetMapByID(id)
local search = pfDB["zones"]["loc"][id]
for cid, cname in pairs({ GetMapContinents() }) do
for mid, mname in pairs({ GetMapZones(cid) }) do
if mname == search then
SetMapZoom(cid, mid)
return
end
end
end
end
local customids = {
["AlteracValley"] = 2597,
}
-- Reforged: sub-maps -- a map area that is a PIECE of a zone pfQuest has data
-- for, rather than a zone of its own (issue #20).
--
-- The Caverns and Mines client patch, which the WDM addon collection is built
-- for, registers the eight starter zones as their own map areas. pfQuest has no
-- data keyed to them (its coordinates are all on the parent zone's rectangle),
-- so GetMapID found no match, UpdateNodes bailed on a nil map, and the whole
-- starter experience showed nothing at all.
--
-- The entry is { parent zone id, left, top, width, height }, the sub-map's
-- rectangle expressed in the PARENT map's percentages. A parent coordinate
-- becomes a sub-map coordinate with (value - left) / size * 100, and anything
-- landing outside 0..100 is simply not on this map and gets culled.
--
-- DERIVED, not guessed. The WDM collection ships continent offsets and extents
-- for both the sub-maps and their parents in its bundled Astrolabe, so each
-- rectangle is (child.xOffset - parent.xOffset) / parent.width and so on. Three
-- checks before trusting them: WDM's GatherMate ships the same eight extents
-- independently and agrees to four decimals on every one; every rectangle comes
-- out square in percentage terms (width% within 0.1% of height%), which has to
-- hold because parent and child are both 3:2; and each one lands where the zone
-- actually is, with Camp Narache and Ammen Vale reaching ~1.5% past the parent
-- edge exactly as they should, both sitting on the map border.
--
-- The KEYS are GetMapInfo() values. Confirmed from two independent tables in
-- that collection that are documented in code to be GetMapInfo()-keyed
-- (Astrolabe's zoneData, GatherMate's zone_data) plus WDM's own mdlevels, which
-- carries Blizzard's "Ogrimmar" misspelling as a giveaway that these are raw
-- map file names. Inert without the patch: these map areas do not exist, so
-- GetMapInfo() never returns any of them.
local submaps = {
-- Eastern Kingdoms
["Northshire"] = { 12, 38.84, 27.27, 27.91, 27.90 }, -- Elwynn Forest
["ColdridgeValley"] = { 1, 16.71, 63.51, 19.59, 19.61 }, -- Dun Morogh
["DeathknellStart"] = { 85, 19.59, 52.00, 24.11, 24.14 }, -- Tirisfal Glades
["SunstriderIsleStart"] = { 3430, 18.19, 6.34, 32.49, 32.49 }, -- Eversong Woods
-- Kalimdor
["ShadowglenStart"] = { 141, 45.62, 23.51, 28.48, 28.48 }, -- Teldrassil
["ValleyofTrialsStart"] = { 14, 31.75, 51.30, 25.53, 25.53 }, -- Durotar
["CampNaracheStart"] = { 215, 35.32, 67.28, 34.39, 34.37 }, -- Mulgore
["AmmenValeStart"] = { 3524, 56.85, 29.86, 44.68, 44.67 }, -- Azuremyst Isle
-- The mine, cave and cavern interiors the same patch adds (issue #20 again).
-- Same mechanism, and the same reason they were empty: pfQuest stores what is
-- inside them at the PARENT zone's coordinates, because that is the only
-- rectangle its data has ever had. Generated straight from the patch's
-- WorldMapArea.dbc rather than derived, walking parentWorldMapID up to the
-- first ancestor pfQuest holds coordinates for. That resolves the awkward
-- ones by construction: Frostmane Hovel is a floor of Coldridge Valley, which
-- is itself a sub-map, and both reduce to Dun Morogh; Scarlet Monastery and
-- the Deadmines carry no parent at all and are placed by containment.
--
-- KNOWN LIMIT, and it is worth saying plainly: pfQuest has no z coordinate,
-- so "inside this rectangle" cannot distinguish the cave from the hillside
-- above it. Surface nodes over a mine will appear on the mine's map. That is
-- tolerable for the small ones, where nearly everything in the rectangle IS
-- the mine, and noticeable for the big ones, where Blackrock Mountain, Uldaman
-- and Ragefire Chasm each cover a fifth or more of their zone. An overlaid
-- pin is still better than the blank map these all drew before.
["Fargodeepmine1_"] = { 12, 36.12, 76.06, 6.91, 6.91 }, -- Elwynn
["Fargodeepmine2_"] = { 12, 35.90, 76.49, 7.35, 7.34 }, -- Elwynn
["EchoRidgeMine3_"] = { 12, 45.02, 24.21, 8.04, 8.04 }, -- Elwynn
["GoldCoastQuarry4_"] = { 40, 26.30, 44.14, 7.50, 7.50 }, -- Westfall
["JangolodeMine5_"] = { 40, 41.32, 17.09, 7.91, 7.91 }, -- Westfall
["ColdridgePass6_"] = { 1, 31.62, 65.27, 6.70, 6.70 }, -- DunMorogh
["TheGrizzledDen7_"] = { 1, 35.93, 43.73, 10.26, 10.26 }, -- DunMorogh
["FrostmaneHold8_"] = { 1, 19.37, 48.97, 6.94, 7.14 }, -- DunMorogh
["FrostmaneHovel9_"] = { 1, 26.27, 78.23, 5.41, 5.41 }, -- DunMorogh
["GnomereganEntrance10_"] = { 1, 14.60, 26.98, 14.83, 14.23 }, -- DunMorogh
["GolBolarQuarry11_"] = { 1, 67.92, 49.03, 7.59, 7.59 }, -- DunMorogh
["NightWebsHollow12_"] = { 85, 22.43, 56.90, 4.87, 4.87 }, -- Tirisfal
["ScarletMonasteryEntrance13_"] = { 28, 25.04, 14.58, 4.77, 4.77 }, -- WesternPlaguelands
["BlackrockMountain14_"] = { 46, 16.88, 15.05, 24.32, 24.33 }, -- BurningSteppes
["BlackrockMountain15_"] = { 46, 29.99, 22.99, 8.71, 8.71 }, -- BurningSteppes
["BlackrockMountain16_"] = { 46, 12.32, 2.84, 25.95, 25.96 }, -- BurningSteppes
["DeadminesWestfall17_"] = { 40, 34.98, 70.93, 12.86, 12.86 }, -- Westfall
["Uldaman18_"] = { 3, 26.92, 3.94, 22.61, 22.61 }, -- Badlands
["JasperlodeMine19_"] = { 12, 57.08, 45.17, 9.31, 9.31 }, -- Elwynn
["Ogrimmar1_"] = { 1637, 34.46, 36.52, 25.82, 25.81 }, -- Ogrimmar
["ShadowthreadCave2_"] = { 141, 52.53, 23.46, 9.43, 9.43 }, -- Teldrassil
["FelRock3_"] = { 141, 50.37, 47.72, 5.49, 5.49 }, -- Teldrassil
["BanethilBarrowden4_"] = { 141, 41.82, 57.45, 4.52, 4.52 }, -- Teldrassil
["BanethilBarrowden5_"] = { 141, 40.84, 55.97, 7.46, 7.46 }, -- Teldrassil
["PalemaneRock6_"] = { 215, 28.57, 58.11, 6.81, 6.81 }, -- Mulgore
["TheVentureCoMine7_"] = { 215, 55.78, 33.96, 14.42, 14.42 }, -- Mulgore
["BurningBladeCoven8_"] = { 14, 41.68, 51.14, 5.03, 5.03 }, -- Durotar
["TiragardeKeep10_"] = { 14, 58.44, 57.07, 2.36, 2.36 }, -- Durotar
["TiragardeKeep11_"] = { 14, 58.44, 57.07, 2.36, 2.36 }, -- Durotar
["SkullRock12_"] = { 14, 50.43, 6.46, 5.11, 5.11 }, -- Durotar
["TwilightsRun13_"] = { 1377, 68.22, 9.69, 7.25, 7.25 }, -- Silithus
["TheSlitheringScar14_"] = { 490, 41.00, 79.59, 10.34, 10.34 }, -- UngoroCrater
["TheNoxiousLair15_"] = { 440, 28.57, 38.37, 10.87, 10.87 }, -- Tanaris
["TheGapingChasm16_"] = { 440, 49.18, 65.76, 12.83, 12.83 }, -- Tanaris
["CavernsofTime17_"] = { 440, 57.17, 45.24, 16.05, 16.05 }, -- Tanaris
["CavernsofTime18_"] = { 440, 50.56, 46.99, 18.93, 18.93 }, -- Tanaris
["DustwindCave19_"] = { 14, 50.31, 23.75, 4.88, 4.88 }, -- Durotar
["WailingCavernsBarrens20_"] = { 17, 44.66, 31.12, 5.63, 5.62 }, -- Barrens
["MaraudonOutside21_"] = { 405, 25.53, 56.78, 13.35, 13.34 }, -- Desolace
["MaraudonOutside22_"] = { 405, 23.76, 51.52, 12.46, 12.45 }, -- Desolace
["AmaniCatacombs1_"] = { 3433, 57.47, 25.30, 9.09, 9.09 }, -- Ghostlands
["TidesHollow2_"] = { 3524, 21.35, 68.01, 9.21, 9.21 }, -- AzuremystIsle
["StillpineHold3_"] = { 3524, 42.93, 7.94, 11.67, 11.67 }, -- AzuremystIsle
}
-- The same eight, keyed by the zone id pfQuest ALREADY has for them: it has
-- always known them as SUBZONES of their parent, so Northshire Valley is 9,
-- Coldridge Valley is 132, and so on. Not one of those ids holds a single
-- coordinate; every node in those places is stored on the parent zone, which is
-- where pfQuest's own rectangle puts it. So anything resolving a zone by NAME
-- has to be redirected or it lands on an empty zone and draws nothing. That is
-- exactly what GetRealZoneText() gives while the player stands in a starter
-- zone, which the minimap and the tracker's proximity list both key off.
local subzoneparent = {
[9] = 12, -- Northshire Valley -> Elwynn Forest
[132] = 1, -- Coldridge Valley -> Dun Morogh
[154] = 85, -- Deathknell -> Tirisfal Glades
[3431] = 3430, -- Sunstrider Isle -> Eversong Woods
[188] = 141, -- Shadowglen -> Teldrassil
[363] = 14, -- Valley of Trials -> Durotar
[221] = 215, -- Camp Narache -> Mulgore
[3526] = 3524, -- Ammen Vale -> Azuremyst Isle
}
function pfMap:ParentZone(id)
if not id then return nil end
return subzoneparent[id] or id
end
-- The sub-map currently being VIEWED, or nil. Keyed on GetMapInfo() on purpose:
-- that is the same frame of reference GetPlayerMapPosition answers in, so the
-- world map and the minimap stay in step even while the player browses a map
-- they are not standing in.
function pfMap:GetSubmap()
return submaps[GetMapInfo() or ""]
end
-- Parent percentage -> sub-map percentage. Second return is false when the
-- point is not inside this sub-map at all.
function pfMap:ToSubmap(sub, x, y)
x = (x - sub[2]) / sub[4] * 100
y = (y - sub[3]) / sub[5] * 100
-- the epsilon is for float equality only, not a margin: a node sitting
-- exactly on the sub-map's edge divides out to 100.00000000000001 and would
-- otherwise be culled from the map it is actually on
local e = 0.000001
return x, y, (x >= -e and x <= 100 + e and y >= -e and y <= 100 + e)
end
-- Sub-map percentage -> parent percentage. The minimap converts this way round
-- instead: the player position is the ONE value it reads in sub-map space, and
-- lifting it into the parent leaves node coordinates, zone sizes and the yard
-- scale all in the space they were already in.
function pfMap:FromSubmap(sub, x, y)
return sub[2] + x / 100 * sub[4], sub[3] + y / 100 * sub[5]
end
local map_zone_cache = {}
function pfMap:GetMapID(cid, mid)
cid = cid or GetCurrentMapContinent()
mid = mid or GetCurrentMapZone()
-- GetMapZones() should always return the same amount
-- of zones for each continent, so we can cache it to
-- avoid further creations of the same table.
if not map_zone_cache[cid] then
map_zone_cache[cid] = { GetMapZones(cid) }
end
local list = map_zone_cache[cid]
local name = list[mid]
-- A sub-map answers with its PARENT: that is the zone the coordinates in the
-- database belong to. This has to take PRECEDENCE over the name lookup, not
-- fall back to it. The patch puts these map areas in GetMapZones under their
-- real names, and pfQuest has always had those names as subzone ids, so
-- "Northshire Valley" resolves to 9 -- a zone that holds no coordinates at
-- all. Answering 9 is worse than answering nothing: it looks like a perfectly
-- good zone with an empty map, which is what shipped in v1.0.47.
local sub = submaps[GetMapInfo() or ""]
if sub then
return sub[1]
end
local id = pfMap:GetMapIDByName(name)
id = id or customids[GetMapInfo()]
-- and the same redirect for anything that resolved to a starter subzone by
-- name without the map area being a sub-map (SetMapByID, addons, /way)
return pfMap:ParentZone(id)
end
function pfMap:AddNode(meta)
if not meta then
return
end
if not meta["zone"] then
return
end
if not meta["title"] then
return
end
-- only compute description if the caller hasn't already done it
-- (SearchMobID / SearchObjectID hoist this call outside their coord loops)
if meta["description"] == nil then
meta["description"] = pfDatabase:BuildQuestDescription(meta)
end
local addon = meta["addon"] or "PFDB"
local map = meta["zone"]
local coords = meta["x"] .. "|" .. meta["y"]
local title = meta["title"]
local layer = GetLayerByTexture(meta["texture"])
local spawn = meta["spawn"]
local item = meta["item"]
local sindex = string.format(
"%s:%s:%s:%s:%s:%s",
(addon or ""),
(map or ""),
(coords or ""),
(title or ""),
(layer or ""),
(spawn or ""),
(item or "")
)
-- use prioritized clusters
if layer >= 9 and meta["priority"] then
layer = layer + (10 - min(meta["priority"], 10))
end
if not pfMap.nodes[addon] then
pfMap.nodes[addon] = {}
end
if not pfMap.nodes[addon][map] then
pfMap.nodes[addon][map] = {}
end
if not pfMap.nodes[addon][map][coords] then
pfMap.nodes[addon][map][coords] = {}
end
-- skip early on existing nodes
if pfMap.nodes[addon][map][coords][title] then
if item and table.getn(pfMap.nodes[addon][map][coords][title].item) > 0 then
-- check if item already exists
for id, name in pairs(pfMap.nodes[addon][map][coords][title].item) do
if name == item then
return
end
end
-- add new item and exit
table.insert(pfMap.nodes[addon][map][coords][title].item, item)
return
end
if
pfMap.nodes[addon][map][coords][title]
and pfMap.nodes[addon][map][coords][title].layer
and layer
and pfMap.nodes[addon][map][coords][title].layer >= layer
then
-- identical node already exists, exit here
return
end
end
-- create new combined data node from given meta data
if not similar_nodes[sindex] then
similar_nodes[sindex] = {}
for key, val in pairs(meta) do
similar_nodes[sindex][key] = val
end
similar_nodes[sindex].item = { [1] = item }
end
-- set current node to combined node
pfMap.nodes[addon][map][coords][title] = similar_nodes[sindex]
-- mark this coord's node table dirty so UpdateNodes knows to reprocess it
pfMap.dirtyNodes[pfMap.nodes[addon][map][coords]] = true
pfMap.dirtyMaps[map] = true
-- maintain reverse title index for O(1) DeleteNode
if not pfMap.titleIndex[addon] then
pfMap.titleIndex[addon] = {}
end
if not pfMap.titleIndex[addon][title] then
pfMap.titleIndex[addon][title] = {}
end
if not pfMap.titleIndex[addon][title][map] then
pfMap.titleIndex[addon][title][map] = {}
end
pfMap.titleIndex[addon][title][map][coords] = true
-- add node to unified cluster cache
if not meta["cluster"] and not meta["texture"] then
local node_index = meta.item or meta.spawn or UNKNOWN
local x, y = tonumber(meta.x), tonumber(meta.y)
-- create prerequisite table structure
unifiedcache[title] = unifiedcache[title] or {}
unifiedcache[title][map] = unifiedcache[title][map] or {}
if not unifiedcache[title][map][node_index] then
-- create new unified node from given meta data
local unified_meta = {}
for key, val in pairs(meta) do
unified_meta[key] = val
end
-- save node to unified cache
unifiedcache[title][map][node_index] = { meta = unified_meta, coords = {} }
end
-- append new coords to unified cache unified cache
table.insert(unifiedcache[title][map][node_index].coords, { x, y })
end
-- add to gametooltips
if spawn and title then
pfMap.tooltips[spawn] = pfMap.tooltips[spawn] or {}
pfMap.tooltips[spawn][title] = pfMap.tooltips[spawn][title] or {}
pfMap.tooltips[spawn][title][map] = pfMap.tooltips[spawn][title][map] or similar_nodes[sindex]
-- maintain reverse tooltip index for O(1) DeleteNode
if not pfMap.tooltipIndex[title] then
pfMap.tooltipIndex[title] = {}
end
pfMap.tooltipIndex[title][spawn] = true
end
pfMap.queue_update = GetTime()
end
function pfMap:GetNodes(addon, title)
local nodes = {}
if title and pfMap.nodes[addon] then
for map, foo in pairs(pfMap.nodes[addon]) do
for coords, node in pairs(pfMap.nodes[addon][map]) do
if pfMap.nodes[addon][map][coords][title] then
table.insert(nodes, pfMap.nodes[addon][map][coords][title])
end
end
end
end
return nodes
end
function pfMap:DeleteNode(addon, title)
if not addon then
-- wipe everything
pfMap.tooltips = {}
pfMap.nodes = {}
pfMap.titleIndex = {}
pfMap.tooltipIndex = {}
pfMap.dirtyNodes = {}
pfMap.dirtyMaps = {}
elseif not title then
-- wipe all nodes for this addon; clean up both reverse indexes
if pfMap.titleIndex[addon] then
for t, maps in pairs(pfMap.titleIndex[addon]) do
-- clean tooltipIndex entries that belonged to this addon's titles
local spawns = pfMap.tooltipIndex[t]
if spawns then
for spawn in pairs(spawns) do