-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaddonmanager.lua
More file actions
156 lines (124 loc) · 4.36 KB
/
addonmanager.lua
File metadata and controls
156 lines (124 loc) · 4.36 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
local UIC_MANAGER = 16777216
local managerWindow
---Corrects the widgets screen position to always be inside the screen.
---@param widget Widget
local function CorrectWidgetScreenPos(widget)
local x, y = widget:CorrectOffsetByScreen()
x = x / UIParent:GetUIScale()
y = y / UIParent:GetUIScale()
widget:RemoveAllAnchors()
widget:AddAnchor("TOPLEFT", "UIParent", x, y)
end
---Toggles a widget.
---@param subItem Widget
local function ToggleAddon(subItem)
local rowWindow = subItem:GetParent() ---@cast rowWindow ListCtrlItem
rowWindow.addon.enable = not rowWindow.addon.enable
ADDON:SetAddonEnable(rowWindow.addon.name, rowWindow.addon.enable)
ADDON:SaveAddonInfos()
ADDON:ReloadAddon(rowWindow.addon.name)
SetViewOfRow(rowWindow)
end
---Creates the addon manager window.
---@return Window
local function CreateManagerWindow()
local addons = ADDON:GetAddonInfos()
table.sort(addons, function (a, b) return a.name < b.name end)
local window = SetViewOfManagerWindow(addons)
local titleBar = window.titleBar ---@type Window
local closeButton = titleBar.closeButton ---@type Button
local contentFrame = window.contentFrame ---@type EmptyWidget
local scrollFrame = contentFrame.scrollFrame ---@type EmptyWidget
local addonsListCtrl = scrollFrame.addonsListCtrl ---@type ListCtrl
local sliderFrame = contentFrame.sliderFrame ---@type EmptyWidget
local upButton = sliderFrame.upButton ---@type Button
local downButton = sliderFrame.downButton ---@type Button
local slider = sliderFrame.slider ---@type Slider
window:SetSounds("bag")
window:EnableHidingIsRemove(true)
window:SetAlphaAnimation(0, 1, .1, .1)
window:SetStartAnimation(true, true)
titleBar:SetHandler("OnDragStart", function ()
window:StartMoving()
end)
titleBar:SetHandler("OnDragStop", function ()
window:StopMovingOrSizing()
CorrectWidgetScreenPos(window)
end)
window.isPinned = false
function titleBar:SetPin(pin)
if pin then
titleBar.titleStyle:SetColorByKey("red")
window:SetUILayer("system")
else
titleBar.titleStyle:SetColorByKey("title")
window:SetUILayer("normal")
end
window:Raise()
window:SetCloseOnEscape(not pin)
end
titleBar:SetPin(false)
titleBar:SetHandler("OnClick", function (self, mouseButton, doubleClick, keyModifier)
if doubleClick then
window.isPinned = not window.isPinned
titleBar:SetPin(window.isPinned)
end
end)
closeButton:SetHandler("OnClick", function ()
window:Show(false)
end)
upButton:SetHandler("OnClick", function ()
slider:Up(WINDOW.ITEM_DIMENSION)
end)
slider:SetHandler("OnSliderChanged", function (self, value)
scrollFrame:ChangeChildAnchorByScrollValue("vert", value)
end)
downButton:SetHandler("OnClick", function ()
slider:Down(WINDOW.ITEM_DIMENSION)
end)
slider:SetPageStep(WINDOW.ITEM_DIMENSION)
slider:SetValueStep(WINDOW.ITEM_DIMENSION)
slider:SetFixedThumb(true)
contentFrame:SetHandler("OnWheelUp", function ()
slider:Up(WINDOW.ITEM_DIMENSION)
end)
contentFrame:SetHandler("OnWheelDown", function ()
slider:Down(WINDOW.ITEM_DIMENSION)
end)
for row, addon in pairs(addons) do
local rowWindow = addonsListCtrl.items[row]
local checkButton, addonNameTextbox, settingsButton, refreshButton = unpack(
rowWindow.subItems
)
checkButton:SetHandler("OnClick", ToggleAddon)
addonNameTextbox:SetHandler("OnClick", ToggleAddon)
settingsButton:SetHandler("OnClick", function ()
ADDON:FireAddon(addon.name)
end)
refreshButton:SetHandler("OnClick", function ()
ADDON:ReloadAddon(addon.name)
end)
end
return window
end
---Toggles the addon manager window.
---@param show boolean|nil
local function ToggleManagerWindow(show)
-- If the window should be shown.
if show == nil then
show = managerWindow == nil or not managerWindow:IsVisible()
end
-- If the window should be shown and doesn't exist, create it.
if show == true and managerWindow == nil then
managerWindow = CreateManagerWindow()
managerWindow:SetDeletedHandler(function ()
managerWindow = nil
end)
end
-- If the window exists, Show or Hide it.
if managerWindow then
managerWindow:Show(show)
end
end
ADDON:RegisterContentTriggerFunc(UIC_MANAGER, ToggleManagerWindow)
ADDON:AddEscMenuButton(5, UIC_MANAGER, "optimizer", locale.addon.name)