-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfig.lua
188 lines (158 loc) · 5.89 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
local ADDON_NAME, Addon = ...
local L = Addon.L
--------------------------------------------------------------------- Options --
Addon.options = {
type = 'group',
childGroups = 'tab',
args = {
general = {
type = 'group',
name = L['General Settings'],
order = 1,
args = {
-- addon-wide settings here
},
},
},
}
----------------------------------------------------------- Debugging Options --
Addon.options.args.debug = {
order = -1, -- alwas at the end?
type = 'group',
name = L["Debugging"],
desc = L["Module debugging menu."],
args = {
desc = {
order = 1,
type = 'description',
name = L["Debugging messages help developers or testers see "..
"what is happening in real time. Regular users should leave "..
"debugging turned off except when troubleshooting a problem."],
},
spacer = {
order = 3,
name = " ",
type = "description",
},
},
}
do
local function get(info)
return Addon:GetDebugStatus(info.arg)
end
local function set(info, value)
Addon:SetDebugStatus(info.arg, value)
end
function Addon:SetupDebugOptions(module)
local args = self.options.args.debug.args
local moduleName = module:GetName()
if not args[moduleName] then
args[moduleName] = {
name = moduleName,
desc = format(L["Enable debugging messages for the %s module."], moduleName),
type = "toggle",
get = get,
set = set,
-- This is passed with the 'info' in callbacks.
arg = module,
}
end
end
end
--------------------------------------------------------------------------------
-- Called in ADDON:OnInitialize, used to setup our options
function Addon:InitializeOptions()
LibStub('AceConfigRegistry-3.0'):RegisterOptionsTable(ADDON_NAME, self.options)
self.options.args.profile = LibStub('AceDBOptions-3.0'):GetOptionsTable(self.db)
self.options.args.profile.order = -1
-- Setup debuggin options for the core addon.
self:SetupDebugOptions(self)
-- REMOVE this line and if you're not using blizzard options.
if self.AddToBlizOptions then return self:AddToBlizOptions() end
end
function Addon:OpenOptions()
-- REMOVE this line and if you're not using blizzard options.
if self.OpenBlizOptions then return self:OpenBlizOptions() end
local Dialog = LibStub('AceConfigDialog-3.0')
if Dialog.OpenFrames[ADDON_NAME] then
Dialog:Close(ADDON_NAME)
else
Dialog:Open(ADDON_NAME)
end
end
-------------------------------------------------- Blizzard interface options --
-- REMOVE this section if you're not using blizzard options.
-- Keep track of panels in the blizzard options.
local blizOptionsPanels = {}
function Addon:AddToBlizOptions()
local panels = {}
-- Grab a list of possible panels
for k,v in pairs(self.options.args) do
if k~='general' then tinsert(panels, k) end
end
-- Sort the panels
table.sort(panels, function(a, b)
if not a then return true end
if not b then return false end
local orderA = self.options.args[a].order or 100
local orderB = self.options.args[b].order or 100
if orderA == orderB then
local nameA = self.options.args[a].name or ""
local nameB = self.options.args[b].name or ""
return nameA:upper() < nameB:upper()
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)
local Dialog = LibStub('AceConfigDialog-3.0')
-- Create the link to the general options
blizOptionsPanels['general'] = Dialog:AddToBlizOptions(ADDON_NAME, self:GetName(), nil, 'general')
-- Create a link for all the panels
for i=1,#panels do
local path = panels[i]
local name = self.options.args[path].name
blizOptionsPanels[path] = Dialog:AddToBlizOptions(ADDON_NAME, name, ADDON_NAME, path)
end
-- All options need to be registered before this is run, and since this is
-- run in ADDON:OnInitialize, modules need to setup their options before that.
-- Once this is called, panels are no longer sortable, and all new panels
-- will be added to the ned of the list.
end
-- TODO: Update to open to child elements
function Addon:OpenBlizOptions()
-- Start by opening the interface options so things can load
InterfaceOptionsFrame_Show()
-- Open to the second panel to expand the options
InterfaceOptionsFrame_OpenToCategory(blizOptionsPanels['profile'])
InterfaceOptionsFrame_OpenToCategory(blizOptionsPanels['general'])
InterfaceOptionsFrame:Raise()
-- TODO: Figure out why it wont open if its not visable
-- the user has to manually scroll the list to get access to it.
end
-------------------------------------------------------------- Slash commands --
Addon:RegisterChatCommand('rl', ReloadUI)
local function SlashHandler(input)
local arg = Addon:GetArgs(input, 1)
-- No argument, open options
if not arg then
Addon:OpenOptions()
-- Version Checking
-- TODO: find better pattern matching
elseif strmatch(strlower(arg), '^ve?r?s?i?o?n?$') then
Addon:Print(format(L['You are using version %s'], self.version))
else
-- Check for register module chat commands
for command, func in pairs(Addon.ModuleSlashCommands) do
if command == arg then
return func(input:sub(#arg+2))
end
end
end
end
-- Register multiple slash commands with the same handler.
Addon:RegisterChatCommand('ace', SlashHandler)
Addon:RegisterChatCommand('ace3test', SlashHandler)