-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathmap.lua
More file actions
1532 lines (1368 loc) · 54.8 KB
/
map.lua
File metadata and controls
1532 lines (1368 loc) · 54.8 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
local addonName, addon = ...
local L = addon.locale.Get
local _G = _G
local HBD = LibStub("HereBeDragons-2.0")
local HBDPins = LibStub("HereBeDragons-Pins-2.0")
addon.activeWaypoints = {}
addon.linePoints = {}
local MapPinPool = {}
local MapLinePool = {}
local worldMapFramePool, miniMapFramePool, lineMapFramePool
addon.arrowFrame = CreateFrame("Frame", "RXPG_ARROW", UIParent)
local af = addon.arrowFrame
function addon.arrowFrame:UpdateVisuals()
self.texture:SetTexture(addon.GetTexture(
"rxp_navigation_arrow-1"))
end
local function IsInInstance()
if _G.IsInInstance() and not select(2, GetInstanceInfo()) == "scenario" then
return true
end
end
addon.IsInInstance = IsInInstance
addon.enabledFrames["arrowFrame"] = af
af.IsFeatureEnabled = function ()
local shown = not addon.settings.profile.disableArrow and (addon.hideArrow ~= nil and not addon.hideArrow)
return shown,false
end
--local chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
af:SetMovable(true)
af:EnableMouse(1)
af:SetClampedToScreen(true)
af:SetSize(32, 32)
af.texture = af:CreateTexture()
af.texture:SetAllPoints()
-- af.texture:SetScale(0.5)
af.text = af:CreateFontString(nil, "OVERLAY")
af.text:SetJustifyH("CENTER")
af.text:SetJustifyV("MIDDLE")
af.text:SetPoint("TOP", af, "BOTTOM", 0, -5)
af.orientation = 0
af.distance = 0
af.lowerbound = math.pi / 64 -- angle in radians
af.upperbound = 2 * math.pi - af.lowerbound
af:SetPoint("TOP")
af:Hide()
af:SetScript("OnMouseDown", function(self, button)
if not addon.settings.profile.lockFrames and af:GetAlpha() ~= 0 then af:StartMoving() end
end)
af:SetScript("OnMouseUp", function(self, button)
self:StopMovingOrSizing()
addon.settings:SaveFramePositions()
end)
function addon.SetupArrow()
af.text:SetFont(addon.font, 9,"OUTLINE")
af.texture:SetTexture(addon.GetTexture("rxp_navigation_arrow-1"))
af.text:SetTextColor(unpack(addon.activeTheme.textColor))
addon.arrowFrame:SetScript("OnUpdate", addon.DrawArrow)
end
function addon.DrawArrow(self)
self = self or addon.arrowFrame
if addon.settings.profile.disableArrow or not self then return end
if af.wrongContinent then
-- If first time setting wrong continent, notify player
if self.text:GetText() ~= "~" then
addon.comms.PrettyPrint("%s %s", _G.ERR_TAXINOSUCHPATH, _G.SPELL_FAILED_INCORRECT_AREA)
end
af.alpha = 1
af:SetAlpha(1)
addon.hideArrow = true
self.texture:SetRotation(0)
self.text:SetText("~")
return
end
local element = self.element
if not element then return end
local x, y, instance = HBD:GetPlayerWorldPosition()
local angle, dist = HBD:GetWorldVector(instance, x, y, element.wx,
element.wy)
local facing = GetPlayerFacing()
if not (dist and facing) then
if af.alpha ~= 0 then
af.alpha = 0
af:SetAlpha(0)
end
return
elseif af.alpha ~= 1 then
af.alpha = 1
af:SetAlpha(1)
end
local orientation = angle - facing
local diff = math.abs(orientation - self.orientation)
dist = math.floor(dist)
if diff > self.lowerbound and diff < self.upperbound or self.forceUpdate then
self.orientation = orientation
self.texture:SetRotation(orientation)
self.forceUpdate = false
end
if dist ~= self.distance then
self.distance = dist
local step = element.step
local title = step and (step.arrowtext or step.title or step.index and (L"Step "..step.index))
if element.title then
for RXP_ in string.gmatch(element.title, "RXP_[A-Z]+_") do
element.title = element.title:gsub(RXP_, addon.guideTextColors[RXP_] or
addon.guideTextColors.default["error"])
end
--self.text:SetText(string.format("%s\n(%dyd)",element.title, dist))
self.text:SetText(string.format("%s\n(%dyd)",element.title, dist))
elseif title then
for RXP_ in string.gmatch(title, "RXP_[A-Z]+_") do
title = title:gsub(RXP_, addon.guideTextColors[RXP_] or addon.guideTextColors.default["error"])
end
self.text:SetText(string.format("%s\n(%dyd)", title, dist))
else
self.text:SetText(string.format("(%dyd)", dist))
end
end
end
local function PinOnEnter(self)
if self:IsForbidden() or _G.GameTooltip:IsForbidden() then
return
end
local pin = self.activeObject
local showTooltip
if self.lineData then
showTooltip = pin.step and pin.step.showTooltip and pin.step.elements
if addon.settings.profile.debug then
self:SetAlpha(0.5)
end
if showTooltip then
local element = self.lineData.element
for line in lineMapFramePool:EnumerateActive() do
if line.lineData.element == element then
line:SetAlpha(0.3)
end
end
end
end
_G.GameTooltip:SetOwner(self, "ANCHOR_RIGHT", 0, 0)
_G.GameTooltip:ClearLines()
local lines = 0
local lastStep
for _, element in pairs(pin.elements or showTooltip or {}) do
local parent = element.parent
local text
local step = element.step
local icon = step.icon or ""
local debug = ""
if addon.settings.profile.debug then
debug = format("%.3f,%.3f:",element.x or 0, element.y or 0)
end
icon = icon:gsub("(|T.-):%d+:%d+:","%1:0:0:")
if parent and not parent.hideTooltip then
local hiddentext = parent.hiddentext
if hiddentext and hiddentext:len() < 8 then
hiddentext = false
end
text = parent.mapTooltip or parent.tooltipText or hiddentext or parent.text or ""
local title = step.mapTooltip or step.title or step.index and (L"Step " .. step.index) or step.tip and L"Tip"
if title and title ~= lastStep then
_G.GameTooltip:AddLine(addon.ReplaceNpcIds(icon..title),unpack(addon.colors.mapPins))
lastStep = title
end
_G.GameTooltip:AddLine(addon.ReplaceNpcIds(debug..text))
lines = lines + 1
elseif not parent and not element.hideTooltip then
local hiddentext = step.hiddentext
if hiddentext and hiddentext:len() < 8 then
hiddentext = false
end
text = element.mapTooltip or element.tooltipText or hiddentext or step.text or ""
local title = step.mapTooltip or step.title or step.index and (L"Step " .. step.index) or step.tip and L"Tip"
if title and step ~= lastStep then
_G.GameTooltip:AddLine(addon.ReplaceNpcIds(icon..title),unpack(addon.colors.mapPins))
lastStep = title
end
_G.GameTooltip:AddLine(addon.ReplaceNpcIds(debug..text))
lines = lines + 1
end
end
_G.GameTooltip:SetShown(lines > 0)
end
local function PinOnLeave(self)
if self:IsForbidden() or _G.GameTooltip:IsForbidden() then
return
end
local lineData = self.lineData
if lineData then
local element = lineData.element
for line in lineMapFramePool:EnumerateActive() do
if line.lineData.element == element then
self:SetAlpha(line.lineData.lineAlpha or 1)
end
end
addon.UpdateMap()
end
_G.GameTooltip:Hide()
end
-- The Frame Pool that will manage pins on the world and mini map
-- You must use a frame pool to aquire and release pin frames,
-- otherwise the pins will not be properly removed from the map.
local CreateFramePool
if _G.CreateSecureFramePool == _G.CreateFramePool then
CreateFramePool = function(ref)
local framePool = _G.CreateUnsecuredTexturePool(nil, nil, nil, "BackdropTemplate",ref.resetterFunc)
framePool.createFunc = ref.creationFunc
return framePool
end
else
CreateFramePool = function(ref)
local framePool = _G.CreateFramePool()
framePool.creationFunc = ref.creationFunc
framePool.resetterFunc = ref.resetterFunc
return framePool
end
end
MapPinPool.create = function()
local framePool = CreateFramePool(MapPinPool)
return framePool
end
-- Create the Frame with the Frame Pool.
--
-- Because you cannot pass the pin data to the Frame Pool when acquiring a frame,
-- the frame is given a "render" function that can be used to bind the corect data
-- to the frame
MapPinPool.creationFunc = function(framePool)
local f = CreateFrame("Button", nil, UIParent,
BackdropTemplateMixin and "BackdropTemplate")
-- Styling
f:SetBackdrop({
bgFile = addon.GetTexture("white_circle"),
insets = {left = 0, right = 0, top = 0, bottom = 0}
})
f:SetWidth(0)
f:SetHeight(0)
f:EnableMouse()
f:SetMouseClickEnabled(false)
f:Hide()
-- Active Step Indicator (A Target Icon)
f.inner = CreateFrame("Button", nil, f,
BackdropTemplateMixin and "BackdropTemplate")
f.inner:SetBackdrop({
bgFile = addon.GetTexture("map_active_step_target_icon"),
insets = {left = 0, right = 0, top = 0, bottom = 0}
})
f.inner:SetPoint("CENTER", 0, 0)
--f.inner:EnableMouse()
-- Text
f.text = f:CreateFontString(nil, "ARTWORK", "GameFontNormal")
f.text:SetTextColor(unpack(addon.colors.mapPins))
f.text:SetFont(addon.font, 14, "OUTLINE")
-- Renders the Pin with Step Information
f.render = function(self, pin, isMiniMapPin)
local element = pin.elements[1]
local step = element.step or pin.step
local icon = step.icon and step.icon:match("(|T.-:%d.*|t)")
local label = icon or element.label or step.index or "*"
self.activeObject = pin
local r = self.text:GetTextColor()
if r ~= addon.colors.mapPins[1] then
self.text:SetTextColor(unpack(addon.colors.mapPins))
end
if not icon and #pin.elements > 1 then
self.text:SetText(label .. "+")
elseif step.alternateIcon and #pin.elements > 1 then
icon = step.alternateIcon and step.alternateIcon:match("(|T.-:%d.*|t)") or icon
label = icon
self.text:SetText(label)
else
self.text:SetText(label)
end
self.text:Show()
if addon.settings.profile.mapCircle and not isMiniMapPin and not icon then
local size = math.max(self.text:GetWidth(), self.text:GetHeight()) + 8
self.inner:Show()
if step.active then
self:SetAlpha(1)
self:SetWidth(size + 3)
self:SetHeight(size + 3)
self:SetBackdropColor(0.0, 0.0, 0.0,
addon.settings.profile.worldMapPinBackgroundOpacity)
self.inner:SetBackdropColor(1, 1, 1, 1)
self.inner:SetWidth(size + 3)
self.inner:SetHeight(size + 3)
self.text:SetFont(addon.font, 14, "OUTLINE")
else
self:SetBackdropColor(0.1, 0.1, 0.1,
addon.settings.profile.worldMapPinBackgroundOpacity)
self:SetWidth(size)
self:SetHeight(size)
self.inner:SetBackdropColor(0, 0, 0, 0)
self.text:SetFont(addon.font, 9, "OUTLINE")
end
self.inner:SetPoint("CENTER", self, 0, 0)
self.inner:SetWidth(size)
self.inner:SetHeight(size)
self.text:SetPoint("CENTER", self, 0, 0)
self:SetScale(addon.settings.profile.worldMapPinScale)
self:SetAlpha(pin.opacity)
else
--print('s3',GetTime())
self.inner:Hide()
if icon then
self:SetBackdropColor(0, 0, 0, 0)
self.text:SetFont(addon.font, 16, "OUTLINE")
local x,y = icon:match("|T.-:(%d+):?(%d*)")
x,y = tonumber(x), tonumber(y)
x = x > 0 and x or 16
y = y or 16
self:SetSize(x,y)
self.text:SetPoint("CENTER", self, 1, 0)
elseif step.active and not isMiniMapPin then
self:SetBackdropColor(0.0, 0.0, 0.0,
addon.settings.profile.worldMapPinBackgroundOpacity)
self.text:SetFont(addon.font, 14, "OUTLINE")
self:SetWidth(self.text:GetStringWidth() + 3)
self:SetHeight(self.text:GetStringHeight() + 5)
self.text:SetPoint("CENTER", self, 1, 0)
else
local bgAlpha = isMiniMapPin and 0 or
addon.settings.profile.worldMapPinBackgroundOpacity
self:SetBackdropColor(0.1, 0.1, 0.1, bgAlpha)
self.text:SetFont(addon.font, 9, "OUTLINE")
self:SetWidth(self.text:GetStringWidth() + 3)
self:SetHeight(self.text:GetStringHeight() + 5)
self.text:SetPoint("CENTER", self, 1, 0)
end
local radius = element.radius
if element.activationRadius and element.wx == element.xref and element.wy == element.yref then
radius = element.activationRadius
end
if step.active and addon.settings.profile.debug and radius and not isMiniMapPin then
radius = math.abs(radius)
local zone = _G.WorldMapFrame:GetMapID()
local w,h = HBD:GetZoneSize(zone)
local canvas = _G.WorldMapFrame:GetCanvas()
local scale = canvas:GetScale()
--local a,b = WorldMapFrame.ScrollContainer:GetCurrentZoomRange()
radius = radius * 2 * scale
local x,y = radius/w,radius/h
local width = canvas:GetWidth() * x
local height = canvas:GetHeight() * y
self:SetWidth(width)
self:SetHeight(height)
self:SetBackdropColor(0.1, 0.1, 0.1, 0.5)
end
self:SetScale(addon.settings.profile.worldMapPinScale)
self:SetAlpha(pin.opacity)
end
-- Mouse Handlers
self:SetScript("OnEnter", PinOnEnter)
self:SetScript("OnLeave", PinOnLeave)
end
return f
end
-- Hides and disables the Frame when it is released
MapPinPool.resetterFunc = function(framePool, frame)
frame:SetHeight(0)
frame:SetWidth(0)
frame:Hide()
frame:EnableMouse(0)
frame.currentPin = nil
end
MapLinePool.create = function()
local framePool = CreateFramePool(MapLinePool)
return framePool
end
-- Create the Frame with the Frame Pool.
--
-- Because you cannot pass the pin data to the Frame Pool when acquiring a frame,
-- the frame is given a "render" function that can be used to bind the corect data
-- to the frame
MapLinePool.creationFunc = function(framePool)
local f = CreateFrame("Button", nil, _G.WorldMapFrame:GetCanvas());
f.line = f.line or f:CreateLine();
local border = f.border or f:CreateLine();
border:SetColorTexture(0, 0, 0, 1);
f.border = border
f.render = function(self, coords)
if coords.lineAlpha == 0 then
self:Hide()
return
end
f.activeObject = self
local thickness = coords.linethickness or 2
local alpha = coords.lineAlpha or 1
self:SetAlpha(alpha)
local canvas = _G.WorldMapFrame:GetCanvas()
local width = canvas:GetWidth()
local height = canvas:GetHeight()
-- print(width,height)
local sX, fX, sY, fY = coords.sX * width / 100, coords.fX * width / 100,
coords.sY * height / -100,
coords.fY * height / -100
local lineWidth = abs(sX - fX) + thickness * 4
local lineHeight = abs(sY - fY) + thickness * 4
self:SetWidth(lineWidth);
self:SetHeight(lineHeight);
local xAnchor = max(sX, fX) - thickness * 2 - lineWidth / 2
local yAnchor = min(sY, fY) + thickness * 2 + lineHeight / 2
local line = self.line
line:SetDrawLayer("OVERLAY", -5)
line:SetStartPoint("TOPLEFT", sX - xAnchor, sY - yAnchor)
line:SetEndPoint("TOPLEFT", fX - xAnchor, fY - yAnchor)
line:SetColorTexture(unpack(addon.colors.mapPins))
--line:SetTexture('interface/buttons/white8x8')
line:SetThickness(thickness);
local lborder = self.border
lborder:SetDrawLayer("OVERLAY", -6)
lborder:SetStartPoint("TOPLEFT", sX - xAnchor, sY - yAnchor)
lborder:SetEndPoint("TOPLEFT", fX - xAnchor, fY - yAnchor)
lborder:SetThickness(thickness + 2);
lborder:SetAlpha(0.5)
self:SetParent(canvas)
self:SetFrameStrata(canvas:GetFrameStrata())
self:SetFrameLevel(2010)
--self:SetFrameStrata("FULLSCREEN_DIALOG")
-- self:SetFrameLevel(3000)
self:SetPoint("TOPLEFT", canvas, "TOPLEFT", xAnchor, yAnchor)
self:EnableMouse(true)
-- self:Show()
f:SetScript("OnEnter",PinOnEnter)
f:SetScript("OnLeave", PinOnLeave)
--local _,_,px,py = line:GetStartPoint()
--print('ok',coords.sX,coords.sY,';',coords.fX,coords.fY,'+',_G.WorldMapFrame:GetMapID())
--print(width,height)
end
return f
end
-- Hides and disables the Frame when it is released
MapLinePool.resetterFunc = function(framePool, frame)
frame:SetHeight(0)
frame:SetWidth(0)
frame:Hide()
frame:EnableMouse(0)
frame.step = nil
frame.zone = nil
frame.lineData = nil
frame.activeObject = nil
end
worldMapFramePool = MapPinPool.create()
miniMapFramePool = MapPinPool.create()
lineMapFramePool = MapLinePool.create()
-- Calculates if a given element is close to any other provided pins
local function elementIsCloseToOtherPins(element, pins, isMiniMapPin)
local overlap = addon.settings.profile.distanceBetweenPins or 1
local pinDistanceMod, pinMaxDistance = 0, 0
if isMiniMapPin then
pinMaxDistance = 25
else
pinDistanceMod = 5e-5 * overlap ^ 2
pinMaxDistance = 60 * overlap
end
for i, pin in ipairs(pins) do
for j, pinElement in ipairs(pin.elements) do
if not (pinElement.hidePin or element.hidePin) then
local relativeDist, dist, dx, dy
--if element.instance == pinElement.instance then
dist, dx, dy = HBD:GetWorldDistance(pinElement.instance,
pinElement.wx,
pinElement.wy,
element.wx, element.wy)
--end
if not isMiniMapPin then
local zx, zy = HBD:GetZoneSize(pin.zone)
if dx ~= nil and zx ~= nil then
relativeDist = (dx / zx) ^ 2 + (dy / zy) ^ 2
end
if (relativeDist and relativeDist < pinDistanceMod) or
(dist and dist < pinMaxDistance) then
return true, pin
end
elseif dist and dist < pinMaxDistance then
return true, pin
end
end
end
end
return false
end
local lsh = bit.lshift
local function GetPinHash(x,y,instance,element,step)
local n = step and step.index or 0
return ((instance + n) % 256) + lsh(math.floor(x*128),8) +
lsh(math.floor(y*1024),15) + lsh((element % 128),25)
end
-- Creates a list of Pin data structures.
--
-- All of the filtering and combining of steps and elements by proximity
-- is done in this step up front. Then the pins are rendered as WoW Frames
-- using the MapPinPool.
local function generatePins(steps, numPins, startingIndex, isMiniMap)
local pins = {}
if addon.currentGuide.empty then return pins end
local numActivePins = 0
local numSteps = #steps
local activeSteps = addon.RXPFrame.activeSteps
local numActive = 0
local function GetNumPins(step)
if step then
for _, element in pairs(step.elements) do
if element.zone and element.wx and not element.hidePin then
numActive = numActive + 1
end
end
end
end
for _, step in pairs(activeSteps) do GetNumPins(step) end
for i = RXPCData.currentStep + 1, RXPCData.currentStep + numPins do
local step = addon.currentGuide.steps[i]
GetNumPins(step)
if step and step.centerPins then
numActive = numActive + #step.centerPins
end
end
if numPins < numActive then numPins = numActive end
-- Loop through the steps until we create the number of pins a user
-- configures or until we reach the end of the current guide.
local function ProcessMapPin(step,ignoreCounter)
if not step then return end
-- Loop through the elements in each step. Again, we check if we
-- already created enough pins, then we check if the element
-- should be included on the map.
--
-- If it should be, we calculate whether the element is close to
-- other pins. If it is, we add the element to a previous pin.
--
-- If it is far enough away, we add a new pin to the map.
local j = 1;
local n = 0;
local nCenter = step.centerPins and #step.centerPins or 0
--print('cp',#step.centerPins)
local nElements = #step.elements
while (numActivePins < numPins or j <= nCenter or ignoreCounter) and j <= nElements + nCenter do
local element
if j > nCenter then
element = step.elements[j-nCenter]
else
element = step.centerPins[j]
--print('c1',element.x,element.y)
end
local skipWp = not(element.zone and element.x)
if not element.wpHash and not skipWp then
element.wpHash = GetPinHash(element.x,element.y,element.zone,n,step)
n = n + 1
end
if not isMiniMap and step.active and not skipWp then
local wpList = RXPCData.completedWaypoints[step.index or "tip"] or {}
skipWp = wpList[element.wpHash] or element.skip
wpList[element.wpHash] = skipWp
RXPCData.completedWaypoints[element.step.index or "tip"] = wpList
end
if element.text and not element.label and not element.textOnly then
element.label = tostring(step.index or "*")
end
if not skipWp and
(not (element.parent and
(element.parent.completed or element.parent.skip)) and
not element.skip) then
if not element.hidePin then
local closeToOtherPin, otherPin =
elementIsCloseToOtherPins(element, pins, isMiniMap)
if closeToOtherPin and not element.hidePin then
table.insert(otherPin.elements, element)
else
local pinalpha = 0
if isMiniMap then
pinalpha = 0.8
elseif element.step and element.step.active then
pinalpha = 1
else
pinalpha = math.max(0.4, 1 - (#pins * 0.05))
end
table.insert(pins, {
elements = {element},
opacity = pinalpha,
instance = element.instance,
wx = element.wx,
wy = element.wy,
zone = element.zone,
parent = element.parent,
wpHash = element.wpHash,
source = element,
})
end
end
if not isMiniMap then
table.insert(addon.activeWaypoints, element)
end
if not element.hidePin then
numActivePins = numActivePins + 1
end
end
j = j + 1
end
end
for _, step in pairs(activeSteps) do ProcessMapPin(step) end
if not isMiniMap then
local currentStep = steps[RXPCData.currentStep]
if (currentStep and not currentStep.active) then
ProcessMapPin(currentStep)
end
local i = 0;
while numActivePins < numPins and (startingIndex + i < numSteps) do
i = i + 1
local step = steps[startingIndex + i]
ProcessMapPin(step)
end
end
addon:ProcessGeneratedSteps(ProcessMapPin,true)
return pins
end
local function generateLines(steps, numPins, startingIndex, isMiniMap)
local pins = {}
if addon.currentGuide.empty then return pins end
local numActivePins = 0
local numSteps = #steps
local activeSteps = addon.RXPFrame.activeSteps
local numActive = 0
local function GetNumPins(step)
if step then
for _, element in pairs(step.elements) do
if element.zone and (element.segments) then
numActive = numActive + 1
end
end
end
end
for _, step in pairs(activeSteps) do GetNumPins(step) end
for i = RXPCData.currentStep + 1, RXPCData.currentStep + numPins do
GetNumPins(addon.currentGuide.steps[i])
end
numPins = math.max(numPins, numActive)
-- Loop through the steps until we create the number of pins a user
-- configures or until we reach the end of the current guide.
local function ProcessLine(step,ignoreCounter)
if not step then return end
step.centerPins = {}
local function InsertLine(element, sX, sY, fX, fY, lineAlpha)
local thickness = tonumber(element.step and step.linethickness)
table.insert(pins, {
element = element,
zone = element.zone,
sX = sX,
sY = sY,
fX = fX,
fY = fY,
lineAlpha = lineAlpha,
linethickness = thickness or element.thickness --or 3
})
end
local centerX, centerY, nEdges = 0,0,0
local j = 1
local n = 0
local function AddPoint(x,y,element,flags,...)
local wx, wy, instance =
HBD:GetWorldCoordinatesFromZone(x/100, y/100,
element.zone)
local point = {
x = x,
y = y,
wx = wx,
wy = wy,
instance = instance,
zone = element.zone,
anchor = element,
range = element.range,
generated = flags,
step = step,
source = element,
parent = element.parent,
mapTooltip = element.mapTooltip,
}
point.wpHash = GetPinHash(x,y,element.zone,n,step)
n = n + 1
local tableList = {...}
for _,tbl in pairs(tableList) do
table.insert(tbl, point)
end
end
while (numActivePins < numPins or ignoreCounter) and j <= #step.elements do
local element = step.elements[j]
local flags = element.bigLoop and 3 or 1
local nPoints = element.segments and
math.floor(#element.segments / 2)
local nSegments = element.segments and #element.segments
if element.zone and nPoints and
(not (element.parent and
(element.parent.completed or element.parent.skip)) and
not element.skip) then
for i = 1, nPoints * 2, 2 do
local sX = (element.segments[i])
local sY = (element.segments[i + 1])
local fX,fY
if element.connectPoints then
fX = (element.segments[(i + 1) % nSegments + 1])
fY = (element.segments[(i + 2) % nSegments + 1])
else
fX = element.segments[i + 2]
fY = element.segments[i + 3]
end
if sX and sY and fX and fY then
if sX < 0 and sY < 0 then
-- Dashed line if start x/y coordinates are negative
sX, sY, fX, fY = math.abs(sX), math.abs(sY),
math.abs(fX), math.abs(fY)
centerX = centerX + sX
centerY = centerY + sY
nEdges = nEdges + 1
-- local distMod = 1.75
local length = math.sqrt(
(fX - sX) ^ 2 + (fY - sY) ^ 2) *
1.75
if length > 1 then
local nSegments = math.floor(length)
local xinc = (fX - sX) / length
local yinc = (fY - sY) / length
local xpos, ypos = sX, sY
for k = 1, nSegments do
local endx = xpos + xinc
local endy = ypos + yinc
local alpha = bit.band(k, 0x1)
if alpha > 0 then
InsertLine(element, xpos, ypos, endx,
endy, alpha)
end
xpos = endx
ypos = endy
end
end
else
sX, sY, fX, fY = math.abs(sX), math.abs(sY),
math.abs(fX), math.abs(fY)
centerX = centerX + sX
centerY = centerY + sY
nEdges = nEdges + 1
InsertLine(element, sX, sY, fX, fY, element.lineAlpha or 1)
end
if element.showArrow and step.active then
AddPoint(sX,sY,element,flags,addon.linePoints,addon.activeWaypoints)
end
end
end
if element.drawCenterPoint and step.active and centerX ~= 0 and centerY then
centerX = centerX/nEdges
centerY = centerY/nEdges
AddPoint(centerX,centerY,element,flags,step.centerPins)
end
end
j = j + 1
end
end
for _, step in pairs(activeSteps) do ProcessLine(step) end
if not isMiniMap then
local currentStep = steps[RXPCData.currentStep]
if not (currentStep and currentStep.active) then
ProcessLine(currentStep)
end
local i = 0;
while numActivePins < numPins and (startingIndex + i < numSteps) do
i = i + 1
local step = steps[startingIndex + i]
ProcessLine(step)
end
addon:ProcessGeneratedSteps(ProcessLine,true)
end
return pins
end
-- Generate pins using the current guide's steps, then add the pins to the world map
local function addWorldMapPins()
if addon.settings.profile.numMapPins == 0 then return end
-- Calculate which pins should be on the world map
local pins = generatePins(addon.currentGuide.steps, addon.settings.profile.numMapPins,
RXPCData.currentStep, false)
-- Convert each "pin" data structure into a WoW frame. Then add that frame to the world map
if IsInInstance() then return end
for i = #pins, 1, -1 do
local pin = pins[i]
if not pin.hidePin then
local element = pin.elements[1]
local worldMapFrame = worldMapFramePool:Acquire()
worldMapFrame:render(pin, false)
local map = element.step and element.step.map and (addon.GetMapId(element.step.map) or tonumber(element.step.map))
local x,y
--if pin.generated then print('f',element.generated) end
if map then
x,y = HBD:GetZoneCoordinatesFromWorld(element.wx, element.wy, map)
else
x = element.x/100
y = element.y/100
map = element.zone
end
HBDPins:AddWorldMapIconMap(addon, worldMapFrame, map, x, y,
_G.HBD_PINS_WORLDMAP_SHOW_CONTINENT)
local subzones = addon.GetSubZones(map)
if subzones then
for _,subzone in pairs(subzones) do
--print(subzone)
local x,y = HBD:GetZoneCoordinatesFromWorld(element.wx, element.wy, subzone, true)
if x and y and not(x < 0 or y < 0 or x > 1 or y > 1) then
local worldMapFrame = worldMapFramePool:Acquire()
worldMapFrame:render(pin, false)
HBDPins:AddWorldMapIconMap(addon, worldMapFrame, subzone, x, y)
end
end
end
end
end
end
local function addWorldMapLines()
local lineData = generateLines(addon.currentGuide.steps, addon.settings.profile.numMapPins,
RXPCData.currentStep, false)
if #lineData > 0 then
local canvas = _G.WorldMapFrame:GetCanvas()
local width = canvas:GetWidth()
local height = canvas:GetHeight()
if width == 0 or height == 0 then
WorldMapFrame:Show()
WorldMapFrame:Hide()
end
end
for i = #lineData, 1, -1 do
local line = lineData[i]
local element = line.element
local step = element.step
local lineFrame = lineMapFramePool:Acquire()
lineFrame.lineData = line
lineFrame.step = step
lineFrame.zone = element.zone
lineFrame:render(line, false)
end
end
-- Generate pins using only the active steps, then add the pins to the Mini Map
local function addMiniMapPins(pins)
if addon.settings.profile.hideMiniMapPins then return end
-- Calculate which pins should be on the mini map
local pins = generatePins(addon.currentGuide.steps, addon.settings.profile.numMapPins,
RXPCData.currentStep, true)
-- Convert each "pin" data structure into a WoW frame. Then add that frame to the mini map
if IsInInstance() then return end
for i = #pins, 1, -1 do
local pin = pins[i]
local element = pin.elements[1]
if element and element.x then
local miniMapFrame = miniMapFramePool:Acquire()
miniMapFrame:render(pin, true)
local step = element.step
HBDPins:AddMinimapIconMap(addon, miniMapFrame, element.zone,
element.x / 100, element.y / 100, true, not (step and step.hideMinimap))
end
end
end
local corpseWP = { title = L"Corpse", generated = 1, wpHash = 0 }
local function IsDeathSkip()
if not addon.SpiritHealerWorld then return false end
for _, step in pairs(addon.RXPFrame.activeSteps) do
if step.elements then
for _, element in pairs(step.elements) do
if element.tag == "deathskip" then
return true
end
end
end
end
end
local function updateArrowData()
local lowPrioWPs
local loop = {}
local isDeathSkip = IsDeathSkip()
local HBD = LibStub("HereBeDragons-2.0")
local function ProcessWaypoint(element, lowPrio, isComplete)
if element.hidden then
return
elseif element.lowPrio and not lowPrio then
table.insert(lowPrioWPs, element)
return
end
local step = element.step or {}