forked from gyakovlev/xCT
-
Notifications
You must be signed in to change notification settings - Fork 22
/
core.lua
executable file
·1954 lines (1695 loc) · 57.1 KB
/
core.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
--[[ ____ ______
/\ _`\ /\__ _\ __
__ _\ \ \/\_\/_/\ \/ /_\ \___
/\ \/'\\ \ \/_/_ \ \ \/\___ __\
\/> </ \ \ \L\ \ \ \ \/__/\_\_/
/\_/\_\ \ \____/ \ \_\ \/_/
\//\/_/ \/___/ \/_/
[=====================================]
[ Author: Dandraffbal-Stormreaver US ]
[ xCT+ Version 4.x.x ]
[ ©2020. All Rights Reserved. ]
[====================================]]
-- Dont do anything for Legion
local build = select(4, GetBuildInfo())
-- Get Addon's name and Blizzard's Addon Stub
local AddonName, addon = ...
local sgsub, ipairs, pairs, type, string_format, table_insert, table_remove, table_sort, print, tostring, tonumber, select, string_lower, collectgarbage, string_match, string_find =
string.gsub, ipairs, pairs, type, string.format, table.insert, table.remove, table.sort, print, tostring, tonumber, select, string.lower, collectgarbage, string.match, string.find
-- compares a tables values
local function tableCompare(t1, t2)
local equal = true
-- nil check
if not t1 or not t2 then
if not t1 and not t2 then
return true
else
return false
end
end
for i,v in pairs(t1) do
if t2[i] ~= v then
equal = false
break;
end
end
return equal
end
-- Local Handle to the Engine
local x = addon.engine
-- Profile Updated, need to refresh important stuff
local function RefreshConfig()
-- Clean up the Profile
x:CompatibilityLogic(true)
x:UpdateFrames()
x:UpdateSpamSpells()
x:UpdateItemTypes()
-- Will this fix the profile issue?
x.GenerateSpellSchoolColors()
x.GenerateColorOptions()
-- Update combat text engine CVars
x.cvar_update( true )
collectgarbage()
end
local function ProfileReset()
-- Clean up the Profile
x:CompatibilityLogic(false)
x:UpdateFrames()
x:UpdateSpamSpells()
x:UpdateItemTypes()
collectgarbage()
end
local function CheckExistingProfile()
local key = UnitName("player").." - "..GetRealmName()
return xCTSavedDB
and xCTSavedDB.profileKeys
and xCTSavedDB.profileKeys[key]
and xCTSavedDB.profiles[xCTSavedDB.profileKeys[key]]
end
-- Handle Addon Initialized
function x:OnInitialize()
if xCT or ct and ct.myname and ct.myclass then
print("|cffFF0000WARNING:|r xCT+ cannot load. Please disable xCT in order to use xCT+.")
return
end
-- Check for new installs
self.existingProfile = CheckExistingProfile()
-- Generate Dynamic Merge Entries
addon.GenerateDefaultSpamSpells()
-- Clean Up Colors in the DB
addon.LoadDefaultColors()
-- Load the Data Base
self.db = LibStub('AceDB-3.0'):New('xCTSavedDB', addon.defaults)
-- Add the profile options to my dialog config
addon.options.args['Profiles'] = LibStub('AceDBOptions-3.0'):GetOptionsTable(self.db)
-- Had to pass the explicit method into here, not sure why
self.db.RegisterCallback(self, 'OnProfileChanged', RefreshConfig)
self.db.RegisterCallback(self, 'OnProfileCopied', RefreshConfig)
self.db.RegisterCallback(self, 'OnProfileReset', ProfileReset)
-- Clean up the Profile
local success = x:CompatibilityLogic(self.existingProfile)
if not success then
x:UpdateCombatTextEvents(false)
return
end
-- Perform xCT+ Update
x:UpdatePlayer()
-- Delay updating frames until all other addons are loaded!
--x:UpdateFrames()
if build < 70000 then
x:UpdateBlizzardFCT()
end
x:UpdateCombatTextEvents(true)
x:UpdateSpamSpells()
x:UpdateItemTypes()
x:UpdateAuraSpellFilter()
x.GenerateColorOptions()
x.GenerateSpellSchoolColors()
-- Update combat text engine CVars
x.cvar_update()
-- Register Slash Commands
x:RegisterChatCommand('xct', 'OpenxCTCommand')
-- Everything got Initialized, show Startup Text
if self.db.profile.showStartupText then
print("Loaded |cffFF0000x|r|cffFFFF00CT|r|cffFF0000+|r. To configure, type: |cffFF0000/xct|r")
end
end
-- Need to create a handle to update frames when every other addon is done.
local frameUpdate = CreateFrame("FRAME")
frameUpdate:RegisterEvent("PLAYER_ENTERING_WORLD")
frameUpdate:SetScript("OnEvent", function(self)
self:UnregisterEvent("PLAYER_ENTERING_WORLD")
x:UpdateFrames()
x.cvar_update()
--x.UpdateBlizzardOptions()
end)
-- Version Compare Helpers... Yeah!
local function VersionToTable( version )
local major, minor, iteration, releaseMsg = string_match(string_lower(version), "(%d+)%.(%d+)%.(%d+)(.*)")
major, minor, iteration = tonumber(major) or 0, tonumber(minor) or 0, tonumber(iteration) or 0
local isAlpha, isBeta = string_find(releaseMsg, "alpha") and true or false, string_find(releaseMsg, "beta") and true or false
local t = { }
t.major = major
t.minor = minor
t.iteration = iteration
t.isAlpha = isAlpha
t.isBeta = isBeta
t.isRelease = not (isAlpha or isBeta)
if not t.isReleased then
t.devBuild = tonumber(string_match(releaseMsg, "(%d+)")) or 1
end
return t
end
local function CompareVersions( a, b, debug )
if debug then
print('First Build:')
for i,v in pairs(a) do
print(' '..i..' = '..tostring(v))
end
print('Second Build:')
for i,v in pairs(b) do
print(' '..i..' = '..tostring(v))
end
end
-- Compare Major numbers
if a.major > b.major then
return 1
elseif a.major < b.major then
return -1
end
-- Compare Minor numbers
if a.minor > b.minor then
return 1
elseif a.minor < b.minor then
return -1
end
-- Compare Iteration numbers
if a.iteration > b.iteration then
return 1
elseif a.iteration < b.iteration then
return -1
end
-- Compare Beta to Release then Alpha
if not a.isBeta and b.isBeta then
if a.isAlpha then
return -1
else
return 1
end
elseif a.isBeta and not b.isBeta then
if b.isAlpha then
return 1
else
return -1
end
end
-- Compare Beta Build Versions
if a.isBeta and b.isBeta then
if a.devBuild > b.devBuild then
return 1
elseif a.devBuild < b.devBuild then
return -1
end
return 0
end
-- Compare Alpha to Release
if not a.isAlpha and b.isAlpha then
return 1
elseif a.isAlpha and not b.isAlpha then
return -1
end
-- Compare Alpha Build Versions
if a.isAlpha and b.isAlpha then
if a.devBuild > b.devBuild then
return 1
elseif a.devBuild < b.devBuild then
return -1
end
return 0
end
return 0
end
do
local cleanUpShown = false
function x.MigratePrint(msg)
if not cleanUpShown then
print("|cffFF0000x|rCT|cffFFFF00+|r: |cffFF8000Clean Up - Migrated Settings|r")
cleanUpShown = true
end
print(" "..msg)
end
end
-- This function was created as the central location for crappy code
function x:CompatibilityLogic( existing )
local addonVersionString = C_AddOns.GetAddOnMetadata("xCT+", "Version")
local currentVersion = VersionToTable(addonVersionString)
local previousVersion = VersionToTable(self.db.profile.dbVersion or "4.3.0 Beta 2")
if not currentVersion.devBuild and UnitName("player") == "Dandraffbal" then
currentVersion.devBuild = 1
end
if existing then
-- Pre-Legion Requires Complete Reset
if CompareVersions( VersionToTable("4.2.9"), previousVersion) > 0 then
StaticPopup_Show("XCT_PLUS_DB_CLEANUP_2")
return false -- Do not continue loading addon
end
-- 4.3.0 Beta 3 -> Removes Spell School Colors from Outgoing fraame settings
if CompareVersions( VersionToTable("4.3.0 Beta 3"), previousVersion) > 0 then
if currentVersion.devBuild then
x.MigratePrint("|cff798BDDSpell School Colors|r (|cffFFFF00From: Config Tool->Frames->Outgoing|r | |cff00FF00To: Config Tool->Spell School Colors|r)")
end
if x.db.profile.frames.outgoing.colors.spellSchools then
local oldDB = x.db.profile.frames.outgoing.colors.spellSchools.colors
local newDB = x.db.profile.SpellColors
local keys = {
['SpellSchool_Physical'] = "1",
['SpellSchool_Holy'] = "2",
['SpellSchool_Fire'] = "4",
['SpellSchool_Nature'] = "8",
['SpellSchool_Frost'] = "16",
['SpellSchool_Shadow'] = "32",
['SpellSchool_Arcane'] = "64",
}
for oldKey, newKey in pairs(keys) do
if oldDB[oldKey] then
newDB[newKey].enabled = oldDB[oldKey].enabled
newDB[newKey].color = oldDB[oldKey].color
end
end
x.db.profile.frames.outgoing.colors.spellSchools = nil
end
end
-- 4.3.0 Beta 4 -> Remove redundent Merge Entries from the Config
if CompareVersions( VersionToTable("4.3.0 Beta 5"), previousVersion) > 0 then
if currentVersion.devBuild then
x.MigratePrint("|cff798BDDMerge Entries:|r (|cffFFFF00Optimizing SavedVars|r)")
end
local merge = x.db.profile.spells.merge
for id, entry in pairs(merge) do
merge[id] = nil
if not entry.enabled and addon.merges[id] then
merge[id] = { enabled = false }
end
end
end
-- Clean up colors names in the database
if CompareVersions( VersionToTable("4.3.3 Beta 1"), previousVersion) > 0 then
if currentVersion.devBuild then --currentVersion.devBuild then
x.MigratePrint("|cff798BDDCustom Colors|r (|cffFFFF00From: Config Tool->Frames-> All Frames ->Colors|r) Removing old options.")
end
for name, settings in pairs(x.db.profile.frames) do
if settings.colors then
for exists in pairs(settings.colors) do
if addon.defaults.profile.frames[name] and not addon.defaults.profile.frames[name].colors[exists] then
settings.colors[exists] = nil
end
end
end
end
end
-- Clean up class frame from database
if CompareVersions( VersionToTable("4.5.1-beta5"), previousVersion ) > 0 then
if currentVersion.devBuild then --currentVersion.devBuild then
x.MigratePrint("|cffFFFF00Cleaning Frame DB (Removing Class)|r")
end
self.db.profile.frames.class = nil
end
else
-- Created New: Dont need to do anything right now
end
self.db.profile.dbVersion = addonVersionString
return true
end
function x.CleanUpForLegion()
local key = xCTSavedDB.profileKeys[UnitName("player").." - "..GetRealmName()]
xCTSavedDB.profiles[key] = {}
ReloadUI()
end
local getSpellDescription
do
local tooltip = CreateFrame('GameTooltip', 'xCT_SpellDescriptionTooltip', nil, 'GameTooltipTemplate')
tooltip:SetOwner(WorldFrame, "ANCHOR_NONE")
local Descriptions, description = { }, nil
function getSpellDescription(spellId)
if Descriptions[spellId] then
return Descriptions[spellId]
end
tooltip:ClearLines()
tooltip:SetSpellByID(spellId)
local font
for i=4,1,-1 do
font = _G['xCT_SpellDescriptionTooltipTextLeft'..i]
if font then
break
end
end
description = font:GetText()
if description == "" then
description = "No Description"
end
Descriptions[spellId] = description
return description
end
end
-- Spammy Spell Get/Set Functions
local function SpamSpellGet(info)
local id = tonumber(info[#info])
local db = x.db.profile.spells.merge[id] or addon.defaults.profile.spells.merge[id]
return db.enabled
end
local function SpamSpellSet(info, value)
local id = tonumber(info[#info])
local db = x.db.profile.spells.merge[id] or {}
db.enabled = value
x.db.profile.spells.merge[id] = db
end
local CLASS_NAMES = {
["DEATHKNIGHT"] = {
[0] = 0, -- All Specs
[250] = 1, -- Blood
[251] = 2, -- Frost
[252] = 3, -- Unholy
},
["DEMONHUNTER"] = {
[0] = 0, -- All Specs
[577] = 1, -- Havoc
[581] = 2, -- Vengeance
},
["DRUID"] = {
[0] = 0, -- All Specs
[102] = 1, -- Balance
[103] = 2, -- Feral
[104] = 3, -- Guardian
[105] = 4, -- Restoration
},
["EVOKER"] = {
[0] = 0, -- All Specs
[1467] = 1, -- Devastation
[1468] = 2, -- Preservation
[1473] = 3, -- Augmentation
},
["HUNTER"] = {
[0] = 0, -- All Specs
[253] = 1, -- Beast Mastery
[254] = 2, -- Marksmanship
[255] = 3, -- Survival
},
["MAGE"] = {
[0] = 0, -- All Specs
[62] = 1, -- Arcane
[63] = 2, -- Fire
[64] = 3, -- Frost
},
["MONK"] = {
[0] = 0, -- All Specs
[268] = 1, -- Brewmaster
[269] = 2, -- Windwalker
[270] = 3, -- Mistweaver
},
["PALADIN"] = {
[0] = 0, -- All Specs
[65] = 1, -- Holy
[66] = 2, -- Protection
[70] = 3, -- Retribution
},
["PRIEST"] = {
[0] = 0, -- All Specs
[256] = 1, -- Discipline
[257] = 2, -- Holy
[258] = 3, -- Shadow
},
["ROGUE"] = {
[0] = 0, -- All Specs
[259] = 1, -- Assassination
[260] = 2, -- Combat
[261] = 3, -- Subtlety
},
["SHAMAN"] = {
[0] = 0, -- All Specs
[262] = 1, -- Elemental
[263] = 2, -- Enhancement
[264] = 3, -- Restoration
},
["WARLOCK"] = {
[0] = 0, -- All Specs
[265] = 1, -- Affliction
[266] = 2, -- Demonology
[267] = 3, -- Destruction
},
["WARRIOR"] = {
[0] = 0, -- All Specs
[71] = 1, -- Arms
[72] = 2, -- Fury
[73] = 3, -- Protection
},
}
function x.GenerateDefaultSpamSpells()
local defaults = addon.defaults.spells.merge
end
local function cleanColors(colorTable)
for index, color in pairs(colorTable) do
if color.colors then
cleanColors(color.colors)
else
color.color = { color.default[1], color.default[2], color.default[3] }
end
end
end
function addon.LoadDefaultColors()
for name, settings in pairs(addon.defaults.profile.frames) do
if settings.colors then
cleanColors(settings.colors)
end
end
cleanColors(addon.defaults.profile.SpellColors)
end
-- Gets spammy spells from the database and creates options
function x:UpdateSpamSpells()
--[[ Update our saved DB
for id, item in pairs(addon.merges) do
if not self.db.profile.spells.merge[id] then
self.db.profile.spells.merge[id] = item
self.db.profile.spells.merge[id]['enabled'] = true -- default all to on
else
-- update merge setting incase they are outdated
self.db.profile.spells.merge[id].interval = item.interval
self.db.profile.spells.merge[id].prep = item.prep
self.db.profile.spells.merge[id].desc = item.desc
self.db.profile.spells.merge[id].class = item.class
end
end]]
local spells = addon.options.args.spells.args.classList.args
local global = addon.options.args.spells.args.globalList.args
local racetab = addon.options.args.spells.args.raceList.args
-- Clear out the old spells
for class, specs in pairs(CLASS_NAMES) do
spells[class].args = {}
for spec, index in pairs(specs) do
local name, _ = "All Specializations"
if index ~= 0 then
_, name = GetSpecializationInfoByID(spec)
end
spells[class].args["specHeader"..index] = {
type = 'header',
order = index * 2,
name = name,
}
end
end
-- Clear out the old spells (global)
for index in pairs(global) do
global[index] = nil
end
-- Create a list of the categories (to be sorted)
local categories = {}
for _, entry in pairs(addon.merges) do
--TODO better code when i understand more the code
if not CLASS_NAMES[entry.class] and entry.desc ~= "Racial Spell" then
table.insert(categories, entry.class)
end
end
-- Show Categories in alphabetical order
table.sort(categories)
-- Assume less than 1000 entries per category ;)
local categoryOffsets = {}
for i, category in pairs(categories) do
local currentIndex = i * 1000
-- Create the Category Header
global[category] = {
type = 'description',
order = currentIndex,
name = "\n"..category,
fontSize = 'large',
}
categoryOffsets[category] = currentIndex + 1
end
------------------------------------------------------
-- Clear out the old spells (racetab)
-- Dirty add have to reform when better understanding the code
for index in pairs(racetab) do
racetab[index] = nil
end
-- Create a list of the categories (to be sorted)
local rcategories = {}
for _, entry in pairs(addon.merges) do
--TODO better code when i understand more the code
if not CLASS_NAMES[entry.class] and entry.desc == "Racial Spell" then
table.insert(rcategories, entry.class)
end
end
-- Show Categories in alphabetical order
table.sort(rcategories)
-- Assume less than 1000 entries per category ;)
local rcategoryOffsets = {}
for i, rcategory in pairs(rcategories) do
local rcurrentIndex = i * 1000
-- Create the Category Header
racetab[rcategory] = {
type = 'description',
order = rcurrentIndex,
name = "\n"..rcategory,
fontSize = 'large',
}
rcategoryOffsets[rcategory] = rcurrentIndex + 1
end
------------------------------------------------------
-- Update the UI
for spellID, entry in pairs(addon.merges) do
local name = C_Spell.GetSpellName(spellID)
if name then
--TODO better code when i understand more the code
-- Create a useful description for the spell
local spellDesc = getSpellDescription(spellID) or "No Description"
local desc = ""
if entry.desc and not CLASS_NAMES[entry.class] then
desc = "|cff9F3ED5" .. entry.desc .. "|r\n\n"
end
desc = desc .. spellDesc .. "\n\n|cffFF0000ID|r |cff798BDD" .. spellID .. "|r"
if entry.interval <= 0.5 then
desc = desc .. "\n|cffFF0000Interval|r Instant"
else
desc = desc .. "\n|cffFF0000Interval|r Merge every |cffFFFF00" .. tostring(entry.interval) .. "|r seconds"
end
-- Add the spell to the UI
if CLASS_NAMES[entry.class] then
local index = CLASS_NAMES[entry.class][tonumber(entry.desc) or 0]
spells[entry.class].args[tostring(spellID)] = {
order = index * 2 + 1,
type = 'toggle',
name = name,
desc = desc,
get = SpamSpellGet,
set = SpamSpellSet,
}
elseif entry.desc == "Racial Spell" then
racetab[tostring(spellID)] = {
order = rcategoryOffsets[entry.class],
type = 'toggle',
name = name,
desc = desc,
get = SpamSpellGet,
set = SpamSpellSet,
}
rcategoryOffsets[entry.class] = rcategoryOffsets[entry.class] + 1
else
global[tostring(spellID)] = {
order = categoryOffsets[entry.class],
type = 'toggle',
name = name,
desc = desc,
get = SpamSpellGet,
set = SpamSpellSet,
}
categoryOffsets[entry.class] = categoryOffsets[entry.class] + 1
end
end
end
end
local function ItemToggleAll(info)
local state = (info[#info] == "disableAll")
for key in pairs(x.db.profile.spells.items[info[#info-1]]) do
x.db.profile.spells.items[info[#info-1]][key] = state
end
end
local function getIF_1(info) return x.db.profile.spells.items[info[#info - 1]][info[#info]] end
local function setIF_1(info, value) x.db.profile.spells.items[info[#info - 1]][info[#info]] = value end
local function getIF_2(info) return x.db.profile.spells.items[info[#info - 1]][info[#info - 1]] end
local function setIF_2(info, value) x.db.profile.spells.items[info[#info - 1]][info[#info - 1]] = value end
-- For Legion - Reimplement legacy GetAuctionItemClasses and GetAuctionItemSubClasses
-- TODO: Figure out how to list all items in Legion
--[[if build >= 70000 then
function GetAuctionItemClasses()
local list = {}
for i, v in pairs(OPEN_FILTER_LIST) do
if v.type == "category" then
list[v.categoryIndex] = v.name
end
end
return list
end
function GetAuctionItemSubClasses(index)
local list, found = {}
for i, v in pairs(OPEN_FILTER_LIST) do
if v.type == "category" then
if found then break end
if v.categoryIndex == index then
found = 1
end
elseif v.type == "subCategory" then
if found then
list[v.subCategoryIndex] = v.name
end
end
end
return list
end
end]]
x.UpdateItemTypes = function(self)end
--[===[
-- Updates item filter list
function x:UpdateItemTypes()
-- check to see if this is the first time we are loading this version
local first = false
if not self.db.profile.spells.items.version then
self.db.profile.spells.items.version = 1
first = true
end
local itemTypes = { GetAuctionItemClasses() }
local allTypes = {
order = 100,
name = "|cffFFFFFFFilter:|r |cff798BDDLoot|r",
type = 'group',
childGroups = "select",
args = {
secondaryFrame = {
type = 'description',
order = 0,
name = "These options allow you to bypass the loot item filter and always show a item from any category, reguardless of the quality.\n",
},
},
}
for i, itype in ipairs(itemTypes) do
local subtypes = { GetAuctionItemSubClasses(i) }
if self.db.profile.spells.items[itype] == nil then
self.db.profile.spells.items[itype] = { }
end
-- Page for the MAIN ITEM GROUP
local group = {
order = i,
name = itype,
type = 'group',
args = { },
}
-- the footer for the current MAIN ITEM GROUP
if #subtypes > 0 then
-- Separator for the TOP toggle switches, and the BOTTOM enable/disable buttons
group.args['enableHeader'] = {
order = 100,
type = 'header',
name = "",
width = "full",
}
-- Button to DISABLE all
group.args['disableAll'] = {
order = 101,
type = 'execute',
name = "|cffDDDD00Enable All|r",
--width = "half",
func = ItemToggleAll,
}
-- Button to ENABLE all
group.args['enableAll'] = {
order = 102,
type = 'execute',
name = "|cffDD0000Disable All|r",
--width = "half",
func = ItemToggleAll,
}
else
-- Quest Items... maybe others
if first or self.db.profile.spells.items[itype][itype] == nil then
self.db.profile.spells.items[itype][itype] = false
end
group.args[itype] = {
order = 1,
type = 'toggle',
name = "Enable",
get = getIF_2,
set = setIF_2,
}
end
-- add all the SUBITEMS
for j, subtype in ipairs(subtypes) do
if first or self.db.profile.spells.items[itype][subtype] == nil then
self.db.profile.spells.items[itype][subtype] = false
end
group.args[subtype] = {
order = j,
type = 'toggle',
name = subtype,
get = getIF_1, --function(info) return self.db.profile.spells.items[itype][subtype] end,
set = setIF_1, --function(info, value) self.db.profile.spells.items[itype][subtype] = value end,
}
end
allTypes.args[itype] = group
end
addon.options.args["spellFilter"].args["typeFilter"] = allTypes
end
]===]
local function getCP_1(info) return x.db.profile.spells.combo[x.player.class][info[#info]] end
local function setCP_1(info, value) x.db.profile.spells.combo[x.player.class][info[#info]] = value end
local function getCP_2(info)
local spec, index = string_match(info[#info], "(%d+),(.+)")
local value = x.db.profile.spells.combo[x.player.class][tonumber(spec)][tonumber(index) or index]
if type(value) == "table" then
return value.enabled
else
return value
end
end
local function setCP_2(info, value)
local spec, index = string_match(info[#info], "(%d+),(.+)")
if value == true then
for key, entry in pairs(x.db.profile.spells.combo[x.player.class][tonumber(spec)]) do
if type(entry) == "table" then
entry.enabled = false
else
x.db.profile.spells.combo[x.player.class][tonumber(spec)][key] = false
end
end
end
if tonumber(index) then -- it is a spell ID
x.db.profile.spells.combo[x.player.class][tonumber(spec)][tonumber(index)].enabled = value
else -- it is a unit's power
x.db.profile.spells.combo[x.player.class][tonumber(spec)][index] = value
end
-- Update tracker
x:UpdateComboTracker()
end
-- Update the combo point list
function x:UpdateComboPointOptions(force)
if x.LOADED_COMBO_POINTS_OPTIONS and not force then return end
local myClass, offset = x.player.class, 2
local comboSpells = {
order = 100,
name = "Misc",
type = 'group',
args = {
specialTweaks = {
type = 'description',
order = 0,
name = "|cff798BDDMiscellaneous Settings|r:",
fontSize = 'large',
},
specialTweaksDesc = {
type = 'description',
order = 1,
name = "|cffFFFFFF(Choose one per specialization)|r\n",
fontSize = 'small',
},
},
}
-- Add "All Specializations" Entries
for name in pairs(x.db.profile.spells.combo[myClass]) do
if not tonumber(name) then
if not comboSpells.args['allSpecsHeader'] then
comboSpells.args['allSpecsHeader'] = {
order = 2,
type = 'header',
name = "All Specializations",
width = "full",
}
end
comboSpells.args[name] = {
order = offset,
type = 'toggle',
name = name,
get = getCP_1,
set = setCP_1,
}
offset = offset + 1
end
end
-- Add the each spec
for spec in ipairs(x.db.profile.spells.combo[myClass]) do
local haveSpec = false
for index, entry in pairs(x.db.profile.spells.combo[myClass][spec] or { }) do
if not haveSpec then
haveSpec = true
local mySpecName = select(2, GetSpecializationInfo(spec)) or "Tree " .. spec
comboSpells.args["title" .. tostring(spec)] = {
order = offset,
type = 'header',
name = "Specialization: |cff798BDD" .. mySpecName .. "|r",
width = "full",
}
offset = offset + 1
end
if tonumber(index) then
-- Class Combo Points ( UNIT_AURA Tracking)
comboSpells.args[tostring(spec) .. "," .. tostring(index)] = {
order = offset,
type = 'toggle',
name = C_Spell.GetSpellName(entry.id),
desc = "Unit to track: |cffFF0000" .. entry.unit .. "|r\nSpell ID: |cffFF0000" .. entry.id .. "|r",
get = getCP_2,
set = setCP_2,
}
else
-- Special Combo Point ( Unit Power )
comboSpells.args[tostring(spec) .. "," .. tostring(index)] = {
order = offset,
type = 'toggle',
name = index,
desc = "Unit Power",
get = getCP_2,
set = setCP_2,
}
end
offset = offset + 1
end
end
addon.options.args["Frames"].args["class"].args["tracker"] = comboSpells
x.LOADED_COMBO_POINTS_OPTIONS = true
x:UpdateComboTracker()
end
function x:UpdateComboTracker()
local myClass, mySpec = x.player.class, x.player.spec
x.TrackingEntry = nil
if not mySpec or mySpec < 1 or mySpec > 4 then return end -- under Level 10 return 5
for i, entry in pairs(x.db.profile.spells.combo[myClass][mySpec]) do
if type(entry) == "table" and entry.enabled then
x.TrackingEntry = entry
end
end
x:QuickClassFrameUpdate()
end
-- Get and set methods for the spell filter
local function getSF(info)
return x.db.profile.spellFilter[info[#info-2]][info[#info]]
end
local function setSF(info, value) x.db.profile.spellFilter[info[#info-2]][info[#info]] = value end
-- Update the Buff, Debuff and Spell filter list
function x:UpdateAuraSpellFilter(specific)
local i = 10
if not specific or specific == "buffs" then
-- Redo all the list