-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTheModule.lua
221 lines (201 loc) · 6.19 KB
/
TheModule.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
local ADDON_NAME, Addon = ...
---------------------------------------------------------------- Setup Module --
local MODULE_NAME = 'TheModule'
local Module = Addon:NewModule(MODULE_NAME)
local L = Addon.L
-------------------------------------------------------------------- Database --
local defaultDB = {
profile = {
},
}
--------------------------------------------------------------------- Options --
-- Makes the order they are created the order they are displayed
local new_order
do
local current = 0
function new_order()
current = current + 1
return current
end
end
Module.options = {
type = 'group',
name = L['The Module'],
get = function(info) return Module.db.profile[info[#info]] end,
set = function(info, value) Module.db.profile[info[#info]] = value end,
args = {
intro1 = {
order = new_order(),
type = 'description',
name = L['Demo options'],
fontSize = 'large',
},
intro2 = {
order = new_order(),
type = 'description',
name = L['This module is just a space to test out how options are built. '
..'Each and every possible type of input type. Each type is '
..'grouped together.']
},
}
}
-- The options table is split here to show that you dont need to build it all at once.
Module.options.args.executes = {
type = 'group', inline = true, order = new_order(),
name = L['Execute types'],
args = {
execute = {
type = 'execute',
name = L['Execute'],
func = function() Module:Print('Execute type pressed!')end,
}
}
}
Module.options.args.inputs = {
type = 'group', inline = true, order = new_order(),
name = L['Inputs types'],
args = {
input = {
type = 'input',
name = L['Input'],
},
input_multiline = {
type = 'input',
name = L['Input Multi-line'],
multiline = true,
width = 'double',
},
}
}
Module.options.args.toggles = {
type = 'group', inline = true, order = new_order(),
name = L['Toggle types'],
args = {
toggle = {
type = 'toggle',
name = L['Toggle'],
},
toggle_tristate = {
type = 'toggle',
name = L['Toggle Tristate'],
tristate = true,
}
}
}
Module.options.args.ranges = {
type = 'group', inline = true, order = new_order(),
name = L['Range types'],
args = {
range = {
type = 'range',
name = L['Range'],
min = 1, max = 100,
},
range_percent = {
type = 'range',
name = L['Range Percent'],
isPercent = true,
min = -1, max = 1,
},
range_bigstep = {
type = 'range',
name = L['Range Bigstep'],
min = 0, max = 100, bigStep = 10,
},
}
}
local function getSelectValues()
return {'First value','Second value','Third value','Fourth value','Fifth value','Sixth value'}
end
Module.options.args.selects = {
type = 'group', inline = true, order = new_order(),
name = L['Select types'],
args = {
select = {
type = 'select',
name = L['Select'],
values = getSelectValues,
},
radioselect = {
type = 'select',
name = L['Radio Select'],
style = 'radio',
values = getSelectValues,
},
}
}
Module.options.args.multiselects = {
type = 'group', inline = true, order = new_order(),
name = L["Multi Selects types"],
-- Multiselect requires a extra table to store the state of each value
get = function(info, key)
Module.db.profile[info[#info]] = Module.db.profile[info[#info]] or {}
return Module.db.profile[info[#info]][key]
end,
set = function(info, key, value)
Module.db.profile[info[#info]] = Module.db.profile[info[#info]] or {}
Module.db.profile[info[#info]][key] = value
end,
args = {
multiselect = {
type = 'multiselect',
name = L["Multi Select"],
values = getSelectValues,
},
multiselecttristate = {
type = 'multiselect',
name = L["Multi Select Tristate"],
tristate = true,
values = getSelectValues,
}
}
}
Module.options.args.colors = {
type = 'group', inline = true, order = new_order(),
name = L["Colors"],
-- Colors deal with multiple values. r,g,b,a
get = function(info) return unpack(Module.db.profile[info[#info]] or {}) end,
set = function(info, ...) Module.db.profile[info[#info]] = {...} end,
args = {
color = {
type = 'color',
name = L["Color"],
},
coloralpha = {
type = 'color',
name = L["Color with Alpha"],
hasAlpha = true,
},
}
}
-- Register the modules with the Addon
Addon.options.args[MODULE_NAME] = Module.options
---------------------------------------------------------------- Core Methods --
function Module:OnInitialize()
-- Modules are responseable for setting their own database
self.db = Addon.db:RegisterNamespace(MODULE_NAME, defaultDB)
-- ... and their own databse callbacks
self.db.RegisterCallback(self, "OnProfileChanged", "OnProfileRefresh")
self.db.RegisterCallback(self, "OnProfileCopied", "OnProfileRefresh")
self.db.RegisterCallback(self, "OnProfileReset", "OnProfileRefresh")
self:RegisterSlashCommand('test', function(input)
local arg = self:GetArgs(input, 1)
self:Print('This is from the module.')
if arg then
self:Print('You passed the argument "'..arg..'"')
else
self:Print('You didnt pass anything')
end
end)
self:Debug('OnInitialize Trigered')
end
function Module:OnEnable()
self:Debug('OnEnabled Trigered')
end
function Module:OnDisable()
self:Debug('OnDisable Trigered')
end
function Module:OnProfileRefresh()
self:Debug('OnProfileRefresh Trigered')
end
------------------------------------------------------------------------- Fin --