forked from davidmeen/TomeOfTeleportation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTomeOfTeleportation.lua
2376 lines (2027 loc) · 65.2 KB
/
TomeOfTeleportation.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
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
-- Tome of Teleportation by Remeen.
-- TODO:
-- Improve speed
-- Optional compact UI
-- Tests for search
-- Known issues:
-- Overlapping buttons
local AddonName = "TomeOfTeleportation"
local AddonTitle = "Tome of Teleportation"
-- Special case strings start with number to force them to be sorted first.
TeleporterHearthString = "0 Hearth"
TeleporterRecallString = "1 Astral Recall"
TeleporterFlightString = "2 Flight Master"
local DungeonsTitle = "Dungeons"
local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
local icon = LibStub("LibDBIcon-1.0")
local dataobj = ldb:NewDataObject("TomeTeleGlobal", {
label = "TomeOfTeleportation",
type = "data source",
icon = "Interface\\Icons\\Spell_Arcane_TeleportDalaran",
text = "Teleport"
})
local TeleporterParentFrame = nil
local CastSpell = nil
local ItemSlot = nil
local OldItems = {}
local RemoveItem = {}
local ButtonSettings = {}
local OrderedButtonSettings = {}
local IsVisible = false
local NeedUpdate = false
local OpenTime = 0
local ShouldNotBeEquiped = {}
local ShouldBeEquiped = {}
local EquipTime = 0
local CustomizeSpells = false
local RemoveIconOffset = 0
local ShowIconOffset = 0
local SortUpIconOffset = 0
local SortDownIconOffset = 0
local AddItemButton = nil
local AddSpellButton = nil
local DebugUnsupported = nil
local ChosenHearth = nil
local IsRefreshing = nil
TomeOfTele_ShareOptions = true
BINDING_NAME_TOMEOFTELEPORTATION = "Tome of Teleportation"
local InvTypeToSlot =
{
["INVTYPE_HEAD"] = 1,
["INVTYPE_NECK"] = 2,
["INVTYPE_SHOULDER"] = 3,
["INVTYPE_BODY"] = 4,
["INVTYPE_CHEST"] = 5,
["INVTYPE_ROBE"] = 5,
["INVTYPE_WAIST"] = 6,
["INVTYPE_LEGS"] = 7,
["INVTYPE_FEET"] = 8,
["INVTYPE_WRIST"] = 9,
["INVTYPE_HAND"] = 10,
["INVTYPE_FINGER"] = 11,
["INVTYPE_TRINKET"] = 13,
["INVTYPE_CLOAK"] = 15,
["INVTYPE_2HWEAPON"] = 16,
["INVTYPE_WEAPONMAINHAND"] = 16,
["INVTYPE_TABARD"] = 19
}
local SortByDestination = 1
local SortByType = 2
local SortCustom = 3
local TitleFrameBG
local DefaultOptions =
{
["theme"] = "Default",
["scale"] = 1,
["buttonHeight"] = 26,
["buttonWidth"] = 128,
["labelHeight"] = 16,
["maximumHeight"] = 200,
["heightScalePercent"] = 100,
["fontHeight"] = 10,
["buttonInset"] = 6,
["showHelp"] = false,
["background"] = "Interface/AchievementFrame/UI-Achievement-Parchment-Horizontal",
["edge"] = "Interface/DialogFrame/UI-DialogBox-Border",
["backgroundR"] = 1,
["backgroundG"] = 1,
["backgroundB"] = 1,
["backgroundA"] = 0.5,
["frameEdgeSize"] = 16,
["showTitle"] = true,
["titleBackground"] = "Interface/DialogFrame/UI-DialogBox-Header",
["titleFont"] = "GameFontNormalSmall",
["titleWidth"] = 280,
["titleHeight"] = 50,
["titleOffset"] = 12,
["buttonFont"] = GameFontNormal:GetFont(),
["buttonBackground"] = "Interface/Tooltips/UI-Tooltip-Background",
["buttonEdge"] = "Interface/Tooltips/UI-Tooltip-Border",
["buttonEdgeSize"] = 16,
["buttonTileSize"] = 16,
["readyColourR"] = 0,
["readyColourG"] = 0.7,
["readyColourB"] = 0,
["unequipedColourR"] = 1,
["unequipedColourG"] = 0,
["unequipedColourB"] = 0,
["cooldownColourR"] = 1,
["cooldownColourG"] = 0.7,
["cooldownColourB"] = 0,
["cooldownBarInset"] = 4,
["disabledColourR"] = 0.5,
["disabledColourG"] = 0.5,
["disabledColourB"] = 0.5,
["QuickMenuSize"] = 50,
["sortUpIcon"] = "Interface/Icons/misc_arrowlup",
["sortDownIcon"] = "Interface/Icons/misc_arrowdown",
["showButtonIcon"] = "Interface/Icons/levelupicon-lfd",
["removeButtonIcon"] = "Interface/Icons/INV_Misc_Bone_Skull_03",
["conciseDungeonSpells"] = 1,
["showSearch"] = 1,
["searchHidden"] = 1,
}
-- Themes. For now there aren't many of these. Message me on curseforge.com
-- if you create a theme that you'd like to be included. Also let me know
-- if you need to change a parameter that isn't exposed.
-- Note that every value is enclosed in {}.
local DefaultTheme =
{
}
local FlatTheme =
{
["background"] = {"Interface/DialogFrame/UI-DialogBox-Gold-Background"},
["edge"] = {""},
["buttonEdge"] = {""},
["titleBackground"] = {"Interface/DialogFrame/UI-DialogBox-Gold-Background"},
["backgroundA"] = {1},
["showTitle"] = {false},
["titleHeight"] = {20},
["titleWidth"] = {150},
["titleOffset"] = {5},
}
local WideTheme =
{
["buttonWidth"] = {225},
["maximumHeight"] = {320}
}
local Themes =
{
["Default"] = DefaultTheme,
["Flat"] = FlatTheme,
["Wide Buttons"] = WideTheme
}
---------------------------------------------------------------
local ItemsFound = {}
local EmulateSlowServer = false
-- Emulating slow server.
local function GetCachedItemInfo(itemId)
if EmulateSlowServer then
if ItemsFound[itemId] == nil then
ItemsFound[itemId] = true
return nil
else
return GetItemInfo(itemId)
end
else
return GetItemInfo(itemId)
end
end
-- [Orignal spell ID] = { Alt spell ID, Buff }
-- Currently unused
local SpellBuffs =
{
--[126892] = { 126896, 126896 } -- Zen Pilgrimage / Zen Pilgrimage: Return
}
local TeleporterSpells = {}
local function GetTheme()
if TomeOfTele_ShareOptions then
if TomeOfTele_OptionsGlobal == nil or TomeOfTele_OptionsGlobal["theme"] == nil then
return DefaultOptions["theme"]
else
return TomeOfTele_OptionsGlobal["theme"]
end
else
if TomeOfTele_Options == nil or TomeOfTele_Options["theme"] == nil then
return DefaultOptions["theme"]
else
return TomeOfTele_Options["theme"]
end
end
end
local function GetOption(option)
local value = nil
if TomeOfTele_ShareOptions then
if TomeOfTele_OptionsGlobal then
value = TomeOfTele_OptionsGlobal[option]
end
else
if TomeOfTele_Options then
value = TomeOfTele_Options[option]
end
end
if value == nil then
local theme = Themes[GetTheme()]
if theme and theme[option] then
return theme[option][1]
else
return DefaultOptions[option]
end
else
return value
end
end
function TeleporterGetOption(option)
return GetOption(option)
end
function TeleporterIsOptionModified(option)
local value = nil
if TomeOfTele_ShareOptions then
if TomeOfTele_OptionsGlobal then
value = TomeOfTele_OptionsGlobal[option]
end
else
if TomeOfTele_Options then
value = TomeOfTele_Options[option]
end
end
if value ~= nil then
return true
else
return false
end
end
local function GetScale()
return GetOption("scale") * UIParent:GetEffectiveScale()
end
local function GetScaledOption(option)
return GetOption(option) * GetScale()
end
local function SetOption(option, value)
if TomeOfTele_Options == nil then
TomeOfTele_Options = {}
end
if TomeOfTele_ShareOptions then
TomeOfTele_OptionsGlobal[option] = value
else
TomeOfTele_Options[option] = value
end
end
function TeleporterSetOption(option, value)
local oldValue = GetOption(option)
local isSame = value == oldValue
if type(value) == "number" and type(oldValue) == "number" then
isSame = math.abs(value - oldValue) < 0.0001
end
if not isSame then
SetOption(option, value)
end
end
function Teleporter_OnEvent(self, event, ...)
if event == "ADDON_LOADED" then
local loadedAddon = ...
if string.upper(loadedAddon) == string.upper(AddonName) then
Teleporter_OnAddonLoaded()
end
elseif event == "UNIT_SPELLCAST_SUCCEEDED" then
local player, guid, spell = ...
if player == "player" then
if C_Spell and C_Spell.GetSpellInfo then
if C_Spell.GetSpellInfo(spell).name == CastSpell then
TeleporterClose()
end
else
if GetSpellInfo(spell) == CastSpell then
TeleporterClose()
end
end
end
elseif event == "UNIT_INVENTORY_CHANGED" then
if IsVisible then
TeleporterUpdateAllButtons()
end
elseif event == "PLAYER_REGEN_DISABLED" then
-- Can't close while in combat due to secure buttons, so disable Esc key
if TeleporterParentFrame then
local frameIndex = TeleporterFindInSpecialFrames()
if frameIndex then
tremove(UISpecialFrames,frameIndex);
end
end
elseif event == "PLAYER_REGEN_ENABLED" then
if TeleporterParentFrame then
if not TeleporterFindInSpecialFrames() then
tinsert(UISpecialFrames,TeleporterParentFrame:GetName());
end
end
elseif event == "ZONE_CHANGED" or event == "ZONE_CHANGED_NEW_AREA" or event == "ZONE_CHANGED_INDOORS" then
TeleporterCheckItemsWereEquiped()
end
end
function TeleporterFindInSpecialFrames()
for i,f in ipairs(UISpecialFrames) do
if f == TeleporterParentFrame:GetName() then
return i
end
end
return nil
end
local function RebuildSpellList()
TeleporterSpells = {}
for i,spell in ipairs(TeleporterDefaultSpells) do
tinsert(TeleporterSpells, spell)
end
local extraSpells = GetOption("extraSpells")
if extraSpells then
for id,dest in pairs(extraSpells) do
local spell = TeleporterCreateSpell(id,dest)
spell.isCustom = true
tinsert(TeleporterSpells, spell)
end
end
local extraItems = GetOption("extraItems")
if extraItems then
for id,dest in pairs(extraItems) do
local spell = TeleporterCreateItem(id,dest)
spell.isCustom = true
tinsert(TeleporterSpells, spell)
end
end
local extraSpellsAndItems = GetOption("extraSpellsAndItems")
if extraSpellsAndItems then
for index = #extraSpellsAndItems,1,-1 do
local spell = extraSpellsAndItems[index]
local isDuplicate = false
for id2, spell2 in ipairs(TeleporterSpells) do
if spell2:Equals(spell) then
isDuplicate = true
table.remove(extraSpellsAndItems, index)
end
end
if not isDuplicate then
TeleporterInitSpell(spell)
tinsert(TeleporterSpells, spell)
end
end
end
end
function TeleporterRebuildSpellList()
RebuildSpellList()
end
function Teleporter_OnLoad()
SlashCmdList["TELEPORTER"] = TeleporterSlashCmdFunction
SLASH_TELEPORTER1 = "/tomeofteleport"
SLASH_TELEPORTER2 = "/tele"
SlashCmdList["TELEPORTEREQUIP"] = TeleporterEquipSlashCmdFunction
SLASH_TELEPORTEREQUIP1 = "/teleporterequip"
SlashCmdList["TELEPORTERUSEITEM"] = TeleporterUseItemSlashCmdFunction
SLASH_TELEPORTERUSEITEM1 = "/teleporteruseitem"
SlashCmdList["TELEPORTERCASTSPELL"] = TeleporterCastSpellSlashCmdFunction
SLASH_TELEPORTERCASTSPELL1 = "/teleportercastspell"
SlashCmdList["TELEPORTERCREATEMACRO"] = TeleporterCreateMacroSlashCmdFunction
SLASH_TELEPORTERCREATEMACRO1 = "/teleportercreatemacro"
if TeleporterSettings_OnLoad then
TeleporterSettings_OnLoad()
end
end
local function SavePosition()
local points = {}
for i = 1,TeleporterParentFrame:GetNumPoints(),1 do
tinsert(points,{TeleporterParentFrame:GetPoint(i)})
end
SetOption("points", points)
end
local function Refresh()
if IsVisible then
IsRefreshing = true
TeleporterClose()
TeleporterOpenFrame()
IsRefreshing = false
end
end
local TeleporterMenu = nil
local TeleporterOptionsMenu = nil
local function OnHideOption(info, option)
local hide = not GetOption(option)
info.checked = hide
SetOption(option, hide)
Refresh()
end
local function TomeOfTele_SetSort(value)
SetOption("sort", value)
Refresh()
end
local function TomeOfTele_SetScale(scale)
SetOption("scale", scale)
Refresh()
end
local function TomeOfTele_SetHeightScale(scale)
SetOption("heightScalePercent", scale)
Refresh()
end
local function TomeOfTele_SetTheme(scale)
SetOption("theme", scale)
Refresh()
end
local function AddHideOptionMenu(index, text, option, owner, level)
local info = UIDropDownMenu_CreateInfo()
info.text = text
info.value = index
info.func = function(info) OnHideOption(info, option) end
info.owner = owner
info.checked = GetOption(option)
UIDropDownMenu_AddButton(info, level)
end
local MenuIDHideItems = 1
local MenuIDHideChallenge = 2
local MenuIDHideSpells = 3
local MenuIDHideConsumables = 4
local MenuIDSort = 5
local MenuIDScale = 6
local MenuIDTheme = 7
local MenuIDSharedSettings = 8
local MenuIDCustomize = 9
local MenuIDHeight = 10
local MenuIDDungeonNames = 11
local MenuIDWrongZone = 12
local MenuIDCurrentDungeons = 13
local MenuIDGroupDungeons = 14
local MenuIDRandomHearth = 15
local MenuIDCloseAfterCast = 16
local function InitTeleporterOptionsMenu(frame, level, menuList, topLevel)
if level == 1 or topLevel then
local info = UIDropDownMenu_CreateInfo()
info.owner = frame
AddHideOptionMenu(MenuIDHideItems, "Hide Items", "hideItems", frame, level)
AddHideOptionMenu(MenuIDHideChallenge, "Hide Dungeon Spells", "hideChallenge", frame, level)
AddHideOptionMenu(MenuIDHideSpells, "Hide Spells", "hideSpells", frame, level)
AddHideOptionMenu(MenuIDHideConsumables, "Hide Consumables", "hideConsumable", frame, level)
AddHideOptionMenu(MenuIDDungeonNames, "Show Dungeon Names", "showDungeonNames", frame, level)
AddHideOptionMenu(MenuIDCurrentDungeons, "Current Dungeons Only", "seasonOnly", frame, level)
AddHideOptionMenu(MenuIDGroupDungeons, "Group Dungeons", "groupDungeons", frame, level)
AddHideOptionMenu(MenuIDRandomHearth, "Random Hearthstone", "randomHearth", frame, level)
AddHideOptionMenu(MenuIDWrongZone, "Show Spells When In Wrong Zone", "showInWrongZone", frame, level)
AddHideOptionMenu(MenuIDCloseAfterCast, "Close When Cast Finishes", "closeAfterCast", frame, level)
info.text = "Sort"
info.hasArrow = true
info.menuList = "Sort"
info.value = MenuIDSort
info.func = nil
info.checked = nil
UIDropDownMenu_AddButton(info, level)
info.text = "Scale"
info.hasArrow = true
info.menuList = "Scale"
info.value = MenuIDScale
info.checked = nil
UIDropDownMenu_AddButton(info, level)
info.text = "Height"
info.hasArrow = true
info.menuList = "Height"
info.value = MenuIDHeight
info.checked = nil
UIDropDownMenu_AddButton(info, level)
info.text = "Theme"
info.hasArrow = true
info.menuList = "Theme"
info.value = MenuIDTheme
info.checked = nil
UIDropDownMenu_AddButton(info, level)
info.text = "Use Shared Settings"
info.value = MenuIDSharedSettings
info.hasArrow = false
info.menuList = nil
info.func = function(info) TomeOfTele_ShareOptions = not TomeOfTele_ShareOptions; Refresh(); end
info.owner = frame
info.checked = TomeOfTele_ShareOptions
UIDropDownMenu_AddButton(info, level)
-- I'd like to split this up, but the Wow API doesn't let you select sub categories.
info.text = "Customize Spells and More Settings"
info.value = MenuIDCustomize
info.hasArrow = false
info.menuList = nil
info.func = function(info)
if GetOption("oldCustomizer") then
CustomizeSpells = not CustomizeSpells; Refresh();
else
TeleporterClose()
TeleporterOpenSettings()
end
end
info.owner = frame
info.checked = CustomizeSpells
UIDropDownMenu_AddButton(info, level)
elseif menuList == "Scale" then
local scales = { 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200 }
for i,s in ipairs(scales) do
local info = UIDropDownMenu_CreateInfo()
info.text = s .. "%"
info.value = s / 10 + 20 -- 26 to 40
info.func = function(info) TomeOfTele_SetScale(s / 100) end
info.owner = frame
info.checked = function(info) return GetOption("scale") == s / 100 end
UIDropDownMenu_AddButton(info, level)
end
elseif menuList == "Height" then
local scales = { 100, 150, 200, 250, 300 }
for i,s in ipairs(scales) do
local info = UIDropDownMenu_CreateInfo()
info.text = s .. "%"
info.value = s / 50 + 50 -- 52 to 56
info.func = function(info) TomeOfTele_SetHeightScale(s) end
info.owner = frame
info.checked = function(info) return GetOption("heightScalePercent") == s end
UIDropDownMenu_AddButton(info, level)
end
elseif menuList == "Theme" then
local index = 40
for themeName, theme in pairs(Themes) do
local info = UIDropDownMenu_CreateInfo()
info.text = themeName
info.value = index
info.func = function(info) TomeOfTele_SetTheme(themeName) end
info.owner = frame
info.checked = function(info) return GetOption("theme") == themeName end
UIDropDownMenu_AddButton(info, level)
index = index + 1
end
elseif menuList== "Sort" then
local info = UIDropDownMenu_CreateInfo()
info.text = "Destination"
info.value = 1
info.func = function(info) TomeOfTele_SetSort(1) end
info.owner = frame
info.checked = function(info) sortMode = GetOption("sort"); return sortMode == nil or sortMode == 1; end
UIDropDownMenu_AddButton(info, level)
info.text = "Type"
info.value = 2
info.func = function(info) TomeOfTele_SetSort(2) end
info.owner = frame
info.checked = function(info) return GetOption("sort") == 2; end
UIDropDownMenu_AddButton(info, level)
info.text = "Custom"
info.value = 3
info.func = function(info) TomeOfTele_SetSort(3) end
info.owner = frame
info.checked = function(info) return GetOption("sort") == 3; end
UIDropDownMenu_AddButton(info, level)
end
end
local function InitTeleporterMenu(frame, level, menuList)
if level == 1 then
local info = UIDropDownMenu_CreateInfo()
info.owner = frame
info.text = "Right click a spell to add favourites"
info.hasArrow = false
info.menuList = nil
info.value = 0
info.checked = nil
UIDropDownMenu_AddButton(info, level)
info.owner = frame
info.text = "Options"
info.hasArrow = true
info.menuList = "Options"
info.value = 0
info.checked = nil
UIDropDownMenu_AddButton(info, level)
elseif level == 2 then
InitTeleporterOptionsMenu(frame, level, menuList, true)
else
InitTeleporterOptionsMenu(frame, level, menuList, false)
end
end
local function ShowOptionsMenu()
if not TeleporterOptionsMenu then
TeleporterOptionsMenu = CreateFrame("Frame", "TomeOfTeleOptionsMenu", UIParent, "UIDropDownMenuTemplate")
UIDropDownMenu_Initialize(TeleporterOptionsMenu, InitTeleporterOptionsMenu, "MENU")
end
ToggleDropDownMenu(1, nil, TeleporterOptionsMenu, "cursor", 3, -3)
end
local function SortSpells(spell1, spell2, sortType)
local spellId1 = spell1.spellId
local spellId2 = spell2.spellId
local spellName1 = spell1.spellName
local spellName2 = spell2.spellName
local spellType1 = spell1.spellType
local spellType2 = spell2.spellType
local zone1 = spell1:GetZone()
local zone2 = spell2:GetZone()
if GetOption("groupDungeons") then
if spell1:IsDungeonSpell() then zone1 = DungeonsTitle end
if spell2:IsDungeonSpell() then zone2 = DungeonsTitle end
end
local so = GetOption("sortOrder") or {}
if sortType == SortCustom then
local optId1 = spell1:GetOptionId()
local optId2 = spell2:GetOptionId()
-- New spells always sort last - not ideal, but makes it easier to have a deterministic sort.
if so[optId1] and so[optId2] then
return so[optId1] < so[optId2]
elseif so[optId1] then
return true
elseif so[optId2] then
return false
end
elseif sortType == SortByType then
if spellType1 ~= spellType2 then
return spellType1 < spellType2
end
end
if zone1 ~= zone2 then
return zone1 < zone2
end
return spellName1 < spellName2
end
function TeleporterGetSearchString()
if GetOption("showSearch") then
local searchString = TeleporterSearchBox:GetText()
if searchString == "" then
return nil
else
return searchString
end
else
return nil
end
end
local function SetupSpells()
local loaded = true
for index, spell in ipairs(TeleporterSpells) do
if spell:IsItem() then
spell.spellName = GetCachedItemInfo( spell.spellId )
else
if C_Spell and C_Spell.GetSpellInfo then
spell.spellName = C_Spell.GetSpellInfo( spell.spellId).name
else
spell.spellName = GetSpellInfo( spell.spellId)
end
end
if not spell.spellName then
if DebugUnsupported then
print(spell.spellType .. " " .. spell.spellId)
end
spell.spellName = "<Loading>"
if spell:CanUse() then
loaded = false
end
end
spell.isItem = spell:IsItem()
end
return loaded
end
local function GetSortedFavourites(favourites)
SetupSpells()
local sorted = {}
local index = 1
for spellId, isItem in pairs(favourites) do
for i,spell in ipairs(TeleporterSpells) do
if spell.spellId == spellId then
sorted[index] = spell
index = index + 1
break
end
end
end
local sortType = GetOption("sort")
table.sort(sorted, function(a,b) return SortSpells(a, b, sortType) end)
return sorted
end
local function ShowMenu()
local favourites = GetOption("favourites")
local next = next
if favourites and next(favourites) ~= nil and not UnitAffectingCombat("player") then
TeleToggleQuickMenu(GetSortedFavourites(favourites), GetScaledOption("QuickMenuSize"))
else
TeleporterMenu = CreateFrame("Frame", "TomeOfTeleMenu", UIParent, "UIDropDownMenuTemplate")
UIDropDownMenu_Initialize(TeleporterMenu, InitTeleporterMenu, "MENU")
ToggleDropDownMenu(1, nil, TeleporterMenu, "cursor", 3, -3)
end
end
function TeleporterItemMustBeEquipped(item)
if IsEquippableItem( item ) then
return not IsEquippedItem ( item )
else
return false
end
end
local function InitTeleporterMenu(frame, level, menuList)
local info = UIDropDownMenu_CreateInfo()
info.owner = frame
info.text = "Options"
info.hasArrow = true
info.menuList = "Options"
info.value = 0
info.checked = nil
UIDropDownMenu_AddButton(info, level)
end
local RightClickMenuSpell = nil
local RightClickMenuSpellIsItem
local RightClickMenuSpellName = nil
local AddFavouriteMenu = nil
local RemoveFavouriteMenu = nil
local CantAddFavouriteMenu = nil
local function CreateAddFavouriteMenu()
if not AddFavouriteMenu then
AddFavouriteMenu = CreateFrame("Frame", "TomeOfTeleAddFavouriteMenu", UIParent, "UIDropDownMenuTemplate")
UIDropDownMenu_Initialize(
AddFavouriteMenu,
function(frame, level, menuList)
local info = UIDropDownMenu_CreateInfo()
info.owner = frame
info.hasArrow = false
info.value = 1000
info.checked = nil
info.text = "Add favourite"
info.func = function()
local favourites = GetOption("favourites")
favourites[RightClickMenuSpell] = RightClickMenuSpellIsItem
end
UIDropDownMenu_AddButton(info, level)
end,
"MENU")
end
end
local function CreateRemoveFavouriteMenu()
if not RemoveFavouriteMenu then
RemoveFavouriteMenu = CreateFrame("Frame", "TomeOfTeleRemoveFavouriteMenu", UIParent, "UIDropDownMenuTemplate")
UIDropDownMenu_Initialize(
RemoveFavouriteMenu,
function(frame, level, menuList)
local info = UIDropDownMenu_CreateInfo()
info.owner = frame
info.hasArrow = false
info.value = 1001
info.checked = nil
info.text = "Remove favourite"
info.func = function()
local favourites = GetOption("favourites")
favourites[RightClickMenuSpell] = nil
end
UIDropDownMenu_AddButton(info, level)
end,
"MENU")
end
end
local function CreateEquipableItemRightClickMenu()
if not RemoveFavouriteMenu then
CantAddFavouriteMenu = CreateFrame("Frame", "TomeOfTeleCantAddFavouriteMenu", UIParent, "UIDropDownMenuTemplate")
UIDropDownMenu_Initialize(
CantAddFavouriteMenu,
function(frame, level, menuList)
local info = UIDropDownMenu_CreateInfo()
info.owner = frame
info.hasArrow = false
info.value = 1002
info.checked = nil
info.text = "This item can not be added to favourites"
info.func = nil
UIDropDownMenu_AddButton(info, level)
-- The macros this creates crash the game!
-- info = UIDropDownMenu_CreateInfo()
-- info.owner = frame
-- info.hasArrow = false
-- info.value = 1003
-- info.checked = nil
-- info.text = "Create macro"
-- info.func = function()
-- TeleporterCreateMacroSlashCmdFunction(RightClickMenuSpellName)
-- end
-- UIDropDownMenu_AddButton(info, level)
end,
"MENU")
end
end
local function OnClickTeleButton(frame,button)
if button == "RightButton" then
local spellId = ButtonSettings[frame].spellId
local isItem = ButtonSettings[frame].isItem
local favourites = GetOption("favourites")
if not favourites then
favourites = {}
SetOption("favourites", favourites)
end
RightClickMenuSpell = spellId
RightClickMenuSpellName = ButtonSettings[frame].spellName
RightClickMenuSpellIsItem = isItem
local isFavourite = favourites[spellId] ~= nil
if isItem and IsEquippableItem(spellId) then
CreateEquipableItemRightClickMenu()
ToggleDropDownMenu(1, nil, CantAddFavouriteMenu, "cursor", 3, -3)
elseif not isFavourite then
CreateAddFavouriteMenu()
ToggleDropDownMenu(1, nil, AddFavouriteMenu, "cursor", 3, -3)
else
CreateRemoveFavouriteMenu()
ToggleDropDownMenu(1, nil, RemoveFavouriteMenu, "cursor", 3, -3)
end
end
end
local function SafeGetItemCooldown(itemId)
if GetItemCooldown ~= nil then
return GetItemCooldown(itemId)
else
return C_Container.GetItemCooldown(itemId)
end
end
function TeleporterUpdateButton(button)
if UnitAffectingCombat("player") then
return
end
local settings = ButtonSettings[button]
local isItem = settings.isItem
local item = settings.spellName
local cooldownbar = settings.cooldownbar
local cooldownString = settings.cooldownString
local itemId = settings.spellId
local countString = settings.countString
local toySpell = settings.toySpell
local spell = settings.spell
local onCooldown = false
local buttonInset = GetScaledOption("buttonInset")
if item then
local cooldownStart, cooldownDuration
if isItem then
cooldownStart, cooldownDuration = SafeGetItemCooldown(itemId)
else
if C_Spell and C_Spell.GetSpellCooldown then
local spellCooldownInfo = C_Spell.GetSpellCooldown(itemId);
cooldownStart = spellCooldownInfo.startTime
cooldownDuration = spellCooldownInfo.duration
else
cooldownStart, cooldownDuration = GetSpellCooldown(itemId)
end
end
if cooldownStart and cooldownStart > 0 then
if GetTime() < cooldownStart then
-- Long cooldowns seem to be reported incorrectly after a server reset. Looks like the
-- time is taken from a 32 bit unsigned int.
cooldownStart = cooldownStart - 4294967.295
end
onCooldown = true
local durationRemaining = cooldownDuration - ( GetTime() - cooldownStart )
if durationRemaining < 0 then
durationRemaining = 0
end
if durationRemaining > cooldownDuration then
durationRemaining = cooldownDuration
end
local parentWidth = button:GetWidth()
local inset = GetOption("cooldownBarInset") * 2
cooldownbar:SetWidth( inset + ( parentWidth - inset ) * durationRemaining / cooldownDuration )
if durationRemaining > 3600 then
cooldownString:SetText(string.format("%.0fh", durationRemaining / 3600))
elseif durationRemaining > 60 then
cooldownString:SetText(string.format("%.0fm", durationRemaining / 60))
else
cooldownString:SetText(string.format("%.0fs", durationRemaining))
end
cooldownbar:SetBackdropColor(1, 1, 1, 1)
else
cooldownString:SetText("")
cooldownbar:SetWidth( 1 )
cooldownbar:SetBackdropColor(0, 0, 0, 0)
end
cooldownString:SetPoint("TOPLEFT",button,"TOPRIGHT",-cooldownString:GetStringWidth()*1.1-buttonInset-2,-buttonInset)
cooldownString:SetPoint("BOTTOMRIGHT",button,"BOTTOMRIGHT",-buttonInset - 2,6)