DungeonPreQuest: minimap markers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-11-10 13:28:44 +00:00
parent d873b7f6fa
commit ef6cb6ab60
13 changed files with 2682 additions and 7 deletions

View file

@ -0,0 +1,717 @@
-- HereBeDragons is a data API for the World of Warcraft mapping system
local MAJOR, MINOR = "HereBeDragonsQuestie-2.0", 34
assert(LibStub, MAJOR .. " requires LibStub")
local HereBeDragons, oldversion = LibStub:NewLibrary(MAJOR, MINOR)
if not HereBeDragons then return end
local CBH = LibStub("CallbackHandler-1.0")
HereBeDragons.eventFrame = HereBeDragons.eventFrame or CreateFrame("Frame")
HereBeDragons.mapData = HereBeDragons.mapData or {}
HereBeDragons.worldMapData = HereBeDragons.worldMapData or {}
HereBeDragons.transforms = HereBeDragons.transforms or {}
HereBeDragons.instanceZones = HereBeDragons.instanceZones or {}
HereBeDragons.callbacks = HereBeDragons.callbacks or CBH:New(HereBeDragons, nil, nil, false)
-- Embedded libraries load before Questie's client flags. Forever shares Retail's project ID,
-- but its map hierarchy and instance transforms belong to Classic.
local interfaceVersion = select(4, GetBuildInfo())
local WoWClassic = (WOW_PROJECT_ID == WOW_PROJECT_CLASSIC) or (interfaceVersion >= 16000 and interfaceVersion < 17000)
local WoWBC = (WOW_PROJECT_ID == WOW_PROJECT_BURNING_CRUSADE_CLASSIC)
local WoWWrath = (WOW_PROJECT_ID == WOW_PROJECT_WRATH_CLASSIC)
local WoWCata = (WOW_PROJECT_ID == WOW_PROJECT_CATACLYSM_CLASSIC)
local WoWMists = (WOW_PROJECT_ID == WOW_PROJECT_MISTS_CLASSIC)
-- Data Constants
local COSMIC_MAP_ID = 946
local WORLD_MAP_ID = 947
-- Lua upvalues
local PI2 = math.pi * 2
local atan2 = math.atan2
local pairs, ipairs = pairs, ipairs
-- WoW API upvalues
local UnitPosition = UnitPosition
local C_Map = C_Map
-- data table upvalues
local mapData = HereBeDragons.mapData -- table { width, height, left, top, .instance, .name, .mapType }
local worldMapData = HereBeDragons.worldMapData -- table { width, height, left, top }
local transforms = HereBeDragons.transforms
local instanceZones = HereBeDragons.instanceZones
local currentPlayerUIMapID, currentPlayerUIMapType
-- Override instance ids for phased content
local instanceIDOverrides = {
-- Draenor
[1152] = 1116, -- Horde Garrison 1
[1330] = 1116, -- Horde Garrison 2
[1153] = 1116, -- Horde Garrison 3
[1154] = 1116, -- Horde Garrison 4 (unused)
[1158] = 1116, -- Alliance Garrison 1
[1331] = 1116, -- Alliance Garrison 2
[1159] = 1116, -- Alliance Garrison 3
[1160] = 1116, -- Alliance Garrison 4 (unused)
[1191] = 1116, -- Ashran PvP Zone
[1203] = 1116, -- Frostfire Finale Scenario
[1207] = 1116, -- Talador Finale Scenario
[1277] = 1116, -- Defense of Karabor Scenario (SMV)
[1402] = 1116, -- Gorgrond Finale Scenario
[1464] = 1116, -- Tanaan
[1465] = 1116, -- Tanaan
-- Legion
[1478] = 1220, -- Temple of Elune Scenario (Val'Sharah)
[1495] = 1220, -- Protection Paladin Artifact Scenario (Stormheim)
[1502] = 1220, -- Dalaran Underbelly
[1533] = 0, -- Karazhan Artifact Scenario
[1539] = 0, -- Arm Warrior Artifact Tirisfal Scenario
[1612] = 1220, -- Feral Druid Artifact Scenario (Suramar)
[1626] = 1220, -- Suramar Withered Scenario
[1662] = 1220, -- Suramar Invasion Scenario
-- BfA
[2213] = 0, -- Horrific Vision of Stormwind
[2241] = 1, -- Uldum N'zoth assault
[2274] = 1, -- Uldum N'zoth Minor Vision
[2275] = 870, -- Vale of Eternal Blossoms N'zoth Minor Vision
}
local dynamicInstanceIDOverrides = {}
instanceIDOverrides = setmetatable(instanceIDOverrides, { __index = dynamicInstanceIDOverrides })
local function overrideInstance(instance) return instanceIDOverrides[instance] or instance end
-- debug only
HereBeDragons.___DIIDO = dynamicInstanceIDOverrides
-- gather map info, but only if this isn't an upgrade (or the upgrade version forces a re-map)
if not oldversion or oldversion < 34 then
-- wipe old data, if required, otherwise the upgrade path isn't triggered
if oldversion then
wipe(mapData)
wipe(worldMapData)
wipe(transforms)
wipe(instanceZones)
end
-- map transform data extracted from UIMapAssignment.db2 (see HereBeDragons-Scripts on GitHub)
-- format: instanceID, newInstanceID, minY, maxY, minX, maxX, offsetY, offsetX
local transformData
if WoWClassic then
transformData = {}
elseif WoWBC or WoWWrath or WoWCata then
transformData = {
{ 530, 0, 4800, 16000, -10133.3, -2666.67, -2400, 2662.8 },
{ 530, 1, -6933.33, 533.33, -16000, -8000, 10339.7, 17600 },
}
elseif WoWMists then
transformData = {
{ 530, 1, -6933.33, 533.33, -16000, -8000, 10339.7, 17600 },
{ 530, 0, 4800, 16000, -10133.3, -2666.67, -2400, 2662.8 },
{ 1014, 870, 3200, 5333.3, 1066.7, 2666.7, 0, 0 },
-- { 1064, 870, 5391, 8148, 3518, 7655, -2134.2, -2286.6 }, -- end of MoP values when Timeless Isle is out
}
else
transformData = {
{ 530, 0, 4800, 16000, -10133.3, -2666.67, -2400, 2400 },
{ 530, 1, -6933.33, 533.33, -16000, -8000, 9916, 17600 },
{ 1014, 870, 3200, 5333.3, 1066.7, 2666.7, 0, 0 },
{ 1208, 1116, -2666, -2133, -2133, -1600, 10210.7, 2411.4 },
{ 1460, 1220, -1066.7, 2133.3, 0, 3200, -2333.9, 966.7 },
{ 1498, 1220, -533.3, 2133.3, 3733.3, 5866.7, 0, 0 },
{ 1545, 1220, -2666.7, 0, 4800, 8000, 0, -0 },
{ 1599, 1, 4800, 5866.7, -4266.7, -3200, -490.6, -0.4 },
}
end
local function processTransforms()
for _, transform in pairs(transformData) do
local instanceID, newInstanceID, minY, maxY, minX, maxX, offsetY, offsetX = unpack(transform)
if not transforms[instanceID] then
transforms[instanceID] = {}
end
table.insert(transforms[instanceID], { newInstanceID = newInstanceID, minY = minY, maxY = maxY, minX = minX, maxX = maxX, offsetY = offsetY, offsetX = offsetX })
end
end
local function applyMapTransforms(instanceID, left, right, top, bottom)
if transforms[instanceID] then
for _, data in ipairs(transforms[instanceID]) do
if left <= data.maxX and right >= data.minX and top <= data.maxY and bottom >= data.minY then
instanceID = data.newInstanceID
left = left + data.offsetX
right = right + data.offsetX
top = top + data.offsetY
bottom = bottom + data.offsetY
break
end
end
end
return instanceID, left, right, top, bottom
end
local vector00, vector05 = CreateVector2D(0, 0), CreateVector2D(0.5, 0.5)
-- gather the data of one map (by uiMapID)
local function processMap(id, data, parent)
if not id or mapData[id] then return end
if not data then
data = C_Map.GetMapInfo(id)
if not data then return end
end
if data.parentMapID and data.parentMapID ~= 0 then
parent = data.parentMapID
elseif not parent then
parent = 0
end
-- get two positions from the map, we use 0/0 and 0.5/0.5 to avoid issues on some maps where 1/1 is translated inaccurately
local instance, center = C_Map.GetWorldPosFromMapPos(id, vector05)
local width, height
if C_Map.GetMapWorldSize then
width, height = C_Map.GetMapWorldSize(id)
else
-- compat for classic... why does that not have GetMapWorldSize?
local _, topleft = C_Map.GetWorldPosFromMapPos(id, vector00)
if center and topleft then
local top, left = topleft:GetXY()
local bottom, right = center:GetXY()
width = (left - right) * 2
height = (top - bottom) * 2
end
end
if center and width and height then
local top, left = center:GetXY()
top = top + (height / 2)
local bottom = top - height
left = left + (width / 2)
local right = left - width
instance, left, right, top, bottom = applyMapTransforms(instance, left, right, top, bottom)
mapData[id] = {left - right, top - bottom, left, top, instance = instance, name = data.name, mapType = data.mapType, parent = parent }
else
mapData[id] = {0, 0, 0, 0, instance = instance or -1, name = data.name, mapType = data.mapType, parent = parent }
end
-- check for zones that are a different instance as their parent continent
if data.mapType == Enum.UIMapType.Zone and mapData[parent] and mapData[parent].mapType == Enum.UIMapType.Continent and instance >= 0 and mapData[parent].instance >= 0 and instance ~= mapData[parent].instance then
local minX, maxX, minY, maxY = C_Map.GetMapRectOnMap(id, parent)
if minX and maxX and minY and maxY and maxX > 0 and maxY > 0 then
mapData[id].rectOnParent = { minX = minX, maxX = maxX, minY = minY, maxY = maxY, parentInstance = mapData[parent].instance }
if not instanceZones[instance] then
instanceZones[instance] = {}
end
if not instanceZones[instance][mapData[parent].instance] then
instanceZones[instance][mapData[parent].instance] = {}
end
table.insert(instanceZones[instance][mapData[parent].instance], id)
end
end
end
local function processMapChildrenRecursive(parent)
local children = C_Map.GetMapChildrenInfo(parent)
if children and #children > 0 then
for i = 1, #children do
local id = children[i].mapID
if id and not mapData[id] then
processMap(id, children[i], parent)
processMapChildrenRecursive(id)
-- process sibling maps (in the same group)
-- in some cases these are not discovered by GetMapChildrenInfo above
local groupID = C_Map.GetMapGroupID(id)
if groupID then
local groupMembers = C_Map.GetMapGroupMembersInfo(groupID)
if groupMembers then
for k = 1, #groupMembers do
local memberId = groupMembers[k].mapID
if memberId and not mapData[memberId] then
processMap(memberId, nil, parent)
processMapChildrenRecursive(memberId)
end
end
end
end
end
end
end
end
---Derives an instance's Azeroth bounds from its continent bounds and Blizzard's displayed rectangle.
---@param continentMapID number
---@return nil
local function updateClassicWorldMapData(continentMapID)
if not C_Map.GetMapRectOnMap then return end
local data = mapData[continentMapID]
if not data or data[1] <= 0 or data[2] <= 0 then return end
local minX, maxX, minY, maxY = C_Map.GetMapRectOnMap(continentMapID, WORLD_MAP_ID)
if not (minX and maxX and minY and maxY and maxX > minX and maxY > minY) then return end
-- Rectangles may extend outside 0..1; that is valid for continent maps and must not be clamped.
local width = data[1] / (maxX - minX)
local height = data[2] / (maxY - minY)
worldMapData[data.instance] = {width, height, data[3] + width * minX, data[4] + height * minY}
end
local function fixupZones()
local cosmic = C_Map.GetMapInfo(COSMIC_MAP_ID)
if cosmic then
mapData[COSMIC_MAP_ID] = {0, 0, 0, 0}
mapData[COSMIC_MAP_ID].instance = -1
mapData[COSMIC_MAP_ID].name = cosmic.name
mapData[COSMIC_MAP_ID].mapType = cosmic.mapType
end
-- data for the azeroth world map
if WoWClassic then
worldMapData[0] = { 44688.53, 29795.11, 32601.04, 9894.93 }
worldMapData[1] = { 44878.66, 29916.10, 8723.96, 14824.53 }
-- Calibrate Era and Forever independently. Retain the legacy bounds only when the API has no usable rectangle.
updateClassicWorldMapData(1415) -- Eastern Kingdoms
updateClassicWorldMapData(1414) -- Kalimdor
elseif WoWBC then
worldMapData[0] = { 44688.53, 29791.24, 32681.47, 11479.44 }
worldMapData[1] = { 44878.66, 29916.10, 8723.96, 14824.53 }
elseif WoWWrath then
worldMapData[0] = { 48033.24, 32020.8, 36867.97, 14848.84 }
worldMapData[1] = { 47908.72, 31935.28, 8552.61, 18467.83 }
worldMapData[571] = { 47662.7, 31772.19, 25198.53, 11072.07 }
elseif WoWCata then
worldMapData[0] = { 48033.24, 32020.8, 36867.97, 14848.84 }
worldMapData[1] = { 47908.72, 31935.28, 8552.61, 18467.83 }
worldMapData[571] = { 47662.7, 31772.19, 25198.53, 11072.07 }
elseif WoWMists then
worldMapData[0] = { 57114.85, 38082.53, 46284.08, 15795.1 }
worldMapData[1] = { 58984.3, 39319.22, 10153.84, 19536.12 }
worldMapData[571] = { 56338.03, 37567.89, 29892.96, 11496.56 }
worldMapData[870] = { 53103.22, 35408.03, 28648.8, 30726.23 }
else
worldMapData[0] = { 76153.14, 50748.62, 65008.24, 23827.51 }
worldMapData[1] = { 77621.12, 51854.98, 12444.4, 28030.61 }
worldMapData[571] = { 71773.64, 50054.05, 36205.94, 12366.81 }
worldMapData[870] = { 67710.54, 45118.08, 33565.89, 38020.67 }
worldMapData[1220] = { 82758.64, 55151.28, 52943.46, 24484.72 }
worldMapData[1642] = { 77933.3, 51988.91, 44262.36, 32835.1 }
worldMapData[1643] = { 76060.47, 50696.96, 55384.8, 25774.35 }
worldMapData[2444] = { 111420.37, 74283, 86088.21, 15682.4 }
worldMapData[2552] = { 82171.44, 54787.67, 21219.3, 47876.05 }
worldMapData[2601] = { 67929.29, 49267.42, 18325.63, 42233.06 }
end
end
local function gatherMapData()
processTransforms()
-- find all maps in well known structures
if WoWClassic then
processMap(WORLD_MAP_ID)
processMapChildrenRecursive(WORLD_MAP_ID)
else
processMapChildrenRecursive(COSMIC_MAP_ID)
end
fixupZones()
-- try to fill in holes in the map list
for i = 1, 2500 do
if not mapData[i] then
local mapInfo = C_Map.GetMapInfo(i)
if mapInfo and mapInfo.name then
processMap(i, mapInfo, nil)
end
end
end
end
gatherMapData()
end
-- Transform a set of coordinates based on the defined map transformations
local function applyCoordinateTransforms(x, y, instanceID)
if transforms[instanceID] then
for _, transformData in ipairs(transforms[instanceID]) do
if transformData.minX <= x and transformData.maxX >= x and transformData.minY <= y and transformData.maxY >= y then
instanceID = transformData.newInstanceID
x = x + transformData.offsetX
y = y + transformData.offsetY
break
end
end
end
return x, y, overrideInstance(instanceID)
end
local StartUpdateTimer
local function UpdateCurrentPosition(instanceCheck)
-- retrieve current zone
local uiMapID = C_Map.GetBestMapForUnit("player")
-- try to override the instance if possible
if instanceCheck then
local _x, _y, instance = HereBeDragons:GetPlayerWorldPosition()
if instance and instance ~= -1 and mapData[uiMapID] and mapData[uiMapID].instance ~= instance and uiMapID ~= -1 and not instanceIDOverrides[instance] and not instanceIDOverrides[mapData[uiMapID].instance] then
dynamicInstanceIDOverrides[instance] = mapData[uiMapID].instance
end
end
if uiMapID ~= currentPlayerUIMapID then
-- update location upvalues
currentPlayerUIMapID, currentPlayerUIMapType = uiMapID, mapData[uiMapID] and mapData[uiMapID].mapType or 0
-- signal callback
HereBeDragons.callbacks:Fire("PlayerZoneChanged", currentPlayerUIMapID, currentPlayerUIMapType)
end
-- start a timer to update in micro dungeons since multi-level micro dungeons do not reliably fire events
if currentPlayerUIMapType == Enum.UIMapType.Micro then
StartUpdateTimer()
end
end
-- upgradeable timer callback, don't want to keep calling the old function if the library is upgraded
HereBeDragons.UpdateCurrentPosition = UpdateCurrentPosition
local function UpdateTimerCallback()
-- signal that the timer ran
HereBeDragons.updateTimerActive = nil
-- run update now
HereBeDragons.UpdateCurrentPosition()
end
function StartUpdateTimer()
if not HereBeDragons.updateTimerActive then
-- prevent running multiple timers
HereBeDragons.updateTimerActive = true
-- and queue an update
C_Timer.After(1, UpdateTimerCallback)
end
end
local function OnEvent(frame, event, ...)
local instanceCheck = false
if event == "ZONE_CHANGED_NEW_AREA" then
instanceCheck = true
elseif event == "PLAYER_ENTERING_WORLD" then
local initial, reload = ...
instanceCheck = (initial or reload)
end
UpdateCurrentPosition(instanceCheck)
-- try to work around missing zone changes where the event fires before the zone updates
StartUpdateTimer()
end
HereBeDragons.eventFrame:SetScript("OnEvent", OnEvent)
HereBeDragons.eventFrame:UnregisterAllEvents()
HereBeDragons.eventFrame:RegisterEvent("ZONE_CHANGED_NEW_AREA")
HereBeDragons.eventFrame:RegisterEvent("ZONE_CHANGED")
HereBeDragons.eventFrame:RegisterEvent("ZONE_CHANGED_INDOORS")
HereBeDragons.eventFrame:RegisterEvent("NEW_WMO_CHUNK")
HereBeDragons.eventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
--- Return the localized zone name for a given uiMapID
-- @param uiMapID uiMapID of the zone
function HereBeDragons:GetLocalizedMap(uiMapID)
return mapData[uiMapID] and mapData[uiMapID].name or nil
end
--- Get the size of the zone
-- @param uiMapID uiMapID of the zone
-- @return width, height of the zone, in yards
function HereBeDragons:GetZoneSize(uiMapID)
local data = mapData[uiMapID]
if not data then return 0, 0 end
return data[1], data[2]
end
--- Get a list of all map IDs
-- @return array-style table with all known/valid map IDs
function HereBeDragons:GetAllMapIDs()
local t = {}
for id in pairs(mapData) do
table.insert(t, id)
end
return t
end
--- Convert local/point coordinates to world coordinates in yards
-- @param x X position in 0-1 point coordinates
-- @param y Y position in 0-1 point coordinates
-- @param zone uiMapID of the zone
function HereBeDragons:GetWorldCoordinatesFromZone(x, y, zone)
local data = mapData[zone]
if not data or data[1] == 0 or data[2] == 0 then return nil, nil, nil end
if not x or not y then return nil, nil, nil end
local width, height, left, top = data[1], data[2], data[3], data[4]
x, y = left - width * x, top - height * y
return x, y, overrideInstance(data.instance)
end
--- Convert local/point coordinates to world coordinates in yards. The coordinates have to come from the Azeroth World Map
-- @param x X position in 0-1 point coordinates
-- @param y Y position in 0-1 point coordinates
-- @param instance Instance to use for the world coordinates
function HereBeDragons:GetWorldCoordinatesFromAzerothWorldMap(x, y, instance)
local data = worldMapData[instance]
if not data or data[1] == 0 or data[2] == 0 then return nil, nil, nil end
if not x or not y then return nil, nil, nil end
local width, height, left, top = data[1], data[2], data[3], data[4]
x, y = left - width * x, top - height * y
return x, y, instance
end
--- Convert world coordinates to local/point zone coordinates
-- @param x Global X position
-- @param y Global Y position
-- @param zone uiMapID of the target zone
-- @param allowOutOfBounds Allow coordinates to go beyond the current map (ie. outside of the 0-1 range), otherwise nil will be returned
-- @deprecated Use GetZoneCoordinatesFromWorldInstance instead
function HereBeDragons:GetZoneCoordinatesFromWorld(x, y, zone, allowOutOfBounds)
local data = mapData[zone]
if not data or data[1] == 0 or data[2] == 0 then return nil, nil end
if not x or not y then return nil, nil end
return self:GetZoneCoordinatesFromWorldInstance(x, y, data.instance, zone, allowOutOfBounds)
end
local function TranslateInstanceZone(self, zoneList, x, y)
for _, id in pairs(zoneList) do
local x1, y1 = self:GetZoneCoordinatesFromWorldInstance(x, y, mapData[id].instance, id)
if x1 and y1 then
x1, y1 = Lerp(mapData[id].rectOnParent.minX, mapData[id].rectOnParent.maxX, x1), Lerp(mapData[id].rectOnParent.minY, mapData[id].rectOnParent.maxY, y1)
return self:GetWorldCoordinatesFromZone(x1, y1, mapData[id].parent)
end
end
end
--- Convert world coordinates to local/point zone coordinates
-- @param x Global X position
-- @param y Global Y position
-- @param instance World instance of the X/Y coordinates
-- @param zone uiMapID of the target zone
-- @param allowOutOfBounds Allow coordinates to go beyond the current map (ie. outside of the 0-1 range), otherwise nil will be returned
function HereBeDragons:GetZoneCoordinatesFromWorldInstance(x, y, instance, zone, allowOutOfBounds)
if zone == WORLD_MAP_ID then -- we can support this, so we should, even if the dedicated API exists
return self:GetAzerothWorldMapCoordinatesFromWorld(x, y, instance, allowOutOfBounds)
end
local data = mapData[zone]
if not data or data[1] == 0 or data[2] == 0 then return nil, nil end
if not x or not y then return nil, nil end
local targetInstance = data.instance
if targetInstance ~= instance then
if instanceZones[instance] and instanceZones[instance][targetInstance] then
x, y, instance = TranslateInstanceZone(self, instanceZones[instance][targetInstance], x, y)
end
if targetInstance ~= instance then
return nil, nil
end
end
local width, height, left, top = data[1], data[2], data[3], data[4]
x, y = (left - x) / width, (top - y) / height
-- verify the coordinates fall into the zone
if not allowOutOfBounds and (x < 0 or x > 1 or y < 0 or y > 1) then return nil, nil end
return x, y
end
--- Convert world coordinates to local/point zone coordinates on the azeroth world map
-- @param x Global X position
-- @param y Global Y position
-- @param instance Instance to translate coordinates from
-- @param allowOutOfBounds Allow coordinates to go beyond the current map (ie. outside of the 0-1 range), otherwise nil will be returned
function HereBeDragons:GetAzerothWorldMapCoordinatesFromWorld(x, y, instance, allowOutOfBounds)
-- try to translate an instanced zone to a supported instance
if not worldMapData[instance] and instanceZones[instance] then
for k, zoneList in pairs(instanceZones[instance]) do
if worldMapData[k] then
x, y, instance = TranslateInstanceZone(self, zoneList, x, y)
break
end
end
end
local data = worldMapData[instance]
if not data or data[1] == 0 or data[2] == 0 then return nil, nil end
if not x or not y then return nil, nil end
local width, height, left, top = data[1], data[2], data[3], data[4]
x, y = (left - x) / width, (top - y) / height
-- verify the coordinates fall into the zone
if not allowOutOfBounds and (x < 0 or x > 1 or y < 0 or y > 1) then return nil, nil end
return x, y
end
-- Helper function to handle world map coordinate translation
local function TranslateAzerothWorldMapCoordinates(self, x, y, oZone, dZone, allowOutOfBounds)
if (oZone ~= WORLD_MAP_ID and not mapData[oZone]) or (dZone ~= WORLD_MAP_ID and not mapData[dZone]) then return nil, nil end
-- determine the instance we're working with
local instance = overrideInstance((oZone == WORLD_MAP_ID) and mapData[dZone].instance or mapData[oZone].instance)
if not worldMapData[instance] then return nil, nil end
if oZone == WORLD_MAP_ID then
x, y = self:GetWorldCoordinatesFromAzerothWorldMap(x, y, instance)
return self:GetZoneCoordinatesFromWorldInstance(x, y, instance, dZone, allowOutOfBounds)
else
x, y = self:GetWorldCoordinatesFromZone(x, y, oZone)
return self:GetAzerothWorldMapCoordinatesFromWorld(x, y, instance, allowOutOfBounds)
end
end
--- Translate zone coordinates from one zone to another
-- @param x X position in 0-1 point coordinates, relative to the origin zone
-- @param y Y position in 0-1 point coordinates, relative to the origin zone
-- @param oZone Origin Zone, uiMapID
-- @param dZone Destination Zone, uiMapID
-- @param allowOutOfBounds Allow coordinates to go beyond the current map (ie. outside of the 0-1 range), otherwise nil will be returned
function HereBeDragons:TranslateZoneCoordinates(x, y, oZone, dZone, allowOutOfBounds)
if oZone == dZone then return x, y end
if oZone == WORLD_MAP_ID or dZone == WORLD_MAP_ID then
return TranslateAzerothWorldMapCoordinates(self, x, y, oZone, dZone, allowOutOfBounds)
end
local data = mapData[dZone]
local data_origin = mapData[oZone]
if not data or not data_origin then return nil, nil end
-- todo: short circuit some translation here for instanceZones
local xCoord, yCoord, instance = self:GetWorldCoordinatesFromZone(x, y, oZone)
if not xCoord then return nil, nil end
return self:GetZoneCoordinatesFromWorldInstance(xCoord, yCoord, instance, dZone, allowOutOfBounds)
end
--- Return the distance from an origin position to a destination position in the same instance/continent.
-- @param instanceID instance ID
-- @param oX origin X
-- @param oY origin Y
-- @param dX destination X
-- @param dY destination Y
-- @return distance, deltaX, deltaY
function HereBeDragons:GetWorldDistance(instanceID, oX, oY, dX, dY)
if not oX or not oY or not dX or not dY then return nil, nil, nil end
local deltaX, deltaY = dX - oX, dY - oY
return (deltaX * deltaX + deltaY * deltaY)^0.5, deltaX, deltaY
end
--- Return the distance between two points on the same continent
-- @param oZone origin zone uiMapID
-- @param oX origin X, in local zone/point coordinates
-- @param oY origin Y, in local zone/point coordinates
-- @param dZone destination zone uiMapID
-- @param dX destination X, in local zone/point coordinates
-- @param dY destination Y, in local zone/point coordinates
-- @return distance, deltaX, deltaY in yards
function HereBeDragons:GetZoneDistance(oZone, oX, oY, dZone, dX, dY)
local oInstance, dInstance
oX, oY, oInstance = self:GetWorldCoordinatesFromZone(oX, oY, oZone)
if not oX then return nil, nil, nil end
-- translate dX, dY to the origin zone
dX, dY, dInstance = self:GetWorldCoordinatesFromZone(dX, dY, dZone)
if not dX then return nil, nil, nil end
if oInstance ~= dInstance then return nil, nil, nil end
return self:GetWorldDistance(oInstance, oX, oY, dX, dY)
end
--- Return the angle and distance from an origin position to a destination position in the same instance/continent.
-- @param instanceID instance ID
-- @param oX origin X
-- @param oY origin Y
-- @param dX destination X
-- @param dY destination Y
-- @return angle, distance where angle is in radians and distance in yards
function HereBeDragons:GetWorldVector(instanceID, oX, oY, dX, dY)
local distance, deltaX, deltaY = self:GetWorldDistance(instanceID, oX, oY, dX, dY)
if not distance then return nil, nil end
-- calculate the angle from deltaY and deltaX
local angle = atan2(-deltaX, deltaY)
-- normalize the angle
if angle > 0 then
angle = PI2 - angle
else
angle = -angle
end
return angle, distance
end
--- Get the current world position of the specified unit
-- The position is transformed to the current continent, if applicable
-- NOTE: The same restrictions as for the UnitPosition() API apply,
-- which means a very limited set of unit ids will actually work.
-- @param unitId Unit Id
-- @return x, y, instanceID
function HereBeDragons:GetUnitWorldPosition(unitId)
-- get the current position
local y, x, _z, instanceID = UnitPosition(unitId)
if not x or not y then return nil, nil, overrideInstance(instanceID) end
-- return transformed coordinates
return applyCoordinateTransforms(x, y, instanceID)
end
--- Get the current world position of the player
-- The position is transformed to the current continent, if applicable
-- @return x, y, instanceID
function HereBeDragons:GetPlayerWorldPosition()
-- get the current position
local y, x, _z, instanceID = UnitPosition("player")
if not x or not y then return nil, nil, overrideInstance(instanceID) end
-- return transformed coordinates
return applyCoordinateTransforms(x, y, instanceID)
end
--- Get the current zone and level of the player
-- The returned mapFile can represent a micro dungeon, if the player currently is inside one.
-- @return uiMapID, mapType
function HereBeDragons:GetPlayerZone()
return currentPlayerUIMapID, currentPlayerUIMapType
end
--- Get the current position of the player on a zone level
-- The returned values are local point coordinates, 0-1. The mapFile can represent a micro dungeon.
-- @param allowOutOfBounds Allow coordinates to go beyond the current map (ie. outside of the 0-1 range), otherwise nil will be returned
-- @return x, y, uiMapID, mapType
function HereBeDragons:GetPlayerZonePosition(allowOutOfBounds)
if not currentPlayerUIMapID then return nil, nil, nil, nil end
local x, y, instanceID = self:GetPlayerWorldPosition()
if not x or not y then return nil, nil, nil, nil end
x, y = self:GetZoneCoordinatesFromWorldInstance(x, y, instanceID, currentPlayerUIMapID, allowOutOfBounds)
if x and y then
return x, y, currentPlayerUIMapID, currentPlayerUIMapType
end
return nil, nil, nil, nil
end
-- if we're loading after entering the world (ie. on demand), update position now
-- This needs to remain at the bottom of the library to ensure all functions are loaded before they are needed
if IsLoggedIn() then
UpdateCurrentPosition(true)
end

View file

@ -0,0 +1,865 @@
-- HereBeDragons-Pins is a library to show pins/icons on the world map and minimap
local MAJOR, MINOR = "HereBeDragonsQuestie-Pins-2.0", 16
assert(LibStub, MAJOR .. " requires LibStub")
local pins, oldversion = LibStub:NewLibrary(MAJOR, MINOR)
if not pins then return end
local HBD = LibStub("HereBeDragonsQuestie-2.0")
local MinimapRadiusAPI = C_Minimap and C_Minimap.GetViewRadius
pins.updateFrame = pins.updateFrame or CreateFrame("Frame")
-- storage for minimap pins
pins.minimapPins = pins.minimapPins or {}
pins.activeMinimapPins = pins.activeMinimapPins or {}
pins.minimapPinRegistry = pins.minimapPinRegistry or {}
-- and worldmap pins
pins.worldmapPins = pins.worldmapPins or {}
pins.worldmapPinRegistry = pins.worldmapPinRegistry or {}
pins.worldmapIconPins = pins.worldmapIconPins or {} -- Questie modification: icon -> acquired pin
pins.worldmapProvider = pins.worldmapProvider or CreateFromMixins(MapCanvasDataProviderMixin)
pins.worldmapProviderPin = pins.worldmapProviderPin or CreateFromMixins(MapCanvasPinMixin)
-- make sure the pool is refreshed
if oldversion and oldversion < 15 and pins.worldmapProvider and CreateUnsecuredRegionPoolInstance then
pins.worldmapProvider:RemoveAllData()
pins.worldmapPinsPool = nil
end
if not pins.worldmapPinsPool then
-- new frame pools in WoW 11.x
if CreateUnsecuredRegionPoolInstance then
pins.worldmapPinsPool = CreateUnsecuredRegionPoolInstance("HereBeDragonsPinsTemplateQuestie")
else
pins.worldmapPinsPool = CreateFramePool("FRAME")
end
end
-- store a reference to the active minimap object
pins.Minimap = pins.Minimap or Minimap
-- Data Constants
local WORLD_MAP_ID = 947
-- upvalue lua api
local cos, sin, max = math.cos, math.sin, math.max
local type, pairs = type, pairs
-- upvalue wow api
local GetPlayerFacing = GetPlayerFacing
-- upvalue data tables
local minimapPins = pins.minimapPins
local activeMinimapPins = pins.activeMinimapPins
local minimapPinRegistry = pins.minimapPinRegistry
local worldmapPins = pins.worldmapPins
local worldmapPinRegistry = pins.worldmapPinRegistry
local worldmapIconPins = pins.worldmapIconPins
local worldmapPinsPool = pins.worldmapPinsPool
local worldmapProvider = pins.worldmapProvider
local worldmapProviderPin = pins.worldmapProviderPin
local minimap_size = {
indoor = {
[0] = 300, -- scale
[1] = 240, -- 1.25
[2] = 180, -- 5/3
[3] = 120, -- 2.5
[4] = 80, -- 3.75
[5] = 50, -- 6
},
outdoor = {
[0] = 466 + 2/3, -- scale
[1] = 400, -- 7/6
[2] = 333 + 1/3, -- 1.4
[3] = 266 + 2/6, -- 1.75
[4] = 200, -- 7/3
[5] = 133 + 1/3, -- 3.5
},
}
local minimap_shapes = {
-- { upper-left, lower-left, upper-right, lower-right }
["SQUARE"] = { false, false, false, false },
["CORNER-TOPLEFT"] = { true, false, false, false },
["CORNER-TOPRIGHT"] = { false, false, true, false },
["CORNER-BOTTOMLEFT"] = { false, true, false, false },
["CORNER-BOTTOMRIGHT"] = { false, false, false, true },
["SIDE-LEFT"] = { true, true, false, false },
["SIDE-RIGHT"] = { false, false, true, true },
["SIDE-TOP"] = { true, false, true, false },
["SIDE-BOTTOM"] = { false, true, false, true },
["TRICORNER-TOPLEFT"] = { true, true, true, false },
["TRICORNER-TOPRIGHT"] = { true, false, true, true },
["TRICORNER-BOTTOMLEFT"] = { true, true, false, true },
["TRICORNER-BOTTOMRIGHT"] = { false, true, true, true },
}
local tableCache = setmetatable({}, {__mode='k'})
local function newCachedTable()
local t = next(tableCache)
if t then
tableCache[t] = nil
else
t = {}
end
return t
end
local function recycle(t)
tableCache[t] = true
end
-------------------------------------------------------------------------------------------
-- Minimap pin position logic
-- minimap rotation
local rotateMinimap = GetCVar("rotateMinimap") == "1"
-- is the minimap indoors or outdoors
local indoors = GetCVar("minimapZoom")+0 == pins.Minimap:GetZoom() and "outdoor" or "indoor"
local minimapPinCount, queueFullUpdate = 0, false
local minimapScale, minimapShape, mapRadius, minimapWidth, minimapHeight, mapSin, mapCos
local lastZoom, lastFacing, lastXY, lastYY
local function drawMinimapPin(pin, data)
local xDist, yDist = lastXY - data.x, lastYY - data.y
-- handle rotation
if rotateMinimap then
local dx, dy = xDist, yDist
xDist = dx*mapCos - dy*mapSin
yDist = dx*mapSin + dy*mapCos
end
-- adapt delta position to the map radius
local diffX = xDist / mapRadius
local diffY = yDist / mapRadius
-- different minimap shapes
local isRound = true
if minimapShape and not (xDist == 0 or yDist == 0) then
isRound = (xDist < 0) and 1 or 3
if yDist < 0 then
isRound = minimapShape[isRound]
else
isRound = minimapShape[isRound + 1]
end
end
-- calculate distance from the center of the map
local dist
if isRound then
dist = (diffX*diffX + diffY*diffY) / 0.9^2
else
dist = max(diffX*diffX, diffY*diffY) / 0.9^2
end
-- if distance > 1, then adapt node position to slide on the border
if dist > 1 and data.floatOnEdge then
dist = dist^0.5
diffX = diffX/dist
diffY = diffY/dist
end
-- Questie Modification.
-- data.floatOnEdge is replaced by (data.floatOnEdge and ((pin.texture and pin.texture.a and pin.texture.a ~= 0) or pin.texture == nil))
-- icons will now only float on edge if they have an opacity which is not 0 or if no texture exist.
data.distanceFromMinimapCenter = dist
if dist <= 1 or (data.floatOnEdge and ((pin.texture and pin.texture.a and pin.texture.a ~= 0) or pin.texture == nil)) then
pin:Show()
pin:ClearAllPoints()
pin:SetPoint("CENTER", pins.Minimap, "CENTER", diffX * minimapWidth, -diffY * minimapHeight)
data.onEdge = (dist > 1)
else
pin:Hide()
data.onEdge = nil
pin.keep = nil
end
end
local function IsParentMap(originMapId, toCheckMapId)
local parentMapID = HBD.mapData[originMapId].parent
while parentMapID and HBD.mapData[parentMapID] do
local mapType = HBD.mapData[parentMapID].mapType
if mapType ~= Enum.UIMapType.Zone and mapType ~= Enum.UIMapType.Dungeon and mapType ~= Enum.UIMapType.Micro then
return false
end
if parentMapID == toCheckMapId then
return true
end
parentMapID = HBD.mapData[parentMapID].parent
end
return false
end
local function UpdateMinimapPins(force)
-- get the current player position
local x, y, instanceID = HBD:GetPlayerWorldPosition()
local mapID = HBD:GetPlayerZone()
-- get data from the API for calculations
local zoom = pins.Minimap:GetZoom()
local diffZoom = zoom ~= lastZoom
-- for rotating minimap support
local facing
if rotateMinimap then
facing = GetPlayerFacing()
else
facing = lastFacing
end
-- check for all values to be available (starting with 7.1.0, instances don't report coordinates)
if not x or not y or (rotateMinimap and not facing) then
minimapPinCount = 0
for pin in pairs(activeMinimapPins) do
pin:Hide()
activeMinimapPins[pin] = nil
end
return
end
local newScale = pins.Minimap:GetScale()
if minimapScale ~= newScale then
minimapScale = newScale
force = true
end
if x ~= lastXY or y ~= lastYY or diffZoom or facing ~= lastFacing or force then
-- minimap information
minimapShape = GetMinimapShape and minimap_shapes[GetMinimapShape() or "ROUND"]
minimapWidth = pins.Minimap:GetWidth() / 2
minimapHeight = pins.Minimap:GetHeight() / 2
if MinimapRadiusAPI then
mapRadius = C_Minimap.GetViewRadius()
else
mapRadius = minimap_size[indoors][zoom] / 2
end
-- update upvalues for icon placement
lastZoom = zoom
lastFacing = facing
lastXY, lastYY = x, y
if rotateMinimap then
mapSin = sin(facing)
mapCos = cos(facing)
end
for pin, data in pairs(minimapPins) do
if data.instanceID == instanceID and math.abs(x-data.x) + math.abs(y-data.y) < 500 then -- questie specific fix
activeMinimapPins[pin] = data
data.keep = true
-- draw the pin (this may reset data.keep if outside of the map)
drawMinimapPin(pin, data)
end
end
minimapPinCount = 0
for pin, data in pairs(activeMinimapPins) do
if not data.keep then
pin:Hide()
activeMinimapPins[pin] = nil
else
minimapPinCount = minimapPinCount + 1
data.keep = nil
end
end
end
end
local function UpdateMinimapIconPosition()
-- get the current map zoom
local zoom = pins.Minimap:GetZoom()
local diffZoom = zoom ~= lastZoom
-- if the map zoom changed, run a full update sweep
if diffZoom then
UpdateMinimapPins()
return
end
-- we have no active minimap pins, just return early
if minimapPinCount == 0 then return end
local x, y = HBD:GetPlayerWorldPosition()
-- for rotating minimap support
local facing
if rotateMinimap then
facing = GetPlayerFacing()
else
facing = lastFacing
end
-- check for all values to be available (starting with 7.1.0, instances don't report coordinates)
if not x or not y or (rotateMinimap and not facing) then
UpdateMinimapPins()
return
end
local refresh
local newScale = pins.Minimap:GetScale()
if minimapScale ~= newScale then
minimapScale = newScale
refresh = true
end
if x ~= lastXY or y ~= lastYY or facing ~= lastFacing or refresh then
-- update radius of the map
if MinimapRadiusAPI then
mapRadius = C_Minimap.GetViewRadius()
else
mapRadius = minimap_size[indoors][zoom] / 2
end
-- update upvalues for icon placement
lastXY, lastYY = x, y
lastFacing = facing
if rotateMinimap then
mapSin = sin(facing)
mapCos = cos(facing)
end
-- iterate all nodes and check if they are still in range of our minimap display
for pin, data in pairs(activeMinimapPins) do
-- update the position of the node
drawMinimapPin(pin, data)
end
end
end
local function UpdateMinimapZoom()
if not MinimapRadiusAPI then
local zoom = pins.Minimap:GetZoom()
if GetCVar("minimapZoom") == GetCVar("minimapInsideZoom") then
pins.Minimap:SetZoom(zoom < 2 and zoom + 1 or zoom - 1)
end
indoors = GetCVar("minimapZoom")+0 == pins.Minimap:GetZoom() and "outdoor" or "indoor"
pins.Minimap:SetZoom(zoom)
end
end
-------------------------------------------------------------------------------------------
-- WorldMap data provider
-- setup pin pool
worldmapPinsPool.parent = WorldMapFrame:GetCanvas()
worldmapPinsPool.createFunc = function()
local frame = CreateFrame("Frame", nil, WorldMapFrame:GetCanvas())
frame:SetSize(1, 1)
return Mixin(frame, worldmapProviderPin)
end
worldmapPinsPool.resetFunc = function(pinPool, pin)
pin:Hide()
pin:ClearAllPoints()
pin:OnReleased()
pin.pinTemplate = nil
pin.owningMap = nil
end
-- pre-11.x func names
worldmapPinsPool.creationFunc = worldmapPinsPool.createFunc
worldmapPinsPool.resetterFunc = worldmapPinsPool.resetFunc
-- register pin pool with the world map
WorldMapFrame.pinPools["HereBeDragonsPinsTemplateQuestie"] = worldmapPinsPool
-- provider base API
function worldmapProvider:RemoveAllData()
self:GetMap():RemoveAllPinsByTemplate("HereBeDragonsPinsTemplateQuestie")
end
-- Questie modification: look up the pin directly instead of scanning all pins, which made bulk removal O(n^2)
function worldmapProvider:RemovePinByIcon(icon)
local pin = worldmapIconPins[icon]
if pin and pin.icon == icon then
self:GetMap():RemovePin(pin)
end
end
function worldmapProvider:RemovePinsByRef(ref)
for pin in self:GetMap():EnumeratePinsByTemplate("HereBeDragonsPinsTemplateQuestie") do
if pin.icon and worldmapPinRegistry[ref][pin.icon] then
self:GetMap():RemovePin(pin)
end
end
end
-- Questie modification
local lastUiMapId = -1;
worldmapProvider.forceUpdate = false -- Put into worldmapProvider to allow addons to force update from outside of HBD.
function worldmapProvider:RefreshAllData(fromOnShow)
local mapId = self:GetMap():GetMapID()
if(lastUiMapId ~= mapId or worldmapProvider.forceUpdate) then
self:RemoveAllData()
local cacheMap = self:GetMap()
local uiMapID = cacheMap:GetMapID()
for icon, data in pairs(worldmapPins) do
self:HandlePin(icon, data, uiMapID, cacheMap)
end
--DEFAULT_CHAT_FRAME:AddMessage(mapId .. " - " .. lastUiMapId .. " : " .. tostring(worldmapProvider.forceUpdate));
lastUiMapId = mapId;
worldmapProvider.forceUpdate = false;
end
end
function worldmapProvider:HandlePin(icon, data)
-- Questie modification: an icon owns at most one pin, so re-adding must not leave the old one behind
self:RemovePinByIcon(icon)
local uiMapID = self:GetMap():GetMapID()
-- check for a valid map
if not uiMapID then return end
-- Questie modification
if (Questie.db.profile.hideIconsOnContinents == true) and (HBD.mapData[uiMapID].mapType == Enum.UIMapType.Continent or uiMapID == 947) or (uiMapID ~= data.uiMapID and data.worldMapShowFlag == HBD_PINS_WORLDMAP_SHOW_CURRENT) then
icon:Hide();
return;
elseif(uiMapID == data.uiMapID and data.worldMapShowFlag == HBD_PINS_WORLDMAP_SHOW_CURRENT) then
icon:Show();
end
local x, y
if uiMapID == WORLD_MAP_ID then
-- should this pin show on the world map?
if uiMapID ~= data.uiMapID and data.worldMapShowFlag ~= HBD_PINS_WORLDMAP_SHOW_WORLD then return end
-- Questie modification
-- Icons which already have world map coordinates are not handled correctly by GetAzerothWorldMapCoordinatesFromWorld, so we use them directly.
if icon.UiMapID == WORLD_MAP_ID then
x, y = icon.x / 100, icon.y / 100
else
-- translate to the world map
x, y = HBD:GetAzerothWorldMapCoordinatesFromWorld(data.x, data.y, data.instanceID)
end
else
-- check that there is data
if not HBD.mapData[uiMapID] then return end
if uiMapID ~= data.uiMapID then
local mapType = HBD.mapData[uiMapID].mapType
if not data.uiMapID then
if mapType == Enum.UIMapType.Continent and data.worldMapShowFlag >= HBD_PINS_WORLDMAP_SHOW_CONTINENT then
-- pass
elseif mapType ~= Enum.UIMapType.Zone and mapType ~= Enum.UIMapType.Dungeon and mapType ~= Enum.UIMapType.Micro then
-- fail
return
end
else
local show = true -- Questie fix to show icons in neighbour areas
local parentMapID = HBD.mapData[data.uiMapID].parent
while parentMapID and HBD.mapData[parentMapID] do
if parentMapID == uiMapID then
local parentMapType = HBD.mapData[parentMapID].mapType
-- show on any parent zones if they are normal zones
if data.worldMapShowFlag >= HBD_PINS_WORLDMAP_SHOW_PARENT and
(parentMapType == Enum.UIMapType.Zone or parentMapType == Enum.UIMapType.Dungeon or parentMapType == Enum.UIMapType.Micro) then
show = true
-- show on the continent
elseif data.worldMapShowFlag >= HBD_PINS_WORLDMAP_SHOW_CONTINENT and
parentMapType == Enum.UIMapType.Continent then
show = true
elseif data.worldMapShowFlag == HBD_PINS_WORLDMAP_SHOW_CURRENT then
-- Questie modification
show = false
end
break
-- worldmap is handled above already
else
parentMapID = HBD.mapData[parentMapID].parent
end
end
if not show then return end
end
end
-- translate coordinates
x, y = HBD:GetZoneCoordinatesFromWorldInstance(data.x, data.y, data.instanceID, uiMapID)
end
if x and y then
self:GetMap():AcquirePin("HereBeDragonsPinsTemplateQuestie", icon, x, y, data.frameLevelType)
end
end
-- map pin base API
function worldmapProviderPin:OnLoad()
self:UseFrameLevelType("PIN_FRAME_LEVEL_AREA_POI")
self:SetScalingLimits(1, 1.0, 1.2)
end
function worldmapProviderPin:OnAcquired(icon, x, y, frameLevelType)
self:UseFrameLevelType(frameLevelType or "PIN_FRAME_LEVEL_AREA_POI")
self:SetPosition(x, y)
self.icon = icon
worldmapIconPins[icon] = self -- Questie modification
icon:SetParent(self)
icon:ClearAllPoints()
icon:SetPoint("CENTER", self, "CENTER")
icon:Show()
end
function worldmapProviderPin:OnReleased()
if self.icon then
if worldmapIconPins[self.icon] == self then -- Questie modification
worldmapIconPins[self.icon] = nil
end
self.icon:Hide()
self.icon:SetParent(UIParent)
self.icon:ClearAllPoints()
self.icon = nil
end
end
-- hack to avoid in-combat error on 10.1.5
worldmapProviderPin.SetPassThroughButtons = function() end
-- register with the world map
WorldMapFrame:AddDataProvider(worldmapProvider)
-- map event handling
local function UpdateMinimap()
UpdateMinimapZoom()
UpdateMinimapPins()
end
local function UpdateWorldMap()
worldmapProvider:RefreshAllData()
end
local last_update = 0
local function OnUpdateHandler(frame, elapsed)
last_update = last_update + elapsed
-- skip updates while the minimap is hidden
if pins.Minimap and not pins.Minimap:IsVisible() then return end
-- check for a full update every second, so pins coming in range get properly rendered
if last_update > 1 or queueFullUpdate then
UpdateMinimapPins(queueFullUpdate)
last_update = 0
queueFullUpdate = false
else
UpdateMinimapIconPosition()
end
end
pins.updateFrame:SetScript("OnUpdate", OnUpdateHandler)
local function OnEventHandler(frame, event, ...)
if event == "CVAR_UPDATE" then
local cvar, value = ...
if cvar == "rotateMinimap" or cvar == "ROTATE_MINIMAP" then
rotateMinimap = (value == "1")
queueFullUpdate = true
end
elseif event == "MINIMAP_UPDATE_ZOOM" then
UpdateMinimap()
elseif event == "PLAYER_LOGIN" then
-- recheck cvars after login
rotateMinimap = GetCVar("rotateMinimap") == "1"
elseif event == "PLAYER_ENTERING_WORLD" then
UpdateMinimap()
UpdateWorldMap()
end
end
pins.updateFrame:SetScript("OnEvent", OnEventHandler)
pins.updateFrame:UnregisterAllEvents()
pins.updateFrame:RegisterEvent("CVAR_UPDATE")
pins.updateFrame:RegisterEvent("MINIMAP_UPDATE_ZOOM")
pins.updateFrame:RegisterEvent("PLAYER_LOGIN")
pins.updateFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
HBD.RegisterCallback(pins, "PlayerZoneChanged", UpdateMinimap)
--- Add a icon to the minimap (x/y world coordinate version)
-- Note: This API does not let you specify a map to limit the pin to, it'll be shown on all maps these coordinates are valid for.
-- @param ref Reference to your addon to track the icon under (ie. your "self" or string identifier)
-- @param icon Icon Frame
-- @param instanceID Instance ID of the map to add the icon to
-- @param x X position in world coordinates
-- @param y Y position in world coordinates
-- @param floatOnEdge flag if the icon should float on the edge of the minimap when going out of range, or hide immediately (default false)
function pins:AddMinimapIconWorld(ref, icon, instanceID, x, y, floatOnEdge)
if not ref then
error(MAJOR..": AddMinimapIconWorld: 'ref' must not be nil", 2)
end
if type(icon) ~= "table" or not icon.SetPoint then
error(MAJOR..": AddMinimapIconWorld: 'icon' must be a frame", 2)
end
if type(instanceID) ~= "number" or type(x) ~= "number" or type(y) ~= "number" then
error(MAJOR..": AddMinimapIconWorld: 'instanceID', 'x' and 'y' must be numbers", 2)
end
if not minimapPinRegistry[ref] then
minimapPinRegistry[ref] = {}
end
minimapPinRegistry[ref][icon] = true
local t = minimapPins[icon] or newCachedTable()
t.instanceID = instanceID
t.x = x
t.y = y
t.floatOnEdge = floatOnEdge
t.uiMapID = nil
t.showInParentZone = nil
minimapPins[icon] = t
queueFullUpdate = true
icon:SetParent(pins.Minimap)
end
--- Add a icon to the minimap (UiMapID zone coordinate version)
-- The pin will only be shown on the map specified, or optionally its parent map if specified
-- @param ref Reference to your addon to track the icon under (ie. your "self" or string identifier)
-- @param icon Icon Frame
-- @param uiMapID uiMapID of the map to place the icon on
-- @param x X position in local/point coordinates (0-1), relative to the zone
-- @param y Y position in local/point coordinates (0-1), relative to the zone
-- @param showInParentZone flag if the icon should be shown in its parent zone - ie. an icon in a microdungeon in the outdoor zone itself (default false)
-- @param floatOnEdge flag if the icon should float on the edge of the minimap when going out of range, or hide immediately (default false)
function pins:AddMinimapIconMap(ref, icon, uiMapID, x, y, showInParentZone, floatOnEdge)
if not ref then
error(MAJOR..": AddMinimapIconMap: 'ref' must not be nil", 2)
end
if type(icon) ~= "table" or not icon.SetPoint then
error(MAJOR..": AddMinimapIconMap: 'icon' must be a frame", 2)
end
if type(uiMapID) ~= "number" or type(x) ~= "number" or type(y) ~= "number" then
error(MAJOR..": AddMinimapIconMap: 'uiMapID', 'x' and 'y' must be numbers", 2)
end
-- convert to world coordinates and use our known adding function
local xCoord, yCoord, instanceID = HBD:GetWorldCoordinatesFromZone(x, y, uiMapID)
if not xCoord then return end
self:AddMinimapIconWorld(ref, icon, instanceID, xCoord, yCoord, floatOnEdge)
-- store extra information
minimapPins[icon].uiMapID = uiMapID
minimapPins[icon].showInParentZone = showInParentZone
end
--- Check if a floating minimap icon is on the edge of the map
-- @param icon the minimap icon
function pins:IsMinimapIconOnEdge(icon)
if not icon then return false end
local data = minimapPins[icon]
if not data then return nil end
return data.onEdge
end
--- Remove a minimap icon
-- @param ref Reference to your addon to track the icon under (ie. your "self" or string identifier)
-- @param icon Icon Frame
function pins:RemoveMinimapIcon(ref, icon)
if not ref or not icon or not minimapPinRegistry[ref] then return end
minimapPinRegistry[ref][icon] = nil
if minimapPins[icon] then
recycle(minimapPins[icon])
minimapPins[icon] = nil
activeMinimapPins[icon] = nil
end
icon:Hide()
end
--- Remove all minimap icons belonging to your addon (as tracked by "ref")
-- @param ref Reference to your addon to track the icon under (ie. your "self" or string identifier)
function pins:RemoveAllMinimapIcons(ref)
if not ref or not minimapPinRegistry[ref] then return end
for icon in pairs(minimapPinRegistry[ref]) do
recycle(minimapPins[icon])
minimapPins[icon] = nil
activeMinimapPins[icon] = nil
icon:Hide()
end
wipe(minimapPinRegistry[ref])
end
--- Set the minimap object to position the pins on. Needs to support the usual functions a Minimap-type object exposes.
-- @param minimapObject The new minimap object, or nil to restore the default
function pins:SetMinimapObject(minimapObject)
pins.Minimap = minimapObject or Minimap
for pin in pairs(minimapPins) do
pin:SetParent(pins.Minimap)
end
UpdateMinimapPins(true)
end
--- Questie addition: the view minimap icons are placed with, so other minimap drawings line up
--- with them. Clients without C_Minimap.GetViewRadius use the indoor/outdoor zoom table.
-- @return radius Yards from the minimap's center to its edge; nil for an unknown zoom level
-- @return rotating true while the minimap turns with the player
function pins:GetMinimapView()
local radius
if MinimapRadiusAPI then
radius = C_Minimap.GetViewRadius()
else
local size = minimap_size[indoors][pins.Minimap:GetZoom()]
radius = size and size / 2
end
return radius, rotateMinimap
end
-- world map constants
-- show worldmap pin only on zone map (Questie modification)
HBD_PINS_WORLDMAP_SHOW_CURRENT = -1
-- show worldmap pin on its parent zone map (if any)
HBD_PINS_WORLDMAP_SHOW_PARENT = 1
-- show worldmap pin on the continent map
HBD_PINS_WORLDMAP_SHOW_CONTINENT = 2
-- show worldmap pin on the continent and world map
HBD_PINS_WORLDMAP_SHOW_WORLD = 3
--- Add a icon to the world map (x/y world coordinate version)
-- Note: This API does not let you specify a map to limit the pin to, it'll be shown on all maps these coordinates are valid for.
-- @param ref Reference to your addon to track the icon under (ie. your "self" or string identifier)
-- @param icon Icon Frame
-- @param instanceID Instance ID of the map to add the icon to
-- @param x X position in world coordinates
-- @param y Y position in world coordinates
-- @param showFlag Flag to control on which maps this pin will be shown
-- @param frameLevel Optional Frame Level type registered with the WorldMapFrame, defaults to PIN_FRAME_LEVEL_AREA_POI
function pins:AddWorldMapIconWorld(ref, icon, instanceID, x, y, showFlag, frameLevel)
if not ref then
error(MAJOR..": AddWorldMapIconWorld: 'ref' must not be nil", 2)
end
if type(icon) ~= "table" or not icon.SetPoint then
error(MAJOR..": AddWorldMapIconWorld: 'icon' must be a frame", 2)
end
if type(instanceID) ~= "number" or type(x) ~= "number" or type(y) ~= "number" then
error(MAJOR..": AddWorldMapIconWorld: 'instanceID', 'x' and 'y' must be numbers", 2)
end
if showFlag ~= nil and type(showFlag) ~= "number" then
error(MAJOR..": AddWorldMapIconWorld: 'showFlag' must be a number (or nil)", 2)
end
if not worldmapPinRegistry[ref] then
worldmapPinRegistry[ref] = {}
end
worldmapPinRegistry[ref][icon] = true
local t = worldmapPins[icon] or newCachedTable()
t.instanceID = instanceID
t.x = x
t.y = y
t.uiMapID = nil
t.worldMapShowFlag = showFlag or 0
t.frameLevelType = frameLevel
worldmapPins[icon] = t
worldmapProvider:HandlePin(icon, t)
end
--- Add a icon to the world map (uiMapID zone coordinate version)
-- @param ref Reference to your addon to track the icon under (ie. your "self" or string identifier)
-- @param icon Icon Frame
-- @param uiMapID uiMapID of the map to place the icon on
-- @param x X position in local/point coordinates (0-1), relative to the zone
-- @param y Y position in local/point coordinates (0-1), relative to the zone
-- @param showFlag Flag to control on which maps this pin will be shown
-- @param frameLevel Optional Frame Level type registered with the WorldMapFrame, defaults to PIN_FRAME_LEVEL_AREA_POI
function pins:AddWorldMapIconMap(ref, icon, uiMapID, x, y, showFlag, frameLevel)
if not ref then
error(MAJOR..": AddWorldMapIconMap: 'ref' must not be nil", 2)
end
if type(icon) ~= "table" or not icon.SetPoint then
error(MAJOR..": AddWorldMapIconMap: 'icon' must be a frame", 2)
end
if type(uiMapID) ~= "number" or type(x) ~= "number" or type(y) ~= "number" then
error(MAJOR..": AddWorldMapIconMap: 'uiMapID', 'x' and 'y' must be numbers", 2)
end
if showFlag ~= nil and type(showFlag) ~= "number" then
error(MAJOR..": AddWorldMapIconMap: 'showFlag' must be a number (or nil)", 2)
end
-- convert to world coordinates
local xCoord, yCoord, instanceID = HBD:GetWorldCoordinatesFromZone(x, y, uiMapID)
if not xCoord then return end
if not worldmapPinRegistry[ref] then
worldmapPinRegistry[ref] = {}
end
worldmapPinRegistry[ref][icon] = true
local t = worldmapPins[icon] or newCachedTable()
t.instanceID = instanceID
t.x = xCoord
t.y = yCoord
t.uiMapID = uiMapID
t.worldMapShowFlag = showFlag or 0
t.frameLevelType = frameLevel
worldmapPins[icon] = t
worldmapProvider:HandlePin(icon, t)
end
--- Remove a worldmap icon
-- @param ref Reference to your addon to track the icon under (ie. your "self" or string identifier)
-- @param icon Icon Frame
function pins:RemoveWorldMapIcon(ref, icon)
if not ref or not icon or not worldmapPinRegistry[ref] then return end
worldmapPinRegistry[ref][icon] = nil
if worldmapPins[icon] then
recycle(worldmapPins[icon])
worldmapPins[icon] = nil
end
worldmapProvider:RemovePinByIcon(icon)
worldmapProvider.forceUpdate = true -- Questie modification
end
--- Remove all worldmap icons belonging to your addon (as tracked by "ref")
-- @param ref Reference to your addon to track the icon under (ie. your "self" or string identifier)
function pins:RemoveAllWorldMapIcons(ref)
if not ref or not worldmapPinRegistry[ref] then return end
for icon in pairs(worldmapPinRegistry[ref]) do
recycle(worldmapPins[icon])
worldmapPins[icon] = nil
end
worldmapProvider:RemovePinsByRef(ref)
wipe(worldmapPinRegistry[ref])
worldmapProvider.forceUpdate = true -- Questie modification
end
--- Return the angle and distance from the player to the specified pin
-- @param icon icon object (minimap or worldmap)
-- @return angle, distance where angle is in radians and distance in yards
function pins:GetVectorToIcon(icon)
if not icon then return nil, nil end
local data = minimapPins[icon] or worldmapPins[icon]
if not data then return nil, nil end
local x, y, instance = HBD:GetPlayerWorldPosition()
if not x or not y or instance ~= data.instanceID then return nil end
return HBD:GetWorldVector(instance, x, y, data.x, data.y)
end
if oldversion then
if WorldMapFrame:IsShown() then
worldmapProvider:RefreshAllData(false)
end
end