-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOptions.lua
239 lines (214 loc) · 6.31 KB
/
Options.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
local type, pairs, tinsert, tsort = type, pairs, table.insert, table.sort
local Core = LibStub("TotemPlates")
local L = Core.L
Core.defaults = {
profile = {},
}
function Core:SetColor(option)
return option.r, option.g, option.b, option.a
end
function Core:option(params)
local defaults = {
get = function(info)
local key = info.arg or info[#info]
return Core.dbi.profile[key]
end,
set = function(info, value)
local key = info.arg or info[#info]
Core.dbi.profile[key] = value
Core:UpdateFrame()
end,
}
for k, v in pairs(params) do
defaults[k] = v
end
return defaults
end
function Core:colorOption(params)
local defaults = {
get = function(info)
local key = info.arg or info[#info]
return Core.dbi.profile[key].r, Core.dbi.profile[key].g, Core.dbi.profile[key].b, Core.dbi.profile[key].a
end,
set = function(info, r, g, b, a)
local key = info.arg or info[#info]
Core.dbi.profile[key].r, Core.dbi.profile[key].g, Core.dbi.profile[key].b, Core.dbi.profile[key].a = r, g, b, a
Core:UpdateFrame()
end,
}
for k, v in pairs(params) do
defaults[k] = v
end
return defaults
end
local function getOpt(info)
local key = info.arg or info[#info]
return Core.dbi.profile[key]
end
local function setOpt(info, value)
local key = info.arg or info[#info]
Core.dbi.profile[key] = value
Core:UpdateFrame()
end
function Core:GetFromMultipleOptions(options)
local val = options[1]
local isAllSameValue = true
for _,v in pairs(options) do
if type(v) == "table" then
if not (v.r == val.r and v.g == val.g and v.b == val.b and v.a == val.a) then
isAllSameValue = false
break
end
else
if val ~= v then
isAllSameValue = false
break
end
end
end
if type(val) == "table" then
if isAllSameValue then
return val.r, val.g, val.b, val.a
else
return 0,0,0,0
end
else
return isAllSameValue and val or ""
end
end
function Core:UpdateFrame()
for _, v in self:IterModules() do
self:Call(v, "UpdateFrame")
end
for _, v in self:IterModules() do
self:Call(v, "UpdateFrameOnce")
end
end
function Core:SetupModule(name, module, order)
local options = module:GetOptions()
if options then
self.options.args[name] = {
type = "group",
name = L[name],
desc = L[name] .. " " .. L["settings"],
childGroups = "tab",
order = order,
args = {},
}
if (type(options) == "table") then
self.options.args[name].args = options
self.options.args[name].args.reset = {
type = "execute",
name = L["Reset module"],
desc = L["Reset module to defaults"],
order = 1,
func = function()
for k, v in pairs(module.defaults) do
self.dbi.profile[k] = v
end
Core:UpdateFrame()
Core:SetupModule(name, module, order) -- For example click names are not reset by default
end
}
else
self.options.args[name].args.nothing = {
type = "description",
name = L["No settings"],
desc = L["Module has no settings"],
order = 1,
}
end
end
end
local function pairsByKeys(t)
local a = {}
for k in pairs(t) do
tinsert(a, k)
end
tsort(a, function(a, b) return L[a] < L[b] end)
local i = 0
return function()
i = i + 1
if (a[i] ~= nil) then
return a[i], t[a[i]]
else
return nil
end
end
end
function Core:ShowOptions()
InterfaceOptionsFrame_OpenToFrame("TotemPlates")
end
function Core:SetupOptions()
self.options = {
type = "group",
name = L["TotemPlates"],
plugins = {},
childGroups = "tree",
get = getOpt,
set = setOpt,
args = {
test = {
order = 2,
width = 0.7,
name = L["Test"],
desc = L["Show Test frames"],
type = "execute",
func = function()
Core:Test()
end,
},
hide = {
order = 3,
width = 0.7,
name = L["Hide"],
desc = L["Hide frames"],
type = "execute",
func = function()
Core:Reset()
end,
},
reload = {
order = 4,
width = 0.7,
name = L["ReloadUI"],
desc = L["Reloads the UI"],
type = "execute",
func = function()
ReloadUI()
end,
},
version = {
order = 5,
width = 1,
type = "description",
name = " " .. Core.version
},
},
}
local order = 6
for k, v in pairsByKeys(self.modules) do
self:SetupModule(k, v, order)
order = order + 1
end
local options = {
name = L["TotemPlates"],
type = "group",
args = {
load = {
name = L["Load configuration"],
desc = L["Load configuration options"],
type = "execute",
func = function()
HideUIPanel(InterfaceOptionsFrame)
HideUIPanel(GameMenuFrame)
LibStub("AceConfigDialog-3.0"):Open("TotemPlates")
end,
},
},
}
self.options.plugins.profiles = { profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.dbi) }
LibStub("AceConfig-3.0"):RegisterOptionsTable("TotemPlates_blizz", options)
LibStub("AceConfigDialog-3.0"):AddToBlizOptions("TotemPlates_blizz", "TotemPlates")
LibStub("AceConfig-3.0"):RegisterOptionsTable("TotemPlates", self.options)
end