forked from shagu/pfQuest-turtle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatchtable.lua
More file actions
851 lines (705 loc) · 27 KB
/
Copy pathpatchtable.lua
File metadata and controls
851 lines (705 loc) · 27 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
local locale = GetLocale()
local dbs = { "items", "quests", "quests-itemreq", "objects", "units", "zones", "professions", "areatrigger", "refloot" }
local function patchtable(base, diff)
if not base or not diff then return end
for k, v in pairs(diff) do
if type(v) == "string" and v == "_" then
base[k] = nil
else
base[k] = v
end
end
end
-- Keep this legacy typo for older clients.
for _, name in pairs({ GetMapZones(2) }) do
if name == "Northwind " then
pfDB["zones"]["enUS-turtle"][5581] = "Northwind "
break
end
end
for _, db in ipairs(dbs) do
local database = pfDB[db]
if database["data-turtle"] then
patchtable(database["data"], database["data-turtle"])
end
for locale_name in pairs(pfDB.locales) do
if database[locale_name] and database[locale_name .. "-turtle"] then
patchtable(database[locale_name], database[locale_name .. "-turtle"])
end
end
end
local loc_core = pfDB["professions"][locale] or pfDB["professions"]["enUS"]
local loc_update = pfDB["professions"][locale .. "-turtle"] or pfDB["professions"]["enUS-turtle"]
if loc_core and loc_update then patchtable(loc_core, loc_update) end
if pfDB["minimap-turtle"] then patchtable(pfDB["minimap"], pfDB["minimap-turtle"]) end
if pfDB["meta-turtle"] then patchtable(pfDB["meta"], pfDB["meta-turtle"]) end
local CUSTOM_QUEST_ID_THRESHOLD = 15000
if pfQuest_questcache then
-- Keep quest titles raw; custom quests are highlighted by icon tint.
pfQuest_questcache = nil
end
if TURTLE_DE_PATCH then
pfDB["zones"]["loc"] = pfDB["zones"]["deDE"] or pfDB["zones"]["enUS"]
pfDB["professions"]["loc"] = pfDB["professions"]["deDE"] or pfDB["professions"]["enUS"]
end
if pfDB.bitraces then
pfDB.bitraces[256] = "Goblin"
pfDB.bitraces[512] = "BloodElf"
end
pfQuest.dburl = "https://database.turtle-wow.org/?quest="
function pfMap:HasMinimap(map_id)
if not IsInInstance() then
return true
end
return GetCurrentMapContinent() < 3
end
local original_UpdateNode = pfMap.UpdateNode
local original_UpdateNodes = pfMap.UpdateNodes
local original_GetMapID = pfMap.GetMapID
local CONTINENT_NODE_ADDON = "PFQUEST_TURTLE_CONTINENT"
local CONTINENT_COORD_PATTERN = "([^|]+)|([^|]+)"
local CONTINENT_COORD_FORMAT = "%.2f|%.2f"
local CONTINENT_MAP_KEY_BASE = 90000
local continent_zone_cache = {}
local continent_zone_debug = {}
local function pfQuestApplyWorldMapPinSize(pin)
if not pin then return end
local base_size = tonumber(pin.pfquest_base_defsize) or tonumber(pin.defsize) or 14
if base_size <= 0 then base_size = 14 end
pin.pfquest_base_defsize = base_size
local eff_scale = tonumber(pin:GetEffectiveScale()) or 1
if eff_scale <= 0 then eff_scale = 1 end
local zoom = tonumber(pfMap and pfMap.worldmap_zoom_state and pfMap.worldmap_zoom_state.scale) or 1
if zoom <= 0 then zoom = 1 end
if zoom == 1 or not pin.pfquest_base_screen_size then
pin.pfquest_base_screen_size = base_size * eff_scale
end
local target_screen_size = tonumber(pin.pfquest_base_screen_size) or (base_size * eff_scale)
local size = target_screen_size / eff_scale
pin.defsize = size
pin:SetWidth(size)
pin:SetHeight(size)
if pin.hl then
local ratio = size / base_size
local hl = 12 * ratio
local off = 5 * ratio
pin.hl:SetWidth(hl)
pin.hl:SetHeight(hl)
pin.hl:ClearAllPoints()
pin.hl:SetPoint("TOPLEFT", pin, "TOPLEFT", -off, off)
end
end
local function pfQuestApplyAllWorldMapPinSizes()
if not pfMap or not pfMap.pins then return end
for _, pin in pairs(pfMap.pins) do
pfQuestApplyWorldMapPinSize(pin)
end
end
function pfMap:UpdateNode(frame, node, color, obj, distance)
original_UpdateNode(self, frame, node, color, obj, distance)
if frame and frame.questid and frame.texture and tonumber(frame.questid) >= CUSTOM_QUEST_ID_THRESHOLD then
if frame.tex and frame.tex.SetVertexColor then
frame.tex:SetVertexColor(0.28, 0.82, 0.8, 1)
end
end
if obj ~= "minimap" and frame then
frame.pfquest_base_defsize = (frame.cluster or frame.layer == 4) and 18 or 14
pfQuestApplyWorldMapPinSize(frame)
end
end
local function pfQuestGetContinentMapKey(continent)
continent = tonumber(continent)
if not continent or continent <= 0 then return nil end
return CONTINENT_MAP_KEY_BASE + continent
end
local function pfQuestGetContinentZoneLookup(continent)
local zone_names = { GetMapZones(continent) }
local zone_name_to_id = {}
local zone_id_to_index = {}
for zone_index, zone_name in ipairs(zone_names) do
if zone_name and zone_name ~= "" then
local map_id = original_GetMapID and original_GetMapID(pfMap, continent, zone_index)
if not map_id then
map_id = pfMap:GetMapIDByName(zone_name)
end
if map_id and map_id > 0 then
zone_name_to_id[zone_name] = map_id
zone_id_to_index[map_id] = zone_index
end
end
end
return zone_names, zone_name_to_id, zone_id_to_index
end
local function pfQuestResolveHighlightZone(zone_names, zone_name_to_id, r1, r2)
if type(r1) == "number" and zone_names[r1] and zone_name_to_id[zone_names[r1]] then
return zone_names[r1]
end
if type(r1) == "string" and zone_name_to_id[r1] then
return r1
end
if type(r2) == "string" and zone_name_to_id[r2] then
return r2
end
end
local function pfQuestSampleContinentRects(continent, mode)
if not UpdateMapHighlight or not WorldMapButton then return nil end
local width = tonumber(WorldMapButton:GetWidth()) or 0
local height = tonumber(WorldMapButton:GetHeight()) or 0
if width <= 0 or height <= 0 then return nil end
local zone_names, zone_name_to_id = pfQuestGetContinentZoneLookup(continent)
if not zone_names or not next(zone_name_to_id) then return nil end
local step = math.floor(math.min(width, height) / 90)
if step < 4 then step = 4 end
local rects = {}
for px = 0, width, step do
for py = 0, height, step do
local sample_x, sample_y
if mode == "relative" then
sample_x = px - (width / 2)
sample_y = (height / 2) - py
elseif mode == "normalized" then
sample_x = px / width
sample_y = py / height
else
sample_x, sample_y = px, py
end
local r1, r2 = UpdateMapHighlight(sample_x, sample_y)
local zone_name = pfQuestResolveHighlightZone(zone_names, zone_name_to_id, r1, r2)
local map_id = zone_name and zone_name_to_id[zone_name]
if map_id then
rects[map_id] = rects[map_id] or { minx = px, maxx = px, miny = py, maxy = py }
local rect = rects[map_id]
if px < rect.minx then rect.minx = px end
if px > rect.maxx then rect.maxx = px end
if py < rect.miny then rect.miny = py end
if py > rect.maxy then rect.maxy = py end
end
end
end
local found = 0
local pad_x = step / 2
local pad_y = step / 2
local zone_rects = {}
for map_id, rect in pairs(rects) do
local left = (math.max(0, rect.minx - pad_x) / width) * 100
local right = (math.min(width, rect.maxx + pad_x) / width) * 100
local top = (math.max(0, rect.miny - pad_y) / height) * 100
local bottom = (math.min(height, rect.maxy + pad_y) / height) * 100
zone_rects[map_id] = { left = left, right = right, top = top, bottom = bottom }
found = found + 1
end
if found == 0 then return nil end
return zone_rects, width, height
end
local function pfQuestGetContinentZoneRects(continent)
continent = tonumber(continent)
if not continent or continent <= 0 then return nil end
local width = WorldMapButton and tonumber(WorldMapButton:GetWidth()) or 0
local height = WorldMapButton and tonumber(WorldMapButton:GetHeight()) or 0
local cached = continent_zone_cache[continent]
if cached and cached.rects and cached.width == width and cached.height == height then
return cached.rects
end
local rects, rw, rh = pfQuestSampleContinentRects(continent, "relative")
if not rects then
rects, rw, rh = pfQuestSampleContinentRects(continent, "normalized")
end
if not rects then
rects, rw, rh = pfQuestSampleContinentRects(continent, "absolute")
end
if not rects then
if not continent_zone_debug[continent] then
continent_zone_debug[continent] = true
if pfQuest and pfQuest.Debug then
pfQuest:Debug("continent markers: unable to resolve zone bounds for continent " .. tostring(continent))
end
end
continent_zone_cache[continent] = nil
return nil
end
continent_zone_debug[continent] = nil
continent_zone_cache[continent] = { rects = rects, width = rw or width, height = rh or height }
return rects
end
local function pfQuestTranslateToContinent(continent, map_id, x, y, zone_rects, zone_id_to_index)
if not map_id then return nil end
local zones = pfDB and pfDB["zones"] and pfDB["zones"]["data"]
local guard = 0
while map_id and map_id > 0 and guard < 8 do
if Astrolabe and Astrolabe.TranslateWorldMapPosition and zone_id_to_index then
local zone_index = zone_id_to_index[map_id]
if zone_index and zone_index > 0 then
local tx, ty = Astrolabe:TranslateWorldMapPosition(continent, zone_index, x / 100, y / 100, continent, 0)
if tx and ty then
return tx * 100, ty * 100
end
end
end
if zone_rects then
local rect = zone_rects[map_id]
if rect then
local width = rect.right - rect.left
local height = rect.bottom - rect.top
return rect.left + (x * width / 100), rect.top + (y * height / 100)
end
end
local meta = zones and zones[map_id]
if not meta then return nil end
local parent, width, height, parent_x, parent_y = unpack(meta)
if not parent or parent <= 0 then return nil end
if not width or not height or not parent_x or not parent_y then return nil end
-- Child map coords are centered at 50,50 in parent-space percentages.
x = parent_x + ((x - 50) * width / 100)
y = parent_y + ((y - 50) * height / 100)
map_id = parent
guard = guard + 1
end
end
local function pfQuestShouldProjectContinentEntry(meta)
local quest_id = meta and tonumber(meta.questid)
if not quest_id or quest_id <= 0 then return nil end
local texture = meta.texture
if not texture then
-- Quest objectives are dot nodes (no texture) in pfQuest.
return true
end
return string.find(texture, "available", 1, true) or string.find(texture, "complete", 1, true)
end
local function pfQuestBuildContinentQuestNodes(continent)
local continent_nodes = {}
local zone_rects = pfQuestGetContinentZoneRects(continent)
local _, _, zone_id_to_index = pfQuestGetContinentZoneLookup(continent)
local can_use_astrolabe = Astrolabe and Astrolabe.TranslateWorldMapPosition and zone_id_to_index and next(zone_id_to_index)
if not zone_rects and not can_use_astrolabe then return continent_nodes end
for addon, maps in pairs(pfMap.nodes or {}) do
if addon ~= CONTINENT_NODE_ADDON then
for map_id, map_nodes in pairs(maps or {}) do
map_id = tonumber(map_id)
if map_id and map_id > 0 then
for coords, node in pairs(map_nodes) do
local coord_x_str, coord_y_str = string.match(coords, CONTINENT_COORD_PATTERN)
local x, y = tonumber(coord_x_str), tonumber(coord_y_str)
if x and y then
local tx, ty = pfQuestTranslateToContinent(continent, map_id, x, y, zone_rects, zone_id_to_index)
if tx and ty and tx >= 0 and tx <= 100 and ty >= 0 and ty <= 100 then
local filtered = nil
for title, meta in pairs(node) do
if pfQuestShouldProjectContinentEntry(meta) then
filtered = filtered or {}
filtered[title] = meta
end
end
if filtered then
local key = string.format(CONTINENT_COORD_FORMAT, tx, ty)
continent_nodes[key] = continent_nodes[key] or {}
for title, meta in pairs(filtered) do continent_nodes[key][title] = meta end
end
end
end
end
end
end
end
end
return continent_nodes
end
function pfMap:GetMapID(cid, mid)
local continent = cid or GetCurrentMapContinent()
local zone = mid
if zone == nil then zone = GetCurrentMapZone() end
if zone == 0 then
local continent_map_key = pfQuestGetContinentMapKey(continent)
if continent_map_key then return continent_map_key end
end
return original_GetMapID(self, cid, mid)
end
function pfMap:UpdateNodes()
if GetCurrentMapZone() == 0 then
local continent = GetCurrentMapContinent()
local continent_map_key = pfQuestGetContinentMapKey(continent)
if continent_map_key then
pfMap.nodes[CONTINENT_NODE_ADDON] = pfMap.nodes[CONTINENT_NODE_ADDON] or {}
pfMap.nodes[CONTINENT_NODE_ADDON][continent_map_key] = pfQuestBuildContinentQuestNodes(continent)
end
end
return original_UpdateNodes(self)
end
local function pfQuestInstallWorldMapZoom()
local ZOOM_VERSION = 4
if pfMap.worldmap_zoom_version ~= ZOOM_VERSION then
pfMap.worldmap_zoom_installed = nil
pfMap.worldmap_zoom_state = nil
pfMap.worldmap_zoom_scroll = nil
pfMap.worldmap_zoom_content = nil
pfMap.worldmap_zoom_drag = nil
pfMap.worldmap_zoom_events = nil
pfMap.worldmap_zoom_version = ZOOM_VERSION
end
if pfMap and pfMap.worldmap_zoom_installed then return true end
if not WorldMapFrame or not WorldMapDetailFrame or not WorldMapButton then return nil end
local zoom_min = 1.0
local zoom_max = 5
local zoom_step = 0.2
pfMap.worldmap_zoom_state = pfMap.worldmap_zoom_state or { scale = 1, scrollX = 0, scrollY = 0 }
local state = pfMap.worldmap_zoom_state
local function clamp(value, minv, maxv)
if value < minv then return minv end
if value > maxv then return maxv end
return value
end
local function cursor_local_to(frame)
if not frame then return nil end
local scale = frame:GetEffectiveScale() or 1
local cursorX, cursorY = GetCursorPosition()
local left = frame:GetLeft()
local bottom = frame:GetBottom()
local width = frame:GetWidth()
local height = frame:GetHeight()
if not left or not bottom or not width or not height or width == 0 or height == 0 then
return nil
end
local x = cursorX / scale - left
local y = cursorY / scale - bottom
if x < 0 or x > width or y < 0 or y > height then
return nil
end
return x, height - y
end
local function capture_base()
local w = WorldMapDetailFrame:GetWidth()
local h = WorldMapDetailFrame:GetHeight()
if not w or not h or w <= 0 or h <= 0 then return nil end
local should_update = (not state.base_width or not state.base_height or not state.base_points)
if state.scale == 1 and (state.base_width ~= w or state.base_height ~= h) then
should_update = true
end
if should_update then
state.base_width = w
state.base_height = h
state.base_parent = WorldMapDetailFrame:GetParent() or WorldMapFrame
state.base_points = {}
local num = WorldMapDetailFrame:GetNumPoints()
if num and num > 0 then
for i = 1, num do
local point, rel, relPoint, x, y = WorldMapDetailFrame:GetPoint(i)
state.base_points[i] = { point = point, rel = rel, relPoint = relPoint, x = x, y = y }
end
else
state.base_points[1] = { point = "TOPLEFT", rel = state.base_parent, relPoint = "TOPLEFT", x = 0, y = 0 }
end
end
return true
end
local function ensure_scroll()
if not capture_base() then return nil end
local parent = state.base_parent or WorldMapFrame
if not parent then return nil end
local scroll = pfMap.worldmap_zoom_scroll
local content = pfMap.worldmap_zoom_content
if not scroll or not content then
scroll = CreateFrame("ScrollFrame", "pfQuestWorldMapScroll", parent)
scroll:SetFrameStrata(WorldMapDetailFrame:GetFrameStrata())
scroll:SetFrameLevel(WorldMapDetailFrame:GetFrameLevel())
scroll:EnableMouse(false)
scroll:Show()
scroll:ClearAllPoints()
for i = 1, table.getn(state.base_points) do
local p = state.base_points[i]
local rel = p.rel or parent
if rel == WorldMapDetailFrame then rel = parent end
if type(rel) == "string" and rel == WorldMapDetailFrame:GetName() then rel = parent end
scroll:SetPoint(p.point, rel, p.relPoint, p.x, p.y)
end
scroll:SetWidth(state.base_width)
scroll:SetHeight(state.base_height)
content = CreateFrame("Frame", "pfQuestWorldMapContent", scroll)
content:SetPoint("TOPLEFT", scroll, "TOPLEFT", 0, 0)
content:SetWidth(state.base_width)
content:SetHeight(state.base_height)
scroll:SetScrollChild(content)
WorldMapDetailFrame:SetParent(content)
WorldMapDetailFrame:ClearAllPoints()
WorldMapDetailFrame:SetPoint("TOPLEFT", content, "TOPLEFT", 0, 0)
WorldMapDetailFrame:SetWidth(state.base_width)
WorldMapDetailFrame:SetHeight(state.base_height)
WorldMapButton:SetParent(content)
WorldMapButton:ClearAllPoints()
WorldMapButton:SetPoint("TOPLEFT", content, "TOPLEFT", 0, 0)
WorldMapButton:SetWidth(state.base_width)
WorldMapButton:SetHeight(state.base_height)
pfMap.worldmap_zoom_scroll = scroll
pfMap.worldmap_zoom_content = content
else
scroll:SetWidth(state.base_width)
scroll:SetHeight(state.base_height)
content:SetWidth(state.base_width)
content:SetHeight(state.base_height)
end
return scroll, content
end
local function max_scroll(viewW, viewH, scale)
local mapW = state.base_width or viewW
local mapH = state.base_height or viewH
local maxX = mapW - (viewW / scale)
local maxY = mapH - (viewH / scale)
if maxX < 0 then maxX = 0 end
if maxY < 0 then maxY = 0 end
return maxX, maxY
end
local function apply_state()
if not WorldMapFrame:IsShown() then return end
local scroll, content = ensure_scroll()
if not scroll or not content then return end
if WorldMapDetailFrame:GetParent() ~= content then
WorldMapDetailFrame:SetParent(content)
end
WorldMapDetailFrame:ClearAllPoints()
WorldMapDetailFrame:SetPoint("TOPLEFT", content, "TOPLEFT", 0, 0)
WorldMapDetailFrame:SetWidth(state.base_width)
WorldMapDetailFrame:SetHeight(state.base_height)
if WorldMapButton:GetParent() ~= content then
WorldMapButton:SetParent(content)
end
WorldMapButton:ClearAllPoints()
WorldMapButton:SetPoint("TOPLEFT", content, "TOPLEFT", 0, 0)
WorldMapButton:SetWidth(state.base_width)
WorldMapButton:SetHeight(state.base_height)
if scroll.GetScrollChild and scroll:GetScrollChild() ~= content then
scroll:SetScrollChild(content)
end
if state.scale < zoom_min then state.scale = zoom_min end
if state.scale > zoom_max then state.scale = zoom_max end
if state.scale == 1 then
state.scrollX = 0
state.scrollY = 0
end
content:SetScale(state.scale)
pfQuestApplyAllWorldMapPinSizes()
local viewW = scroll:GetWidth()
local viewH = scroll:GetHeight()
if not viewW or not viewH or viewW <= 0 or viewH <= 0 then return end
local maxX, maxY = max_scroll(viewW, viewH, state.scale)
state.scrollX = clamp(state.scrollX or 0, 0, maxX)
state.scrollY = clamp(state.scrollY or 0, 0, maxY)
if scroll.SetHorizontalScroll then
scroll:SetHorizontalScroll(0)
scroll:SetVerticalScroll(0)
end
content:ClearAllPoints()
content:SetPoint("TOPLEFT", scroll, "TOPLEFT", -state.scrollX, state.scrollY)
pfMap.queue_update = GetTime()
end
local function zoom_by(delta)
if not WorldMapFrame:IsShown() then return end
local scroll, content = ensure_scroll()
if not scroll or not content then return end
local viewW = scroll:GetWidth()
local viewH = scroll:GetHeight()
if not viewW or not viewH or viewW <= 0 or viewH <= 0 then return end
local current = state.scale or 1
local target = clamp(current + delta, zoom_min, zoom_max)
if target == current then return end
local localX, localY = cursor_local_to(scroll)
if not localX or not localY then return end
local mapX = state.scrollX + (localX / current)
local mapY = state.scrollY + (localY / current)
state.scale = target
state.scrollX = mapX - (localX / target)
state.scrollY = mapY - (localY / target)
apply_state()
end
local function on_mousewheel(_, delta)
local wheel = delta or arg1 or 0
if wheel > 0 then
zoom_by(zoom_step)
elseif wheel < 0 then
zoom_by(-zoom_step)
end
end
local function hook_wheel(frame, require_hover)
if not frame or frame.pfquest_zoom_hooked then return end
frame:EnableMouseWheel(true)
if frame.HookScript then
frame:HookScript("OnMouseWheel", function(self, delta)
if require_hover then
local view = pfMap.worldmap_zoom_scroll or WorldMapDetailFrame
if not MouseIsOver(view) then return end
end
on_mousewheel(self, delta)
end)
else
local original = frame:GetScript("OnMouseWheel")
frame:SetScript("OnMouseWheel", function(self, delta)
if original then original(self, delta) end
if require_hover then
local view = pfMap.worldmap_zoom_scroll or WorldMapDetailFrame
if not MouseIsOver(view) then return end
end
on_mousewheel(self, delta)
end)
end
frame.pfquest_zoom_hooked = true
end
hook_wheel(WorldMapButton, true)
hook_wheel(WorldMapFrame, true)
if not pfMap.worldmap_zoom_drag then
local drag = CreateFrame("Frame")
drag:SetScript("OnUpdate", function()
if not state.dragging then return end
if ( this.throttle or 0) > GetTime() then return else this.throttle = GetTime() + 0.01 end
local scroll, content = ensure_scroll()
if not scroll or not content then return end
local localX, localY = cursor_local_to(scroll)
if not localX or not localY then return end
local dx = localX - (state.dragStartX or localX)
local dy = localY - (state.dragStartY or localY)
local viewW = scroll:GetWidth()
local viewH = scroll:GetHeight()
local maxX, maxY = max_scroll(viewW, viewH, state.scale)
state.scrollX = clamp((state.dragBaseX or 0) - (dx / state.scale), 0, maxX)
state.scrollY = clamp((state.dragBaseY or 0) - (dy / state.scale), 0, maxY)
apply_state()
end)
pfMap.worldmap_zoom_drag = drag
end
local function hook_drag(frame)
if not frame or frame.pfquest_drag_hooked then return end
local function on_down(self, button)
if not WorldMapFrame:IsShown() then return end
if button ~= "MiddleButton" and button ~= "Button3" then return end
local view = pfMap.worldmap_zoom_scroll or WorldMapDetailFrame
if not MouseIsOver(view) then return end
local localX, localY = cursor_local_to(view)
if not localX or not localY then return end
state.dragging = true
state.dragStartX = localX
state.dragStartY = localY
state.dragBaseX = state.scrollX or 0
state.dragBaseY = state.scrollY or 0
end
local function on_up(self, button)
if button ~= "MiddleButton" and button ~= "Button3" then return end
state.dragging = nil
end
if frame.HookScript then
frame:HookScript("OnMouseDown", on_down)
frame:HookScript("OnMouseUp", on_up)
else
local original_down = frame:GetScript("OnMouseDown")
local original_up = frame:GetScript("OnMouseUp")
frame:SetScript("OnMouseDown", function(self, button)
if original_down then original_down(self, button) end
on_down(self, button)
end)
frame:SetScript("OnMouseUp", function(self, button)
if original_up then original_up(self, button) end
on_up(self, button)
end)
end
frame.pfquest_drag_hooked = true
end
hook_drag(WorldMapButton)
hook_drag(WorldMapFrame)
if not pfMap.worldmap_zoom_events then
local events = CreateFrame("Frame")
events:RegisterEvent("WORLD_MAP_UPDATE")
events:RegisterEvent("PLAYER_ENTERING_WORLD")
events:SetScript("OnEvent", function()
apply_state()
end)
pfMap.worldmap_zoom_events = events
end
if pfMap then
pfMap.worldmap_zoom_installed = true
end
apply_state()
return true
end
if not pfQuestInstallWorldMapZoom() then
local zoominit = CreateFrame("Frame")
zoominit:RegisterEvent("PLAYER_ENTERING_WORLD")
zoominit:RegisterEvent("WORLD_MAP_UPDATE")
zoominit:SetScript("OnEvent", function()
if pfQuestInstallWorldMapZoom() then
this:UnregisterAllEvents()
end
end)
end
pfDatabase:Reload()
local function strsplit(delimiter, subject)
if not subject then return nil end
local fields = {}
local pattern = string.format("([^%s]+)", delimiter or ":")
string.gsub(subject, pattern, function(token) fields[table.getn(fields)+1] = token end)
return unpack(fields)
end
-- Server reports direct completions only; close/pre chains are resolved here.
local function complete(history, qid)
qid = tonumber(qid)
if not qid then return end
local previous = pfQuest_history and pfQuest_history[qid]
history[qid] = { previous and previous[1] or 0, previous and previous[2] or 0 }
local quest_data = pfDB["quests"] and pfDB["quests"]["data"]
local quest = quest_data and quest_data[qid]
if not quest then return end
local close = quest["close"]
if close then
for _, close_qid in pairs(close) do
if not history[close_qid] then complete(history, close_qid) end
end
end
local prequests = quest["pre"]
if prequests then
for _, pre_qid in pairs(prequests) do
if not history[pre_qid] then complete(history, pre_qid) end
end
end
end
local query = CreateFrame("Frame")
query:Hide()
query:SetScript("OnEvent", function()
if arg1 == "TWQUEST" then
for _, qid in pairs({strsplit(" ", arg2)}) do
complete(this.history, qid)
end
end
end)
query:SetScript("OnShow", function()
this.history = {}
this.time = GetTime()
this:RegisterEvent("CHAT_MSG_ADDON")
SendChatMessage(".queststatus", "GUILD")
end)
query:SetScript("OnHide", function()
this:UnregisterEvent("CHAT_MSG_ADDON")
local count = 0
for qid in pairs(this.history) do count = count + 1 end
DEFAULT_CHAT_FRAME:AddMessage("|cff33ffccpf|cffffffffQuest|r: A total of " .. count .. " quests have been marked as completed.")
pfQuest_history = this.history
this.history = nil
pfQuest:ResetAll()
end)
query:SetScript("OnUpdate", function()
if GetTime() > this.time + 3 then this:Hide() end
end)
function pfDatabase:QueryServer()
DEFAULT_CHAT_FRAME:AddMessage("|cff33ffccpf|cffffffffQuest|r: Receiving quest data from server...")
query:Show()
end
local update_check = CreateFrame("Frame")
update_check:RegisterEvent("PLAYER_ENTERING_WORLD")
update_check:SetScript("OnEvent", function()
local turtle_quests = pfDB["quests"]["data-turtle"]
if turtle_quests then
local count = 0
for _ in pairs(turtle_quests) do
count = count + 1
end
pfQuest:Debug("TurtleWoW loaded with |cff33ffcc" .. count .. "|r quests.")
if not pfQuest_turtlecount or pfQuest_turtlecount ~= count then
pfQuest:Debug("New quests found. Reloading |cff33ffccCache|r")
pfQuest_questcache = {}
end
pfQuest_turtlecount = count
end
end)