forked from Hydra9268/ZGESO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pointer.lua
1532 lines (1245 loc) · 45.9 KB
/
Pointer.lua
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 ZGV=ZygorGuidesViewer
if not ZGV then return end
local GPS = LibGPS2
MEMORYSPAM=false
local Pointer = {}
ZGV.Pointer = Pointer
local _G,assert,table,string,tinsert,tonumber,tostring,type,ipairs,pairs,setmetatable,math,abs,ceil = _G,assert,table,string,table.insert,tonumber,tostring,type,ipairs,pairs,setmetatable,math,abs,ceil
local min,max = math.min,math.max
local wipe=function(tab) for k,v in pairs(tab) do tab[k]=nil end end
local L=ZGV.L
local print = d
local BZL=ZGV.BZL
local BZR=ZGV.BZR
local CHAIN = ZGV.Utils.ChainCall
Pointer.nummanual = 0
Pointer.antphase=0
Pointer.waypoints = {}
Astrolabe = {}
local profile={}
local unusedMarkers = {}
local last_distance=0
local speed=0
local last_speed=0
local lastminimapdist=99999
local minimapcontrol_suspension=0
local minimap_lastset = 0
local cuedinged=nil
local submap_cache = nil
local GetMapNameByID --defined later
function Pointer:GetMapTex()
local tex = GetMapTileTexture()
return tex and tex:match(".*/(.-)_%d+.dds") or tex
end
local MapFloorCountCache
function ZGV:SanitizeMapFloor(map,flr)
do return map,flr end
end
Pointer.MapFloors = {} setmetatable(Pointer.MapFloors,{__index=function(self,id) return rawget(self,id) or 0 end})
function Pointer:Startup()
self:InitMaps()
self:SetArrowSkin(profile.arrowskin) -- stub for now
if self.ArrowFrame then
CHAIN(self.ArrowFrame)
:ClearAllPoints()
:SetHandler("OnMoveStop", function(me)
local isValidAnchor, point, relativeTo, relativePoint, offsetX, offsetY = me:GetAnchor()
if isValidAnchor then
ZGV.db.profile.arrowanchor = {
point,
relativeTo:GetName(), -- Can not store userdata. Just put a string in and it will be forced to GuiRoot when setting
relativePoint,
offsetX,
offsetY
}
end
end)
Pointer:UpdateArrowPosition()
end
self:UpdateArrowVisibility()
self.ready = true
end
function Pointer:UpdateArrowPosition()
local DEFAULT_ANCHOR = { -- Set point using Top so that goals grow downward properly
BOTTOM,
ZGV.Viewer.name,
TOP,
0,
-50,
}
ZGV.db.profile.arrowanchor = ZGV.db.profile.arrowanchor and #ZGV.db.profile.arrowanchor==5 and ZGV.db.profile.arrowanchor or DEFAULT_ANCHOR
local point, relativeTo, relativePoint, offsetX, offsetY = unpack(ZGV.db.profile.arrowanchor)
relativeTo = (relativeTo=="GuiRoot" and GuiRoot) or (relativeTo==ZGV.Viewer.name and ZGV.Frame)
self.ArrowFrame:ClearAllPoints()
self.ArrowFrame:SetPoint(point, relativeTo, relativePoint, offsetX, offsetY)
end
function Pointer:ResetWaypointerSettings()
local opt_group = ZGV.Settings:GetOptionGroupByName("arrow")
opt_group:SetToDefault() -- Set all options in our setting menu to default.
ZGV.db.profile.arrowanchor = nil
self:UpdateArrowPosition()
end
__CLASS = __CLASS or {}
Pointer.Icons = {
default = "ESOdot",
ESOdot = { icon=ZGV.DIR.."/Arrows/Stealth/arrow-error.dds", size=40, minisize=25, rotates=false, edgeicon=ZGV.DIR.."\\Skins\\minimaparrow-green-edge", edgesize=60, spinner=true, onminimap=always },
greendot = { icon=ZGV.DIR.."\\Skins\\minimaparrow-green-dot", size=40, minisize=25, rotates=false, edgeicon=ZGV.DIR.."\\Skins\\minimaparrow-green-edge", edgesize=60, spinner=true, onminimap=always },
graydot = { icon=ZGV.DIR.."\\Skins\\minimaparrow-green-dot", size=40, minisize=25, rotates=false, edgeicon=ZGV.DIR.."\\Skins\\minimaparrow-green-edge", edgesize=60, spinner=true, desat=1, onminimap=always },
arrow = { icon=ZGV.DIR.."\\Skins\\minimaparrow-path", size=70, minisize=60, rotates=true, edgeicon=ZGV.DIR.."\\Skins\\minimaparrow-path", edgesize=50 },
ant = { icon=ZGV.DIR.."\\Skins\\minimaparrow-ant", alpha=0.8, size=30, minisize=25, rotates=false, edgeicon=nil, edgesize=1 },
ant_g = { icon=ZGV.DIR.."\\Skins\\minimaparrow-ant", r=0.4, g=1, b=0, alpha=0.8, size=30, minisize=25, rotates=false, edgeicon=nil, edgesize=1 },
ant_b = { icon=ZGV.DIR.."\\Skins\\minimaparrow-ant", r=0, g=0.7, b=1, alpha=0.8, size=30, minisize=25, rotates=false, edgeicon=nil, edgesize=1 },
ant_p = { icon=ZGV.DIR.."\\Skins\\minimaparrow-ant", r=0.8, g=0.3, b=1, alpha=0.8, size=30, minisize=25, rotates=false, edgeicon=nil, edgesize=1 },
ant_y = { icon=ZGV.DIR.."\\Skins\\minimaparrow-ant", r=1, g=0.8, b=0, alpha=0.8, size=30, minisize=25, rotates=false, edgeicon=nil, edgesize=1 },
none = { icon="", alpha=0.0, size=1, minisize=1, rotates=false, edgeicon=nil, edgesize=1 },
ant_g_default = { r=0.4, g=1, b=0, alpha=0.8 },
ant_b_default = { r=0, g=0.7, b=1, alpha=0.8 },
ant_p_default = { r=0.8, g=0.3, b=1, alpha=0.8 },
ant_y_default = { r=1, g=0.8, b=0, alpha=0.8 },
ant_default = { r=1, g=1, b=1, alpha=0.8 },
}
setmetatable(Pointer.Icons,{__index=function(k) return Pointer.Icons[Pointer.Icons.default] end})
for k,v in pairs(Pointer.Icons) do if type(v)=="table" then __CLASS[v]="PointerIcon_"..k end end
-- SPECIAL setwaypoint, optimized for ants
local icons=Pointer.Icons
local tmp_data = {}
local function add_default_data(data)
tmp_data = {}
for k,v in pairs(data) do tmp_data[k]=v end
if not tmp_data.type then tmp_data.type="way" end
if not tmp_data.icon then tmp_data.icon=Pointer.Icons[Pointer.Icons.default] end
return tmp_data
end
function Pointer:SetWaypoint (m,f,x,y,data,arrow)
local data = add_default_data(data or {}) -- Clone! so this is tmp_data from above, basically.
if data.cleartype and data.type then self:ClearWaypoints(data.type) end
local tx,ty=Pointer:TranslateCoords(m,x,y,self:GetMapTex())
if tx and ty then
PingMap(88,MAP_TYPE_LOCATION_CENTERED,tx,ty)
else
RemovePlayerWaypoint()
end
if not m then
SetMapToPlayerLocation() ZO_WorldMap_UpdateMap() -- hey we trashed it already... why not just be obvious.
m,f = self:GetMapTex(),0
else
--m=self:SanitizePhase(m) -- de-phase map!
end
local waypoint = self:GetMapMarker (m,f or 0,x,y,data)
if not waypoint then return end
waypoint.title=data.arrowtitle or data.title or ("%s %d,%d"):format(Pointer.Zones[waypoint.m].name,waypoint.x*100,waypoint.y*100)
waypoint:SetIcon(waypoint.icon)
if waypoint.type=="manual" then
self.nummanual = self.nummanual + 1
end
tinsert(self.waypoints,waypoint)
if arrow==nil then arrow=true end
if arrow and (waypoint.type=="manual" or waypoint.type=="way" or waypoint.type=="route" or waypoint.type=="corpse") then
self:ShowArrow(waypoint)
end
if data.findpath then
self:FindTravelPath(waypoint)
end
return waypoint
end
function Pointer:ShowWaiting(phase)
self.ArrowFrame.WaitingPhase = phase
end
function Pointer:GetMapMarker (m,f,x,y,data)
if not m and not f then
m,f = self:GetMapTex(),0
end
if not m or not f or not x or not y then
Pointer:Debug("GetMapMarker bailing out; map=%s/%d %.2f %.2f",m,f or -1,x or -99,y or -99)
return
end
local waypoint = self:GetUnusedMarker()
waypoint.m = m
waypoint.f = f
waypoint.x = x
waypoint.y = y
ZGV.Utils.table_join(waypoint,data)
return waypoint
end
local dont_setwaypoint=false
function Pointer:ClearWaypoints (waytype)
Pointer:Debug("ClearWaypoints %s",waytype or "all?")
local n=0
local w=1
dont_setwaypoint=true
while w<=#self.waypoints do
if not waytype or self.waypoints[w].type==waytype then
n=n+1
self:RemoveWaypoint(w)
else
w=w+1
end
end
dont_setwaypoint=false
return n
end
function Pointer:RemoveWaypoint(waypoint)
local wayn
if type(waypoint)=="number" then wayn=waypoint waypoint=self.waypoints[wayn] end
if not waypoint then return end -- let's just play nice --assert(waypoint,"Waypoint not found")
assert(__CLASS[waypoint]=="Waypoint")
if not wayn and type(waypoint)=="table" then for w=1,#self.waypoints do if self.waypoints[w]==waypoint then wayn=w end end end
if not wayn then return end -- let's just play nice assert(wayn,"No waypoint number found")
if waypoint.type=="manual" then
self.nummanual = max(0,self.nummanual - 1)
end
if waypoint.in_set then self:RemoveWaypointFromSets(waypoint) end
if self.ArrowFrame.waypoint==waypoint then self:HideArrow() end
if self.DestinationWaypoint==waypoint then
Pointer:Debug("Removed DestinationWaypoint")
self.DestinationWaypoint=nil self.TempWaypath=nil
end
for k,v in pairs(waypoint) do if not k:match(".+Frame") then waypoint[k]=nil end end
unusedMarkers[waypoint]=1
table.remove(self.waypoints,wayn)
end
function Pointer:RemoveWaypointFromSets(waypoint)
local set = self.pointsets[waypoint.in_set]
if not set then return end
for pi,point in ipairs(set.points) do if point==waypoint then tremove(set,pi) return end end
end
function Pointer:HideArrow()
self.ArrowFrame.waypoint = nil
end
function Pointer:ShowArrow(waypoint)
self.initialdist = nil
if not waypoint then return self:HideArrow() end
assert(__CLASS[waypoint]=="Waypoint")
self.ArrowFrame.waypoint = waypoint
self.ArrowFrame.WaitingPhase = nil
last_distance = 0
speed = 0
-- Adjusting the speed between zone maps and non-zone maps
if (GetCurrentMapIndex() == nil) then
lastbeeptime = GetTimeStamp() + 3
else
lastbeeptime = GetGameTimeMilliseconds() + 250
end
cuedinged = nil
lastminimapdist = 99999
local tx,ty=Pointer:TranslateCoords(waypoint.m,waypoint.x,waypoint.y,self:GetMapTex())
if tx and ty then
PingMap(88,MAP_TYPE_LOCATION_CENTERED,tx,ty)
end
end
local markerproto = {}
local markermeta = {__index=markerproto}
local nummarkers=0
function Pointer:MakeMarkerFrames(marker,type)
setmetatable(marker,markermeta)
type=type or "Marker"
return marker
end
function Pointer:GetUnusedMarker()
local marker = next(unusedMarkers)
if marker then
unusedMarkers[marker]=nil
return marker
end
-- create a new marker
nummarkers=nummarkers+1
marker = self:MakeMarkerFrames({visible=true})
__CLASS[marker]="Waypoint"
return marker
end
function markerproto:Hide()
self.minimapFrame:Hide()
self.worldmapFrame:Hide()
self.taximapFrame:Hide()
self.visible = false
end
function markerproto:Show()
self.minimapFrame:Show()
self.worldmapFrame:Show()
if TaxiFrame:IsShown() then self.taximapFrame:Show() end
self.visible = true
end
function markerproto:SetIcon(icon) -- leave icon empty to just reset the current icon
icon = icon or self.icon
self.icon = icon
end
local function FormatDistance(dist)
if not dist then return "" end
if ZGV.db.profile.arrowmeters then -- only metric!
local mdist = dist
if mdist > 1000 then
return L['dist_km']:format(mdist/1000)
else
return L['dist_m']:format(mdist)
end
else
local ydist = dist / 0.9144
if dist > 1760 then
return L['dist_mi']:format(dist / 1760)
else
return L['dist_yd']:format(dist)
end
end
end
ZGV.FormatDistance=FormatDistance
function Pointer:CreateArrowFrame()
if not self.ArrowFrameCtrl then
self.ArrowFrameCtrl = ZGESO_Pointer_ArrowCtrl
self.ArrowFrameCtrl:SetHandler("OnUpdate",self.ArrowFrameControl_OnUpdate)
end
if not self.CurrentArrowSkin then
self:SetArrowSkin(ZGV.db.profile.arrowskin)
end
self:SetupArrow()
end
function Pointer:SetupArrow()
if not self.CurrentArrowSkin then
self:Debug("No CurrentArrowSkin in SetupArrow")
return
end
self.ArrowFrame = CHAIN(self.CurrentArrowSkin:CreateFrame())
:SetHandler("OnClick",ZygorGuidesViewer.Pointer.ArrowFrame_OnClick)
-- freeze?
:SetMovable(not ZGV.db.profile.arrowfreeze)
:SetMouseEnabled(not ZGV.db.profile.arrowfreeze)
.__END
-- scale
local scale = ZGV.db.profile.arrowscale or 1.0
self.ArrowFrame:SetScale(scale)
-- opacity
self.ArrowFrame:SetAlpha(ZGV.db.profile.arrowalpha or 1.0)
-- font
self:SetFontSize(ZGV.db.profile.arrowfontsize or 12)
end
function Pointer:UpdateWaypoints()
do return end
-- worldmap updates only, so far
local m,f=GetCurrentMapAreaID(),GetCurrentMapDungeonLevel()
for w,way in ipairs(self.waypoints) do
way:UpdateWorldMapIcon(m,f)
way:UpdateMiniMapIcon(m,f)
way:UpdateTaxiMapIcon(m,f)
end
end
function Pointer:SetFontSize(size)
if not self.ArrowFrame then return end
self.ArrowFrame.title:SetFontSize(size)
end
function Pointer.WorldMapButton_OnMouseWheel(self,delta,...)
if ZGV.db.profile.debug then
self.waypoint.truesize = (self.waypoint.truesize or 50) * (delta>0 and 1.1 or 0.909090)
print(self.waypoint.truesize)
self.waypoint:SetIcon(Pointer.Icons.greendot)
end
end
function Pointer:IsCorpseArrowNeeded() -- small utility against bulky ifs, NB: waypointer-independent
return ZGV.db.profile.corpsearrow and UnitIsDeadOrGhost("player") and select(2, IsInInstance()) ~= "pvp" and not IsActiveBattlefieldArena()
end
------------------------------------------- ARROW -----------------
local arrowctrl_fps = 1/30
local arrowctrl_last=0
local forceupdate_fps = 3
local forceupdate_last = 0
local autosurvey_fps = 5
local autosurvey_last = 0
function Pointer.ArrowFrameControl_OnUpdate(self,msec)
if msec-arrowctrl_last >= arrowctrl_fps then
-- update skin IF WE HAVE ONE ON only
if Pointer.ArrowFrame then Pointer.ArrowFrame_OnUpdate_Common(Pointer.ArrowFrame,msec) end
arrowctrl_last=msec
end
-- unthrottled
if Pointer.ArrowFrame then
local icon=Pointer.ArrowFrame.ArrowIcon
if icon and icon:IsVisible() and not ZGV.Pointer.ArrowFrame:IsVisible() then Pointer.ArrowFrame_HideSpellArrow(self) end
end
-- update waypoints periodically, in case some get stuck on player-out-of-map,-go-away state
if msec-forceupdate_last >= forceupdate_fps then
Pointer:UpdateWaypoints()
forceupdate_last = msec
end
-- auto-surveyer
if Pointer.do_autosurvey then
if msec-autosurvey_last >= autosurvey_fps then
Pointer:SurveyMap("here",nil,not ZGV.DEV)
autosurvey_last = msec
end
end
end
-- And we have an onupdating frame even if hidden. Yay!
-- map perc as: t1..t2 to 0.0..0.5 t3..t4 to 0.5..1.0
function Pointer.CalculateDirectionTiers(perc,t1,t2,t3,t4)
if perc<t1 then return 0 , 1
elseif perc<t2 then return (perc-t1)/(t2-t1)*0.5 , 2
elseif perc<t3 then return 0.5 , 3
elseif perc<t4 then return ((perc-t3)/(t4-t3)*0.5) + 0.5 , 4
else return 1.0 , 5 end
end
local oldangle = 0
local title,disttxt,etatxt
local speeds={}
local stoptime=0
local avgspeed=0
local eta_elapsed=0
local etadisp_elapsed=0
-- local lastbeeptime=GetTimeStamp()
local lastbeeptime = GetGameTimeMilliseconds()
local lastturntime = lastbeeptime
local laststoptime = lastbeeptime
local lastmovetime = lastbeeptime
local msin,mcos,mabs=math.sin,math.cos,math.abs
local eta
function Pointer:GetDefaultStepDist()
return IsFlying("player") and 15 or 5
end
local pathfindlockout = 0
local function TableFind(table,val) -- unused, yeah
for k,v in pairs(table) do if v==val then return k end end
end
--- Find 2 values in a table
-- @return key1,key2
local function TableFind2(table,val1,val2)
local k1,k2
for k,v in pairs(table) do if v==val1 then k1=k end if v==val2 then k2=k end end
return k1 or -1,k2 or -1
end
-- For very specific crossing descriptions, see Localization/Core_enUS.lua, entries "pointer_floors_29_14_16" etc.
local function L_or_nil(id)
local l = L[id]
if l==id then return nil else return l end
end
function Pointer:GetDirectionToWaypoint(way)
local px,py = GetMapPlayerPosition("player")
local pmap = Pointer:GetMapTex()
local wx,wy,err = Pointer:TranslateCoords(way.m,way.x,way.y,pmap)
if pmap=="mundus_base" then return end --expected failure
if err then
return nil
end
if not (wx and wy) then return nil end
local dir = math.atan2(px-wx,py-wy)
return dir
end
local cache_throttle=0
local were_in_unknown_location
function Pointer.ArrowFrame_ShowSpellArrow(self,waypoint)
do return end
end
local noskip_time=0
local dummy_waypoint = {DUMMY=1}
-- /dump ZGV.Pointer:TranslateCoords("bleakrock_base_0",0.7,0.7,"bleakrockvillage_base_0")
-- /dump ZGV.Pointer:TranslateCoords("deshaan_base",.4053,.7517,"kragenmoor_base")
-- /dump ZGV.Pointer:GetDistToCoords("shimmerene_base",50.50,50.50,"shimmerenewaterworks01_base")
function Pointer:TranslateCoords(map1,x,y,map2)
if map1==map2 or not (map1 and map2) then return x,y end
if not x or not y then return nil,nil end
local Zones=self.Zones
local Z1=Zones[map1]
local Z2=Zones[map2]
if not Z1 then return nil,nil,map1.." unknown" end
if not Z2 then return nil,nil,map2.." unknown" end
if not Z1.scale then return nil,nil,map1.." not scaled" end
if not Z2.scale then return nil,nil,map2.." not scaled" end
if Z1.parentWorld~=Z2.parentWorld then return nil,nil,map1.." and "..map2.." don't share a parent" end
if Z1.noParent then return nil,nil,map1.." has no parent" end
if Z2.noParent then return nil,nil,map2.." has no parent" end
if not Z1.xoffset then return nil,nil,map1.." no X offset" end
if not Z2.xoffset then return nil,nil,map2.." no X offset" end
-- move to world coords
x=x*Z1.scale+Z1.xoffset
y=y*Z1.scale+Z1.yoffset
return (x-Z2.xoffset)/Z2.scale,(y-Z2.yoffset)/Z2.scale
end
--/dump ZGV.Pointer:GetDistToCoords(auridon_base,52.50,91.57)
--/dump ZGV.Pointer:GetDistToCoords(shimmerenewaterworks01_base,50.50,50.50)
--/dump ZGV.Pointer:TranslateCoords("auridon_base",52.50,91.57,"vulkhelguard_base")
function Pointer:GetDistToCoords(m,x,y)
local px,py = GetMapPlayerPosition("player")
local pmap = Pointer:GetMapTex()
local wx,wy = Pointer:TranslateCoords(m,x,y,pmap)
if not wx then return 9999999 end
wx = wx or x
wy = wy or y
local zone = self.Zones[pmap]
local scale = zone and zone.scale or .01
local di = wx and math.sqrt((px-wx)*(px-wx)+(py-wy)*(py-wy)) or 0
local parentWorld = zone and zone.parentWorld or "Tamriel"
local worldsize = ZGV.MapData.Zones[parentWorld].worldWidth or 10000
local dist = worldsize*(scale or 0)*di
return dist
end
function Pointer.ArrowFrame_OnUpdate_Common(self,elapsed)
-- NASTY. Replace master object, Indy Jones-style.
local ArrowFrame = self
self=Pointer
local safe = true
local waypoint = ArrowFrame.waypoint
if not waypoint
or not ZGV.db.profile.arrowshow
or GuiRoot:IsHidden()
or ( (not ZGV.Frame or ZGV.Frame:IsHidden()) and ZGV.db.profile.hidearrowwithguide and waypoint.type~="manual")
then
if safe then
ArrowFrame:Hide()
end
return
end
if safe then ArrowFrame:Show() end
-- adding icons over arrow for different types of teleports sequential digging in, safe and pretty fast
local icon = ArrowFrame.ArrowIcon
-- Handle spell icons
if icon then
if waypoint.pathnode and Pointer.ArrowFrame_ShowSpellArrow(ArrowFrame,waypoint) then
if MouseIsOver(icon) and IsMouseButtonDown("RightButton") then
Pointer.ArrowFrame_OnClick(nil,"RightButton") --***Is possible for it to not work if click goes up and down without OnUpdate running***
end
return
else
if safe then Pointer.ArrowFrame_HideSpellArrow(ArrowFrame) end
end
end
-- normal operation...
local dist,x,y
local errortxt
local dist = Pointer:GetDistToCoords(waypoint.m,waypoint.x,waypoint.y)
if were_in_unknown_location then
dist=nil
if WorldMapFrame:IsVisible() then
errortxt = L['pointer_close_map']
else
errortxt = "(current position unknown)"
end
end
dist=dist or 99999999 -- this means FAR or UNKNOWN or whatever. Causes "zone, continent" display.
self.curdist = dist
-- trigger rover update if we got 100yd away from current target (are we lost?)
if self.initialdist and ZGV.db.profile.pathfinding then
self.closingdist = min(self.initialdist,self.closingdist or 9999)
lastforcedupdate=lastforcedupdate or 0
if dist-self.closingdist>100 and GetTime()-lastforcedupdate>120 then
LibRover:UpdateNow(true)
lastforcedupdate = GetTime()
end
end
local show_stairs
local samemap=true --todo wtf workaround!
if samemap and waypoint and waypoint.f~=cf then
errortxt = nil --ESO: no need for GetPreciseFloorCrossingText(cm,cf,waypoint.f)
show_stairs = nil --We are trying to enter a cave, point to the location inside the cave
end
-- Safety measure, make sure self.badfloortxt is updated to reflect current surroundings
ArrowFrame.errortxt = errortxt
-- okay, we're live. 3, 2, 1, action!
if safe then ArrowFrame:Show() end
local playerangle = GetPlayerCameraHeading()
local angle=0
local going_up
if errortxt then
local plusminus,err2=errortxt:match("([+-])(.*)")
if plusminus then going_up=(plusminus=="+") and 1 or -1 errortxt=err2 end
end
-- ARRIVAL. MAJOR TODO.
if show_stairs then
if ArrowFrame.ShowStairs then ArrowFrame:ShowStairs(going_up) end -- wrong floor, omg
else
self.heretime=0
--[[ angle ]]--
if false and waypoint.actionicon then
if waypoint.actionicon=="upstairs" then ArrowFrame:ShowStairs(true)
elseif waypoint.actionicon=="downstairs" then ArrowFrame:ShowStairs(false)
end
showstairs=true -- after all!
else
angle = Pointer:GetDirectionToWaypoint(waypoint)
if not angle or errortxt=="far" then
angle = (GetGameTimeMilliseconds()/500)%6.283
else
angle = angle - playerangle
end
while angle<0 do angle=angle+6.28319 end
if profile.arrowsmooth and self.CurrentArrowSkin and self.CurrentArrowSkin.features.smooth then
local dif = angle-oldangle
if dif>0.001 or dif<0.001 then
while dif>3.14159 do dif=dif-6.28319 end
while dif<-3.14159 do dif=dif+6.28319 end
angle = angle-dif/(1+elapsed*20) --speed!
while angle>6.28319 do angle=angle-6.28319 end
while angle<0 do angle=angle+6.28319 end
end
oldangle=angle
end
ArrowFrame:ShowTraveling(elapsed,angle,dist)
end
end
-- Pointer:Debug(("dist %.2f chg %.2f speed %.2f ela %.2f"):format(dist,last_distance-dist,speed,eta_elapsed))
local limit,minlimit=30,5
eta_elapsed = eta_elapsed + elapsed
if eta_elapsed >= 0.2 then
if (self.pathfollow=="smart" or self.pathfollow=="loose" or self.pathfollow=="smart2")
and waypoint.type=="path" then
local nextway = self:GetNextInPath()
if nextway and type(nextway)=="table" and nextway~=waypoint then self:ShowArrow(nextway) end
end
speed = (last_distance-dist) / eta_elapsed
if last_distance == 0 then speed = 0 end
if last_distance==dist then stoptime=stoptime+eta_elapsed else stoptime=0 end
if speed>=0 and stoptime<2 then
table.insert(speeds,1,speed)
if #speeds>limit then table.remove(speeds) end
else
speed=0
ZGV.Utils.table_wipe(speeds)
end
if ZGV.db.profile.audiocues and IsFlying() then
local t=GetTime()
if lastplayerangle~=playerangle then lastturntime=t end
if GetUnitSpeed("player")==0 then laststoptime=t else lastmovetime=t end
if t-lastmovetime<=1 and t-laststoptime>3 and t-lastturntime>5 then
-- if flying, basically.
-- and beelining for the last 3 seconds.
if dist<=100 and not cuedinged then
PlaySoundFile("Sound\\Doodad\\BoatDockedWarning.wav")
cuedinged=true
else
end
-- warning beeps
if ArrowFrame.arrow:IsVisible() then
local perc = mabs(1-angle*0.3183) -- 1/pi
if perc<=0.9 then
if t-lastbeeptime>2 then
PlaySoundFile( [[Sound\Interface\RaidWarning.ogg]] )
if ArrowFrame.ShowWarning then ArrowFrame:ShowWarning() end
lastbeeptime=t
end
end
end
end
lastplayerangle=playerangle
end
last_distance = dist
eta_elapsed = 0
end
etadisp_elapsed = etadisp_elapsed + elapsed
if etadisp_elapsed >= 0.9 then
local avg=speed
for i=2,#speeds do avg=avg+speeds[i] end
avg=avg/max(#speeds,1)
if #speeds>=minlimit and avg>0 then
eta = math.abs(dist / avg)
else
local spd=1
eta = math.abs(dist / spd)
end
etadisp_elapsed = 0
end
-- spew it out.
ArrowFrame:ShowText(
waypoint.arrowtitle or waypoint.title,
dist,
eta,
errortxt)
end
-- The function! It does nothing!
function Pointer.ArrowFrame_Proto_ShowText(frame)
end
function Pointer.ArrowFrame_Proto_GetFarText(self)
local way = self.waypoint
local m = way.m or ""
return Pointer.Zones[m] and Pointer.Zones[m].name or "?"
end
function Pointer.ArrowFrame_Proto_GetDistTxt(self,dist)
if not dist or dist=="far" or (tonumber(dist or 0)>9999998) then return Pointer.ArrowFrame_Proto_GetFarText(self)
elseif type(dist)=="string" then return dist
else return ZGV.FormatDistance(dist)
end
end
local mfloor=math.floor
function Pointer.FormatTime(eta)
return ("%01d:%02d|r"):format(eta / 60, eta % 60)
end
function Pointer.ArrowFrame_Proto_GetETATxt(self,eta)
if eta and eta<7200 and eta>0 then
local etacolor = "ffbb00"
return (" |c".. etacolor .. Pointer.FormatTime(eta) .. "|r")
end
end
function Pointer.ArrowFrame_OnShow(frame)
lastturntime=GetTime()
end
function Pointer.ArrowFrame_OnClick(frame,button)
if ZGV.db.profile.arrowfreeze then return end -- how did we get the OnClick event, anyway?
if button=="LeftButton" then
if not frame.dragging then
ZGV:SetWaypoint()
end
elseif button=="RightButton" then
Pointer.ArrowFrame_ShowMenu()
end
end
function Pointer.ArrowFrame_SetAlpha(but,v)
ZGV:SetOption("Arrow","arrowalpha "..v)
end
function Pointer.ArrowFrame_SetScale(but,v)
ZGV:SetOption("Arrow","arrowscale "..v)
end
Pointer.ArrowSkins = {}
local function _new_skin(id,name)
local skin = {id=id or "skin", name=name or "unnamed skin",styles={} }
return skin
end
function Pointer:AddArrowSkin(id,name)
local skin = _new_skin(id,name)
self.ArrowSkins[id] = skin
return skin
end
function Pointer:GetSkinPath(skin)
if not skin then skin=ZGV.db.options.arrowskin end
return ZGV.DIR .. "\\Arrows\\" .. skin .. "\\"
end
function Pointer:SetArrowSkin(skin)
-- no style? grab default
if not skin then
skin = next(self.ArrowSkins)
assert(skin,"No arrow skin to fall back to!")
return self:SetArrowSkin(skin)
end
local skindata = self.ArrowSkins[skin]
if not skindata then
ZGV:Print("Unknown arrow skin '"..skin.."', falling back to default")
return self:SetArrowSkin()
end
-- remove old skin
local way
if self.CurrentArrowSkin then
way = self.ArrowFrame.waypoint
self.ArrowFrame:Hide()
end
ZGV.db.profile.arrowskin = skin
self.CurrentArrowSkin = skindata
self.ArrowSkinDir = self:GetSkinPath(skin,style)
self:CreateArrowFrame()
if not self.ArrowFrame then
d("CreateArrowFrame failed")
return
end
self.ArrowFrame.waypoint = way
end
function Pointer:UpdateArrowVisibility()
if not self.ArrowFrame then return end
if ZGV.db.profile.arrowshow then self.ArrowFrame:Show() else self.ArrowFrame:Hide() end
end
-- Access tables, actually fronts for using SV data for DEVs before hardcoded zone data before SV data again.
Pointer.ZoneNameToTex = {}
Pointer.Zones = {}
Pointer.GetMapNameByID2 = function(tex) return Pointer.Zones[tex] and Pointer.Zones[tex].name or "zone "..tostring(tex).."?" end
-- start with some cities hardcoded. That's mostly for testing before Data is loaded, or if that fails.
local function AddMap(name,tex)
if ZGV.MapData.ZoneNameToTex[name]~=tex then ZGV.MapData.ZoneNameToTex[name]=tex end
ZGV.MapData.Zones[tex] = ZGV.MapData.Zones[tex] or {}
ZGV.MapData.Zones[tex].name=name
end
-- Grab all ESO maps
function Pointer:InitMaps()
-- initialize saved data
ZGV.db.profile.Zones = ZGV.db.profile.Zones or {}
ZGV.db.profile.ZoneNameToTex = ZGV.db.profile.ZoneNameToTex or {}
if not ZGV.MapData then
ZGV.MapData={Zones={},ZoneNameToTex={}}
ZGV:Error("No Map Data. Please report this issue.")
end
(function()
if GetCVar("language.2")=="en" then return end
local mapdata_local = ZGV.MapData.LocalizedMapNames[GetCVar("language.2")]
if not mapdata_local then return end
local mapdata_en = ZGV.MapData.LocalizedMapNames['en']
for mapindex,mapname_local in pairs(mapdata_local) do
local mapname_en = mapdata_en[mapindex]
for maptex,mapdata in pairs(ZGV.MapData.Zones) do
if mapdata.name==mapname_en then mapdata.name=mapname_local end
end
end
end)()
-- These are in MapData anyway, they're here just to make sure unit tests are passed.
AddMap("Dhalmora","dhalmora_base")
AddMap("Bleakrock Village","bleakrockvillage_base")
AddMap("Malabal Tor","malabaltor_base")
ZGV.MapData.Zones["Tamriel"]=ZGV.MapData.Zones["Tamriel"] or {}
ZGV.MapData.Zones["Tamriel"].xoffset=0
ZGV.MapData.Zones["Tamriel"].yoffset=0
ZGV.MapData.Zones["Tamriel"].scale=1
ZGV.MapData.Zones["coldharbour_base"]=ZGV.MapData.Zones["coldharbour_base"] or {}
ZGV.MapData.Zones["coldharbour_base"].xoffset=0
ZGV.MapData.Zones["coldharbour_base"].yoffset=0
ZGV.MapData.Zones["coldharbour_base"].scale=1
ZGV.MapData.Zones["coldharbour_base"].parentWorld="coldharbour_base"
-- this probably shouldn't be accessed before it is initalized
Pointer.ZoneNameToTex = {}
Pointer.Zones = {}
setmetatable(Pointer.ZoneNameToTex,{
__index=function(z,key)
return (ZGV.DEV and ZGV.sv.profile.ZoneNameToTex[key])
or ZGV.MapData.ZoneNameToTex[key]
or ZGV.sv.profile.ZoneNameToTex[key]
end,
__newindex=function(z,key,val)
ZGV.sv.profile.ZoneNameToTex[key]=val
end}
)
function Pointer.Zones:GetAllMaps()
local ret = {SV={},Data={}}
for k,v in pairs(ZGV.sv.profile.Zones) do ret.SV[k]=v end
for k,v in pairs(ZGV.MapData.Zones) do ret.Data[k]=v end
return ret
end