-
Notifications
You must be signed in to change notification settings - Fork 7
/
Map.lua
279 lines (236 loc) · 8.33 KB
/
Map.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
--[[
Map modifications
]]
-- Function: Completely clear a POI
local function EFM_Map_POIClear(POI)
POI:ClearAllPoints();
POI.Location = nil;
POI:Hide();
end
-- Function: Clear old map node references.
function EFM_Map_ClearPoints()
if (EFM_MyConf == nil) then
return;
end
local index;
index = 1;
while (getglobal("EFM_MAP_POI"..index) ~= nil) do
POI = getglobal("EFM_MAP_POI"..index);
EFM_Map_POIClear(POI);
index = index + 1;
end
index = 1;
while (getglobal("EFM_WM_Route"..index) ~= nil) do
POI = getglobal("EFM_WM_Route"..index);
EFM_Map_POIClear(POI);
index = index + 1;
end
end
-- Function: World Map Update thingy.
function EFM_Map_WorldMapEvent()
if (EFM_MyConf == nil) then
return;
end
local index;
index = 1;
while (getglobal("EFM_MAP_POI"..index) ~= nil) do
POI = getglobal("EFM_MAP_POI"..index);
EFM_Map_POIClear(POI);
index = index + 1;
end
index = 1;
while (getglobal("EFM_WM_Route"..index) ~= nil) do
POI = getglobal("EFM_WM_Route"..index);
EFM_Map_POIClear(POI);
index = index + 1;
end
local myFaction = UnitFactionGroup("player");
local mapID = WorldMapFrame:GetMapID();
local mapInfo = C_Map.GetMapInfo(mapID);
if (mapInfo.mapType == 1) then
if (EFM_MyConf.WorldOverlay == true) then
EFM_Map_DisplayEFMPOIs(mapInfo.name, 1);
return;
end
elseif (mapInfo.mapType == 2) then
if (EFM_MyConf.ContinentOverlay == true) then
EFM_Map_DisplayEFMPOIs(mapInfo.name, 2);
return;
end
elseif (mapInfo.mapType == 3) then
if (EFM_MyConf.ZoneMarker == true) then
EFM_Map_DisplayEFMPOIs(mapInfo.name, 3);
return;
end
end
end
-- Function: POI On Enter
function EFM_MAP_POIOnEnter(frame)
local displayRoutes = {};
local px, py = frame:GetCenter();
local align = "ANCHOR_LEFT";
local wx, wy = UIParent:GetCenter();
if (px <= wx) then
align = "ANCHOR_RIGHT";
end
EFM_ToolTip:SetOwner(frame, align);
EFM_ToolTip:AddLine(frame.Location);
-- Flight path display stuff...
local myNode = EFM_NI_GetNodeByName(frame.Location, frame.nodeStyle);
if (myNode ~= nil) then
local flightDuration = "";
local routeList = myNode["routes"];
if (routeList ~= nil) then
EFM_ToolTip:AddLine(EFM_MAP_PATHLIST, 1.0, 1.0, 1.0);
table.sort(routeList);
for index, routeName in pairs(routeList) do
if (not EFM_SF_StringInTable(displayRoutes, routeName)) then
table.insert(displayRoutes, routeName);
flightDuration = EFM_NI_GetNode_FlightDuration(frame.Location, routeName);
if (EFM_NI_CheckReachable(routeName)) then
flightColour = "|c0000FF00";
else
flightColour = "|c00909090";
end
if (flightDuration) then
EFM_ToolTip:AddDoubleLine(flightColour..routeName, EFM_SF_FormatTime(flightDuration));
else
EFM_ToolTip:AddLine(flightColour..routeName);
end
end
end
end
end
-- Match the tooltip scale to the UIParent Scaling factor
local myScale = UIParent:GetScale() ;
myScale = EFM_SF_ValueToPrecision(myScale, 2);
EFM_ToolTip:SetScale(myScale);
-- Show the Tooltip
EFM_ToolTip:Show();
end
-- Function: Display some EFM data on the world map...
function EFM_Map_DisplayEFMPOIs(locName, locLevel)
local myDebug = false;
local myFaction = UnitFactionGroup("player");
local zoneList = {};
local zoneName = "";
local knownPoints = {};
local buttonCount = 0;
local mapCanvas = WorldMapFrame:GetCanvas();
local w = mapCanvas:GetWidth();
local h = mapCanvas:GetHeight();
-- World Map
if (locLevel == 1) then
for index, myContinent in pairs(EFM_GetContinentList() or {}) do
for myZone in pairs(EFM_Data[EFM_Global_Faction][myContinent] or {}) do
for myNode in pairs(EFM_Data[EFM_Global_Faction][myContinent][myZone] or {}) do
EFM_Shared_DebugMessage("Node Added: "..EFM_Data[EFM_Global_Faction][myContinent][myZone][myNode]["name"], myDebug);
table.insert(knownPoints, EFM_Data[EFM_Global_Faction][myContinent][myZone][myNode]["name"]);
end
end
end
nodeLevel = EFM_LocTypes[1];
EFM_Shared_DebugMessage("EFM_Map_DisplayEFMPOIs: Trying to display POIs on the World Map.", myDebug);
-- Continent Map
elseif (locLevel == 2) then
myContinent = locName;
knownPoints = EFM_NI_GetNode_List(locName);
nodeLevel = EFM_LocTypes[2];
-- Zone Map
elseif (locLevel == 3 or locName == C_Map.GetMapInfo(125).name) then -- Working around Dalaran (Northrend) being mapType=4?
knownPoints = EFM_NI_GetNodeListByZone(locName);
myContinent = EFM_NI_GetContinentByZone(locName);
nodeLevel = EFM_LocTypes[3];
end
-- Abort if we are seeing this too early.
if (nodeLevel == nil) then
EFM_Shared_DebugMessage("EFM_Map_DisplayEFMPOIs: nodeLevel not set yet.", myDebug);
EFM_Shared_DebugMessage("EFM_LocTypes:"..EFM_LocTypes[1], myDebug);
return;
end
EFM_Shared_DebugMessage("EFM_Map_DisplayEFMPOIs: Getting data for knownPoints!", myDebug);
EFM_Shared_DebugMessage("EFM_Map_DisplayEFMPOIs: nodeLevel: "..nodeLevel, myDebug);
if (knownPoints ~= nil) then
EFM_Shared_DebugMessage("EFM_Map_DisplayEFMPOIs: knownPoints has data!", myDebug);
local POI;
local POITexture;
-- Clear the seenRoutes variable.
local seenRoutes = {};
local routepoi = 0;
-- Currently we only want to display "land" flight nodes, will expand later, this is only temporary.
local nodeStyle = 0;
-- Show the flight nodes
for index, flightNode in pairs(knownPoints) do
EFM_Shared_DebugMessage("EFM_Map_DisplayEFMPOIs Node Name: "..flightNode, myDebug);
local myNode = EFM_NI_GetNodeByName(flightNode, nodeStyle);
local nodeName = myNode["name"];
if (myNode[nodeLevel] ~= nil) then
EFM_Shared_DebugMessage("EFM_Map_DisplayEFMPOIs Node Name: nodeLevel is NOT nil." , myDebug);
local mapX = tonumber(myNode[nodeLevel]["x"]);
local mapY = tonumber(myNode[nodeLevel]["y"]);
if ((mapX ~= nil) and (mapY ~= nil)) then
EFM_Shared_DebugMessage("EFM_Map_DisplayEFMPOIs: Node is at x "..mapX..", y "..mapY , myDebug);
local pointX = (mapX * w);
local pointY = (mapY * h);
if (locLevel == 3) then
pointX = (mapX/100) * w;
pointY = (mapY/100) * h;
end
buttonCount = buttonCount + 1;
POI = getglobal("EFM_MAP_POI"..buttonCount);
if (POI == nil) then
POI = CreateFrame("Button", "EFM_MAP_POI"..buttonCount, mapCanvas, "EFM_POI_Template");
end
POITexture = getglobal("EFM_MAP_POI"..buttonCount.."Icon");
-- Display the actual POI Button
if (EFM_NI_CheckReachable(nodeName)) then
POITexture:SetTexture("Interface\\TaxiFrame\\UI-Taxi-Icon-Yellow");
else
POITexture:SetTexture("Interface\\TaxiFrame\\UI-Taxi-Icon-Gray");
end
POI:ClearAllPoints();
POI:SetPoint("CENTER", mapCanvas, "BOTTOMLEFT", pointX, h-pointY);
POI:SetAlpha(0.5);
POI:Show();
-- Set the Location & Continent Fields.
POI.Location = nodeName;
POI.Continent = myContinent;
POI.nodeStyle = 0;
-- Draw Routes on map, unless we're on the zone-level then don't do that.
if ((myNode.routes ~= nil) and (locLevel < 3)) then
local flightDuration = "";
WorldMapTooltip:AddLine(EFM_MAP_PATHLIST, 1.0, 1.0, 1.0);
for key, routeName in pairs(myNode.routes) do
if ((routeName ~= nil) and (not EFM_SF_StringInTable(seenRoutes, routeName))) then
local endNode = EFM_NI_GetNodeByName(routeName, nodeStyle);
if (endNode ~= nil) then
if (endNode[nodeLevel] ~= nil) then
-- Create a new texture for the route line if needed
routepoi = routepoi + 1;
line = getglobal("EFM_WM_Route"..routepoi);
if (line == nil) then
line = mapCanvas:CreateTexture("EFM_WM_Route"..routepoi, "OVERLAY");
end
line:SetTexture("Interface\\TaxiFrame\\UI-Taxi-Line");
local destX = tonumber(endNode[nodeLevel]["x"]);
local destY = tonumber(endNode[nodeLevel]["y"]);
if (locLevel == 3) then
destX = tonumber(endNode[nodeLevel]["x"])/100;
destY = tonumber(endNode[nodeLevel]["y"])/100;
end
if ((destX ~= nil) and (destY ~= nil)) then
DrawLine(line, mapCanvas, pointX, (h - pointY), destX * w, (h - (destY * h)), 32, TAXIROUTE_LINEFACTOR);
line:SetAlpha(0.5);
line:Show();
end
end
end
end
end
table.insert(seenRoutes, zone);
end
end
end
end
end
end