/
worldmap.lua
executable file
·6715 lines (5661 loc) · 252 KB
/
worldmap.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 g_mapTileManager
local g_mapPinManager
local g_mapLocationManager
local g_mouseoverMapBlobManager
local g_keepNetworkManager
local g_ownsTooltip = false
local g_playerChoseCurrentMap = false
local g_resizingMap = false
local g_resizeIsWidthDriven
local g_savedVars
local g_fastTravelNodeIndex = nil
local g_queryType = BGQUERY_UNKNOWN
local g_campaignId = 0
local g_pendingKeepInfo
local g_keybindStrips = {}
local g_mapRefresh
local g_interactKeybindForceHidden = false
local g_questPingData = nil
--- The list of locals was at the absolute size limit of what Lua can handle
--- (any more and it was erroring with "too many registers" and "too complex".)
--- I put all the local constants in a single table to prevent this.
local CONSTANTS =
{
MAP_HEIGHT = 690,
MAP_WIDTH = 690,
MAP_MIN_SIZE = 200,
KEYBOARD_MAP_PADDING_Y_PIXELS = 30,
GAMEPAD_MAP_PADDING_Y_PIXELS = 75,
CENTER_OFFSET_Y_PIXELS = 9,
GAMEPAD_CENTER_OFFSET_Y_PIXELS = -10,
MAIN_MENU_AREA_Y = 120,
MAP_INFO_WIDTH = 425,
ZOOM_DIRECTION_IN = 1,
ZOOM_DIRECTION_OUT = 2,
WORLDMAP_SIZE_SMALL_WINDOW_SIZE = 550,
WORLDMAP_RESIZE_WIDTH_DRIVEN = true,
WORLDMAP_RESIZE_HEIGHT_DRIVEN = false,
WORLDMAP_SIZE_FULLSCREEN = 1,
WORLDMAP_SIZE_SMALL = 2,
GAMEPAD_TOOLTIP_ID = 1,
HISTORY_SLIDER_RANGE = 100,
DRAG_START_DIST_SQ = 10 * 10,
-- times are in seconds
PIN_UPDATE_DELAY = .04, -- Delay for updating pin positions and rotations for player and group members.
MAP_REFRESH_UPDATE_DELAY = 1, -- Delay between checking to see if the map needs to change based on the player's current location
ALLIANCE_TO_RESTRICTED_PIN_TYPE = {
[ALLIANCE_ALDMERI_DOMINION] = MAP_PIN_TYPE_RESTRICTED_LINK_ALDMERI_DOMINION,
[ALLIANCE_EBONHEART_PACT] = MAP_PIN_TYPE_RESTRICTED_LINK_EBONHEART_PACT,
[ALLIANCE_DAGGERFALL_COVENANT] = MAP_PIN_TYPE_RESTRICTED_LINK_DAGGERFALL_COVENANT,
},
}
-- To properly contain the actual map, the worldmap window needs to compensate for these offsets
--Padding is the total space in the window not occupied by the map
local MAP_CONTAINER_LAYOUT =
{
[CONSTANTS.WORLDMAP_SIZE_SMALL] =
{
--left edge, right edge
paddingX = 4 + 4,
--top edge, title bar, buttons bar, bot edge
paddingY = 4 + 26 + 36 + 4,
offsetX = 4,
offsetY = 30,
titleBarHeight = 26,
},
[CONSTANTS.WORLDMAP_SIZE_FULLSCREEN] =
{
paddingX = 0,
paddingY = 0,
offsetX = 0,
offsetY = 0,
},
}
local function GetInformationTooltip(isGamepadMode)
if isGamepadMode then
return ZO_MapLocationTooltip_Gamepad
else
return InformationTooltip
end
end
local function GetKeepTooltip(isGamepadMode)
if isGamepadMode then
return ZO_MapLocationTooltip_Gamepad
else
return ZO_KeepTooltip
end
end
local function GetMapLocationTooltip(isGamepadMode)
if isGamepadMode then
return ZO_MapLocationTooltip_Gamepad
else
return ZO_MapLocationTooltip
end
end
local function GetPlatformInformationTooltip()
return GetInformationTooltip(IsInGamepadPreferredMode())
end
local function GetPlatformKeepTooltip()
return GetKeepTooltip(IsInGamepadPreferredMode())
end
local function GetPlatformMapLocationTooltip()
return GetMapLocationTooltip(IsInGamepadPreferredMode())
end
local g_mapOverflowX = 0
local g_mapOverflowY = 0
local g_mapOverflowMaxX = 0
local g_mapOverflowMaxY = 0
local g_mapScale = 1
local g_dataRegistration
local g_cyrodiilMapIndex
local g_imperialCityMapIndex
local g_mapDragX
local g_mapDragY
local g_dragging = false
local g_mapPanAndZoom
local g_pinUpdateTime = nil
local g_refreshUpdateTime = nil
local g_activeGroupPins = {}
local g_objectiveMovingPins = {}
local g_nextRespawnTimeMS = 0
MAP_FLOOR_CHANGE_DIRECTION_UP = 1
MAP_FLOOR_CHANGE_DIRECTION_DOWN = -1
MAP_MODE_SMALL_CUSTOM = 1
MAP_MODE_LARGE_CUSTOM = 2
MAP_MODE_KEEP_TRAVEL = 3
MAP_MODE_FAST_TRAVEL = 4
MAP_MODE_AVA_RESPAWN = 5
MAP_MODE_AVA_KEEP_RECALL = 6
MAP_MODE_DIG_SITES = 7
local MAP_TRANSIENT_MODES =
{
[MAP_MODE_SMALL_CUSTOM] = {},
[MAP_MODE_LARGE_CUSTOM] = {},
}
local MAP_MODE_CHANGE_RESTRICTIONS =
{
[MAP_MODE_KEEP_TRAVEL] =
{
disableMapChanging = true,
},
[MAP_MODE_AVA_RESPAWN] =
{
restrictedCyrodiilImperialCityMapChanging = true,
},
[MAP_MODE_AVA_KEEP_RECALL] =
{
disableMapChanging = true,
},
[MAP_MODE_DIG_SITES] =
{
disableMapChanging = true,
},
}
local g_enableCampaignHistory = false
local g_historyPercent = 1.0
local function ShouldUseHistoryPercent()
if g_enableCampaignHistory == false then
return false
end
local modeData = WORLD_MAP_MANAGER:GetModeData()
return modeData.allowHistory == nil or modeData.allowHistory == true
end
function ZO_WorldMap_GetHistoryPercentToUse()
if ShouldUseHistoryPercent() then
return g_historyPercent
else
return 1.0
end
end
local function IsShowingCosmicMap()
return GetMapType() == MAPTYPE_COSMIC
end
function ZO_WorldMap_IsNormalizedPointInsideMapBounds(x, y)
-- At some point this could take a size as well to determine if an icon/pin would hang off the edge of the map, even though the center of the pin is inside the map.
-- NOTE: This will NEVER show a point on the edge, assuming that icons displayed there would always hang outside the map.
return x > 0 and x < 1 and y > 0 and y < 1
end
local function NormalizePreferredMousePositionToMap()
if IsInGamepadPreferredMode() then
local x, y = ZO_WorldMapScroll:GetCenter()
return NormalizePointToControl(x, y, ZO_WorldMapContainer)
else
return NormalizeMousePositionToControl(ZO_WorldMapContainer)
end
end
local function IsMouseOverMap()
-- WORLD_MAP_AUTO_NAVIGATION_OVERLAY_FRAGMENT will eat all the mouse input, so the mouse can't be over the map
if not WORLD_MAP_AUTO_NAVIGATION_OVERLAY_FRAGMENT:IsShowing() then
if IsInGamepadPreferredMode() then
return SCENE_MANAGER:IsShowing("gamepad_worldMap")
else
return not ZO_WorldMapScroll:IsHidden() and MouseIsOver(ZO_WorldMapScroll) and SCENE_MANAGER:IsShowing("worldMap")
end
end
return false
end
--[[
Pin management...
--]]
--[[
Map Tile Pool Object. Creates the base tiles for the world map...controls must be able to be indexed by tile
--]]
local ZO_WorldMapTiles = ZO_Object:Subclass()
function ZO_WorldMapTiles:New(...)
local tiles = ZO_Object.New(self)
tiles:Initialize(...)
return tiles
end
function ZO_WorldMapTiles:Initialize(parent)
self.parent = parent
self.indexToTile = {}
end
function ZO_WorldMapTiles:GetTile(i)
return self.indexToTile[i]
end
function ZO_WorldMapTiles:GetOrCreateTile(i)
local tile = self:GetTile(i)
if tile == nil then
tile = CreateControlFromVirtual(self.parent:GetName(), self.parent, "ZO_MapTile", i)
self.indexToTile[i] = tile
end
return tile
end
function ZO_WorldMapTiles:ReleaseTiles()
for k, tile in ipairs(self.indexToTile) do
tile:SetHidden(true)
end
end
function ZO_WorldMapTiles:UpdateMapData()
local numHorizontalTiles, numVerticalTiles = GetMapNumTiles()
self.horizontalTiles = numHorizontalTiles
self.verticalTiles = numVerticalTiles
end
function ZO_WorldMapTiles:LayoutTiles()
if self.horizontalTiles == nil then
self:UpdateMapData()
end
local tileWidth = CONSTANTS.MAP_WIDTH / self.horizontalTiles
local tileHeight = CONSTANTS.MAP_HEIGHT / self.verticalTiles
local numHorizontalTiles, numVerticalTiles = self.horizontalTiles, self.verticalTiles
self:ReleaseTiles()
for i = 1, (numHorizontalTiles * numVerticalTiles) do
local tileControl = self:GetOrCreateTile(i)
tileControl:SetHidden(false)
tileControl:SetDimensions(tileWidth, tileHeight)
tileControl:ClearAnchors()
local xOffset = zo_mod(i - 1, numHorizontalTiles) * tileWidth
local yOffset = zo_floor((i - 1) / numHorizontalTiles) * tileHeight
tileControl:SetAnchor(TOPLEFT, ZO_WorldMapContainer, TOPLEFT, xOffset, yOffset)
end
end
function ZO_WorldMapTiles:UpdateTextures()
self:UpdateMapData()
self:LayoutTiles()
local totalTiles = self.horizontalTiles * self.verticalTiles
for i = 1, totalTiles do
local tileControl = self:GetTile(i)
tileControl:SetTexture(GetMapTileTexture(i))
tileControl:SetHidden(false)
end
for i = totalTiles + 1, #self.indexToTile do
local tileControl = self:GetTile(i)
tileControl:SetHidden(true)
end
end
local InformationTooltipMixin = {}
function InformationTooltipMixin:AddDivider()
-- Does nothing on non-gamepad version
end
function InformationTooltipMixin:AddMoney(tooltip, cost, text, hasEnough)
ZO_ItemTooltip_AddMoney(tooltip, cost, text, hasEnough)
end
function ZO_WorldMap_GetWayshrineTooltipCollectibleLockedText(pin)
--Don't call this function if you don't already know it's locked.
--Otherwise we'd run superflous code to return useless information
assert(pin:IsLockedByLinkedCollectible())
local collectibleId = GetFastTravelNodeLinkedCollectibleId(pin:GetFastTravelNodeIndex())
local collectibleData = ZO_COLLECTIBLE_DATA_MANAGER:GetCollectibleDataById(collectibleId)
local stringId = collectibleData:IsCategoryType(COLLECTIBLE_CATEGORY_TYPE_CHAPTER) and SI_TOOLTIP_POI_LINKED_CHAPTER_COLLECTIBLE_LOCKED or SI_TOOLTIP_POI_LINKED_DLC_COLLECTIBLE_LOCKED
return zo_strformat(stringId, collectibleData:GetName(), collectibleData:GetCategoryData():GetName())
end
function InformationTooltipMixin:AppendDelveInfo(pin)
local poiIndex = pin:GetPOIIndex()
local zoneIndex = pin:GetPOIZoneIndex()
local poiName, _, poiStartDesc, poiFinishedDesc = GetPOIInfo(zoneIndex, poiIndex)
local informationTooltip = GetPlatformInformationTooltip()
if pin:IsDelvePin() then
informationTooltip:AddLine(zo_strformat(SI_WORLD_MAP_DELVE_NAME, poiName), "", ZO_TOOLTIP_DEFAULT_COLOR:UnpackRGB())
elseif pin:IsPublicDungeonPin() then
informationTooltip:AddLine(zo_strformat(SI_WORLD_MAP_PUBLIC_DUNGEON_NAME, poiName), "", ZO_TOOLTIP_DEFAULT_COLOR:UnpackRGB())
else
informationTooltip:AddLine(poiName, "", ZO_TOOLTIP_DEFAULT_COLOR:UnpackRGB())
end
local skyshardId = GetPOISkyshardId(zoneIndex, poiIndex)
if skyshardId ~= 0 then
local hintText = GetSkyshardHint(skyshardId)
informationTooltip:AddLine(zo_strformat(SI_WORLD_MAP_SKYSHARD_HINT_FORMATTER, hintText), "", ZO_TOOLTIP_DEFAULT_COLOR:UnpackRGB())
local skyshardDiscoveryStatus = GetSkyshardDiscoveryStatus(skyshardId)
informationTooltip:AddLine(zo_strformat(SI_WORLD_MAP_SKYSHARD_STATUS_FORMATTER, GetString("SI_SKYSHARDDISCOVERYSTATUS", skyshardDiscoveryStatus)), "", ZO_TOOLTIP_DEFAULT_COLOR:UnpackRGB())
end
end
function InformationTooltipMixin:AppendWayshrineTooltip(pin)
local nodeIndex = pin:GetFastTravelNodeIndex()
local informationTooltip = GetPlatformInformationTooltip()
local _, name, _, _, _, _, poiType = GetFastTravelNodeInfo(nodeIndex)
informationTooltip:AddLine(zo_strformat(SI_WORLD_MAP_LOCATION_NAME, name), "", ZO_TOOLTIP_DEFAULT_COLOR:UnpackRGB())
local isCurrentLoc = g_fastTravelNodeIndex == nodeIndex
local isOutboundOnly, outboundOnlyErrorStringId = GetFastTravelNodeOutboundOnlyInfo(nodeIndex)
local nodeIsHousePreview = poiType == POI_TYPE_HOUSE and not HasCompletedFastTravelNodePOI(nodeIndex)
if isCurrentLoc then --NO CLICK: Can't travel to origin
informationTooltip:AddLine(GetString(SI_TOOLTIP_WAYSHRINE_CURRENT_LOC), "", ZO_HIGHLIGHT_TEXT:UnpackRGB())
elseif g_fastTravelNodeIndex == nil and IsInCampaign() then --NO CLICK: Can't recall while inside AvA zone
informationTooltip:AddLine(GetString(SI_TOOLTIP_WAYSHRINE_CANT_RECALL_AVA), "", ZO_ERROR_COLOR:UnpackRGB())
elseif isOutboundOnly then --NO CLICK: Can't travel to this wayshrine, only from it
local message = GetErrorString(outboundOnlyErrorStringId)
informationTooltip:AddLine(message, "", ZO_ERROR_COLOR:UnpackRGB())
elseif not CanLeaveCurrentLocationViaTeleport() then --NO CLICK: Current Zone or Subzone restricts jumping
local cantLeaveStringId
if IsInOutlawZone() then
cantLeaveStringId = SI_TOOLTIP_WAYSHRINE_CANT_RECALL_OUTLAW_REFUGE
else
cantLeaveStringId = SI_TOOLTIP_WAYSHRINE_CANT_RECALL_FROM_LOCATION
end
informationTooltip:AddLine(GetString(cantLeaveStringId), "", ZO_ERROR_COLOR:UnpackRGB())
elseif pin:IsLockedByLinkedCollectible() then --CLICK: Open the store
local r, g, b = GetInterfaceColor(INTERFACE_COLOR_TYPE_MARKET_COLORS, MARKET_COLORS_ON_SALE)
local SET_TO_FULL_SIZE = true
informationTooltip:AddLine(ZO_WorldMap_GetWayshrineTooltipCollectibleLockedText(pin), "", r, g, b, CENTER, MODIFY_TEXT_TYPE_NONE, TEXT_ALIGN_CENTER, SET_TO_FULL_SIZE)
if pin:GetLinkedCollectibleType() == COLLECTIBLE_CATEGORY_TYPE_CHAPTER then
informationTooltip:AddLine(GetString(SI_TOOLTIP_WAYSHRINE_CLICK_TO_UPGRADE_CHAPTER), "", ZO_HIGHLIGHT_TEXT:UnpackRGB())
else
informationTooltip:AddLine(GetString(SI_TOOLTIP_WAYSHRINE_CLICK_TO_OPEN_CROWN_STORE), "", ZO_HIGHLIGHT_TEXT:UnpackRGB())
end
elseif IsUnitDead("player") then --NO CLICK: Dead
informationTooltip:AddLine(GetString(SI_TOOLTIP_WAYSHRINE_CANT_RECALL_WHEN_DEAD), "", ZO_ERROR_COLOR:UnpackRGB())
elseif g_fastTravelNodeIndex == nil then --Recall
local _, premiumTimeLeft = GetRecallCooldown()
if premiumTimeLeft == 0 then --CLICK: Recall
local text = GetString(nodeIsHousePreview and SI_TOOLTIP_WAYSHRINE_CLICK_TO_PREVIEW_HOUSE or SI_TOOLTIP_WAYSHRINE_CLICK_TO_RECALL)
informationTooltip:AddLine(text, "", ZO_HIGHLIGHT_TEXT:UnpackRGB())
local cost = GetRecallCost(nodeIndex)
if cost > 0 then
local currency = GetRecallCurrency(nodeIndex)
local notEnoughCurrency = cost > GetCurrencyAmount(currency, CURRENCY_LOCATION_CHARACTER)
informationTooltip:AddMoney(informationTooltip, cost, SI_TOOLTIP_RECALL_COST, notEnoughCurrency)
end
else --NO CLICK: Waiting on cooldown
local cooldownText = zo_strformat(SI_TOOLTIP_WAYSHRINE_RECALL_COOLDOWN, ZO_FormatTimeMilliseconds(premiumTimeLeft, TIME_FORMAT_STYLE_DESCRIPTIVE, TIME_FORMAT_PRECISION_SECONDS))
informationTooltip:AddLine(cooldownText, "", ZO_HIGHLIGHT_TEXT:UnpackRGB())
end
else --CLICK: Fast Travel
local text = GetString(nodeIsHousePreview and SI_TOOLTIP_WAYSHRINE_CLICK_TO_PREVIEW_HOUSE or SI_TOOLTIP_WAYSHRINE_CLICK_TO_FAST_TRAVEL)
informationTooltip:AddLine(text, "", ZO_HIGHLIGHT_TEXT:UnpackRGB())
end
end
function InformationTooltipMixin:AppendSuggestionActivity(pin)
local shortDescription = pin:GetShortDescription()
if shortDescription then
GetPlatformInformationTooltip():AddLine(shortDescription, "", ZO_TOOLTIP_DEFAULT_COLOR:UnpackRGB())
end
end
function ZO_WorldMap_GetTooltipForMode(mode)
if mode == ZO_MAP_TOOLTIP_MODE.INFORMATION then
return GetPlatformInformationTooltip()
elseif mode == ZO_MAP_TOOLTIP_MODE.KEEP then
return GetPlatformKeepTooltip()
elseif mode == ZO_MAP_TOOLTIP_MODE.MAP_LOCATION then
return GetPlatformMapLocationTooltip()
else
assert(false)
end
end
local tooltipOrder =
{
ZO_MAP_TOOLTIP_MODE.KEEP, ZO_MAP_TOOLTIP_MODE.MAP_LOCATION, ZO_MAP_TOOLTIP_MODE.INFORMATION
}
--[[
Sticky Pin Utilities for gamepad map control (utilized by mouse over list construction)
--]]
local WorldMapStickyPin = ZO_Object:Subclass()
local g_stickyPin
function WorldMapStickyPin:New(...)
local stickyPin = ZO_Object.New(self)
stickyPin:Initialize(...)
return stickyPin
end
function WorldMapStickyPin:Initialize()
self.BASE_STICKY_MIN_DISTANCE_UNITS = 50
self.BASE_STICKY_MAX_DISTANCE_UNITS = 75
self.m_thresholdDistanceSq = self.BASE_STICKY_MIN_DISTANCE_UNITS * self.BASE_STICKY_MIN_DISTANCE_UNITS
self.m_enabled = true
end
function WorldMapStickyPin:SetEnabled(enabled)
self.m_enabled = enabled
end
function WorldMapStickyPin:UpdateThresholdDistance(currentNormalizedZoom)
local stickyDistance = zo_lerp(self.BASE_STICKY_MIN_DISTANCE_UNITS, self.BASE_STICKY_MAX_DISTANCE_UNITS, currentNormalizedZoom)
self.m_thresholdDistanceSq = stickyDistance * stickyDistance
end
function WorldMapStickyPin:SetStickyPin(pin)
self.m_pin = pin
end
function WorldMapStickyPin:GetStickyPin()
return self.m_pin
end
function WorldMapStickyPin:ClearStickyPin(mover)
if self.m_movingToPin and self:GetStickyPin() then
mover:ClearTargetOffset()
end
self:SetStickyPin(nil)
end
function WorldMapStickyPin:MoveToStickyPin(mover)
local movingToPin = self:GetStickyPin()
if movingToPin then
self.m_movingToPin = movingToPin
local useCurrentZoom = true
mover:PanToPin(movingToPin, useCurrentZoom)
end
end
function WorldMapStickyPin:SetStickyPinFromNearestCandidate()
self:SetStickyPin(self.m_nearestCandidate)
end
function WorldMapStickyPin:ClearNearestCandidate()
self.m_nearestCandidate = nil
self.m_nearestCandidateDistanceSq = 0
end
function WorldMapStickyPin:ConsiderPin(pin, x, y)
if self.m_enabled then
local pinGroup = pin:GetPinGroup()
if pinGroup == nil or WORLD_MAP_MANAGER:AreStickyPinsEnabledForPinGroup(pinGroup) then
local distanceSq = pin:DistanceToSq(x, y)
if distanceSq < self.m_thresholdDistanceSq then
if not self.m_nearestCandidate or distanceSq < self.m_nearestCandidateDistanceSq then
self.m_nearestCandidate = pin
self.m_nearestCandidateDistanceSq = distanceSq
end
end
end
end
end
--[[
Utilities to build lists of pins the mouse is currently over and was previously over so the world map knows how
to properly call the OnMouseExit and OnMouseEnter events on the pins.
--]]
local currentMouseOverPins = {}
local previousMouseOverPins = {}
local mouseExitPins = {}
local mousedOverPinWasReset = false
local invalidateTooltip = false
function ZO_WorldMap_InvalidateTooltip()
invalidateTooltip = true
end
local function ResetMouseOverPins()
for pin, mousedOver in pairs(currentMouseOverPins) do
if mousedOver then
pin:SetTargetScale(1)
end
end
currentMouseOverPins = {}
previousMouseOverPins = {}
end
local function BuildMouseOverPinLists(cursorPositionX, cursorPositionY)
-- Determine if the mouse is even over the world map
local mouseOverWorldMap = IsMouseOverMap()
-- Swap lists
previousMouseOverPins, currentMouseOverPins = currentMouseOverPins, previousMouseOverPins
-- Update any pins that were moused over in the current list that may no longer be in the active pins
for pin, mousedOver in pairs(currentMouseOverPins) do
if mousedOver then
currentMouseOverPins[pin] = mouseOverWorldMap and pin:MouseIsOver(cursorPositionX, cursorPositionY)
end
end
-- Update active list and determine the sticky pin!
g_stickyPin:ClearNearestCandidate()
local pins = g_mapPinManager:GetActiveObjects()
for k, pin in pairs(pins) do
local isMouseCurrentlyOverPin = mouseOverWorldMap and pin:MouseIsOver(cursorPositionX, cursorPositionY)
currentMouseOverPins[pin] = isMouseCurrentlyOverPin
g_stickyPin:ConsiderPin(pin, cursorPositionX, cursorPositionY)
end
g_stickyPin:SetStickyPinFromNearestCandidate()
-- Determine which pins need to have their mouse enter called and which need to have their mouse exit called.
-- Return whether or not the lists for current and previous changed so that nothing is updated unecessarily
local wasPreviouslyMousedOver, doMouseEnter, doMouseExit
local listsChanged = false
local needsContinuousTooltipUpdates = false
for pin, isMousedOver in pairs(currentMouseOverPins) do
wasPreviouslyMousedOver = previousMouseOverPins[pin]
doMouseEnter = isMousedOver and not wasPreviouslyMousedOver
doMouseExit = not isMousedOver and wasPreviouslyMousedOver
mouseExitPins[pin] = doMouseExit
listsChanged = listsChanged or doMouseEnter or doMouseExit
needsContinuousTooltipUpdates = needsContinuousTooltipUpdates or (isMousedOver and pin:NeedsContinuousTooltipUpdates())
end
return listsChanged, needsContinuousTooltipUpdates
end
local function DoMouseExitForPin(pin)
if pin:IsPOI() or pin:IsFastTravelWayShrine() then
--reset the status to show what part of the map we're over (except if it's the name of this zone)
if g_mouseoverMapBlobManager.m_currentLocation ~= ZO_WorldMap.zoneName then
ZO_WorldMapMouseoverName:SetText(zo_strformat(SI_WORLD_MAP_LOCATION_NAME, g_mouseoverMapBlobManager.m_currentLocation))
ZO_WorldMapMouseoverName.owner = "map"
else
ZO_WorldMapMouseoverName:SetText("")
ZO_WorldMapMouseoverName.owner = ""
end
ZO_WorldMapMouseOverDescription:SetText("")
end
local pinType = pin:GetPinType()
g_keybindStrips.mouseover:DoMouseExitForPinType(pinType)
g_keybindStrips.gamepad:DoMouseExitForPinType(pinType)
end
local function MouseOverPins_OnPinReset(pin)
if currentMouseOverPins[pin] then
mousedOverPinWasReset = true
DoMouseExitForPin(pin)
end
currentMouseOverPins[pin] = nil
previousMouseOverPins[pin] = nil
--If we are showing a menu to choose a pin action and one of those pins is removed from the map then we need to handle that here
WORLD_MAP_CHOICE_DIALOG_GAMEPAD:OnPinRemovedFromMap(pin)
if ZO_MapPin.pinsInKeyboardMapChoiceDialog and ZO_MapPin.pinsInKeyboardMapChoiceDialog[pin] then
ClearMenu()
end
end
local usedTooltips = {}
local function HideKeyboardTooltips()
local NOT_GAMEPAD_MODE = false
if g_ownsTooltip then
ClearTooltip(GetInformationTooltip(NOT_GAMEPAD_MODE))
g_ownsTooltip = false
end
GetKeepTooltip(NOT_GAMEPAD_MODE):SetHidden(true)
ClearTooltip(GetMapLocationTooltip(NOT_GAMEPAD_MODE))
end
local function HideGamepadTooltip()
local GAMEPAD_MODE = true
GetMapLocationTooltip(GAMEPAD_MODE):ClearLines()
SCENE_MANAGER:RemoveFragment(GAMEPAD_WORLD_MAP_TOOLTIP_FRAGMENT)
end
local g_hideTooltipsAt
local function ClearHideTooltipsLater()
g_hideTooltipsAt = nil
end
local function HideAllTooltipsLater()
if IsInGamepadPreferredMode() then
g_hideTooltipsAt = GetGameTimeMilliseconds() + 1000
else
HideKeyboardTooltips()
for i = 1, #tooltipOrder do
usedTooltips[i] = nil
end
end
end
local function HideAllTooltips()
if IsInGamepadPreferredMode() then
HideGamepadTooltip()
else
HideKeyboardTooltips()
end
ClearHideTooltipsLater()
for i = 1, #tooltipOrder do
usedTooltips[i] = nil
end
end
local function ShowGamepadTooltip(resetScroll)
if not IsInGamepadPreferredMode() then return end
if g_hideTooltipsAt then
-- If we are in the process of hiding the tooltips then treat it as a fresh tooltip
ZO_MapLocationTooltip_Gamepad:ClearLines(resetScroll)
ClearHideTooltipsLater()
end
if not usedTooltips[CONSTANTS.GAMEPAD_TOOLTIP_ID] then
usedTooltips[CONSTANTS.GAMEPAD_TOOLTIP_ID] = true
SCENE_MANAGER:AddFragment(GAMEPAD_WORLD_MAP_TOOLTIP_FRAGMENT)
ZO_MapLocationTooltip_Gamepad:ClearLines(resetScroll)
end
return ZO_MapLocationTooltip_Gamepad
end
local function GetValueOrExecute(value, ...)
if type(value) == "function" then
return value(...)
end
return value
end
local function CompareIgnoreNil(first, second)
if first == second then
return nil
elseif first and second then
return first < second
elseif first then
return true
else
return false
end
end
local function GamepadTooltipPinSortFunction(firstPin, secondPin)
local firstPinType = firstPin and firstPin:GetPinType()
local secondPinType = secondPin and secondPin:GetPinType()
-- We don't need to check the types for nil, as if they are nil, the following
-- infos will get nil, and that will produce the same result.
local firstTooltipInfo = ZO_MapPin.TOOLTIP_CREATORS[firstPinType]
local secondTooltipInfo = ZO_MapPin.TOOLTIP_CREATORS[secondPinType]
-- If either tooltip info is nil, that pin has no tooltip, and we just need
-- to make sure it sorts to a consistant place.
if not firstTooltipInfo then
return false
elseif not secondTooltipInfo then
return true
end
local firstCategoryId = GetValueOrExecute(firstTooltipInfo.categoryId, firstPin) or GetValueOrExecute(firstTooltipInfo.gamepadCategory, firstPin)
local secondCategoryId = GetValueOrExecute(secondTooltipInfo.categoryId, secondPin) or GetValueOrExecute(secondTooltipInfo.gamepadCategory, secondPin)
local idResult = CompareIgnoreNil(firstCategoryId, secondCategoryId)
if idResult ~= nil then
return idResult
end
local firstCategory = GetValueOrExecute(firstTooltipInfo.gamepadCategory, firstPin)
local secondCategory = GetValueOrExecute(secondTooltipInfo.gamepadCategory, secondPin)
idResult = CompareIgnoreNil(firstCategory, secondCategory)
if idResult ~= nil then
return idResult
end
local firstEntryName = GetValueOrExecute(firstTooltipInfo.entryName, firstPin)
local secondEntryName = GetValueOrExecute(secondTooltipInfo.entryName, secondPin)
idResult = CompareIgnoreNil(firstEntryName, secondEntryName)
if idResult ~= nil then
return idResult
end
return false
end
local function TooltipPinSortFunction(firstPin, secondPin)
local firstPinType = firstPin and firstPin:GetPinType()
local secondPinType = secondPin and secondPin:GetPinType()
-- We don't need to check the types for nil, as if they are nil, the following
-- infos will get nil, and that will produce the same result.
local firstTooltipInfo = ZO_MapPin.TOOLTIP_CREATORS[firstPinType]
local secondTooltipInfo = ZO_MapPin.TOOLTIP_CREATORS[secondPinType]
-- If either tooltip info is nil, that pin has no tooltip, and we just need
-- to make sure it sorts to a consistant place.
if not firstTooltipInfo then
return false
elseif not secondTooltipInfo then
return true
end
local firstCategoryId = GetValueOrExecute(firstTooltipInfo.categoryId, firstPin)
local secondCategoryId = GetValueOrExecute(secondTooltipInfo.categoryId, secondPin)
local idResult = CompareIgnoreNil(firstCategoryId, secondCategoryId)
if idResult ~= nil then
return idResult
end
local firstEntryName = GetValueOrExecute(firstTooltipInfo.entryName, firstPin)
local secondEntryName = GetValueOrExecute(secondTooltipInfo.entryName, secondPin)
idResult = CompareIgnoreNil(firstEntryName, secondEntryName)
if idResult ~= nil then
return idResult
end
return false
end
local tooltipMouseOverPins = {}
local foundTooltipMouseOverPins = {}
local function GetTooltipMouseOverPins()
ZO_ClearNumericallyIndexedTable(tooltipMouseOverPins)
ZO_ClearNumericallyIndexedTable(foundTooltipMouseOverPins)
for pin, isMousedOver in pairs(currentMouseOverPins) do
if pin then
table.insert(tooltipMouseOverPins, pin)
end
end
return tooltipMouseOverPins
end
local function UpdateMouseOverPins()
local isInGamepadPreferredMode = SCENE_MANAGER:IsCurrentSceneGamepad()
local cursorPositionX
local cursorPositionY
if isInGamepadPreferredMode then
cursorPositionX, cursorPositionY = ZO_WorldMapScroll:GetCenter()
else
cursorPositionX, cursorPositionY = GetUIMousePosition()
end
local mouseOverListChanged, needsContinuousTooltipUpdates = BuildMouseOverPinLists(cursorPositionX, cursorPositionY)
local needsTooltipUpdate = mouseOverListChanged or mousedOverPinWasReset or needsContinuousTooltipUpdates or invalidateTooltip
local needsTooltipScrollReset = mouseOverListChanged or mousedOverPinWasReset
invalidateTooltip = false
mousedOverPinWasReset = false
if not needsTooltipUpdate then
return
end
local wasShowingTooltip = ZO_WorldMap_IsTooltipShowing()
HideAllTooltipsLater()
-- Iterate over the current pins, using the key as the actual pin to facilitate looking up whether or not it's appropriate to call mouseEnter/mouseExit
-- for the pins.
local tooltipMouseOverPins = GetTooltipMouseOverPins()
-- Do the exit pins first (so that ZO_WorldMapMouseoverName gets cleared then set in the correct order)
for index, pin in ipairs(tooltipMouseOverPins) do
if mouseExitPins[pin] then
DoMouseExitForPin(pin)
end
end
for index, pin in ipairs(tooltipMouseOverPins) do
local isMousedOver = currentMouseOverPins[pin]
-- Verify that control is still moused over due to OnUpdate/OnShow handler issues (prevents tooltip popping)
if isMousedOver and pin:MouseIsOver(cursorPositionX, cursorPositionY) then
table.insert(foundTooltipMouseOverPins, pin)
else
pin:SetTargetScale(1)
end
end
if IsInGamepadPreferredMode() then
table.sort(foundTooltipMouseOverPins, GamepadTooltipPinSortFunction)
else
table.sort(foundTooltipMouseOverPins, TooltipPinSortFunction)
if #foundTooltipMouseOverPins > 0 then
WORLD_MAP_MANAGER:HidePinPointerBox()
end
end
local MAX_QUEST_PINS = 10
local currentQuestPins = 0
local missedQuestPins = 0
local maxKeepTooltipPinLevel = 0
local informationTooltipAppendedTo = false
local lastGamepadCategory = nil
local informationTooltip = GetPlatformInformationTooltip()
for index, pin in ipairs(foundTooltipMouseOverPins) do
local pinType = pin:GetPinType()
local pinTooltipInfo = ZO_MapPin.TOOLTIP_CREATORS[pinType]
if pinTooltipInfo then
local layoutPinTooltip = true
if pin:IsQuest() then
if pin:IsAssisted() then
--always allow assisted pins through
elseif currentQuestPins < MAX_QUEST_PINS then
currentQuestPins = currentQuestPins + 1
else
layoutPinTooltip = false
missedQuestPins = missedQuestPins + 1
end
end
if layoutPinTooltip then
if not pin:IsAreaPin() or pin:ShowsPinAndArea() then
pin:SetTargetScale(1.3)
end
local layoutTooltip = true
local usedTooltip = pinTooltipInfo.tooltip
if not isInGamepadPreferredMode and usedTooltip == ZO_MAP_TOOLTIP_MODE.KEEP then
local pinLevel = pin:GetLevel()
if pinLevel > maxKeepTooltipPinLevel then
maxKeepTooltipPinLevel = pinLevel
else
layoutTooltip = false
end
end
if layoutTooltip and pinTooltipInfo.hasTooltip then
layoutTooltip = pinTooltipInfo.hasTooltip(pin)
end
if layoutTooltip then
if usedTooltip then
if not isInGamepadPreferredMode then
for i = 1, #tooltipOrder do
if tooltipOrder[i] == usedTooltip then
if not usedTooltips[i] then
usedTooltips[i] = true
if usedTooltip == ZO_MAP_TOOLTIP_MODE.KEEP then
GetPlatformKeepTooltip():SetHidden(false)
else
InitializeTooltip(ZO_WorldMap_GetTooltipForMode(usedTooltip), pin:GetControl())
end
end
end
end
else
if not ZO_WorldMap_IsWorldMapInfoShowing() and not ZO_WorldMap_IsKeepInfoShowing() then
ShowGamepadTooltip(needsTooltipScrollReset)
end
end
end
if isInGamepadPreferredMode then
local nextCategoryText = GetValueOrExecute(pinTooltipInfo.gamepadCategory, pin)
if type(nextCategoryText) == "number" then
nextCategoryText = GetString(nextCategoryText)
end
local nextCategory = nextCategoryText
if not nextCategory then
nextCategory = pinTooltipInfo.categoryId
end
local isDifferentCategory = (lastGamepadCategory ~= nextCategory)
if nextCategoryText and isDifferentCategory then
local categoryIcon = GetValueOrExecute(pinTooltipInfo.gamepadCategoryIcon, pin)
local titleStyleName = pinTooltipInfo.gamepadCategoryStyleName
titleStyleName = titleStyleName and informationTooltip.tooltip:GetStyle(titleStyleName)
local groupSection = informationTooltip.tooltip:AcquireSection(titleStyleName, informationTooltip.tooltip:GetStyle("mapKeepCategorySpacing"))
local mapIconTitleStyle = categoryIcon and informationTooltip.tooltip:GetStyle("mapIconTitle") or nil
informationTooltip:LayoutGroupHeader(groupSection, categoryIcon, nextCategoryText, titleStyleName, mapIconTitleStyle, informationTooltip.tooltip:GetStyle("mapTitle"))
informationTooltip.tooltip:AddSection(groupSection)
elseif pinTooltipInfo.gamepadSpacing or isDifferentCategory then
local groupSection = informationTooltip.tooltip:AcquireSection(informationTooltip.tooltip:GetStyle("mapKeepCategorySpacing"))
informationTooltip.tooltip:AddSectionEvenIfEmpty(groupSection)
end
lastGamepadCategory = nextCategory
end
pinTooltipInfo.creator(pin)
g_keybindStrips.mouseover:DoMouseEnterForPinType(pinType)
g_keybindStrips.gamepad:DoMouseEnterForPinType(pinType)
--space out the appended lines in the information tooltip
if usedTooltip == ZO_MAP_TOOLTIP_MODE.INFORMATION and not isInGamepadPreferredMode then
informationTooltipAppendedTo = true
informationTooltip:AddVerticalPadding(5)
end
end
end
end
-- For POIs, add name to the top of the map
local pinType = pin:GetPinType()
if pinType == MAP_PIN_TYPE_POI_COMPLETE or pinType == MAP_PIN_TYPE_POI_SEEN then
local poiIndex = pin:GetPOIIndex()
local zoneIndex = pin:GetPOIZoneIndex()
local poiName, _, poiStartDesc, poiFinishedDesc = GetPOIInfo(zoneIndex, poiIndex)
ZO_WorldMapMouseoverName.owner = "poi"
ZO_WorldMapMouseoverName:SetText(zo_strformat(SI_WORLD_MAP_LOCATION_NAME, poiName))
if pinType == MAP_PIN_TYPE_POI_COMPLETE then
ZO_WorldMapMouseOverDescription:SetText(poiFinishedDesc)
else
ZO_WorldMapMouseOverDescription:SetText(poiStartDesc)
end
end
end
if missedQuestPins > 0 then
local text = string.format(zo_strformat(SI_TOOLTIP_MAP_MORE_QUESTS, missedQuestPins))
if not IsInGamepadPreferredMode() then
informationTooltip:AddLine(text)