forked from enderneko/Cell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCore.lua
901 lines (806 loc) · 34.8 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
local addonName, Cell = ...
_G.Cell = Cell
Cell.defaults = {}
Cell.frames = {}
Cell.vars = {}
Cell.snippetVars = {}
Cell.funcs = {}
Cell.iFuncs = {}
Cell.bFuncs = {}
Cell.uFuncs = {}
Cell.animations = {}
local F = Cell.funcs
local I = Cell.iFuncs
local P = Cell.pixelPerfectFuncs
local L = Cell.L
-- sharing version check
Cell.MIN_VERSION = 189
Cell.MIN_CLICKCASTINGS_VERSION = 189
Cell.MIN_LAYOUTS_VERSION = 203
Cell.MIN_INDICATORS_VERSION = 203
Cell.MIN_DEBUFFS_VERSION = 189
--@debug@
local debugMode = true
--@end-debug@
function F:Debug(arg, ...)
if debugMode then
if type(arg) == "string" or type(arg) == "number" then
print(arg, ...)
elseif type(arg) == "function" then
arg(...)
elseif arg == nil then
return true
end
end
end
function F:Print(msg)
print("|cFFFF3030[Cell]|r " .. msg)
end
local IsInRaid = IsInRaid
local IsInGroup = IsInGroup
local GetNumGroupMembers = GetNumGroupMembers
local GetRaidRosterInfo = GetRaidRosterInfo
local UnitGUID = UnitGUID
-- local IsInBattleGround = C_PvP.IsBattleground -- NOTE: can't get valid value immediately after PLAYER_ENTERING_WORLD
-------------------------------------------------
-- layout
-------------------------------------------------
local delayedLayoutGroupType, delayedUpdateIndicators
local delayedFrame = CreateFrame("Frame")
delayedFrame:SetScript("OnEvent", function()
delayedFrame:UnregisterEvent("PLAYER_REGEN_ENABLED")
F:UpdateLayout(delayedLayoutGroupType, delayedUpdateIndicators)
end)
function F:UpdateLayout(layoutGroupType, updateIndicators)
if InCombatLockdown() then
F:Debug("|cFF7CFC00F:UpdateLayout(\""..layoutGroupType.."\") DELAYED")
delayedLayoutGroupType, delayedUpdateIndicators = layoutGroupType, updateIndicators
delayedFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
else
F:Debug("|cFF7CFC00F:UpdateLayout(\""..layoutGroupType.."\")")
local layout
if Cell.vars.layoutAutoSwitch[Cell.vars.playerSpecID] then
layout = Cell.vars.layoutAutoSwitch[Cell.vars.playerSpecID][layoutGroupType]
else
layout = Cell.vars.layoutAutoSwitch[Cell.vars.playerSpecRole][layoutGroupType]
end
Cell.vars.currentLayout = layout
Cell.vars.currentLayoutTable = CellDB["layouts"][layout]
Cell.vars.layoutGroupType = layoutGroupType
Cell:Fire("UpdateLayout", Cell.vars.currentLayout)
if updateIndicators then
Cell:Fire("UpdateIndicators")
end
end
end
local bgMaxPlayers = {
[2197] = 40, -- 科尔拉克的复仇
}
-- layout auto switch
local instanceType
local function PreUpdateLayout()
if not Cell.vars.playerSpecRole then return end
if instanceType == "pvp" then
local name, _, _, _, _, _, _, id = GetInstanceInfo()
if bgMaxPlayers[id] then
if bgMaxPlayers[id] <= 15 then
Cell.vars.inBattleground = 15
F:UpdateLayout("battleground15", true)
else
Cell.vars.inBattleground = 40
F:UpdateLayout("battleground40", true)
end
else
Cell.vars.inBattleground = 15
F:UpdateLayout("battleground15", true)
end
elseif instanceType == "arena" then
Cell.vars.inBattleground = 5 -- treat as bg 5
F:UpdateLayout("arena", true)
else
Cell.vars.inBattleground = false
if Cell.vars.groupType == "solo" or Cell.vars.groupType == "party" then
F:UpdateLayout("party", true)
else -- raid
if Cell.vars.inMythic then
F:UpdateLayout("raid_mythic", true)
elseif Cell.vars.inInstance then
F:UpdateLayout("raid_instance", true)
else
F:UpdateLayout("raid_outdoor", true)
end
end
end
end
Cell:RegisterCallback("GroupTypeChanged", "Core_GroupTypeChanged", PreUpdateLayout)
Cell:RegisterCallback("SpecChanged", "Core_SpecChanged", PreUpdateLayout)
Cell:RegisterCallback("LayoutAutoSwitchChanged", "Core_LayoutAutoSwitchChanged", PreUpdateLayout)
-------------------------------------------------
-- events
-------------------------------------------------
local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("VARIABLES_LOADED")
eventFrame:RegisterEvent("ADDON_LOADED")
eventFrame:RegisterEvent("PLAYER_LOGIN")
eventFrame:RegisterEvent("LOADING_SCREEN_ENABLED")
function eventFrame:LOADING_SCREEN_ENABLED()
if not InCombatLockdown() and not UnitAffectingCombat("player") then
F:Debug("|cffff7777collectgarbage")
collectgarbage("collect")
end
end
function eventFrame:VARIABLES_LOADED()
SetCVar("predictedHealth", 1)
end
local GetAddOnMetadata = C_AddOns and C_AddOns.GetAddOnMetadata or GetAddOnMetadata
-- local cellLoaded, omnicdLoaded
function eventFrame:ADDON_LOADED(arg1)
if arg1 == addonName then
-- cellLoaded = true
eventFrame:UnregisterEvent("ADDON_LOADED")
if type(CellDB) ~= "table" then CellDB = {} end
if type(CellDB["optionsFramePosition"]) ~= "table" then CellDB["optionsFramePosition"] = {} end
if type(CellDB["indicatorPreviewAlpha"]) ~= "number" then CellDB["indicatorPreviewAlpha"] = 0.5 end
if type(CellDB["indicatorPreviewScale"]) ~= "number" then CellDB["indicatorPreviewScale"] = 1 end
if type(CellDB["customTextures"]) ~= "table" then CellDB["customTextures"] = {} end
if type(CellDB["snippets"]) ~= "table" then CellDB["snippets"] = {} end
if not CellDB["snippets"][0] then CellDB["snippets"][0] = F:GetDefaultSnippet() end
Cell.vars.playerClass, Cell.vars.playerClassID = UnitClassBase("player")
-- general --------------------------------------------------------------------------------
if type(CellDB["general"]) ~= "table" then
CellDB["general"] = {
["enableTooltips"] = false,
["hideTooltipsInCombat"] = true,
["tooltipsPosition"] = {"BOTTOMLEFT", "Default", "TOPLEFT", 0, 15},
["showSolo"] = true,
["showParty"] = true,
["hideBlizzardParty"] = true,
["hideBlizzardRaid"] = true,
["locked"] = false,
["fadeOut"] = false,
["menuPosition"] = "top_bottom",
["alwaysUpdateBuffs"] = false,
["alwaysUpdateDebuffs"] = false,
["overrideLGF"] = false,
["framePriority"] = "normal_spotlight",
["useCleuHealthUpdater"] = false,
["translit"] = false,
}
end
-- nicknames ------------------------------------------------------------------------------
if type(CellDB["nicknames"]) ~= "table" then
CellDB["nicknames"] = {
["mine"] = "",
["sync"] = false,
["custom"] = false,
["list"] = {},
}
end
-- tools ----------------------------------------------------------------------------------
if type(CellDB["tools"]) ~= "table" then
CellDB["tools"] = {
["showBattleRes"] = true,
["buffTracker"] = {false, "left-to-right", 32, {}},
["deathReport"] = {false, 10},
["readyAndPull"] = {false, "text_button", {"default", 7}, {}},
["marks"] = {false, false, "both_h", {}},
["fadeOut"] = false,
}
end
-- spellRequest ---------------------------------------------------------------------------
if type(CellDB["spellRequest"]) ~= "table" then
local POWER_INFUSION, _, POWER_INFUSION_ICON = GetSpellInfo(10060)
local INNERVATE, _, INNERVATE_ICON = GetSpellInfo(29166)
CellDB["spellRequest"] = {
["enabled"] = false,
["checkIfExists"] = true,
["knownSpellsOnly"] = true,
["freeCooldownOnly"] = true,
["replyCooldown"] = true,
["responseType"] = "me",
["timeout"] = 10,
-- ["replyAfterCast"] = nil,
["sharedIconOptions"] = {
"beat", -- [1] animation
27, -- [2] size
"BOTTOMRIGHT", -- [3] anchor
"BOTTOMRIGHT", -- [4] anchorTo
0, -- [5] x
0, -- [6] y
},
["spells"] = {
{
["spellId"] = 10060,
["buffId"] = 10060,
["keywords"] = POWER_INFUSION,
["icon"] = POWER_INFUSION_ICON,
["type"] = "icon",
["iconColor"] = {1, 1, 0, 1},
["glowOptions"] = {
"pixel", -- [1] glow type
{
{1,1,0,1}, -- [1] color
0, -- [2] x
0, -- [3] y
9, -- [4] N
0.25, -- [5] frequency
8, -- [6] length
2 -- [7] thickness
} -- [2] glowOptions
},
["isBuiltIn"] = true
},
{
["spellId"] = 29166,
["buffId"] = 29166,
["keywords"] = INNERVATE,
["icon"] = INNERVATE_ICON,
["type"] = "icon",
["iconColor"] = {0, 1, 1, 1},
["glowOptions"] = {
"pixel", -- [1] glow type
{
{0, 1, 1, 1}, -- [1] color
0, -- [2] x
0, -- [3] y
9, -- [4] N
0.25, -- [5] frequency
8, -- [6] length
2 -- [7] thickness
} -- [2] glowOptions
},
["isBuiltIn"] = true
},
},
}
end
-- dispelRequest --------------------------------------------------------------------------
if type(CellDB["dispelRequest"]) ~= "table" then
CellDB["dispelRequest"] = {
["enabled"] = false,
["dispellableByMe"] = true,
["responseType"] = "all",
["timeout"] = 10,
["debuffs"] = {},
["type"] = "text",
["textOptions"] = {
"A",
{1, 0, 0, 1}, -- [1] color
32, -- [2] size
"TOPLEFT", -- [3] anchor
"TOPLEFT", -- [4] anchorTo
-1, -- [5] x
5, -- [6] y
},
["glowOptions"] = {
"shine", -- [1] glow type
{
{1, 0, 0.4, 1}, -- [1] color
0, -- [2] x
0, -- [3] y
9, -- [4] N
0.5, -- [5] frequency
2, -- [6] scale
} -- [2] glowOptions
}
}
end
-- quickCast ------------------------------------------------------------------------------
if type(CellDB["quickCast"]) ~= "table" then CellDB["quickCast"] = {} end
-- remove unused quick cast table
for c, ct in pairs(CellDB["quickCast"]) do
for s, st in pairs(ct) do
if not st["enabled"] and st["outerBuff"] == 0 and st["innerBuff"] == 0 then
ct[s] = nil
end
end
if F:Getn(ct) == 0 then
CellDB["quickCast"][c] = nil
end
end
-- appearance -----------------------------------------------------------------------------
if type(CellDB["appearance"]) ~= "table" then
-- get recommended scale
local pScale = P:GetPixelPerfectScale()
local scale
if pScale >= 0.7 then
scale = 1
elseif pScale >= 0.5 then
scale = 1.4
else
scale = 2
end
CellDB["appearance"] = F:Copy(Cell.defaults.appearance)
-- update recommended scale
CellDB["appearance"]["scale"] = scale
end
P:SetRelativeScale(CellDB["appearance"]["scale"])
-- color ---------------------------------------------------------------------------------
if CellDB["appearance"]["accentColor"] then -- version < r103
if CellDB["appearance"]["accentColor"][1] == "custom" then
Cell:OverrideAccentColor(CellDB["appearance"]["accentColor"][2])
end
end
-- click-casting --------------------------------------------------------------------------
if type(CellDB["clickCastings"]) ~= "table" then CellDB["clickCastings"] = {} end
if type(CellDB["clickCastings"][Cell.vars.playerClass]) ~= "table" then
CellDB["clickCastings"][Cell.vars.playerClass] = {
["useCommon"] = true,
["smartResurrection"] = "disabled",
["alwaysTargeting"] = {
["common"] = "disabled",
},
["common"] = {
{"type1", "target"},
{"type2", "togglemenu"},
},
}
-- add resurrections for "common"
for _, t in pairs(F:GetResurrectionClickCastings(Cell.vars.playerClass)) do
tinsert(CellDB["clickCastings"][Cell.vars.playerClass]["common"], t)
end
-- https://wow.gamepedia.com/SpecializationID
local indices = {}
for i = 1, GetNumSpecializationsForClassID(Cell.vars.playerClassID) do
tinsert(indices, i)
end
tinsert(indices, 5) -- "Initials" (no spec)
for _, sepcIndex in pairs(indices) do
local specID = GetSpecializationInfoForClassID(Cell.vars.playerClassID, sepcIndex)
CellDB["clickCastings"][Cell.vars.playerClass]["alwaysTargeting"][specID] = "disabled"
CellDB["clickCastings"][Cell.vars.playerClass][specID] = {
{"type1", "target"},
{"type2", "togglemenu"},
}
-- add resurrections for each spec
for _, t in pairs(F:GetResurrectionClickCastings(Cell.vars.playerClass)) do
tinsert(CellDB["clickCastings"][Cell.vars.playerClass][specID], t)
end
end
end
Cell.vars.clickCastings = CellDB["clickCastings"][Cell.vars.playerClass]
-- layouts --------------------------------------------------------------------------------
if type(CellDB["layouts"]) ~= "table" then
CellDB["layouts"] = {
["default"] = F:Copy(Cell.defaults.layout)
}
end
-- init enabled layout
if type(CellDB["layoutAutoSwitch"]) ~= "table" then
CellDB["layoutAutoSwitch"] = {
["TANK"] = {
["party"] = "default",
["raid_outdoor"] = "default",
["raid_instance"] = "default",
["raid_mythic"] = "default",
["arena"] = "default",
["battleground15"] = "default",
["battleground40"] = "default",
},
["HEALER"] = {
["party"] = "default",
["raid_outdoor"] = "default",
["raid_instance"] = "default",
["raid_mythic"] = "default",
["arena"] = "default",
["battleground15"] = "default",
["battleground40"] = "default",
},
["DAMAGER"] = {
["party"] = "default",
["raid_outdoor"] = "default",
["raid_instance"] = "default",
["raid_mythic"] = "default",
["arena"] = "default",
["battleground15"] = "default",
["battleground40"] = "default",
},
}
end
-- validate layout
for role, t in pairs(CellDB["layoutAutoSwitch"]) do
for groupType, layout in pairs(t) do
if not CellDB["layouts"][layout] then
CellDB["layoutAutoSwitch"][role][groupType] = "default"
end
end
end
Cell.vars.layoutAutoSwitch = CellDB["layoutAutoSwitch"]
-- dispelBlacklist ------------------------------------------------------------------------
if type(CellDB["dispelBlacklist"]) ~= "table" then
CellDB["dispelBlacklist"] = I:GetDefaultDispelBlacklist()
end
Cell.vars.dispelBlacklist = F:ConvertTable(CellDB["dispelBlacklist"])
-- debuffBlacklist ------------------------------------------------------------------------
if type(CellDB["debuffBlacklist"]) ~= "table" then
CellDB["debuffBlacklist"] = I:GetDefaultDebuffBlacklist()
end
Cell.vars.debuffBlacklist = F:ConvertTable(CellDB["debuffBlacklist"])
-- bigDebuffs -----------------------------------------------------------------------------
if type(CellDB["bigDebuffs"]) ~= "table" then
CellDB["bigDebuffs"] = I:GetDefaultBigDebuffs()
end
Cell.vars.bigDebuffs = F:ConvertTable(CellDB["bigDebuffs"])
-- debuffTypeColor -----------------------------------------------------------------------------
if type(CellDB["debuffTypeColor"]) ~= "table" then
I:ResetDebuffTypeColor()
end
-- defensives/externals -------------------------------------------------------------------
if type(CellDB["defensives"]) ~= "table" then CellDB["defensives"] = {["disabled"]={}, ["custom"]={}} end
if type(CellDB["externals"]) ~= "table" then CellDB["externals"] = {["disabled"]={}, ["custom"]={}} end
-- raid debuffs ---------------------------------------------------------------------------
if type(CellDB["raidDebuffs"]) ~= "table" then CellDB["raidDebuffs"] = {} end
-- CellDB["raidDebuffs"] = {
-- [instanceId] = {
-- ["general"] = {
-- [spellId] = {order, glowType, glowColor},
-- },
-- [bossId] = {
-- [spellId] = {order, glowType, glowColor},
-- },
-- }
-- }
-- if type(CellDB["cleuAuras"]) ~= "table" then CellDB["cleuAuras"] = {} end
-- I:UpdateCleuAuras(CellDB["cleuAuras"])
-- if type(CellDB["cleuGlow"]) ~= "table" then
-- CellDB["cleuGlow"] = {"Pixel", {{0, 1, 1, 1}, 9, 0.25, 8, 2}}
-- end
-- targetedSpells -------------------------------------------------------------------------
if type(CellDB["targetedSpellsList"]) ~= "table" then
CellDB["targetedSpellsList"] = I:GetDefaultTargetedSpellsList()
end
Cell.vars.targetedSpellsList = F:ConvertTable(CellDB["targetedSpellsList"])
if type(CellDB["targetedSpellsGlow"]) ~= "table" then
CellDB["targetedSpellsGlow"] = I:GetDefaultTargetedSpellsGlow()
end
Cell.vars.targetedSpellsGlow = CellDB["targetedSpellsGlow"]
-- crowdControls --------------------------------------------------------------------------
if type(CellDB["crowdControls"]) ~= "table" then CellDB["crowdControls"] = {["disabled"]={}, ["custom"]={}} end
-- consumables ----------------------------------------------------------------------------
if type(CellDB["consumables"]) ~= "table" then
CellDB["consumables"] = I:GetDefaultConsumables()
end
Cell.vars.consumables = I:ConvertConsumables(CellDB["consumables"])
-- misc -----------------------------------------------------------------------------------
Cell.version = GetAddOnMetadata(addonName, "version")
Cell.versionNum = tonumber(string.match(Cell.version, "%d+"))
if not CellDB["revise"] then CellDB["firstRun"] = true end
F:Revise()
F:CheckWhatsNew()
F:RunSnippets()
Cell.loaded = true
end
-- omnicd -------------------------------------------------------------------------------------
-- if arg1 == "OmniCD" then
-- omnicdLoaded = true
-- local E = OmniCD[1]
-- tinsert(E.unitFrameData, 1, {
-- [1] = "Cell",
-- [2] = "CellPartyFrameMember",
-- [3] = "unitid",
-- [4] = 1,
-- })
-- local function UnitFrames()
-- if not E.customUF.optionTable.Cell then
-- E.customUF.optionTable.Cell = "Cell"
-- E.customUF.optionTable.enabled.Cell = {
-- ["delay"] = 1,
-- ["frame"] = "CellPartyFrameMember",
-- ["unit"] = "unitid",
-- }
-- end
-- end
-- hooksecurefunc(E, "UnitFrames", UnitFrames)
-- end
-- if cellLoaded and omnicdLoaded then
-- eventFrame:UnregisterEvent("ADDON_LOADED")
-- end
end
Cell.vars.raidSetup = {
["TANK"]={["ALL"]=0},
["HEALER"]={["ALL"]=0},
["DAMAGER"]={["ALL"]=0},
}
function eventFrame:GROUP_ROSTER_UPDATE()
if IsInRaid() then
if Cell.vars.groupType ~= "raid" then
Cell.vars.groupType = "raid"
F:Debug("|cffffbb77GroupTypeChanged:|r raid")
Cell:Fire("GroupTypeChanged", "raid")
end
-- reset raid setup
for _, t in pairs(Cell.vars.raidSetup) do
for class in pairs(t) do
if class == "ALL" then
t["ALL"] = 0
else
t[class] = nil
end
end
end
-- update guid & raid setup
for i = 1, GetNumGroupMembers() do
-- update raid setup
local _, _, _, _, _, class, _, _, _, _, _, role = GetRaidRosterInfo(i)
if not role or role == "NONE" then role = "DAMAGER" end
-- update ALL
Cell.vars.raidSetup[role]["ALL"] = Cell.vars.raidSetup[role]["ALL"] + 1
-- update for each class
if class then
if not Cell.vars.raidSetup[role][class] then
Cell.vars.raidSetup[role][class] = 1
else
Cell.vars.raidSetup[role][class] = Cell.vars.raidSetup[role][class] + 1
end
end
end
-- update Cell.unitButtons.raid.units
for i = GetNumGroupMembers()+1, 40 do
Cell.unitButtons.raid.units["raid"..i] = nil
_G["CellRaidFrameMember"..i] = nil
end
F:UpdateRaidSetup()
-- update Cell.unitButtons.party.units
Cell.unitButtons.party.units["player"] = nil
Cell.unitButtons.party.units["pet"] = nil
for i = 1, 4 do
Cell.unitButtons.party.units["party"..i] = nil
Cell.unitButtons.party.units["partypet"..i] = nil
end
elseif IsInGroup() then
if Cell.vars.groupType ~= "party" then
Cell.vars.groupType = "party"
F:Debug("|cffffbb77GroupTypeChanged:|r party")
Cell:Fire("GroupTypeChanged", "party")
end
-- update Cell.unitButtons.raid.units
for i = 1, 40 do
Cell.unitButtons.raid.units["raid"..i] = nil
_G["CellRaidFrameMember"..i] = nil
end
-- update Cell.unitButtons.party.units
for i = GetNumGroupMembers(), 4 do
Cell.unitButtons.party.units["party"..i] = nil
Cell.unitButtons.party.units["partypet"..i] = nil
end
else
if Cell.vars.groupType ~= "solo" then
Cell.vars.groupType = "solo"
F:Debug("|cffffbb77GroupTypeChanged:|r solo")
Cell:Fire("GroupTypeChanged", "solo")
end
-- update Cell.unitButtons.raid.units
for i = 1, 40 do
Cell.unitButtons.raid.units["raid"..i] = nil
_G["CellRaidFrameMember"..i] = nil
end
-- update Cell.unitButtons.party.units
Cell.unitButtons.party.units["player"] = nil
Cell.unitButtons.party.units["pet"] = nil
for i = 1, 4 do
Cell.unitButtons.party.units["party"..i] = nil
Cell.unitButtons.party.units["partypet"..i] = nil
end
end
if Cell.vars.hasPermission ~= F:HasPermission() or Cell.vars.hasPartyMarkPermission ~= F:HasPermission(true) then
Cell.vars.hasPermission = F:HasPermission()
Cell.vars.hasPartyMarkPermission = F:HasPermission(true)
Cell:Fire("PermissionChanged")
F:Debug("|cffbb00bbPermissionChanged")
end
end
local inInstance
function eventFrame:PLAYER_ENTERING_WORLD()
-- eventFrame:UnregisterEvent("PLAYER_ENTERING_WORLD")
F:Debug("PLAYER_ENTERING_WORLD")
Cell.vars.inMythic = false
local isIn, iType = IsInInstance()
instanceType = iType
Cell.vars.inInstance = isIn
if isIn then
F:Debug("|cffff1111Entered Instance:|r", iType)
Cell:Fire("EnterInstance", iType)
PreUpdateLayout()
inInstance = true
-- NOTE: delayed check mythic raid
if Cell.vars.groupType == "raid" and iType == "raid" then
C_Timer.After(0.5, function()
local difficultyID, difficultyName = select(3, GetInstanceInfo()) --! can't get difficultyID, difficultyName immediately after entering an instance
Cell.vars.inMythic = difficultyID == 16
if Cell.vars.inMythic then
PreUpdateLayout()
end
end)
end
elseif inInstance then -- left insntance
F:Debug("|cffff1111Left Instance|r")
Cell:Fire("LeaveInstance")
PreUpdateLayout()
inInstance = false
end
if CellDB["firstRun"] then
F:FirstRun()
end
end
local prevSpec
function eventFrame:PLAYER_LOGIN()
F:Debug("PLAYER_LOGIN")
eventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
eventFrame:RegisterEvent("GROUP_ROSTER_UPDATE")
eventFrame:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
eventFrame:RegisterEvent("UI_SCALE_CHANGED")
Cell.vars.playerNameShort = GetUnitName("player")
Cell.vars.playerNameFull = F:UnitFullName("player")
--! init bgMaxPlayers
for i = 1, GetNumBattlegroundTypes() do
local bgName, _, _, _, _, _, bgId, maxPlayers = GetBattlegroundInfo(i)
bgMaxPlayers[bgId] = maxPlayers
end
if not prevSpec then prevSpec = GetSpecialization() end
Cell.vars.playerGUID = UnitGUID("player")
-- update spec vars
Cell.vars.playerSpecID, Cell.vars.playerSpecName, _, Cell.vars.playerSpecIcon, Cell.vars.playerSpecRole = GetSpecializationInfo(prevSpec)
--! init Cell.vars.currentLayout and Cell.vars.currentLayoutTable
eventFrame:GROUP_ROSTER_UPDATE()
-- update visibility
Cell:Fire("UpdateVisibility")
-- update click-castings
Cell:Fire("UpdateClickCastings")
-- update indicators
-- Cell:Fire("UpdateIndicators") -- NOTE: already update in GROUP_ROSTER_UPDATE -> GroupTypeChanged -> F:UpdateLayout
-- update texture and font
Cell:Fire("UpdateAppearance")
Cell:UpdateOptionsFont(CellDB["appearance"]["optionsFontSizeOffset"], CellDB["appearance"]["useGameFont"])
Cell:UpdateAboutFont(CellDB["appearance"]["optionsFontSizeOffset"])
-- update tools
Cell:Fire("UpdateTools")
-- update requests
Cell:Fire("UpdateRequests")
-- update quick cast
Cell:Fire("UpdateQuickCast")
-- update raid debuff list
Cell:Fire("UpdateRaidDebuffs")
-- hide blizzard
if CellDB["general"]["hideBlizzardParty"] then F:HideBlizzardParty() end
if CellDB["general"]["hideBlizzardRaid"] then F:HideBlizzardRaid() end
-- lock & menu
Cell:Fire("UpdateMenu")
-- update CLEU health
Cell:Fire("UpdateCLEU")
-- update builtIns and customs
I:UpdateDefensives(CellDB["defensives"])
I:UpdateExternals(CellDB["externals"])
I:UpdateCrowdControls(CellDB["crowdControls"])
-- update pixel perfect
Cell:Fire("UpdatePixelPerfect")
-- overrideLGF
F:OverrideLGF(CellDB["general"]["overrideLGF"])
end
function eventFrame:UI_SCALE_CHANGED()
if not InCombatLockdown() then
F:Debug("UI_SCALE_CHANGED: ", "effectiveScale:", P:GetEffectiveScale(), "uiScale:", UIParent:GetScale())
Cell:Fire("UpdatePixelPerfect")
Cell:Fire("UpdateAppearance", "scale")
PreUpdateLayout()
end
end
local forceRecheck
local checkSpecFrame = CreateFrame("Frame")
checkSpecFrame:SetScript("OnEvent", function()
eventFrame:ACTIVE_TALENT_GROUP_CHANGED()
end)
-- PLAYER_SPECIALIZATION_CHANGED fires when level up, ACTIVE_TALENT_GROUP_CHANGED usually fire twice.
-- NOTE: ACTIVE_TALENT_GROUP_CHANGED fires before PLAYER_LOGIN, but can't GetSpecializationInfo before PLAYER_LOGIN
function eventFrame:ACTIVE_TALENT_GROUP_CHANGED()
F:Debug("ACTIVE_TALENT_GROUP_CHANGED")
-- not in combat & spec CHANGED
if not InCombatLockdown() and (prevSpec and prevSpec ~= GetSpecialization() or forceRecheck) then
prevSpec = GetSpecialization()
-- update spec vars
Cell.vars.playerSpecID, Cell.vars.playerSpecName, _, Cell.vars.playerSpecIcon, Cell.vars.playerSpecRole = GetSpecializationInfo(prevSpec)
if not Cell.vars.playerSpecID then -- NOTE: when join in battleground, spec auto switched, during loading, can't get info from GetSpecializationInfo, until PLAYER_ENTERING_WORLD
forceRecheck = true
checkSpecFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
F:Debug("|cffffbb77SpecChanged:|r FAILED")
else
forceRecheck = false
checkSpecFrame:UnregisterEvent("PLAYER_ENTERING_WORLD")
if not CellDB["clickCastings"][Cell.vars.playerClass]["useCommon"] then
Cell:Fire("UpdateClickCastings")
end
F:Debug("|cffffbb77SpecChanged:|r", Cell.vars.playerSpecRole)
Cell:Fire("SpecChanged", Cell.vars.playerSpecRole)
end
end
end
eventFrame:SetScript("OnEvent", function(self, event, ...)
self[event](self, ...)
end)
-------------------------------------------------
-- slash command
-------------------------------------------------
SLASH_CELL1 = "/cell"
function SlashCmdList.CELL(msg, editbox)
local command, rest = msg:match("^(%S*)%s*(.-)$")
if command == "options" or command == "opt" then
F:ShowOptionsFrame()
elseif command == "healers" then
F:FirstRun()
elseif command == "reset" then
if rest == "position" then
Cell.frames.anchorFrame:ClearAllPoints()
Cell.frames.anchorFrame:SetPoint("TOPLEFT", UIParent, "CENTER")
Cell.vars.currentLayoutTable["position"] = {}
P:ClearPoints(Cell.frames.readyAndPullFrame)
Cell.frames.readyAndPullFrame:SetPoint("TOPRIGHT", UIParent, "CENTER")
CellDB["tools"]["readyAndPull"][4] = {}
P:ClearPoints(Cell.frames.raidMarksFrame)
Cell.frames.raidMarksFrame:SetPoint("BOTTOMRIGHT", UIParent, "CENTER")
CellDB["tools"]["marks"][4] = {}
P:ClearPoints(Cell.frames.buffTrackerFrame)
Cell.frames.buffTrackerFrame:SetPoint("BOTTOMLEFT", UIParent, "CENTER")
CellDB["tools"]["buffTracker"][4] = {}
elseif rest == "all" then
Cell.frames.anchorFrame:ClearAllPoints()
Cell.frames.anchorFrame:SetPoint("TOPLEFT", UIParent, "CENTER")
Cell.frames.readyAndPullFrame:ClearAllPoints()
Cell.frames.readyAndPullFrame:SetPoint("TOPRIGHT", UIParent, "CENTER")
Cell.frames.raidMarksFrame:ClearAllPoints()
Cell.frames.raidMarksFrame:SetPoint("BOTTOMRIGHT", UIParent, "CENTER")
Cell.frames.buffTrackerFrame:ClearAllPoints()
Cell.frames.buffTrackerFrame:SetPoint("BOTTOMLEFT", UIParent, "CENTER")
CellDB = nil
ReloadUI()
elseif rest == "layouts" then
CellDB["layouts"] = nil
ReloadUI()
elseif rest == "clickcastings" then
CellDB["clickCastings"] = nil
ReloadUI()
elseif rest == "raiddebuffs" then
CellDB["raidDebuffs"] = nil
ReloadUI()
elseif rest == "snippets" then
CellDB["snippets"] = {}
CellDB["snippets"][0] = F:GetDefaultSnippet()
ReloadUI()
end
elseif command == "report" then
rest = tonumber(rest:format("%d"))
if rest and rest >= 0 and rest <= 40 then
if rest == 0 then
F:Print(L["Cell will report all deaths during a raid encounter."])
else
F:Print(string.format(L["Cell will report first %d deaths during a raid encounter."], rest))
end
CellDB["tools"]["deathReport"][2] = rest
Cell:Fire("UpdateTools", "deathReport")
else
F:Print(L["A 0-40 integer is required."])
end
-- elseif command == "buff" then
-- rest = tonumber(rest:format("%d"))
-- if rest and rest > 0 then
-- CellDB["tools"]["buffTracker"][3] = rest
-- F:Print(string.format(L["Buff Tracker icon size is set to %d."], rest))
-- Cell:Fire("UpdateTools", "buffTracker")
-- else
-- F:Print(L["A positive integer is required."])
-- end
else
F:Print(L["Available slash commands"]..":\n"..
"|cFFFFB5C5/cell options|r, |cFFFFB5C5/cell opt|r: "..L["show Cell options frame"]..".\n"..
"|cFFFFB5C5/cell healers|r: "..L["create a \"Healers\" indicator"]..".\n"..
"|cFFFF7777"..L["These \"reset\" commands below affect all your characters in this account"]..".|r\n"..
"|cFFFFB5C5/cell reset position|r: "..L["reset Cell position"]..".\n"..
"|cFFFFB5C5/cell reset layouts|r: "..L["reset all Layouts and Indicators"]..".\n"..
"|cFFFFB5C5/cell reset clickcastings|r: "..L["reset all Click-Castings"]..".\n"..
"|cFFFFB5C5/cell reset raiddebuffs|r: "..L["reset all Raid Debuffs"]..".\n"..
"|cFFFFB5C5/cell reset snippets|r: "..L["reset all Code Snippets"]..".\n"..
"|cFFFFB5C5/cell reset all|r: "..L["reset all Cell settings"].."."
)
end
end
function Cell_OnAddonCompartmentClick()
F:ShowOptionsFrame()
end