MapUtil.lua

MapUtil.lua (9.2.0.43345; unchanged since 9.0.2.36710)
  1. local SHADOWLANDS_CONTINENT_MAP_ID = 1550;
  2. local ORIBOS_UI_MAP_IDS = { 1670, 1671, 1672, 1673 };
  3. MapUtil = {};
  4. function MapUtil.IsMapTypeZone(mapID)
  5. local mapInfo = C_Map.GetMapInfo(mapID);
  6. return mapInfo and mapInfo.mapType == Enum.UIMapType.Zone;
  7. end
  8. function MapUtil.GetMapParentInfo(mapID, mapType, topMost)
  9. local candidate;
  10. local mapInfo = C_Map.GetMapInfo(mapID);
  11. while mapInfo do
  12. if ( mapInfo.mapType == mapType ) then
  13. if ( topMost ) then
  14. candidate = mapInfo;
  15. else
  16. return mapInfo;
  17. end
  18. end
  19. mapInfo = C_Map.GetMapInfo(mapInfo.parentMapID);
  20. end
  21. return candidate;
  22. end
  23. function MapUtil.ShouldMapTypeShowQuests(mapType)
  24. return mapType ~= Enum.UIMapType.World and mapType ~= Enum.UIMapType.Continent and mapType ~= Enum.UIMapType.Cosmic;
  25. end
  26. function MapUtil.ShouldShowTask(mapID, info)
  27. if (info.isQuestStart and info.inProgress) then
  28. return false
  29. end
  30. if not HaveQuestData(info.questId) then
  31. return false;
  32. end
  33. -- callings are allowed on other maps if they are zone maps
  34. if C_QuestLog.IsQuestCalling(info.questId) and MapUtil.IsMapTypeZone(mapID) then
  35. return true;
  36. end
  37. return mapID == info.mapID;
  38. end
  39. function MapUtil.MapHasUnlockedBounties(mapID)
  40. local displayLocation, lockedQuestID, bountySetID = C_QuestLog.GetBountySetInfoForMapID(mapID);
  41. if displayLocation and (not lockedQuestID or not C_QuestLog.IsOnQuest(lockedQuestID)) then
  42. local bounties = C_QuestLog.GetBountiesForMapID(mapID);
  43. return bounties and #bounties > 0;
  44. end
  45. return false;
  46. end
  47. function MapUtil.MapHasEmissaries(mapID)
  48. local displayLocation, lockedQuestID, bountySetID = C_QuestLog.GetBountySetInfoForMapID(mapID);
  49. return displayLocation ~= nil;
  50. end
  51. function MapUtil.FindBestAreaNameAtMouse(mapID, normalizedCursorX, normalizedCursorY)
  52. local exploredAreaIDs = C_MapExplorationInfo.GetExploredAreaIDsAtPosition(mapID, CreateVector2D(normalizedCursorX, normalizedCursorY));
  53. if exploredAreaIDs then
  54. for i, areaID in ipairs(exploredAreaIDs) do
  55. local name = C_Map.GetAreaInfo(areaID);
  56. if name then
  57. return name;
  58. end
  59. end
  60. end
  61. return nil;
  62. end
  63. function MapUtil.GetDisplayableMapForPlayer()
  64. local mapID = C_Map.GetBestMapForUnit("player");
  65. if mapID then
  66. repeat
  67. if C_Map.MapHasArt(mapID) then
  68. return mapID;
  69. end
  70. local mapInfo = C_Map.GetMapInfo(mapID);
  71. mapID = mapInfo and mapInfo.parentMapID or 0;
  72. until mapID == 0;
  73. end
  74. return C_Map.GetFallbackWorldMapID();
  75. end
  76. function MapUtil.GetBountySetMaps(bountySetID)
  77. if not MapUtil.bountySetMaps then
  78. MapUtil.bountySetMaps = { };
  79. end
  80. local bountySetMaps = MapUtil.bountySetMaps[bountySetID];
  81. if not bountySetMaps then
  82. bountySetMaps = C_Map.GetBountySetMaps(bountySetID);
  83. MapUtil.bountySetMaps[bountySetID] = bountySetMaps;
  84. end
  85. return bountySetMaps;
  86. end
  87. function MapUtil.GetMapCenterOnMap(mapID, topMapID)
  88. local left, right, top, bottom = C_Map.GetMapRectOnMap(mapID, topMapID);
  89. if left == nil then
  90. return nil, nil;
  91. end
  92. local centerX = left + (right - left) * .5;
  93. local centerY = top + (bottom - top) * .5;
  94. return centerX, centerY;
  95. end
  96. function MapUtil.IsChildMap(mapID, ancestorMapID)
  97. local mapInfo = C_Map.GetMapInfo(mapID);
  98. while (mapInfo ~= nil) and (mapInfo.parentMapID ~= nil) do
  99. if mapInfo.parentMapID == ancestorMapID then
  100. return true;
  101. end
  102. mapInfo = C_Map.GetMapInfo(mapInfo.parentMapID);
  103. end
  104. return false;
  105. end
  106. function MapUtil.IsOribosMap(mapID)
  107. return tContains(ORIBOS_UI_MAP_IDS, mapID);
  108. end
  109. function MapUtil.IsShadowlandsZoneMap(mapID)
  110. if mapID == SHADOWLANDS_CONTINENT_MAP_ID or MapUtil.IsOribosMap(mapID) then
  111. return true;
  112. end
  113. local mapInfo = C_Map.GetMapInfo(mapID);
  114. if (mapInfo.mapType ~= Enum.UIMapType.Zone) and (mapInfo.mapType ~= Enum.UIMapType.Continent) then
  115. return false;
  116. end
  117. return MapUtil.IsChildMap(mapID, SHADOWLANDS_CONTINENT_MAP_ID);
  118. end
  119. function MapUtil.MapShouldShowWorldQuestFilters(mapID)
  120. return MapUtil.MapHasEmissaries(mapID) or MapUtil.IsShadowlandsZoneMap(mapID);
  121. end