-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlightMap.lua
More file actions
929 lines (796 loc) · 30.9 KB
/
FlightMap.lua
File metadata and controls
929 lines (796 loc) · 30.9 KB
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
-- FlightMap - AddOn to show inbound and outbound flightpaths from a given
-- zone on the World Map. Additionally shows flight costs and
-- zone level ranges.
-- Copyright (c) 2005 Byron Ellacott (Dhask of Uther)
--
-- An unlimited license to use, reproduce and copy this work is granted, on
-- the condition that the licensee accepts all responsibility and liability
-- for any damage that may arise from the use of this AddOn.
-- Version number
FLIGHTMAP_VERSION = "1.12-1";
-- Maximum lines to draw at once
FLIGHTMAP_MAX_PATHS = 15;
-- Size and names for path texture files
FLIGHTMAP_LINE_SIZE = 256;
FLIGHTMAP_TEX_UP = "Interface\\AddOns\\FlightMap\\FlightMapUp";
FLIGHTMAP_TEX_DOWN = "Interface\\AddOns\\FlightMap\\FlightMapDown";
-- Maximum POI buttons defined
FLIGHTMAP_MAX_POIS = 15;
-- How many pixels is too close to another POI?
FLIGHTMAP_CLOSE = 16;
FLIGHTMAP_CLOSE_SQ = FLIGHTMAP_CLOSE * FLIGHTMAP_CLOSE; -- Pre-compute for distance checks
-- Textures for flightmaster POI icons
FLIGHTMAP_POI_KNOWN = "Interface\\TaxiFrame\\UI-Taxi-Icon-Green";
FLIGHTMAP_POI_OTHER = "Interface\\TaxiFrame\\UI-Taxi-Icon-Gray";
local lTYPE_HORDE = FLIGHTMAP_HORDE;
local lTYPE_ALLIANCE = FLIGHTMAP_ALLIANCE;
local lTYPE_CONTESTED = FLIGHTMAP_CONTESTED;
-- According to http://www.worldofwarcraft.com/ at any rate...
FLIGHTMAP_RANGES = {
[FLIGHTMAP_ELWYNN] = { 1, 10, lTYPE_ALLIANCE},
[FLIGHTMAP_DUNMOROGH] = { 1, 10, lTYPE_ALLIANCE},
[FLIGHTMAP_TIRISFAL] = { 1, 10, lTYPE_HORDE},
[FLIGHTMAP_LOCHMODAN] = {10, 20, lTYPE_ALLIANCE},
[FLIGHTMAP_SILVERPINE] = {10, 20, lTYPE_HORDE},
[FLIGHTMAP_WESTFALL] = {10, 20, lTYPE_ALLIANCE},
[FLIGHTMAP_REDRIDGE] = {15, 25, lTYPE_CONTESTED},
[FLIGHTMAP_DUSKWOOD] = {18, 30, lTYPE_CONTESTED},
[FLIGHTMAP_HILLSBRAD] = {20, 30, lTYPE_CONTESTED},
[FLIGHTMAP_WETLANDS] = {20, 30, lTYPE_CONTESTED},
[FLIGHTMAP_ALTERAC] = {30, 40, lTYPE_CONTESTED},
[FLIGHTMAP_ARATHI] = {30, 40, lTYPE_CONTESTED},
[FLIGHTMAP_STRANGLETHORN] = {30, 45, lTYPE_CONTESTED},
[FLIGHTMAP_BADLANDS] = {35, 45, lTYPE_CONTESTED},
[FLIGHTMAP_SORROWS] = {35, 45, lTYPE_CONTESTED},
[FLIGHTMAP_HINTERLANDS] = {40, 50, lTYPE_CONTESTED},
[FLIGHTMAP_SEARINGGORGE] = {43, 50, lTYPE_CONTESTED},
[FLIGHTMAP_BLASTEDLANDS] = {45, 55, lTYPE_CONTESTED},
[FLIGHTMAP_BURNINGSTEPPE] = {50, 58, lTYPE_CONTESTED},
[FLIGHTMAP_WESTERNPLAGUE] = {51, 58, lTYPE_CONTESTED},
[FLIGHTMAP_EASTERNPLAGUE] = {53, 60, lTYPE_CONTESTED},
[FLIGHTMAP_DUROTAR] = { 1, 10, lTYPE_HORDE},
[FLIGHTMAP_MULGORE] = { 1, 10, lTYPE_HORDE},
[FLIGHTMAP_DARKSHORE] = {10, 20, lTYPE_ALLIANCE},
[FLIGHTMAP_BARRENS] = {10, 25, lTYPE_HORDE},
[FLIGHTMAP_STONETALON] = {15, 27, lTYPE_CONTESTED},
[FLIGHTMAP_ASHENVALE] = {18, 30, lTYPE_CONTESTED},
[FLIGHTMAP_1KNEEDLES] = {25, 35, lTYPE_CONTESTED},
[FLIGHTMAP_DESOLACE] = {30, 40, lTYPE_CONTESTED},
[FLIGHTMAP_DUSTWALLOW] = {35, 45, lTYPE_CONTESTED},
[FLIGHTMAP_FERALAS] = {40, 50, lTYPE_CONTESTED},
[FLIGHTMAP_TANARIS] = {40, 50, lTYPE_CONTESTED},
[FLIGHTMAP_AZSHARA] = {45, 55, lTYPE_CONTESTED},
[FLIGHTMAP_FELWOOD] = {48, 55, lTYPE_CONTESTED},
[FLIGHTMAP_UNGOROCRATER] = {48, 55, lTYPE_CONTESTED},
[FLIGHTMAP_SILITHUS] = {55, 60, lTYPE_CONTESTED},
[FLIGHTMAP_WINTERSPRING] = {55, 60, lTYPE_CONTESTED},
[FLIGHTMAP_TELDRASSIL] = { 1, 10, lTYPE_ALLIANCE},
[FLIGHTMAP_MOONGLADE] = { 1, 60, lTYPE_CONTESTED},
[FLIGHTMAP_DEADWINDPASS] = {55, 60, lTYPE_CONTESTED},
};
-- Colours for zones
FLIGHTMAP_COLORS = {
Unknown = { r = 0.8, g = 0.8, b = 0.8 },
Hostile = { r = 0.9, g = 0.2, b = 0.2 },
Friendly = { r = 0.2, g = 0.9, b = 0.2 },
Contested = { r = 0.8, g = 0.6, b = 0.4 },
};
-- Auto dismount for these buffs
FLIGHTMAP_DISMOUNTS = {
["Interface\\Icons\\Ability_Mount_BlackDireWolf"] = 1,
["Interface\\Icons\\Ability_Mount_BlackPanther"] = 1,
["Interface\\Icons\\Ability_Mount_Charger"] = 1,
["Interface\\Icons\\Ability_Mount_Dreadsteed"] = 1,
["Interface\\Icons\\Ability_Mount_JungleTiger"] = 1,
["Interface\\Icons\\Ability_Mount_Kodo_01"] = 1,
["Interface\\Icons\\Ability_Mount_Kodo_02"] = 1,
["Interface\\Icons\\Ability_Mount_Kodo_03"] = 1,
["Interface\\Icons\\INV_Misc_Horn_01"] = 1,
["Interface\\Icons\\Ability_Mount_MountainRam"] = 1,
["Interface\\Icons\\Spell_Nature_Swiftness"] = 1,
["Interface\\Icons\\Ability_Mount_NightmareHorse"] = 1,
["Interface\\Icons\\Ability_Mount_PinkTiger"] = 1,
["Interface\\Icons\\Ability_Mount_Raptor"] = 1,
["Interface\\Icons\\Ability_Mount_RidingHorse"] = 1,
["Interface\\Icons\\Ability_Mount_Undeadhorse"] = 1,
["Interface\\Icons\\Ability_Mount_WhiteDireWolf"] = 1,
["Interface\\Icons\\Ability_Mount_WhiteTiger"] = 1,
}
-- Cache for faction lookup (avoid repeated UnitFactionGroup calls)
local lFactionCache = nil;
local lFactionCacheTime = 0;
-- Cache for frame references (avoid repeated getglobal calls)
local lPOIButtonCache = {};
local lPathFrameCache = {};
------------------ Data access functions ------------------
local function lStripPoint(map, point)
for k, v in map do
if v.Costs then
v.Costs[point] = nil;
end
if v.Flights then
v.Flights[point] = nil;
end
end
for k, v in FlightMap.Knowledge do
v[point] = nil;
end
map[point] = nil;
end
-- Default option settings
FLIGHTMAP_DEFAULT_OPTS = {
showPaths = true,
showPOIs = true,
showCosts = true,
showTimes = true,
showDestinations = true,
showAllInfo = false,
showMultiHop = true,
lockFlightTimes = false,
autoDismount = true,
fontSize = 12,
showLevelRanges = true,
};
local function lSetDefaultData()
-- Create an empty knowledge record
if not FlightMap["Knowledge"] then
FlightMap.Knowledge = {};
end
-- Default option settings
if (not FlightMap["Opts"]) then
FlightMap["Opts"] = FLIGHTMAP_DEFAULT_OPTS;
end
-- Any options that don't have a value at all should be defaulted
for k, v in pairs(FLIGHTMAP_DEFAULT_OPTS) do
if FlightMap.Opts[k] == nil then
FlightMap.Opts[k] = v;
end
end
-- Patch 1.8: Remove any references to Valor's Rest
lStripPoint(FlightMap[FLIGHTMAP_HORDE] or {}, "1:461:226");
lStripPoint(FlightMap[FLIGHTMAP_ALLIANCE] or {}, "1:463:223");
-- Patch 1.12: Remove any references to Alliance's misplaced Moonglade
lStripPoint(FlightMap[FLIGHTMAP_ALLIANCE] or {}, "1:552:793");
-- Revision 1.8-2: Delete pre-1.7 data
FlightMap.Locs = nil;
FlightMap.Times = nil;
end
-- Learn about the currently open taxi map
local function lLearnTaxiNode()
local map = FlightMapUtil.getFlightMap();
local oldCont, oldZone = GetCurrentMapContinent(),
GetCurrentMapZone();
SetMapToCurrentZone();
local thisCont = GetCurrentMapContinent();
local thisNode;
local destinations = {};
local numNodes = NumTaxiNodes();
for index = 1, numNodes, 1 do
local tType = TaxiNodeGetType(index);
if (tType == "CURRENT") then
thisNode = index;
elseif (tType == "REACHABLE") then
local mx, my = TaxiNodePosition(index);
local destName = FlightMapUtil.makeNodeName(thisCont, mx, my);
destinations[destName] = index;
FlightMapUtil.knownNode(destName, true);
if not map[destName] then
map[destName] = {
Name = "Fix me",
Zone = "Unknown!",
Continent = -1,
Flights = {},
Costs = {},
Routes = {},
Location = {
Taxi = { x = mx, y = my },
Zone = { x = 0, y = 0 },
Continent = { x = 0, y = 0 },
},
};
end
if map[destName] then
map[destName].Name = TaxiNodeName(index);
end
end
end
if (thisNode) then
local mx, my = TaxiNodePosition(thisNode);
local thisName = FlightMapUtil.makeNodeName(thisCont, mx, my);
local zoneName = FlightMapUtil.getZoneName();
local zx, zy = GetPlayerMapPosition("player");
SetMapZoom(thisCont, nil);
local cx, cy = GetPlayerMapPosition("player");
FlightMapUtil.knownNode(thisName, true);
if not map[thisName] then
map[thisName] = {};
end
if not map[thisName].Flights then
map[thisName].Flights = {};
end
if not map[thisName].Costs then
map[thisName].Costs = {};
end
if not map[thisName].Routes then
map[thisName].Routes = {};
end
map[thisName].Name = TaxiNodeName(thisNode);
map[thisName].Zone = zoneName;
map[thisName].Continent = thisCont;
map[thisName].Location = {
Zone = { x = zx, y = zy },
Continent = { x = cx, y = cy },
Taxi = { x = mx, y = my },
};
for k,v in pairs(destinations) do
map[thisName].Costs[k] = TaxiNodeCost(v);
local routes = GetNumRoutes(v);
if routes > 1 then
local totalTime = 0;
local prevSpot = thisName;
local newRoute = {};
for r = 1, routes do
local dest = FlightMapUtil.makeNodeName(thisCont,
TaxiGetDestX(v, r), TaxiGetDestY(v, r));
table.insert(newRoute, dest);
if map[prevSpot] and map[prevSpot].Flights[dest]
and map[prevSpot].Flights[dest] > 0
and totalTime then
totalTime = totalTime + map[prevSpot].Flights[dest];
else
totalTime = nil;
end
prevSpot = dest;
end
local oldRoute = map[thisName].Routes[k];
local isNewRoute = not oldRoute
or table.getn(oldRoute) ~= table.getn(newRoute)
or table.foreachi(newRoute, function(idx)
return newRoute[idx] ~= oldRoute[idx];
end);
if isNewRoute or map[thisName].Flights[k] == 0 then
map[thisName].Flights[k] = totalTime;
map[thisName].Routes[k] = newRoute;
end
else
map[thisName].Routes[k] = nil;
end
if not map[thisName].Flights[k] then
map[thisName].Flights[k] = 0;
end
end
end
SetMapZoom(oldCont, oldZone);
end
------------------ Miscellaneous utility ------------------
-- Cached faction lookup with time decay (60 second cache)
local function lGetPlayerFaction()
local currentTime = GetTime();
if lFactionCache and (currentTime - lFactionCacheTime) < 60 then
return lFactionCache;
end
lFactionCache = UnitFactionGroup("player");
lFactionCacheTime = currentTime;
return lFactionCache;
end
local function lAutoDismount()
if not FlightMap.Opts.autoDismount then return; end
for i = 0, 15, 1 do
local id, isAura = GetPlayerBuff(i, "HELPFUL");
if isAura and FLIGHTMAP_DISMOUNTS[GetPlayerBuffTexture(id)] then
CancelPlayerBuff(id);
end
end
end
------------------ Map drawing functions ------------------
local function lFormatExtra(cost, secs)
local result = "";
if cost ~= nil and FlightMap.Opts.showCosts then
local dosh = FlightMapUtil.formatMoney(cost);
if cost == 0 then dosh = FLIGHTMAP_NO_COST; end
result = dosh;
end
if secs ~= nil and FlightMap.Opts.showTimes then
local durn = FlightMapUtil.formatTime(secs);
if result ~= "" then
result = result .. " " .. durn;
else
result = durn;
end
end
return result;
end
-- Add node name and location into the given tooltip
local function lAddFlightsForNode(tooltip, node, prefix, source)
if not prefix then prefix = ""; end
local map = FlightMapUtil.getFlightMap();
local data = map[node];
if not data then return 0; end
if not data.Costs then data.Costs = {}; end
local name = data.Name;
local locn = "";
if data.Location.Zone then
locn = string.format("%d, %d", data.Location.Zone.x * 100,
data.Location.Zone.y * 100);
end
if FlightMapUtil.knownNode(node) then
tooltip:AddDoubleLine(prefix .. name, locn);
else
local r = NORMAL_FONT_COLOR.r * 0.7;
local g = NORMAL_FONT_COLOR.g * 0.7;
local b = NORMAL_FONT_COLOR.b * 0.7;
tooltip:AddDoubleLine(prefix .. name, locn, r, g, b, r, g, b);
end
prefix = prefix .. " ";
if source and map[source] then
if map[source].Flights[node] then
local durn = FlightMapUtil.formatTime(map[source].Flights[node]);
GameTooltip:AddLine(prefix .. FLIGHTMAP_FLIGHTTIME .. durn, 1, 1, 1);
end
if map[source].Routes[node] then
local src = map[source];
for i = 1, table.getn(src.Routes[node]) - 1 do
local hop = src.Routes[node][i];
GameTooltip:AddLine(prefix .. FLIGHTMAP_VIA .. map[hop].Name,
0.7, 0.7, 0.7);
end
end
end
if not source and FlightMap.Opts.showDestinations then
for dest, secs in data.Flights do
local islocal = (not data.Routes or not data.Routes[dest]);
local destData = map[dest];
if destData and (islocal or FlightMap.Opts.showMultiHop) then
local name, _ = FlightMapUtil.getNameAndZone(destData.Name);
local cost = data.Costs[dest];
local extra = lFormatExtra(cost, secs);
if FlightMapUtil.knownNode(dest) then
tooltip:AddDoubleLine(prefix .. name, extra,
1, 1, 1, 1, 1, 1);
elseif FlightMap.Opts.showAllInfo then
tooltip:AddDoubleLine(prefix .. name, extra,
0.7, 0.7, 0.7, 0.7, 0.7, 0.7);
end
end
end
end
return 1;
end
FlightMapUtil.addFlightsForNode = lAddFlightsForNode;
-- Update the flight tooltip for a zone
local function lUpdateTooltip(zoneName)
if not zoneName or zoneName == "" then
FlightMapTooltip:Hide();
return;
end
FlightMapTooltip:SetOwner(this, "ANCHOR_LEFT");
local title = FLIGHTMAP_COLORS.Unknown;
local levels = nil;
if (FLIGHTMAP_RANGES[zoneName]) then
local faction = lGetPlayerFaction();
local min = FLIGHTMAP_RANGES[zoneName][1];
local max = FLIGHTMAP_RANGES[zoneName][2];
local side = FLIGHTMAP_RANGES[zoneName][3];
if (side == lTYPE_CONTESTED) then
title = FLIGHTMAP_COLORS.Contested;
else
if (faction == side) then
title = FLIGHTMAP_COLORS.Friendly;
else
title = FLIGHTMAP_COLORS.Hostile;
end
end
levels = string.format(FLIGHTMAP_LEVELS, min, max);
end
FlightMapTooltip:SetText(zoneName, title.r, title.g, title.b);
if levels and FlightMap.Opts.showLevelRanges then
FlightMapTooltip:AddLine(levels, title.r, title.g, title.b);
end
local nodes = FlightMapUtil.getNodesInZone(zoneName, true);
local flights = 0;
for node, data in nodes do
if FlightMapUtil.knownNode(node) or FlightMap.Opts.showAllInfo then
flights = flights + lAddFlightsForNode(FlightMapTooltip, node, "");
end
end
FlightMapTooltip:SetBackdropColor(0, 0, 0, 0.5);
FlightMapTooltip:SetBackdropBorderColor(0, 0, 0, 0);
FlightMapTooltip:ClearAllPoints();
FlightMapTooltip:SetPoint("BOTTOMLEFT", "WorldMapDetailFrame",
"BOTTOMLEFT", 0, 0);
if flights > 0 or (levels and FlightMap.Opts.showLevelRanges) then
FlightMapTooltip:Show();
else
FlightMapTooltip:Hide();
end
FlightMapTooltip:ClearAllPoints();
FlightMapTooltip:SetPoint("BOTTOMLEFT", WorldMapDetailFrame);
end
-- Returns true iff an existing world map POI icon is very close to the given coordinates
local function lCloseToExistingPOI(x, y)
local closeDistSq = FLIGHTMAP_CLOSE_SQ;
for i = 1, NUM_WORLDMAP_POIS, 1 do
local button = getglobal("WorldMapFramePOI" .. i);
if button:IsVisible() then
local _, _, index, _, _ = GetMapLandmarkInfo(i);
if index ~= 15 then
local px, py = button:GetCenter();
px = px - WorldMapDetailFrame:GetLeft();
py = py - WorldMapDetailFrame:GetBottom();
local dx = px - x;
local dy = py - y;
if (dx * dx + dy * dy) < closeDistSq then
return true;
end
end
end
end
return false;
end
-- Try showing a POI node
local function lShowNodePOI(node, data, space, num)
if not data.Location[space] then return false; end
if num > FLIGHTMAP_MAX_POIS then return false; end
local x = data.Location[space].x;
local y = data.Location[space].y;
x = x * WorldMapDetailFrame:GetWidth();
y = (1 - y) * WorldMapDetailFrame:GetHeight();
if lCloseToExistingPOI(x, y) then return false; end
local name, _ = FlightMapUtil.getNameAndZone(data.Name);
local button = lPOIButtonCache[num];
if not button then
button = getglobal("FlightMapPOI" .. num);
lPOIButtonCache[num] = button;
end
if not FlightMapUtil.knownNode(node) then
if not FlightMap.Opts.showAllInfo then
return false;
end
button:SetNormalTexture(FLIGHTMAP_POI_OTHER);
else
button:SetNormalTexture(FLIGHTMAP_POI_KNOWN);
end
button.name = name;
button.data = data;
button.node = node;
button:SetPoint("CENTER", "WorldMapDetailFrame",
"BOTTOMLEFT", x, y);
button:Show();
return true;
end
-- Show locations of flight masters for either continent or zone level maps
local function lUpdateFlightPOIs(zoneName)
local continent = GetCurrentMapContinent();
local mapZone = GetCurrentMapZone();
local POI = 1;
if mapZone ~= 0 and FlightMap.Opts.showPOIs then
local nodes = FlightMapUtil.getNodesInZone(zoneName, false);
for node, data in nodes do
if lShowNodePOI(node, data, "Zone", POI) then
POI = POI + 1;
end
end
elseif continent ~= 0 and FlightMap.Opts.showPOIs then
local map = FlightMapUtil.getFlightMap();
for node, data in map do
if data.Continent == continent then
if lShowNodePOI(node, data, "Continent", POI) then
POI = POI + 1;
end
end
end
end
for i = POI, FLIGHTMAP_MAX_POIS, 1 do
local button = lPOIButtonCache[i];
if not button then
button = getglobal("FlightMapPOI" .. i);
lPOIButtonCache[i] = button;
end
button:Hide();
end
end
-- Draw a line from one flight node to another
local function lDrawFlightLine(from, to, num)
if num > FLIGHTMAP_MAX_PATHS then return false; end
local map = FlightMapUtil.getFlightMap();
if not map[from] or not map[to] then return false; end
local src = map[from].Location.Continent;
local dst = map[to].Location.Continent;
if not src or not dst then return false; end
local tex = lPathFrameCache[num];
if not tex then
tex = getglobal("FlightMapPath" .. num);
lPathFrameCache[num] = tex;
end
return FlightMapUtil.drawLine(WorldMapDetailFrame, tex,
src.x, src.y, dst.x, dst.y);
end
-- Fill in flight map lines
local function lDrawFlightLines(zoneName)
local lineNum = 1;
if zoneName and FlightMap.Opts.showPaths then
local nodes = FlightMapUtil.getNodesInZone(zoneName, true);
for node, data in nodes do
if FlightMap.Opts.showAllInfo or FlightMapUtil.knownNode(node) then
for dest, duration in data.Flights do
if not (data.Routes and data.Routes[dest])
and (FlightMap.Opts.showAllInfo
or FlightMapUtil.knownNode(dest)) then
if lDrawFlightLine(node, dest, lineNum) then
lineNum = lineNum + 1;
end
end
end
end
end
end
for i = lineNum, FLIGHTMAP_MAX_PATHS, 1 do
local tex = lPathFrameCache[i];
if not tex then
tex = getglobal("FlightMapPath" .. i);
lPathFrameCache[i] = tex;
end
tex:Hide();
end
end
-- Last drawn info for tooltip
lFM_CurrentZone = nil;
lFM_CurrentArea = nil;
local lFM_OldUpdate = function() end;
-- Replacement function to draw all the extra goodies of FlightMap
function FlightMap_WorldMapButton_OnUpdate(arg1)
lFM_OldUpdate(arg1);
local areaName = WorldMapFrame.areaName;
local zoneNum = GetCurrentMapZone();
if FLIGHTMAP_SUBZONES[areaName] then
areaName = FLIGHTMAP_SUBZONES[areaName];
end
if zoneNum == lFM_CurrentZone and areaName == lFM_CurrentArea then
return;
end
lFM_CurrentZone = zoneNum;
lFM_CurrentArea = areaName;
if zoneNum == 0 then
lUpdateTooltip(areaName);
lUpdateFlightPOIs(areaName);
lDrawFlightLines(areaName);
else
lUpdateFlightPOIs(FlightMapUtil.getZoneName());
lUpdateTooltip(nil);
lDrawFlightLines(nil);
end
end
function FlightMapPOIButton_OnEnter()
local x, y = this:GetCenter();
local parentX, parentY = WorldMapDetailFrame:GetCenter();
if (x > parentX) then
WorldMapTooltip:SetOwner(this, "ANCHOR_LEFT");
else
WorldMapTooltip:SetOwner(this, "ANCHOR_RIGHT");
end
lAddFlightsForNode(WorldMapTooltip, this.node, "");
WorldMapTooltip:Show();
end
---------------- Initialization functions -----------------
-- /flightmap handler
function FlightMap_OnSlashCmd(args)
if args == FLIGHTMAP_RESET then
FlightMapTimesFrame:ClearAllPoints();
FlightMapTimesFrame:SetPoint("TOP", PVPArenaTextString, "BOTTOM");
elseif args == FLIGHTMAP_SHOWMAP then
FlightMapTaxi_ShowContinent();
elseif args == FLIGHTMAP_LOCKTIMES then
FlightMap.Opts.lockFlightTimes = not FlightMap.Opts.lockFlightTimes;
DEFAULT_CHAT_FRAME:AddMessage(
FLIGHTMAP_TIMESLOCKED[FlightMap.Opts.lockFlightTimes],
1.0, 1.0, 1.0);
elseif args == FLIGHTMAP_GETHELP then
for cmd, desc in FLIGHTMAP_SUBCOMMANDS do
DEFAULT_CHAT_FRAME:AddMessage("|cffcc9010" .. cmd .. "|r " .. desc,
1.0, 1.0, 1.0);
end
elseif (FlightMapOptionsFrame:IsVisible()) then
HideUIPanel(FlightMapOptionsFrame);
else
ShowUIPanel(FlightMapOptionsFrame);
end
end
function FlightMap_OnLoad()
this:RegisterEvent("TAXIMAP_OPENED");
if (Sea) then
Sea.util.hook("WorldMapButton_OnUpdate",
"FlightMap_WorldMapButton_OnUpdate",
"after");
else
lFM_OldUpdate = WorldMapButton_OnUpdate;
WorldMapButton_OnUpdate = FlightMap_WorldMapButton_OnUpdate;
end
SLASH_FLIGHTMAP1 = "/fmap";
SLASH_FLIGHTMAP2 = "/flightmap";
SlashCmdList["FLIGHTMAP"] = FlightMap_OnSlashCmd;
this:RegisterEvent("VARIABLES_LOADED");
UIPanelWindows["FlightMapOptionsFrame"] = {
area = "center",
pushable = 0,
};
end
function FlightMap_OnEvent(event)
if (event == "TAXIMAP_OPENED") then
lAutoDismount();
lLearnTaxiNode();
elseif (event == "VARIABLES_LOADED") then
lSetDefaultData();
FlightMap_UpdateTooltipFont();
if (myAddOnsFrame_Register) then
myAddOnsFrame_Register({
name = "FlightMap",
version = FLIGHTMAP_VERSION,
releaseDate = FLIGHTMAP_RELEASE,
author = "Dhask",
category = MYADDONS_CATEGORY_MAP,
optionsframe = "FlightMapOptionsFrame",
});
end
end
end
----------------- Options panel functions -----------------
function FlightMapOptionsFrame_OnShow()
FlightMapOptionsFrameClose:SetText(FLIGHTMAP_OPTIONS_CLOSE);
FlightMapOptionsFrameTitle:SetText(FLIGHTMAP_OPTIONS_TITLE);
local base = "FlightMapOptionsFrame"
for optid, option in pairs(FLIGHTMAP_OPTIONS or {}) do
local name = base .. "Opt" .. optid;
local button = getglobal(name);
local label = getglobal(name .. "Text");
OptionsFrame_EnableCheckBox(button, 1, FlightMap.Opts[option.option]);
label:SetText(option.label);
button.tooltipText = option.tooltip;
button.option = option.option;
button.children = option.children or {};
end
for optid, option in pairs(FLIGHTMAP_OPTIONS or {}) do
for _, child in option.children or {} do
local other = getglobal(base .. "Opt" .. child);
if other then
if FlightMap.Opts[option.option] then
OptionsFrame_EnableCheckBox(other, 1,
FlightMap.Opts[FLIGHTMAP_OPTIONS[child].option]);
else
OptionsFrame_DisableCheckBox(other);
end
end
end
end
if not FlightMapLevelRangesCheckButton then
local button = CreateFrame("CheckButton", "FlightMapLevelRangesCheckButton", FlightMapOptionsFrame, "OptionsCheckButtonTemplate");
button:SetPoint("TOPLEFT", FlightMapOptionsFrameClose, "BOTTOMLEFT", 35, 109);
button:SetChecked(FlightMap.Opts.showLevelRanges);
button.option = "showLevelRanges";
button.children = {};
button:SetScript("OnClick", FlightMapOptionsCheckButton_OnClick);
local label = button:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall");
label:SetPoint("LEFT", button, "RIGHT", 2, 0);
label:SetText("Show Level Ranges");
button.tooltipText = "Display the recommended level range for each zone";
button:SetScript("OnEnter", function()
if (button.tooltipText) then
GameTooltip:SetOwner(button, "ANCHOR_RIGHT");
GameTooltip:AddLine(button.tooltipText, 1, 1, 1);
GameTooltip:Show();
end
end);
button:SetScript("OnLeave", function()
GameTooltip:Hide();
end);
else
FlightMapLevelRangesCheckButton:SetChecked(FlightMap.Opts.showLevelRanges);
end
if not FlightMapFontSizeSlider then
CreateFrame("Slider", "FlightMapFontSizeSlider", FlightMapOptionsFrame, "OptionsSliderTemplate");
FlightMapFontSizeSlider:SetWidth(220);
FlightMapFontSizeSlider:SetHeight(16);
FlightMapFontSizeSlider:SetOrientation("HORIZONTAL");
FlightMapFontSizeSlider:SetPoint("TOP", FlightMapOptionsFrameClose, "BOTTOM", 0, 55);
FlightMapFontSizeSlider:SetMinMaxValues(8, 20);
FlightMapFontSizeSlider:SetValueStep(1);
local txt = getglobal("FlightMapFontSizeSliderText");
if txt then txt:SetText("Tooltip Font Size"); end
local low = getglobal("FlightMapFontSizeSliderLow");
local high = getglobal("FlightMapFontSizeSliderHigh");
if low then low:SetText("8"); end
if high then high:SetText("20"); end
FlightMapFontSizeSlider.tooltipText = "Adjusts the font size of the FlightMap tooltip text.";
FlightMapFontSizeSlider:SetScript("OnEnter", function()
if FlightMapFontSizeSlider.tooltipText then
GameTooltip:SetOwner(FlightMapFontSizeSlider, "ANCHOR_RIGHT");
GameTooltip:AddLine(FlightMapFontSizeSlider.tooltipText, 1, 1, 1);
GameTooltip:Show();
end
end);
FlightMapFontSizeSlider:SetScript("OnLeave", function()
GameTooltip:Hide();
end);
local function FlightMapFontSizeSlider_Internal_OnValueChanged(maybeSelf, maybeValue)
local frame = maybeSelf or this;
if not frame then
frame = getglobal("FlightMapFontSizeSlider");
end
if not frame then return; end
local value = maybeValue;
if not value then
if type(maybeSelf) == "number" then
value = maybeSelf;
else
value = frame:GetValue();
end
end
local val = tonumber(value) or frame:GetValue() or 12;
val = math.floor(val +0.5);
if not FlightMap then FlightMap = {}; end
if not FlightMap.Opts then FlightMap.Opts = {}; end
FlightMap.Opts.fontSize = val;
if FlightMap_UpdateTooltipFont then
FlightMap_UpdateTooltipFont();
end
end
FlightMapFontSizeSlider:SetScript("OnValueChanged", FlightMapFontSizeSlider_Internal_OnValueChanged);
end
FlightMapFontSizeSlider:SetValue( (FlightMap and FlightMap.Opts and FlightMap.Opts.fontSize) or 12 );
if FlightMap_UpdateTooltipFont then FlightMap_UpdateTooltipFont(); end
end
function FlightMapOptionsFrame_OnHide()
if (MYADDONS_ACTIVE_OPTIONSFRAME == this) then
ShowUIPanel(myAddOnsFrame);
end
end
function FlightMapOptionsCheckButton_OnClick()
if (this:GetChecked()) then
FlightMap.Opts[this.option] = true;
else
FlightMap.Opts[this.option] = false;
end
local base = "FlightMapOptionsFrame";
for _, child in this.children do
local other = getglobal(base .. "Opt" .. child);
if other then
if FlightMap.Opts[this.option] then
OptionsFrame_EnableCheckBox(other, 1,
FlightMap.Opts[FLIGHTMAP_OPTIONS[child].option]);
else
OptionsFrame_DisableCheckBox(other);
end
end
end
end
function FlightMap_UpdateTooltipFont()
local size = 12;
if FlightMap and FlightMap.Opts and FlightMap.Opts.fontSize then
size = FlightMap.Opts.fontSize;
end
local maxLines = 30;
for i = 1, maxLines do
local left = getglobal("FlightMapTooltipTextLeft" .. i)
if left and left.SetFont then
left:SetFont("Fonts\\FRIZQT__.TTF", size)
end
local right = getglobal("FlightMapTooltipTextRight" .. i)
if right and right.SetFont then
right:SetFont("Fonts\\FRIZQT__.TTF", size)
end
end
end
if hooksecurefunc then
hooksecurefunc("FlightMap_WorldMapButton_OnUpdate", function()
if FlightMap and FlightMap.Opts then
FlightMap_UpdateTooltipFont();
end
end);
else
local _old_WorldMapButton_OnUpdate = FlightMap_WorldMapButton_OnUpdate;
function FlightMap_WorldMapButton_OnUpdate(arg1)
_old_WorldMapButton_OnUpdate(arg1);
if FlightMap and FlightMap.Opts then
FlightMap_UpdateTooltipFont();
end
end
end