vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | Name: AceConsole-2.0 |
||
3 | Revision: $Rev: 15051 $ |
||
4 | Developed by: The Ace Development Team (http://www.wowace.com/index.php/The_Ace_Development_Team) |
||
5 | Inspired By: Ace 1.x by Turan (turan@gryphon.com) |
||
6 | Website: http://www.wowace.com/ |
||
7 | Documentation: http://www.wowace.com/index.php/AceConsole-2.0 |
||
8 | SVN: http://svn.wowace.com/root/trunk/Ace2/AceConsole-2.0 |
||
9 | Description: Mixin to allow for input/output capabilities. This uses the |
||
10 | AceOptions data table format to determine input. |
||
11 | http://wiki.wowace.com/index.php/AceOptions_data_table |
||
12 | Dependencies: AceLibrary, AceOO-2.0 |
||
13 | ]] |
||
14 | |||
15 | local MAJOR_VERSION = "AceConsole-2.0" |
||
16 | local MINOR_VERSION = "$Revision: 15051 $" |
||
17 | |||
18 | if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary.") end |
||
19 | if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end |
||
20 | |||
21 | if not AceLibrary:HasInstance("AceOO-2.0") then error(MAJOR_VERSION .. " requires AceOO-2.0.") end |
||
22 | |||
23 | local MAP_ONOFF, USAGE, IS_CURRENTLY_SET_TO, IS_NOW_SET_TO, IS_NOT_A_VALID_OPTION_FOR, IS_NOT_A_VALID_VALUE_FOR, NO_OPTIONS_AVAILABLE, OPTION_HANDLER_NOT_FOUND, OPTION_HANDLER_NOT_VALID, OPTION_IS_DISABLED |
||
24 | if GetLocale() == "deDE" then |
||
25 | MAP_ONOFF = { [false] = "|cffff0000Aus|r", [true] = "|cff00ff00An|r" } |
||
26 | USAGE = "Benutzung" |
||
27 | IS_CURRENTLY_SET_TO = "|cffffff7f%s|r steht momentan auf |cffffff7f[|r%s|cffffff7f]|r" |
||
28 | IS_NOW_SET_TO = "|cffffff7f%s|r ist nun auf |cffffff7f[|r%s|cffffff7f]|r gesetzt" |
||
29 | IS_NOT_A_VALID_OPTION_FOR = "[|cffffff7f%s|r] ist keine g\195\188ltige Option f\195\188r |cffffff7f%s|r" |
||
30 | IS_NOT_A_VALID_VALUE_FOR = "[|cffffff7f%s|r] ist kein g\195\188ltiger Wert f\195\188r |cffffff7f%s|r" |
||
31 | NO_OPTIONS_AVAILABLE = "Keine Optionen verfügbar" |
||
32 | OPTION_HANDLER_NOT_FOUND = "Optionen handler |cffffff7f%q|r nicht gefunden." |
||
33 | OPTION_HANDLER_NOT_VALID = "Optionen handler nicht g\195\188ltig." |
||
34 | OPTION_IS_DISABLED = "Option |cffffff7f%s|r deaktiviert." |
||
35 | elseif GetLocale() == "frFR" then |
||
36 | MAP_ONOFF = { [false] = "|cffff0000Inactif|r", [true] = "|cff00ff00Actif|r" } |
||
37 | USAGE = "Utilisation" |
||
38 | IS_CURRENTLY_SET_TO = "|cffffff7f%s|r est actuellement positionn\195\169 sur |cffffff7f[|r%s|cffffff7f]|r" |
||
39 | IS_NOW_SET_TO = "|cffffff7f%s|r est maintenant positionn\195\169 sur |cffffff7f[|r%s|cffffff7f]|r" |
||
40 | IS_NOT_A_VALID_OPTION_FOR = "[|cffffff7f%s|r] n'est pas une option valide pour |cffffff7f%s|r" |
||
41 | IS_NOT_A_VALID_VALUE_FOR = "[|cffffff7f%s|r] n'est pas une valeur valide pour |cffffff7f%s|r" |
||
42 | NO_OPTIONS_AVAILABLE = "Pas d'options disponibles" |
||
43 | OPTION_HANDLER_NOT_FOUND = "Le gestionnaire d'option |cffffff7f%q|r n'a pas \195\169t\195\169 trouv\195\169." |
||
44 | OPTION_HANDLER_NOT_VALID = "Le gestionnaire d'option n'est pas valide." |
||
45 | OPTION_IS_DISABLED = "L'option |cffffff7f%s|r est d\195\169sactiv\195\169e." |
||
46 | elseif GetLocale() == "koKR" then |
||
47 | MAP_ONOFF = { [false] = "|cffff0000끔|r", [true] = "|cff00ff00켬|r" } |
||
48 | USAGE = "사용법" |
||
49 | IS_CURRENTLY_SET_TO = "|cffffff7f%s|r|1은;는; 현재 상태는 |cffffff7f[|r%s|cffffff7f]|r|1으로;로; 설정되어 있습니다" |
||
50 | IS_NOW_SET_TO = "|cffffff7f%s|r|1을;를; |cffffff7f[|r%s|cffffff7f]|r 상태로 변경합니다" |
||
51 | IS_NOT_A_VALID_OPTION_FOR = "[|cffffff7f%s|r]|1은;는; |cffffff7f%s|r에서 사용불가능한 설정입니다" |
||
52 | IS_NOT_A_VALID_VALUE_FOR = "[|cffffff7f%s|r]|1은;는; |cffffff7f%s|r에서 사용불가능한 설정값입니다" |
||
53 | NO_OPTIONS_AVAILABLE = "가능한 설정이 없습니다" |
||
54 | OPTION_HANDLER_NOT_FOUND = "설정 조정값인 |cffffff7f%q|r|1을;를; 찾지 못했습니다." |
||
55 | OPTION_HANDLER_NOT_VALID = "설정 조정값이 올바르지 않습니다." |
||
56 | OPTION_IS_DISABLED = "|cffffff7f%s|r 설정은 사용할 수 없습니다." |
||
57 | elseif GetLocale() == "zhCN" then |
||
58 | MAP_ONOFF = { [false] = "|cffff0000\229\133\179\233\151\173|r", [true] = "|cff00ff00\229\188\128\229\144\175|r" } |
||
59 | USAGE = "\231\148\168\230\179\149" |
||
60 | IS_CURRENTLY_SET_TO = "|cffffff7f%s|r \229\189\147\229\137\141\232\162\171\232\174\190\231\189\174 |cffffff7f[|r%s|cffffff7f]|r" |
||
61 | IS_NOW_SET_TO = "|cffffff7f%s|r \231\142\176\229\156\168\232\162\171\232\174\190\231\189\174\228\184\186 |cffffff7f[|r%s|cffffff7f]|r" |
||
62 | IS_NOT_A_VALID_OPTION_FOR = "[|cffffff7f%s|r] \228\184\141\230\152\175\228\184\128\228\184\170\230\156\137\230\149\136\231\154\132\233\128\137\233\161\185 \228\184\186 |cffffff7f%s|r" |
||
63 | IS_NOT_A_VALID_VALUE_FOR = "[|cffffff7f%s|r] \228\184\141\230\152\175\228\184\128\228\184\170\230\156\137\230\149\136\229\128\188 \228\184\186 |cffffff7f%s|r" |
||
64 | NO_OPTIONS_AVAILABLE = "\230\178\161\230\156\137\233\128\137\233\161\185\229\143\175\231\148\168" |
||
65 | OPTION_HANDLER_NOT_FOUND = "\233\128\137\233\161\185\229\164\132\231\144\134\231\168\139\229\186\143 |cffffff7f%q|r \230\178\161\230\159\165\230\137\190." |
||
66 | OPTION_HANDLER_NOT_VALID = "\233\128\137\233\161\185\229\164\132\231\144\134\231\168\139\229\186\143 \230\151\160\230\149\136." |
||
67 | OPTION_IS_DISABLED = "\233\128\137\233\161\185 |cffffff7f%s|r \228\184\141\229\174\140\230\149\180." |
||
68 | elseif GetLocale() == "zhTW" then |
||
69 | MAP_ONOFF = { [false] = "|cffff0000關閉|r", [true] = "|cff00ff00開啟|r" } |
||
70 | USAGE = "用法" |
||
71 | IS_CURRENTLY_SET_TO = "|cffffff7f%s|r 目前的設定為 |cffffff7f[|r%s|cffffff7f]|r" |
||
72 | IS_NOW_SET_TO = "|cffffff7f%s|r 現在被設定為 |cffffff7f[|r%s|cffffff7f]|r" |
||
73 | IS_NOT_A_VALID_OPTION_FOR = "[|cffffff7f%s|r] 是一個不符合規定的選項,對 |cffffff7f%s|r" |
||
74 | IS_NOT_A_VALID_VALUE_FOR = "[|cffffff7f%s|r] 是一個不符合規定的數值,對 |cffffff7f%s|r" |
||
75 | NO_OPTIONS_AVAILABLE = "沒有可用的選項處理器。" |
||
76 | OPTION_HANDLER_NOT_FOUND = "找不到 |cffffff7f%q|r 選項處理器。" |
||
77 | OPTION_HANDLER_NOT_VALID = "選項處理器不符合規定。" |
||
78 | OPTION_IS_DISABLED = "|cffffff7f%s|r 已被停用。" |
||
79 | else -- enUS |
||
80 | MAP_ONOFF = { [false] = "|cffff0000Off|r", [true] = "|cff00ff00On|r" } |
||
81 | USAGE = "Usage" |
||
82 | IS_CURRENTLY_SET_TO = "|cffffff7f%s|r is currently set to |cffffff7f[|r%s|cffffff7f]|r" |
||
83 | IS_NOW_SET_TO = "|cffffff7f%s|r is now set to |cffffff7f[|r%s|cffffff7f]|r" |
||
84 | IS_NOT_A_VALID_OPTION_FOR = "[|cffffff7f%s|r] is not a valid option for |cffffff7f%s|r" |
||
85 | IS_NOT_A_VALID_VALUE_FOR = "[|cffffff7f%s|r] is not a valid value for |cffffff7f%s|r" |
||
86 | NO_OPTIONS_AVAILABLE = "No options available" |
||
87 | OPTION_HANDLER_NOT_FOUND = "Option handler |cffffff7f%q|r not found." |
||
88 | OPTION_HANDLER_NOT_VALID = "Option handler not valid." |
||
89 | OPTION_IS_DISABLED = "Option |cffffff7f%s|r is disabled." |
||
90 | end |
||
91 | |||
92 | local NONE = NONE or "None" |
||
93 | |||
94 | local AceOO = AceLibrary("AceOO-2.0") |
||
95 | local AceEvent |
||
96 | |||
97 | local AceConsole = AceOO.Mixin { "Print", "PrintComma", "CustomPrint", "RegisterChatCommand" } |
||
98 | local Dewdrop |
||
99 | |||
100 | local _G = getfenv(0) |
||
101 | |||
102 | local table_setn |
||
103 | do |
||
104 | local version = GetBuildInfo() |
||
105 | if string.find(version, "^2%.") then |
||
106 | -- 2.0.0 |
||
107 | table_setn = function() end |
||
108 | else |
||
109 | table_setn = table.setn |
||
110 | end |
||
111 | end |
||
112 | |||
113 | local function print(text, name, r, g, b, frame, delay) |
||
114 | if not text or string.len(text) == 0 then |
||
115 | text = " " |
||
116 | end |
||
117 | if not name or name == AceConsole then |
||
118 | (frame or DEFAULT_CHAT_FRAME):AddMessage(text, r, g, b, nil, delay or 5) |
||
119 | else |
||
120 | (frame or DEFAULT_CHAT_FRAME):AddMessage("|cffffff78" .. tostring(name) .. ":|r " .. text, r, g, b, nil, delay or 5) |
||
121 | end |
||
122 | end |
||
123 | |||
124 | local tmp |
||
125 | function AceConsole:CustomPrint(r, g, b, frame, delay, connector, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) |
||
126 | a1 = tostring(a1) |
||
127 | if string.find(a1, "%%") then |
||
128 | print(string.format(a1, tostring(a2), tostring(a3), tostring(a4), tostring(a5), tostring(a6), tostring(a7), tostring(a8), tostring(a9), tostring(a10), tostring(a11), tostring(a12), tostring(a13), tostring(a14), tostring(a15), tostring(a16), tostring(a17), tostring(a18), tostring(a19), tostring(a20)), self, r, g, b, frame or self.printFrame, delay) |
||
129 | else |
||
130 | if not tmp then |
||
131 | tmp = {} |
||
132 | end |
||
133 | tmp[1] = a1 |
||
134 | tmp[2] = a2 |
||
135 | tmp[3] = a3 |
||
136 | tmp[4] = a4 |
||
137 | tmp[5] = a5 |
||
138 | tmp[6] = a6 |
||
139 | tmp[7] = a7 |
||
140 | tmp[8] = a8 |
||
141 | tmp[9] = a9 |
||
142 | tmp[10] = a10 |
||
143 | tmp[11] = a11 |
||
144 | tmp[12] = a12 |
||
145 | tmp[13] = a13 |
||
146 | tmp[14] = a14 |
||
147 | tmp[15] = a15 |
||
148 | tmp[16] = a16 |
||
149 | tmp[17] = a17 |
||
150 | tmp[18] = a18 |
||
151 | tmp[19] = a19 |
||
152 | tmp[20] = a20 |
||
153 | local n = 20 |
||
154 | while tmp[n] == nil do |
||
155 | n = n - 1 |
||
156 | end |
||
157 | table_setn(tmp, n) |
||
158 | for k = 1, n do |
||
159 | tmp[k] = tostring(tmp[k]) |
||
160 | end |
||
161 | print(table.concat(tmp, connector or " "), self, r, g, b, frame or self.printFrame, delay) |
||
162 | for k,v in pairs(tmp) do |
||
163 | tmp[k] = nil |
||
164 | end |
||
165 | table_setn(tmp, 0) |
||
166 | end |
||
167 | end |
||
168 | |||
169 | function AceConsole:Print(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) |
||
170 | return AceConsole.CustomPrint(self, nil, nil, nil, nil, nil, " ", a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) |
||
171 | end |
||
172 | |||
173 | function AceConsole:PrintComma(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) |
||
174 | return AceConsole.CustomPrint(self, nil, nil, nil, nil, nil, ", ", a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) |
||
175 | end |
||
176 | |||
177 | local work |
||
178 | local argwork |
||
179 | |||
180 | local string_gfind = string.gmatch or string.gfind |
||
181 | |||
182 | local function findTableLevel(self, options, chat, text, index, passTable) |
||
183 | if not index then |
||
184 | index = 1 |
||
185 | if work then |
||
186 | for k,v in pairs(work) do |
||
187 | work[k] = nil |
||
188 | end |
||
189 | table_setn(work, 0) |
||
190 | for k,v in pairs(argwork) do |
||
191 | argwork[k] = nil |
||
192 | end |
||
193 | table_setn(argwork, 0) |
||
194 | else |
||
195 | work = {} |
||
196 | argwork = {} |
||
197 | end |
||
198 | local len = string.len(text) |
||
199 | local count |
||
200 | repeat |
||
201 | text, count = string.gsub(text, "(|cff%x%x%x%x%x%x|Hitem:%d-:%d-:%d-:%d-|h%[[^%]]-) (.-%]|h|r)", "%1\001%2") |
||
202 | until count == 0 |
||
203 | text = string.gsub(text, "(%]|h|r)(|cff%x%x%x%x%x%x|Hitem:%d-:%d-:%d-:%d-|h%[)", "%1 %2") |
||
204 | for token in string_gfind(text, "([^%s]+)") do |
||
205 | local token = token |
||
206 | local num = tonumber(token) |
||
207 | if num then |
||
208 | token = num |
||
209 | else |
||
210 | token = string.gsub(token, "\001", " ") |
||
211 | end |
||
212 | table.insert(work, token) |
||
213 | end |
||
214 | end |
||
215 | |||
216 | local path = chat |
||
217 | for i = 1, index - 1 do |
||
218 | path = path .. " " .. tostring(work[i]) |
||
219 | end |
||
220 | |||
221 | if type(options.args) == "table" then |
||
222 | local disabled, hidden = options.disabled, options.cmdHidden or options.hidden |
||
223 | if hidden then |
||
224 | if type(hidden) == "function" then |
||
225 | hidden = hidden() |
||
226 | elseif type(hidden) == "string" then |
||
227 | local handler = options.handler or self |
||
228 | if type(handler[hidden]) ~= "function" then |
||
229 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, hidden) |
||
230 | end |
||
231 | hidden = handler[hidden](handler) |
||
232 | end |
||
233 | end |
||
234 | if hidden then |
||
235 | disabled = true |
||
236 | elseif disabled then |
||
237 | if type(disabled) == "function" then |
||
238 | disabled = disabled() |
||
239 | elseif type(disabled) == "string" then |
||
240 | local handler = options.handler or self |
||
241 | if type(handler[disabled]) ~= "function" then |
||
242 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, disabled) |
||
243 | end |
||
244 | disabled = handler[disabled](handler) |
||
245 | end |
||
246 | end |
||
247 | if not disabled then |
||
248 | local next = work[index] and string.lower(work[index]) |
||
249 | if next then |
||
250 | for k,v in pairs(options.args) do |
||
251 | local good = false |
||
252 | if string.lower(k) == next then |
||
253 | good = true |
||
254 | elseif type(v.aliases) == "table" then |
||
255 | for _,alias in ipairs(v.aliases) do |
||
256 | if string.lower(alias) == next then |
||
257 | good = true |
||
258 | break |
||
259 | end |
||
260 | end |
||
261 | elseif type(v.aliases) == "string" and string.lower(v.aliases) == next then |
||
262 | good = true |
||
263 | end |
||
264 | if good then |
||
265 | return findTableLevel(options.handler or self, v, chat, text, index + 1, options.pass and options or nil) |
||
266 | end |
||
267 | end |
||
268 | end |
||
269 | end |
||
270 | end |
||
271 | for i = index, table.getn(work) do |
||
272 | table.insert(argwork, work[i]) |
||
273 | end |
||
274 | return options, path, argwork, options.handler or self, passTable, passTable and work[index - 1] |
||
275 | end |
||
276 | |||
277 | local function validateOptionsMethods(self, options, position) |
||
278 | if type(options) ~= "table" then |
||
279 | return "Options must be a table.", position |
||
280 | end |
||
281 | self = options.handler or self |
||
282 | if options.type == "execute" then |
||
283 | if options.func and type(options.func) ~= "string" and type(options.func) ~= "function" then |
||
284 | return "func must be a string or function", position |
||
285 | end |
||
286 | if options.func and type(options.func) == "string" and type(self[options.func]) ~= "function" then |
||
287 | return string.format("%q is not a proper function", options.func), position |
||
288 | end |
||
289 | else |
||
290 | if options.get then |
||
291 | if type(options.get) ~= "string" and type(options.get) ~= "function" then |
||
292 | return "get must be a string or function", position |
||
293 | end |
||
294 | if type(options.get) == "string" and type(self[options.get]) ~= "function" then |
||
295 | return string.format("%q is not a proper function", options.get), position |
||
296 | end |
||
297 | end |
||
298 | if options.set then |
||
299 | if type(options.set) ~= "string" and type(options.set) ~= "function" then |
||
300 | return "set must be a string or function", position |
||
301 | end |
||
302 | if type(options.set) == "string" and type(self[options.set]) ~= "function" then |
||
303 | return string.format("%q is not a proper function", options.set), position |
||
304 | end |
||
305 | end |
||
306 | if options.validate and type(options.validate) ~= "table" then |
||
307 | if type(options.validate) ~= "string" and type(options.validate) ~= "function" then |
||
308 | return "validate must be a string or function", position |
||
309 | end |
||
310 | if type(options.validate) == "string" and type(self[options.validate]) ~= "function" then |
||
311 | return string.format("%q is not a proper function", options.validate), position |
||
312 | end |
||
313 | end |
||
314 | end |
||
315 | if options.disabled and type(options.disabled) == "string" and type(self[options.disabled]) ~= "function" then |
||
316 | return string.format("%q is not a proper function", options.disabled), position |
||
317 | end |
||
318 | if options.cmdHidden and type(options.cmdHidden) == "string" and type(self[options.cmdHidden]) ~= "function" then |
||
319 | return string.format("%q is not a proper function", options.cmdHidden), position |
||
320 | end |
||
321 | if options.guiHidden and type(options.guiHidden) == "string" and type(self[options.guiHidden]) ~= "function" then |
||
322 | return string.format("%q is not a proper function", options.guiHidden), position |
||
323 | end |
||
324 | if options.hidden and type(options.hidden) == "string" and type(self[options.hidden]) ~= "function" then |
||
325 | return string.format("%q is not a proper function", options.hidden), position |
||
326 | end |
||
327 | if options.type == "group" and type(options.args) == "table" then |
||
328 | for k,v in pairs(options.args) do |
||
329 | if type(v) == "table" then |
||
330 | local newposition |
||
331 | if position then |
||
332 | newposition = position .. ".args." .. k |
||
333 | else |
||
334 | newposition = "args." .. k |
||
335 | end |
||
336 | local err, pos = validateOptionsMethods(self, v, newposition) |
||
337 | if err then |
||
338 | return err, pos |
||
339 | end |
||
340 | end |
||
341 | end |
||
342 | end |
||
343 | end |
||
344 | |||
345 | local function validateOptions(options, position, baseOptions, fromPass) |
||
346 | if not baseOptions then |
||
347 | baseOptions = options |
||
348 | end |
||
349 | if type(options) ~= "table" then |
||
350 | return "Options must be a table.", position |
||
351 | end |
||
352 | local kind = options.type |
||
353 | if type(kind) ~= "string" then |
||
354 | return '"type" must be a string.', position |
||
355 | elseif kind ~= "group" and kind ~= "range" and kind ~= "text" and kind ~= "execute" and kind ~= "toggle" and kind ~= "color" and kind ~= "header" then |
||
356 | return '"type" must either be "range", "text", "group", "toggle", "execute", "color", or "header".', position |
||
357 | end |
||
358 | if options.aliases then |
||
359 | if type(options.aliases) ~= "table" and type(options.aliases) ~= "string" then |
||
360 | return '"alias" must be a table or string', position |
||
361 | end |
||
362 | end |
||
363 | if not fromPass then |
||
364 | if kind == "execute" then |
||
365 | if type(options.func) ~= "string" and type(options.func) ~= "function" then |
||
366 | return '"func" must be a string or function', position |
||
367 | end |
||
368 | elseif kind == "range" or kind == "text" or kind == "toggle" then |
||
369 | if type(options.set) ~= "string" and type(options.set) ~= "function" then |
||
370 | return '"set" must be a string or function', position |
||
371 | end |
||
372 | if kind == "text" and options.get == false then |
||
373 | elseif type(options.get) ~= "string" and type(options.get) ~= "function" then |
||
374 | return '"get" must be a string or function', position |
||
375 | end |
||
376 | elseif kind == "group" and options.pass then |
||
377 | if options.pass ~= true then |
||
378 | return '"pass" must be either nil, true, or false', position |
||
379 | end |
||
380 | if not options.func then |
||
381 | if type(options.set) ~= "string" and type(options.set) ~= "function" then |
||
382 | return '"set" must be a string or function', position |
||
383 | end |
||
384 | if type(options.get) ~= "string" and type(options.get) ~= "function" then |
||
385 | return '"get" must be a string or function', position |
||
386 | end |
||
387 | elseif type(options.func) ~= "string" and type(options.func) ~= "function" then |
||
388 | return '"func" must be a string or function', position |
||
389 | end |
||
390 | end |
||
391 | else |
||
392 | if kind == "group" then |
||
393 | return 'cannot have "type" = "group" as a subgroup of a passing group', position |
||
394 | end |
||
395 | end |
||
396 | if options ~= baseOptions then |
||
397 | if kind == "header" then |
||
398 | elseif type(options.desc) ~= "string" then |
||
399 | return '"desc" must be a string', position |
||
400 | elseif string.len(options.desc) == 0 then |
||
401 | return '"desc" cannot be a 0-length string', position |
||
402 | end |
||
403 | end |
||
404 | |||
405 | if options ~= baseOptions or kind == "range" or kind == "text" or kind == "toggle" or kind == "color" then |
||
406 | if options.type == "header" and not options.cmdName and not options.name then |
||
407 | elseif options.cmdName then |
||
408 | if type(options.cmdName) ~= "string" then |
||
409 | return '"cmdName" must be a string or nil', position |
||
410 | elseif string.len(options.cmdName) == 0 then |
||
411 | return '"cmdName" cannot be a 0-length string', position |
||
412 | end |
||
413 | if type(options.guiName) ~= "string" then |
||
414 | if not options.guiNameIsMap then |
||
415 | return '"guiName" must be a string or nil', position |
||
416 | end |
||
417 | elseif string.len(options.guiName) == 0 then |
||
418 | return '"guiName" cannot be a 0-length string', position |
||
419 | end |
||
420 | else |
||
421 | if type(options.name) ~= "string" then |
||
422 | return '"name" must be a string', position |
||
423 | elseif string.len(options.name) == 0 then |
||
424 | return '"name" cannot be a 0-length string', position |
||
425 | end |
||
426 | end |
||
427 | end |
||
428 | if options.guiNameIsMap then |
||
429 | if type(options.guiNameIsMap) ~= "boolean" then |
||
430 | return '"guiNameIsMap" must be a boolean or nil', position |
||
431 | elseif options.type ~= "toggle" then |
||
432 | return 'if "guiNameIsMap" is true, then "type" must be set to \'toggle\'', position |
||
433 | elseif type(options.map) ~= "table" then |
||
434 | return '"map" must be a table', position |
||
435 | end |
||
436 | end |
||
437 | if options.message and type(options.message) ~= "string" then |
||
438 | return '"message" must be a string or nil', position |
||
439 | end |
||
440 | if options.error and type(options.error) ~= "string" then |
||
441 | return '"error" must be a string or nil', position |
||
442 | end |
||
443 | if options.current and type(options.current) ~= "string" then |
||
444 | return '"current" must be a string or nil', position |
||
445 | end |
||
446 | if options.order then |
||
447 | if type(options.order) ~= "number" or (-1 < options.order and options.order < 0.999) then |
||
448 | return '"order" must be a non-zero number or nil', position |
||
449 | end |
||
450 | end |
||
451 | if options.disabled then |
||
452 | if type(options.disabled) ~= "function" and type(options.disabled) ~= "string" and options.disabled ~= true then |
||
453 | return '"disabled" must be a function, string, or boolean', position |
||
454 | end |
||
455 | end |
||
456 | if options.cmdHidden then |
||
457 | if type(options.cmdHidden) ~= "function" and type(options.cmdHidden) ~= "string" and options.cmdHidden ~= true then |
||
458 | return '"cmdHidden" must be a function, string, or boolean', position |
||
459 | end |
||
460 | end |
||
461 | if options.guiHidden then |
||
462 | if type(options.guiHidden) ~= "function" and type(options.guiHidden) ~= "string" and options.guiHidden ~= true then |
||
463 | return '"guiHidden" must be a function, string, or boolean', position |
||
464 | end |
||
465 | end |
||
466 | if options.hidden then |
||
467 | if type(options.hidden) ~= "function" and type(options.hidden) ~= "string" and options.hidden ~= true then |
||
468 | return '"hidden" must be a function, string, or boolean', position |
||
469 | end |
||
470 | end |
||
471 | if kind == "text" then |
||
472 | if type(options.validate) == "table" then |
||
473 | local t = options.validate |
||
474 | local iTable = nil |
||
475 | for k,v in pairs(t) do |
||
476 | if type(k) == "number" then |
||
477 | if iTable == nil then |
||
478 | iTable = true |
||
479 | elseif not iTable then |
||
480 | return '"validate" must either have all keys be indexed numbers or strings', position |
||
481 | elseif k < 1 or k > table.getn(t) then |
||
482 | return '"validate" numeric keys must be indexed properly. >= 1 and <= table.getn', position |
||
483 | end |
||
484 | else |
||
485 | if iTable == nil then |
||
486 | iTable = false |
||
487 | elseif iTable then |
||
488 | return '"validate" must either have all keys be indexed numbers or strings', position |
||
489 | end |
||
490 | end |
||
491 | if type(v) ~= "string" then |
||
492 | return '"validate" values must all be strings', position |
||
493 | end |
||
494 | end |
||
495 | else |
||
496 | if type(options.usage) ~= "string" then |
||
497 | return '"usage" must be a string', position |
||
498 | elseif options.validate and type(options.validate) ~= "string" and type(options.validate) ~= "function" then |
||
499 | return '"validate" must be a string, function, or table', position |
||
500 | end |
||
501 | end |
||
502 | elseif kind == "range" then |
||
503 | if options.min or options.max then |
||
504 | if type(options.min) ~= "number" then |
||
505 | return '"min" must be a number', position |
||
506 | elseif type(options.max) ~= "number" then |
||
507 | return '"max" must be a number', position |
||
508 | elseif options.min >= options.max then |
||
509 | return '"min" must be less than "max"', position |
||
510 | end |
||
511 | end |
||
512 | if options.step then |
||
513 | if type(options.step) ~= "number" then |
||
514 | return '"step" must be a number', position |
||
515 | elseif options.step < 0 then |
||
516 | return '"step" must be nonnegative', position |
||
517 | end |
||
518 | end |
||
519 | if options.isPercent and options.isPercent ~= true then |
||
520 | return '"isPercent" must either be nil, true, or false', position |
||
521 | end |
||
522 | elseif kind == "toggle" then |
||
523 | if options.map then |
||
524 | if type(options.map) ~= "table" then |
||
525 | return '"map" must be a table', position |
||
526 | elseif type(options.map[true]) ~= "string" then |
||
527 | return '"map[true]" must be a string', position |
||
528 | elseif type(options.map[false]) ~= "string" then |
||
529 | return '"map[false]" must be a string', position |
||
530 | end |
||
531 | end |
||
532 | elseif kind == "color" then |
||
533 | if options.hasAlpha and options.hasAlpha ~= true then |
||
534 | return '"hasAlpha" must be nil, true, or false', position |
||
535 | end |
||
536 | elseif kind == "group" then |
||
537 | if options.pass and options.pass ~= true then |
||
538 | return '"pass" must be nil, true, or false', position |
||
539 | end |
||
540 | if type(options.args) ~= "table" then |
||
541 | return '"args" must be a table', position |
||
542 | end |
||
543 | for k,v in pairs(options.args) do |
||
544 | if type(k) ~= "string" then |
||
545 | return '"args" keys must be strings', position |
||
546 | elseif string.find(k, "%s") then |
||
547 | return string.format('"args" keys must not include spaces. %q is not appropriate.', k), position |
||
548 | elseif string.len(k) == 0 then |
||
549 | return '"args" keys must not be 0-length strings.', position |
||
550 | end |
||
551 | if type(v) ~= "table" then |
||
552 | return '"args" values must be tables', position and position .. "." .. k or k |
||
553 | end |
||
554 | local newposition |
||
555 | if position then |
||
556 | newposition = position .. ".args." .. k |
||
557 | else |
||
558 | newposition = "args." .. k |
||
559 | end |
||
560 | local err, pos = validateOptions(v, newposition, baseOptions, options.pass) |
||
561 | if err then |
||
562 | return err, pos |
||
563 | end |
||
564 | end |
||
565 | end |
||
566 | end |
||
567 | |||
568 | local colorTable |
||
569 | local colorFunc |
||
570 | local colorCancelFunc |
||
571 | |||
572 | local order |
||
573 | |||
574 | local mysort_args |
||
575 | local mysort |
||
576 | |||
577 | local function printUsage(self, handler, realOptions, options, path, args, quiet, filter) |
||
578 | if filter then |
||
579 | filter = "^" .. string.gsub(filter, "([%(%)%.%*%+%-%[%]%?%^%$%%])", "%%%1") |
||
580 | end |
||
581 | local hidden, disabled = options.cmdHidden or options.hidden, options.disabled |
||
582 | if hidden then |
||
583 | if type(hidden) == "function" then |
||
584 | hidden = hidden() |
||
585 | elseif type(hidden) == "string" then |
||
586 | if type(handler[handler]) ~= "function" then |
||
587 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, handler) |
||
588 | end |
||
589 | hidden = handler[hidden](handler) |
||
590 | end |
||
591 | end |
||
592 | if hidden then |
||
593 | disabled = true |
||
594 | elseif disabled then |
||
595 | if type(disabled) == "function" then |
||
596 | disabled = disabled() |
||
597 | elseif type(disabled) == "string" then |
||
598 | if type(handler[disabled]) ~= "function" then |
||
599 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, disabled) |
||
600 | end |
||
601 | disabled = handler[disabled](handler) |
||
602 | end |
||
603 | end |
||
604 | local kind = string.lower(options.type or "group") |
||
605 | if disabled then |
||
606 | print(string.format(OPTION_IS_DISABLED, path), realOptions.cmdName or realOptions.name or self) |
||
607 | elseif kind == "text" then |
||
608 | local var |
||
609 | if passTable then |
||
610 | if not passTable.get then |
||
611 | elseif type(passTable.get) == "function" then |
||
612 | var = passTable.get(passValue) |
||
613 | else |
||
614 | local handler = passTable.handler or handler |
||
615 | if type(handler[passTable.get]) ~= "function" then |
||
616 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, passTable.get) |
||
617 | end |
||
618 | var = handler[passTable.get](handler, passValue) |
||
619 | end |
||
620 | else |
||
621 | if not options.get then |
||
622 | elseif type(options.get) == "function" then |
||
623 | var = options.get() |
||
624 | else |
||
625 | local handler = options.handler or handler |
||
626 | if type(handler[options.get]) ~= "function" then |
||
627 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, options.get) |
||
628 | end |
||
629 | var = handler[options.get](handler) |
||
630 | end |
||
631 | end |
||
632 | |||
633 | local usage |
||
634 | if type(options.validate) == "table" then |
||
635 | if filter then |
||
636 | if not order then |
||
637 | order = {} |
||
638 | end |
||
639 | for k,v in pairs(options.validate) do |
||
640 | if string.find(v, filter) then |
||
641 | table.insert(order, v) |
||
642 | end |
||
643 | end |
||
644 | usage = "{" .. table.concat(order, " || ") .. "}" |
||
645 | for k in pairs(order) do |
||
646 | order[k] = nil |
||
647 | end |
||
648 | table_setn(order, 0) |
||
649 | else |
||
650 | if not order then |
||
651 | order = {} |
||
652 | end |
||
653 | for k,v in pairs(options.validate) do |
||
654 | table.insert(order, v) |
||
655 | end |
||
656 | usage = "{" .. table.concat(order, " || ") .. "}" |
||
657 | for k in pairs(order) do |
||
658 | order[k] = nil |
||
659 | end |
||
660 | table_setn(order, 0) |
||
661 | end |
||
662 | var = options.validate[var] or var |
||
663 | else |
||
664 | usage = options.usage or "<value>" |
||
665 | end |
||
666 | if not quiet then |
||
667 | print(string.format("|cffffff7f%s:|r %s %s", USAGE, path, usage), realOptions.cmdName or realOptions.name or self) |
||
668 | end |
||
669 | if (passTable and passTable.get) or options.get then |
||
670 | print(string.format(options.current or IS_CURRENTLY_SET_TO, tostring(options.cmdName or options.name), tostring(var or NONE))) |
||
671 | end |
||
672 | elseif kind == "range" then |
||
673 | local var |
||
674 | if passTable then |
||
675 | if type(passTable.get) == "function" then |
||
676 | var = passTable.get(passValue) |
||
677 | else |
||
678 | local handler = passTable.handler or handler |
||
679 | if type(handler[passTable.get]) ~= "function" then |
||
680 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, passTable.get) |
||
681 | end |
||
682 | var = handler[passTable.get](handler, passValue) |
||
683 | end |
||
684 | else |
||
685 | if type(options.get) == "function" then |
||
686 | var = options.get() |
||
687 | else |
||
688 | local handler = options.handler or handler |
||
689 | if type(handler[options.get]) ~= "function" then |
||
690 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, options.get) |
||
691 | end |
||
692 | var = handler[options.get](handler) |
||
693 | end |
||
694 | end |
||
695 | |||
696 | local usage |
||
697 | local min = options.min or 0 |
||
698 | local max = options.max or 1 |
||
699 | if options.isPercent then |
||
700 | min, max = min * 100, max * 100 |
||
701 | var = tostring(var * 100) .. "%" |
||
702 | end |
||
703 | local bit = "-" |
||
704 | if min < 0 or max < 0 then |
||
705 | bit = " - " |
||
706 | end |
||
707 | usage = string.format("(%s%s%s)", min, bit, max) |
||
708 | if not quiet then |
||
709 | print(string.format("|cffffff7f%s:|r %s %s", USAGE, path, usage), realOptions.cmdName or realOptions.name or self) |
||
710 | end |
||
711 | print(string.format(options.current or IS_CURRENTLY_SET_TO, tostring(options.cmdName or options.name), tostring(var or NONE))) |
||
712 | elseif kind == "group" then |
||
713 | local usage |
||
714 | if next(options.args) then |
||
715 | if not order then |
||
716 | order = {} |
||
717 | end |
||
718 | for k,v in pairs(options.args) do |
||
719 | if v.type ~= "header" then |
||
720 | local hidden = v.cmdHidden or v.hidden |
||
721 | if hidden then |
||
722 | if type(hidden) == "function" then |
||
723 | hidden = hidden() |
||
724 | elseif type(hidden) == "string" then |
||
725 | local handler = v.handler or handler |
||
726 | if type(handler[hidden]) ~= "function" then |
||
727 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, hidden) |
||
728 | end |
||
729 | hidden = handler[hidden](handler) |
||
730 | end |
||
731 | end |
||
732 | if not hidden then |
||
733 | if filter then |
||
734 | if string.find(k, filter) then |
||
735 | table.insert(order, k) |
||
736 | elseif type(v.aliases) == "table" then |
||
737 | for _,bit in ipairs(v.aliases) do |
||
738 | if string.find(v.aliases, filter) then |
||
739 | table.insert(order, k) |
||
740 | break |
||
741 | end |
||
742 | end |
||
743 | elseif type(v.aliases) == "string" then |
||
744 | if string.find(v.aliases, filter) then |
||
745 | table.insert(order, k) |
||
746 | end |
||
747 | end |
||
748 | else |
||
749 | table.insert(order, k) |
||
750 | end |
||
751 | end |
||
752 | end |
||
753 | end |
||
754 | if not mysort then |
||
755 | mysort = function(a, b) |
||
756 | local alpha, bravo = mysort_args[a], mysort_args[b] |
||
757 | local alpha_order = alpha and alpha.order or 100 |
||
758 | local bravo_order = bravo and bravo.order or 100 |
||
759 | if alpha_order == bravo_order then |
||
760 | return tostring(a) < tostring(b) |
||
761 | else |
||
762 | if alpha_order < 0 then |
||
763 | if bravo_order > 0 then |
||
764 | return false |
||
765 | end |
||
766 | else |
||
767 | if bravo_order < 0 then |
||
768 | return true |
||
769 | end |
||
770 | end |
||
771 | if alpha_order > 0 and bravo_order > 0 then |
||
772 | return tostring(a) < tostring(b) |
||
773 | end |
||
774 | return alpha_order < bravo_order |
||
775 | end |
||
776 | end |
||
777 | end |
||
778 | mysort_args = options.args |
||
779 | table.sort(order, mysort) |
||
780 | mysort_args = nil |
||
781 | if not quiet then |
||
782 | if options == realOptions then |
||
783 | if options.desc then |
||
784 | print(tostring(options.desc), realOptions.cmdName or realOptions.name or self) |
||
785 | print(string.format("|cffffff7f%s:|r %s %s", USAGE, path, "{" .. table.concat(order, " || ") .. "}")) |
||
786 | elseif self.description or self.notes then |
||
787 | print(tostring(self.description or self.notes), realOptions.cmdName or realOptions.name or self) |
||
788 | print(string.format("|cffffff7f%s:|r %s %s", USAGE, path, "{" .. table.concat(order, " || ") .. "}")) |
||
789 | else |
||
790 | print(string.format("|cffffff7f%s:|r %s %s", USAGE, path, "{" .. table.concat(order, " || ") .. "}"), realOptions.cmdName or realOptions.name or self) |
||
791 | end |
||
792 | else |
||
793 | if options.desc then |
||
794 | print(string.format("|cffffff7f%s:|r %s %s", USAGE, path, "{" .. table.concat(order, " || ") .. "}"), realOptions.cmdName or realOptions.name or self) |
||
795 | print(tostring(options.desc)) |
||
796 | else |
||
797 | print(string.format("|cffffff7f%s:|r %s %s", USAGE, path, "{" .. table.concat(order, " || ") .. "}"), realOptions.cmdName or realOptions.name or self) |
||
798 | end |
||
799 | end |
||
800 | end |
||
801 | for _,k in ipairs(order) do |
||
802 | local v = options.args[k] |
||
803 | if v then |
||
804 | local disabled = v.disabled |
||
805 | if disabled then |
||
806 | if type(disabled) == "function" then |
||
807 | disabled = disabled() |
||
808 | elseif type(disabled) == "string" then |
||
809 | local handler = v.handler or handler |
||
810 | if type(handler[disabled]) ~= "function" then |
||
811 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, disabled) |
||
812 | end |
||
813 | disabled = handler[disabled](handler) |
||
814 | end |
||
815 | end |
||
816 | if type(v.aliases) == "table" then |
||
817 | k = k .. " || " .. table.concat(v.aliases, " || ") |
||
818 | elseif type(v.aliases) == "string" then |
||
819 | k = k .. " || " .. v.aliases |
||
820 | end |
||
821 | if v.get then |
||
822 | local a1,a2,a3,a4 |
||
823 | if type(v.get) == "function" then |
||
824 | if options.pass then |
||
825 | a1,a2,a3,a4 = v.get(k) |
||
826 | else |
||
827 | a1,a2,a3,a4 = v.get() |
||
828 | end |
||
829 | else |
||
830 | local handler = v.handler or handler |
||
831 | if type(handler[v.get]) ~= "function" then |
||
832 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, v.get) |
||
833 | end |
||
834 | if options.pass then |
||
835 | a1,a2,a3,a4 = handler[v.get](handler, k) |
||
836 | else |
||
837 | a1,a2,a3,a4 = handler[v.get](handler) |
||
838 | end |
||
839 | end |
||
840 | if v.type == "color" then |
||
841 | if v.hasAlpha then |
||
842 | if not a1 or not a2 or not a3 or not a4 then |
||
843 | s = NONE |
||
844 | else |
||
845 | s = string.format("|c%02x%02x%02x%02x%02x%02x%02x%02x|r", a4*255, a1*255, a2*255, a3*255, a4*255, a1*255, a2*255, a3*255) |
||
846 | end |
||
847 | else |
||
848 | if not a1 or not a2 or not a3 then |
||
849 | s = NONE |
||
850 | else |
||
851 | s = string.format("|cff%02x%02x%02x%02x%02x%02x|r", a1*255, a2*255, a3*255, a1*255, a2*255, a3*255) |
||
852 | end |
||
853 | end |
||
854 | elseif v.type == "toggle" then |
||
855 | if v.map then |
||
856 | s = tostring(v.map[a1 and true or false] or NONE) |
||
857 | else |
||
858 | s = tostring(MAP_ONOFF[a1 and true or false] or NONE) |
||
859 | end |
||
860 | elseif v.type == "range" then |
||
861 | if v.isPercent then |
||
862 | s = tostring(a1 * 100) .. "%" |
||
863 | else |
||
864 | s = tostring(a1) |
||
865 | end |
||
866 | elseif v.type == "text" and type(v.validate) == "table" then |
||
867 | s = tostring(v.validate[a1] or a1) |
||
868 | else |
||
869 | s = tostring(a1 or NONE) |
||
870 | end |
||
871 | if disabled then |
||
872 | local s = string.gsub(s, "|cff%x%x%x%x%x%x(.-)|r", "%1") |
||
873 | local desc = string.gsub(v.desc or NONE, "|cff%x%x%x%x%x%x(.-)|r", "%1") |
||
874 | print(string.format("|cffcfcfcf - %s: [%s] %s|r", k, s, desc)) |
||
875 | else |
||
876 | print(string.format(" - |cffffff7f%s: [|r%s|cffffff7f]|r %s", k, s, v.desc or NONE)) |
||
877 | end |
||
878 | else |
||
879 | if disabled then |
||
880 | local desc = string.gsub(v.desc or NONE, "|cff%x%x%x%x%x%x(.-)|r", "%1") |
||
881 | print(string.format("|cffcfcfcf - %s: %s", k, desc)) |
||
882 | else |
||
883 | print(string.format(" - |cffffff7f%s:|r %s", k, v.desc or NONE)) |
||
884 | end |
||
885 | end |
||
886 | end |
||
887 | end |
||
888 | for k in pairs(order) do |
||
889 | order[k] = nil |
||
890 | end |
||
891 | table_setn(order, 0) |
||
892 | else |
||
893 | if options.desc then |
||
894 | desc = options.desc |
||
895 | print(string.format("|cffffff7f%s:|r %s", USAGE, path), realOptions.cmdName or realOptions.name or self) |
||
896 | print(tostring(options.desc)) |
||
897 | elseif options == realOptions and (self.description or self.notes) then |
||
898 | print(tostring(self.description or self.notes), realOptions.cmdName or realOptions.name or self) |
||
899 | print(string.format("|cffffff7f%s:|r %s", USAGE, path)) |
||
900 | else |
||
901 | print(string.format("|cffffff7f%s:|r %s", USAGE, path), realOptions.cmdName or realOptions.name or self) |
||
902 | end |
||
903 | print(self, NO_OPTIONS_AVAILABLE) |
||
904 | end |
||
905 | end |
||
906 | end |
||
907 | |||
908 | local function handlerFunc(self, chat, msg, options) |
||
909 | if not msg then |
||
910 | msg = "" |
||
911 | else |
||
912 | msg = string.gsub(msg, "^%s*(.-)%s*$", "%1") |
||
913 | msg = string.gsub(msg, "%s+", " ") |
||
914 | end |
||
915 | |||
916 | local realOptions = options |
||
917 | local options, path, args, handler, passTable, passValue = findTableLevel(self, options, chat, msg) |
||
918 | |||
919 | local hidden, disabled = options.cmdHidden or options.hidden, options.disabled |
||
920 | if hidden then |
||
921 | if type(hidden) == "function" then |
||
922 | hidden = hidden() |
||
923 | elseif type(hidden) == "string" then |
||
924 | if type(handler[hidden]) ~= "function" then |
||
925 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, hidden) |
||
926 | end |
||
927 | hidden = handler[hidden](handler) |
||
928 | end |
||
929 | end |
||
930 | if hidden then |
||
931 | disabled = true |
||
932 | elseif disabled then |
||
933 | if type(disabled) == "function" then |
||
934 | disabled = disabled() |
||
935 | elseif type(disabled) == "string" then |
||
936 | if type(handler[disabled]) ~= "function" then |
||
937 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, disabled) |
||
938 | end |
||
939 | disabled = handler[disabled](handler) |
||
940 | end |
||
941 | end |
||
942 | local _G_this = this |
||
943 | local kind = string.lower(options.type or "group") |
||
944 | if disabled then |
||
945 | print(string.format(OPTION_IS_DISABLED, path), realOptions.cmdName or realOptions.name or self) |
||
946 | elseif kind == "text" then |
||
947 | if table.getn(args) > 0 then |
||
948 | if (type(options.validate) == "table" and table.getn(args) > 1) or (type(options.validate) ~= "table" and not options.input) then |
||
949 | local arg = table.concat(args, " ") |
||
950 | for k,v in pairs(args) do |
||
951 | args[k] = nil |
||
952 | end |
||
953 | table_setn(args, 0) |
||
954 | table.insert(args, arg) |
||
955 | end |
||
956 | if options.validate then |
||
957 | local good |
||
958 | if type(options.validate) == "function" then |
||
959 | good = options.validate(unpack(args)) |
||
960 | elseif type(options.validate) == "table" then |
||
961 | local arg = args[1] |
||
962 | arg = string.lower(tostring(arg)) |
||
963 | for k,v in pairs(options.validate) do |
||
964 | if string.lower(v) == arg then |
||
965 | args[1] = type(k) == "string" and k or v |
||
966 | good = true |
||
967 | break |
||
968 | end |
||
969 | end |
||
970 | if not good and type((next(options.validate))) == "string" then |
||
971 | for k,v in pairs(options.validate) do |
||
972 | if type(k) == "string" and string.lower(k) == arg then |
||
973 | args[1] = k |
||
974 | good = true |
||
975 | break |
||
976 | end |
||
977 | end |
||
978 | end |
||
979 | else |
||
980 | if type(handler[options.validate]) ~= "function" then |
||
981 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, options.validate) |
||
982 | end |
||
983 | good = handler[options.validate](handler, unpack(args)) |
||
984 | end |
||
985 | if not good then |
||
986 | local usage |
||
987 | if type(options.validate) == "table" then |
||
988 | if not order then |
||
989 | order = {} |
||
990 | end |
||
991 | for k,v in pairs(options.validate) do |
||
992 | table.insert(order, v) |
||
993 | end |
||
994 | usage = "{" .. table.concat(order, " || ") .. "}" |
||
995 | for k in pairs(order) do |
||
996 | order[k] = nil |
||
997 | end |
||
998 | table_setn(order, 0) |
||
999 | else |
||
1000 | usage = options.usage or "<value>" |
||
1001 | end |
||
1002 | print(string.format(options.error or IS_NOT_A_VALID_OPTION_FOR, tostring(table.concat(args, " ")), path), realOptions.cmdName or realOptions.name or self) |
||
1003 | print(string.format("|cffffff7f%s:|r %s %s", USAGE, path, usage)) |
||
1004 | return |
||
1005 | end |
||
1006 | end |
||
1007 | |||
1008 | local var |
||
1009 | if passTable then |
||
1010 | if not passTable.get then |
||
1011 | elseif type(passTable.get) == "function" then |
||
1012 | var = passTable.get(passValue) |
||
1013 | else |
||
1014 | if type(handler[passTable.get]) ~= "function" then |
||
1015 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, passTable.get) |
||
1016 | end |
||
1017 | var = handler[passTable.get](handler, passValue) |
||
1018 | end |
||
1019 | else |
||
1020 | if not options.get then |
||
1021 | elseif type(options.get) == "function" then |
||
1022 | var = options.get() |
||
1023 | else |
||
1024 | if type(handler[options.get]) ~= "function" then |
||
1025 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, options.get) |
||
1026 | end |
||
1027 | var = handler[options.get](handler) |
||
1028 | end |
||
1029 | end |
||
1030 | |||
1031 | if var ~= args[1] then |
||
1032 | if passTable then |
||
1033 | if type(passTable.set) == "function" then |
||
1034 | passTable.set(passValue, unpack(args)) |
||
1035 | else |
||
1036 | if type(handler[passTable.set]) ~= "function" then |
||
1037 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, passTable.set) |
||
1038 | end |
||
1039 | handler[passTable.set](handler, passTable.set, unpack(args)) |
||
1040 | end |
||
1041 | else |
||
1042 | if type(options.set) == "function" then |
||
1043 | options.set(unpack(args)) |
||
1044 | else |
||
1045 | if type(handler[options.set]) ~= "function" then |
||
1046 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, options.set) |
||
1047 | end |
||
1048 | handler[options.set](handler, unpack(args)) |
||
1049 | end |
||
1050 | end |
||
1051 | end |
||
1052 | end |
||
1053 | |||
1054 | if table.getn(args) > 0 then |
||
1055 | local var |
||
1056 | if passTable then |
||
1057 | if not passTable.get then |
||
1058 | elseif type(passTable.get) == "function" then |
||
1059 | var = passTable.get(passValue) |
||
1060 | else |
||
1061 | if type(handler[passTable.get]) ~= "function" then |
||
1062 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, passTable.get) |
||
1063 | end |
||
1064 | var = handler[passTable.get](handler, passValue) |
||
1065 | end |
||
1066 | else |
||
1067 | if not options.get then |
||
1068 | elseif type(options.get) == "function" then |
||
1069 | var = options.get() |
||
1070 | else |
||
1071 | if type(handler[options.get]) ~= "function" then |
||
1072 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, options.get) |
||
1073 | end |
||
1074 | var = handler[options.get](handler) |
||
1075 | end |
||
1076 | end |
||
1077 | if type(options.validate) == "table" then |
||
1078 | var = options.validate[var] or var |
||
1079 | end |
||
1080 | if (passTable and passTable.get) or options.get then |
||
1081 | print(string.format(options.message or IS_NOW_SET_TO, tostring(options.cmdName or options.name), tostring(var or NONE)), realOptions.cmdName or realOptions.name or self) |
||
1082 | end |
||
1083 | if var == args[1] then |
||
1084 | return |
||
1085 | end |
||
1086 | else |
||
1087 | printUsage(self, handler, realOptions, options, path, args) |
||
1088 | return |
||
1089 | end |
||
1090 | elseif kind == "execute" then |
||
1091 | if passTable then |
||
1092 | if type(passFunc) == "function" then |
||
1093 | set(passValue) |
||
1094 | else |
||
1095 | if type(handler[passFunc]) ~= "function" then |
||
1096 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, passFunc) |
||
1097 | end |
||
1098 | handler[passFunc](handler, passValue) |
||
1099 | end |
||
1100 | else |
||
1101 | local ret, msg |
||
1102 | if type(options.func) == "function" then |
||
1103 | options.func() |
||
1104 | else |
||
1105 | local handler = options.handler or self |
||
1106 | if type(handler[options.func]) ~= "function" then |
||
1107 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, options.func) |
||
1108 | end |
||
1109 | handler[options.func](handler) |
||
1110 | end |
||
1111 | end |
||
1112 | elseif kind == "toggle" then |
||
1113 | local var |
||
1114 | if passTable then |
||
1115 | if type(passTable.get) == "function" then |
||
1116 | var = passTable.get(passValue) |
||
1117 | else |
||
1118 | if type(handler[passTable.get]) ~= "function" then |
||
1119 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, passTable.get) |
||
1120 | end |
||
1121 | var = handler[passTable.get](handler, passValue) |
||
1122 | end |
||
1123 | if type(passTable.set) == "function" then |
||
1124 | passTable.set(passValue, not var) |
||
1125 | else |
||
1126 | if type(handler[passTable.set]) ~= "function" then |
||
1127 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, passTable.set) |
||
1128 | end |
||
1129 | handler[passTable.set](handler, passValue, not var) |
||
1130 | end |
||
1131 | if type(passTable.get) == "function" then |
||
1132 | var = passTable.get(passValue) |
||
1133 | else |
||
1134 | var = handler[passTable.get](handler, passValue) |
||
1135 | end |
||
1136 | else |
||
1137 | local handler = options.handler or self |
||
1138 | if type(options.get) == "function" then |
||
1139 | var = options.get() |
||
1140 | else |
||
1141 | if type(handler[options.get]) ~= "function" then |
||
1142 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, options.get) |
||
1143 | end |
||
1144 | var = handler[options.get](handler) |
||
1145 | end |
||
1146 | if type(options.set) == "function" then |
||
1147 | options.set(not var) |
||
1148 | else |
||
1149 | if type(handler[options.set]) ~= "function" then |
||
1150 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, options.set) |
||
1151 | end |
||
1152 | handler[options.set](handler, not var) |
||
1153 | end |
||
1154 | if type(options.get) == "function" then |
||
1155 | var = options.get() |
||
1156 | else |
||
1157 | var = handler[options.get](handler) |
||
1158 | end |
||
1159 | end |
||
1160 | |||
1161 | print(string.format(options.message or IS_NOW_SET_TO, tostring(options.cmdName or options.name), (options.map or MAP_ONOFF)[var and true or false] or NONE), realOptions.cmdName or realOptions.name or self) |
||
1162 | elseif kind == "range" then |
||
1163 | local arg |
||
1164 | if table.getn(args) <= 1 then |
||
1165 | arg = args[1] |
||
1166 | else |
||
1167 | arg = table.concat(args, " ") |
||
1168 | end |
||
1169 | |||
1170 | if arg then |
||
1171 | local min = options.min or 0 |
||
1172 | local max = options.max or 1 |
||
1173 | local good = false |
||
1174 | if type(arg) == "number" then |
||
1175 | if options.isPercent then |
||
1176 | arg = arg / 100 |
||
1177 | end |
||
1178 | |||
1179 | if arg >= min and arg <= max then |
||
1180 | good = true |
||
1181 | end |
||
1182 | |||
1183 | if good and type(options.step) == "number" and options.step > 0 then |
||
1184 | local step = options.step |
||
1185 | arg = math.floor((arg - min) / step + 0.5) * step + min |
||
1186 | if arg > max then |
||
1187 | arg = max |
||
1188 | elseif arg < min then |
||
1189 | arg = min |
||
1190 | end |
||
1191 | end |
||
1192 | end |
||
1193 | if not good then |
||
1194 | local usage |
||
1195 | local min = options.min or 0 |
||
1196 | local max = options.max or 1 |
||
1197 | if options.isPercent then |
||
1198 | min, max = min * 100, max * 100 |
||
1199 | end |
||
1200 | local bit = "-" |
||
1201 | if min < 0 or max < 0 then |
||
1202 | bit = " - " |
||
1203 | end |
||
1204 | usage = string.format("(%s%s%s)", min, bit, max) |
||
1205 | print(string.format(options.error or IS_NOT_A_VALID_VALUE_FOR, tostring(arg), path), realOptions.cmdName or realOptions.name or self) |
||
1206 | print(string.format("|cffffff7f%s:|r %s %s", USAGE, path, usage)) |
||
1207 | return |
||
1208 | end |
||
1209 | |||
1210 | local var |
||
1211 | if passTable then |
||
1212 | if type(passTable.get) == "function" then |
||
1213 | var = passTable.get(passValue) |
||
1214 | else |
||
1215 | if type(handler[passTable.get]) ~= "function" then |
||
1216 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, passTable.get) |
||
1217 | end |
||
1218 | var = handler[passTable.get](handler, passValue) |
||
1219 | end |
||
1220 | else |
||
1221 | if type(options.get) == "function" then |
||
1222 | var = options.get() |
||
1223 | else |
||
1224 | local handler = options.handler or self |
||
1225 | if type(handler[options.get]) ~= "function" then |
||
1226 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, options.get) |
||
1227 | end |
||
1228 | var = handler[options.get](handler) |
||
1229 | end |
||
1230 | end |
||
1231 | |||
1232 | if var ~= arg then |
||
1233 | if passTable then |
||
1234 | if type(passTable.set) == "function" then |
||
1235 | passTable.set(passValue, arg) |
||
1236 | else |
||
1237 | if type(handler[passTable.set]) ~= "function" then |
||
1238 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, passTable.set) |
||
1239 | end |
||
1240 | handler[passTable.set](handler, passValue, arg) |
||
1241 | end |
||
1242 | else |
||
1243 | if type(options.set) == "function" then |
||
1244 | options.set(arg) |
||
1245 | else |
||
1246 | local handler = options.handler or self |
||
1247 | if type(handler[options.set]) ~= "function" then |
||
1248 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, options.set) |
||
1249 | end |
||
1250 | handler[options.set](handler, arg) |
||
1251 | end |
||
1252 | end |
||
1253 | end |
||
1254 | end |
||
1255 | |||
1256 | if arg then |
||
1257 | local var |
||
1258 | if passTable then |
||
1259 | if type(passTable.get) == "function" then |
||
1260 | var = passTable.get(passValue) |
||
1261 | else |
||
1262 | if type(handler[passTable.get]) ~= "function" then |
||
1263 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, passTable.get) |
||
1264 | end |
||
1265 | var = handler[passTable.get](handler, passValue) |
||
1266 | end |
||
1267 | else |
||
1268 | if type(options.get) == "function" then |
||
1269 | var = options.get() |
||
1270 | else |
||
1271 | local handler = options.handler or self |
||
1272 | if type(handler[options.get]) ~= "function" then |
||
1273 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, options.get) |
||
1274 | end |
||
1275 | var = handler[options.get](handler) |
||
1276 | end |
||
1277 | end |
||
1278 | |||
1279 | if var and options.isPercent then |
||
1280 | var = tostring(var * 100) .. "%" |
||
1281 | end |
||
1282 | print(string.format(options.message or IS_NOW_SET_TO, tostring(options.cmdName or options.name), tostring(var or NONE)), realOptions.cmdName or realOptions.name or self) |
||
1283 | if var == arg then |
||
1284 | return |
||
1285 | end |
||
1286 | else |
||
1287 | printUsage(self, handler, realOptions, options, path, args) |
||
1288 | return |
||
1289 | end |
||
1290 | elseif kind == "color" then |
||
1291 | if table.getn(args) > 0 then |
||
1292 | local r,g,b,a |
||
1293 | if table.getn(args) == 1 then |
||
1294 | local arg = tostring(args[1]) |
||
1295 | if options.hasAlpha then |
||
1296 | if string.len(arg) == 8 and string.find(arg, "^%x*$") then |
||
1297 | r,g,b,a = tonumber(string.sub(arg, 1, 2), 16) / 255, tonumber(string.sub(arg, 3, 4), 16) / 255, tonumber(string.sub(arg, 5, 6), 16) / 255, tonumber(string.sub(arg, 7, 8), 16) / 255 |
||
1298 | end |
||
1299 | else |
||
1300 | if string.len(arg) == 6 and string.find(arg, "^%x*$") then |
||
1301 | r,g,b = tonumber(string.sub(arg, 1, 2), 16) / 255, tonumber(string.sub(arg, 3, 4), 16) / 255, tonumber(string.sub(arg, 5, 6), 16) / 255 |
||
1302 | end |
||
1303 | end |
||
1304 | elseif table.getn(args) == 4 and options.hasAlpha then |
||
1305 | local a1,a2,a3,a4 = args[1], args[2], args[3], args[4] |
||
1306 | if type(a1) == "number" and type(a2) == "number" and type(a3) == "number" and type(a4) == "number" and a1 <= 1 and a2 <= 1 and a3 <= 1 and a4 <= 1 then |
||
1307 | r,g,b,a = a1,a2,a3,a4 |
||
1308 | elseif (type(a1) == "number" or string.len(a1) == 2) and string.find(a1, "^%x*$") and (type(a2) == "number" or string.len(a2) == 2) and string.find(a2, "^%x*$") and (type(a3) == "number" or string.len(a3) == 2) and string.find(a3, "^%x*$") and (type(a4) == "number" or string.len(a4) == 2) and string.find(a4, "^%x*$") then |
||
1309 | r,g,b,a = tonumber(a1, 16) / 255, tonumber(a2, 16) / 255, tonumber(a3, 16) / 255, tonumber(a4, 16) / 255 |
||
1310 | end |
||
1311 | elseif table.getn(args) == 3 and not options.hasAlpha then |
||
1312 | local a1,a2,a3 = args[1], args[2], args[3] |
||
1313 | if type(a1) == "number" and type(a2) == "number" and type(a3) == "number" and a1 <= 1 and a2 <= 1 and a3 <= 1 then |
||
1314 | r,g,b = a1,a2,a3 |
||
1315 | elseif (type(a1) == "number" or string.len(a1) == 2) and string.find(a1, "^%x*$") and (type(a2) == "number" or string.len(a2) == 2) and string.find(a2, "^%x*$") and (type(a3) == "number" or string.len(a3) == 2) and string.find(a3, "^%x*$") then |
||
1316 | r,g,b = tonumber(a1, 16) / 255, tonumber(a2, 16) / 255, tonumber(a3, 16) / 255 |
||
1317 | end |
||
1318 | end |
||
1319 | if not r then |
||
1320 | print(string.format(options.error or IS_NOT_A_VALID_OPTION_FOR, table.concat(args, ' '), path), realOptions.cmdName or realOptions.name or self) |
||
1321 | print(string.format("|cffffff7f%s:|r %s {0-1} {0-1} {0-1}%s", USAGE, path, options.hasAlpha and " {0-1}" or "")) |
||
1322 | return |
||
1323 | end |
||
1324 | if passTable then |
||
1325 | if type(passTable.set) == "function" then |
||
1326 | passTable.set(passValue, r,g,b,a) |
||
1327 | else |
||
1328 | if type(handler[passTable.set]) ~= "function" then |
||
1329 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, passTable.set) |
||
1330 | end |
||
1331 | handler[passTable.set](handler, passValue, r,g,b,a) |
||
1332 | end |
||
1333 | else |
||
1334 | if type(options.set) == "function" then |
||
1335 | options.set(r,g,b,a) |
||
1336 | else |
||
1337 | if type(handler[options.set]) ~= "function" then |
||
1338 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, options.set) |
||
1339 | end |
||
1340 | handler[options.set](handler, r,g,b,a) |
||
1341 | end |
||
1342 | end |
||
1343 | |||
1344 | local r,g,b,a |
||
1345 | if passTable then |
||
1346 | if type(passTable.get) == "function" then |
||
1347 | r,g,b,a = passTable.get(passValue) |
||
1348 | else |
||
1349 | if type(handler[passTable.get]) ~= "function" then |
||
1350 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, passTable.get) |
||
1351 | end |
||
1352 | r,g,b,a = handler[passTable.get](handler, passValue) |
||
1353 | end |
||
1354 | else |
||
1355 | if type(options.get) == "function" then |
||
1356 | r,g,b,a = options.get() |
||
1357 | else |
||
1358 | if type(handler[options.get]) ~= "function" then |
||
1359 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, options.get) |
||
1360 | end |
||
1361 | r,g,b,a = handler[options.get](handler) |
||
1362 | end |
||
1363 | end |
||
1364 | |||
1365 | local s |
||
1366 | if type(r) == "number" and type(g) == "number" and type(b) == "number" then |
||
1367 | if options.hasAlpha and type(a) == "number" then |
||
1368 | s = string.format("|c%02x%02x%02x%02x%02x%02x%02x%02x|r", a*255, r*255, g*255, b*255, r*255, g*255, b*255, a*255) |
||
1369 | else |
||
1370 | s = string.format("|cff%02x%02x%02x%02x%02x%02x|r", r*255, g*255, b*255, r*255, g*255, b*255) |
||
1371 | end |
||
1372 | else |
||
1373 | s = NONE |
||
1374 | end |
||
1375 | print(string.format(options.message or IS_NOW_SET_TO, tostring(options.cmdName or options.name), s), realOptions.cmdName or realOptions.name or self) |
||
1376 | else |
||
1377 | local r,g,b,a |
||
1378 | if passTable then |
||
1379 | if type(passTable.get) == "function" then |
||
1380 | r,g,b,a = passTable.get(passValue) |
||
1381 | else |
||
1382 | if type(handler[passTable.get]) ~= "function" then |
||
1383 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, passTable.get) |
||
1384 | end |
||
1385 | r,g,b,a = handler[passTable.get](handler, passValue) |
||
1386 | end |
||
1387 | else |
||
1388 | if type(options.get) == "function" then |
||
1389 | r,g,b,a = options.get() |
||
1390 | else |
||
1391 | if type(handler[options.get]) ~= "function" then |
||
1392 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, options.get) |
||
1393 | end |
||
1394 | r,g,b,a = handler[options.get](handler) |
||
1395 | end |
||
1396 | end |
||
1397 | |||
1398 | if not colorTable then |
||
1399 | colorTable = {} |
||
1400 | local t = colorTable |
||
1401 | |||
1402 | if ColorPickerOkayButton then |
||
1403 | local ColorPickerOkayButton_OnClick = ColorPickerOkayButton:GetScript("OnClick") |
||
1404 | ColorPickerOkayButton:SetScript("OnClick", function() |
||
1405 | if ColorPickerOkayButton_OnClick then |
||
1406 | ColorPickerOkayButton_OnClick() |
||
1407 | end |
||
1408 | if t.active then |
||
1409 | ColorPickerFrame.cancelFunc = nil |
||
1410 | ColorPickerFrame.func = nil |
||
1411 | ColorPickerFrame.opacityFunc = nil |
||
1412 | local r,g,b,a |
||
1413 | if t.passValue then |
||
1414 | if type(t.get) == "function" then |
||
1415 | r,g,b,a = t.get(t.passValue) |
||
1416 | else |
||
1417 | if type(t.handler[t.get]) ~= "function" then |
||
1418 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, t.get) |
||
1419 | end |
||
1420 | r,g,b,a = t.handler[t.get](t.handler, t.passValue) |
||
1421 | end |
||
1422 | else |
||
1423 | if type(t.get) == "function" then |
||
1424 | r,g,b,a = t.get() |
||
1425 | else |
||
1426 | if type(t.handler[t.get]) ~= "function" then |
||
1427 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, t.get) |
||
1428 | end |
||
1429 | r,g,b,a = t.handler[t.get](t.handler) |
||
1430 | end |
||
1431 | end |
||
1432 | if r ~= t.r or g ~= t.g or b ~= t.b or (t.hasAlpha and a ~= t.a) then |
||
1433 | local s |
||
1434 | if type(r) == "number" and type(g) == "number" and type(b) == "number" then |
||
1435 | if t.hasAlpha and type(a) == "number" then |
||
1436 | s = string.format("|c%02x%02x%02x%02x%02x%02x%02x%02x|r", a*255, r*255, g*255, b*255, r*255, g*255, b*255, a*255) |
||
1437 | else |
||
1438 | s = string.format("|cff%02x%02x%02x%02x%02x%02x|r", r*255, g*255, b*255, r*255, g*255, b*255) |
||
1439 | end |
||
1440 | else |
||
1441 | s = NONE |
||
1442 | end |
||
1443 | print(string.format(t.message, tostring(t.name), s), t.realOptions.cmdName or t.realOptions.name or self) |
||
1444 | end |
||
1445 | for k,v in pairs(t) do |
||
1446 | t[k] = nil |
||
1447 | end |
||
1448 | end |
||
1449 | end) |
||
1450 | end |
||
1451 | else |
||
1452 | for k,v in pairs(colorTable) do |
||
1453 | colorTable[k] = nil |
||
1454 | end |
||
1455 | end |
||
1456 | |||
1457 | if type(r) ~= "number" or type(g) ~= "number" or type(b) ~= "number" then |
||
1458 | r,g,b = 1, 1, 1 |
||
1459 | end |
||
1460 | if type(a) ~= "number" then |
||
1461 | a = 1 |
||
1462 | end |
||
1463 | local t = colorTable |
||
1464 | t.r = r |
||
1465 | t.g = g |
||
1466 | t.b = b |
||
1467 | if hasAlpha then |
||
1468 | t.a = a |
||
1469 | end |
||
1470 | t.realOptions = realOptions |
||
1471 | t.hasAlpha = options.hasAlpha |
||
1472 | t.handler = handler |
||
1473 | t.set = passTable and passTable.set or options.set |
||
1474 | t.get = passTable and passTable.get or options.get |
||
1475 | t.name = options.cmdName or options.name |
||
1476 | t.message = options.message or IS_NOW_SET_TO |
||
1477 | t.passValue = passValue |
||
1478 | t.active = true |
||
1479 | |||
1480 | if not colorFunc then |
||
1481 | colorFunc = function() |
||
1482 | local r,g,b = ColorPickerFrame:GetColorRGB() |
||
1483 | if t.hasAlpha then |
||
1484 | local a = 1 - OpacitySliderFrame:GetValue() |
||
1485 | if type(t.set) == "function" then |
||
1486 | if t.passValue then |
||
1487 | t.set(t.passValue, r,g,b,a) |
||
1488 | else |
||
1489 | t.set(r,g,b,a) |
||
1490 | end |
||
1491 | else |
||
1492 | if type(t.handler[t.set]) ~= "function" then |
||
1493 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, t.set) |
||
1494 | end |
||
1495 | if t.passValue then |
||
1496 | t.handler[t.set](t.handler, t.passValue, r,g,b,a) |
||
1497 | else |
||
1498 | t.handler[t.set](t.handler, r,g,b,a) |
||
1499 | end |
||
1500 | end |
||
1501 | else |
||
1502 | if type(t.set) == "function" then |
||
1503 | if t.passValue then |
||
1504 | t.set(t.passValue, r,g,b) |
||
1505 | else |
||
1506 | t.set(r,g,b) |
||
1507 | end |
||
1508 | else |
||
1509 | if type(t.handler[t.set]) ~= "function" then |
||
1510 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, t.set) |
||
1511 | end |
||
1512 | if t.passValue then |
||
1513 | t.handler[t.set](t.handler, t.passValue, r,g,b) |
||
1514 | else |
||
1515 | t.handler[t.set](t.handler, r,g,b) |
||
1516 | end |
||
1517 | end |
||
1518 | end |
||
1519 | end |
||
1520 | end |
||
1521 | |||
1522 | ColorPickerFrame.func = colorFunc |
||
1523 | ColorPickerFrame.hasOpacity = options.hasAlpha |
||
1524 | if options.hasAlpha then |
||
1525 | ColorPickerFrame.opacityFunc = ColorPickerFrame.func |
||
1526 | ColorPickerFrame.opacity = 1 - a |
||
1527 | end |
||
1528 | ColorPickerFrame:SetColorRGB(r,g,b) |
||
1529 | |||
1530 | if not colorCancelFunc then |
||
1531 | colorCancelFunc = function() |
||
1532 | if t.hasAlpha then |
||
1533 | if type(t.set) == "function" then |
||
1534 | if t.passValue then |
||
1535 | t.set(t.passValue, t.r,t.g,t.b,t.a) |
||
1536 | else |
||
1537 | t.set(t.r,t.g,t.b,t.a) |
||
1538 | end |
||
1539 | else |
||
1540 | if type(t.handler[t.get]) ~= "function" then |
||
1541 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, t.get) |
||
1542 | end |
||
1543 | if t.passValue then |
||
1544 | t.handler[t.set](t.handler, t.passValue, t.r,t.g,t.b,t.a) |
||
1545 | else |
||
1546 | t.handler[t.set](t.handler, t.r,t.g,t.b,t.a) |
||
1547 | end |
||
1548 | end |
||
1549 | else |
||
1550 | if type(t.set) == "function" then |
||
1551 | if t.passValue then |
||
1552 | t.set(t.passValue, t.r,t.g,t.b) |
||
1553 | else |
||
1554 | t.set(t.r,t.g,t.b) |
||
1555 | end |
||
1556 | else |
||
1557 | if type(t.handler[t.set]) ~= "function" then |
||
1558 | AceConsole:error(OPTION_HANDLER_NOT_FOUND, t.set) |
||
1559 | end |
||
1560 | if t.passValue then |
||
1561 | t.handler[t.set](t.handler, t.passValue, t.r,t.g,t.b) |
||
1562 | else |
||
1563 | t.handler[t.set](t.handler, t.r,t.g,t.b) |
||
1564 | end |
||
1565 | end |
||
1566 | end |
||
1567 | for k,v in pairs(t) do |
||
1568 | t[k] = nil |
||
1569 | end |
||
1570 | ColorPickerFrame.cancelFunc = nil |
||
1571 | ColorPickerFrame.func = nil |
||
1572 | ColorPickerFrame.opacityFunc = nil |
||
1573 | end |
||
1574 | end |
||
1575 | |||
1576 | ColorPickerFrame.cancelFunc = colorCancelFunc |
||
1577 | |||
1578 | ShowUIPanel(ColorPickerFrame) |
||
1579 | end |
||
1580 | return |
||
1581 | elseif kind == "group" then |
||
1582 | if table.getn(args) == 0 then |
||
1583 | printUsage(self, handler, realOptions, options, path, args) |
||
1584 | else |
||
1585 | -- invalid argument |
||
1586 | print(string.format(options.error or IS_NOT_A_VALID_OPTION_FOR, args[1], path), realOptions.cmdName or realOptions.name or self) |
||
1587 | end |
||
1588 | return |
||
1589 | end |
||
1590 | this = _G_this |
||
1591 | if Dewdrop then |
||
1592 | Dewdrop:Refresh(1) |
||
1593 | Dewdrop:Refresh(2) |
||
1594 | Dewdrop:Refresh(3) |
||
1595 | Dewdrop:Refresh(4) |
||
1596 | Dewdrop:Refresh(5) |
||
1597 | end |
||
1598 | end |
||
1599 | |||
1600 | local external |
||
1601 | function AceConsole:RegisterChatCommand(slashCommands, options, name) |
||
1602 | if type(slashCommands) ~= "table" and slashCommands ~= false then |
||
1603 | AceConsole:error("Bad argument #2 to `RegisterChatCommand' (expected table, got %s)", type(slashCommands)) |
||
1604 | end |
||
1605 | if not slashCommands and type(name) ~= "string" then |
||
1606 | AceConsole:error("Bad argument #4 to `RegisterChatCommand' (expected string, got %s)", type(name)) |
||
1607 | end |
||
1608 | if type(options) ~= "table" and type(options) ~= "function" and options ~= nil then |
||
1609 | AceConsole:error("Bad argument #3 to `RegisterChatCommand' (expected table, function, or nil, got %s)", type(options)) |
||
1610 | end |
||
1611 | if name then |
||
1612 | if type(name) ~= "string" then |
||
1613 | AceConsole:error("Bad argument #4 to `RegisterChatCommand' (expected string or nil, got %s)", type(name)) |
||
1614 | elseif not string.find(name, "^%w+$") or string.upper(name) ~= name or string.len(name) == 0 then |
||
1615 | AceConsole:error("Argument #4 must be an uppercase, letters-only string with at least 1 character") |
||
1616 | end |
||
1617 | end |
||
1618 | if slashCommands then |
||
1619 | if table.getn(slashCommands) == 0 then |
||
1620 | AceConsole:error("Argument #2 to `RegisterChatCommand' must include at least one string") |
||
1621 | end |
||
1622 | |||
1623 | for k,v in pairs(slashCommands) do |
||
1624 | if type(k) ~= "number" then |
||
1625 | AceConsole:error("All keys in argument #2 to `RegisterChatCommand' must be numbers") |
||
1626 | end |
||
1627 | if type(v) ~= "string" then |
||
1628 | AceConsole:error("All values in argument #2 to `RegisterChatCommand' must be strings") |
||
1629 | elseif not string.find(v, "^/[A-Za-z][A-Za-z0-9_]*$") then |
||
1630 | AceConsole:error("All values in argument #2 to `RegisterChatCommand' must be in the form of \"/word\"") |
||
1631 | end |
||
1632 | end |
||
1633 | end |
||
1634 | |||
1635 | if not options then |
||
1636 | options = { |
||
1637 | type = 'group', |
||
1638 | args = {}, |
||
1639 | handler = self |
||
1640 | } |
||
1641 | end |
||
1642 | |||
1643 | if type(options) == "table" then |
||
1644 | local err, position = validateOptions(options) |
||
1645 | if err then |
||
1646 | if position then |
||
1647 | AceConsole:error(position .. ": " .. err) |
||
1648 | else |
||
1649 | AceConsole:error(err) |
||
1650 | end |
||
1651 | end |
||
1652 | |||
1653 | if not options.handler then |
||
1654 | options.handler = self |
||
1655 | end |
||
1656 | |||
1657 | if options.handler == self and string.lower(options.type) == "group" and self.class then |
||
1658 | AceConsole:InjectAceOptionsTable(self, options) |
||
1659 | end |
||
1660 | end |
||
1661 | |||
1662 | local chat |
||
1663 | if slashCommands then |
||
1664 | chat = slashCommands[1] |
||
1665 | else |
||
1666 | chat = _G["SLASH_"..name..1] |
||
1667 | end |
||
1668 | |||
1669 | local handler |
||
1670 | if type(options) == "function" then |
||
1671 | handler = options |
||
1672 | for k,v in pairs(_G) do |
||
1673 | if handler == v then |
||
1674 | local k = k |
||
1675 | handler = function(msg) |
||
1676 | return _G[k](msg) |
||
1677 | end |
||
1678 | end |
||
1679 | end |
||
1680 | else |
||
1681 | function handler(msg) |
||
1682 | handlerFunc(self, chat, msg, options) |
||
1683 | end |
||
1684 | end |
||
1685 | |||
1686 | if not _G.SlashCmdList then |
||
1687 | _G.SlashCmdList = {} |
||
1688 | end |
||
1689 | |||
1690 | if not name then |
||
1691 | repeat |
||
1692 | name = string.char(math.random(26) + string.byte('A') - 1) .. string.char(math.random(26) + string.byte('A') - 1) .. string.char(math.random(26) + string.byte('A') - 1) .. string.char(math.random(26) + string.byte('A') - 1) .. string.char(math.random(26) + string.byte('A') - 1) .. string.char(math.random(26) + string.byte('A') - 1) .. string.char(math.random(26) + string.byte('A') - 1) .. string.char(math.random(26) + string.byte('A') - 1) |
||
1693 | until not _G.SlashCmdList[name] |
||
1694 | end |
||
1695 | |||
1696 | if slashCommands then |
||
1697 | if _G.SlashCmdList[name] then |
||
1698 | local i = 0 |
||
1699 | while true do |
||
1700 | i = i + 1 |
||
1701 | if _G["SLASH_"..name..i] then |
||
1702 | _G["SLASH_"..name..i] = nil |
||
1703 | else |
||
1704 | break |
||
1705 | end |
||
1706 | end |
||
1707 | end |
||
1708 | |||
1709 | local i = 0 |
||
1710 | for _,command in ipairs(slashCommands) do |
||
1711 | i = i + 1 |
||
1712 | _G["SLASH_"..name..i] = command |
||
1713 | if string.lower(command) ~= command then |
||
1714 | i = i + 1 |
||
1715 | _G["SLASH_"..name..i] = string.lower(command) |
||
1716 | end |
||
1717 | end |
||
1718 | end |
||
1719 | _G.SlashCmdList[name] = handler |
||
1720 | if self ~= AceConsole and self.slashCommand == nil then |
||
1721 | self.slashCommand = chat |
||
1722 | end |
||
1723 | |||
1724 | if not AceEvent and AceLibrary:HasInstance("AceEvent-2.0") then |
||
1725 | external(AceConsole, "AceEvent-2.0", AceLibrary("AceEvent-2.0")) |
||
1726 | end |
||
1727 | if AceEvent then |
||
1728 | if not AceConsole.nextAddon then |
||
1729 | AceConsole.nextAddon = {} |
||
1730 | end |
||
1731 | if type(options) == "table" then |
||
1732 | AceConsole.nextAddon[self] = options |
||
1733 | if not self.playerLogin then |
||
1734 | AceConsole:RegisterEvent("PLAYER_LOGIN", "PLAYER_LOGIN", true) |
||
1735 | end |
||
1736 | end |
||
1737 | end |
||
1738 | |||
1739 | AceConsole.registry[name] = options |
||
1740 | end |
||
1741 | |||
1742 | function AceConsole:InjectAceOptionsTable(handler, options) |
||
1743 | self:argCheck(handler, 2, "table") |
||
1744 | self:argCheck(options, 3, "table") |
||
1745 | if string.lower(options.type) ~= "group" then |
||
1746 | self:error('Cannot inject into options table argument #3 if its type is not "group"') |
||
1747 | end |
||
1748 | if options.handler ~= nil and options.handler ~= handler then |
||
1749 | self:error("Cannot inject into options table argument #3 if it has a different handler than argument #2") |
||
1750 | end |
||
1751 | options.handler = handler |
||
1752 | local class = handler.class |
||
1753 | if not class then |
||
1754 | self:error("Cannot retrieve AceOptions tables from a non-object argument #2") |
||
1755 | end |
||
1756 | while class and class ~= AceOO.Class do |
||
1757 | if type(class.GetAceOptionsDataTable) == "function" then |
||
1758 | local t = class:GetAceOptionsDataTable(handler) |
||
1759 | for k,v in pairs(t) do |
||
1760 | if type(options.args) ~= "table" then |
||
1761 | options.args = {} |
||
1762 | end |
||
1763 | if options.args[k] == nil then |
||
1764 | options.args[k] = v |
||
1765 | end |
||
1766 | end |
||
1767 | end |
||
1768 | local mixins = class.mixins |
||
1769 | if mixins then |
||
1770 | for mixin in pairs(mixins) do |
||
1771 | if type(mixin.GetAceOptionsDataTable) == "function" then |
||
1772 | local t = mixin:GetAceOptionsDataTable(handler) |
||
1773 | for k,v in pairs(t) do |
||
1774 | if type(options.args) ~= "table" then |
||
1775 | options.args = {} |
||
1776 | end |
||
1777 | if options.args[k] == nil then |
||
1778 | options.args[k] = v |
||
1779 | end |
||
1780 | end |
||
1781 | end |
||
1782 | end |
||
1783 | end |
||
1784 | class = class.super |
||
1785 | end |
||
1786 | return options |
||
1787 | end |
||
1788 | |||
1789 | function AceConsole:PLAYER_LOGIN() |
||
1790 | self.playerLogin = true |
||
1791 | for addon, options in pairs(self.nextAddon) do |
||
1792 | local err, position = validateOptionsMethods(addon, options) |
||
1793 | if err then |
||
1794 | if position then |
||
1795 | error(tostring(addon) .. ": AceConsole: " .. position .. ": " .. err) |
||
1796 | else |
||
1797 | error(tostring(addon) .. ": AceConsole: " .. err) |
||
1798 | end |
||
1799 | end |
||
1800 | self.nextAddon[addon] = nil |
||
1801 | end |
||
1802 | |||
1803 | self:RegisterChatCommand({ "/reload", "/rl", "/reloadui" }, ReloadUI, "RELOAD") |
||
1804 | |||
1805 | local version = GetBuildInfo() |
||
1806 | if string.find(version, "^2%.") then |
||
1807 | -- 2.0.0 |
||
1808 | self:RegisterChatCommand({ "/print" }, function(text) |
||
1809 | RunScript("local function func(...) local arg = {...}; for k = 1,select('#', ...) do arg[k] = tostring(arg[k]) end DEFAULT_CHAT_FRAME:AddMessage(table.concat(arg, ' ')) end func(" .. text .. ")") |
||
1810 | end, "PRINT") |
||
1811 | else |
||
1812 | self:RegisterChatCommand({ "/print" }, function(text) |
||
1813 | RunScript("local function func(...) for k = 1,table.getn(arg) do arg[k] = tostring(arg[k]) end DEFAULT_CHAT_FRAME:AddMessage(table.concat(arg, ' ')) end func(" .. text .. ")") |
||
1814 | end, "PRINT") |
||
1815 | end |
||
1816 | end |
||
1817 | |||
1818 | function AceConsole:TabCompleteInfo(cmdpath) |
||
1819 | local _, _, cmd = string.find(cmdpath, "(/%S+)") |
||
1820 | if not cmd then |
||
1821 | return |
||
1822 | end |
||
1823 | local path = string.sub(cmdpath, string.len(cmd) + 2) |
||
1824 | for name in pairs(SlashCmdList) do --global |
||
1825 | if AceConsole.registry[name] then |
||
1826 | local i = 0 |
||
1827 | while true do |
||
1828 | i = i + 1 |
||
1829 | local scmd = _G["SLASH_"..name..i] |
||
1830 | if not scmd then break end |
||
1831 | if cmd == scmd then |
||
1832 | return name, cmd, path |
||
1833 | end |
||
1834 | end |
||
1835 | end |
||
1836 | end |
||
1837 | end |
||
1838 | |||
1839 | function external(self, major, instance) |
||
1840 | if major == "AceEvent-2.0" then |
||
1841 | if not AceEvent then |
||
1842 | AceEvent = instance |
||
1843 | |||
1844 | AceEvent:embed(self) |
||
1845 | end |
||
1846 | elseif major == "AceTab-2.0" then |
||
1847 | instance:RegisterTabCompletion("AceConsole", "%/.*", function(t, cmdpath, pos) |
||
1848 | local ac = AceLibrary("AceConsole-2.0") |
||
1849 | local name, cmd, path = ac:TabCompleteInfo(string.sub(cmdpath, 1, pos)) |
||
1850 | |||
1851 | if not ac.registry[name] then |
||
1852 | return false |
||
1853 | else |
||
1854 | local validArgs = findTableLevel(ac, ac.registry[name], cmd, path or "") |
||
1855 | if validArgs.args then |
||
1856 | for arg in pairs(validArgs.args) do |
||
1857 | table.insert(t, arg) |
||
1858 | end |
||
1859 | end |
||
1860 | end |
||
1861 | end, function(u, matches, gcs, cmdpath) |
||
1862 | local ac = AceLibrary("AceConsole-2.0") |
||
1863 | local name, cmd, path = ac:TabCompleteInfo(cmdpath) |
||
1864 | if ac.registry[name] then |
||
1865 | local validArgs, path2, argwork = findTableLevel(ac, ac.registry[name], cmd, path) |
||
1866 | printUsage(ac, validArgs.handler, ac.registry[name], validArgs, path2, argwork, not gcs or gcs ~= "", gcs) |
||
1867 | end |
||
1868 | end) |
||
1869 | elseif major == "Dewdrop-2.0" then |
||
1870 | Dewdrop = instance |
||
1871 | end |
||
1872 | end |
||
1873 | |||
1874 | local function activate(self, oldLib, oldDeactivate) |
||
1875 | AceConsole = self |
||
1876 | |||
1877 | self.super.activate(self, oldLib, oldDeactivate) |
||
1878 | |||
1879 | if oldLib then |
||
1880 | self.registry = oldLib.registry |
||
1881 | self.nextAddon = oldLib.nextAddon |
||
1882 | end |
||
1883 | if not self.registry then |
||
1884 | self.registry = {} |
||
1885 | else |
||
1886 | for name,options in pairs(self.registry) do |
||
1887 | self:RegisterChatCommand(false, options, name) |
||
1888 | end |
||
1889 | end |
||
1890 | |||
1891 | if oldDeactivate then |
||
1892 | oldDeactivate(oldLib) |
||
1893 | end |
||
1894 | end |
||
1895 | |||
1896 | AceLibrary:Register(AceConsole, MAJOR_VERSION, MINOR_VERSION, activate, nil, external) |
||
1897 | AceConsole = AceLibrary(MAJOR_VERSION) |