mirror of
https://github.com/Bluewhale1337/ElvUIModernized.git
synced 2026-07-27 08:24:44 +00:00
replace Ace3v with Ace3 ElvUI-TBC version
or easy tracking of code difference
This commit is contained in:
@@ -14,37 +14,28 @@ REQUIRES: AceConsole-3.0 for command registration (loaded on demand)
|
||||
|
||||
-- TODO: plugin args
|
||||
|
||||
local cfgreg = LibStub("AceConfigRegistry-3.0-ElvUI")
|
||||
|
||||
local MAJOR, MINOR = "AceConfigCmd-3.0", 13
|
||||
local MAJOR, MINOR = "AceConfigCmd-3.0-ElvUI", 14
|
||||
local AceConfigCmd = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
|
||||
if not AceConfigCmd then return end
|
||||
|
||||
local AceCore = LibStub("AceCore-3.0")
|
||||
local Dispatchers = AceCore.Dispatchers
|
||||
local strtrim = AceCore.strtrim
|
||||
--local strsplit = AceCore.strsplit
|
||||
local new, del = AceCore.new, AceCore.del
|
||||
local wipe = AceCore.wipe
|
||||
|
||||
AceConfigCmd.commands = AceConfigCmd.commands or {}
|
||||
AceConfigCmd.embeds = AceConfigCmd.embeds or {}
|
||||
local commands = AceConfigCmd.commands
|
||||
|
||||
local cfgreg = LibStub("AceConfigRegistry-3.0")
|
||||
local AceConsole -- LoD
|
||||
local AceConsoleName = "AceConsole-3.0"
|
||||
|
||||
-- Lua APIs
|
||||
local strbyte, strsub = string.byte, string.sub
|
||||
local strlen, strupper, strlower = string.len, string.upper, string.lower
|
||||
local strfind, strgfind, strgsub = string.find, string.gfind, string.gsub
|
||||
|
||||
local format = string.format
|
||||
local tsort, tinsert, tgetn, tremove = table.sort, table.insert, table.getn, table.remove
|
||||
local strsub, strsplit, strlower, strmatch, strtrim = string.sub, string.split, string.lower, string.match, string.trim
|
||||
local format, tonumber, tostring = string.format, tonumber, tostring
|
||||
local tsort, tinsert = table.sort, table.insert
|
||||
local select, pairs, next, type = select, pairs, next, type
|
||||
local error, assert = error, assert
|
||||
|
||||
-- WoW APIs
|
||||
local _G = AceCore._G
|
||||
local _G = _G
|
||||
|
||||
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
|
||||
-- List them here for Mikk's FindGlobals script
|
||||
@@ -69,7 +60,17 @@ local handlermsg = "expected a table"
|
||||
local functypes = {["function"]=true, ["string"]=true}
|
||||
local funcmsg = "expected function or member name"
|
||||
|
||||
local pickfirstset = AceCore.pickfirstset
|
||||
|
||||
-- pickfirstset() - picks the first non-nil value and returns it
|
||||
|
||||
local function pickfirstset(...)
|
||||
for i=1,select("#",...) do
|
||||
if select(i,...)~=nil then
|
||||
return select(i,...)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- err() - produce real error() regarding malformed options tables etc
|
||||
|
||||
@@ -89,26 +90,23 @@ end
|
||||
|
||||
-- callmethod() - call a given named method (e.g. "get", "set") with given arguments
|
||||
|
||||
|
||||
|
||||
local function callmethod(info, inputpos, tab, methodtype, argc, a1, a2, a3, a4)
|
||||
local function callmethod(info, inputpos, tab, methodtype, ...)
|
||||
local method = info[methodtype]
|
||||
if not method then
|
||||
err(info, inputpos, "'"..methodtype.."': not set")
|
||||
end
|
||||
|
||||
argc = argc or 0
|
||||
info.arg = tab.arg
|
||||
info.option = tab
|
||||
info.type = tab.type
|
||||
|
||||
if type(method)=="function" then
|
||||
return Dispatchers[argc+1](method, info, a1, a2, a3, a4)
|
||||
return method(info, ...)
|
||||
elseif type(method)=="string" then
|
||||
if type(info.handler[method])~="function" then
|
||||
err(info, inputpos, "'"..methodtype.."': '"..method.."' is not a member function of "..tostring(info.handler))
|
||||
end
|
||||
return Dispatchers[argc+2](info.handler[method], info.handler, info, a1, a2, a3, a4)
|
||||
return info.handler[method](info.handler, info, ...)
|
||||
else
|
||||
assert(false) -- type should have already been checked on read
|
||||
end
|
||||
@@ -116,8 +114,7 @@ end
|
||||
|
||||
-- callfunction() - call a given named function (e.g. "name", "desc") with given arguments
|
||||
|
||||
-- Ace3v: the variable arguments are currently unused, so we removed it
|
||||
local function callfunction(info, tab, methodtype)
|
||||
local function callfunction(info, tab, methodtype, ...)
|
||||
local method = tab[methodtype]
|
||||
|
||||
info.arg = tab.arg
|
||||
@@ -125,18 +122,17 @@ local function callfunction(info, tab, methodtype)
|
||||
info.type = tab.type
|
||||
|
||||
if type(method)=="function" then
|
||||
return method(info)
|
||||
return method(info, ...)
|
||||
else
|
||||
assert(false) -- type should have already been checked on read
|
||||
end
|
||||
end
|
||||
|
||||
-- do_final() - do the final step (set/execute) along with validation and confirmation
|
||||
-- Ace3v: experimental
|
||||
-- @param argc number of variable arguments
|
||||
local function do_final(info, inputpos, tab, methodtype, argc, a1, a2, a3, a4) -- currently maximum 4 arguments
|
||||
|
||||
local function do_final(info, inputpos, tab, methodtype, ...)
|
||||
if info.validate then
|
||||
local res = callmethod(info,inputpos,tab,"validate",argc,a1,a2,a3,a4)
|
||||
local res = callmethod(info,inputpos,tab,"validate",...)
|
||||
if type(res)=="string" then
|
||||
usererr(info, inputpos, "'"..strsub(info.input, inputpos).."' - "..res)
|
||||
return
|
||||
@@ -144,7 +140,7 @@ local function do_final(info, inputpos, tab, methodtype, argc, a1, a2, a3, a4) -
|
||||
end
|
||||
-- console ignores .confirm
|
||||
|
||||
callmethod(info,inputpos,tab,methodtype,argc,a1,a2,a3,a4)
|
||||
callmethod(info,inputpos,tab,methodtype, ...)
|
||||
end
|
||||
|
||||
|
||||
@@ -167,6 +163,8 @@ end
|
||||
|
||||
|
||||
-- iterateargs(tab) - custom iterator that iterates both t.args and t.plugins.*
|
||||
local dummytable={}
|
||||
|
||||
local function iterateargs(tab)
|
||||
if not tab.plugins then
|
||||
return pairs(tab.args)
|
||||
@@ -191,21 +189,17 @@ local function iterateargs(tab)
|
||||
end
|
||||
end
|
||||
|
||||
local function getValueFromTab(info, inputpos, tab, key)
|
||||
local v = tab[key]
|
||||
if type(v) == "function" or type(v) == "string" then
|
||||
info[key] = v
|
||||
v = callmethod(info, inputpos, tab, key)
|
||||
info[key] = nil
|
||||
end
|
||||
return v
|
||||
end
|
||||
|
||||
local function checkhidden(info, inputpos, tab)
|
||||
if tab.cmdHidden~=nil then
|
||||
return tab.cmdHidden
|
||||
end
|
||||
return getValueFromTab(info, inputpos, tab, "hidden")
|
||||
local hidden = tab.hidden
|
||||
if type(hidden) == "function" or type(hidden) == "string" then
|
||||
info.hidden = hidden
|
||||
hidden = callmethod(info, inputpos, tab, 'hidden')
|
||||
info.hidden = nil
|
||||
end
|
||||
return hidden
|
||||
end
|
||||
|
||||
local function showhelp(info, inputpos, tab, depth, noHead)
|
||||
@@ -213,8 +207,8 @@ local function showhelp(info, inputpos, tab, depth, noHead)
|
||||
print("|cff33ff99"..info.appName.."|r: Arguments to |cffffff78/"..info[0].."|r "..strsub(info.input,1,inputpos-1)..":")
|
||||
end
|
||||
|
||||
local sortTbl = new() -- [1..n]=name
|
||||
local refTbl = new() -- [name]=tableref
|
||||
local sortTbl = {} -- [1..n]=name
|
||||
local refTbl = {} -- [name]=tableref
|
||||
|
||||
for k,v in iterateargs(tab) do
|
||||
if not refTbl[k] then -- a plugin overriding something in .args
|
||||
@@ -228,16 +222,16 @@ local function showhelp(info, inputpos, tab, depth, noHead)
|
||||
local o2 = refTbl[two].order or 100
|
||||
if type(o1) == "function" or type(o1) == "string" then
|
||||
info.order = o1
|
||||
tinsert(info, one)
|
||||
info[#info+1] = one
|
||||
o1 = callmethod(info, inputpos, refTbl[one], "order")
|
||||
tremove(info)
|
||||
info[#info] = nil
|
||||
info.order = nil
|
||||
end
|
||||
if type(o2) == "function" or type(o1) == "string" then
|
||||
info.order = o2
|
||||
tinsert(info, two)
|
||||
info[#info+1] = two
|
||||
o2 = callmethod(info, inputpos, refTbl[two], "order")
|
||||
tremove(info)
|
||||
info[#info] = nil
|
||||
info.order = nil
|
||||
end
|
||||
if o1<0 and o2<0 then return o1<o2 end
|
||||
@@ -247,7 +241,7 @@ local function showhelp(info, inputpos, tab, depth, noHead)
|
||||
return o1<o2
|
||||
end)
|
||||
|
||||
for i = 1, tgetn(sortTbl) do
|
||||
for i = 1, #sortTbl do
|
||||
local k = sortTbl[i]
|
||||
local v = refTbl[k]
|
||||
if not checkhidden(info, inputpos, v) then
|
||||
@@ -260,27 +254,26 @@ local function showhelp(info, inputpos, tab, depth, noHead)
|
||||
if type(desc) == "function" then
|
||||
desc = callfunction(info, v, 'desc')
|
||||
end
|
||||
if v.type == "group" and pickfirstset(3, v.cmdInline, v.inline, false) then
|
||||
if v.type == "group" and pickfirstset(v.cmdInline, v.inline, false) then
|
||||
print(" "..(desc or name)..":")
|
||||
local oldhandler,oldhandler_at = getparam(info, inputpos, v, depth, "handler", handlertypes, handlermsg)
|
||||
showhelp(info, inputpos, v, depth, true)
|
||||
info.handler,info.handler_at = oldhandler,oldhandler_at
|
||||
else
|
||||
local key = strgsub(k, " ", "_")
|
||||
local key = k:gsub(" ", "_")
|
||||
print(" |cffffff78"..key.."|r - "..(desc or name or ""))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
del(sortTbl) -- Ace3v: release the tables
|
||||
del(refTbl)
|
||||
end
|
||||
|
||||
|
||||
local function keybindingValidateFunc(text)
|
||||
if text == nil or text == "NONE" then
|
||||
return nil
|
||||
end
|
||||
text = strupper(text)
|
||||
text = text:upper()
|
||||
local shift, ctrl, alt
|
||||
local modifier
|
||||
while true do
|
||||
@@ -318,7 +311,7 @@ local function keybindingValidateFunc(text)
|
||||
if text == "" then
|
||||
return false
|
||||
end
|
||||
if not strfind(text,"^F%d+$") and text ~= "CAPSLOCK" and strlen(text) ~= 1 and (strbyte(text) < 128 or strlen(text) > 4) and not _G["KEY_" .. text] then
|
||||
if not text:find("^F%d+$") and text ~= "CAPSLOCK" and text:len() ~= 1 and (text:byte() < 128 or text:len() > 4) and not _G["KEY_" .. text] then
|
||||
return false
|
||||
end
|
||||
local s = text
|
||||
@@ -364,7 +357,7 @@ local function handle(info, inputpos, tab, depth, retfalse)
|
||||
if tab.plugins and type(tab.plugins)~="table" then err(info,inputpos) end
|
||||
|
||||
-- grab next arg from input
|
||||
local _,nextpos,arg = strfind(info.input, " *([^ ]+) *", inputpos)
|
||||
local _,nextpos,arg = (info.input):find(" *([^ ]+) *", inputpos)
|
||||
if not arg then
|
||||
showhelp(info, inputpos, tab, depth)
|
||||
return
|
||||
@@ -376,17 +369,17 @@ local function handle(info, inputpos, tab, depth, retfalse)
|
||||
if not(type(k)=="string" and type(v)=="table" and type(v.type)=="string") then err(info,inputpos, "options table child '"..tostring(k).."' is malformed") end
|
||||
|
||||
-- is this child an inline group? if so, traverse into it
|
||||
if v.type=="group" and pickfirstset(3, v.cmdInline, v.inline, false) then
|
||||
tinsert(info,k)
|
||||
if v.type=="group" and pickfirstset(v.cmdInline, v.inline, false) then
|
||||
info[depth+1] = k
|
||||
if handle(info, inputpos, v, depth+1, true)==false then
|
||||
tremove(info)
|
||||
info[depth+1] = nil
|
||||
-- wasn't found in there, but that's ok, we just keep looking down here
|
||||
else
|
||||
return -- done, name was found in inline group
|
||||
end
|
||||
-- matching name and not a inline group
|
||||
elseif strlower(arg)==strlower(strgsub(k, " ", "_")) then
|
||||
tinsert(info,k)
|
||||
elseif strlower(arg)==strlower(k:gsub(" ", "_")) then
|
||||
info[depth+1] = k
|
||||
return handle(info,nextpos,v,depth+1)
|
||||
end
|
||||
end
|
||||
@@ -419,21 +412,16 @@ local function handle(info, inputpos, tab, depth, retfalse)
|
||||
elseif tab.type=="input" then
|
||||
------------ input --------------------------------------------
|
||||
|
||||
if str=="" and tab.nullable == false then
|
||||
usererr(info, inputpos, "'"..str.."' - " .. L["invalid input"])
|
||||
return
|
||||
end
|
||||
|
||||
local res = true
|
||||
if tab.pattern then
|
||||
if not(type(tab.pattern)=="string") then err(info, inputpos, "'pattern' - expected a string") end
|
||||
if not strfind(str, tab.pattern) then
|
||||
if not strmatch(str, tab.pattern) then
|
||||
usererr(info, inputpos, "'"..str.."' - " .. L["invalid input"])
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
do_final(info, inputpos, tab, "set", 1, str)
|
||||
do_final(info, inputpos, tab, "set", str)
|
||||
|
||||
|
||||
|
||||
@@ -472,71 +460,54 @@ local function handle(info, inputpos, tab, depth, retfalse)
|
||||
return
|
||||
end
|
||||
|
||||
do_final(info, inputpos, tab, "set", 1, b)
|
||||
do_final(info, inputpos, tab, "set", b)
|
||||
|
||||
|
||||
elseif tab.type=="range" then
|
||||
------------ range --------------------------------------------
|
||||
local str = strtrim(strlower(str))
|
||||
if str == "" then
|
||||
-- TODO: Show current value
|
||||
return
|
||||
end
|
||||
|
||||
local val = tonumber(str)
|
||||
if not val then
|
||||
usererr(info, inputpos, "'"..str.."' - "..L["expected number"])
|
||||
return
|
||||
end
|
||||
|
||||
local step = getValueFromTab(info, inputpos, tab, "step")
|
||||
local min = getValueFromTab(info, inputpos, tab, "min")
|
||||
|
||||
if type(step)=="number" then
|
||||
val = min + math.floor((val-min)/step) * step
|
||||
if type(info.step)=="number" then
|
||||
val = val- (val % info.step)
|
||||
end
|
||||
|
||||
if type(min)=="number" and val<min then
|
||||
usererr(info, inputpos, val.." - "..format(L["must be equal to or higher than %s"], tostring(min)) )
|
||||
if type(info.min)=="number" and val<info.min then
|
||||
usererr(info, inputpos, val.." - "..format(L["must be equal to or higher than %s"], tostring(info.min)) )
|
||||
return
|
||||
end
|
||||
if type(info.max)=="number" and val>info.max then
|
||||
usererr(info, inputpos, val.." - "..format(L["must be equal to or lower than %s"], tostring(info.max)) )
|
||||
return
|
||||
end
|
||||
|
||||
local max = getValueFromTab(info, inputpos, tab, "max")
|
||||
if type(max)=="number" and val>max then
|
||||
usererr(info, inputpos, val.." - "..format(L["must be equal to or lower than %s"], tostring(max)) )
|
||||
return
|
||||
end
|
||||
|
||||
do_final(info, inputpos, tab, "set", 1, val)
|
||||
do_final(info, inputpos, tab, "set", val)
|
||||
|
||||
|
||||
elseif tab.type=="select" then
|
||||
------------ select ------------------------------------
|
||||
local str = strtrim(strlower(str))
|
||||
|
||||
local values = getValueFromTab(info, inputpos, tab, "values")
|
||||
local values = tab.values
|
||||
if type(values) == "function" or type(values) == "string" then
|
||||
info.values = values
|
||||
values = callmethod(info, inputpos, tab, "values")
|
||||
info.values = nil
|
||||
end
|
||||
|
||||
if str == "" then
|
||||
-- Ace3v: it is possbile to not have a current value
|
||||
-- we do this only for select but not for multiselect
|
||||
local b = tab.get
|
||||
if type(b) == "function" or type(b) == "string" then
|
||||
b = callmethod(info, inputpos, tab, "get")
|
||||
else
|
||||
b = nil
|
||||
end
|
||||
|
||||
local b = callmethod(info, inputpos, tab, "get")
|
||||
local fmt = "|cffffff78- [%s]|r %s"
|
||||
local fmt_sel = "|cffffff78- [%s]|r %s |cffff0000*|r"
|
||||
print(L["Options for |cffffff78"..info[tgetn(info)].."|r:"])
|
||||
print(L["Options for |cffffff78"..info[#info].."|r:"])
|
||||
for k, v in pairs(values) do
|
||||
if b == k then
|
||||
print(format(fmt_sel, k, v))
|
||||
print(fmt_sel:format(k, v))
|
||||
else
|
||||
print(format(fmt, k, v))
|
||||
print(fmt:format(k, v))
|
||||
end
|
||||
end
|
||||
if tab.valuesTableDestroyable then del(values) end
|
||||
return
|
||||
end
|
||||
|
||||
@@ -548,42 +519,45 @@ local function handle(info, inputpos, tab, depth, retfalse)
|
||||
break
|
||||
end
|
||||
end
|
||||
if tab.valuesTableDestroyable then del(values) end
|
||||
if not ok then
|
||||
usererr(info, inputpos, "'"..str.."' - "..L["unknown selection"])
|
||||
return
|
||||
end
|
||||
|
||||
do_final(info, inputpos, tab, "set", 1, str)
|
||||
do_final(info, inputpos, tab, "set", str)
|
||||
|
||||
elseif tab.type=="multiselect" then
|
||||
------------ multiselect -------------------------------------------
|
||||
local str = strtrim(strlower(str))
|
||||
|
||||
local values = getValueFromTab(info, inputpos, tab, "values")
|
||||
local values = tab.values
|
||||
if type(values) == "function" or type(values) == "string" then
|
||||
info.values = values
|
||||
values = callmethod(info, inputpos, tab, "values")
|
||||
info.values = nil
|
||||
end
|
||||
|
||||
if str == "" then
|
||||
local fmt = "|cffffff78- [%s]|r %s"
|
||||
local fmt_sel = "|cffffff78- [%s]|r %s |cffff0000*|r"
|
||||
print(L["Options for |cffffff78"..info[tgetn(info)].."|r (multiple possible):"])
|
||||
print(L["Options for |cffffff78"..info[#info].."|r (multiple possible):"])
|
||||
for k, v in pairs(values) do
|
||||
if callmethod(info, inputpos, tab, "get", 1, k) then
|
||||
print(format(fmt_sel, k, v))
|
||||
if callmethod(info, inputpos, tab, "get", k) then
|
||||
print(fmt_sel:format(k, v))
|
||||
else
|
||||
print(format(fmt, k, v))
|
||||
print(fmt:format(k, v))
|
||||
end
|
||||
end
|
||||
if tab.valuesTableDestroyable then del(values) end
|
||||
return
|
||||
end
|
||||
|
||||
--build a table of the selections, checking that they exist
|
||||
--parse for =on =off =default in the process
|
||||
--table will be key = true for options that should toggle, key = [on|off|default] for options to be set
|
||||
local sels = new()
|
||||
for v in strgfind(str, "[^ ]+") do
|
||||
local sels = {}
|
||||
for v in str:gmatch("[^ ]+") do
|
||||
--parse option=on etc
|
||||
local _, _, opt, val = strfind(v, '(.+)=(.+)')
|
||||
local opt, val = v:match('(.+)=(.+)')
|
||||
--get option if toggling
|
||||
if not opt then
|
||||
opt = v
|
||||
@@ -598,7 +572,6 @@ local function handle(info, inputpos, tab, depth, retfalse)
|
||||
break
|
||||
end
|
||||
end
|
||||
if tab.valuesTableDestroyable then del(values) end
|
||||
|
||||
if not ok then
|
||||
usererr(info, inputpos, "'"..opt.."' - "..L["unknown selection"])
|
||||
@@ -616,7 +589,6 @@ local function handle(info, inputpos, tab, depth, retfalse)
|
||||
else
|
||||
usererr(info, inputpos, format(L["'%s' '%s' - expected 'on' or 'off', or no argument to toggle."], v, val))
|
||||
end
|
||||
del(sels)
|
||||
return
|
||||
end
|
||||
else
|
||||
@@ -630,7 +602,7 @@ local function handle(info, inputpos, tab, depth, retfalse)
|
||||
|
||||
if (val == true) then
|
||||
--toggle the option
|
||||
local b = callmethod(info, inputpos, tab, "get", 1, opt)
|
||||
local b = callmethod(info, inputpos, tab, "get", opt)
|
||||
|
||||
if tab.tristate then
|
||||
--cycle in true, nil, false order
|
||||
@@ -656,9 +628,8 @@ local function handle(info, inputpos, tab, depth, retfalse)
|
||||
end
|
||||
end
|
||||
|
||||
do_final(info, inputpos, tab, "set", 2, opt, newval)
|
||||
do_final(info, inputpos, tab, "set", opt, newval)
|
||||
end
|
||||
del(sels)
|
||||
|
||||
|
||||
elseif tab.type=="color" then
|
||||
@@ -669,17 +640,22 @@ local function handle(info, inputpos, tab, depth, retfalse)
|
||||
return
|
||||
end
|
||||
|
||||
local _, r, g, b, a
|
||||
local r, g, b, a
|
||||
|
||||
local hasAlpha = getValueFromTab(info, inputpos, tab, 'hasAlpha')
|
||||
local hasAlpha = tab.hasAlpha
|
||||
if type(hasAlpha) == "function" or type(hasAlpha) == "string" then
|
||||
info.hasAlpha = hasAlpha
|
||||
hasAlpha = callmethod(info, inputpos, tab, 'hasAlpha')
|
||||
info.hasAlpha = nil
|
||||
end
|
||||
|
||||
if hasAlpha then
|
||||
if strlen(str) == 8 and strfind(str, "^%x*$") then
|
||||
if str:len() == 8 and str:find("^%x*$") then
|
||||
--parse a hex string
|
||||
r,g,b,a = tonumber(strsub(str, 1, 2), 16) / 255, tonumber(strsub(str, 3, 4), 16) / 255, tonumber(strsub(str, 5, 6), 16) / 255, tonumber(strsub(str, 7, 8), 16) / 255
|
||||
r,g,b,a = tonumber(str:sub(1, 2), 16) / 255, tonumber(str:sub(3, 4), 16) / 255, tonumber(str:sub(5, 6), 16) / 255, tonumber(str:sub(7, 8), 16) / 255
|
||||
else
|
||||
--parse seperate values
|
||||
_,_,r,g,b,a = strfind(str, "^([%d%.]+) ([%d%.]+) ([%d%.]+) ([%d%.]+)$")
|
||||
r,g,b,a = str:match("^([%d%.]+) ([%d%.]+) ([%d%.]+) ([%d%.]+)$")
|
||||
r,g,b,a = tonumber(r), tonumber(g), tonumber(b), tonumber(a)
|
||||
end
|
||||
if not (r and g and b and a) then
|
||||
@@ -701,12 +677,12 @@ local function handle(info, inputpos, tab, depth, retfalse)
|
||||
end
|
||||
else
|
||||
a = 1.0
|
||||
if strlen(str) == 6 and strfind(str, "^%x*$") then
|
||||
if str:len() == 6 and str:find("^%x*$") then
|
||||
--parse a hex string
|
||||
r,g,b = tonumber(strsub(str, 1, 2), 16) / 255, tonumber(strsub(str, 3, 4), 16) / 255, tonumber(strsub(str, 5, 6), 16) / 255
|
||||
r,g,b = tonumber(str:sub(1, 2), 16) / 255, tonumber(str:sub(3, 4), 16) / 255, tonumber(str:sub(5, 6), 16) / 255
|
||||
else
|
||||
--parse seperate values
|
||||
_,_,r,g,b = strfind(str, "^([%d%.]+) ([%d%.]+) ([%d%.]+)$")
|
||||
r,g,b = str:match("^([%d%.]+) ([%d%.]+) ([%d%.]+)$")
|
||||
r,g,b = tonumber(r), tonumber(g), tonumber(b)
|
||||
end
|
||||
if not (r and g and b) then
|
||||
@@ -726,7 +702,7 @@ local function handle(info, inputpos, tab, depth, retfalse)
|
||||
end
|
||||
end
|
||||
|
||||
do_final(info, inputpos, tab, "set", 4, r,g,b,a)
|
||||
do_final(info, inputpos, tab, "set", r,g,b,a)
|
||||
|
||||
elseif tab.type=="keybinding" then
|
||||
------------ keybinding --------------------------------------------
|
||||
@@ -735,13 +711,13 @@ local function handle(info, inputpos, tab, depth, retfalse)
|
||||
--TODO: Show current value
|
||||
return
|
||||
end
|
||||
local value = keybindingValidateFunc(strupper(str))
|
||||
local value = keybindingValidateFunc(str:upper())
|
||||
if value == false then
|
||||
usererr(info, inputpos, format(L["'%s' - Invalid Keybinding."], str))
|
||||
return
|
||||
end
|
||||
|
||||
do_final(info, inputpos, tab, "set", 1, value)
|
||||
do_final(info, inputpos, tab, "set", value)
|
||||
|
||||
elseif tab.type=="description" then
|
||||
------------ description --------------------
|
||||
@@ -771,9 +747,6 @@ end
|
||||
-- LibStub("AceConfigCmd-3.0").HandleCommand(MyAddon, "mychat", "MyOptions", input)
|
||||
-- end
|
||||
-- end
|
||||
-- Ace3v: experimental, user should copy info table if he wanna reuse it outside
|
||||
-- then handler
|
||||
local info_ = {}
|
||||
function AceConfigCmd:HandleCommand(slashcmd, appName, input)
|
||||
|
||||
local optgetter = cfgreg:GetOptionsTable(appName)
|
||||
@@ -782,65 +755,32 @@ function AceConfigCmd:HandleCommand(slashcmd, appName, input)
|
||||
end
|
||||
local options = assert( optgetter("cmd", MAJOR) )
|
||||
|
||||
-- Ace3v: prevent user from using AceConfigCmd as self
|
||||
if self == AceConfigCmd then
|
||||
error([[Usage: HandleCommand("slashcmd", "appName", "input"): 'self' - use your own 'self']], 2)
|
||||
end
|
||||
local info = { -- Don't try to recycle this, it gets handed off to callbacks and whatnot
|
||||
[0] = slashcmd,
|
||||
appName = appName,
|
||||
options = options,
|
||||
input = input,
|
||||
self = self,
|
||||
handler = self,
|
||||
uiType = "cmd",
|
||||
uiName = MAJOR,
|
||||
}
|
||||
|
||||
--local info = { -- Don't try to recycle this, it gets handed off to callbacks and whatnot
|
||||
-- [0] = slashcmd,
|
||||
-- appName = appName,
|
||||
-- options = options,
|
||||
-- input = input,
|
||||
-- self = self,
|
||||
-- handler = self,
|
||||
-- uiType = "cmd",
|
||||
-- uiName = MAJOR,
|
||||
--}
|
||||
|
||||
wipe(info_)
|
||||
info_[0] = slashcmd
|
||||
info_.appName = appName
|
||||
info_.options = options
|
||||
info_.input = input
|
||||
info_.self = self
|
||||
info_.handler = self
|
||||
info_.uiType = "cmd"
|
||||
info_.uiName = MAJOR
|
||||
|
||||
handle(info_, 1, options, 0) -- (info, inputpos, table, depth)
|
||||
handle(info, 1, options, 0) -- (info, inputpos, table, depth)
|
||||
end
|
||||
|
||||
--- Utility function to create a slash command handler.
|
||||
-- Also registers tab completion with AceTab
|
||||
-- @param slashcmd The slash command WITHOUT leading slash (only used for error output)
|
||||
-- @param appName The application name as given to `:RegisterOptionsTable()`
|
||||
function AceConfigCmd:CreateChatCommand(slashcmd, appName, func)
|
||||
function AceConfigCmd:CreateChatCommand(slashcmd, appName)
|
||||
if not AceConsole then
|
||||
AceConsole = LibStub(AceConsoleName)
|
||||
end
|
||||
|
||||
-- Ace3v: prevent user from using AceConfigCmd as self
|
||||
if self == AceConfigCmd then
|
||||
error([[Usage: CreateChatCommand("slashcmd", "appName"[, "func"]): 'self' - use your own 'self']], 2)
|
||||
end
|
||||
|
||||
local t = type(func)
|
||||
|
||||
-- Ace3v: make it possible to call another function
|
||||
local handler
|
||||
if t == "string" then
|
||||
handler = function(input) self[func](self, input, slashcmd, appName) end
|
||||
elseif t ~= "function" then
|
||||
handler = function(input)
|
||||
AceConfigCmd.HandleCommand(self, slashcmd, appName, input) -- upgradable
|
||||
end
|
||||
else
|
||||
handler = func
|
||||
end
|
||||
|
||||
if AceConsole.RegisterChatCommand(self, slashcmd, handler, true) then
|
||||
-- succesfully registered so lets get the command -> app table in
|
||||
if AceConsole.RegisterChatCommand(self, slashcmd, function(input)
|
||||
AceConfigCmd.HandleCommand(self, slashcmd, appName, input) -- upgradable
|
||||
end,
|
||||
true) then -- succesfully registered so lets get the command -> app table in
|
||||
commands[slashcmd] = appName
|
||||
end
|
||||
end
|
||||
@@ -852,12 +792,3 @@ end
|
||||
function AceConfigCmd:GetChatCommandOptions(slashcmd)
|
||||
return commands[slashcmd]
|
||||
end
|
||||
|
||||
function AceConfigCmd:Embed(target)
|
||||
target["HandleCommand"] = self["HandleCommand"]
|
||||
target["CreateChatCommand"] = self["CreateChatCommand"]
|
||||
end
|
||||
|
||||
for addon in pairs(AceConfigCmd.embeds) do
|
||||
AceConfigCmd:Embed(addon)
|
||||
end
|
||||
Reference in New Issue
Block a user