forked from artscout/Broker_portals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
portals.lua
1028 lines (924 loc) · 37.1 KB
/
portals.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
if not LibStub then return end
local dewdrop = LibStub('LibDewdrop-3.0', true)
local icon = LibStub('LibDBIcon-1.0')
local _
local CreateFrame = CreateFrame
local C_ToyBox = C_ToyBox
local GetBindLocation = GetBindLocation
local GetContainerItemCooldown = C_Container.GetContainerItemCooldown
local GetContainerItemInfo = C_Container.GetContainerItemInfo
local GetContainerItemLink = C_Container.GetContainerItemLink
local GetContainerNumSlots = C_Container.GetContainerNumSlots
local GetItemCooldown = C_Container.GetItemCooldown
local GetInventoryItemCooldown = GetInventoryItemCooldown
local GetInventoryItemLink = GetInventoryItemLink
local GetNumGroupMembers = GetNumGroupMembers
local GetSpellBookItemName = GetSpellBookItemName or C_SpellBook.GetSpellBookItemName
local GetSpellCooldown = GetSpellCooldown or C_Spell.GetSpellCooldown
local GetSpellInfo = GetSpellInfo or C_Spell.GetSpellInfo
local GetTime = GetTime
local IsPlayerSpell = IsPlayerSpell
local PlayerHasToy = PlayerHasToy
local SecondsToTime = SecondsToTime
local SendChatMessage = SendChatMessage
local UnitClass = UnitClass
local UnitInRaid = UnitInRaid
local UnitRace = UnitRace
local UIDROPDOWNMENU_DEFAULT_TEXT_HEIGHT = UIDROPDOWNMENU_DEFAULT_TEXT_HEIGHT
local isCataclysmClassic = (WOW_PROJECT_ID == WOW_PROJECT_CATACLYSM_CLASSIC)
local engineeringName = C_TradeSkillUI.GetTradeSkillDisplayName(202)
local engineeringIcon = C_TradeSkillUI.GetTradeSkillTexture(202)
local heartstonesIcon = 134414 -- icon of Heartstone
local teleportsIcon = 237509 -- Teleport to Dalaran icon used
local engineringItemsCount = 0
local challengeSpellCount = 0
local heartstoneItemsCount = 0
local databaseLoaded = false
local category = nil
local methods = {}
local addonName, addonTable = ...
local L = addonTable.L
-- IDs of items usable for transportation
local items = {
-- Dalaran rings
40585, -- Signet of the Kirin Tor
40586, -- Band of the Kirin Tor
44934, -- Loop of the Kirin Tor
44935, -- Ring of the Kirin Tor
45688, -- Inscribed Band of the Kirin Tor
45689, -- Inscribed Loop of the Kirin Tor
45690, -- Inscribed Ring of the Kirin Tor
45691, -- Inscribed Signet of the Kirin Tor
48954, -- Etched Band of the Kirin Tor
48955, -- Etched Loop of the Kirin Tor
48956, -- Etched Ring of the Kirin Tor
48957, -- Etched Signet of the Kirin Tor
51557, -- Runed Signet of the Kirin Tor
51558, -- Runed Loop of the Kirin Tor
51559, -- Runed Ring of the Kirin Tor
51560, -- Runed Band of the Kirin Tor
139599, -- Empowered Ring of the Kirin Tor
-- Seasonal items
21711, -- Lunar Festival Invitation
37863, -- Direbrew's Remote
-- Miscellaneous
17690, -- Frostwolf Insignia Rank 1 (Horde)
17691, -- Stormpike Insignia Rank 1 (Alliance)
17900, -- Stormpike Insignia Rank 2 (Alliance)
17901, -- Stormpike Insignia Rank 3 (Alliance)
17902, -- Stormpike Insignia Rank 4 (Alliance)
17903, -- Stormpike Insignia Rank 5 (Alliance)
17904, -- Stormpike Insignia Rank 6 (Alliance)
17905, -- Frostwolf Insignia Rank 2 (Horde)
17906, -- Frostwolf Insignia Rank 3 (Horde)
17907, -- Frostwolf Insignia Rank 4 (Horde)
17908, -- Frostwolf Insignia Rank 5 (Horde)
17909, -- Frostwolf Insignia Rank 6 (Horde)
22631, -- Atiesh, Greatstaff of the Guardian
32757, -- Blessed Medallion of Karabor
35230, -- Darnarian's Scroll of Teleportation
43824, -- The Schools of Arcane Magic - Mastery
46874, -- Argent Crusader's Tabard
50287, -- Boots of the Bay
52251, -- Jaina's Locket
58487, -- Potion of Deepholm
61379, -- Gidwin's Hearthstone
63206, -- Wrap of Unity (Alliance)
63207, -- Wrap of Unity (Horde)
63352, -- Shroud of Cooperation (Alliance)
63353, -- Shroud of Cooperation (Horde)
63378, -- Hellscream's Reach Tabard
63379, -- Baradin's Wardens Tabard
64457, -- The Last Relic of Argus
65274, -- Cloak of Coordination (Horde)
65360, -- Cloak of Coordination (Alliance)
95050, -- The Brassiest Knuckle (Horde)
95051, -- The Brassiest Knuckle (Alliance)
95567, -- Kirin Tor Beacon
95568, -- Sunreaver Beacon
87548, -- Lorewalker's Lodestone
93672, -- Dark Portal
103678, -- Time-Lost Artifact
110560, -- Garrison Hearthstone
118662, -- Bladespire Relic
118663, -- Relic of Karabor
118907, -- Pit Fighter's Punching Ring
128353, -- Admiral's Compass
128502, -- Hunter's Seeking Crystal
128503, -- Master Hunter's Seeking Crystal
136849, -- Nature's Beacon
139590, -- Scroll of Teleport: Ravenholdt
140192, -- Dalaran Hearthstone
140324, -- Mobile Telemancy Beacon
142469, -- Violet Seal of the Grand Magus
144391, -- Pugilist's Powerful Punching Ring (Alliance)
144392, -- Pugilist's Powerful Punching Ring (Horde)
151016, -- Fractured Necrolyte Skull
166559 -- Commander's Signet of Battle
}
local heartstones = {
-- items usable instead of hearthstone
28585, -- Ruby Slippers
37118, -- Scroll of Recall
44314, -- Scroll of Recall II
44315, -- Scroll of Recall III
37118, -- Scroll of Recall
44314, -- Scroll of Recall II
44315, -- Scroll of Recall III
54452, -- Ethereal Portal
64488, -- The Innkeeper's Daughter
142298, -- Astonishingly Scarlet Slippers
142542, -- Tome of Town Portal
162973, -- Greatfather Winter's Hearthstone
163045, -- Headless Horseman's Hearthstone
165669, -- Lunar Elder's Hearthstone
165670, -- Peddlefeet's Lovely Hearthstone
165802, -- Noble Gardener's Hearthstone
166746, -- Fire Eater's Hearthstone
166747, -- Brewfest Reveler's Hearthstone
168907, -- Holographic Digitalization Hearthstone
172179, -- Eternal Traveler's Hearthstone
180290, -- Night Fae Hearthstone
182773, -- Necrolord Heartstone
183716, -- Venthyr Sinstone
184353, -- Kyrian Hearthstone
184871, -- Dark Portal
188952, -- Dominated Hearthstone
190196, -- Enlightened Hearthstone
190237, -- Broker Translocation Matrix
193588, -- Timewalker's Hearthstone
206195, -- Path of the Naaru
200630, -- Ohn'ir Windsage's Hearthstone
208704, -- Deepdweller's Earthen Hearthstone
209035, -- Hearthstone of the Flame
212337 -- Stone of the Hearth
}
local engineeringItems = {
-- Engineering Gadgets
18984, -- Dimensional Ripper - Everlook
18986, -- Ultrasafe Transporter: Gadgetzan
30542, -- Dimensional Ripper - Area 52
30544, -- Ultrasafe Transporter: Toshley's Station
48933, -- Wormhole Generator: Northrend
87215, -- Wormhole Generator: Pandaria
112059, -- Wormhole Centrifuge
151652, -- Wormhole Generator: Argus
168807, -- Wormhole Generator: Kul Tiras
168808, -- Wormhole Generator: Zandalar
172924, -- Wormhole Generator: Shadowlands
198156, -- Wormhole Generator: Dragon Isles
221966, -- Wormhole GeneratorL Khaz Algar
132523, -- Reaves Battery, unfortunately we can't check for Wormhole Generator module
144341 -- Rechargeable Reaves Battery, same as with Reaves Battery
}
local scrolls = {
6948 -- Hearthstone
}
-- Gold Challenge portals
local challengeSpells = {
--DH Classic
{ 159902, 'TRUE' }, -- Path of the Burning Mountain
{ 373262, 'TRUE' }, -- Path of the Fallen Guardian
{ 131232, 'TRUE' }, -- Path of the Necromancer
{ 131231, 'TRUE' }, -- Path of the Scarlet Blade
{ 131229, 'TRUE' }, -- Path of the Scarlet Mitre
{ 393222, 'TRUE' }, -- Path of the Watcher's Legacy
--DH BC
--DH Cata
{ 445424, 'TRUE' }, -- Path of the Grim Batol
{ 424142, 'TRUE' }, -- Path of the Tidehunter
{ 410080, 'TRUE' }, -- Path of the Wind's Domain
--DH MOP
{ 131228, 'TRUE' }, -- Path of the Black Ox
{ 131204, 'TRUE' }, -- Path of the Jade Serpent
{ 131222, 'TRUE' }, -- Path of the Mogu King
{ 131225, 'TRUE' }, -- Path of the Setting Sun
{ 131206, 'TRUE' }, -- Path of the Shado-Pan
{ 131205, 'TRUE' }, -- Path of the Stout Brew
--DH WOD
{ 159895, 'TRUE' }, -- Path of the Bloodmaul
{ 159899, 'TRUE' }, -- Path of the Crescent Moon
{ 159900, 'TRUE' }, -- Path of the Dark Rail
{ 159896, 'TRUE' }, -- Path of the Iron Prow
{ 159898, 'TRUE' }, -- Path of the Skies
{ 159901, 'TRUE' }, -- Path of the Verdant
{ 159897, 'TRUE' }, -- Path of the Vigilant
--DH Legion
{ 424153, 'TRUE' }, -- Path of the Ancient Horrors
{ 410078, 'TRUE' }, -- Path of the Earth-Warder
{ 393766, 'TRUE' }, -- Path of the Grand Magistrix
{ 424163, 'TRUE' }, -- Path of the Nightmare Lord
{ 393764, 'TRUE' }, -- Path of the Proven Worth
--DH BFA
{ 410074, 'TRUE' }, -- Path of the Festering Rot
{ 410071, 'TRUE' }, -- Path of the Freebooter
{ 424187, 'TRUE' }, -- Path of the Golden Tomb
{ 424167, 'TRUE' }, -- Path of the Heart's Bane
{ 373274, 'TRUE' }, -- Path of the Scrappy Prince
{ 445418, 'TRUE' }, -- Path of the Siege of Boralus
--DH SL
{ 354466, 'TRUE' }, -- Path of the Ascendant
{ 354462, 'TRUE' }, -- Path of the Courageous
{ 373192, 'TRUE' }, -- Path of the First Ones
{ 354464, 'TRUE' }, -- Path of the Misty Forest
{ 354463, 'TRUE' }, -- Path of the Plagued
{ 354468, 'TRUE' }, -- Path of the Scheming Loa
{ 354465, 'TRUE' }, -- Path of the Sinful Soul
{ 373190, 'TRUE' }, -- Path of the Sire
{ 354469, 'TRUE' }, -- Path of the Stone Warden
{ 367416, 'TRUE' }, -- Path of the Streetwise Merchant
{ 373191, 'TRUE' }, -- Path of the Tormented Soul
{ 354467, 'TRUE' }, -- Path of the Undefeated
--DH DF
{ 393279, 'TRUE' }, -- Path of the Arcane Secrets
{ 432257, 'TRUE' }, -- Path of the Bitter Lagacy
{ 393256, 'TRUE' }, -- Path of the Clutch Defender
{ 393273, 'TRUE' }, -- Path of the Draconic Diploma
{ 393276, 'TRUE' }, -- Path of the Obsidian Hoard
{ 432254, 'TRUE' }, -- Path of the Primal Prison
{ 393267, 'TRUE' }, -- Path of the Rotting Woods
{ 432258, 'TRUE' }, -- Path of the Scorching Dream
{ 393283, 'TRUE' }, -- Path of the Titanic Reservoir
{ 424197, 'TRUE' }, -- Path of the Twisted Time
{ 393262, 'TRUE' }, -- Path of the Windswept Plains
--DH TWW
{ 445417, 'TRUE' }, -- Path of the Ara-Kara, City of Echoes
{ 445440, 'TRUE' }, -- Path of the Brewery
{ 445416, 'TRUE' }, -- Path of the City of Threads
{ 445441, 'TRUE' }, -- Path of the Darkflame Cleft
{ 445414, 'TRUE' }, -- Path of the Dawnbreaker
{ 445444, 'TRUE' }, -- Path of the Priory of the Sacred Flame
{ 445443, 'TRUE' }, -- Path of the Rookery
{ 445269, 'TRUE' } -- Path of the Stonevault
}
local whistle = {
141605, -- Flight Master's Whistle
168862 -- G.E.A.R. Tracking Beacon
}
local obj = LibStub:GetLibrary('LibDataBroker-1.1'):NewDataObject(addonName, {
type = 'data source',
text = L['P'],
icon = 'Interface\\Icons\\INV_Misc_Rune_06',
})
local portals
local frame = CreateFrame('frame')
local function CreateCheckbox(checkboxText, key, checkboxTooltip)
local checkbox = CreateFrame("CheckButton", "BPCheckboxID" .. checkboxes, settingsFrame, "UICheckButtonTemplate")
checkbox.Text:SetText(checkboxText)
checkbox:SetPoint("TOPLEFT", settingsFrame, "TOPLEFT", 10, -30 + (checkboxes * -30))
end
frame:SetScript('OnEvent', function(self, event, ...) if self[event] then return self[event](self, event, ...) end end)
frame:RegisterEvent('PLAYER_LOGIN')
local function CreateSettingsPanel()
if Settings then
OptionsFrame = CreateFrame("Frame", nil)
OptionsFrame.name = "Broker Portals"
local showItemsCheckBox = CreateFrame("CheckButton", "ShowItemsCheckbox", OptionsFrame, "InterfaceOptionsCheckButtonTemplate")
showItemsCheckBox:SetPoint("TOPLEFT", 16, -16)
showItemsCheckBox.Text:SetText(L["SHOW_ITEMS"])
showItemsCheckBox.tooltipText = L["SHOW_ITEMS_TOOLTIP"]
showItemsCheckBox:SetChecked(PortalsDB.showItems)
showItemsCheckBox:SetScript("OnClick", function(self)
PortalsDB.showItems = not PortalsDB.showItems
end)
local showHSItemsCheckBox = CreateFrame("CheckButton", "ShowHSItemsCheckbox", OptionsFrame, "InterfaceOptionsCheckButtonTemplate")
showHSItemsCheckBox:SetPoint("TOPLEFT", 320, -16)
showHSItemsCheckBox.Text:SetText(L["SHOW_HS_ITEMS"])
showHSItemsCheckBox.tooltipText = L["SHOW_HS_ITEMS_TOOLTIP"]
showHSItemsCheckBox:SetChecked(PortalsDB.showHSItems)
showHSItemsCheckBox:SetScript("OnClick", function(self)
PortalsDB.showHSItems = not PortalsDB.showHSItems
end)
local showItemsCooldownCheckBox = CreateFrame("CheckButton", "ShowItemsCooldownCheckbox", OptionsFrame, "InterfaceOptionsCheckButtonTemplate")
showItemsCooldownCheckBox:SetPoint("TOPLEFT", 16, -64)
showItemsCooldownCheckBox.Text:SetText(L["SHOW_ITEM_COOLDOWNS"])
showItemsCooldownCheckBox.tooltipText = L["SHOW_ITEM_COOLDOWNS_TOOLTIP"]
showItemsCooldownCheckBox:SetChecked(PortalsDB.showItemCooldowns)
showItemsCooldownCheckBox:SetScript("OnClick", function(self)
PortalsDB.showItemCooldowns = not PortalsDB.showItemCooldowns
end)
local showChallengeTeleportsCheckBox = CreateFrame("CheckButton", "ShowChallengeTeleportsCheckbox", OptionsFrame, "InterfaceOptionsCheckButtonTemplate")
showChallengeTeleportsCheckBox:SetPoint("TOPLEFT", 320, -64)
showChallengeTeleportsCheckBox.Text:SetText(L["SHOW_CHALLENGE_TELEPORTS"])
showChallengeTeleportsCheckBox.tooltipText = L["SHOW_CHALLENGE_TELEPORTS_TOOLTIP"]
showChallengeTeleportsCheckBox:SetChecked(PortalsDB.showChallengeTeleports)
showChallengeTeleportsCheckBox:SetScript("OnClick", function(self)
PortalsDB.showChallengeTeleports = not PortalsDB.showChallengeTeleports
end)
local showEnginneringSubCatCheckBox = CreateFrame("CheckButton", "ShowEngineeringSubCatCheckbox", OptionsFrame, "InterfaceOptionsCheckButtonTemplate")
showEnginneringSubCatCheckBox:SetPoint("TOPLEFT", 16, -110)
showEnginneringSubCatCheckBox.Text:SetText(L["SHOW_ENGINEERING_SUBCAT"])
showEnginneringSubCatCheckBox.tooltipText = L["SHOW_ENGINEERING_SUBCAT_TOOLTIP"]
showEnginneringSubCatCheckBox:SetChecked(PortalsDB.showEnginneringSubCat)
showEnginneringSubCatCheckBox:SetScript("OnClick", function(self)
PortalsDB.showEnginneringSubCat = not PortalsDB.showEnginneringSubCat
end)
local announceCheckBox = CreateFrame("CheckButton", "ShowItemsCheckbox", OptionsFrame, "InterfaceOptionsCheckButtonTemplate")
announceCheckBox:SetPoint("TOPLEFT", 320, -110)
announceCheckBox.Text:SetText(L["ANNOUNCE"])
announceCheckBox.tooltipText = L["ANNOUNCE_TOOLTIP"]
announceCheckBox:SetChecked(PortalsDB.announce)
announceCheckBox:SetScript("OnClick", function(self)
PortalsDB.announce = not PortalsDB.announce
end)
local minimapButtonBox = CreateFrame("CheckButton", "ShowItemsCheckbox", OptionsFrame, "InterfaceOptionsCheckButtonTemplate")
minimapButtonBox:SetPoint("TOPLEFT", 16, -158)
minimapButtonBox.Text:SetText(L['ATT_MINIMAP'])
minimapButtonBox.tooltipText = L['ATT_MINIMAP']
minimapButtonBox:SetChecked(not PortalsDB.minimap.hide)
minimapButtonBox:SetScript("OnClick", function(self)
ToggleMinimap()
end)
local fontSizeSlider = CreateFrame("Slider", "FontSizeSlider", OptionsFrame, "OptionsSliderTemplate")
fontSizeSlider:SetPoint("TOPLEFT", 320, -158)
fontSizeSlider.Text:SetText(L['DROPDOWN_FONT_SIZE'])
fontSizeSlider.tooltipText = L['DROPDOWN_FONT_SIZE']
fontSizeSlider:SetMinMaxValues(8, 32)
fontSizeSlider:SetValueStep(1)
fontSizeSlider:SetScript('OnShow', function(self) self:SetValue(PortalsDB.fontSize) end)
fontSizeSlider:SetScript('OnValueChanged', function(self,value) PortalsDB.fontSize = tonumber(value) end)
category = Settings.RegisterCanvasLayoutCategory(OptionsFrame, OptionsFrame.name)
Settings.RegisterAddOnCategory(category)
end
end
local function pairsByKeys(t)
local a = {}
for n in pairs(t) do
table.insert(a, n)
end
table.sort(a)
local i = 0
local iter = function()
i = i + 1
if a[i] == nil then
return nil
else
return a[i], t[a[i]]
end
end
return iter
end
local function tconcat(t1, t2)
for i = 1, #t2 do
t1[#t1 + 1] = t2[i]
end
return t1
end
-- returns true, if player has item with given ID in inventory or bags and it's not on cooldown
local function hasItem(itemID)
local item, found, id
-- scan inventory
for slotId = 1, 19 do
item = GetInventoryItemLink('player', slotId)
if item then
found, _, id = item:find('^|c%x+|Hitem:(%d+):.+')
if found and tonumber(id) == itemID then
if GetInventoryItemCooldown('player', slotId) ~= 0 then
return false
else
return true
end
end
end
end
-- check Toybox
if PlayerHasToy(itemID) and C_ToyBox.IsToyUsable(itemID) then
local startTime, duration, cooldown
startTime, duration = GetItemCooldown(itemID)
cooldown = duration - (GetTime() - startTime)
if cooldown > 0 then
return false
else
return true
end
end
-- scan bags
for bag = 0, 4 do
for slot = 1, GetContainerNumSlots(bag) do
item = GetContainerItemLink(bag, slot)
if item then
found, _, id = item:find('^|c%x+|Hitem:(%d+):.+')
if found and tonumber(id) == itemID then
if GetContainerItemCooldown(bag, slot) ~= 0 then
return false
else
return true
end
end
end
end
end
return false
end
local function getReagentCount(name)
local count = 0
for bag = 0, 4 do
for slot = 1, GetContainerNumSlots(bag) do
local item = GetContainerItemLink(bag, slot)
if item then
if item:find(name) then
local itemInfo = GetContainerItemInfo(bag, slot)
count = count + itemInfo.stackCount
end
end
end
end
return count
end
local function SetupSpells()
local spells = {
Alliance = {
{ 3561, 'TP_RUNE' }, -- TP:Stormwind
{ 3562, 'TP_RUNE' }, -- TP:Ironforge
{ 3565, 'TP_RUNE' }, -- TP:Darnassus
{ 32271, 'TP_RUNE' }, -- TP:Exodar
{ 49359, 'TP_RUNE' }, -- TP:Theramore
{ 33690, 'TP_RUNE' }, -- TP:Shattrath
{ 53140, 'TP_RUNE' }, -- TP:Dalaran
{ 88342, 'TP_RUNE' }, -- TP:Tol Barad
{ 132621, 'TP_RUNE' }, -- TP:Vale of Eternal Blossoms
{ 120145, 'TP_RUNE' }, -- TP:Ancient Dalaran
{ 176248, 'TP_RUNE' }, -- TP:StormShield
{ 224869, 'TP_RUNE' }, -- TP:Dalaran - Broken Isles
{ 193759, 'TP_RUNE' }, -- TP:Hall of the Guardian
{ 281403, 'TP_RUNE' }, -- TP:Boralus
{ 344587, 'TP_RUNE' }, -- TP:Oribos
{ 395277, 'TP_RUNE' }, -- TP:Valdrakken
{ 446540, 'TP_RUNE' }, -- TP:Dornogal
{ 10059, 'P_RUNE' }, -- P:Stormwind
{ 11416, 'P_RUNE' }, -- P:Ironforge
{ 11419, 'P_RUNE' }, -- P:Darnassus
{ 32266, 'P_RUNE' }, -- P:Exodar
{ 49360, 'P_RUNE' }, -- P:Theramore
{ 33691, 'P_RUNE' }, -- P:Shattrath
{ 53142, 'P_RUNE' }, -- P:Dalaran
{ 88345, 'P_RUNE' }, -- P:Tol Barad
{ 120146, 'P_RUNE' }, -- P:Ancient Dalaran
{ 132620, 'P_RUNE' }, -- P:Vale of Eternal Blossoms
{ 176246, 'P_RUNE' }, -- P:StormShield
{ 224871, 'P_RUNE' }, -- P:Dalaran - Broken Isles
{ 281400, 'P_RUNE' }, -- P:Boralus
{ 344597, 'P_RUNE' }, -- P:Oribos
{ 395289, 'P_RUNE' }, -- P:Valdrakken
{ 446534, 'P_RUNE' } -- P:Dornogal
},
Horde = {
{ 3563, 'TP_RUNE' }, -- TP:Undercity
{ 3566, 'TP_RUNE' }, -- TP:Thunder Bluff
{ 3567, 'TP_RUNE' }, -- TP:Orgrimmar
{ 32272, 'TP_RUNE' }, -- TP:Silvermoon
{ 49358, 'TP_RUNE' }, -- TP:Stonard
{ 35715, 'TP_RUNE' }, -- TP:Shattrath
{ 53140, 'TP_RUNE' }, -- TP:Dalaran
{ 88344, 'TP_RUNE' }, -- TP:Tol Barad
{ 132627, 'TP_RUNE' }, -- TP:Vale of Eternal Blossoms
{ 120145, 'TP_RUNE' }, -- TP:Ancient Dalaran
{ 176242, 'TP_RUNE' }, -- TP:Warspear
{ 224869, 'TP_RUNE' }, -- TP:Dalaran - Broken Isles
{ 193759, 'TP_RUNE' }, -- TP:Hall of the Guardian
{ 281404, 'TP_RUNE' }, -- TP:Dazar'alor
{ 344587, 'TP_RUNE' }, -- TP:Oribos
{ 395277, 'TP_RUNE' }, -- TP:Valdrakken
{ 446540, 'TP_RUNE' }, -- TP:Dornogal
{ 11418, 'P_RUNE' }, -- P:Undercity
{ 11420, 'P_RUNE' }, -- P:Thunder Bluff
{ 11417, 'P_RUNE' }, -- P:Orgrimmar
{ 32267, 'P_RUNE' }, -- P:Silvermoon
{ 49361, 'P_RUNE' }, -- P:Stonard
{ 35717, 'P_RUNE' }, -- P:Shattrath
{ 53142, 'P_RUNE' }, -- P:Dalaran
{ 88346, 'P_RUNE' }, -- P:Tol Barad
{ 120146, 'P_RUNE' }, -- P:Ancient Dalaran
{ 132626, 'P_RUNE' }, -- P:Vale of Eternal Blossoms
{ 176244, 'P_RUNE' }, -- P:Warspear
{ 224871, 'P_RUNE' }, -- P:Dalaran - Broken Isles
{ 281402, 'P_RUNE' }, -- P:Dazar'alor
{ 344597, 'P_RUNE' }, -- P:Oribos
{ 395289, 'P_RUNE' }, -- P:Valdrakken
{ 446534, 'P_RUNE' } -- P:Dornogal
}
}
local _, class = UnitClass('player')
if class == 'MAGE' then
portals = spells[select(1, UnitFactionGroup('player'))]
elseif class == 'DEATHKNIGHT' then
portals = {
{ 50977, 'TRUE' } -- Death Gate
}
elseif class == 'DRUID' then
portals = {
{ 18960, 'TRUE' }, -- TP:Moonglade
{ 147420, 'TRUE' }, -- TP:One with Nature
{ 193753, 'TRUE' } -- TP:Dreamwalk
}
elseif class == 'SHAMAN' then
portals = {
{ 556, 'TRUE' } -- Astral Recall
}
elseif class == 'MONK' then
portals = {
{ 126892, 'TRUE' }, -- Zen Pilgrimage
{ 126895, 'TRUE' } -- Zen Pilgrimage: Return
}
else
portals = {}
end
local _, race = UnitRace('player')
if race == 'DarkIronDwarf' then
table.insert(portals, { 265225, 'TRUE' }) -- Mole Machine
end
wipe(spells)
end
local function GenerateMenuEntries(itemType, itemList, menuCategory)
local itemsGenerated = 0
if itemType == "spell" then
for _, unTransSpell in ipairs(itemList) do
if IsPlayerSpell(unTransSpell[1]) then
local spellName
local spell, _, spellIcon, _, _, _, spellId = GetSpellInfo(unTransSpell[1])
if type(spell) == "table" then
spellId = spell.spellID
spellIcon = spell.iconID
spellName = spell.name
else
spellName = spell
end
if spellId then
if not methods[menuCategory] then
methods[menuCategory] = {}
end
methods[menuCategory][spellName] = {
itemID = spellId,
itemName = spellName,
itemIcon = spellIcon,
itemType = itemType,
itemRGB = nil,
isPortal = unTransSpell[2] == 'P_RUNE',
secure = {
type = 'spell',
spell = spellName
}
}
itemsGenerated = itemsGenerated + 1
end
end
end
else
local i = 0
for i = 1, #itemList do
if hasItem(itemList[i]) then
local itemName, _, itemQuality, _, _, _, _, _, _, itemIcon = GetItemInfo(itemList[i])
if not methods[menuCategory] then
methods[menuCategory] = {}
end
methods[menuCategory][itemName] = {
itemID = itemList[i],
itemName = itemName,
itemIcon = itemIcon,
itemType = itemType,
itemRGB = ITEM_QUALITY_COLORS[itemQuality],
secure = {
type = 'item',
item = itemName
}
}
itemsGenerated = itemsGenerated + 1
end
i = i + 1
end
end
return itemsGenerated
end
local function PrepareMenuData()
wipe(methods)
if not portals then
SetupSpells()
end
if portals then
GenerateMenuEntries("spell", portals, "mainspells")
end
if not isCataclysmClassic then
challengeSpellCount = GenerateMenuEntries("spell", challengeSpells, "challenges")
end
GenerateMenuEntries("items", items, "mainitems")
engineringItemsCount = GenerateMenuEntries("items", engineeringItems, "engineering")
heartstoneItemsCount = GenerateMenuEntries("items", heartstones, "heartstones")
databaseLoaded = true
end
local function UpdateIcon(icon)
obj.icon = icon
end
local function ShowMenuEntries(category)
if methods[category] then
for _, menuEntry in pairsByKeys(methods[category]) do
if menuEntry.itemType == "spell" then
local spellCooldown
if isCataclysmClassic then spellCooldown = GetSpellCooldown(menuEntry.itemName) else spellCooldown = GetSpellCooldown(menuEntry.itemName).startTime end
if menuEntry.secure and spellCooldown == 0 then
dewdrop:AddLine(
'textHeight', PortalsDB.fontSize,
'text', menuEntry.itemName,
'secure', menuEntry.secure,
'icon', tostring(menuEntry.itemIcon),
'func', function()
UpdateIcon(menuEntry.itemIcon)
if announce and menuyEntry.isPortal and chatType then
SendChatMessage(L['ANNOUNCEMENT'] .. ' ' .. menuEntry.itemName, chatType)
end
end,
'closeWhenClicked', true)
end
else
dewdrop:AddLine(
'textHeight', PortalsDB.fontSize,
'text', menuEntry.itemName,
'textR', menuEntry.itemRGB.r,
'textG', menuEntry.itemRGB.g,
'textB', menuEntry.itemRGB.b,
'secure', menuEntry.secure,
'icon', tostring(menuEntry.itemIcon),
'func', function() UpdateIcon(menuEntry.itemIcon) end,
'closeWhenClicked', true)
end
end
end
end
local function GetItemCooldowns()
local cooldown, cooldowns, hours, mins, secs
for i = 1, #items do
if GetItemCount(items[i]) > 0 or (PlayerHasToy(items[i]) and C_ToyBox.IsToyUsable(items[i])) then
startTime, duration = GetItemCooldown(items[i])
cooldown = duration - (GetTime() - startTime)
if cooldown <= 0 then
cooldown = L['READY']
else
cooldown = SecondsToTime(cooldown)
end
if cooldowns == nil then
cooldowns = {}
end
local name = GetItemInfo(items[i]) or select(2, C_ToyBox.GetToyInfo(items[i]))
if name then
cooldowns[name] = cooldown
end
end
end
return cooldowns
end
local function GetScrollCooldown()
local cooldown, startTime, duration
for i = 1, #scrolls do
if GetItemCount(scrolls[i]) > 0 or (PlayerHasToy(scrolls[i]) and C_ToyBox.IsToyUsable(scrolls[i])) then
startTime, duration = GetItemCooldown(scrolls[i])
cooldown = duration - (GetTime() - startTime)
if cooldown <= 0 then
return L['READY']
else
return SecondsToTime(cooldown)
end
end
end
return L['N/A']
end
local function GetWhistleCooldown()
local cooldown, startTime, duration
if GetItemCount(whistle[1]) > 0 then
startTime, duration = GetItemCooldown(whistle[1])
cooldown = duration - (GetTime() - startTime)
if cooldown <= 0 then
return L['READY']
else
return SecondsToTime(cooldown)
end
end
return L['N/A']
end
local function ShowHearthstone()
local bindLoc = GetBindLocation()
local secure, text, icon, name
for i = 1, #scrolls do
if hasItem(scrolls[i]) then
name, _, _, _, _, _, _, _, _, icon = GetItemInfo(scrolls[i])
text = L['INN'] .. ' ' .. bindLoc
secure = {
type = 'item',
item = name
}
break
end
end
if secure ~= nil then
dewdrop:AddLine(
'textHeight', PortalsDB.fontSize,
'text', text,
'secure', secure,
'icon', tostring(icon),
'func', function() UpdateIcon(icon) end,
'closeWhenClicked', true)
end
end
local function ShowWhistle()
local secure, icon, name
if hasItem(whistle[1]) then
name, _, _, _, _, _, _, _, _, icon = GetItemInfo(whistle[1])
secure = {
type = 'item',
item = name
}
end
if secure ~= nil then
dewdrop:AddLine()
dewdrop:AddLine(
'textHeight', PortalsDB.fontSize,
'text', name,
'secure', secure,
'icon', tostring(icon),
'func', function() UpdateIcon(icon) end,
'closeWhenClicked', true)
dewdrop:AddLine()
end
end
local function ToggleMinimap()
local hide = not PortalsDB.minimap.hide
PortalsDB.minimap.hide = hide
if hide then
icon:Hide('Broker_Portals')
else
icon:Show('Broker_Portals')
end
end
local function UpdateMenu(level, value)
dewdrop:SetFontSize(PortalsDB.fontSize)
if level == 1 then
dewdrop:AddLine('text', 'Broker_Portals', 'isTitle', true)
PrepareMenuData()
local chatType = (UnitInRaid("player") and "RAID") or (GetNumGroupMembers() > 0 and "PARTY") or nil
local announce = PortalsDB.announce
if not portals then
SetupSpells()
end
if portals then
ShowMenuEntries("mainspells")
dewdrop:AddLine()
end
ShowHearthstone()
dewdrop:AddLine()
if PortalsDB.showItems then
ShowMenuEntries("mainitems")
ShowWhistle()
end
if PortalsDB.showItems and engineringItemsCount > 0 then
if PortalsDB.showEnginneringSubCat then
dewdrop:AddLine()
dewdrop:AddLine(
'textHeight', PortalsDB.fontSize,
'text', engineeringName,
'icon', tostring(engineeringIcon),
'hasArrow', true,
'value', 'engineering')
else
ShowMenuEntries("engineering")
dewdrop:AddLine()
end
end
if PortalsDB.showChallengeTeleports and not isCataclysmClassic and challengeSpellCount > 0 then
dewdrop:AddLine(
'textHeight', PortalsDB.fontSize,
'text', L['CHALLENGE_TELEPORTS'],
'icon', tostring(teleportsIcon),
'hasArrow', true,
'value', 'challenges')
end
if PortalsDB.showHSItems and heartstoneItemsCount > 0 then
dewdrop:AddLine(
'textHeight', PortalsDB.fontSize,
'text', L['HEARTHSTONE_ANALOGUES'],
'icon', tostring(heartstonesIcon),
'hasArrow', true,
'value', 'heartstones')
end
dewdrop:AddLine()
dewdrop:AddLine(
'textHeight', PortalsDB.fontSize,
'text', L['OPTIONS'],
'hasArrow', false,
'func', function() Settings.OpenToCategory(category:GetID()); end,
'closeWhenClicked', true)
dewdrop:AddLine(
'textHeight', PortalsDB.fontSize,
'text', CLOSE,
'tooltipTitle', CLOSE,
'tooltipText', CLOSE_DESC,
'closeWhenClicked', true)
elseif level == 2 and value == 'heartstones' then
ShowMenuEntries("heartstones")
elseif level == 2 and value == 'challenges' then
ShowMenuEntries("challenges")
elseif level == 2 and value == 'engineering' then
ShowMenuEntries("engineering")
end
end
function frame:PLAYER_LOGIN()
-- PortalsDB.minimap is there for smooth upgrade of SVs from old version
if (not PortalsDB) or (PortalsDB.version == nil) then
PortalsDB = {}
PortalsDB.minimap = {}
PortalsDB.minimap.hide = false
PortalsDB.showItems = true
PortalsDB.showHSItems = true
PortalsDB.showItemCooldowns = true
PortalsDB.showChallengeTeleports = true
PortalsDB.showEnginneringSubCat = true
PortalsDB.announce = false
PortalsDB.fontSize = UIDROPDOWNMENU_DEFAULT_TEXT_HEIGHT
PortalsDB.version = 7
end
-- upgrade from versions
if PortalsDB.version == 6 then
PortalsDB.showEnginneringSubCat = true
PortalsDB.version = 7
elseif PortalsDB.version == 5 then
PortalsDB.showChallengeTeleports = true
PortalsDB.version = 6
elseif PortalsDB.version == 4 then
PortalsDB.fontSize = UIDROPDOWNMENU_DEFAULT_TEXT_HEIGHT
PortalsDB.version = 5
elseif PortalsDB.version == 3 then
PortalsDB.announce = false
PortalsDB.version = 4
elseif PortalsDB.version == 2 then
PortalsDB.showItemCooldowns = true
PortalsDB.announce = false
PortalsDB.version = 4
elseif PortalsDB.version < 2 then
PortalsDB.showItems = true
PortalsDB.showItemCooldowns = true
PortalsDB.announce = false
PortalsDB.version = 4
end
if icon then
icon:Register('Broker_Portals', obj, PortalsDB.minimap)
end
CreateSettingsPanel()
self:UnregisterEvent('PLAYER_LOGIN')
end
-- All credit for this func goes to Tekkub and his picoGuild!
local function GetTipAnchor(frame)
local x, y = frame:GetCenter()
if not x or not y then return 'TOPLEFT', 'BOTTOMLEFT' end
local hhalf = (x > UIParent:GetWidth() * 2 / 3) and 'RIGHT' or (x < UIParent:GetWidth() / 3) and 'LEFT' or ''
local vhalf = (y > UIParent:GetHeight() / 2) and 'TOP' or 'BOTTOM'
return vhalf .. hhalf, frame, (vhalf == 'TOP' and 'BOTTOM' or 'TOP') .. hhalf
end
function obj.OnClick(self, button)
GameTooltip:Hide()
if button == 'RightButton' then
dewdrop:Open(self, 'children', function(level, value) UpdateMenu(level, value) end)
end
end
function obj.OnLeave()
GameTooltip:Hide()
end
function obj.OnEnter(self)
GameTooltip:SetOwner(self, 'ANCHOR_NONE')
GameTooltip:SetPoint(GetTipAnchor(self))
GameTooltip:ClearLines()
GameTooltip:AddLine('Broker Portals')
GameTooltip:AddDoubleLine(L['RCLICK'], L['SEE_SPELLS'], 0.9, 0.6, 0.2, 0.2, 1, 0.2)
GameTooltip:AddLine(' ')
local scrollCooldown = GetScrollCooldown()
if scrollCooldown == L['READY'] then
GameTooltip:AddDoubleLine(L['HEARTHSTONE'] .. ': ' .. GetBindLocation(), scrollCooldown, 0.9, 0.6, 0.2, 0.2, 1, 0.2)
else
GameTooltip:AddDoubleLine(L['HEARTHSTONE'] .. ': ' .. GetBindLocation(), scrollCooldown, 0.9, 0.6, 0.2, 1, 1, 0.2)
end
if isCataclysmClassic then
GameTooltip:AddLine(" ")
GameTooltip:AddDoubleLine(L["TP_P"], getReagentCount(L["TP_RUNE"]).."/"..getReagentCount(L["P_RUNE"]), 0.9, 0.6, 0.2, 0.2, 1, 0.2)
end