forked from Eliote/SimpleAddonManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddonListFrame.lua
More file actions
509 lines (452 loc) · 15.6 KB
/
Copy pathAddonListFrame.lua
File metadata and controls
509 lines (452 loc) · 15.6 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
local _, T = ...
local L = T.L
local C = T.Color
local EDDM = LibStub("ElioteDropDownMenu-1.0")
local dropdownFrame = EDDM.UIDropDownMenu_GetOrCreate("SimpleAddonManager_MenuFrame")
--- @type SimpleAddonManager
local frame = T.AddonFrame
local module = frame:RegisterModule("AddonList")
local BANNED_ADDON = "BANNED"
local function AddonTooltipBuildDepsString(addonIndex)
local deps = { frame.compat.GetAddOnDependencies(addonIndex) }
local depsString = "";
for i, name in ipairs(deps) do
local color = C.white
if (not frame:IsAddonInstalled(name)) then
color = C.red
elseif (frame:IsAddonSelected(name)) then
color = C.green
end
if (i == 1) then
depsString = ADDON_DEPENDENCIES .. color:WrapText(name)
else
depsString = depsString .. ", " .. color:WrapText(name)
end
end
return depsString;
end
local function AddonTooltipBuildChildrenString(children)
local childrenString = "";
local first = true
for name, _ in pairs(children) do
local color = C.white
if (not frame:IsAddonInstalled(name)) then
color = C.red
elseif (frame:IsAddonSelected(name)) then
color = C.green
end
if (first) then
first = false
childrenString = L["AddOns: "] .. color:WrapText(name)
else
childrenString = childrenString .. ", " .. color:WrapText(name)
end
end
return childrenString;
end
local function EnableAllDeps(addonIndex)
local requiredDeps = { frame.compat.GetAddOnDependencies(addonIndex) }
for _, depName in ipairs(requiredDeps) do
if (frame:IsAddonInstalled(depName)) then
frame:EnableAddOn(depName)
EnableAllDeps(depName)
end
end
end
local function CreateAddonChildrenList(name)
local list = {}
for i = 1, frame.compat.GetNumAddOns() do
local addon = frame.compat.GetAddOnInfo(i)
local requiredDeps = { frame.compat.GetAddOnDependencies(i) }
for _, depName in ipairs(requiredDeps) do
if (depName == name) then
list[addon] = true
break
end
end
end
return list
end
local function SetAllChildren(children, state)
for name, _ in pairs(children) do
if (frame:IsAddonInstalled(name)) then
if (state) then
frame:EnableAddOn(name)
else
frame:DisableAddOn(name)
end
end
end
end
local function AddonRightClickMenu(addon)
if (not frame:IsAddonInstalled(addon.index)) then
return
end
local addonIndex = addon.index
local name, title, _, _, reason = frame.compat.GetAddOnInfo(addonIndex)
local menu = {
{ text = title, isTitle = true, notCheckable = true },
}
if (not frame.compat.IsAddOnLoaded(addonIndex) and frame.compat.IsAddOnLoadOnDemand(addonIndex) and reason == "DEMAND_LOADED") then
table.insert(menu, {
text = L["Load AddOn"],
func = function()
frame:Update()
end,
notCheckable = true,
})
end
if (frame.compat.GetAddOnDependencies(addonIndex)) then
table.insert(menu, {
text = L["Enable this Addon and its dependencies"],
func = function()
frame:EnableAddOn(addonIndex)
EnableAllDeps(addonIndex)
frame:Update()
end,
notCheckable = true,
tooltipOnButton = true,
tooltipTitle = title,
tooltipText = AddonTooltipBuildDepsString(addonIndex)
})
end
local children = CreateAddonChildrenList(name)
if (next(children)) then
table.insert(menu, {
text = L["Enable this and every AddOn that depends on it"],
func = function()
frame:EnableAddOn(addonIndex)
SetAllChildren(children, true)
frame:Update()
end,
notCheckable = true,
tooltipOnButton = true,
tooltipTitle = title,
tooltipText = AddonTooltipBuildChildrenString(children)
})
table.insert(menu, {
text = L["Disable this and every AddOn that depends on it"],
func = function()
frame:DisableAddOn(addonIndex)
SetAllChildren(children, false)
frame:Update()
end,
notCheckable = true,
tooltipOnButton = true,
tooltipTitle = title,
tooltipText = AddonTooltipBuildChildrenString(children)
})
end
table.insert(menu, T.separatorInfo)
table.insert(menu, { text = L["Categories"], isTitle = true, notCheckable = true })
local userCategories, tocCategories = frame:GetCategoryTables()
local sortedCategories = frame:TableKeysToSortedList(userCategories, tocCategories)
for _, categoryName in ipairs(sortedCategories) do
local categoryDb = userCategories[categoryName]
local tocCategory = tocCategories[categoryName]
local isInToc = tocCategory and tocCategory.addons and tocCategory.addons[name]
table.insert(menu, {
text = frame:LocalizeCategoryName(categoryName, not isInToc) .. (isInToc and (" " .. C.yellow:WrapText(L["(Automatically in category)"])) or ""),
checked = function()
return categoryDb and categoryDb.addons and categoryDb.addons[name]
end,
keepShownOnClick = true,
func = function(_, _, _, checked)
userCategories[categoryName] = userCategories[categoryName] or { name = categoryName }
userCategories[categoryName].addons = userCategories[categoryName].addons or {}
userCategories[categoryName].addons[name] = checked or nil
frame:Update()
end,
})
end
table.insert(menu, T.separatorInfo)
table.insert(menu, T.closeMenuInfo)
return menu
end
local function Checkbox_SetAddonState(self, enabled, addonIndex)
local checkedTexture = self.CheckedTexture
checkedTexture:SetVertexColor(1, 1, 1)
checkedTexture:SetDesaturated(false)
if (enabled) then
self:SetChecked(true)
else
local togglingMe = frame:GetCharacter() == 1
local enabledSome = (not togglingMe) and frame:IsAddonSelected(addonIndex, true)
if (enabledSome) then
self:SetChecked(true)
local isEnabledByMe = frame.compat.GetAddOnEnableState(addonIndex, UnitName("player")) == 2
if (isEnabledByMe) then
checkedTexture:SetVertexColor(0.4, 1.0, 0.4)
else
checkedTexture:SetDesaturated(true)
end
else
self:SetChecked(false)
end
end
end
local function ToggleAddon(self)
local addonIndex = self:GetParent().addon.index
local _, _, _, _, _, security = frame.compat.GetAddOnInfo(addonIndex)
if (security == BANNED_ADDON) then
return
end
local newValue = not frame:IsAddonSelected(addonIndex)
Checkbox_SetAddonState(self, newValue, addonIndex)
if (newValue) then
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON)
frame:EnableAddOn(addonIndex)
else
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_OFF)
frame:DisableAddOn(addonIndex)
end
frame:Update()
end
local function AddonButtonOnClick(self, mouseButton)
if (mouseButton == "LeftButton") then
ToggleAddon(self.EnabledButton)
else
EDDM.EasyMenu(AddonRightClickMenu(self.addon), dropdownFrame, "cursor", 0, 0, "MENU")
end
end
local function ProfilesInAddon(name)
local db = frame:GetDb()
local setsList = db.sets
local profilesForAddon = ""
local profilesTable = {}
for profileNameTable, subPair in pairs(setsList) do
local list = subPair.addons
for i, _ in pairs(list) do
if name == i then
table.insert(profilesTable, profileNameTable)
end
end
end
table.sort(profilesTable)
for _, profileName in ipairs(profilesTable) do
profilesForAddon = profilesForAddon .. profileName .. ", "
end
-- Remove Last 2 Characters cause whitespace and ','
profilesForAddon = string.sub(profilesForAddon, 0, strlen(profilesForAddon) - 2)
return profilesForAddon
end
local function UpdateTooltip(self)
local addonIndex = self.addon.index
local name, title, notes, _, reason, security = frame.compat.GetAddOnInfo(addonIndex)
GameTooltip:ClearLines();
GameTooltip:SetOwner(self, "ANCHOR_NONE")
GameTooltip:SetPoint("LEFT", self, "RIGHT")
if (security == BANNED_ADDON) then
GameTooltip:SetText(ADDON_BANNED_TOOLTIP);
else
if (title) then
GameTooltip:AddLine(title);
GameTooltip:AddLine(name, 0.7, 0.7, 0.7);
--GameTooltip:AddLine("debug: '" .. self.addon.name .. "'|r");
--GameTooltip:AddLine("dept: '" .. self.addon.dept .. "'|r");
--GameTooltip:AddLine("reason: '" .. (reason or "null") .. "'|r");
else
GameTooltip:AddLine(name);
end
if (reason == "MISSING") then
GameTooltip:AddLine(C.red:WrapText(L["This addons is not installed!"]), nil, nil, nil, true);
return
end
local version = frame:GetAddOnMetadata(addonIndex, "Version")
if (version) then
GameTooltip:AddLine(L["Version: "] .. C.white:WrapText(version));
end
local author = frame:GetAddOnMetadata(addonIndex, "Author")
if (author) then
GameTooltip:AddLine(L["Author: "] .. C.white:WrapText(strtrim(author)));
end
if (frame.compat.IsAddOnLoaded(addonIndex)) then
local mem = GetAddOnMemoryUsage(addonIndex)
GameTooltip:AddLine(L["Memory: "] .. C.white:WrapText(frame:FormatMemory(mem)));
end
GameTooltip:AddLine(AddonTooltipBuildDepsString(addonIndex), nil, nil, nil, true);
if (self.addon.warning) then
GameTooltip:AddLine(self.addon.warning, nil, nil, nil, true);
end
local profilesForAddon = ProfilesInAddon(name)
if profilesForAddon ~= "" then
GameTooltip:AddLine(L["Profiles: "] .. C.white:WrapText(profilesForAddon), nil, nil, nil, true);
end
GameTooltip:AddLine(" ");
GameTooltip:AddLine(notes, 1.0, 1.0, 1.0, true);
GameTooltip:AddLine(" ");
GameTooltip:AddLine("|A:newplayertutorial-icon-mouse-rightbutton:0:0|a " .. L["Right-click to edit"]);
end
GameTooltip:Show()
end
local function AddonButtonOnEnter(self)
if (frame:GetDb().config.memoryUpdate > 0) then
self.UpdateTooltip = UpdateTooltip
end
UpdateTooltip(self)
GameTooltip:Show()
end
local function AddonButtonOnLeave(self)
self.UpdateTooltip = nil
GameTooltip:Hide()
end
local function ShouldColorStatus(enabled, loaded, reason)
if (reason == "DEP_DEMAND_LOADED" or reason == "DEMAND_LOADED") then
return false
end
return (enabled and not loaded) or
(enabled and loaded and reason == "INTERFACE_VERSION")
end
local function UpdateExpandOrCollapseButtonState(button, isCollapsed)
if (isCollapsed) then
button:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-Up");
else
button:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-Up");
end
end
local function ExpandOrCollapseButtonOnClick(self)
local addon = self:GetParent().addon
frame:ToggleAddonCollapsed(addon.key, addon.parentKey)
frame:Update()
end
local function DeptMargin(dept)
return 13 * (dept or 0)
end
local function GetTitleWithIcon(addon)
local addonIndex = addon.index
local name, title = frame.compat.GetAddOnInfo(addonIndex)
local titleText = title or name
local version = ""
if (frame:GetDb().config.showVersions and addon.exists) then
version = frame:GetAddOnMetadata(addonIndex, "Version")
version = (version and C.grey:WrapText(" (" .. version .. ")")) or ""
end
local iconTexture = frame:GetAddOnMetadata(addonIndex, "IconTexture");
local iconAtlas = frame:GetAddOnMetadata(addonIndex, "IconAtlas");
if iconTexture and CreateSimpleTextureMarkup then
titleText = CreateSimpleTextureMarkup(iconTexture, 20, 20) .. " " .. titleText;
elseif iconAtlas and CreateAtlasMarkup then
titleText = CreateAtlasMarkup(iconAtlas, 20, 20) .. " " .. titleText;
end
return titleText .. version
end
local wowExpMargin = LE_EXPANSION_LEVEL_CURRENT >= 9 and 4 or 0
local function UpdateList()
local buttons = HybridScrollFrame_GetButtons(frame.ScrollFrame);
local offset = HybridScrollFrame_GetOffset(frame.ScrollFrame);
local buttonHeight;
local addons = frame:GetAddonsList()
local count = #addons
local isInTreeMode = frame:GetDb().config.addonListStyle == "tree"
for buttonIndex = 1, #buttons do
local button = buttons[buttonIndex]
button:SetPoint("LEFT", frame.ScrollFrame)
button:SetPoint("RIGHT", frame.ScrollFrame)
local relativeButtonIndex = buttonIndex + offset
buttonHeight = button:GetHeight()
if relativeButtonIndex <= count then
local addon = addons[relativeButtonIndex]
local addonIndex = addon.index
local _, _, _, loadable, reason, security = frame.compat.GetAddOnInfo(addonIndex)
local loaded = frame.compat.IsAddOnLoaded(addonIndex)
local enabled = frame:IsAddonSelected(addonIndex)
button.ExpandOrCollapseButton:SetScript("OnClick", ExpandOrCollapseButtonOnClick)
local showExpandOrCollapseButton = isInTreeMode and addon.children and next(addon.children)
local isCollapsed = frame:IsAddonCollapsed(addon.key, addon.parentKey)
if showExpandOrCollapseButton then
button.ExpandOrCollapseButton:Show()
UpdateExpandOrCollapseButtonState(
button.ExpandOrCollapseButton,
isCollapsed
)
else
button.ExpandOrCollapseButton:Hide()
end
local expandOrCollapseButtonSize = isInTreeMode and button.ExpandOrCollapseButton:GetWidth() or 0
local marginCorrection = isInTreeMode and 3 or 0
local margin = DeptMargin(addon.dept) + expandOrCollapseButtonSize + marginCorrection + wowExpMargin
button.Name:SetPoint("TOPLEFT", 30 + margin, 0)
button.EnabledButton:SetPoint("LEFT", 4 + margin, 0)
button.Name:SetText(GetTitleWithIcon(addon))
if (loadable or (enabled and (reason == "DEP_DEMAND_LOADED" or reason == "DEMAND_LOADED"))) then
button.Name:SetTextColor(C.yellow:GetRGB());
elseif enabled then
button.Name:SetTextColor(C.red:GetRGB());
elseif reason == "MISSING" then
button.Name:SetTextColor(C.red:GetRGB());
else
button.Name:SetTextColor(C.grey:GetRGB());
end
button.addon = addon
button.Status:SetTextColor(C.grey:GetRGB());
button.Status:SetText((not loaded and not loadable and reason and _G["ADDON_" .. reason]) or "")
if (ShouldColorStatus(enabled, loaded, reason)) then
button.Status:SetTextColor(C.red:GetRGB());
if (reason == nil) then
button.Status:SetText(REQUIRES_RELOAD)
end
end
Checkbox_SetAddonState(button.EnabledButton, enabled, addonIndex)
button.EnabledButton:SetScript("OnClick", ToggleAddon)
button.EnabledButton:SetEnabled(security ~= BANNED_ADDON and addon.exists)
button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
button:SetScript("OnClick", AddonButtonOnClick)
button:SetScript("OnEnter", AddonButtonOnEnter)
button:SetScript("OnLeave", AddonButtonOnLeave)
button:Show()
else
button:Hide()
end
end
HybridScrollFrame_Update(frame.ScrollFrame, count * buttonHeight, frame.ScrollFrame:GetHeight())
end
local function OnSizeChanged(self)
local offsetBefore = self:GetValue()
HybridScrollFrame_CreateButtons(self:GetParent(), "SimpleAddonManagerAddonItem")
self:SetValue(offsetBefore)
self:GetParent().update()
end
local function UpdateMemory()
UpdateAddOnMemoryUsage()
end
local function OnShow()
frame:UpdateMemoryTickerPeriod(frame:GetDb().config.memoryUpdate)
UpdateMemory()
end
local function OnHide()
frame:UpdateMemoryTickerPeriod(0)
end
function frame:UpdateMemoryTickerPeriod(period)
if (self.MemoryUpdateTicker) then
self.MemoryUpdateTicker:Cancel()
self.MemoryUpdateTicker = nil
end
if (period > 0) then
self.MemoryUpdateTicker = C_Timer.NewTicker(period, UpdateMemory)
end
end
function module:PreInitialize()
frame.ScrollFrame = CreateFrame("ScrollFrame", nil, frame, "HybridScrollFrameTemplate")
frame.ScrollFrame:SetScript("OnMouseWheel", frame.HybridScrollFrame_ShiftAwareOnScrollWheel)
frame.ScrollFrame.ScrollBar = CreateFrame("Slider", nil, frame.ScrollFrame, "HybridScrollBarTemplate")
end
function module:Initialize()
frame.ScrollFrame:Hide()
frame.ScrollFrame:SetPoint("TOPLEFT", 7, -64)
frame.ScrollFrame:SetPoint("BOTTOMRIGHT", -30, 30)
frame.ScrollFrame:SetScript("OnShow", OnShow)
frame.ScrollFrame:SetScript("OnHide", OnHide)
frame.ScrollFrame.update = UpdateList
frame.ScrollFrame:Show()
frame.ScrollFrame.ScrollBar:SetPoint("TOPLEFT", frame.ScrollFrame, "TOPRIGHT", 1, -16)
frame.ScrollFrame.ScrollBar:SetPoint("BOTTOMLEFT", frame.ScrollFrame, "BOTTOMRIGHT", 1, 12)
frame.ScrollFrame.ScrollBar:SetScript("OnSizeChanged", OnSizeChanged)
frame.ScrollFrame.ScrollBar.doNotHide = true
HybridScrollFrame_CreateButtons(frame.ScrollFrame, "SimpleAddonManagerAddonItem")
end
function module:OnLoad()
local db = frame:GetDb()
frame:CreateDefaultOptions(db.config, {
memoryUpdate = 0
})
end