view WhistleMaster.lua @ 5:090b3be6489d

Fix for a LOD issue. Seems Kludgy, but I haven't figured out a better method yet.
author Vynn <mischivin@gmail.com>
date Sat, 05 Nov 2016 23:44:42 -0400
parents 4402edd42a3f
children 148e87d347f5
line wrap: on
line source

function WM_Debug() 
	print("debug text")
end

--indexes corrispond to map IDs that contain valid flight points for the Flight Masters Whistle
--Doesn't work in 1021 (Broken Shore)
WM_validIDs = { [1014] = true, [1015] = true, [1017] = true, [1018] = true, [1021] = false, [1024] = true, [1033] = true, [1096] = true }

local WhistleLoc = CreateFrame("FRAME", "WhistleLOC", WorldMapPOIFrame)
WhistleLoc:SetSize(64, 64)
WhistleLoc:SetPoint("CENTER", 0, 0)
WhistleLoc:Show()

WM_ClosestNode = nil

--[[local Rotate = WhistleLoc:CreateTexture()
Rotate:SetTexture("Interface\minimap\UI-Minimap-Ping-Rotate")
Rotate:SetPoint("CENTER")
Rotate:SetSize(48, 48)
Rotate:SetVertexColor(0.9, 0.1, 0.1)

local Ring = WhistleLoc:CreateTexture()
Ring:SetTexture("Interface\minimap\UI-Minimap-Ping-Center")
Ring:SetPoint("CENTER")
Ring:SetSize(32, 32)
Ring:SetVertexColor(0.9, 0.1, 0.1)]]




local function GetDistance(nX, nY)
	local pX, pY = GetPlayerMapPosition("player")

	local dX = pX - nX
    local dY = pY - nY
 
	return math.sqrt( ( dX^2 ) + ( dY^2 ) )
end

local function GetNode()
	local node
	local distance
	local index
	for k = 1, GetNumMapLandmarks() do
		local n = {}
		n.type, n.name, n.description, n.textureIndex, n.x, n.y = GetMapLandmarkInfo(k)
		if n.type == LE_MAP_LANDMARK_TYPE_TAXINODE then --LE_MAP_LANDMARK_TYPE_TAXINODE is a constant defined by Blizzard
			local d = GetDistance(n.x, n.y)
			if distance == nil or d < distance then
				n.index = k
				distance = d
				node = n
			end
		end
	end
	return node
end

local function UpdateWhistleMaster()
	if GetCurrentMapContinent() == 8 and WM_validIDs[ select(1, GetCurrentMapAreaID() ) ] and not GetNumDungeonMapLevels() then
		WM_ClosestNode = GetNode()
		WhistleLoc:SetPoint("CENTER", "WorldMapFramePOI" .. WM_ClosestNode.index, 0, 0)
		WhistleLoc:Show()
		WhistlePing.Ping:Play()
		return true
	else
		WhistleLoc:Hide()
		WhistlePing.Ping:Stop()
		return false
	end
end

local mapVisible = false

local function EventHandler(self, event, ...)
	if ( (event == "WORLD_MAP_UPDATE") and WorldMapFrame:IsVisible() ) then
		mapVisible = true
		UpdateWhistleMaster()
	end
	if ( (mapVisible) and not WorldMapFrame:IsVisible() ) then
 		mapVisible = false
 	end
 	if (event == "VARIABLES_LOADED") then
		WorldMapFrame:Show()
		WorldMapFrame:Hide()
 		UpdateWhistleMaster()
 	end
end

local WhistleMaster = CreateFrame("FRAME", "WhistleMaster", WorldMapPOIFrame)
WhistleMaster:RegisterEvent("WORLD_MAP_UPDATE")
WhistleMaster:RegisterEvent("VARIABLES_LOADED")
WhistleMaster:SetScript("OnEvent", EventHandler)

local cleared = true
local function OnTooltipCleared(self)
   cleared = true   
end
 
local function OnTooltipSetItem(self)
	if cleared then
		local name, tooltipLink = self:GetItem()
		if tooltipLink then
			local item = tooltipLink:match("Hitem:(%d+)")
			if item == "141605" then
				if UpdateWhistleMaster() then
					self:AddLine("\nWhistle Destination:|cFFFFFFFF " .. WM_ClosestNode.name ,0.5,1,0.5, true)
				else
					self:AddLine("\nWhistle Destination:|cFFFFFFFF N/A",0.5,1,0.5, true)
				end
			end
			cleared = true
		end
	end
end
 
GameTooltip:HookScript("OnTooltipCleared", OnTooltipCleared)
GameTooltip:HookScript("OnTooltipSetItem", OnTooltipSetItem)