Repository navigation
Expand file tree
/
Copy pathTeleportMenu.lua
More file actions
677 lines (609 loc) · 22.5 KB
/
Copy pathTeleportMenu.lua
File metadata and controls
677 lines (609 loc) · 22.5 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
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 globalWidth, globalHeight = 40, 40 -- defaults
tpm.TEXTURE_SCALE = 0
function tpm:GetButtonSize()
return globalWidth, globalHeight
end
local IsSpellKnown = C_SpellBook.IsSpellKnown
local issecretvalue = issecretvalue or function() return false end
function tpm:IsSecret(value)
return issecretvalue(value)
end
--------------------------------------
-- Teleport Tables
--------------------------------------
tpm.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!!"],
[1286828] = L["Temple of Sethraliss"], -- Midnight S2
[1286831] = L["Kings' Rest"], -- Midnight S2
-- 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
[1286801] = L["The Blinding Vale"], -- Midnight S2
[1286804] = L["Voidscar Arena"], -- Midnight S2
[1286807] = L["Den of Nalorakk"], -- Midnight S2
[1286809] = L["Murder Row"], -- Midnight S2
[1286812] = L["Altar of Fangs"], -- Midnight S2
-- 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)
{ id = 1238686, type = "spell" }, -- Rootwalking (Haranir)
-- 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", currentExpansion = true }, -- Hero's Path: Midnight Raids
}
--------------------------------------
-- Functions
--------------------------------------
function tpm:GetShortName(spellId)
return shortNames[spellId]
end
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()
local 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] = 159898, -- Skyreach XXX 1254557 seems incorrect
[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
[239] = 1254551, -- Seat of the Triumvirate
},
-- Midnight S2
[2] = {
[249] = 1286831, -- King's Rest
[250] = 1286828, -- Temple of Sethraliss
[399] = 393256, -- Ruby Life Pools
[584] = 1286801, -- The Blinding Vale
[585] = 1286804, -- Voidscar Arena
[586] = 1286807, -- Den of Nalorakk
[587] = 1286809, -- Murder Row
[588] = 1286812, -- Altar of Fangs
},
}
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
tpm.AvailableSeasonalTeleports = availableSeasonalTeleports
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:SetRandomHearthstoneOnButton(button)
local randomHearthstone = tpm:GetRandomHearthstone()
button.id = randomHearthstone
button:SetAttribute("toy", randomHearthstone)
button:CheckCooldown()
end
function tpm:updateHearthstone()
local hearthstoneButton = TeleportMeButtonsFrameLeft.hearthstoneButton
if MasqueGroup then
MasqueGroup:RemoveButton(hearthstoneButton)
end
if not hearthstoneButton then
return
end
if db["Teleports:Hearthstone"] == "rng" then
hearthstoneButton.pendingIconItem = nil -- Drop any pending toy icon load so it can't overwrite the random icon
hearthstoneButton.icon:SetTexture(1669494) -- misc_rune_pvp_random
hearthstoneButton:SetAttribute("type", "toy")
tpm:SetRandomHearthstoneOnButton(hearthstoneButton)
elseif db["Teleports:Hearthstone"] == "disabled" then
hearthstoneButton:Hide()
return
elseif db["Teleports:Hearthstone"] ~= "none" then
tpm.SecureButton:SetTextureByItemId(hearthstoneButton, db["Teleports:Hearthstone"])
hearthstoneButton:SetAttribute("type", "toy")
hearthstoneButton:SetAttribute("toy", db["Teleports:Hearthstone"])
hearthstoneButton:SetScript("OnEnter", function(s)
tpm.Tooltip:Set(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
tpm.SecureButton:SetTextureByItemId(hearthstoneButton, 6948)
hearthstoneButton:SetAttribute("type", "item")
hearthstoneButton:SetAttribute("item", "item:6948")
hearthstoneButton:SetScript("OnEnter", function(s)
tpm.Tooltip:Set(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, Cooldown = hearthstoneButton.cooldownFrame, Highlight = hearthstoneButton:GetHighlightTexture() })
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"] == "rng" and TeleportMeButtonsFrameLeft.hearthstoneButton then
tpm:SetRandomHearthstoneOnButton(TeleportMeButtonsFrameLeft.hearthstoneButton)
end
tpm.SecureButton:UpdateEquippedHighlights()
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)
buttonsFrameLeft.hearthstoneButton = nil -- The previous one was recycled; set again below if created
for _, teleport in ipairs(tpTable) do
local showHearthstone = db["Teleports:Hearthstone"] ~= "disabled"
local texture
local known
-- 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")
teleport.type = "toy"
known = true
if db["Teleports:Hearthstone"] == "rng" then
texture = 1669494 -- misc_rune_pvp_random
teleport.id = tpm:GetRandomHearthstone()
-- Toy data can briefly be unavailable (e.g. during a loading screen), leaving nothing to
-- pick from. Skip the button then; it's rebuilt on the next TOYS_UPDATED.
known = teleport.id ~= nil
else
teleport.id = db["Teleports:Hearthstone"]
end
tpm:DebugPrint("Overwrite Info:", known, teleport.id, teleport.type, texture)
elseif teleport.type == "item" and C_Item.GetItemCount(teleport.id) > 0 then
known = true
elseif
teleport.type == "toy" and PlayerHasToy(teleport.id --[[@as integer]])
then
if teleport.quest then
known = tpm:checkQuestCompletion(teleport.quest)
else
known = true
end
elseif
teleport.type == "spell" and IsSpellKnown(teleport.id --[[@as integer]])
then
known = true
end
if showHearthstone and not known and teleport.hearthstone and db["Teleports:Hearthstone"] == "none" 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 (teleport.type == "toy" or teleport.type == "item" or teleport.type == "spell" or (showHearthstone and teleport.hearthstone)) then
tpm:DebugPrint(teleport.hearthstone)
local button = tpm.SecureButton:Create(buttonsFrameLeft, teleport.type, nil, teleport.id --[[@as integer]], teleport.hearthstone)
local yOffset = -globalHeight * buttonsFrameLeft:GetButtonAmount()
button:SetPoint("LEFT", buttonsFrameLeft, "TOPRIGHT", 0, yOffset)
if teleport.hearthstone then -- store to replace item later
buttonsFrameLeft.hearthstoneButton = button
end
buttonsFrameLeft:IncrementButtons()
elseif teleport.type == "housing" and C_Housing and C_Housing.HasHousingExpansionAccess() then
local playerFaction = UnitFactionGroup("player")
if tpm.Housing:HasAPlot() and tpm.Housing:GetActiveHousingButtons() == 0 and (#houseData == 1 or playerFaction == teleport.faction) then -- only 1 house for now, fix more
local button = tpm.Housing:CreateSecureHousingButton(teleport.faction)
button:SetParent(buttonsFrameLeft)
local yOffset = -globalHeight * buttonsFrameLeft:GetButtonAmount()
button:SetPoint("LEFT", buttonsFrameLeft, "TOPRIGHT", 0, yOffset)
buttonsFrameLeft:IncrementButtons()
end
elseif teleport.type == "wormholes" then
local created = tpm.Flyout:CreateWormholes(teleport)
if created then
buttonsFrameLeft:IncrementButtons()
end
elseif teleport.type == "item_teleports" then
local created = tpm.Flyout:CreateItemTeleports(teleport)
if created then
buttonsFrameLeft:IncrementButtons()
end
elseif teleport.type == "flyout" then
local created = tpm.Flyout:Create(teleport, teleport.subtype == "mage" and "LEFT")
if created then
local frameAdded = teleport.subtype == "mage" and buttonsFrameLeft or buttonsFrameRight
frameAdded:IncrementButtons()
end
end
end
local function CreateCurrentSeasonTeleports()
local created = tpm.Flyout:CreateSeasonal()
if created then
buttonsFrameRight:IncrementButtons()
end
end
CreateCurrentSeasonTeleports()
tpm:updateHearthstone() -- XXX Temp as this fixes the rng icon if it's selected
end
function tpm:ReloadFrames()
if not GameMenuFrame:IsShown() then
return
end
if InCombatLockdown() then
return
end
if db["Button:Size"] then
globalWidth = db["Button:Size"]
globalHeight = db["Button:Size"]
end
tpm.TEXTURE_SCALE = db["Button:Texture:Zoom"] or 0
-- Rebuilding closes all flyouts. Remember the open one, e.g. when equipping an item from
-- a flyout triggers a bag update and with it a rebuild.
local openFlyoutKey = tpm.Flyout:GetOpenFlyoutKey()
tpm.Flyout:RecycleAll()
tpm.SecureButton:RecycleAll()
tpm.Housing:RecycleHousingButtons()
if TeleportMeButtonsFrameRight then
TeleportMeButtonsFrameRight.reload = true
end
-- Why can't we clear these? causes bugs when re-sizing.
-- secureButtons = {}
-- housingButtons = {}
createAnchors()
tpm.Flyout:ReopenFlyout(openFlyoutKey)
end
function tpm:CloseMainMenu()
local db = tpm:GetOptions()
if db["General:AutoClose"] and GameMenuFrame:IsShown() then
HideUIPanel(GameMenuFrame)
end
end
-- Slash Commands
SLASH_TPMENU1 = "/tpm"
SLASH_TPMENU2 = "/tpmenu"
SlashCmdList["TPMENU"] = function(msg)
local args = { (" "):split(msg:lower()) }
msg = args[1]
if msg == "" then
Settings.OpenToCategory(tpm:GetOptionsCategory())
elseif msg == "filters" then
Settings.OpenToCategory(tpm:GetOptionsCategory(msg))
elseif msg == "housing" then
tpm.Housing:DumpHouseData()
else
print(APPEND .. " unknown command: " .. msg)
end
end
--------------------------------------
-- Loading
--------------------------------------
local function checkItemsLoaded(self)
if self.continuableContainer then
self.continuableContainer:Cancel()
end
self.continuableContainer = ContinuableContainer:Create()
local function LoadItems(itemTable)
for id, _ in ipairs(itemTable) do
self.continuableContainer:AddContinuable(Item:CreateFromItemID(id))
end
end
LoadItems(tpm.Wormholes)
LoadItems(tpm.Hearthstones)
LoadItems(tpm.ItemTeleports)
local allLoaded = true
local function OnItemsLoaded()
if allLoaded then
tpm:Setup()
tpm:LoadOptions()
self:UnregisterEvent("ADDON_LOADED")
else
checkItemsLoaded(self)
end
end
allLoaded = self.continuableContainer:ContinueOnLoad(OnItemsLoaded)
end
-- Recomputes which toy/item-gated teleports are currently available and
-- redraws frames. Called on login and whenever toy/bag data that these
-- checks depend on changes, since PlayerHasToy/GetItemCount can still be
-- stale right after PLAYER_LOGIN.
function tpm:RefreshAvailableTeleports()
tpm:UpdateAvailableHearthstones()
tpm:UpdateAvailableWormholes()
tpm:UpdateAvailableItemTeleports()
if tpm.RefreshHearthstoneOptions then -- Set once the options are loaded
tpm:RefreshHearthstoneOptions()
end
tpm:ReloadFrames()
end
function tpm:Setup()
if db["Button:Size"] then
globalWidth = db["Button:Size"]
globalHeight = db["Button:Size"]
end
tpm:RefreshAvailableTeleports()
tpm:UpdateAvailableSeasonalTeleports()
tpm:LoadHouses()
if
db["Teleports:Hearthstone"]
and db["Teleports:Hearthstone"] ~= "rng"
and db["Teleports:Hearthstone"] ~= "none"
and db["Teleports:Hearthstone"] ~= "disabled"
and not PlayerHasToy(db["Teleports:Hearthstone"] --[[@as integer]])
then
print(APPEND .. L["Hearthone Reset Error"]:format(db["Teleports:Hearthstone"]))
db["Teleports:Hearthstone"] = "none"
tpm:updateHearthstone()
end
hooksecurefunc("ToggleGameMenu", tpm.ReloadFrames)
end
-- Event Handlers
local events = {}
local f = CreateFrame("Frame")
f:RegisterEvent("ADDON_LOADED")
f:RegisterEvent("PLAYER_LOGIN")
f:RegisterEvent("BAG_UPDATE_DELAYED")
f:RegisterEvent("TOYS_UPDATED")
f:SetScript("OnEvent", function(self, event, ...)
events[event](self, ...)
end)
function events:ADDON_LOADED(...)
local addOnName = ...
if addOnName == "TeleportMenu" then
db = tpm:GetOptions()
tpm.settings.current_season = 2
db.debug = false
f:UnregisterEvent("ADDON_LOADED")
end
end
function events:PLAYER_LOGIN()
checkItemsLoaded(f)
f:UnregisterEvent("PLAYER_LOGIN")
end
function events:TOYS_UPDATED()
tpm:SyncItemPossession()
tpm:RefreshAvailableTeleports()
end
function events:BAG_UPDATE_DELAYED()
tpm:SyncItemPossession()
tpm:RefreshAvailableTeleports()
end
-- Debug Functions
function tpm:DebugPrint(...)
if not db.debug then
return
end
print(APPEND, ...)
end