-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathroute.lua
More file actions
815 lines (712 loc) · 28.5 KB
/
Copy pathroute.lua
File metadata and controls
815 lines (712 loc) · 28.5 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
-- Performance: cache frequently-used globals
local pairs = pairs
local floor, ceil, sqrt, abs = math.floor, math.ceil, math.sqrt, math.abs
local sin, cos, rad, pi = math.sin, math.cos, math.rad, math.pi
-- WoW's global atan2 returns degrees; fallback for clients without it
local atan2 = atan2 or function(x, y)
return math.deg(math.atan2(x, y))
end
local min, max = math.min, math.max
local getn, insert, sort = table.getn, table.insert, table.sort
local GetTime = GetTime
-- table.getn doesn't return sizes on tables that
-- are using a named index on which setn is not updated
local function tablesize(tbl)
local count = 0
for _ in pairs(tbl) do
count = count + 1
end
return count
end
local function modulo(val, by)
return val - floor(val / by) * by
end
local function GetNearest(xstart, ystart, db, blacklist)
local nearest = nil
local best = nil
for id, data in pairs(db) do
if data[1] and data[2] and not blacklist[id] then
local x, y = xstart - data[1], ystart - data[2]
-- Use squared distance for comparison (avoid sqrt)
local distSq = x * x + y * y
if not nearest or distSq < nearest then
nearest = distSq
best = id
end
end
end
if not best then
return
end
blacklist[best] = true
return db[best]
end
-- connection between objectives
local objectivepath = {}
-- connection between player and the first objective
local playerpath = {} -- worldmap
local mplayerpath = {} -- minimap
local function ClearPath(path)
for id, tex in pairs(path) do
tex.enable = nil
tex:Hide()
end
end
local function DrawLine(path, x, y, nx, ny, hl, minimap)
local display = true
local zoom = 1
-- calculate minimap variables
local xplayer, yplayer, xdraw, ydraw
if minimap then
-- player coords
xplayer, yplayer = GetPlayerMapPosition("player")
xplayer, yplayer = xplayer * 100, yplayer * 100
-- query minimap zoom/size data
local mZoom = pfMap.drawlayer:GetZoom()
local mapID = pfMap:GetMapIDByName(GetRealZoneText())
local mapZoom = pfMap.minimap_zoom[pfMap.minimap_indoor()][mZoom]
local mapWidth = pfMap.minimap_sizes[mapID] and pfMap.minimap_sizes[mapID][1] or 0
local mapHeight = pfMap.minimap_sizes[mapID] and pfMap.minimap_sizes[mapID][2] or 0
-- calculate drawlayer size
xdraw = pfMap.drawlayer:GetWidth() / (mapZoom / mapWidth) / 100
ydraw = pfMap.drawlayer:GetHeight() / (mapZoom / mapHeight) / 100
zoom = ((mapZoom / mapWidth) + (mapZoom / mapHeight)) * 3
end
-- general
local dx, dy = x - nx, y - ny
local dots = ceil(math.sqrt(dx * 1.5 * dx * 1.5 + dy * dy)) / zoom
for i = (minimap and 1 or 2), dots - (minimap and 1 or 2) do
local xpos = nx + dx / dots * i
local ypos = ny + dy / dots * i
if minimap then
-- adjust values to minimap
xpos = (xplayer - xpos) * xdraw
ypos = (yplayer - ypos) * ydraw
-- check if dot should be visible
if pfUI.minimap then
display = (abs(xpos) + 1 < pfMap.drawlayer:GetWidth() / 2 and abs(ypos) + 1 < pfMap.drawlayer:GetHeight() / 2)
and true
or nil
else
local distance = sqrt(xpos * xpos + ypos * ypos)
display = (distance + 1 < pfMap.drawlayer:GetWidth() / 2) and true or nil
end
else
-- adjust values to worldmap
xpos = xpos / 100 * WorldMapButton:GetWidth()
ypos = ypos / 100 * WorldMapButton:GetHeight()
end
if display then
local nline = tablesize(path) + 1
for id, tex in pairs(path) do
if not tex.enable then
nline = id
break
end
end
path[nline] = path[nline] or (minimap and pfMap.drawlayer or WorldMapButton.routes):CreateTexture(nil, "OVERLAY")
path[nline]:SetWidth(4)
path[nline]:SetHeight(4)
path[nline]:SetTexture(pfQuestConfig.path .. "\\img\\route")
if hl and minimap then
path[nline]:SetVertexColor(0.6, 0.4, 0.2, 0.5)
elseif hl then
path[nline]:SetVertexColor(1, 0.8, 0.4, 1)
else
path[nline]:SetVertexColor(0.6, 0.4, 0.2, 1)
end
path[nline]:ClearAllPoints()
if minimap then -- draw minimap
path[nline]:SetPoint("CENTER", pfMap.drawlayer, "CENTER", -xpos, ypos)
else -- draw worldmap
path[nline]:SetPoint("CENTER", WorldMapButton, "TOPLEFT", xpos, -ypos)
end
path[nline]:Show()
path[nline].enable = true
end
end
end
pfQuest.route = CreateFrame("Frame", "pfQuestRoute", WorldFrame)
pfQuest.route.firstnode = nil
pfQuest.route.coords = {}
pfQuest.route.Reset = function(self)
self.coords = {}
self.firstnode = nil
self.lastDrawX = nil
self.lastDrawY = nil
self.lastDrawNode = nil
self.tick = nil
self.throttle = nil
self.recalculate = nil
self.refreshTrackerDistances = true
end
pfQuest.route.AddPoint = function(self, tbl)
table.insert(self.coords, tbl)
self.firstnode = nil
end
local targetTitle, targetCluster, targetLayer, targetTexture = nil, nil, nil, nil
pfQuest.route.SetTarget = function(node, default)
if
node
and (
node.title ~= targetTitle
or node.cluster ~= targetCluster
or node.layer ~= targetLayer
or node.texture ~= targetTexture
)
then
-- a TIMESTAMP, never a boolean: map.lua's node-update debounce does
-- "queue_update + 0.25 < GetTime()", so a true here throws every frame
-- ("attempt to perform arithmetic on field 'queue_update'") and, because
-- the throw lands BEFORE the line that clears the field, the flag stays
-- true and map node updates stall for the rest of the session.
pfMap.queue_update = GetTime()
end
targetTitle = node and node.title or nil
targetCluster = node and node.cluster or nil
targetLayer = node and node.layer or nil
targetTexture = node and node.texture or nil
end
pfQuest.route.IsTarget = function(node)
if node then
if
targetTitle
and targetTitle == node.title
and targetCluster == node.cluster
and targetLayer == node.layer
and targetTexture == node.texture
then
return true
end
end
return nil
end
local lastpos, completed = 0, 0
local function GetQuestSortMode()
return pfQuest_config["trackerquestsort"] == "distance" and "distance" or "level"
end
-- Match tracker.lua's fallback behavior so missing route distances sort last
-- without relying on math.huge on older clients.
local DIST_FAR = 99999999
local function sortfunc(a, b)
if pfQuest_config["trackingmethod"] == 5 then
-- Route tuples are { x, y, node, distance, watched, questid }
-- Watched quests stay ahead of all local non-watched candidates in mode 5.
if (a[5] and 1 or -1) ~= (b[5] and 1 or -1) then
return (a[5] and 1 or -1) > (b[5] and 1 or -1)
end
local alevel = (a[3] and tonumber(a[3].qlvl)) or -1
local blevel = (b[3] and tonumber(b[3].qlvl)) or -1
if GetQuestSortMode() == "distance" then
-- "Nearest" mode still keeps watched quests first; after that, prefer the
-- closest current-map objective and only use quest level as a tie-breaker.
if (a[4] or DIST_FAR) ~= (b[4] or DIST_FAR) then
return (a[4] or DIST_FAR) < (b[4] or DIST_FAR)
end
if alevel ~= blevel then
return alevel > blevel
end
else
-- "Level" mode flips the middle priority: higher quest level wins first,
-- then distance breaks ties so the chosen target still feels local.
if alevel ~= blevel then
return alevel > blevel
end
if (a[4] or DIST_FAR) ~= (b[4] or DIST_FAR) then
return (a[4] or DIST_FAR) < (b[4] or DIST_FAR)
end
end
-- Final stable tie-breaker so equal watched/level/distance candidates do
-- not reshuffle unpredictably between updates.
local atitle = (a[3] and a[3].title) or ""
local btitle = (b[3] and b[3].title) or ""
if atitle ~= btitle then
return atitle < btitle
end
end
return a[4] < b[4]
end
pfQuest.route:SetScript("OnUpdate", function()
local xplayer, yplayer = GetPlayerMapPosition("player")
local wrongmap = xplayer == 0 and yplayer == 0 and true or nil
local curpos = xplayer + yplayer
-- limit distance and route updates to once per .1 seconds
if (this.tick or 5) > GetTime() and lastpos == curpos then
return
else
this.tick = GetTime() + 1
end
-- limit to a maxium of each .05 seconds even on position change
if (this.throttle or 0.2) > GetTime() then
return
else
this.throttle = GetTime() + 0.05
end
-- save current position
lastpos = curpos
-- update distances to player
for id, data in ipairs(this.coords) do
if data[1] and data[2] then
local x, y = (xplayer * 100 - data[1]) * 1.5, yplayer * 100 - data[2]
this.coords[id][4] = ceil(math.sqrt(x * x + y * y) * 100) / 100
end
end
-- sort all coords by distance only once per second
if not this.recalculate or this.recalculate < GetTime() then
table.sort(this.coords, sortfunc)
-- order list on custom targets
if targetTitle and this.coords[1] and not pfQuest.route.IsTarget(this.coords[1][3]) then
local target = nil
-- check for the old index of the target
for id, data in ipairs(this.coords) do
if pfQuest.route.IsTarget(data[3]) then
target = id
break
end
end
-- rearrange coordinates
if target then
local tmp = {}
table.insert(tmp, this.coords[target])
for id, data in ipairs(this.coords) do
if id ~= target then
table.insert(tmp, this.coords[id])
end
end
this.coords = tmp
end
end
this.recalculate = GetTime() + 1
if this.refreshTrackerDistances and tracker and tracker.RefreshNearestDistances then
tracker:RefreshNearestDistances()
this.refreshTrackerDistances = nil
end
end
-- show arrow when route exists and is stable
if
not wrongmap
and this.coords[1]
and this.coords[1][4]
and not this.arrow:IsShown()
and pfQuest_config["arrow"] == "1"
and GetTime() > completed + 1
then
this.arrow:Show()
end
-- abort without any nodes or distances
if not this.coords[1] or not this.coords[1][4] or pfQuest_config["routes"] == "0" then
ClearPath(objectivepath)
ClearPath(playerpath)
ClearPath(mplayerpath)
return
end
-- continent or two-continent view: hide all paths and skip route calculation.
-- wrongmap means GetPlayerMapPosition returned 0,0 so distances are meaningless;
-- without this guard the re-sort from bad distances flips firstnode and causes
-- the route to be redrawn on the continent map.
if wrongmap then
ClearPath(objectivepath)
ClearPath(playerpath)
ClearPath(mplayerpath)
this.lastDrawX = nil
this.lastDrawY = nil
this.firstnode = nil
return
end
-- check first node for changes (numeric concat already yields a string, so
-- tostring() was redundant; build the key once instead of concatenating twice)
local fnkey = this.coords[1][1] .. this.coords[1][2]
if this.firstnode ~= fnkey then
this.firstnode = fnkey
-- recalculate objective paths
local route = { [1] = this.coords[1] }
local blacklist = { [1] = true }
for i = 2, table.getn(this.coords) do
if route[i - 1] then -- make sure the route was not blacklisted
route[i] = GetNearest(route[i - 1][1], route[i - 1][2], this.coords, blacklist)
end
-- remove other item requirement gameobjects of same type from route
if route[i] and route[i][3] and route[i][3].itemreq then
for id, data in ipairs(this.coords) do
if
not blacklist[id]
and data[1]
and data[2]
and data[3]
and data[3].itemreq
and data[3].itemreq == route[i][3].itemreq
then
blacklist[id] = true
end
end
end
end
ClearPath(objectivepath)
for i, data in pairs(route) do
if i > 1 then
DrawLine(objectivepath, route[i - 1][1], route[i - 1][2], route[i][1], route[i][2])
end
end
-- route calculation timestamp
completed = GetTime()
end
-- only redraw player-to-object path when position has changed enough to
-- produce a visible difference — DrawLine places one dot-texture per unit
-- of distance, so sub-threshold redraws are pure waste.
-- also invalidate when the target node changed (firstnode flip).
local px, py = xplayer * 100, yplayer * 100
local dx = (this.lastDrawX or px + 1) - px
local dy = (this.lastDrawY or py + 1) - py
local moved = dx * dx + dy * dy
local targetChanged = this.lastDrawNode ~= this.firstnode
if moved > 0.09 or targetChanged then -- threshold: 0.3 map units squared
this.lastDrawX = px
this.lastDrawY = py
this.lastDrawNode = this.firstnode
-- draw player-to-object path
ClearPath(playerpath)
ClearPath(mplayerpath)
DrawLine(playerpath, px, py, this.coords[1][1], this.coords[1][2], true)
-- also draw minimap path if enabled
if pfQuest_config["routeminimap"] == "1" then
DrawLine(mplayerpath, px, py, this.coords[1][1], this.coords[1][2], true, true)
end
end
end)
pfQuest.route.drawlayer = CreateFrame("Frame", "pfQuestRouteDrawLayer", WorldMapButton)
pfQuest.route.drawlayer:SetFrameLevel(113)
pfQuest.route.drawlayer:SetAllPoints()
WorldMapButton.routes = CreateFrame("Frame", "pfQuestRouteDisplay", pfQuest.route.drawlayer)
WorldMapButton.routes:SetAllPoints()
pfQuest.route.arrow = CreateFrame("Frame", "pfQuestRouteArrow", UIParent)
pfQuest.route.arrow:SetPoint("CENTER", 0, -100)
pfQuest.route.arrow:SetWidth(48)
pfQuest.route.arrow:SetHeight(36)
pfQuest.route.arrow:SetClampedToScreen(true)
pfQuest.route.arrow:SetMovable(true)
pfQuest.route.arrow:EnableMouse(true)
pfQuest.route.arrow:RegisterForDrag("LeftButton")
pfQuest.route.arrow:SetScript("OnDragStart", function()
if IsShiftKeyDown() then
this:StartMoving()
end
end)
pfQuest.route.arrow:SetScript("OnDragStop", function()
this:StopMovingOrSizing()
local anchor, x, y = pfUI.api.ConvertFrameAnchor(this, pfUI.api.GetBestAnchor(this))
this:ClearAllPoints()
this:SetPoint(anchor, x, y)
-- save position
pfQuest_config.arrowpos = { anchor, x, y }
end)
pfQuest.route.arrow:SetScript("OnShow", function()
if pfQuest_config.arrowpos then
this:ClearAllPoints()
this:SetPoint(unpack(pfQuest_config.arrowpos))
end
end)
local invalid, lasttarget
local lastangle, lastt
local xplayer, yplayer, wrongmap
local xDelta, yDelta, dir, angle
local player, perc, column, row, xstart, ystart, xend, yend
local area, alpha, texalpha, color
local defcolor = "|cffffcc00"
local r, g, b
pfQuest.route.arrow:SetScript("OnUpdate", function()
-- abort if the frame is not initialized yet
if not this.parent then
return
end
-- resolve the arrow style once, in-game (every addon is loaded by the first
-- OnUpdate, so IsAddOnLoaded is reliable here regardless of load order)
if not this.styled then
this.styled = true
this:ConfigureStyle()
end
xplayer, yplayer = GetPlayerMapPosition("player")
wrongmap = xplayer == 0 and yplayer == 0 and true or nil
target = this.parent.coords and this.parent.coords[1] and this.parent.coords[1][4] and this.parent.coords[1] or nil
-- disable arrow on invalid map/route; also while on a taxi flight, where
-- position/facing race along the path and the bearing is useless (QA)
if not target or wrongmap or UnitOnTaxi("player") or pfQuest_config["arrow"] == "0" then
if invalid and invalid < GetTime() then
this:Hide()
elseif not invalid then
invalid = GetTime() + 1
end
return
else
invalid = nil
end
-- Reforged perf: this handler recomputed ~3 atan2 + sin/cos + SetTexCoord +
-- SetVertexColor every rendered frame while shown, even standing still. Cap to
-- ~50/sec (indistinguishable for a pointer) and, once the ease has settled,
-- skip the whole recompute when the player has not moved or turned and the
-- target is unchanged -- every value below is a pure function of player
-- position, facing and target. lastt is refreshed on skip so a later move
-- eases instead of snapping.
local now = GetTime()
if this.perfTick and now < this.perfTick then return end
this.perfTick = now + 0.02
player = pfQuestCompat.GetPlayerFacing()
if this.settled and target == lasttarget
and xplayer == this.lastXP and yplayer == this.lastYP and player == this.lastFacing then
lastt = now
return
end
this.lastXP, this.lastYP, this.lastFacing = xplayer, yplayer, player
-- Reforged: free-rotation arrow. Bearing math: map coords are x-east/y-south,
-- GetPlayerFacing is 0=north increasing counterclockwise. Relative clockwise
-- bearing rel = atan2(dx, -dy) + facing (0 = target dead ahead). The rotation
-- constant 3pi/4 is the phi at which the arrow art renders pointing UP under
-- the 8-corner SetTexCoord below (verified in an offline render of the exact
-- corner mapping); increasing phi turns the art counterclockwise, so
-- phi = 3pi/4 - rel points the arrow at the target.
xDelta = (target[1] - xplayer * 100) * 1.5
yDelta = (target[2] - yplayer * 100)
-- math.atan2, NOT the bare atan2: the client's global atan2 works in
-- DEGREES while GetPlayerFacing/math.sin are radians -- mixing them spun
-- the arrow wildly on any movement (QA). Zygor pins the radian one for the
-- same math (Astrolabe.lua: local atan2 = math.atan2).
angle = math.atan2(xDelta, -yDelta) + player
angle = math.atan2(math.sin(angle), math.cos(angle)) -- normalize to [-pi, pi]
-- ease toward the new bearing across the shortest wrap so target switches
-- turn the arrow instead of snapping it (Zygor Pointer.lua does the same)
if lastangle and lastt then
local dif = angle - lastangle
if dif > math.pi then dif = dif - 2 * math.pi end
if dif < -math.pi then dif = dif + 2 * math.pi end
this.settled = math.abs(dif) < 0.0008 -- reached target bearing -> idle-skip eligible
angle = lastangle + dif * math.min(1, (now - lastt) * 10)
angle = math.atan2(math.sin(angle), math.cos(angle))
else
this.settled = nil
end
lastangle, lastt = angle, now
perc = math.abs(((math.pi - math.abs(angle)) / math.pi))
r, g, b = pfUI.api.GetColorGradient(floor(perc * 100) / 100)
-- guess area based on node count
area = target[3].priority and target[3].priority or 1
area = max(1, area)
area = min(20, area)
area = (area / 10) + 1
alpha = target[4] - area
alpha = alpha > 1 and 1 or alpha
alpha = alpha < 0.5 and 0.5 or alpha
texalpha = (1 - alpha) * 2
texalpha = texalpha > 1 and 1 or texalpha
texalpha = texalpha < 0 and 0 or texalpha
r, g, b = r + texalpha, g + texalpha, b + texalpha
-- update arrow. GW2 mode: single art free-rotated around its center via the
-- 8-corner SetTexCoord (art stays inside the inscribed circle so the rotated
-- sample never clips). Stock mode (no GW2_UI): pfQuest's 9x12 sprite sheet --
-- pick the cell for this bearing. cell 0 = up and the index increases counter-
-- clockwise (verified against the sheet: 27=left, 54=down, 81=right); our
-- `angle` is clockwise-positive (0 = target ahead), so negate it to walk the
-- sheet the right way.
if this.gw2 then
local phi = 2.35619449019234 - angle
local sin_a = math.sin(phi) * 0.70710678118655
local cos_a = math.cos(phi) * 0.70710678118655
this.model:SetTexCoord(
0.5 - sin_a, 0.5 + cos_a,
0.5 + cos_a, 0.5 + sin_a,
0.5 - cos_a, 0.5 - sin_a,
0.5 + sin_a, 0.5 - cos_a
)
else
local cell = floor(-angle / (2 * math.pi) * 108 + 0.5) % 108
column = cell % 9
row = floor(cell / 9)
xstart = (column * 56) / 512
ystart = (row * 42) / 512
xend = ((column + 1) * 56) / 512
yend = ((row + 1) * 42) / 512
this.model:SetTexCoord(xstart, xend, ystart, yend)
end
this.model:SetVertexColor(r, g, b)
-- recalculate values on target change
if target ~= lasttarget then
-- calculate difficulty color
color = defcolor
if tonumber(target[3]["qlvl"]) then
color = pfMap:HexDifficultyColor(tonumber(target[3]["qlvl"]))
end
-- update node texture
if target[3].texture then
this.texture:SetTexture(target[3].texture)
if target[3].vertex and (target[3].vertex[1] > 0 or target[3].vertex[2] > 0 or target[3].vertex[3] > 0) then
this.texture:SetVertexColor(unpack(target[3].vertex))
else
this.texture:SetVertexColor(1, 1, 1, 1)
end
else
this.texture:SetTexture(pfQuestConfig.path .. "\\img\\node")
this.texture:SetVertexColor(pfMap.str2rgb(target[3].title))
end
-- update arrow texts
local level = target[3].qlvl and "[" .. target[3].qlvl .. "] " or ""
this.title:SetText(color .. level .. target[3].title .. "|r")
local desc = target[3].description or ""
if not pfUI or not pfUI.uf then
this.description:SetTextColor(1, 0.9, 0.7, 1)
desc = string.gsub(desc, "ff33ffcc", "ffffffff")
end
this.description:SetText(desc .. "|r.")
-- Reforged perf: the "on target change" guard above was dead -- lasttarget
-- was declared (line ~465) but never assigned, so this whole block
-- (SetTexture/SetVertexColor/SetText/string builds/gsub) ran every frame.
-- Commit the target so it now runs only on an actual target switch.
lasttarget = target
end
-- only refresh distance text on change
local distance = floor(target[4] * 10) / 10
if distance ~= this.distance.number then
this.distance:SetText("|cffaaaaaa" .. pfQuest_Loc["Distance"] .. ": " .. string.format("%.1f", distance))
this.distance.number = distance
-- Reforged: re-fit the text panel (title/description width changes arrive
-- through the same paths that change the distance/target)
this:UpdateTextPanel()
end
-- update transparencies
this.texture:SetAlpha(texalpha)
this.model:SetAlpha(alpha)
end)
-- Keep the outer arrow frame as the stable drag/anchor box and scale a child container instead
pfQuest.route.arrow.content = CreateFrame("Frame", nil, pfQuest.route.arrow)
pfQuest.route.arrow.content:SetPoint("TOPLEFT", pfQuest.route.arrow, "TOPLEFT", -80, 0)
pfQuest.route.arrow.content:SetPoint("BOTTOMRIGHT", pfQuest.route.arrow, "BOTTOMRIGHT", 80, -54)
-- Reforged: with GW2_UI, a single smoothly-rotated arrow (img\arrow-gw2, drawn for
-- this addon) that the OnUpdate turns via the free 8-corner SetTexCoord (same
-- technique the GW2_UI compass uses), so the pointer rotates continuously instead
-- of snapping. Without GW2_UI, ConfigureStyle() swaps this back to pfQuest's stock
-- 108-cell sprite sheet (img\arrow). The texture/size below is just the initial
-- state; ConfigureStyle sets the final art on the first in-game frame.
pfQuest.route.arrow.model = pfQuest.route.arrow.content:CreateTexture("pfQuestRouteArrow", "MEDIUM")
pfQuest.route.arrow.model:SetTexture(pfQuestConfig.path .. "\\img\\arrow-gw2")
pfQuest.route.arrow.model:SetWidth(44)
pfQuest.route.arrow.model:SetHeight(44)
pfQuest.route.arrow.model:SetPoint("TOP", pfQuest.route.arrow.content, "TOP", 0, 0)
pfQuest.route.arrow.texture = pfQuest.route.arrow.content:CreateTexture("pfQuestRouteNodeTexture", "OVERLAY")
pfQuest.route.arrow.texture:SetWidth(28)
pfQuest.route.arrow.texture:SetHeight(28)
pfQuest.route.arrow.texture:SetPoint("BOTTOM", pfQuest.route.arrow.model, "BOTTOM", 0, 0)
pfQuest.route.arrow.title = pfQuest.route.arrow.content:CreateFontString("pfQuestRouteText", "HIGH", "GameFontWhite")
pfQuest.route.arrow.title:SetPoint("TOP", pfQuest.route.arrow.model, "BOTTOM", 0, -10)
pfQuest.route.arrow.title:SetFont(pfUI.font_default, pfUI_config.global.font_size + 1, "OUTLINE")
pfQuest.route.arrow.title:SetTextColor(1, 0.8, 0)
pfQuest.route.arrow.title:SetJustifyH("CENTER")
pfQuest.route.arrow.description = pfQuest.route.arrow.content:CreateFontString("pfQuestRouteText", "HIGH", "GameFontWhite")
pfQuest.route.arrow.description:SetPoint("TOP", pfQuest.route.arrow.title, "BOTTOM", 0, -2)
pfQuest.route.arrow.description:SetFont(pfUI.font_default, pfUI_config.global.font_size, "OUTLINE")
pfQuest.route.arrow.description:SetTextColor(1, 1, 1)
pfQuest.route.arrow.description:SetJustifyH("CENTER")
pfQuest.route.arrow.distance = pfQuest.route.arrow.content:CreateFontString("pfQuestRouteDistance", "HIGH", "GameFontWhite")
pfQuest.route.arrow.distance:SetPoint("TOP", pfQuest.route.arrow.description, "BOTTOM", 0, -2)
pfQuest.route.arrow.distance:SetFont(pfUI.font_default, pfUI_config.global.font_size - 1, "OUTLINE")
pfQuest.route.arrow.distance:SetTextColor(0.8, 0.8, 0.8)
pfQuest.route.arrow.distance:SetJustifyH("CENTER")
-- Reforged: GW2 flight-timer style panel behind the waypoint texts (same soft
-- parchment art the GW2_UI popups/flight timer use), sized dynamically to the
-- widest visible line so long quest titles never overflow the background.
pfQuest.route.arrow.textbg = pfQuest.route.arrow.content:CreateTexture(nil, "BACKGROUND")
pfQuest.route.arrow.textbg:SetTexture(pfQuestConfig.path .. "\\img\\panel-gw2")
pfQuest.route.arrow.textbg:SetPoint("TOP", pfQuest.route.arrow.model, "BOTTOM", 0, -4)
pfQuest.route.arrow.textbg:Hide()
-- Reforged: the GW2 arrow art and the parchment text panel are part of the GW2_UI
-- look, so only use them when GW2_UI is actually loaded. Without it, fall back to
-- pfQuest's stock sprite-sheet arrow and never draw the panel. Called once from the
-- first OnUpdate (in-game), where IsAddOnLoaded is reliable regardless of load order.
function pfQuest.route.arrow:ConfigureStyle()
self.gw2 = IsAddOnLoaded and IsAddOnLoaded("GW2_UI") and true or false
if self.gw2 then
self.model:SetTexture(pfQuestConfig.path .. "\\img\\arrow-gw2")
self.model:SetWidth(44)
self.model:SetHeight(44)
else
self.model:SetTexture(pfQuestConfig.path .. "\\img\\arrow")
self.model:SetWidth(48)
self.model:SetHeight(36)
self.textbg:Hide()
end
end
function pfQuest.route.arrow:UpdateTextPanel()
if not self.gw2 then
self.textbg:Hide()
return
end
local w = math.max(
self.title:GetStringWidth() or 0,
self.description:GetStringWidth() or 0,
self.distance:GetStringWidth() or 0
)
if w <= 0 then
self.textbg:Hide()
return
end
local fs = pfUI_config.global.font_size
self.textbg:SetWidth(w + 36)
self.textbg:SetHeight(3 * fs + 26)
self.textbg:Show()
end
pfQuest.route.arrow.parent = pfQuest.route
-- arrow scale method: single source of truth for both scroll wheel and config slider
function pfQuest.route.arrow:ApplyScale()
local scale = tonumber(pfQuest_config["arrowscale"]) or 1
scale = max(0.5, min(3.0, scale))
scale = floor(scale * 10 + 0.5) / 10
pfQuest_config["arrowscale"] = tostring(scale)
self.content:SetScale(scale)
end
-- scale indicator: brief "1.5x" flash on scroll
pfQuest.route.arrow.scaletext = pfQuest.route.arrow.content:CreateFontString(nil, "OVERLAY", "GameFontWhite")
pfQuest.route.arrow.scaletext:SetPoint("BOTTOMRIGHT", pfQuest.route.arrow.model, "BOTTOMRIGHT", -2, 2)
pfQuest.route.arrow.scaletext:SetFont(pfUI.font_default, pfUI_config.global.font_size, "OUTLINE")
pfQuest.route.arrow.scaletext:SetJustifyH("RIGHT")
pfQuest.route.arrow.scaletext:SetTextColor(1, 1, 1, 1)
pfQuest.route.arrow.scaletext:Hide()
pfQuest.route.arrow.scalefader = CreateFrame("Frame", nil, pfQuest.route.arrow.content)
pfQuest.route.arrow.scalefader:Hide()
pfQuest.route.arrow.scalefader:SetScript("OnUpdate", function()
local elapsed = GetTime() - this.fadetime
if elapsed > 1.5 then
pfQuest.route.arrow.scaletext:Hide()
this:Hide()
return
end
local alpha = 1.0 - (elapsed / 1.5)
pfQuest.route.arrow.scaletext:SetAlpha(alpha)
end)
local function ShowScaleIndicator(val)
pfQuest.route.arrow.scaletext:SetText(string.format("%.1fx", val))
pfQuest.route.arrow.scaletext:SetAlpha(1)
pfQuest.route.arrow.scaletext:Show()
pfQuest.route.arrow.scalefader.fadetime = GetTime()
pfQuest.route.arrow.scalefader:Show()
end
-- Extend wheel capture across the whole visible arrow block, including the
-- text below the model, without stealing click/drag input from the parent.
pfQuest.route.arrow.hitframe = CreateFrame("Frame", nil, pfQuest.route.arrow.content)
pfQuest.route.arrow.hitframe:SetAllPoints(pfQuest.route.arrow.content)
pfQuest.route.arrow.hitframe:EnableMouseWheel(true)
pfQuest.route.arrow.hitframe:SetScript("OnMouseWheel", function()
if not IsShiftKeyDown() then
return
end
local current = tonumber(pfQuest_config["arrowscale"]) or 1
if arg1 > 0 then
current = current + 0.1
else
current = current - 0.1
end
current = max(0.5, min(3.0, current))
current = floor(current * 10 + 0.5) / 10
pfQuest_config["arrowscale"] = tostring(current)
pfQuest.route.arrow:ApplyScale()
ShowScaleIndicator(current)
-- sync config slider if visible
if pfQuestConfig:IsShown() then
pfQuestConfig:UpdateConfigEntries()
end
end)