-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProfiles.lua
More file actions
725 lines (622 loc) · 19 KB
/
Copy pathProfiles.lua
File metadata and controls
725 lines (622 loc) · 19 KB
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
local addon, ns = ...
local L = ns.L
local listFrame = AddonMgrAddonList
local lastProfileName, profilePopupAction
listFrame.addonName = ("%s_ADDON_"):format(addon:upper())
--POPUPS
StaticPopupDialogs[listFrame.addonName.."NEW_PROFILE"] = {
text = addon..": "..L["Create profile"],
button1 = ACCEPT,
button2 = CANCEL,
hasEditBox = 1,
maxLetters = 48,
editBoxWidth = 350,
hideOnEscape = 1,
whileDead = 1,
OnAccept = function(self, cb) cb(self) end,
EditBoxOnEnterPressed = function(self)
StaticPopup_OnClick(self:GetParent(), 1)
end,
EditBoxOnEscapePressed = function(self)
self:GetParent():Hide()
end,
}
local function profileExistsAccept(popup, data)
if not popup then return end
popup:Hide()
profilePopupAction(listFrame, data)
profilePopupAction = nil
lastProfileName = nil
end
StaticPopupDialogs[listFrame.addonName.."PROFILE_EXISTS"] = {
text = addon..": "..L["A profile with the same name exists."],
button1 = OKAY,
hideOnEscape = 1,
whileDead = 1,
-- enterClicksFirstButton = 1,
OnAccept = profileExistsAccept,
OnCancel = profileExistsAccept,
}
StaticPopupDialogs[listFrame.addonName.."EDIT_PROFILE"] = {
text = addon..": "..EDIT,
button1 = ACCEPT,
button2 = CANCEL,
hasEditBox = 1,
maxLetters = 48,
editBoxWidth = 350,
hideOnEscape = 1,
whileDead = 1,
OnAccept = function(self, cb) cb(self) end,
EditBoxOnEnterPressed = function(self)
StaticPopup_OnClick(self:GetParent(), 1)
end,
EditBoxOnEscapePressed = function(self)
self:GetParent():Hide()
end,
}
StaticPopupDialogs[listFrame.addonName.."DELETE_PROFILE"] = {
text = addon..": "..L["Are you sure you want to delete %s profile?"],
button1 = DELETE,
button2 = CANCEL,
hideOnEscape = 1,
whileDead = 1,
OnAccept = function(_, cb) cb() end,
}
StaticPopupDialogs[listFrame.addonName.."YOU_WANT"] = {
text = addon..": "..L["Are you sure you want to %s?"],
button1 = OKAY,
button2 = CANCEL,
hideOnEscape = 1,
whileDead = 1,
OnAccept = function(_, cb) cb() end,
}
StaticPopupDialogs[listFrame.addonName.."CUSTOM_OK_CANCEL"] = {
text = addon..": %s",
button1 = OKAY,
button2 = CANCEL,
hideOnEscape = 1,
whileDead = 1,
-- enterClicksFirstButton = 1,
OnAccept = function(_, cb) cb() end,
}
-- SAVE CHAR PROFILES
function listFrame:PLAYER_LOGOUT()
local charName = self.charName.." - "..GetRealmName()
local curCharProfile
for i = 1, #self.charProfiles do
if self.charProfiles[i].name == charName then
curCharProfile = self.charProfiles[i]
break
end
end
if not curCharProfile then
curCharProfile = {name = charName, addons = {}}
self.charProfiles[#self.charProfiles + 1] = curCharProfile
sort(self.charProfiles, function(a, b) return strcmputf8i(a.name, b.name) < 0 end)
end
curCharProfile.class = select(2, UnitClass("player"))
self:saveProfileAddons(curCharProfile)
if AddonMgrAutoLoadChar and not next(AddonMgrAutoLoadChar) then
AddonMgrAutoLoadChar = nil
end
end
listFrame:RegisterEvent("PLAYER_LOGOUT")
-- AUTOLOAD PROFILES
local function addToList(list, profile, context)
context = context or {}
if context[profile] then return end
context[profile] = true
for addonName in next, profile.addons do
list[addonName] = true
end
if profile.loadProfiles then
for name in next, profile.loadProfiles do
local lProfile = listFrame:getProfileByName(name)
if lProfile then addToList(list, lProfile, context) end
end
end
end
local function requireLoadProfile(profile)
local list = {}
addToList(list, profile)
for i = 1, #listFrame.sorted do
local addonName = listFrame.sorted[i]
local loadable, reason = C_AddOns.IsAddOnLoadable(addonName, listFrame.charGUID)
if (reason ~= "DISABLED") == not list[addonName] then return true end
end
end
local actualInstances
local function setActualInstances()
if actualInstances ~= nil then return end
local numTiers = EJ_GetNumTiers()
if numTiers < 1 then
actualInstances = false
return
end
local backupTier = EJ_GetCurrentTier()
actualInstances = {}
for i = numTiers > 10 and numTiers - 1 or numTiers, numTiers do
EJ_SelectTier(i)
for j = 1, 2 do
local showRaid = j == 2
local index = 1
local jInstanceID = EJ_GetInstanceByIndex(index, showRaid)
while jInstanceID do
--EJ_SelectInstance(jInstanceID)
local _,_,_,_,_,_,_,_,_, instanceID = EJ_GetInstanceInfo(jInstanceID)
actualInstances[instanceID] = true
index = index + 1
jInstanceID = EJ_GetInstanceByIndex(index, showRaid)
end
end
end
EJ_SelectTier(backupTier)
end
function listFrame:PLAYER_UPDATE_RESTING()
if IsResting() and self.autoLoadProfiles.resting then
local profile = self:getProfileByName(self.autoLoadProfiles.resting)
if profile then
if requireLoadProfile(profile) then
self:loadProfileAddons(profile, true)
end
return true
end
end
end
listFrame:RegisterEvent("PLAYER_UPDATE_RESTING")
function listFrame:PLAYER_ENTERING_WORLD(isInitialLogin, isReloadingUi)
if isInitialLogin or isReloadingUi then
self:setAutoLoadObj()
if isReloadingUi then return end
end
if not next(self.autoLoadProfiles) then return end
setActualInstances()
if self:PLAYER_UPDATE_RESTING() then return end
C_Timer.After(0, function()
local _, instanceType, difficultyID, _,_,_,_, instanceID = GetInstanceInfo()
local pName = self.autoLoadProfiles[instanceType]
if pName and actualInstances and (instanceType == "party" or instanceType == "raid") and not actualInstances[instanceID]
and difficultyID ~= 24 and difficultyID ~= 33 then return end -- Timewalking
local profile = self:getProfileByName(pName or self.autoLoadProfiles.none)
if profile and requireLoadProfile(profile) then
self:loadProfileAddons(profile, true)
end
end)
end
listFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
-- DROPDOWN
listFrame:HookScript("OnShow", function(self)
local dd = LibStub("LibSFDropDown-1.5"):CreateStretchButton(self, 90, 26)
if not self.isMainline then dd:ddSetDisplayMode("menuBackdrop") end
self.profileBtn = dd
dd:SetPoint("TOPRIGHT", -6, -30)
dd:SetText(L["Profiles"])
dd:ddSetInitFunc(function(dd, level, value)
local info = {}
if level == 1 then
info.keepShownOnClick = true
info.notCheckable = true
info.hasArrow = true
info.text = L["Characters"]
info.value = "chars"
dd:ddAddButton(info, level)
info.text = L["Autoload profile"]
info.value = "autoload"
dd:ddAddButton(info, level)
if #self.profiles ~= 0 then
dd:ddAddSeparator(level)
local lastLoadName = self:getLastLoadProfileName()
local widgets = {
{
icon = [[Interface\WorldMap\GEAR_64GREY]],
OnClick = function(btn)
self:editProfile(btn.value)
dd:ddCloseMenus()
end,
OnTooltipShow = function(_, tooltip)
tooltip:SetText(EDIT)
end,
},
}
local func = function(btn) self:loadProfileAddons(btn.value) end
local remove = function(btn) self:removeProfile(btn.value, self.profiles) end
local list = {}
for i, profile in ipairs(self.profiles) do
list[i] = {
hasArrow = true,
notCheckable = true,
text = self:getProfileDisplayName(profile, lastLoadName),
value = profile,
func = func,
remove = remove,
widgets = widgets,
}
end
info.list = list
dd:ddAddButton(info, level)
info.list = nil
end
dd:ddAddSeparator(level)
info.keepShownOnClick = nil
info.hasArrow = nil
info.text = L["Create profile"]
info.func = function() self:createProfile() end
dd:ddAddButton(info, level)
elseif value == "chars" then
local list = {}
local charName = self.charName.." - "..GetRealmName()
local empty = true
local func = function(btn) self:loadProfileAddons(btn.value) end
local remove = function(btn) self:removeProfile(btn.value, self.charProfiles) end
for i = 1, #self.charProfiles do
local profile = self.charProfiles[i]
if profile.name ~= charName then
empty = false
local _,_,_, color = GetClassColor(profile.class)
local name, realm = (" "):split(profile.name, 2)
local t = CLASS_ICON_TCOORDS[profile.class]
list[#list + 1] = {
notCheckable = true,
text = ("|c%s%s|r %s |cff808080(%d %s)|r"):format(color, name, realm, profile.count, ADDONS),
icon = "Interface/Glues/CharacterCreate/UI-CharacterCreate-Classes",
iconInfo = {
tCoordLeft = t[1],
tCoordRight = t[2],
tCoordTop = t[3],
tCoordBottom = t[4],
},
value = profile,
func = func,
remove = remove,
}
end
end
if empty then
info.notCheckable = true
info.disabled = true
info.text = EMPTY
else
list[#list + 1] = {
notCheckable = true,
text = L["Clear all"],
func = function() self:removeAllCharProfiles() end,
}
info.list = list
end
dd:ddAddButton(info, level)
elseif value == "autoload" then
info.keepShownOnClick = true
info.notCheckable = true
info.hasArrow = true
info.text = TUTORIAL_TITLE30
info.value = "resting"
dd:ddAddButton(info, level)
info.text = WORLD
info.value = "none"
dd:ddAddButton(info, level)
info.text = TRACKER_HEADER_DUNGEON
info.value = "party"
dd:ddAddButton(info, level)
info.text = RAID
info.value = "raid"
dd:ddAddButton(info, level)
info.text = ARENA
info.value = "arena"
dd:ddAddButton(info, level)
info.text = BATTLEGROUND
info.value = "pvp"
dd:ddAddButton(info, level)
info.list = nil
info.hasArrow = nil
info.notCheckable = nil
info.value = nil
info.isNotRadio = true
info.text = L["Character Specific"]
info.func = function(_,_,_, checked)
self.config.autoLoadChar = checked
self:setAutoLoadObj()
end
info.checked = self.config.autoLoadChar
dd:ddAddButton(info, level)
elseif level == 2 and type(value) == "table" then
info.notCheckable = true
info.isTitle = true
info.text = value.name
dd:ddAddButton(info, level)
info.isTitle = nil
info.text = L["Load"]
info.value = value
info.func = function(btn) self:loadProfileAddons(btn.value) end
dd:ddAddButton(info, level)
info.text = L["Save"]
info.func = function(btn) self:rewriteProfileAddons(btn.value) end
dd:ddAddButton(info, level)
info.text = L["Enable Addons"]
info.func = function(btn) self:enableProfileAddons(btn.value) end
dd:ddAddButton(info, level)
info.text = L["Disable Addons"]
info.func = function(btn) self:disableProfileAddons(btn.value) end
dd:ddAddButton(info, level)
dd:ddAddSpace(level)
info.notCheckable = nil
info.keepShownOnClick = true
info.isNotRadio = true
info.text = L["Highlight Addons"]
info.value = value.addons
info.func = function(btn, _,_, checked)
self.selProfileAddons = checked and btn.value or nil
self:updateList()
end
info.checked = self.selProfileAddons == value.addons
dd:ddAddButton(info, level)
dd:ddAddSpace(level)
info.func = nil
info.notCheckable = true
info.hasArrow = true
info.text = L["Also load profiles"]
info.value = value
dd:ddAddButton(info, level)
elseif level == 3 then
if type(value) == "string" then
if #self.profiles == 0 then
info.notCheckable = true
info.disabled = true
info.text = EMPTY
dd:ddAddButton(info, level)
return
end
local func = function(btn)
self.autoLoadProfiles[value] = btn.value
dd:ddRefresh(level)
end
local check = function(btn) return btn.value == self.autoLoadProfiles[value] end
local list = {
{
keepShownOnClick = true,
text = NONE,
func = func,
checked = check,
},
}
for i, profile in ipairs(self.profiles) do
list[#list + 1] = {
keepShownOnClick = true,
text = profile.name,
value = profile.name,
func = func,
checked = check,
}
end
info.list = list
dd:ddAddButton(info, level)
else
local list = {}
local func = function(btn, _,_, checked) self:setLoadProfiles(value, btn.value, checked) end
for i, profile in ipairs(self.profiles) do
if profile ~= value then
list[#list + 1] = {
keepShownOnClick = true,
isNotRadio = true,
text = profile.name,
value = profile.name,
func = func,
checked = value.loadProfiles and value.loadProfiles[profile.name],
}
end
end
if #list == 0 then
info.notCheckable = true
info.disabled = true
info.text = EMPTY
else
info.list = list
end
dd:ddAddButton(info, level)
end
end
end)
end)
function listFrame:setAutoLoadObj()
if self.config.autoLoadChar then
AddonMgrAutoLoadChar = AddonMgrAutoLoadChar or {}
self.autoLoadProfiles = AddonMgrAutoLoadChar
else
self.autoLoadProfiles = self.db.autoLoadProfiles
end
end
function listFrame:saveProfileAddons(profile)
wipe(profile.addons)
profile.count = 0
for i = 1, C_AddOns.GetNumAddOns() do
if C_AddOns.GetAddOnEnableState(i, self.addonCharacter) > Enum.AddOnEnableState.None then
profile.count = profile.count + 1
profile.addons[C_AddOns.GetAddOnInfo(i)] = 1
end
end
end
function listFrame:rewriteProfileAddons(profile)
StaticPopup_Show(self.addonName.."CUSTOM_OK_CANCEL", L["Rewrite addons to %s profile?"]:format(NORMAL_FONT_COLOR:WrapTextInColorCode(profile.name)), nil, function()
self:saveProfileAddons(profile)
self:updateList()
end)
end
function listFrame:getProfileDisplayName(profile, lastLoadName)
return ("%s |cff808080(%d %s)|r %s"):format(
profile.name,
profile.count,
ADDONS,
lastLoadName == profile.name and "|cffffd200(L)|r" or ""
)
end
function listFrame:setLastLoadProfileName(name)
if self.config.usePlayer then
self.config.lastLoadCharProfileName = self.config.lastLoadCharProfileName or {}
self.config.lastLoadCharProfileName[self.charGUID] = name
else
self.config.lastLoadCharProfileName = nil
self.config.lastLoadProfileName = name
end
end
function listFrame:getLastLoadProfileName()
if self.config.lastLoadCharProfileName then
local name = self.config.lastLoadCharProfileName[self.charGUID]
if name then return name end
end
return self.config.lastLoadProfileName
end
function listFrame:getProfileByName(name)
if name then
for _, profile in ipairs(self.profiles) do
if profile.name == name then return profile end
end
end
end
function listFrame:enableAddonsTree(profile, enabled, context)
context = context or {}
if context[profile] then return end
context[profile] = true
for addonName in next, profile.addons do
self:enableAddon(addonName, enabled)
end
if profile.loadProfiles then
for name in next, profile.loadProfiles do
local lProfile = self:getProfileByName(name)
if lProfile then self:enableAddonsTree(lProfile, enabled, context) end
end
end
end
function listFrame:loadProfile(profile, reloadCheck)
self.preLastLoadProfileName = nil
self:setAddonsEnabled(false)
self:enableAddonsTree(profile, true)
if reloadCheck then
self:setLastLoadProfileName(profile.name)
if self:hasAnyChanges() then
ReloadUI()
return
end
C_AddOns.SaveAddOns()
else
self.preLastLoadProfileName = profile.name
end
if self:IsShown() then
self:updateFilters()
self:updateReloadButton()
end
end
function listFrame:loadProfileByName(name, reloadCheck, hwEvent)
local profile = self:getProfileByName(name)
if profile then
if hwEvent then self:loadProfile(profile, reloadCheck)
else self:loadProfileAddons(profile, reloadCheck) end
end
end
function listFrame:loadProfileAddons(profile, reloadCheck)
local actionText = reloadCheck and L["Load %s profile and reload UI?"] or L["Load %s profile?"]
local dialog = StaticPopup_Show(self.addonName.."CUSTOM_OK_CANCEL", actionText:format(NORMAL_FONT_COLOR:WrapTextInColorCode(profile.name)), nil, function()
self:loadProfile(profile, reloadCheck)
end)
end
function listFrame:enableProfileAddons(profile)
StaticPopup_Show(self.addonName.."CUSTOM_OK_CANCEL", L["Enable addons from %s profile?"]:format(NORMAL_FONT_COLOR:WrapTextInColorCode(profile.name)), nil, function()
self:enableAddonsTree(profile, true)
self:updateFilters()
self:updateReloadButton()
end)
end
function listFrame:disableProfileAddons(profile)
StaticPopup_Show(self.addonName.."CUSTOM_OK_CANCEL", L["Disable addons from %s profile?"]:format(NORMAL_FONT_COLOR:WrapTextInColorCode(profile.name)), nil, function()
self:enableAddonsTree(profile, false)
self:updateFilters()
self:updateReloadButton()
end)
end
function listFrame:createProfile()
local dialog = StaticPopup_Show(self.addonName.."NEW_PROFILE", nil, nil, function(popup)
local editBox = popup.editBox or popup.EditBox
local text = editBox:GetText()
popup:Hide()
if text and text ~= "" then
local profile = self:getProfileByName(text)
if profile then
lastProfileName = text
profilePopupAction = self.createProfile
StaticPopup_Show(self.addonName.."PROFILE_EXISTS")
return
end
local profile = {name = text, addons = {}}
self:saveProfileAddons(profile)
self.profiles[#self.profiles + 1] = profile
sort(self.profiles, function(a, b) return strcmputf8i(a.name, b.name) < 0 end)
end
end)
if dialog and lastProfileName then
local editBox = dialog.editBox or dialog.EditBox
editBox:SetText(lastProfileName)
editBox:HighlightText()
end
end
function listFrame:editProfile(editProfile)
local dialog = StaticPopup_Show(self.addonName.."EDIT_PROFILE", nil, nil, function(popup)
local editBox = popup.editBox or popup.EditBox
local text = editBox:GetText()
popup:Hide()
if text and text ~= editProfile.name and text ~= "" then
local profile = self:getProfileByName(text)
if profile then
lastProfileName = text
profilePopupAction = self.editProfile
StaticPopup_Show(self.addonName.."PROFILE_EXISTS", nil, nil, editProfile)
return
end
editProfile.name = text
sort(self.profiles, function(a, b) return strcmputf8i(a.name, b.name) < 0 end)
end
end)
if dialog then
local editBox = dialog.editBox or dialog.EditBox
editBox:SetText(lastProfileName or editProfile.name)
editBox:HighlightText()
end
end
function listFrame:removeProfile(removeProfile, profiles)
StaticPopup_Show(self.addonName.."DELETE_PROFILE", NORMAL_FONT_COLOR:WrapTextInColorCode(removeProfile.name), nil, function()
for i, profile in ipairs(profiles) do
if profile == removeProfile then
tremove(profiles, i)
if self.selProfileAddons == removeProfile.addons then
self.selProfileAddons = nil
self:updateList()
end
else
self:setLoadProfiles(profile, removeProfile.name, false)
end
end
end)
end
function listFrame:removeAllCharProfiles()
StaticPopup_Show(self.addonName.."YOU_WANT", NORMAL_FONT_COLOR:WrapTextInColorCode(L["Remove all character profiles"]), nil, function()
wipe(self.charProfiles)
end)
end
function listFrame:setLoadProfiles(pProfile, cName, enabled)
if enabled then
pProfile.loadProfiles = pProfile.loadProfiles or {}
pProfile.loadProfiles[cName] = 1
elseif pProfile.loadProfiles then
pProfile.loadProfiles[cName] = nil
if not next(pProfile.loadProfiles) then
pProfile.loadProfiles = nil
end
end
end
function listFrame:getProfilesWithAddon(name)
local list = {}
for i = 1, #self.profiles do
local profile = self.profiles[i]
if profile.addons[name] then
list[#list + 1] = profile.name
end
end
return table.concat(list, ", ")
end