vanilla-wow-addons – Blame information for rev 1

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