forked from Justw8/TeleportMenu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTeleportMenu.lua
More file actions
1222 lines (1069 loc) · 38 KB
/
TeleportMenu.lua
File metadata and controls
1222 lines (1069 loc) · 38 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
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local _, tpm = ...
--------------------------------------
-- Libraries
--------------------------------------
local L = LibStub("AceLocale-3.0"):GetLocale("TeleportMenu")
local MSQ = LibStub("Masque", true)
local MasqueGroup = MSQ and MSQ:Group(L["ADDON_NAME"])
--------------------------------------
-- Locales
--------------------------------------
local db = {}
local APPEND = L["AddonNamePrint"]
local DEFAULT_ICON = "Interface\\Icons\\INV_Misc_QuestionMark"
local globalWidth, globalHeight = 40, 40 -- defaults
tpm.TEXTURE_SCALE = 0
local IsSpellKnown = C_SpellBook.IsSpellKnown
local issecretvalue = issecretvalue or function() return false end
function tpm:IsSecret(value)
return issecretvalue(value)
end
--------------------------------------
-- Teleport Tables
--------------------------------------
local availableSeasonalTeleports = {}
local shortNames = {
-- CATA
[410080] = L["The Vortex Pinnacle"],
[424142] = L["Throne of the Tides"],
[445424] = L["Grim Batol"],
-- WLK
[1254555] = L["Pit of Saron"], -- Midnight S1
-- MoP
[131204] = L["Temple of the Jade Serpent"],
[131205] = L["Stormstout Brewery"],
[131206] = L["Shado-Pan Monastery"],
[131222] = L["Mogu'shan Palace"],
[131225] = L["Gate of the Setting Sun"],
[131228] = L["Siege of Niuzao Temple"],
[131229] = L["Scarlet Monastery"],
[131231] = L["Scarlet Halls"],
[131232] = L["Scholomance"],
-- WoD
[159901] = L["The Everbloom"],
[159899] = L["Shadowmoon Burial Grounds"],
[159900] = L["Grimrail Depot"],
[159896] = L["Iron Docks"],
[159895] = L["Bloodmaul Slag Mines"],
[159897] = L["Auchindoun"],
[159898] = L["Skyreach"],
[159902] = L["Upper Blackrock Spire"],
[1254557] = L["Skyreach"], -- Midnight S1
-- Legion
[393764] = L["Halls of Valor"],
[410078] = L["Neltharion's Lair"],
[393766] = L["Court of Stars"],
[373262] = L["Karazhan"],
[424153] = L["Black Rook Hold"],
[424163] = L["Darkheart Thicket"],
[1254551] = L["Seat of the Triumvirate"], -- Midnight S1
-- BFA
[410071] = L["Freehold"],
[410074] = L["The Underrot"],
[373274] = L["Mechagon"],
[424167] = L["Waycrest Manor"],
[424187] = L["Atal'Dazar"],
[445418] = L["Siege of Boralus"],
[464256] = L["Siege of Boralus"],
[467553] = L["The MOTHERLODE!!"],
[467555] = L["The MOTHERLODE!!"],
-- SL
[354462] = L["The Necrotic Wake"],
[354463] = L["Plaguefall"],
[354464] = L["Mists of Tirna Scithe"],
[354465] = L["Halls of Atonement"],
[354466] = L["Bastion"],
[354467] = L["Theater of Pain"],
[354468] = L["De Other Side"],
[354469] = L["Sanguine Depths"],
[367416] = L["Tazavesh, the Veiled Market"],
-- SL R
[373190] = L["Castle Nathria"],
[373191] = L["Sanctum of Domination"],
[373192] = L["Sepulcher of the First Ones"],
-- DF
[393256] = L["Ruby Life Pools"],
[393262] = L["The Nokhud Offensive"],
[393267] = L["Brackenhide Hollow"],
[393273] = L["Algeth'ar Academy"], -- Midnight S1
[393276] = L["Neltharus"],
[393279] = L["The Azure Vault"],
[393283] = L["Halls of Infusion"],
[393222] = L["Uldaman"],
[424197] = L["Dawn of the Infinite"],
-- DF R
[432254] = L["Vault of the Incarnates"],
[432257] = L["Aberrus, the Shadowed Crucible"],
[432258] = L["Amirdrassil, the Dream's Hope"],
-- TWW
[445416] = L["City of Threads"],
[445414] = L["The Dawnbreaker"],
[445269] = L["The Stonevault"],
[445443] = L["The Rookery"],
[445440] = L["Cinderbrew Meadery"],
[445444] = L["Priory of the Sacred Flame"],
[445417] = L["Ara-Kara, City of Echoes"],
[445441] = L["Darkflame Cleft"],
[1216786] = L["Operation: Floodgate"],
[1237215] = L["Eco-Dome Al'dani"],
-- TWW R
[1226482] = L["Liberation of Undermine"],
[1239155] = L["Manaforge Omega"],
-- Midnight
[1254400] = L["Windrunner Spire"], -- Midnight S1
[1254559] = L["Maisara Caverns"], -- Midnight S1
[1254563] = L["Nexus-Point Xenas"], -- Midnight S1
[1254572] = L["Magisters' Terrace"], -- Midnight S1
-- Midnight R
-- Mage teleports
[3561] = L["Stormwind"],
[3562] = L["Ironforge"],
[3563] = L["Undercity"],
[3565] = L["Darnassus"],
[3566] = L["Thunder Bluff"],
[3567] = L["Orgrimmar"],
[32271] = L["Exodar"],
[32272] = L["Silvermoon"],
[33690] = L["Shattrath"],
[35715] = L["Shattrath"],
[49358] = L["Stonard"],
[49359] = L["Theramore"],
[53140] = L["Dalaran - Northrend"],
[88342] = L["Tol Barad"], -- Alliance
[88344] = L["Tol Barad"], -- Horde
[120145] = L["Dalaran - Ancient"],
[132621] = L["Vale of Eternal Blossoms"], -- Alliance
[132627] = L["Vale of Eternal Blossoms"], -- Horde
[176242] = L["Warspear"],
[176248] = L["Stormshield"],
[193759] = L["Hall of the Guardian"],
[224869] = L["Dalaran - Broken Isles"],
[281403] = L["Boralus"],
[281404] = L["Dazar'alor"],
[344587] = L["Oribos"],
[395277] = L["Valdrakken"],
[446540] = L["Dornogal"],
-- Mage portals
[10059] = L["Stormwind"],
[11416] = L["Ironforge"],
[11417] = L["Orgrimmar"],
[11418] = L["Undercity"],
[11419] = L["Darnassus"],
[11420] = L["Thunder Bluff"],
[32266] = L["Exodar"],
[32267] = L["Silvermoon"],
[33691] = L["Shattrath"],
[35717] = L["Shattrath"],
[49360] = L["Theramore"],
[49361] = L["Stonard"],
[53142] = L["Dalaran - Northrend"],
[88345] = L["Tol Barad"], -- Alliance
[88346] = L["Tol Barad"], -- Horde
[120146] = L["Dalaran - Ancient"],
[132620] = L["Vale of Eternal Blossoms"], -- Alliance
[132626] = L["Vale of Eternal Blossoms"], -- Horde
[176244] = L["Warspear"],
[176246] = L["Stormshield"],
[224871] = L["Dalaran - Broken Isles"],
[281400] = L["Boralus"],
[281402] = L["Dazar'alor"],
[344597] = L["Oribos"],
[395289] = L["Valdrakken"],
[446534] = L["Dornogal"],
[1259194] = L["Silvermoon City"], -- Midnight
}
local tpTable = {
-- Hearthstones
{ id = 6948, type = "item", hearthstone = true }, -- Hearthstone
{ id = 1233637, type = "housing", faction = "Alliance"}, -- Teleport Home (Alliance House)
{ id = 1233637, type = "housing", faction = "Horde"}, -- Teleport Home (Horde House)
{ id = 556, type = "spell" }, -- Astral Recall (Shaman)
{ id = 110560, type = "toy", quest = { 34378, 34586 } }, -- Garrison Hearthstone
{ id = 140192, type = "toy", quest = { 44184, 44663 } }, -- Dalaran Hearthstone
-- Engineering
{ type = "wormholes", iconId = 4620673 }, -- Engineering Wormholes
{ type = "item_teleports", iconId = 133655 }, -- Item Teleports
-- Class Teleports
{ id = 1, type = "flyout", iconId = 237509, subtype = "mage" }, -- Teleport (Mage) (Horde)
{ id = 8, type = "flyout", iconId = 237509, subtype = "mage" }, -- Teleport (Mage) (Alliance)
{ id = 11, type = "flyout", iconId = 135744, subtype = "mage" }, -- Portals (Mage) (Horde)
{ id = 12, type = "flyout", iconId = 135748, subtype = "mage" }, -- Portals (Mage) (Alliance)
{ id = 126892, type = "spell" }, -- Zen Pilgrimage (Monk)
{ id = 50977, type = "spell" }, -- Death Gate (Death Knight)
{ id = 18960, type = "spell" }, -- Teleport: Moonglade (Druid)
{ id = 193753, type = "spell" }, -- Dreamwalk (Druid) (replaces Teleport: Moonglade)
-- Racials
{ id = 312370, type = "spell" }, -- Make Camp (Vulpera)
{ id = 312372, type = "spell" }, -- Return to Camp (Vulpera)
{ id = 265225, type = "spell" }, -- Mole Machine (Dark Iron Dwarf)
-- Dungeon/Raid Teleports
{ id = 230, type = "flyout", iconId = 574788, name = L["Cataclysm"], subtype = "path" }, -- Hero's Path: Cataclysm
{ id = 84, type = "flyout", iconId = 328269, name = L["Mists of Pandaria"], subtype = "path" }, -- Hero's Path: Mists of Pandaria
{ id = 96, type = "flyout", iconId = 1413856, name = L["Warlords of Draenor"], subtype = "path" }, -- Hero's Path: Warlords of Draenor
{ id = 224, type = "flyout", iconId = 1260827, name = L["Legion"], subtype = "path" }, -- Hero's Path: Legion
{ id = 223, type = "flyout", iconId = 1869493, name = L["Battle for Azeroth"], subtype = "path" }, -- Hero's Path: Battle for Azeroth
{ id = 220, type = "flyout", iconId = 236798, name = L["Shadowlands"], subtype = "path" }, -- Hero's Path: Shadowlands
{ id = 222, type = "flyout", iconId = 4062765, name = L["Shadowlands Raids"], subtype = "path" }, -- Hero's Path: Shadowlands Raids
{ id = 227, type = "flyout", iconId = 4640496, name = L["Dragonflight"], subtype = "path" }, -- Hero's Path: Dragonflight
{ id = 231, type = "flyout", iconId = 5342925, name = L["Dragonflight Raids"], subtype = "path" }, -- Hero's Path: Dragonflight Raids
{ id = 232, type = "flyout", iconId = 5872031, name = L["The War Within"], subtype = "path" }, -- Hero's Path: The War Within
{ id = 242, type = "flyout", iconId = 6997112, name = L["The War Within Raids"], subtype = "path" }, -- Hero's Path: The War Within Raids
{ id = 246, type = "flyout", iconId = 7266215, name = L["Midnight"], subtype = "path", currentExpansion=true }, -- Hero's Path: Midnight
--{ id = 246, type = "flyout", iconId = 7266215, name = L["Midnight Raids"], subtype = "path" }, -- Hero's Path: Midnight Raids
}
local GetItemCount = C_Item.GetItemCount
--------------------------------------
-- Texture Stuff
--------------------------------------
local function SetTextureByItemId(frame, itemId)
frame.icon:SetTexture(DEFAULT_ICON) -- Temp while loading
local item = Item:CreateFromItemID(tonumber(itemId))
item:ContinueOnItemLoad(function()
local icon = item:GetItemIcon()
frame.icon:SetTexture(icon)
end)
end
--------------------------------------
--- Tooltip
--------------------------------------
local function setCombatTooltip(self)
GameTooltip:SetOwner(self, "ANCHOR_NONE")
local yOffset = globalHeight / 2
GameTooltip:SetPoint("BOTTOMLEFT", TeleportMeButtonsFrameRight, "TOPRIGHT", 0, yOffset)
GameTooltip:SetText(L["Not In Combat Tooltip"], 1, 1, 1)
GameTooltip:Show()
end
local function setToolTip(self, tpType, id, hs)
GameTooltip:SetOwner(self, "ANCHOR_NONE")
local yOffset = globalHeight / 2
GameTooltip:SetPoint("BOTTOMLEFT", TeleportMeButtonsFrameRight, "TOPRIGHT", 0, yOffset)
if hs and db["Teleports:Hearthstone"] and db["Teleports:Hearthstone"] == "rng" then
local bindLocation = GetBindLocation()
GameTooltip:SetText(L["Random Hearthstone"], 1, 1, 1)
GameTooltip:AddLine(L["Random Hearthstone Tooltip"], 1, 1, 1)
GameTooltip:AddLine(L["Random Hearthstone Location"]:format(bindLocation), 1, 1, 1, true) -- `false` is supposed to disable text wrapping, but somehow `true` works that way in action
elseif tpType == "item" then
GameTooltip:SetItemByID(id)
elseif tpType == "item_teleports" then
GameTooltip:SetText(L["Item Teleports"] .. "\n" .. L["Item Teleports Tooltip"], 1, 1, 1)
elseif tpType == "toy" then
GameTooltip:SetToyByItemID(id)
elseif tpType == "spell" then
GameTooltip:SetSpellByID(id)
elseif tpType == "flyout" then
local name = GetFlyoutInfo(id)
GameTooltip:SetText(name, 1, 1, 1)
elseif tpType == "profession" then
local professionInfo = C_TradeSkillUI.GetProfessionInfoBySkillLineID(id)
if professionInfo then
GameTooltip:SetText(professionInfo.professionName, 1, 1, 1)
end
elseif tpType == "seasonalteleport" then
local currExpID = GetExpansionLevel()
local expName = _G["EXPANSION_NAME" .. currExpID]
local title = MYTHIC_DUNGEON_SEASON:format(expName, tpm.settings.current_season)
GameTooltip:SetText(title, 1, 1, 1)
GameTooltip:AddLine(L["Seasonal Teleports Tooltip"], 1, 1, 1)
end
GameTooltip:Show()
end
--------------------------------------
-- Frames
--------------------------------------
local flyOutButtons = {}
local flyOutButtonsPool = {}
local flyOutFrames = {}
local flyOutFramesPool = {}
local secureButtons = {}
local secureButtonsPool = {}
local function createCooldownFrame(frame)
if frame.cooldownFrame then
return frame.cooldownFrame
end
local cooldownFrame = CreateFrame("Cooldown", nil, frame, "CooldownFrameTemplate")
cooldownFrame:SetAllPoints()
function cooldownFrame:CheckCooldown(id, buttonType)
if buttonType ~= "housing" and not id then
return
end
local start, duration, enabled
if buttonType == "toy" or buttonType == "item" then
start, duration, enabled = C_Item.GetItemCooldown(id)
elseif buttonType == "housing" then
local cdInfo = C_Housing.GetVisitCooldownInfo()
start = cdInfo.startTime
duration = cdInfo.duration
enabled = cdInfo.isEnabled
else
local cooldown = C_Spell.GetSpellCooldown(id)
start = cooldown.startTime
duration = cooldown.duration
enabled = true
end
if enabled and not tpm:IsSecret(duration) and duration > 0 then
self:SetCooldown(start, duration)
else
self:Clear()
end
end
return cooldownFrame
end
local function CloseAllFlyouts()
for _, frame in ipairs(flyOutFrames) do
frame:Hide()
end
end
local function createFlyOutButton(flyOutFrame, flyoutData, tooltipData, side) -- Flyout Data needs: id, name, iconId
local flyOutButton
if next(flyOutButtonsPool) then
flyOutButton = table.remove(flyOutButtonsPool)
else
flyOutButton = CreateFrame("Button", nil, side == "LEFT" and TeleportMeButtonsFrameLeft or TeleportMeButtonsFrameRight, "SecureActionButtonTemplate")
function flyOutButton:SetFlyOutFrame(frame)
self.flyoutFrame = frame
end
function flyOutButton:Recycle()
self:ClearAllPoints()
self:SetFlyOutFrame(nil)
self:Hide()
table.insert(flyOutButtonsPool, self)
if MasqueGroup then
MasqueGroup:RemoveButton(self)
end
end
-- Text
flyOutButton.text = flyOutButton:CreateFontString(nil, "OVERLAY")
flyOutButton.text:SetPoint("BOTTOM", flyOutButton, "BOTTOM", 0, 5)
flyOutButton.text:SetTextColor(1, 1, 1, 1)
-- Icon
flyOutButton.icon = flyOutButton:CreateTexture(nil, "BACKGROUND")
flyOutButton.icon:SetAllPoints()
-- Frame Levels
flyOutButton:SetFrameStrata("HIGH")
flyOutButton:SetFrameLevel(101)
-- Mouse Interaction
flyOutButton:EnableMouse(true)
flyOutButton:RegisterForClicks("AnyDown", "AnyUp")
flyOutButton:SetAttribute("useOnKeyDown", true)
table.insert(flyOutButtons, flyOutButton)
end
flyOutButton:SetFlyOutFrame(flyOutFrame)
-- Tooltips
local tooltipType = "flyout"
local tooltipId = flyoutData.id
if tooltipData then
tooltipType = tooltipData.type
tooltipId = tooltipData.id
end
flyOutButton:SetScript("OnEnter", function(self)
if InCombatLockdown() then
setCombatTooltip(self)
return
end
CloseAllFlyouts()
setToolTip(self, tooltipType, tooltipId)
self.flyoutFrame:Show()
end)
flyOutButton:SetScript("OnLeave", function(self)
GameTooltip:Hide()
end)
-- Text
flyOutButton.text:Hide()
if db["Button:Text:Show"] == true and flyoutData.name then
flyOutButton.text:SetFont(STANDARD_TEXT_FONT, db["Button:Text:Size"], "OUTLINE")
flyOutButton.text:SetText(flyoutData.name)
flyOutButton.text:Show()
end
-- Texture
flyOutButton.icon:SetTexture(flyoutData.iconId)
local zoomFactor = tpm.TEXTURE_SCALE
local offset = zoomFactor / 2
flyOutButton.icon:SetTexCoord(offset, 1-offset, offset, 1-offset)
-- Size
flyOutButton:SetSize(globalWidth, globalHeight)
flyOutButton:Show()
if MasqueGroup then
MasqueGroup:AddButton(flyOutButton, { Icon = flyOutButton.icon })
end
return flyOutButton
end
local function createFlyOutFrame(side)
local flyOutFrame
if next(flyOutFramesPool) then
flyOutFrame = table.remove(flyOutFramesPool)
else
flyOutFrame = CreateFrame("Frame", nil)
function flyOutFrame:Recycle()
self:ClearAllPoints()
self:Hide()
table.insert(flyOutFramesPool, self)
end
flyOutFrame:SetFrameStrata("HIGH")
flyOutFrame:SetFrameLevel(103)
flyOutFrame:SetPropagateMouseClicks(true)
flyOutFrame:SetPropagateMouseMotion(true)
flyOutFrame:SetScript("OnLeave", function(self)
GameTooltip:Hide()
if not InCombatLockdown() then -- XXX Needed?
self:Hide()
end
end)
table.insert(flyOutFrames, flyOutFrame)
end
flyOutFrame:SetParent(side == "LEFT" and TeleportMeButtonsFrameLeft or TeleportMeButtonsFrameRight)
flyOutFrame:Hide()
return flyOutFrame
end
---@param id ItemInfo
---@return boolean
local function IsItemEquipped(id)
return C_Item.IsEquippableItem(id) and C_Item.IsEquippedItem(id)
end
local function ClearAllInvalidHighlights()
for _, button in pairs(secureButtons) do
button:ClearHighlightTexture()
if button:GetAttribute("item") ~= nil then
local id = string.match(button:GetAttribute("item"), "%d+")
if IsItemEquipped(id) then
button:Highlight()
end
end
end
end
---@param frame Frame
---@param buttonType string
---@param text string|nil
---@param id integer
---@param hearthstone? boolean
---@return Frame
local function CreateSecureButton(frame, buttonType, text, id, hearthstone)
local button
if next(secureButtonsPool) then
button = table.remove(secureButtonsPool)
else
button = CreateFrame("Button", nil, nil, "SecureActionButtonTemplate")
function button:Recycle()
self.buttonType = nil
self.id = nil
self.hearthstone = nil
self:ClearHighlightTexture()
self:SetParent(nil)
self:ClearAllPoints()
self:Hide()
table.insert(secureButtonsPool, self)
if MasqueGroup then
MasqueGroup:RemoveButton(self)
end
end
-- Icon
button.icon = button:CreateTexture(nil, "BACKGROUND")
button.icon:SetAllPoints()
-- Cooldown Frame
button.cooldownFrame = createCooldownFrame(button)
function button:CheckCooldown()
self.cooldownFrame:CheckCooldown(self.id, self.buttonType)
end
-- Text
button.text = button:CreateFontString(nil, "OVERLAY")
button.text:SetPoint("BOTTOM", button, "BOTTOM", 0, 5)
button.text:SetTextColor(1, 1, 1, 1)
-- Highlighting
function button:Highlight()
self:SetHighlightAtlas("talents-node-choiceflyout-square-green")
end
button:LockHighlight()
-- Mouse Interaction
button:EnableMouse(true)
button:RegisterForClicks("AnyDown", "AnyUp")
button:SetAttribute("useOnKeyDown", true)
-- Scripts
button:SetScript("OnLeave", function(self)
GameTooltip:Hide()
end)
button:SetScript("PostClick", function(self)
if self.buttonType == "item" and C_Item.IsEquippableItem(self.id) then
C_Timer.After(0.25, function() -- Slight delay due to equipping the item not being instant.
if IsItemEquipped(self.id) then
ClearAllInvalidHighlights()
self:Highlight()
end
end)
if IsItemEquipped(self.id) then
tpm:CloseMainMenu()
end
else
tpm:CloseMainMenu()
end
end)
button:SetScript("OnEnter", function(self)
setToolTip(self, self.buttonType, self.id, self.hearthstone)
end)
button:SetScript("OnShow", function(self)
self:CheckCooldown()
end)
table.insert(secureButtons, button)
end
-- Properties
button.buttonType = buttonType
button.id = id
button.hearthstone = hearthstone
-- Text
button.text:Hide()
if db["Button:Text:Show"] == true and text then
button.text:SetFont(STANDARD_TEXT_FONT, db["Button:Text:Size"], "OUTLINE")
button.text:SetText(text)
button.text:Show()
end
-- Cooldown
button:CheckCooldown()
-- Textures
if buttonType == "spell" then
local spellTexture = C_Spell.GetSpellTexture(id)
button.icon:SetTexture(spellTexture)
else -- item or toy
SetTextureByItemId(button, id)
end
local zoomFactor = tpm.TEXTURE_SCALE
local offset = zoomFactor / 2
button.icon:SetTexCoord(offset, 1-offset, offset, 1-offset)
-- Attributes
button:SetAttribute("type", buttonType)
if buttonType == "item" then
button:SetAttribute(buttonType, "item:" .. id)
if C_Item.IsEquippableItem(id) and IsItemEquipped(id) then
button:Highlight()
end
else
button:SetAttribute(buttonType, id)
end
-- Positioning/Size
button:SetParent(frame)
button:SetSize(globalWidth, globalHeight)
button:SetFrameStrata("HIGH")
button:SetFrameLevel(102) -- This needs to be lower than the flyout frame
if MasqueGroup then
MasqueGroup:AddButton(button, { Icon = button.icon })
end
button:Show()
return button
end
--------------------------------------
-- Functions
--------------------------------------
function tpm:GetIconText(spellId)
local text = shortNames[spellId]
if text then
return text
end
print(APPEND .. "No short name found for spellID " .. spellId .. ", please report this on GitHub")
end
function tpm:UpdateAvailableSeasonalTeleports()
availableSeasonalTeleports = {}
local factionTeleports = {
Alliance = { siegeOfBoralus = 445418, motherlode = 467553 },
Horde = { siegeOfBoralus = 464256, motherlode = 467555 }
}
local playerFaction = UnitFactionGroup("player")
local factionData = factionTeleports[playerFaction] or {}
local siegeOfBoralus = factionData.siegeOfBoralus
local motherlode = factionData.motherlode
local seasonalTeleports = {
-- Midnight S1
[1] = {
[161] = 1254557, -- Skyreach
[402] = 393273, -- Algeth'ar Academy
[556] = 1254555, -- Pit of Saron
[557] = 1254400, -- Windrunner Spire
[558] = 1254572, -- Magisters' Terrace
[559] = 1254563, -- Nexus-Point Xenas
[560] = 1254559, -- Maisara Caverns
[583] = 1254551, -- Seat of the Triumvirate
},
-- TWW S2
[2] = {
[247] = motherlode, -- The MOTHERLODE!!
[370] = 373274, -- Operation: Mechagon - Workshop
[382] = 354467, -- Theater of Pain
[499] = 445444, -- Priory of the Sacred Flame
[500] = 445443, -- The Rookery
[504] = 445441, -- Darkflame Cleft
[506] = 445440, -- Cinderbrew Meadery
[525] = 1216786, -- Operation: Floodgate
},
-- TWW S3
[3] = {
[499] = 445444, -- Priory of the Sacred Flame
[542] = 1237215, -- Eco-Dome Al'dani
[378] = 354465, -- Halls of Atonement
[525] = 1216786, -- Operation: Floodgate
[503] = 445417, -- Ara-Kara, City of Echoes
[392] = 367416, -- Tazavesh: So'leah's Gambit
-- [391] = 367416, -- Tazavesh: Streets of Wonder
[505] = 445414, -- The Dawnbreaker
},
}
for _, mapId in ipairs(C_ChallengeMode.GetMapTable()) do
local spellID = seasonalTeleports[tpm.settings.current_season][mapId]
if spellID and IsSpellKnown(spellID) then
table.insert(availableSeasonalTeleports, spellID)
end
end
end
function tpm:checkQuestCompletion(quest)
if type(quest) == "table" then
for _, questID in ipairs(quest) do
if C_QuestLog.IsQuestFlaggedCompleted(questID) then
return true
end
end
else
return C_QuestLog.IsQuestFlaggedCompleted(quest)
end
end
function tpm:CreateFlyout(flyoutData, side)
local ButtonFrame = side == "LEFT" and TeleportMeButtonsFrameLeft or TeleportMeButtonsFrameRight
if db["Teleports:Seasonal:Only"] and (flyoutData.subtype == "path" and not flyoutData.currentExpansion) then
return
end
local _, _, spells, flyoutKnown = GetFlyoutInfo(flyoutData.id)
if not flyoutKnown then
return
end
local yOffset = -globalHeight * ButtonFrame:GetButtonAmount()
local flyOutFrame = createFlyOutFrame(side)
flyOutFrame:SetPoint(side == "LEFT" and "RIGHT" or "LEFT", ButtonFrame, side == "LEFT" and "TOPLEFT" or "TOPRIGHT", side == "LEFT" and globalWidth or 0, yOffset)
-- Flyout Main Button
local button = createFlyOutButton(flyOutFrame, flyoutData, nil, side)
button:SetPoint("LEFT", ButtonFrame, "TOPRIGHT", 0, yOffset)
local childButtons = {}
local flyoutsCreated = 0
local rowNr = 1
local inverse = db["Teleports:Mage:Reverse"] and flyoutData.subtype == "mage"
local start, endLoop, step = 1, spells, 1
if inverse then -- Inverse loop params
start, endLoop, step = spells, 1, -1
end
for i = start, endLoop, step do
local spellId = (GetFlyoutSlotInfo(flyoutData.id, i))
if IsSpellKnown(spellId) then
if flyoutsCreated == db["Flyout:Max_Per_Row"] then
flyoutsCreated = 0
rowNr = rowNr + 1
end
flyoutsCreated = flyoutsCreated + 1
local flyOutButton = CreateSecureButton(flyOutFrame, "spell", shortNames[spellId], spellId)
local offsetY = (rowNr - 1) * - globalHeight
local offsetX = globalWidth * flyoutsCreated
if side == "LEFT" then
offsetX = -globalWidth * flyoutsCreated
end
flyOutButton:SetPoint(side == "LEFT" and "TOPRIGHT" or "TOPLEFT", flyOutFrame, side == "LEFT" and "TOPRIGHT" or "TOPLEFT", offsetX, offsetY)
table.insert(childButtons, flyOutButton)
end
end
local frameWidth = rowNr > 1 and globalWidth * (db["Flyout:Max_Per_Row"] + 1) or globalWidth * (flyoutsCreated + 1)
flyOutFrame:SetSize(frameWidth, globalHeight * rowNr)
button.childButtons = childButtons
return button
end
function tpm:CreateSeasonalTeleportFlyout()
if #availableSeasonalTeleports == 0 then
return
end
local tooltipData = { type = "seasonalteleport" }
local seasonalFlyOutData = { id = -1, name = L["Season " .. tpm.settings.current_season], iconId = 5927657 }
local yOffset = -globalHeight * TeleportMeButtonsFrameRight:GetButtonAmount()
local flyOutFrame = createFlyOutFrame()
flyOutFrame:SetPoint("LEFT", TeleportMeButtonsFrameRight, "TOPRIGHT", 0, yOffset)
local button = createFlyOutButton(flyOutFrame, seasonalFlyOutData, tooltipData, "RIGHT")
button:SetPoint("LEFT", TeleportMeButtonsFrameRight, "TOPRIGHT", 0, yOffset)
local flyoutsCreated = 0
local rowNr = 1
for _, spellId in ipairs(availableSeasonalTeleports) do
if IsSpellKnown(spellId) then
if flyoutsCreated == db["Flyout:Max_Per_Row"] then
flyoutsCreated = 0
rowNr = rowNr + 1
end
flyoutsCreated = flyoutsCreated + 1
local text = tpm:GetIconText(spellId)
local flyOutButton = CreateSecureButton(flyOutFrame, "spell", text, spellId)
flyOutButton:SetPoint("TOPLEFT", flyOutFrame, "TOPLEFT", globalWidth * flyoutsCreated, (rowNr - 1) * - globalHeight)
end
end
local frameWidth = rowNr > 1 and globalWidth * (db["Flyout:Max_Per_Row"] + 1) or globalWidth * (flyoutsCreated + 1)
flyOutFrame:SetSize(frameWidth, globalHeight * rowNr)
return button
end
function tpm:CreateWormholeFlyout(flyoutData)
local usableWormholes = tpm.AvailableWormholes:GetUsable()
if #usableWormholes == 0 then
return
end
local yOffset = -globalHeight * TeleportMeButtonsFrameLeft:GetButtonAmount()
local flyOutFrame = createFlyOutFrame("LEFT")
flyOutFrame:SetPoint("RIGHT", TeleportMeButtonsFrameLeft, "TOPLEFT", globalWidth, yOffset)
local button = createFlyOutButton(flyOutFrame, flyoutData, { type = "profession", id = 202 }, "LEFT")
button:SetPoint("LEFT", TeleportMeButtonsFrameLeft, "TOPRIGHT", 0, yOffset)
local flyoutsCreated = 0
local rowNr = 1
for _, wormholeId in ipairs(usableWormholes) do
if flyoutsCreated == db["Flyout:Max_Per_Row"] then
flyoutsCreated = 0
rowNr = rowNr + 1
end
flyoutsCreated = flyoutsCreated + 1
local flyOutButton = CreateSecureButton(flyOutFrame, "toy", nil, wormholeId)
flyOutButton:SetPoint("TOPRIGHT", flyOutFrame, "TOPRIGHT", -globalWidth * flyoutsCreated, (rowNr - 1) * - globalHeight)
end
local frameWidth = rowNr > 1 and globalWidth * (db["Flyout:Max_Per_Row"] + 1) or globalWidth * (flyoutsCreated + 1)
flyOutFrame:SetSize(frameWidth, globalHeight * rowNr)
return button
end
function tpm:CreateItemTeleportsFlyout(flyoutData)
if #tpm.AvailableItemTeleports == 0 then
return
end
local yOffset = -globalHeight * TeleportMeButtonsFrameLeft:GetButtonAmount()
local flyOutFrame = createFlyOutFrame("LEFT")
flyOutFrame:SetPoint("RIGHT", TeleportMeButtonsFrameLeft, "TOPLEFT", globalWidth, yOffset)
local button = createFlyOutButton(flyOutFrame, flyoutData, { type = "item_teleports" }, "LEFT")
button:SetPoint("LEFT", TeleportMeButtonsFrameLeft, "TOPRIGHT", 0, yOffset)
local flyoutsCreated = 0
local rowNr = 1
for _, itemTeleportId in ipairs(tpm.AvailableItemTeleports) do
if flyoutsCreated == db["Flyout:Max_Per_Row"] then
flyoutsCreated = 0
rowNr = rowNr + 1
end
flyoutsCreated = flyoutsCreated + 1
local isToy = tpm:IsToyTeleport(itemTeleportId)
local flyOutButton = CreateSecureButton(flyOutFrame, isToy and "toy" or "item", nil, itemTeleportId)
flyOutButton:SetPoint("TOPRIGHT", flyOutFrame, "TOPRIGHT", -globalWidth * flyoutsCreated, (rowNr - 1) * - globalHeight)
end
local frameWidth = rowNr > 1 and globalWidth * (db["Flyout:Max_Per_Row"] + 1) or globalWidth * (flyoutsCreated + 1)
flyOutFrame:SetSize(frameWidth, globalHeight * rowNr)
return button
end
function tpm:updateHearthstone()
local hearthstoneButton = TeleportMeButtonsFrameLeft.hearthstoneButton
if not hearthstoneButton then
return
end
if MasqueGroup then
MasqueGroup:RemoveButton(hearthstoneButton)
end
if db["Teleports:Hearthstone"] == "rng" then
local rng = math.random(#tpm.AvailableHearthstones)
hearthstoneButton.icon:SetTexture(1669494) -- misc_rune_pvp_random
hearthstoneButton:SetAttribute("type", "toy")
hearthstoneButton:SetAttribute("toy", tpm.AvailableHearthstones[rng])
elseif db["Teleports:Hearthstone"] == "disabled" then
hearthstoneButton:Hide()
return
elseif db["Teleports:Hearthstone"] ~= "none" then
SetTextureByItemId(hearthstoneButton, db["Teleports:Hearthstone"])
hearthstoneButton:SetAttribute("type", "toy")
hearthstoneButton:SetAttribute("toy", db["Teleports:Hearthstone"])
hearthstoneButton:SetScript("OnEnter", function(s)
setToolTip(s, "toy", db["Teleports:Hearthstone"], true)
end)
else
if C_Item.GetItemCount(6948) == 0 then
print(APPEND .. L["No Hearthtone In Bags"])
hearthstoneButton:Hide()
return
end
SetTextureByItemId(hearthstoneButton, 6948)
hearthstoneButton:SetAttribute("type", "item")
hearthstoneButton:SetAttribute("item", "item:6948")
hearthstoneButton:SetScript("OnEnter", function(s)
setToolTip(s, "item", 6948, true)
end)
end
local zoomFactor = tpm.TEXTURE_SCALE
local offset = zoomFactor / 2
hearthstoneButton.icon:SetTexCoord(offset, 1-offset, offset, 1-offset)
if MasqueGroup then
MasqueGroup:AddButton(hearthstoneButton, { Icon = hearthstoneButton.icon })
end
hearthstoneButton:Show()
end
local function anchorInit(side)
local frameName = side == "LEFT" and "TeleportMeButtonsFrameLeft" or "TeleportMeButtonsFrameRight"
local buttonsFrame = CreateFrame("Frame", frameName, GameMenuFrame)
buttonsFrame.reload = nil
buttonsFrame:SetSize(1, 1)
buttonsFrame.buttonAmount = 0
function buttonsFrame:IncrementButtons()
self.buttonAmount = self.buttonAmount + 1
end
function buttonsFrame:GetButtonAmount()
return self.buttonAmount
end
return buttonsFrame
end
local function createAnchors()
if TeleportMeButtonsFrameRight and not TeleportMeButtonsFrameRight.reload then
if not db["Enabled"] then
TeleportMeButtonsFrameRight:Hide()
TeleportMeButtonsFrameLeft:Hide()
return
end
if TeleportMeButtonsFrameLeft:IsVisible() and db["Teleports:Hearthstone"] and db["Teleports:Hearthstone"] == "rng" then
local rng = tpm:GetRandomHearthstone()
TeleportMeButtonsFrameLeft.hearthstoneButton:SetAttribute("toy", rng)
end
ClearAllInvalidHighlights()
return
end
if not db["Enabled"] then
return
end
local buttonsFrameRight = TeleportMeButtonsFrameRight or anchorInit("RIGHT")
local buttonsFrameLeft = TeleportMeButtonsFrameLeft or anchorInit("LEFT")
buttonsFrameRight.buttonAmount = 0
buttonsFrameLeft.buttonAmount = 0
local buttonFrameYOffset = globalHeight / 2
buttonsFrameLeft:SetPoint("TOPRIGHT", GameMenuFrame, "TOPLEFT", -globalHeight - 1, -buttonFrameYOffset + 1)
buttonsFrameRight:SetPoint("TOPLEFT", GameMenuFrame, "TOPRIGHT", 0, -buttonFrameYOffset + 1)
if C_Housing and C_Housing.HasHousingExpansionAccess() and not tpm.Housing:HasAPlot() and not tpm._housing_reload_scheduled then
tpm._housing_reload_scheduled = true
C_Timer.After(2, function()
tpm._housing_reload_scheduled = false
tpm:ReloadFrames()
end)
end
for _, teleport in ipairs(tpTable) do
local showHearthstone = db["Teleports:Hearthstone"] ~= "disabled"
local texture
local known
local tpType = teleport.type
local tpId = teleport.id
-- Checks and overwrites
if showHearthstone and teleport.hearthstone and db["Teleports:Hearthstone"] ~= "none" then -- Overwrite main HS with user set HS
tpm:DebugPrint("Overwriting main HS with user set HS")
tpType = "toy"
known = true
if db["Teleports:Hearthstone"] == "rng" then
texture = 1669494 -- misc_rune_pvp_random
tpId = tpm:GetRandomHearthstone()
else
tpId = db["Teleports:Hearthstone"]
end
tpm:DebugPrint("Overwrite Info:", known, tpId, tpType, texture)
elseif tpType == "item" and C_Item.GetItemCount(tpId) > 0 then
known = true
elseif
tpType == "toy" and PlayerHasToy(tpId --[[@as integer]])
then
if teleport.quest then
known = tpm:checkQuestCompletion(teleport.quest)
else
known = true
end
elseif
tpType == "spell" and IsSpellKnown(tpId --[[@as integer]])
then
known = true
end
if showHearthstone and not known and teleport.hearthstone then -- Player has no HS in bags and not set a custom TP.
print(APPEND .. L["No Hearthtone In Bags"])
end
-- Create Stuff
if known and (tpType == "toy" or tpType == "item" or tpType == "spell" or (showHearthstone and teleport.hearthstone)) then
tpm:DebugPrint(teleport.hearthstone)
local button = CreateSecureButton(buttonsFrameLeft, tpType, nil, tpId --[[@as integer]], teleport.hearthstone)
local yOffset = -globalHeight * buttonsFrameLeft:GetButtonAmount()
button:SetPoint("LEFT", buttonsFrameLeft, "TOPRIGHT", 0, yOffset)