-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfig.lua
284 lines (258 loc) · 9.44 KB
/
Config.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
local _G = _G
-- Locale
local L = LibStub("AceLocale-3.0"):GetLocale("APR-Recorder")
local L_APR = LibStub("AceLocale-3.0"):GetLocale("APR")
AprRC.settings = AprRC:NewModule("Settings", "AceConsole-3.0")
-- Ace option config table
local aceConfig = _G.LibStub("AceConfig-3.0")
local aceDialog = _G.LibStub("AceConfigDialog-3.0")
-- Databroker support -- minimapIcon
local libDataBroker = LibStub("LibDataBroker-1.1")
local libDBIcon = LibStub("LibDBIcon-1.0")
local function GetProfileOption(info) return AprRC.settings.profile[info[#info]] end
local function SetProfileOption(info, value)
AprRC.settings.profile[info[#info]] = value
end
function AprRC.settings:ResetSettings()
SettingsDB:ResetProfile()
self:RefreshProfile()
end
function AprRC.settings:InitializeBlizOptions()
self:InitializeSettings()
self:createBlizzOptions()
self:CreateMiniMapButton()
self:RegisterChatCommand("aprrc", self.ChatCommand)
end
function AprRC.settings:InitializeSettings()
-- Default setting
local settingsDBDefaults = {
profile = {
-- frame
recordBarFrame = {
rotation = "HORIZONTAL",
position = {},
isRecording = false,
},
commandBarFrame = {
rotation = "HORIZONTAL",
position = {},
tutorialShown = true
},
commandBarSettingFrame = {},
--debug
minimap = { minimapPos = 285 },
enableMinimapButton = true,
debug = false,
enableAddon = true,
}
}
SettingsDB = LibStub("AceDB-3.0"):New("AprRCSettings", settingsDBDefaults)
SettingsDB.RegisterCallback(self, "OnProfileChanged", "RefreshProfile")
SettingsDB.RegisterCallback(self, "OnProfileCopied", "RefreshProfile")
SettingsDB.RegisterCallback(self, "OnProfileReset", "RefreshProfile")
self.profile = SettingsDB.profile
end
function AprRC.settings.ChatCommand(input)
AprRC.command:SlashCmd(input)
end
function AprRC.settings:RefreshProfile()
self.profile = SettingsDB.profile
C_UI.Reload()
end
function AprRC.settings:createBlizzOptions()
-- Setting definition
local optionsTable = {
name = AprRC.title .. ' - ' .. AprRC.version,
type = "group",
args = {
discordButton = {
order = 1.1,
name = L_APR["JOIN_DISCORD"],
type = "execute",
width = 0.75,
func = function()
APR.questionDialog:CreateEditBoxPopup(L_APR["COPY_HELPER"], L_APR["CLOSE"], AprRC.discord)
end
},
githubButton = {
order = 1.2,
name = "Github",
type = "execute",
width = 0.75,
func = function()
APR.questionDialog:CreateEditBoxPopup(L_APR["COPY_HELPER"], L_APR["CLOSE"], AprRC.github)
end
},
buttonOffset = {
order = 1.3,
name = "",
type = "description",
width = 1.35,
},
resetButton = {
order = 1.4,
name = L_APR["RESET_SETTINGS"],
type = "execute",
width = 0.75,
func = function()
APR.questionDialog:CreateQuestionPopup(
nil,
function() AprRC.settings:ResetSettings() end
)
end
},
header_Automation = {
order = 2,
type = "header",
width = "full",
name = "Settings",
},
icon = {
order = 3,
type = "group",
name = "Minimap",
inline = true,
args = {
enableMinimapButton = {
name = L_APR["ENABLE_MINIMAP_BUTTON"],
desc = L_APR["ENABLE_MINIMAP_BUTTON_DESC"],
type = "toggle",
width = "full",
order = 3.1,
get = GetProfileOption,
set = function(info, value)
SetProfileOption(info, value)
if value then
libDBIcon:Show(AprRC.title)
else
libDBIcon:Hide(AprRC.title)
end
end
},
}
},
debug = {
order = 4,
type = "group",
name = "Debug",
inline = true,
args = {
enableAddon = {
order = 4.1,
type = "toggle",
name = L_APR["ENABLE_ADDON"],
width = "full",
get = GetProfileOption,
set = function(info, value)
SetProfileOption(info, value)
self:ToggleAddon()
end,
},
debug = {
order = 4.2,
type = "toggle",
name = L_APR["DEBUG"],
width = "full",
get = GetProfileOption,
set = SetProfileOption,
disabled = function()
return not self.profile.enableAddon
end,
},
}
},
}
}
-- Register setting to the option table
aceConfig:RegisterOptionsTable(AprRC.title, optionsTable)
-- Add settings to bliz option
AprRC.Options = aceDialog:AddToBlizOptions(AprRC.title, AprRC.title)
-- add profile to bliz option
aceConfig:RegisterOptionsTable(AprRC.title .. "/Profile", _G.LibStub("AceDBOptions-3.0"):GetOptionsTable(SettingsDB))
aceDialog:AddToBlizOptions(AprRC.title .. "/Profile", L_APR["PROFILES"], AprRC.title)
local category, layout = Settings.RegisterCanvasLayoutCategory(AprRC, AprRC.title);
AprRC.settings.category = category
end
function AprRC.settings:CreateMiniMapButton()
if not self.profile.enableMinimapButton then return end
local minimapButton = libDataBroker:NewDataObject(AprRC.title, {
type = "launcher",
icon = "Interface\\AddOns\\APR-Recorder\\assets\\logo",
OnClick = function(_, button)
if button == "RightButton" then
self.profile.enableAddon = not self.profile.enableAddon
self:ToggleAddon()
else
if SettingsPanel:IsShown() then
self:CloseSettings()
else
self:OpenSettings(AprRC.title)
end
end
end,
OnTooltipShow = function(tooltip)
local toggleAddon = ''
if self.profile.enableAddon then
toggleAddon = "|ccce0000f " .. L_APR["DISABLE"] .. "|r"
else
toggleAddon = "|cff00ff00 " .. L_APR["ENABLE"] .. "|r"
end
tooltip:AddLine(AprRC.title)
tooltip:AddLine(L_APR["LEFT_CLICK"] .. ": |cffeda55f" .. L_APR["SHOW_MENU"] .. "|r",
unpack(AprRC.Color.white))
tooltip:AddLine(L_APR["RIGHT_CLICK"] .. ": " .. toggleAddon .. "|cffeda55f " .. L_APR["ADDON"] .. "|r",
unpack(AprRC.Color.white))
end
})
libDBIcon:Register(AprRC.title, minimapButton, self.profile.minimap);
end
function AprRC.settings:ToggleAddon()
AprRC.record:RefreshFrameAnchor()
end
function AprRC.settings:OpenSettings(name)
if name == AprRC.title then
if InterfaceOptionsFrame_OpenToCategory then
InterfaceOptionsFrame_OpenToCategory(AprRC.title)
else
Settings.OpenToCategory(self.category.ID)
end
AprRC.settings:OpenSettings(L_APR["PROFILES"])
end
if AprRC.Options then
if SettingsPanel then
local category = SettingsPanel:GetCategoryList():GetCategory(AprRC.Options.name)
if category then
SettingsPanel:Open()
SettingsPanel:SelectCategory(category)
if AprRC.OptionsRoute and category:HasSubcategories() then
for _, subcategory in pairs(category:GetSubcategories()) do
if subcategory:GetName() == name then
SettingsPanel:SelectCategory(subcategory)
break
end
end
end
end
return
elseif InterfaceOptionsFrame_OpenToCategory then
InterfaceOptionsFrame_OpenToCategory(AprRC.Options)
if AprRC.OptionsRoute then
InterfaceOptionsFrame_OpenToCategory(AprRC.OptionsRoute)
end
return
else
Settings.OpenToCategory(self.category.ID)
end
end
end
function AprRC.settings:CloseSettings()
if AprRC.Options then
if SettingsPanel then
local category = SettingsPanel:GetCategoryList():GetCategory(AprRC.Options.name)
if category then
SettingsPanel:Hide()
end
return
end
end
end