forked from doadin/Plexus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCore.lua
975 lines (848 loc) · 33 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
--[[--------------------------------------------------------------------
Plexus
Compact party and raid unit frames.
Copyright (c) 2006-2009 Kyle Smith (Pastamancer)
Copyright (c) 2009-2018 Phanx <[email protected]>
All rights reserved. See the accompanying LICENSE file for details.
----------------------------------------------------------------------]]
local PLEXUS, Plexus = ...
local format = format
local strfind = strfind
local strjoin = strjoin
local strlen = strlen
local strlower = strlower
local strmatch = strmatch
local strtrim = strtrim
local strupper = strupper
local tinsert = tinsert
--local GetBuildInfo = GetBuildInfo
local CreateFrame = CreateFrame
local GetAddOnMetadata = C_AddOns and C_AddOns.GetAddOnMetadata or GetAddOnMetadata
local InCombatLockdown = InCombatLockdown
local IsAddOnLoaded = C_AddOns and C_AddOns.IsAddOnLoaded or IsAddOnLoaded
local StaticPopup_Show = StaticPopup_Show
local tostringall = tostringall
local WOW_PROJECT_ID = WOW_PROJECT_ID
local WOW_PROJECT_CLASSIC = WOW_PROJECT_CLASSIC
local WOW_PROJECT_BURNING_CRUSADE_CLASSIC = WOW_PROJECT_BURNING_CRUSADE_CLASSIC
local WOW_PROJECT_WRATH_CLASSIC = WOW_PROJECT_WRATH_CLASSIC
local WOW_PROJECT_CATACLYSM_CLASSIC = WOW_PROJECT_CATACLYSM_CLASSIC
local WOW_PROJECT_MAINLINE = WOW_PROJECT_MAINLINE
local LE_EXPANSION_LEVEL_CURRENT = LE_EXPANSION_LEVEL_CURRENT
local LE_EXPANSION_BURNING_CRUSADE = LE_EXPANSION_BURNING_CRUSADE
local LE_EXPANSION_WRATH_OF_THE_LICH_KING = LE_EXPANSION_WRATH_OF_THE_LICH_KING
local LE_EXPANSION_CATACLYSM = LE_EXPANSION_CATACLYSM
local LDBIcon = LibStub:GetLibrary("LibDBIcon-1.0")
local LibDeflate = LibStub:GetLibrary('LibDeflate')
local AceGUI = LibStub:GetLibrary("AceGUI-3.0")
local AceSerializer = LibStub:GetLibrary("AceSerializer-3.0")
local tostring, type , tcopy = tostring, type, CopyTable
function Plexus:IsClassicWow() --luacheck: ignore 212
return WOW_PROJECT_ID == WOW_PROJECT_CLASSIC
end
function Plexus:IsTBCWow() --luacheck: ignore 212
return WOW_PROJECT_ID == WOW_PROJECT_BURNING_CRUSADE_CLASSIC and LE_EXPANSION_LEVEL_CURRENT == LE_EXPANSION_BURNING_CRUSADE
end
function Plexus:IsWrathWow() --luacheck: ignore 212
return WOW_PROJECT_ID == WOW_PROJECT_WRATH_CLASSIC and LE_EXPANSION_LEVEL_CURRENT == LE_EXPANSION_WRATH_OF_THE_LICH_KING
end
function Plexus:IsCataWow() --luacheck: ignore 212
return WOW_PROJECT_ID == WOW_PROJECT_CATACLYSM_CLASSIC and LE_EXPANSION_LEVEL_CURRENT == LE_EXPANSION_CATACLYSM
end
function Plexus:IsRetailWow() --luacheck: ignore 212
return WOW_PROJECT_ID == WOW_PROJECT_MAINLINE
end
_G.Plexus = LibStub:GetLibrary("AceAddon-3.0"):NewAddon(Plexus, PLEXUS, "AceConsole-3.0", "AceEvent-3.0")
if NickTag then
LibStub("NickTag-1.0"):Embed(Plexus)
if not Plexus.nick_tag_cache then
Plexus.nick_tag_cache = {}
end
Plexus:NickTagSetCache(Plexus.nick_tag_cache)
end
if (IsAddOnLoaded("Grid")) then
StaticPopupDialogs["GRID_ENABLED"] = { --luacheck: ignore 112
text = "Grid and Plexus should never be enabled at the same time, unless you are copying settings! Do you want to copy Grid settings to Plexus?(Please Have Backups and Note: Restart is Required After Copy)",
button1 = "Yes",
button2 = "No",
OnAccept = function()
PlexusDB.namespaces.PlexusFrame = GridDB.namespaces.GridFrame
PlexusDB.namespaces.PlexusLayout = GridDB.namespaces.GridLayout
PlexusDB.namespaces.PlexusRoster = GridDB.namespaces.GridRoster
PlexusDB.namespaces.PlexusStatus = GridDB.namespaces.GridStatus
PlexusDB.namespaces.PlexusStatusAbsorbs = GridDB.namespaces.GridStatusAbsorbs
PlexusDB.namespaces.PlexusStatusAggro = GridDB.namespaces.GridStatusAggro
PlexusDB.namespaces.PlexusStatusAuras = GridDB.namespaces.GridStatusAuras
PlexusDB.namespaces.PlexusStatusGroup = GridDB.namespaces.GridStatusGroup
PlexusDB.namespaces.PlexusStatusHeals = GridDB.namespaces.GridStatusHeals
PlexusDB.namespaces.PlexusStatusHealth = GridDB.namespaces.GridStatusHealth
PlexusDB.namespaces.PlexusStatusMana = GridDB.namespaces.GridStatusMana
PlexusDB.namespaces.PlexusStatusMouseover = GridDB.namespaces.GridStatusMouseover
PlexusDB.namespaces.PlexusStatusName = GridDB.namespaces.GridStatusName
PlexusDB.namespaces.PlexusStatusRaidIcon = GridDB.namespaces.GridStatusRaidIcon
PlexusDB.namespaces.PlexusStatusRange = GridDB.namespaces.GridStatusRange
PlexusDB.namespaces.PlexusStatusReadyCheck = GridDB.namespaces.GridStatusReadyCheck
PlexusDB.namespaces.PlexusStatusResurrect = GridDB.namespaces.GridStatusResurrect
PlexusDB.namespaces.PlexusStatusRole = GridDB.namespaces.GridStatusRole
PlexusDB.namespaces.PlexusStatusStagger = GridDB.namespaces.GridStatusStagger
PlexusDB.namespaces.PlexusStatusTarget = GridDB.namespaces.GridStatusTarget
PlexusDB.namespaces.PlexusStatusVehicle = GridDB.namespaces.GridStatusVehicle
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3, -- avoid some UI taint, see http://www.wowace.com/announcements/how-to-avoid-some-ui-taint/
}
StaticPopup_Show ("GRID_ENABLED")
end
if not Plexus.L then Plexus.L = { } end
local L = setmetatable( Plexus.L, {
__index = function(t, k)
t[k] = k
return k
end
})
------------------------------------------------------------------------
function Plexus:Debug(str, ...)
if not self.debug then return end
if not str or strlen(str) == 0 then return end
if (...) then
if strfind(str, "%%%.%d") or strfind(str, "%%[dfqsx%d]") then
str = format(str, ...)
else
str = strjoin(" ", str, tostringall(...))
end
end
local name = self.moduleName or self.name or PLEXUS
_G[Plexus.db.global.debugFrame]:AddMessage(format("|cffff9933%s:|r %s", name, str))
end
function Plexus:GetDebuggingEnabled(moduleName)
return self.db.global.debug[moduleName]
end
do
local function FindModule(start, moduleName)
--print("FindModule", start.moduleName, moduleName)
if start.name == moduleName or start.moduleName == moduleName then
return start
end
for _, module in start:IterateModules() do
local found = FindModule(module, moduleName)
if found then
--print("FOUND")
return found
end
end
end
function Plexus:SetDebuggingEnabled(moduleName, value)
--print("SetDebuggingEnabled", moduleName, value)
local module = FindModule(self, moduleName)
if not module then
--print("ERROR: module "..moduleName.." doesn't exist!")
return
end
if module.db and module.db.profile and module.db.profile.debug ~= nil then
--print("Removed old debug setting from module", moduleName, tostring(module.db.profile.debug))
module.db.profile.debug = nil
end
local args = self.options.args.debug.args
if not args[moduleName] then
args[moduleName] = self:GetDebuggingOptions(moduleName)
end
if value == nil then
module.debug = self.db.global.debug[moduleName]
else
self.db.global.debug[moduleName] = value or nil
module.debug = value
end
end
end
------------------------------------------------------------------------
Plexus.options = {
name = function() return "Plexus " .. GetAddOnMetadata(PLEXUS, "Version") end,
handler = Plexus,
type = "group",
childGroups = "tab",
args = {
general = {
type = "group",
name = L["General"],
order = 1,
args = {
minimap = {
name = L["Show minimap icon"],
desc = L["Show the Plexus icon on the minimap. Note that some DataBroker display addons may hide the icon regardless of this setting."],
order = 1,
width = "double",
type = "toggle",
get = function()
return not Plexus.db.profile.minimap.hide
end,
set = function(info, value) --luacheck: ignore 212
Plexus.db.profile.minimap.hide = not value
if Plexus:IsClassicWow() or Plexus:IsTBCWow() or Plexus:IsWrathWow() or Plexus:IsCataWow() then
if value then
LDBIcon:Show(PLEXUS)
else
LDBIcon:Hide(PLEXUS)
end
end
end,
hidden = Plexus:IsRetailWow(),
},
standaloneOptions = {
name = L["Standalone options"],
desc = L["Open Plexus's options in their own window, instead of the Interface Options window, when typing /plexus or right-clicking on the minimap icon, DataBroker icon, or layout tab."],
order = 2,
width = "double",
type = "toggle",
get = function()
return Plexus.db.profile.standaloneOptions
end,
set = function(info, value) --luacheck: ignore 212
Plexus.db.profile.standaloneOptions = value
end,
},
import = {
name = L["Import Profile"],
order = 5,
width = "double",
type = "execute",
func = function() Plexus:ImportProfile() end,
},
export = {
name = L["Export Profile"],
order = 6,
width = "double",
type = "execute",
func = function() Plexus:ExportProfile() end,
}
},
},
debug = {
type = "group",
name = L["Debugging"],
desc = L["Module debugging menu."],
order = -1,
args = {
desc = {
order = 1,
type = "description",
name = L["Debugging messages help developers or testers see what is happening inside Plexus in real time. Regular users should leave debugging turned off except when troubleshooting a problem for a bug report."],
},
frame = {
order = 2,
name = L["Output Frame"],
desc = L["Show debugging messages in this frame."],
type = "select",
get = function(info) --luacheck: ignore 212
return Plexus.db.global.debugFrame
end,
set = function(info, value) --luacheck: ignore 212
Plexus.db.global.debugFrame = value
end,
values = {
ChatFrame1 = "ChatFrame1",
ChatFrame2 = "ChatFrame2",
ChatFrame3 = "ChatFrame3",
ChatFrame4 = "ChatFrame4",
ChatFrame5 = "ChatFrame5",
ChatFrame6 = "ChatFrame6",
ChatFrame7 = "ChatFrame7",
ChatFrame8 = "ChatFrame8",
ChatFrame9 = "ChatFrame9",
ChatFrame10 = "ChatFrame10",
},
},
spacer = {
order = 3,
name = " ",
type = "description",
},
}
}
}
}
function Plexus:ExportProfile() --luacheck: ignore 212
local ExportProfile = tcopy(PlexusDB.namespaces)
local SerializedProfile = AceSerializer:Serialize(ExportProfile)
local EncodedProfile = LibDeflate:EncodeForPrint(SerializedProfile);
local input = AceGUI:Create("MultiLineEditBox");
input:SetWidth(400);
input:SetNumLines(20);
input.button:Hide();
input.frame:SetClipsChildren(true);
input:SetLabel("Export Plexus Profile");
input:SetText(EncodedProfile);
input.editBox:HighlightText();
input:SetFocus();
local f = AceGUI:Create("Frame")
f:SetStatusText("Profile Exported Copy Text Above!")
f:SetTitle("Export Profile")
f:SetWidth(500)
f:AddChild(input)
f:SetCallback("OnClose", function() AceGUI:Release(input) end)
input.editBox:SetScript("OnEscapePressed", function() f:Close(); end);
end
function Plexus:ImportProfile() --luacheck: ignore 212
local input = AceGUI:Create("MultiLineEditBox");
input:SetWidth(400);
input:SetNumLines(20);
input.button:Hide();
input.frame:SetClipsChildren(true);
input:SetLabel("Import Plexus Profile");
input:SetText("");
input.editBox:HighlightText();
input:SetFocus();
local f = AceGUI:Create("Frame")
f:SetTitle("Import Profile")
f:SetWidth(500)
f:AddChild(input)
local ImportButton = CreateFrame("Button", nil, f.frame, "UIPanelButtonTemplate");
ImportButton:SetScript("OnClick",
function()
local decoded = LibDeflate:DecodeForPrint(input:GetText());
local DeserializedResult, DeserializedData = AceSerializer:Deserialize(decoded);
if DeserializedResult then
PlexusDB.namespaces = DeserializedData;
f:SetStatusText("Profile imported You can now reload!");
else
f:SetStatusText("Invalid Profile!")
end;
end);
ImportButton:SetPoint("BOTTOMRIGHT", -30, 50);
ImportButton:SetFrameLevel(ImportButton:GetFrameLevel() + 1)
ImportButton:SetHeight(25);
ImportButton:SetWidth(150);
ImportButton:SetText("Import and ReloadUI")
end
------------------------------------------------------------------------
Plexus.defaultDB = {
profile = {
minimap = {},
standaloneOptions = false,
},
global = {
debug = {},
debugFrame = "ChatFrame1",
}
}
------------------------------------------------------------------------
Plexus.modulePrototype = {
core = Plexus,
Debug = Plexus.Debug,
registeredModules = { },
}
if Plexus:IsRetailWow() then
Plexus.defaultDB.profile.hideBlizzardParty = false
Plexus.defaultDB.profile.hideBlizzardRaid = false
Plexus.options.args.general.args.hideBlizzardParty = {
name = L["Hide Blizzard Party Frames"],
desc = L["Enable or Disable Showing Blizzard Party Frames. Requires ReloadUI!"],
order = 3,
width = "double",
type = "toggle",
get = function()
return Plexus.db.profile.hideBlizzardParty
end,
set = function(info, value) --luacheck: ignore 212
Plexus.db.profile.hideBlizzardParty = value
end,
}
Plexus.options.args.general.args.hideBlizzardRaid = {
name = L["Hide Blizzard Raid Frames"],
desc = L["Enable or Disable Showing Blizzard Raid Frames. Requires ReloadUI!"],
order = 4,
width = "double",
type = "toggle",
get = function()
return Plexus.db.profile.hideBlizzardRaid
end,
set = function(info, value) --luacheck: ignore 212
Plexus.db.profile.hideBlizzardRaid = value
end,
}
end
function Plexus.modulePrototype:OnInitialize()
if not self.db then
self.db = Plexus.db:RegisterNamespace(self.moduleName, { profile = self.defaultDB or { } })
end
self:Debug("OnInitialize")
Plexus:SetDebuggingEnabled(self.moduleName)
for name, module in self:IterateModules() do
self:RegisterModule(name, module)
Plexus:SetDebuggingEnabled(name)
end
if type(self.PostInitialize) == "function" then
self:PostInitialize()
end
end
function Plexus.modulePrototype:OnEnable()
for name, module in self:IterateModules() do
self:RegisterModule(name, module)
end
self:EnableModules()
if type(self.PostEnable) == "function" then
self:PostEnable()
end
end
function Plexus.modulePrototype:OnDisable()
self:DisableModules()
if type(self.PostDisable) == "function" then
self:PostDisable()
end
end
function Plexus.modulePrototype:Reset()
self:Debug("Reset")
self:ResetModules()
if type(self.PostReset) == "function" then
self:PostReset()
end
end
function Plexus.modulePrototype:OnModuleCreated(module)
module.super = self.modulePrototype
self:Debug("OnModuleCreated", module.moduleName)
if Plexus.db then
-- otherwise it will be caught in core OnInitialize
Plexus:SetDebuggingEnabled(module.moduleName)
end
end
function Plexus.modulePrototype:RegisterModule(name, module)
if self.registeredModules[module] then return end
self:Debug("Registering", name)
if not module.db then
module.db = Plexus.db:RegisterNamespace(name, { profile = module.defaultDB or { } })
end
if module.extraOptions and not module.options then
module.options = {
name = module.menuName or module.moduleName,
type = "group",
args = {},
}
for modulename, option in pairs(module.extraOptions) do
module.options.args[modulename] = option
end
end
if module.options then
self.options.args[name] = module.options
end
self.registeredModules[module] = true
end
function Plexus.modulePrototype:EnableModules()
for name, _ in self:IterateModules() do
self:EnableModule(name)
end
end
function Plexus.modulePrototype:DisableModules()
for name, _ in self:IterateModules() do
self:DisableModule(name)
end
end
function Plexus.modulePrototype:ResetModules()
for name, module in self:IterateModules() do
self:Debug("Resetting " .. name)
module.db = self.core.db:GetNamespace(name)
if type(module.Reset) == "function" then
module:Reset()
end
end
end
function Plexus.modulePrototype:StartTimer(callback, delay, repeating, arg)
if not self.ScheduleTimer then
-- This module doesn't use AceTimer-3.0.
self:Debug("Attempt to call StartTimer without AceTimer-3.0!")
return
end
self:Debug("StartTimer", callback, delay, repeating, arg)
local handles = self.timerHandles
if not handles then
-- First time starting a timer.
handles = {}
self.timerHandles = handles
end
local timerName = tostring(callback)
if handles[timerName] then
-- Timer is already running; stop it first.
self:StopTimer(timerName)
end
local handle
if repeating then
handle = self:ScheduleRepeatingTimer(callback, delay, arg)
else
handle = self:ScheduleTimer(callback, delay, arg)
-- KNOWN ISSUE: Unless the module cancels the timer itself in
-- the callback function, the timer will remain listed in the
-- module.timerHandles table. Should not cause any problems,
-- though, since StopTimer calls CancelTimer silently.
end
handles[timerName] = handle
return handle
end
function Plexus.modulePrototype:StopTimer(callback)
local handles, timerName = self.timerHandles, tostring(callback)
if not handles or not handles[timerName] then
-- This module doesn't use AceTimer, or hasn't started any timers
-- yet, or the specified timer is not running.
self:Debug("Attempt to call StopTimer without AceTimer-3.0!")
return
end
self:Debug("StopTimer", timerName)
self:CancelTimer(handles[timerName], true)
handles[timerName] = nil
end
Plexus:SetDefaultModulePrototype(Plexus.modulePrototype)
Plexus:SetDefaultModuleLibraries("AceEvent-3.0")
------------------------------------------------------------------------
function Plexus:OnInitialize()
self.db = LibStub:GetLibrary("AceDB-3.0"):New("PlexusDB", self.defaultDB, true)
self.db.RegisterCallback(self, "OnProfileChanged", "OnProfileEnable")
self.db.RegisterCallback(self, "OnProfileCopied", "OnProfileEnable")
self.db.RegisterCallback(self, "OnProfileReset", "OnProfileEnable")
self.options.args.profile = LibStub:GetLibrary("AceDBOptions-3.0"):GetOptionsTable(self.db)
self.options.args.profile.order = -3
if Plexus:IsRetailWow() or Plexus:IsWrathWow() then
local LibDualSpec = LibStub:GetLibrary("LibDualSpec-1.0")
LibDualSpec:EnhanceDatabase(self.db, PLEXUS)
LibDualSpec:EnhanceOptions(self.options.args.profile, self.db)
end
LibStub:GetLibrary("AceConfigRegistry-3.0"):RegisterOptionsTable(PLEXUS, self.options)
--
-- Broker launcher
--
local DataBroker = LibStub:GetLibrary("LibDataBroker-1.1", true)
if DataBroker then
self.Broker = DataBroker:NewDataObject(PLEXUS, {
type = "launcher",
icon = "Interface\\AddOns\\Plexus\\Media\\icon",
OnClick = function(_, button)
if button == "RightButton" then
Plexus:ToggleOptions()
elseif not InCombatLockdown() then
local PlexusLayout = Plexus:GetModule("PlexusLayout")
PlexusLayout.db.profile.lock = not PlexusLayout.db.profile.lock
LibStub:GetLibrary("AceConfigRegistry-3.0"):NotifyChange(PLEXUS)
PlexusLayout:UpdateTabVisibility()
end
end,
OnTooltipShow = function(tooltip)
tooltip:AddLine(PLEXUS, 1, 1, 1)
if InCombatLockdown() then
tooltip:AddLine(L["Click to toggle the frame lock."], 0.5, 0.5, 0.5)
else
tooltip:AddLine(L["Click to toggle the frame lock."])
end
tooltip:AddLine(L["Right-Click for more options."])
end,
})
end
function PlexusOnAddonCompartmentClick(_, button)
if button == "RightButton" then
Plexus:ToggleOptions()
elseif not InCombatLockdown() then
local PlexusLayout = Plexus:GetModule("PlexusLayout")
PlexusLayout.db.profile.lock = not PlexusLayout.db.profile.lock
LibStub:GetLibrary("AceConfigRegistry-3.0"):NotifyChange(PLEXUS)
PlexusLayout:UpdateTabVisibility()
end
end
if Plexus:IsClassicWow() or Plexus:IsTBCWow() or Plexus:IsWrathWow() or Plexus:IsCataWow() then
LDBIcon:Register(PLEXUS, self.Broker, self.db.profile.minimap)
if self.db.profile.minimap.hide then
LDBIcon:Hide(PLEXUS)
else
LDBIcon:Show(PLEXUS)
end
end
self:SetDebuggingEnabled("Plexus")
for name, module in self:IterateModules() do
self:RegisterModule(name, module)
end
-- to catch mysteriously late-loading modules
self:RegisterEvent("ADDON_LOADED")
self:UpdateBlizzardFrames()
end
function Plexus:OnEnable()
self:Debug("OnEnable")
for name, module in self:IterateModules() do
self:RegisterModule(name, module)
end
self:EnableModules()
if self.SetupOptions then
self:SetupOptions()
end
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("PLAYER_REGEN_DISABLED")
self:RegisterEvent("PLAYER_REGEN_ENABLED")
self:SendMessage("Plexus_Enabled")
end
function Plexus:OnDisable()
self:Debug("OnDisable")
self:SendMessage("Plexus_Disabled")
self:DisableModules()
end
function Plexus:OnProfileEnable()
self:Debug("Loaded profile", self.db:GetCurrentProfile())
if Plexus:IsClassicWow() or Plexus:IsTBCWow() or Plexus:IsWrathWow() or Plexus:IsCataWow() then
if LDBIcon then
LDBIcon:Refresh(PLEXUS, self.db.profile.minimap)
if self.db.profile.minimap.hide then
LDBIcon:Hide(PLEXUS)
else
LDBIcon:Show(PLEXUS)
end
end
end
self:ResetModules()
end
function Plexus:SetupOptions()
local Command = LibStub:GetLibrary("AceConfigCmd-3.0")
local Dialog = LibStub:GetLibrary("AceConfigDialog-3.0")
---------------------------------------------------------------------
-- Standalone options
local status = Dialog:GetStatusTable(PLEXUS)
status.width = 780 -- 685
status.height = 500 -- 530
local child1 = Dialog:GetStatusTable(PLEXUS, { "PlexusIndicator" })
child1.groups = child1.groups or {}
child1.groups.treewidth = 220
local child2 = Dialog:GetStatusTable(PLEXUS, { "PlexusStatus" })
child2.groups = child2.groups or {}
child2.groups.treewidth = 260
local child3 = Dialog:GetStatusTable(PLEXUS, { "PlexusHelp" })
child3.groups = child3.groups or {}
child3.groups.treewidth = 300
self:RegisterChatCommand("plexus", function(input)
if input then
input = strtrim(input)
end
if not input or input == "" then
self:ToggleOptions()
elseif strmatch(strlower(input), "^ve?r?s?i?o?n?$") then
local version = GetAddOnMetadata(PLEXUS, "Version")
if version == "@" .. "project-version" .. "@" then -- concatenation to trick the packager
self:Print("You are using a developer version.") -- no need to localize
else
self:Print(format(L["You are using version %s"], version))
end
else
Command.HandleCommand(Plexus, "plexus", PLEXUS, input)
end
end)
if SettingsPanel then
SettingsPanel:HookScript("OnShow", function()
Dialog:Close(PLEXUS)
end)
else
InterfaceOptionsFrame:HookScript("OnShow", function()
Dialog:Close(PLEXUS)
end)
end
---------------------------------------------------------------------
-- Interface Options frame integrated options
local panels = {}
for k in pairs(self.options.args) do
if k ~= "general" then
tinsert(panels, k)
end
end
table.sort(panels, function(a, b) -- copied from Dialog-3.0
if not a then return true end
if not b then return false end
local orderA, orderB = self.options.args[a].order or 10000, self.options.args[b].order or 10000
if orderA == orderB then
return strupper(self.options.args[a].name or "") < strupper(self.options.args[b].name or "")
end
if orderA < 0 then
if orderB > 0 then return false end
else
if orderB < 0 then return true end
end
return orderA < orderB
end)
self.optionsPanels = {
Dialog:AddToBlizOptions(PLEXUS, PLEXUS, nil, "general") -- "appName", "panelName", "parentName", ... "optionsPath"
}
--local noop = function() end
for i = 1, #panels do
local path = panels[i]
local name = self.options.args[path].name
local f = Dialog:AddToBlizOptions(PLEXUS, name, PLEXUS, path)
--f.obj:SetTitle(PLEXUS .. " - " .. name) -- workaround for AceConfig deficiency
--f.obj.SetTitle = noop
self.optionsPanels[i+1] = f
end
self.SetupOptions = nil
end
function Plexus:ToggleOptions()
if self.db.profile.standaloneOptions then
local Dialog = LibStub:GetLibrary("AceConfigDialog-3.0")
if Dialog.OpenFrames[PLEXUS] then
Dialog:Close(PLEXUS)
else
Dialog:Open(PLEXUS)
end
else
if Settings and Settings.OpenToCategory then
Settings.OpenToCategory(self.optionsPanels[2])
else
InterfaceOptionsFrame_OpenToCategory(self.optionsPanels[2]) -- default to Layout
InterfaceOptionsFrame_OpenToCategory(self.optionsPanels[2]) -- double up as a workaround for the bug that opens the frame without selecting the panel
end
end
end
------------------------------------------------------------------------
do
local function debug_get(info)
--print("debug_get", info[#info])
return Plexus:GetDebuggingEnabled(info[#info])
end
local function debug_set(info, value)
--print("debug_set", info[#info], value)
return Plexus:SetDebuggingEnabled(info[#info], value)
end
function Plexus:GetDebuggingOptions(moduleName) --luacheck: ignore 212
return {
name = moduleName,
desc = format(L["Enable debugging messages for the %s module."], moduleName),
type = "toggle",
width = "double",
get = debug_get,
set = debug_set,
}
end
end
function Plexus:OnModuleCreated(module)
module.super = self.modulePrototype
if self.db then
-- otherwise it will be caught in core OnInitialize
self:SetDebuggingEnabled(module.moduleName)
end
end
------------------------------------------------------------------------
local registeredModules = { }
function Plexus:RegisterModule(name, module)
if registeredModules[module] then return end
self:Debug("Registering " .. name)
if not module.db then
module.db = self.db:RegisterNamespace(name, { profile = module.defaultDB or { } })
end
if module.options then
self.options.args[name] = module.options
end
registeredModules[module] = true
end
function Plexus:EnableModules()
for name, _ in self:IterateModules() do
self:EnableModule(name)
end
end
function Plexus:DisableModules()
for name, _ in self:IterateModules() do
self:DisableModule(name)
end
end
function Plexus:ResetModules()
for name, module in self:IterateModules() do
self:Debug("Resetting " .. name)
module.db = self.db:GetNamespace(name)
if type(module.Reset) == "function" then
module:Reset()
end
end
end
------------------------------------------------------------------------
-- Hide blizzard raid & party frames
do
local hiddenFrame
local function rehide(self)
if not InCombatLockdown() then self:Hide() end
end
local function unregister(f)
if f then f:UnregisterAllEvents() end
end
local function hideFrame(frame)
if frame then
UnregisterUnitWatch(frame)
frame:Hide()
frame:UnregisterAllEvents()
frame:SetParent(hiddenFrame)
frame:HookScript("OnShow", rehide)
unregister(frame.healthbar)
unregister(frame.manabar)
unregister(frame.powerBarAlt)
unregister(frame.spellbar)
end
end
-- party frames
local function HidePartyFrames()
hiddenFrame = hiddenFrame or CreateFrame('Frame')
hiddenFrame:Hide()
if PartyFrame then
hideFrame(PartyFrame)
for frame in PartyFrame.PartyMemberFramePool:EnumerateActive() do
hideFrame(frame)
hideFrame(frame.HealthBar)
hideFrame(frame.ManaBar)
end
PartyFrame.PartyMemberFramePool:ReleaseAll()
end
hideFrame(CompactPartyFrame)
UIParent:UnregisterEvent("GROUP_ROSTER_UPDATE") -- used by compact party frame
end
-- raid frames
local function HideRaidFrames()
if not CompactRaidFrameManager then return end
local function HideFrames()
CompactRaidFrameManager:SetAlpha(0)
CompactRaidFrameManager:UnregisterAllEvents()
CompactRaidFrameContainer:UnregisterAllEvents()
if not InCombatLockdown() then
CompactRaidFrameManager:Hide()
local shown = CompactRaidFrameManager_GetSetting('IsShown')
if shown and shown ~= '0' then
CompactRaidFrameManager_SetSetting('IsShown', '0')
end
end
end
hiddenFrame = hiddenFrame or CreateFrame('Frame')
hiddenFrame:Hide()
hooksecurefunc('CompactRaidFrameManager_UpdateShown', HideFrames)
CompactRaidFrameManager:HookScript('OnShow', HideFrames)
CompactRaidFrameContainer:HookScript('OnShow', HideFrames)
HideFrames()
end
-- Only for dragonflight, for classic compactRaidFrames addon is disabled from options
function Plexus:UpdateBlizzardFrames()
if Plexus:IsRetailWow() then
local hideBlizzardParty = self.db.profile.hideBlizzardParty
local hideBlizzardRaid = self.db.profile.hideBlizzardRaid
if hideBlizzardRaid then
HideRaidFrames()
end
if hideBlizzardParty then
HidePartyFrames()
end
end
self.UpdateBlizzardFrames = nil
end
end
function Plexus:PLAYER_ENTERING_WORLD()
-- this is needed for zoning while in combat
self:PLAYER_REGEN_ENABLED()
end
function Plexus:PLAYER_REGEN_DISABLED()
self:Debug("Entering combat")
self:SendMessage("Plexus_EnteringCombat")
Plexus.inCombat = true
end
function Plexus:PLAYER_REGEN_ENABLED()
Plexus.inCombat = InCombatLockdown() == 1
if not Plexus.inCombat then
self:Debug("Leaving combat")
self:SendMessage("Plexus_LeavingCombat")
end
end
function Plexus:ADDON_LOADED()
for name, module in self:IterateModules() do
self:RegisterModule(name, module)
end
end