comparison WhistleMaster.lua @ 3:4402edd42a3f v0.7.1.0-Beta

Added tooltip to Flight Masters Whistle, improved update function call.
author Vynn <mischivin@gmail.com>
date Sat, 05 Nov 2016 13:19:54 -0400
parents 06d230725448
children 090b3be6489d
comparison
equal deleted inserted replaced
2:881a2c218fa5 3:4402edd42a3f
2 function WM_Debug() 2 function WM_Debug()
3 print("debug text") 3 print("debug text")
4 end 4 end
5 5
6 --indexes corrispond to map IDs that contain valid flight points for the Flight Masters Whistle 6 --indexes corrispond to map IDs that contain valid flight points for the Flight Masters Whistle
7 local validIDs = { [1014] = true, [1015] = true, [1017] = true, [1018] = true, [1024] = true, [1033] = true, [1096] = true } 7 --Doesn't work in 1021 (Broken Shore)
8 WM_validIDs = { [1014] = true, [1015] = true, [1017] = true, [1018] = true, [1021] = false, [1024] = true, [1033] = true, [1096] = true }
8 9
9 local WhistleLoc = CreateFrame("FRAME", "WhistleLOC", WorldMapPOIFrame) 10 local WhistleLoc = CreateFrame("FRAME", "WhistleLOC", WorldMapPOIFrame)
10 WhistleLoc:SetSize(64, 64) 11 WhistleLoc:SetSize(64, 64)
11 WhistleLoc:SetPoint("CENTER", 0, 0) 12 WhistleLoc:SetPoint("CENTER", 0, 0)
12 WhistleLoc:Show() 13 WhistleLoc:Show()
14
15 WM_ClosestNode = nil
13 16
14 --[[local Rotate = WhistleLoc:CreateTexture() 17 --[[local Rotate = WhistleLoc:CreateTexture()
15 Rotate:SetTexture("Interface\minimap\UI-Minimap-Ping-Rotate") 18 Rotate:SetTexture("Interface\minimap\UI-Minimap-Ping-Rotate")
16 Rotate:SetPoint("CENTER") 19 Rotate:SetPoint("CENTER")
17 Rotate:SetSize(48, 48) 20 Rotate:SetSize(48, 48)
49 distance = d 52 distance = d
50 node = n 53 node = n
51 end 54 end
52 end 55 end
53 end 56 end
54 print("The closest node is... " .. node.name)
55 return node 57 return node
56 end 58 end
57 59
58 local function UpdateWhistleMaster() 60 local function UpdateWhistleMaster()
59 if GetCurrentMapContinent() == 8 and validIDs[ select(1, GetCurrentMapAreaID() ) ] then 61 if GetCurrentMapContinent() == 8 and WM_validIDs[ select(1, GetCurrentMapAreaID() ) ] and not GetNumDungeonMapLevels() then
60 local closest = GetNode() 62 WM_ClosestNode = GetNode()
61 WhistleLoc:SetPoint("CENTER", "WorldMapFramePOI" .. closest.index, 0, 0) 63 WhistleLoc:SetPoint("CENTER", "WorldMapFramePOI" .. WM_ClosestNode.index, 0, 0)
62 WhistleLoc:Show() 64 WhistleLoc:Show()
63 WhistlePing.Ping:Play() 65 WhistlePing.Ping:Play()
66 return true
64 else 67 else
65 WhistleLoc:Hide() 68 WhistleLoc:Hide()
66 WhistlePing.Ping:Stop() 69 WhistlePing.Ping:Stop()
67 print("wrong continent for whistle master") 70 return false
68 end 71 end
69 end 72 end
70 73
71 local mapVisible = false 74 local mapVisible = false
72 75
76 UpdateWhistleMaster() 79 UpdateWhistleMaster()
77 end 80 end
78 if ( (mapVisible) and not WorldMapFrame:IsVisible() ) then 81 if ( (mapVisible) and not WorldMapFrame:IsVisible() ) then
79 mapVisible = false 82 mapVisible = false
80 end 83 end
84 if (event == "VARIABLES_LOADED") then
85 UpdateWhistleMaster()
86 end
81 end 87 end
82
83
84 88
85 local WhistleMaster = CreateFrame("FRAME", "WhistleMaster", WorldMapPOIFrame) 89 local WhistleMaster = CreateFrame("FRAME", "WhistleMaster", WorldMapPOIFrame)
86 WhistleMaster:RegisterEvent("WORLD_MAP_UPDATE") 90 WhistleMaster:RegisterEvent("WORLD_MAP_UPDATE")
91 WhistleMaster:RegisterEvent("VARIABLES_LOADED")
87 WhistleMaster:SetScript("OnEvent", EventHandler) 92 WhistleMaster:SetScript("OnEvent", EventHandler)
88 93
94 local cleared = true
95 local function OnTooltipCleared(self)
96 cleared = true
97 end
98
99 local function OnTooltipSetItem(self)
100 if cleared then
101 local name, tooltipLink = self:GetItem()
102 if tooltipLink then
103 local item = tooltipLink:match("Hitem:(%d+)")
104 if item == "141605" then
105 if UpdateWhistleMaster() then
106 self:AddLine("\nWhistle Destination:|cFFFFFFFF " .. WM_ClosestNode.name ,0.5,1,0.5, true)
107 else
108 self:AddLine("\nWhistle Destination:|cFFFFFFFF N/A",0.5,1,0.5, true)
109 end
110 end
111 cleared = true
112 end
113 end
114 end
115
116 GameTooltip:HookScript("OnTooltipCleared", OnTooltipCleared)
117 GameTooltip:HookScript("OnTooltipSetItem", OnTooltipSetItem)
118