-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquest.lua
More file actions
1285 lines (1147 loc) · 47.3 KB
/
Copy pathquest.lua
File metadata and controls
1285 lines (1147 loc) · 47.3 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
local _, _, _, client = GetBuildInfo()
client = client or 11200
local _G = client == 11200 and getfenv(0) or _G
-- Performance: cache frequently-used globals
local pairs, ipairs, next = pairs, ipairs, next
local strfind = strfind
local format = string.format
local getn, insert, concat = table.getn, table.insert, table.concat
local tostring, tonumber, type = tostring, tonumber, type
local GetTime = GetTime
local UnitLevel = UnitLevel
pfQuest = CreateFrame("Frame")
pfQuest.icons = {}
-- Track which quests should be hidden because their zone header is collapsed.
-- collapsedQuestIDs[questid] = zoneName
--
-- Questid-keyed rather than zone-name-keyed because some quests appear under
-- a different zone header when their real zone header is collapsed (vanilla API
-- quirk). CollapseQuestHeader scans visible quests before the collapse takes
-- effect so the true membership is recorded before the API hides them.
pfQuest.collapsedQuestIDs = {}
local function questInPlayerZone(questid)
local playerZone = pfMap and pfMap.playerZone
if not playerZone or not pfMap.nodes or not pfMap.nodes["PFQUEST"] or not pfMap.nodes["PFQUEST"][playerZone] then
return nil
end
for _, coordNode in pairs(pfMap.nodes["PFQUEST"][playerZone]) do
for _, node in pairs(coordNode) do
if (node.questid or node.title) == questid then
return true
end
end
end
return nil
end
local function questAffectsCurrentZoneTracker(questid)
local data = pfQuest.questlog and pfQuest.questlog[questid]
-- Current Zone mode still shows watched off-zone quests at the top, so a
-- collapse/expand on those quests must refresh the tracker too.
if data and data.qlogid and IsQuestWatched(data.qlogid) then
return true
end
return questInPlayerZone(questid)
end
local _CollapseQuestHeader = CollapseQuestHeader
CollapseQuestHeader = function(index)
local title, _, _, header = compat.GetQuestLogTitle(index)
if header and title then
local affectsCurrentZoneTracker = nil
-- Scan quests under this header and mark them collapsed by questid.
-- Must be done before calling the real CollapseQuestHeader because
-- after the collapse the quests disappear from GetQuestLogTitle.
for qi = index + 1, 40 do
local qtitle, _, _, qheader = compat.GetQuestLogTitle(qi)
if qheader or not qtitle then break end
for questid, data in pairs(pfQuest.questlog) do
if data.title == qtitle then
pfQuest.collapsedQuestIDs[questid] = title
data.collapsed = true
if not affectsCurrentZoneTracker and pfQuest_config["trackingmethod"] == 5
and questAffectsCurrentZoneTracker(questid) then
affectsCurrentZoneTracker = true
end
break
end
end
end
if pfQuest_config["trackingmethod"] == 5 then
if affectsCurrentZoneTracker and pfQuest.tracker and pfQuest.tracker.RefreshZoneTracker then
pfQuest.tracker.RefreshZoneTracker()
end
else
pfMap.queue_update = GetTime()
end
end
return _CollapseQuestHeader(index)
end
local _ExpandQuestHeader = ExpandQuestHeader
ExpandQuestHeader = function(index)
local title, _, _, header = compat.GetQuestLogTitle(index)
if header and title then
if pfQuest.userClickingHeader then
-- User explicitly expanded this zone: clear our collapsed tracking for it.
-- Collect keys first to avoid modifying the table mid-iteration.
local toRemove = {}
local affectsCurrentZoneTracker = nil
for questid, zone in pairs(pfQuest.collapsedQuestIDs) do
if zone == title then
toRemove[questid] = true
if not affectsCurrentZoneTracker and pfQuest_config["trackingmethod"] == 5
and questAffectsCurrentZoneTracker(questid) then
affectsCurrentZoneTracker = true
end
end
end
for questid in pairs(toRemove) do
pfQuest.collapsedQuestIDs[questid] = nil
if pfQuest.questlog[questid] then
pfQuest.questlog[questid].collapsed = false
end
end
if pfQuest_config["trackingmethod"] == 5 then
if affectsCurrentZoneTracker and pfQuest.tracker and pfQuest.tracker.RefreshZoneTracker then
pfQuest.tracker.RefreshZoneTracker()
end
else
pfMap.queue_update = GetTime()
end
end
-- If not user-initiated (e.g. vanilla expanding a zone on quest accept/turn-in),
-- leave collapsedQuestIDs intact. The QLU sync will re-apply data.collapsed from
-- it after the subsequent QUEST_LOG_UPDATE, keeping collapsed quests off the tracker.
end
return _ExpandQuestHeader(index)
end
if client >= 30300 then
pfQuest.dburl = "https://www.wowhead.com/wotlk/quest="
elseif client >= 20400 then
pfQuest.dburl = "https://www.wowhead.com/tbc/quest="
else
pfQuest.dburl = "https://www.wowhead.com/classic/quest="
end
function pfQuest:Debug(msg)
-- only show debug output if enabled
if not pfQuest_config.debug and pfQuest.debugwin then
pfQuest.debugwin:Hide()
return
elseif not pfQuest_config.debug then
return
end
if not pfQuest.debugwin then
pfQuest.debugwin = CreateFrame("ScrollingMessageFrame", nil, UIParent)
pfQuest.debugwin:SetWidth(320)
pfQuest.debugwin:SetHeight(320)
pfQuest.debugwin:SetPoint("RIGHT", -42, 0)
local font = pfUI and pfUI.font_default or STANDARD_TEXT_FONT
local size = tonumber(pfQuest_config["trackerfontsize"]) or 12
pfQuest.debugwin:SetFont(font, size, "OUTLINE")
pfQuest.debugwin:SetFading(false)
pfQuest.debugwin:SetMaxLines(150)
pfQuest.debugwin:SetJustifyH("RIGHT")
pfQuest.debugwin:SetJustifyV("CENTER")
end
local font = pfUI and pfUI.font_default or STANDARD_TEXT_FONT
local size = tonumber(pfQuest_config["trackerfontsize"]) or 12
pfQuest.debugwin:SetFont(font, size, "OUTLINE")
pfQuest.debugwin:AddMessage(msg)
pfQuest.debugwin:Show()
end
function pfQuest:SortedPairs(t, index, reverse)
-- collect the keys
local keys = {}
for k, v in pairs(t) do
if v then
keys[table.getn(keys) + 1] = k
end
end
local order
if reverse then
order = function(t, a, b)
return t[a][index] < t[b][index]
end
else
order = function(t, a, b)
return t[a][index] > t[b][index]
end
end
table.sort(keys, function(a, b)
return order(t, a, b)
end)
-- return the iterator function
local i = 0
return function()
i = i + 1
if keys[i] then
return keys[i], t[keys[i]]
end
end
end
pfQuest.queue = {}
pfQuest.queueCount = 0 -- Track queue size to avoid O(n) tsize() calls
pfQuest.abandon = ""
pfQuest.questlog = {}
pfQuest.questlog_tmp = {}
-- Helper to add to queue with count tracking
local function queueAdd(entry)
insert(pfQuest.queue, entry)
pfQuest.queueCount = pfQuest.queueCount + 1
end
local skillstate = ""
pfQuest:RegisterEvent("QUEST_WATCH_UPDATE")
pfQuest:RegisterEvent("QUEST_LOG_UPDATE")
pfQuest:RegisterEvent("QUEST_FINISHED")
pfQuest:RegisterEvent("PLAYER_LEVEL_UP")
pfQuest:RegisterEvent("PLAYER_ENTERING_WORLD")
pfQuest:RegisterEvent("SKILL_LINES_CHANGED")
pfQuest:RegisterEvent("ADDON_LOADED")
pfQuest:SetScript("OnEvent", function()
if event == "ADDON_LOADED" then
if strsub(tostring(arg1), 1, 7) == "pfQuest" then
-- Clean up legacy SavedVariable from an earlier version of this fix that
-- accidentally stored collapsedZones in pfQuest_track, causing database.lua
-- to crash when iterating that table as {query, meta} tracking pairs.
if pfQuest_track and pfQuest_track.collapsedZones then
pfQuest_track.collapsedZones = nil
end
-- Link collapsedQuestIDs to pfQuest_config so collapse state survives reload.
-- The wrappers write to pfQuest.collapsedQuestIDs directly; since it is the
-- same table as pfQuest_config.collapsedQuestIDs, the SavedVar stays in sync.
if pfQuest_config then
pfQuest_config.collapsedQuestIDs = pfQuest_config.collapsedQuestIDs or {}
pfQuest.collapsedQuestIDs = pfQuest_config.collapsedQuestIDs
end
pfQuest:AddQuestLogIntegration()
pfQuest:AddWorldMapIntegration()
this.lock = GetTime() + 10
else
return
end
elseif event == "SKILL_LINES_CHANGED" then
-- Use table.concat to avoid string concatenation garbage
local skillParts = {}
for i = 0, GetNumSkillLines() do
skillParts[i + 1] = GetSkillLineInfo(i) or ""
end
local skills = concat(skillParts)
-- update quest givers when new skills or
-- professions became available
if skills ~= skillstate then
pfQuest.updateQuestGivers = true
skillstate = skills
end
elseif event == "PLAYER_LEVEL_UP" or event == "PLAYER_ENTERING_WORLD" then
pfQuest.updateQuestGivers = true
else
pfQuest.updateQuestLog = true
end
if event == "QUEST_LOG_UPDATE" then
-- Keep data.collapsed in sync with collapsedQuestIDs. The wrappers update
-- it directly on user action; this handles any edge cases where data.collapsed
-- drifts (e.g. quest log rebuilt after a zone change).
if pfQuest.questlog then
local affectsCurrentZoneTracker = nil
for questid, data in pairs(pfQuest.questlog) do
local isCollapsed = pfQuest.collapsedQuestIDs[questid] and true or false
if isCollapsed ~= (data.collapsed and true or false) then
data.collapsed = isCollapsed
if pfQuest_config["trackingmethod"] == 5 then
if not affectsCurrentZoneTracker and questAffectsCurrentZoneTracker(questid) then
affectsCurrentZoneTracker = true
end
else
pfMap.queue_update = GetTime()
end
end
end
if pfQuest_config["trackingmethod"] == 5 and affectsCurrentZoneTracker
and pfQuest.tracker and pfQuest.tracker.RefreshZoneTracker then
pfQuest.tracker.RefreshZoneTracker()
end
end
-- lock initial scan during incoming events
if this.lock and this.lock > GetTime() then
this.lock = GetTime() + 1.5
end
end
end)
pfQuest:SetScript("OnUpdate", function()
if this.lock and this.lock > GetTime() then
return
end
if not pfDatabase.localized then
return
end
if (this.tick or 0.05) > GetTime() then
return
else
this.tick = GetTime() + 0.05
end
-- check questlog each second
if (this.qlogtick or 1) < GetTime() then
local t0 = GetTime()
if pfQuest:UpdateQuestlog() then
pfQuest:Debug(format("Update Quest|cff33ffccLog|r [|cffff3333Tick|r] %.4fs", GetTime() - t0))
end
this.qlogtick = GetTime() + 1
end
if this.updateQuestLog == true and pfQuest.queueCount == 0 then
local t0 = GetTime()
pfQuest:UpdateQuestlog()
pfQuest:Debug(format("Update Quest|cff33ffccLog %.4fs", GetTime() - t0))
this.updateQuestLog = false
end
if this.updateQuestGivers == true then
pfQuest:Debug("Update Quest|cff33ffcc Givers")
if pfQuest_config["trackingmethod"] ~= 4 and pfQuest_config["allquestgivers"] == "1" then
local meta = { ["addon"] = "PFQUEST" }
local t0 = GetTime()
pfDatabase:SearchQuests(meta)
pfQuest:Debug(format("|cffff3333TIMER SearchQuests: %.4fs", GetTime() - t0))
end
this.updateQuestGivers = false
end
if pfQuest.queueCount == 0 then
return
end
-- process queue
for id, entry in pairs(this.queue) do
-- questgivers only need refreshing when quests are added or removed,
-- not when objectives change (RELOAD). track this before clearing the entry.
if entry[4] == "NEW" or entry[4] == "REMOVE" then
this.needsQuestGiverUpdate = true
end
-- remove quest
if entry[4] == "REMOVE" then
pfQuest:Debug("|cffff5555Remove Quest: " .. entry[1] .. " (" .. entry[2] .. ")")
-- write pfQuest.questlog history
if entry[1] == pfQuest.abandon then
pfQuest_history[entry[2]] = nil
else
pfQuest_history[entry[2]] = { time(), UnitLevel("player") }
end
-- remove from collapsed tracking so the SavedVar doesn't accumulate
-- stale questids from quests that were turned in or abandoned
pfQuest.collapsedQuestIDs[entry[2]] = nil
-- Mark journal dirty when history changes
if pfJournal then
pfJournal.dirty = true
end
if pfQuest_config["trackingmethod"] ~= 4 then
-- delete nodes by title
local t0 = GetTime()
pfMap:DeleteNode("PFQUEST", entry[1])
-- also delete nodes by quest ids for servers with different names
if entry[2] and pfDB["quests"]["loc"][entry[2]] and pfDB["quests"]["loc"][entry[2]].T then
pfMap:DeleteNode("PFQUEST", pfDB["quests"]["loc"][entry[2]].T)
end
pfQuest:Debug(format("|cffffff00TIMER DeleteNode(REMOVE): %.4fs", GetTime() - t0))
end
pfQuest.abandon = ""
else
if entry[4] == "NEW" then
pfQuest:Debug("|cff55ff55New Quest: " .. entry[1] .. " (" .. entry[2] .. ")")
else
pfQuest:Debug("|cffffff55Update Quest: " .. entry[1] .. " (" .. entry[2] .. ")")
end
-- update quest nodes
if pfQuest_config["trackingmethod"] ~= 4 then
-- Reforged: decide the re-add BEFORE deleting. The old flow deleted the
-- quest's nodes unconditionally and could then skip the re-add (manual
-- mode, tracked-mode gates, a transiently unreadable quest log slot mid
-- QUEST_LOG_UPDATE burst), consuming the queue entry with the state
-- string already recorded -- so nothing ever restored the nodes and the
-- quest vanished from map+minimap until a /reload. The wotlk AUTO QUEST
-- WATCH flips the watch state on the very first kill, which is exactly
-- when players noticed (QA: "killing a quest mob hides the markers").
local method = pfQuest_config["trackingmethod"]
local eligible = method ~= 3 and (method ~= 2 or IsQuestWatched(entry[3]))
-- manual mode: a quest the user has ALREADY shown by hand gets
-- refreshed instead of dropped
if not eligible and method == 3 and pfMap.nodes["PFQUEST"] then
for _, coords in pairs(pfMap.nodes["PFQUEST"]) do
for _, node in pairs(coords) do
if node[entry[1]] then eligible = true break end
end
if eligible then break end
end
end
local verified = nil
if eligible then
-- Verify the quest is still at the expected log position. If the
-- slot is empty or holds a different quest (e.g. turned in while
-- this entry was queued), skip SearchQuestID to avoid adding a
-- spurious complete_c node.
verified = entry[3] and compat.GetQuestLogTitle(entry[3]) == entry[1]
if not verified then
-- transiently unreadable slot: retry a few ticks with the nodes
-- (and the queue entry) untouched instead of wiping the quest
entry.retries = (entry.retries or 0) + 1
if entry.retries < 10 then
return
end
end
end
-- delete only when about to re-add (refresh), or when hiding is the
-- intended behavior (tracked-only mode + quest not watched)
if (eligible and verified) or (not eligible and method == 2) then
local t0 = GetTime()
pfMap:DeleteNode("PFQUEST", entry[1])
-- delete nodes by quest ids for servers with different names
if entry[2] and pfDB["quests"]["loc"][entry[2]] and pfDB["quests"]["loc"][entry[2]].T then
pfMap:DeleteNode("PFQUEST", pfDB["quests"]["loc"][entry[2]].T)
end
pfQuest:Debug(format("|cffffff00TIMER DeleteNode(NEW/RELOAD): %.4fs", GetTime() - t0))
end
if eligible and verified then
local meta = { ["addon"] = "PFQUEST", ["qlogid"] = entry[3] }
local t1 = GetTime()
pfDatabase:SearchQuestID(entry[2], meta)
pfQuest:Debug(format("|cffff8800TIMER SearchQuestID: %.4fs", GetTime() - t1))
end
end
end
-- remove entry from queue and decrement counter
pfQuest.queue[id] = nil
pfQuest.queueCount = pfQuest.queueCount - 1
-- Force map update so tracker refreshes (even for quests with no objectives)
pfMap.queue_update = GetTime()
-- only return when other entries exist
-- otherwise, continue and update questgivers
if pfQuest.queueCount > 0 then
return
end
end
-- trigger questgiver update only when needed
if pfQuest.queueCount == 0 then
this.updateQuestLog = true
if this.needsQuestGiverUpdate then
this.updateQuestGivers = true
this.needsQuestGiverUpdate = false
end
end
end)
local questlog_flip, questlog_flop = {}, {}
-- Reforged perf: reused scratch table for the per-quest state string. This
-- rebuild runs on a 1s poll plus on quest changes, so allocating a fresh table
-- per quest (up to ~25) meant ~25 throwaway tables/sec even at idle.
local sp_scratch = {}
function pfQuest:UpdateQuestlog()
-- initialize flip flop if not yet defined
pfQuest.questlog_tmp = pfQuest.questlog_tmp or questlog_flip
local _, numQuests = GetNumQuestLogEntries()
local found = 0
local change = nil
local underCollapsedHeader = false
-- iterate over all quests
for qlogid = 1, 40 do
local title, _, _, header, collapsed, complete = compat.GetQuestLogTitle(qlogid)
local objectives = GetNumQuestLeaderBoards(qlogid)
local watched, questid, state
if header then
-- track the collapsed state for subsequent quests
underCollapsedHeader = collapsed and true or false
elseif title then
questid = pfDatabase:GetQuestIDs(qlogid)
questid = questid and tonumber(questid[1]) or title
watched = IsQuestWatched(qlogid)
-- build state string via table.concat (avoids string-concat garbage), into
-- a reused scratch table with a range-limited concat so no per-quest table
-- is allocated and no tail-clear is needed.
local sp = sp_scratch
sp[1] = watched and "track" or ""
local n = 1
if objectives then
for i = 1, objectives, 1 do
local text, _, done = GetQuestLogLeaderBoard(i, qlogid)
sp[n + 1] = i
sp[n + 2] = done and "done" or "todo"
n = n + 2
end
end
state = concat(sp, "", 1, n)
-- Some WoW clients (e.g. group/dungeon/raid quests) set collapsed=true on the
-- individual quest entry itself rather than (or in addition to) the zone header.
local effectiveCollapsed = underCollapsedHeader or (collapsed and true or false)
-- add new quest to the questlog
if not pfQuest.questlog[questid] then
queueAdd({ title, questid, qlogid, "NEW" })
-- Use collapsedQuestIDs (questid-keyed SavedVar) as the authoritative
-- collapsed state. Zone-name lookup is unreliable because vanilla
-- reassigns some quests to a different zone header when their real
-- zone header is collapsed (e.g. DM quests appear under SoS).
local initCollapsed = pfQuest.collapsedQuestIDs[questid] and true or effectiveCollapsed
pfQuest.questlog_tmp[questid] = {
title = title,
qlogid = qlogid,
state = state,
collapsed = initCollapsed,
}
change = true
elseif pfQuest.questlog[questid].qlogid ~= qlogid then
queueAdd({ title, questid, qlogid, "RELOAD" })
pfQuest.questlog_tmp[questid] = pfQuest.questlog[questid]
pfQuest.questlog_tmp[questid].qlogid = qlogid
pfQuest.questlog_tmp[questid].state = state
change = true
elseif pfQuest.questlog[questid].state ~= state then
queueAdd({ title, questid, qlogid, "RELOAD" })
pfQuest.questlog_tmp[questid] = pfQuest.questlog[questid]
pfQuest.questlog_tmp[questid].qlogid = qlogid
pfQuest.questlog_tmp[questid].state = state
change = true
else
pfQuest.questlog_tmp[questid] = pfQuest.questlog[questid]
end
-- seen this scan -> reset the consecutive-miss counter used by the
-- removal loop below
if pfQuest.questlog_tmp[questid] then pfQuest.questlog_tmp[questid].gwMiss335 = nil end
found = found + 1
-- Reforged: do NOT break at `found >= numQuests`. GetNumQuestLogEntries()
-- transiently UNDER-reports during a QUEST_LOG_UPDATE burst on some cores
-- (QA: kill/loot); breaking early left every not-yet-scanned quest out of
-- questlog_tmp, and the removal loop below then wrote them all to
-- pfQuest_history (marked complete) and deleted their nodes -- a wipe that
-- never recovered because the false "completed" flag suppresses the re-add.
-- Scanning all 40 slots is cheap (empty slots short-circuit on nil title)
-- and makes the rebuild independent of the unreliable count.
end
end
-- quest removal events. A quest present last scan but absent from this
-- rebuild is only a REMOVE candidate; a SINGLE absence is almost always a
-- transient burst hiccup (unreadable slot, or the count under-report above),
-- not a real turn-in. Require TWO consecutive misses before removing, so a
-- one-scan flicker never deletes nodes or poisons pfQuest_history.
for questid, data in pairs(pfQuest.questlog) do
if not pfQuest.questlog_tmp[questid] then
data.gwMiss335 = (data.gwMiss335 or 0) + 1
if data.gwMiss335 >= 2 and not pfQuest.collapsedQuestIDs[questid] then
queueAdd({ data.title, questid, nil, "REMOVE" })
change = true
else
-- transient miss (or collapsed): preserve, nodes untouched
pfQuest.questlog_tmp[questid] = data
end
end
end
-- set questlog to current flip flop
pfQuest.questlog = pfQuest.questlog_tmp
-- switch tmp to the other flip flop
if pfQuest.questlog_tmp == questlog_flip then
pfQuest.questlog_tmp = questlog_flop
else
pfQuest.questlog_tmp = questlog_flip
end
-- clear next temporary questlog entries
for k, v in pairs(pfQuest.questlog_tmp) do
pfQuest.questlog_tmp[k] = nil
end
return change
end
function pfQuest:ResetAll()
-- force reload all quests
pfMap:DeleteNode("PFQUEST")
pfQuest.questlog = {}
pfQuest.updateQuestLog = true
pfQuest.updateQuestGivers = true
-- pfMap.nodes["PFQUEST"] is now empty; tell SearchQuests to start fresh
if pfDatabase then
for id in pairs(pfDatabase.lastQuestGiversSet) do
pfDatabase.lastQuestGiversSet[id] = nil
end
end
end
-- register popup dialog to copy urls
StaticPopupDialogs["PFQUEST_URLCOPY"] = {
text = "|cff33ffccpf|cffffffffQuest " .. pfQuest_Loc["Online Search"],
button1 = "Close",
hasEditBox = 1,
hasWideEditBox = 1,
timeout = 0,
exclusive = 1,
whileDead = 1,
hideOnEscape = 1,
OnShow = function()
local editBox = _G[this:GetName() .. "WideEditBox"]
editBox:SetText(StaticPopupDialogs["PFQUEST_URLCOPY"].data)
editBox:HighlightText()
end,
OnHide = function()
_G[this:GetName() .. "WideEditBox"]:SetText("")
end,
EditBoxOnEnterPressed = function()
this:GetParent():Hide()
end,
EditBoxOnEscapePressed = function()
this:GetParent():Hide()
end,
EditBoxOnTextChanged = function()
this:SetText(StaticPopupDialogs["PFQUEST_URLCOPY"].data)
this:HighlightText()
end,
}
function pfQuest:AddQuestLogIntegration()
if pfQuest_config["questlogbuttons"] == "0" then
return
end
local dockFrame = EQL3_QuestLogDetailScrollChildFrame
or ShaguQuest_QuestLogDetailScrollChildFrame
or QuestLogDetailScrollChildFrame
local dockTitle = EQL3_QuestLogDescriptionTitle
or ShaguQuest_QuestLogDescriptionTitle
or pfQuestCompat.QuestLogDescriptionTitle
dockTitle:SetHeight(dockTitle:GetHeight() + 30)
dockTitle:SetJustifyV("BOTTOM")
pfQuest.buttonOnline = pfQuest.buttonOnline or CreateFrame("Button", "pfQuestOnline", dockFrame)
pfQuest.buttonOnline:SetWidth(18)
pfQuest.buttonOnline:SetHeight(15)
pfQuest.buttonOnline:SetPoint("TOPRIGHT", dockFrame, "TOPRIGHT", -12, -10)
pfQuest.buttonOnline:SetScript("OnClick", function()
if pfUI and pfUI.chat then
pfUI.chat.urlcopy.text:SetText(pfQuest.dburl .. (this:GetID() or 0))
pfUI.chat.urlcopy:Show()
else
StaticPopupDialogs["PFQUEST_URLCOPY"].data = pfQuest.dburl .. (this:GetID() or 0)
local dialog = StaticPopup_Show("PFQUEST_URLCOPY")
_G[dialog:GetName() .. "Button1"]:ClearAllPoints()
_G[dialog:GetName() .. "Button1"]:SetPoint("BOTTOM", dialog, "BOTTOM", 0, 16)
_G[dialog:GetName() .. "WideEditBox"]:SetScript("OnTextChanged", StaticPopup_EditBoxOnTextChanged)
dialog:SetWidth(420)
end
end)
pfQuest.buttonOnline.txt = pfQuest.buttonOnline:CreateFontString("pfQuestIDButton", "HIGH", "GameFontWhite")
pfQuest.buttonOnline.txt:SetAllPoints(pfQuest.buttonOnline)
pfQuest.buttonOnline.txt:SetJustifyH("RIGHT")
pfQuest.buttonOnline.txt:SetText("|cff000000[|cffaa2222?|cff000000]")
pfQuest.buttonLanguage = pfQuest.buttonLanguage or CreateFrame("Button", "pfQuestLanguage", dockFrame)
pfQuest.buttonLanguage:SetWidth(75)
pfQuest.buttonLanguage:SetHeight(15)
pfQuest.buttonLanguage:SetPoint("RIGHT", pfQuest.buttonOnline, "LEFT", 0, 0)
pfQuest.buttonLanguage.txt = pfQuest.buttonLanguage:CreateFontString("pfQuestIDButton", "HIGH", "GameFontWhite")
pfQuest.buttonLanguage.txt:SetAllPoints(pfQuest.buttonLanguage)
pfQuest.buttonLanguage.txt:SetJustifyH("RIGHT")
pfQuest.buttonLanguage.txt:SetText("|cff000000[|cff333333" .. pfQuest_Loc["Translate"] .. "|cff000000]")
pfQuest.buttonLanguage:SetScript("OnClick", function()
UIDropDownMenu_Initialize(self, function()
local func = function()
pfQuest_config.translate = this.value
end
local info = {}
info.text = "|cffaaaaaa" .. pfQuest_Loc["Reset Language"]
info.value = nil
info.func = func
UIDropDownMenu_AddButton(info)
for loc, caption in pairs(pfDB.locales) do
local info = {}
info.text = caption
info.value = loc
info.func = func
UIDropDownMenu_AddButton(info)
end
end)
ToggleDropDownMenu(1, nil, self, "cursor", 3, -3)
end)
pfQuest.buttonLanguage:SetScript("OnUpdate", function()
local id = pfQuest.buttonOnline:GetID()
local lang = pfQuest_config.translate
if this.translate ~= pfQuest_config.translate then
pfQuest.buttonLanguage.txt:SetText(
"|cff000000[|cff3333ff"
.. (pfDB.locales[pfQuest_config.translate] or "|cff333333" .. pfQuest_Loc["Translate"])
.. "|cff000000]"
)
this.translate = pfQuest_config.translate
QuestLog_UpdateQuestDetails(true)
return
end
if id and pfDB["quests"][lang] and pfDB["quests"][lang][id] then
-- Reforged perf: this ran 3x FormatQuestText + SetText + UpdateScrollChildRect
-- EVERY frame while the quest log was open in translate mode. FormatQuestText
-- is only a function of (id, lang), so cache the formatted strings and
-- recompute them only when the selected quest or language changes. The
-- SetText re-apply must still fire whenever Blizzard re-renders the detail
-- (QUEST_LOG_UPDATE resets it to the source language), so gate that on a
-- cheap GetText compare -- zero allocation in the steady state.
if this.fmtId ~= id or this.fmtLang ~= lang then
this.fmtId, this.fmtLang = id, lang
this.fmtTitle = pfDatabase:FormatQuestText(pfDB["quests"][lang][id]["T"])
this.fmtObj = pfDatabase:FormatQuestText(pfDB["quests"][lang][id]["O"])
this.fmtDesc = pfDatabase:FormatQuestText(pfDB["quests"][lang][id]["D"])
end
local QuestLogQuestTitle = EQL3_QuestLogQuestTitle or pfQuestCompat.QuestLogQuestTitle
if QuestLogQuestTitle:GetText() ~= this.fmtTitle then
local QuestLogObjectivesText = EQL3_QuestLogObjectivesText or pfQuestCompat.QuestLogObjectivesText
local QuestLogQuestDescription = EQL3_QuestLogQuestDescription or pfQuestCompat.QuestLogQuestDescription
local QuestLogDetailScrollFrame = EQL3_QuestLogDetailScrollFrame or QuestLogDetailScrollFrame
QuestLogQuestTitle:SetText(this.fmtTitle)
QuestLogObjectivesText:SetText(this.fmtObj)
QuestLogQuestDescription:SetText(this.fmtDesc)
QuestLogDetailScrollFrame:UpdateScrollChildRect()
end
end
end)
pfQuest.buttonShow = pfQuest.buttonShow or CreateFrame("Button", "pfQuestShow", dockFrame, "UIPanelButtonTemplate")
pfQuest.buttonShow:SetWidth(70)
pfQuest.buttonShow:SetHeight(20)
pfQuest.buttonShow:SetText(pfQuest_Loc["Show"])
pfQuest.buttonShow:SetPoint("TOP", dockTitle, "TOP", -110, 0)
pfQuest.buttonShow:SetScript("OnClick", function()
local questIndex = GetQuestLogSelection()
local questids = pfDatabase:GetQuestIDs(questIndex)
local title, _, _, header, _, complete = compat.GetQuestLogTitle(questIndex)
local id = questids and tonumber(questids[1])
if header or not id then
return
end
local maps, meta = {}, { ["addon"] = "PFQUEST", ["qlogid"] = questIndex }
maps = pfDatabase:SearchQuestID(id, meta, maps)
pfMap:ShowMapID(pfDatabase:GetBestMap(maps))
end)
pfQuest.buttonHide = pfQuest.buttonHide or CreateFrame("Button", "pfQuestHide", dockFrame, "UIPanelButtonTemplate")
pfQuest.buttonHide:SetWidth(70)
pfQuest.buttonHide:SetHeight(20)
pfQuest.buttonHide:SetText(pfQuest_Loc["Hide"])
pfQuest.buttonHide:SetPoint("TOP", dockTitle, "TOP", -37, 0)
pfQuest.buttonHide:SetScript("OnClick", function()
local questIndex = GetQuestLogSelection()
local title, _, _, header, _, complete = compat.GetQuestLogTitle(questIndex)
if header then
return
end
pfMap:DeleteNode("PFQUEST", title)
end)
pfQuest.buttonClean = pfQuest.buttonClean or CreateFrame("Button", "pfQuestClean", dockFrame, "UIPanelButtonTemplate")
pfQuest.buttonClean:SetWidth(70)
pfQuest.buttonClean:SetHeight(20)
pfQuest.buttonClean:SetText(pfQuest_Loc["Clean"])
pfQuest.buttonClean:SetPoint("TOP", dockTitle, "TOP", 37, 0)
pfQuest.buttonClean:SetScript("OnClick", function()
pfMap:DeleteNode("PFQUEST")
end)
pfQuest.buttonReset = pfQuest.buttonReset or CreateFrame("Button", "pfQuestReset", dockFrame, "UIPanelButtonTemplate")
pfQuest.buttonReset:SetWidth(70)
pfQuest.buttonReset:SetHeight(20)
pfQuest.buttonReset:SetText(pfQuest_Loc["Reset"])
pfQuest.buttonReset:SetPoint("TOP", dockTitle, "TOP", 110, 0)
pfQuest.buttonReset:SetScript("OnClick", function()
pfQuest:ResetAll()
end)
-- use pfUI buttons in native mode
if not pfUI.api.emulated then
pfUI.api.SkinButton(pfQuest.buttonShow)
pfUI.api.SkinButton(pfQuest.buttonHide)
pfUI.api.SkinButton(pfQuest.buttonClean)
pfUI.api.SkinButton(pfQuest.buttonReset)
end
end
function pfQuest:AddWorldMapIntegration()
if pfQuest_config["worldmapmenu"] == "0" then
return
end
-- Quest Display Selection
-- Parent + anchor to the visible map viewport so the dropdown stays pinned
-- to the top-right of the visible map AND scales with the map mode:
-- * default 3.3.5: WorldMapDetailFrame is the visible map area, scales
-- with WORLDMAP_SETTINGS.size (windowed=0.573, fullmap=1.0), doesn't pan.
-- * Magnify: it creates WorldMapScrollFrame as the clipped viewport,
-- reparents WorldMapDetailFrame inside it as a panned/scaled scroll
-- child. WorldMapScrollFrame scales with WORLDMAP_SETTINGS.size and
-- doesn't pan/zoom, so it's the safe anchor.
local mapAnchor = WorldMapScrollFrame or WorldMapDetailFrame
pfQuest.mapButton = CreateFrame("Frame", "pfQuestMapDropdown", mapAnchor, "UIDropDownMenuTemplate")
pfQuest.mapButton:ClearAllPoints()
pfQuest.mapButton:SetPoint("TOPRIGHT", mapAnchor, "TOPRIGHT", 0, -10)
-- Lift above WorldMapButton (Blizzard sets it to WORLDMAP_POI_FRAMELEVEL - 10
-- = 90 in WorldMapFrame_ResetFrameLevels). Without this, Magnify's
-- WorldMapButton OnMouseDown handler swallows clicks aimed at the dropdown
-- because WorldMapScrollFrame (created at .toc-load time, before WMF's
-- ResetFrameLevels) sits at a very low frame level, leaving its children
-- below WorldMapButton's 90.
pfQuest.mapButton:SetFrameLevel((WORLDMAP_POI_FRAMELEVEL or 100) + 2)
-- Reforged: step out of the way of anything else living in this corner
-- (issue #20). Two things do, both from WDM:
--
-- * WDM_WorldMapButton, a minimap-style tracking button anchored to
-- WorldMapButton TOPRIGHT (-4,-4) at strata TOOLTIP. Same corner as this
-- dropdown, and TOOLTIP outranks us, so it draws straight over our right
-- end -- which is exactly where our own arrow sits.
-- * Blizzard's floor dropdown, which WDM shows on far more maps than the
-- stock client (it is normally limited to a handful of micro-dungeons).
-- UIDropDownMenuTemplate hangs 64px of artwork off a 32px frame, 17 above
-- and 15 below, so its textures and ours overlap by 20px even though the
-- visible boxes look 4px apart.
--
-- Detected by frame name and IsShown, never by addon presence: both are
-- ordinary frames, so with WDM absent or its modules switched off this
-- leaves the dropdown exactly where it has always been.
local BASE_X, BASE_Y = 0, -10
local function reposition()
local x, y = BASE_X, BASE_Y
local corner = _G["WDM_WorldMapButton"]
if corner and corner:IsShown() then
x = x - 40 -- its 32px width at -4, plus a 4px gap
end
if WorldMapLevelDropDown and WorldMapLevelDropDown:IsShown() then
y = y - 26 -- the 20px of texture overlap, plus a 6px margin
end
if pfQuest.mapButton.offsetX ~= x or pfQuest.mapButton.offsetY ~= y then
pfQuest.mapButton.offsetX, pfQuest.mapButton.offsetY = x, y
pfQuest.mapButton:ClearAllPoints()
pfQuest.mapButton:SetPoint("TOPRIGHT", mapAnchor, "TOPRIGHT", x, y)
end
end
pfQuest.RepositionMapDropdown = reposition
-- Hooked to the floor dropdown's own visibility rather than to
-- WorldMapFrame_Update: WorldMapFrame_UpdateMap calls
-- WorldMapLevelDropDown_Update AFTER WorldMapFrame_Update, so a hook on the
-- latter reads the previous map's state, and hooking
-- WorldMapLevelDropDown_Update itself would race WDM's hook on the same
-- function. OnShow/OnHide fire whoever changed it.
if WorldMapLevelDropDown and WorldMapLevelDropDown.HookScript then
WorldMapLevelDropDown:HookScript("OnShow", reposition)
WorldMapLevelDropDown:HookScript("OnHide", reposition)
end
pfQuest.mapButton:SetScript("OnShow", function()
pfQuest.mapButton.current = tonumber(pfQuest_config["trackingmethod"])
pfQuest.mapButton:UpdateMenu()
-- WDM_WorldMapButton is built in its addon's OnEnable, which may well run
-- after ours; the map being open is always later than both.
reposition()
end)
pfQuest.mapButton.point = "TOPLEFT"
pfQuest.mapButton.relativePoint = "BOTTOMLEFT"
-- One-time width/justify setup. Previously these lived inside UpdateMenu
-- and re-ran on every map show, which would overwrite the width that
-- ElvUI's HandleDropDownBox sets when it skins the dropdown.
if client >= 30300 then
UIDropDownMenu_SetWidth(pfQuest.mapButton, 120)
UIDropDownMenu_SetButtonWidth(pfQuest.mapButton, 125)
UIDropDownMenu_JustifyText(pfQuest.mapButton, "RIGHT")
else
UIDropDownMenu_SetWidth(120, pfQuest.mapButton)
UIDropDownMenu_SetButtonWidth(125, pfQuest.mapButton)
UIDropDownMenu_JustifyText("RIGHT", pfQuest.mapButton)
end
function pfQuest.mapButton:UpdateMenu()
local function CreateEntries()
local info = {}
info.text = pfQuest_Loc["All Quests"]
info.checked = false
info.func = function()
UIDropDownMenu_SetSelectedID(pfQuest.mapButton, this:GetID(), 0)
pfQuest_config["trackingmethod"] = this:GetID()
pfQuest:ResetAll()
end
UIDropDownMenu_AddButton(info)
local info = {}
info.text = pfQuest_Loc["Tracked Quests"]
info.checked = false
info.func = function()
UIDropDownMenu_SetSelectedID(pfQuest.mapButton, this:GetID(), 0)
pfQuest_config["trackingmethod"] = this:GetID()
pfQuest:ResetAll()
end
UIDropDownMenu_AddButton(info)
local info = {}
info.text = pfQuest_Loc["Manual Selection"]
info.checked = false
info.func = function()
UIDropDownMenu_SetSelectedID(pfQuest.mapButton, this:GetID(), 0)
pfQuest_config["trackingmethod"] = this:GetID()
pfQuest:ResetAll()
end
UIDropDownMenu_AddButton(info)
local info = {}
info.text = pfQuest_Loc["Hide Quests"]
info.checked = false
info.func = function()
UIDropDownMenu_SetSelectedID(pfQuest.mapButton, this:GetID(), 0)
pfQuest_config["trackingmethod"] = this:GetID()
pfQuest:ResetAll()
end
UIDropDownMenu_AddButton(info)
local info = {}
info.text = pfQuest_Loc["Current Zone"]
info.checked = false
info.func = function()
UIDropDownMenu_SetSelectedID(pfQuest.mapButton, this:GetID(), 0)
pfQuest_config["trackingmethod"] = this:GetID()
pfQuest:ResetAll()
end
UIDropDownMenu_AddButton(info)
end
UIDropDownMenu_Initialize(pfQuest.mapButton, CreateEntries)
UIDropDownMenu_SetSelectedID(pfQuest.mapButton, pfQuest.mapButton.current)
end
-- ElvUI skin: mirror ModernMapMarkers' approach. If ElvUI is loaded,
-- wait until its engine is initialized, then run S:HandleDropDownBox on
-- pfQuest's All-Quests dropdown so it matches MMM's filter/find dropdowns.
do
local function SkinDropdown(S)
if pfQuest.mapButton.backdrop then return end
S:HandleDropDownBox(pfQuest.mapButton, 134)
end
local function OnReady()
if not ElvUI then return end
local E = ElvUI[1]
if not E then return end
local S = E:GetModule("Skins")
if not S then return end
SkinDropdown(S)
end
if ElvUI and ElvUI[1] then
if ElvUI[1].initialized then
OnReady()
else
hooksecurefunc(ElvUI[1], "Initialize", OnReady)
end
end
end