tercio@0: --- AceConfigDialog-3.0 generates AceGUI-3.0 based windows based on option tables. tercio@0: -- @class file tercio@0: -- @name AceConfigDialog-3.0 tercio@0: -- @release $Id: AceConfigDialog-3.0.lua 1089 2013-09-13 14:32:35Z nevcairiel $ tercio@0: tercio@0: local LibStub = LibStub tercio@0: local MAJOR, MINOR = "AceConfigDialog-3.0", 58 tercio@0: local AceConfigDialog, oldminor = LibStub:NewLibrary(MAJOR, MINOR) tercio@0: tercio@0: if not AceConfigDialog then return end tercio@0: tercio@0: AceConfigDialog.OpenFrames = AceConfigDialog.OpenFrames or {} tercio@0: AceConfigDialog.Status = AceConfigDialog.Status or {} tercio@0: AceConfigDialog.frame = AceConfigDialog.frame or CreateFrame("Frame") tercio@0: tercio@0: AceConfigDialog.frame.apps = AceConfigDialog.frame.apps or {} tercio@0: AceConfigDialog.frame.closing = AceConfigDialog.frame.closing or {} tercio@0: AceConfigDialog.frame.closeAllOverride = AceConfigDialog.frame.closeAllOverride or {} tercio@0: tercio@0: local gui = LibStub("AceGUI-3.0") tercio@0: local reg = LibStub("AceConfigRegistry-3.0") tercio@0: tercio@0: -- Lua APIs tercio@0: local tconcat, tinsert, tsort, tremove, tsort = table.concat, table.insert, table.sort, table.remove, table.sort tercio@0: local strmatch, format = string.match, string.format tercio@0: local assert, loadstring, error = assert, loadstring, error tercio@0: local pairs, next, select, type, unpack, wipe, ipairs = pairs, next, select, type, unpack, wipe, ipairs tercio@0: local rawset, tostring, tonumber = rawset, tostring, tonumber tercio@0: local math_min, math_max, math_floor = math.min, math.max, math.floor tercio@0: tercio@0: -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded tercio@0: -- List them here for Mikk's FindGlobals script tercio@0: -- GLOBALS: NORMAL_FONT_COLOR, GameTooltip, StaticPopupDialogs, ACCEPT, CANCEL, StaticPopup_Show tercio@0: -- GLOBALS: PlaySound, GameFontHighlight, GameFontHighlightSmall, GameFontHighlightLarge tercio@0: -- GLOBALS: CloseSpecialWindows, InterfaceOptions_AddCategory, geterrorhandler tercio@0: tercio@0: local emptyTbl = {} tercio@0: tercio@0: --[[ tercio@0: xpcall safecall implementation tercio@0: ]] tercio@0: local xpcall = xpcall tercio@0: tercio@0: local function errorhandler(err) tercio@0: return geterrorhandler()(err) tercio@0: end tercio@0: tercio@0: local function CreateDispatcher(argCount) tercio@0: local code = [[ tercio@0: local xpcall, eh = ... tercio@0: local method, ARGS tercio@0: local function call() return method(ARGS) end tercio@0: tercio@0: local function dispatch(func, ...) tercio@0: method = func tercio@0: if not method then return end tercio@0: ARGS = ... tercio@0: return xpcall(call, eh) tercio@0: end tercio@0: tercio@0: return dispatch tercio@0: ]] tercio@0: tercio@0: local ARGS = {} tercio@0: for i = 1, argCount do ARGS[i] = "arg"..i end tercio@0: code = code:gsub("ARGS", tconcat(ARGS, ", ")) tercio@0: return assert(loadstring(code, "safecall Dispatcher["..argCount.."]"))(xpcall, errorhandler) tercio@0: end tercio@0: tercio@0: local Dispatchers = setmetatable({}, {__index=function(self, argCount) tercio@0: local dispatcher = CreateDispatcher(argCount) tercio@0: rawset(self, argCount, dispatcher) tercio@0: return dispatcher tercio@0: end}) tercio@0: Dispatchers[0] = function(func) tercio@0: return xpcall(func, errorhandler) tercio@0: end tercio@0: tercio@0: local function safecall(func, ...) tercio@0: return Dispatchers[select("#", ...)](func, ...) tercio@0: end tercio@0: tercio@0: local width_multiplier = 170 tercio@0: tercio@0: --[[ tercio@0: Group Types tercio@0: Tree - All Descendant Groups will all become nodes on the tree, direct child options will appear above the tree tercio@0: - Descendant Groups with inline=true and thier children will not become nodes tercio@0: tercio@0: Tab - Direct Child Groups will become tabs, direct child options will appear above the tab control tercio@0: - Grandchild groups will default to inline unless specified otherwise tercio@0: tercio@0: Select- Same as Tab but with entries in a dropdown rather than tabs tercio@0: tercio@0: tercio@0: Inline Groups tercio@0: - Will not become nodes of a select group, they will be effectivly part of thier parent group seperated by a border tercio@0: - If declared on a direct child of a root node of a select group, they will appear above the group container control tercio@0: - When a group is displayed inline, all descendants will also be inline members of the group tercio@0: tercio@0: ]] tercio@0: tercio@0: -- Recycling functions tercio@0: local new, del, copy tercio@0: --newcount, delcount,createdcount,cached = 0,0,0 tercio@0: do tercio@0: local pool = setmetatable({},{__mode="k"}) tercio@0: function new() tercio@0: --newcount = newcount + 1 tercio@0: local t = next(pool) tercio@0: if t then tercio@0: pool[t] = nil tercio@0: return t tercio@0: else tercio@0: --createdcount = createdcount + 1 tercio@0: return {} tercio@0: end tercio@0: end tercio@0: function copy(t) tercio@0: local c = new() tercio@0: for k, v in pairs(t) do tercio@0: c[k] = v tercio@0: end tercio@0: return c tercio@0: end tercio@0: function del(t) tercio@0: --delcount = delcount + 1 tercio@0: wipe(t) tercio@0: pool[t] = true tercio@0: end tercio@0: -- function cached() tercio@0: -- local n = 0 tercio@0: -- for k in pairs(pool) do tercio@0: -- n = n + 1 tercio@0: -- end tercio@0: -- return n tercio@0: -- end tercio@0: end tercio@0: tercio@0: -- picks the first non-nil value and returns it tercio@0: local function pickfirstset(...) tercio@0: for i=1,select("#",...) do tercio@0: if select(i,...)~=nil then tercio@0: return select(i,...) tercio@0: end tercio@0: end tercio@0: end tercio@0: tercio@0: --gets an option from a given group, checking plugins tercio@0: local function GetSubOption(group, key) tercio@0: if group.plugins then tercio@0: for plugin, t in pairs(group.plugins) do tercio@0: if t[key] then tercio@0: return t[key] tercio@0: end tercio@0: end tercio@0: end tercio@0: tercio@0: return group.args[key] tercio@0: end tercio@0: tercio@0: --Option member type definitions, used to decide how to access it tercio@0: tercio@0: --Is the member Inherited from parent options tercio@0: local isInherited = { tercio@0: set = true, tercio@0: get = true, tercio@0: func = true, tercio@0: confirm = true, tercio@0: validate = true, tercio@0: disabled = true, tercio@0: hidden = true tercio@0: } tercio@0: tercio@0: --Does a string type mean a literal value, instead of the default of a method of the handler tercio@0: local stringIsLiteral = { tercio@0: name = true, tercio@0: desc = true, tercio@0: icon = true, tercio@0: usage = true, tercio@0: width = true, tercio@0: image = true, tercio@0: fontSize = true, tercio@0: } tercio@0: tercio@0: --Is Never a function or method tercio@0: local allIsLiteral = { tercio@0: type = true, tercio@0: descStyle = true, tercio@0: imageWidth = true, tercio@0: imageHeight = true, tercio@0: } tercio@0: tercio@0: --gets the value for a member that could be a function tercio@0: --function refs are called with an info arg tercio@0: --every other type is returned tercio@0: local function GetOptionsMemberValue(membername, option, options, path, appName, ...) tercio@0: --get definition for the member tercio@0: local inherits = isInherited[membername] tercio@0: tercio@0: tercio@0: --get the member of the option, traversing the tree if it can be inherited tercio@0: local member tercio@0: tercio@0: if inherits then tercio@0: local group = options tercio@0: if group[membername] ~= nil then tercio@0: member = group[membername] tercio@0: end tercio@0: for i = 1, #path do tercio@0: group = GetSubOption(group, path[i]) tercio@0: if group[membername] ~= nil then tercio@0: member = group[membername] tercio@0: end tercio@0: end tercio@0: else tercio@0: member = option[membername] tercio@0: end tercio@0: tercio@0: --check if we need to call a functon, or if we have a literal value tercio@0: if ( not allIsLiteral[membername] ) and ( type(member) == "function" or ((not stringIsLiteral[membername]) and type(member) == "string") ) then tercio@0: --We have a function to call tercio@0: local info = new() tercio@0: --traverse the options table, picking up the handler and filling the info with the path tercio@0: local handler tercio@0: local group = options tercio@0: handler = group.handler or handler tercio@0: tercio@0: for i = 1, #path do tercio@0: group = GetSubOption(group, path[i]) tercio@0: info[i] = path[i] tercio@0: handler = group.handler or handler tercio@0: end tercio@0: tercio@0: info.options = options tercio@0: info.appName = appName tercio@0: info[0] = appName tercio@0: info.arg = option.arg tercio@0: info.handler = handler tercio@0: info.option = option tercio@0: info.type = option.type tercio@0: info.uiType = "dialog" tercio@0: info.uiName = MAJOR tercio@0: tercio@0: local a, b, c ,d tercio@0: --using 4 returns for the get of a color type, increase if a type needs more tercio@0: if type(member) == "function" then tercio@0: --Call the function tercio@0: a,b,c,d = member(info, ...) tercio@0: else tercio@0: --Call the method tercio@0: if handler and handler[member] then tercio@0: a,b,c,d = handler[member](handler, info, ...) tercio@0: else tercio@0: error(format("Method %s doesn't exist in handler for type %s", member, membername)) tercio@0: end tercio@0: end tercio@0: del(info) tercio@0: return a,b,c,d tercio@0: else tercio@0: --The value isnt a function to call, return it tercio@0: return member tercio@0: end tercio@0: end tercio@0: tercio@0: --[[calls an options function that could be inherited, method name or function ref tercio@0: local function CallOptionsFunction(funcname ,option, options, path, appName, ...) tercio@0: local info = new() tercio@0: tercio@0: local func tercio@0: local group = options tercio@0: local handler tercio@0: tercio@0: --build the info table containing the path tercio@0: -- pick up functions while traversing the tree tercio@0: if group[funcname] ~= nil then tercio@0: func = group[funcname] tercio@0: end tercio@0: handler = group.handler or handler tercio@0: tercio@0: for i, v in ipairs(path) do tercio@0: group = GetSubOption(group, v) tercio@0: info[i] = v tercio@0: if group[funcname] ~= nil then tercio@0: func = group[funcname] tercio@0: end tercio@0: handler = group.handler or handler tercio@0: end tercio@0: tercio@0: info.options = options tercio@0: info[0] = appName tercio@0: info.arg = option.arg tercio@0: tercio@0: local a, b, c ,d tercio@0: if type(func) == "string" then tercio@0: if handler and handler[func] then tercio@0: a,b,c,d = handler[func](handler, info, ...) tercio@0: else tercio@0: error(string.format("Method %s doesn't exist in handler for type func", func)) tercio@0: end tercio@0: elseif type(func) == "function" then tercio@0: a,b,c,d = func(info, ...) tercio@0: end tercio@0: del(info) tercio@0: return a,b,c,d tercio@0: end tercio@0: --]] tercio@0: tercio@0: --tables to hold orders and names for options being sorted, will be created with new() tercio@0: --prevents needing to call functions repeatedly while sorting tercio@0: local tempOrders tercio@0: local tempNames tercio@0: tercio@0: local function compareOptions(a,b) tercio@0: if not a then tercio@0: return true tercio@0: end tercio@0: if not b then tercio@0: return false tercio@0: end tercio@0: local OrderA, OrderB = tempOrders[a] or 100, tempOrders[b] or 100 tercio@0: if OrderA == OrderB then tercio@0: local NameA = (type(tempNames[a]) == "string") and tempNames[a] or "" tercio@0: local NameB = (type(tempNames[b]) == "string") and tempNames[b] or "" tercio@0: return NameA:upper() < NameB:upper() tercio@0: end tercio@0: if OrderA < 0 then tercio@0: if OrderB > 0 then tercio@0: return false tercio@0: end tercio@0: else tercio@0: if OrderB < 0 then tercio@0: return true tercio@0: end tercio@0: end tercio@0: return OrderA < OrderB tercio@0: end tercio@0: tercio@0: tercio@0: tercio@0: --builds 2 tables out of an options group tercio@0: -- keySort, sorted keys tercio@0: -- opts, combined options from .plugins and args tercio@0: local function BuildSortedOptionsTable(group, keySort, opts, options, path, appName) tercio@0: tempOrders = new() tercio@0: tempNames = new() tercio@0: tercio@0: if group.plugins then tercio@0: for plugin, t in pairs(group.plugins) do tercio@0: for k, v in pairs(t) do tercio@0: if not opts[k] then tercio@0: tinsert(keySort, k) tercio@0: opts[k] = v tercio@0: tercio@0: path[#path+1] = k tercio@0: tempOrders[k] = GetOptionsMemberValue("order", v, options, path, appName) tercio@0: tempNames[k] = GetOptionsMemberValue("name", v, options, path, appName) tercio@0: path[#path] = nil tercio@0: end tercio@0: end tercio@0: end tercio@0: end tercio@0: tercio@0: for k, v in pairs(group.args) do tercio@0: if not opts[k] then tercio@0: tinsert(keySort, k) tercio@0: opts[k] = v tercio@0: tercio@0: path[#path+1] = k tercio@0: tempOrders[k] = GetOptionsMemberValue("order", v, options, path, appName) tercio@0: tempNames[k] = GetOptionsMemberValue("name", v, options, path, appName) tercio@0: path[#path] = nil tercio@0: end tercio@0: end tercio@0: tercio@0: tsort(keySort, compareOptions) tercio@0: tercio@0: del(tempOrders) tercio@0: del(tempNames) tercio@0: end tercio@0: tercio@0: local function DelTree(tree) tercio@0: if tree.children then tercio@0: local childs = tree.children tercio@0: for i = 1, #childs do tercio@0: DelTree(childs[i]) tercio@0: del(childs[i]) tercio@0: end tercio@0: del(childs) tercio@0: end tercio@0: end tercio@0: tercio@0: local function CleanUserData(widget, event) tercio@0: tercio@0: local user = widget:GetUserDataTable() tercio@0: tercio@0: if user.path then tercio@0: del(user.path) tercio@0: end tercio@0: tercio@0: if widget.type == "TreeGroup" then tercio@0: local tree = user.tree tercio@0: widget:SetTree(nil) tercio@0: if tree then tercio@0: for i = 1, #tree do tercio@0: DelTree(tree[i]) tercio@0: del(tree[i]) tercio@0: end tercio@0: del(tree) tercio@0: end tercio@0: end tercio@0: tercio@0: if widget.type == "TabGroup" then tercio@0: widget:SetTabs(nil) tercio@0: if user.tablist then tercio@0: del(user.tablist) tercio@0: end tercio@0: end tercio@0: tercio@0: if widget.type == "DropdownGroup" then tercio@0: widget:SetGroupList(nil) tercio@0: if user.grouplist then tercio@0: del(user.grouplist) tercio@0: end tercio@0: if user.orderlist then tercio@0: del(user.orderlist) tercio@0: end tercio@0: end tercio@0: end tercio@0: tercio@0: -- - Gets a status table for the given appname and options path. tercio@0: -- @param appName The application name as given to `:RegisterOptionsTable()` tercio@0: -- @param path The path to the options (a table with all group keys) tercio@0: -- @return tercio@0: function AceConfigDialog:GetStatusTable(appName, path) tercio@0: local status = self.Status tercio@0: tercio@0: if not status[appName] then tercio@0: status[appName] = {} tercio@0: status[appName].status = {} tercio@0: status[appName].children = {} tercio@0: end tercio@0: tercio@0: status = status[appName] tercio@0: tercio@0: if path then tercio@0: for i = 1, #path do tercio@0: local v = path[i] tercio@0: if not status.children[v] then tercio@0: status.children[v] = {} tercio@0: status.children[v].status = {} tercio@0: status.children[v].children = {} tercio@0: end tercio@0: status = status.children[v] tercio@0: end tercio@0: end tercio@0: tercio@0: return status.status tercio@0: end tercio@0: tercio@0: --- Selects the specified path in the options window. tercio@0: -- The path specified has to match the keys of the groups in the table. tercio@0: -- @param appName The application name as given to `:RegisterOptionsTable()` tercio@0: -- @param ... The path to the key that should be selected tercio@0: function AceConfigDialog:SelectGroup(appName, ...) tercio@0: local path = new() tercio@0: tercio@0: tercio@0: local app = reg:GetOptionsTable(appName) tercio@0: if not app then tercio@0: error(("%s isn't registed with AceConfigRegistry, unable to open config"):format(appName), 2) tercio@0: end tercio@0: local options = app("dialog", MAJOR) tercio@0: local group = options tercio@0: local status = self:GetStatusTable(appName, path) tercio@0: if not status.groups then tercio@0: status.groups = {} tercio@0: end tercio@0: status = status.groups tercio@0: local treevalue tercio@0: local treestatus tercio@0: tercio@0: for n = 1, select("#",...) do tercio@0: local key = select(n, ...) tercio@0: tercio@0: if group.childGroups == "tab" or group.childGroups == "select" then tercio@0: --if this is a tab or select group, select the group tercio@0: status.selected = key tercio@0: --children of this group are no longer extra levels of a tree tercio@0: treevalue = nil tercio@0: else tercio@0: --tree group by default tercio@0: if treevalue then tercio@0: --this is an extra level of a tree group, build a uniquevalue for it tercio@0: treevalue = treevalue.."\001"..key tercio@0: else tercio@0: --this is the top level of a tree group, the uniquevalue is the same as the key tercio@0: treevalue = key tercio@0: if not status.groups then tercio@0: status.groups = {} tercio@0: end tercio@0: --save this trees status table for any extra levels or groups tercio@0: treestatus = status tercio@0: end tercio@0: --make sure that the tree entry is open, and select it. tercio@0: --the selected group will be overwritten if a child is the final target but still needs to be open tercio@0: treestatus.selected = treevalue tercio@0: treestatus.groups[treevalue] = true tercio@0: tercio@0: end tercio@0: tercio@0: --move to the next group in the path tercio@0: group = GetSubOption(group, key) tercio@0: if not group then tercio@0: break tercio@0: end tercio@0: tinsert(path, key) tercio@0: status = self:GetStatusTable(appName, path) tercio@0: if not status.groups then tercio@0: status.groups = {} tercio@0: end tercio@0: status = status.groups tercio@0: end tercio@0: tercio@0: del(path) tercio@0: reg:NotifyChange(appName) tercio@0: end tercio@0: tercio@0: local function OptionOnMouseOver(widget, event) tercio@0: --show a tooltip/set the status bar to the desc text tercio@0: local user = widget:GetUserDataTable() tercio@0: local opt = user.option tercio@0: local options = user.options tercio@0: local path = user.path tercio@0: local appName = user.appName tercio@0: tercio@0: GameTooltip:SetOwner(widget.frame, "ANCHOR_TOPRIGHT") tercio@0: local name = GetOptionsMemberValue("name", opt, options, path, appName) tercio@0: local desc = GetOptionsMemberValue("desc", opt, options, path, appName) tercio@0: local usage = GetOptionsMemberValue("usage", opt, options, path, appName) tercio@0: local descStyle = opt.descStyle tercio@0: tercio@0: if descStyle and descStyle ~= "tooltip" then return end tercio@0: tercio@0: GameTooltip:SetText(name, 1, .82, 0, 1) tercio@0: tercio@0: if opt.type == "multiselect" then tercio@0: GameTooltip:AddLine(user.text,0.5, 0.5, 0.8, 1) tercio@0: end tercio@0: if type(desc) == "string" then tercio@0: GameTooltip:AddLine(desc, 1, 1, 1, 1) tercio@0: end tercio@0: if type(usage) == "string" then tercio@0: GameTooltip:AddLine("Usage: "..usage, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, 1) tercio@0: end tercio@0: tercio@0: GameTooltip:Show() tercio@0: end tercio@0: tercio@0: local function OptionOnMouseLeave(widget, event) tercio@0: GameTooltip:Hide() tercio@0: end tercio@0: tercio@0: local function GetFuncName(option) tercio@0: local type = option.type tercio@0: if type == "execute" then tercio@0: return "func" tercio@0: else tercio@0: return "set" tercio@0: end tercio@0: end tercio@0: local function confirmPopup(appName, rootframe, basepath, info, message, func, ...) tercio@0: if not StaticPopupDialogs["ACECONFIGDIALOG30_CONFIRM_DIALOG"] then tercio@0: StaticPopupDialogs["ACECONFIGDIALOG30_CONFIRM_DIALOG"] = {} tercio@0: end tercio@0: local t = StaticPopupDialogs["ACECONFIGDIALOG30_CONFIRM_DIALOG"] tercio@0: for k in pairs(t) do tercio@0: t[k] = nil tercio@0: end tercio@0: t.text = message tercio@0: t.button1 = ACCEPT tercio@0: t.button2 = CANCEL tercio@0: t.preferredIndex = STATICPOPUP_NUMDIALOGS tercio@0: local dialog, oldstrata tercio@0: t.OnAccept = function() tercio@0: safecall(func, unpack(t)) tercio@0: if dialog and oldstrata then tercio@0: dialog:SetFrameStrata(oldstrata) tercio@0: end tercio@0: AceConfigDialog:Open(appName, rootframe, unpack(basepath or emptyTbl)) tercio@0: del(info) tercio@0: end tercio@0: t.OnCancel = function() tercio@0: if dialog and oldstrata then tercio@0: dialog:SetFrameStrata(oldstrata) tercio@0: end tercio@0: AceConfigDialog:Open(appName, rootframe, unpack(basepath or emptyTbl)) tercio@0: del(info) tercio@0: end tercio@0: for i = 1, select("#", ...) do tercio@0: t[i] = select(i, ...) or false tercio@0: end tercio@0: t.timeout = 0 tercio@0: t.whileDead = 1 tercio@0: t.hideOnEscape = 1 tercio@0: tercio@0: dialog = StaticPopup_Show("ACECONFIGDIALOG30_CONFIRM_DIALOG") tercio@0: if dialog then tercio@0: oldstrata = dialog:GetFrameStrata() tercio@0: dialog:SetFrameStrata("TOOLTIP") tercio@0: end tercio@0: end tercio@0: tercio@0: local function ActivateControl(widget, event, ...) tercio@0: --This function will call the set / execute handler for the widget tercio@0: --widget:GetUserDataTable() contains the needed info tercio@0: local user = widget:GetUserDataTable() tercio@0: local option = user.option tercio@0: local options = user.options tercio@0: local path = user.path tercio@0: local info = new() tercio@0: tercio@0: local func tercio@0: local group = options tercio@0: local funcname = GetFuncName(option) tercio@0: local handler tercio@0: local confirm tercio@0: local validate tercio@0: --build the info table containing the path tercio@0: -- pick up functions while traversing the tree tercio@0: if group[funcname] ~= nil then tercio@0: func = group[funcname] tercio@0: end tercio@0: handler = group.handler or handler tercio@0: confirm = group.confirm tercio@0: validate = group.validate tercio@0: for i = 1, #path do tercio@0: local v = path[i] tercio@0: group = GetSubOption(group, v) tercio@0: info[i] = v tercio@0: if group[funcname] ~= nil then tercio@0: func = group[funcname] tercio@0: end tercio@0: handler = group.handler or handler tercio@0: if group.confirm ~= nil then tercio@0: confirm = group.confirm tercio@0: end tercio@0: if group.validate ~= nil then tercio@0: validate = group.validate tercio@0: end tercio@0: end tercio@0: tercio@0: info.options = options tercio@0: info.appName = user.appName tercio@0: info.arg = option.arg tercio@0: info.handler = handler tercio@0: info.option = option tercio@0: info.type = option.type tercio@0: info.uiType = "dialog" tercio@0: info.uiName = MAJOR tercio@0: tercio@0: local name tercio@0: if type(option.name) == "function" then tercio@0: name = option.name(info) tercio@0: elseif type(option.name) == "string" then tercio@0: name = option.name tercio@0: else tercio@0: name = "" tercio@0: end tercio@0: local usage = option.usage tercio@0: local pattern = option.pattern tercio@0: tercio@0: local validated = true tercio@0: tercio@0: if option.type == "input" then tercio@0: if type(pattern)=="string" then tercio@0: if not strmatch(..., pattern) then tercio@0: validated = false tercio@0: end tercio@0: end tercio@0: end tercio@0: tercio@0: local success tercio@0: if validated and option.type ~= "execute" then tercio@0: if type(validate) == "string" then tercio@0: if handler and handler[validate] then tercio@0: success, validated = safecall(handler[validate], handler, info, ...) tercio@0: if not success then validated = false end tercio@0: else tercio@0: error(format("Method %s doesn't exist in handler for type execute", validate)) tercio@0: end tercio@0: elseif type(validate) == "function" then tercio@0: success, validated = safecall(validate, info, ...) tercio@0: if not success then validated = false end tercio@0: end tercio@0: end tercio@0: tercio@0: local rootframe = user.rootframe tercio@0: if type(validated) == "string" then tercio@0: --validate function returned a message to display tercio@0: if rootframe.SetStatusText then tercio@0: rootframe:SetStatusText(validated) tercio@0: else tercio@0: -- TODO: do something else. tercio@0: end tercio@0: PlaySound("igPlayerInviteDecline") tercio@0: del(info) tercio@0: return true tercio@0: elseif not validated then tercio@0: --validate returned false tercio@0: if rootframe.SetStatusText then tercio@0: if usage then tercio@0: rootframe:SetStatusText(name..": "..usage) tercio@0: else tercio@0: if pattern then tercio@0: rootframe:SetStatusText(name..": Expected "..pattern) tercio@0: else tercio@0: rootframe:SetStatusText(name..": Invalid Value") tercio@0: end tercio@0: end tercio@0: else tercio@0: -- TODO: do something else tercio@0: end tercio@0: PlaySound("igPlayerInviteDecline") tercio@0: del(info) tercio@0: return true tercio@0: else tercio@0: tercio@0: local confirmText = option.confirmText tercio@0: --call confirm func/method tercio@0: if type(confirm) == "string" then tercio@0: if handler and handler[confirm] then tercio@0: success, confirm = safecall(handler[confirm], handler, info, ...) tercio@0: if success and type(confirm) == "string" then tercio@0: confirmText = confirm tercio@0: confirm = true tercio@0: elseif not success then tercio@0: confirm = false tercio@0: end tercio@0: else tercio@0: error(format("Method %s doesn't exist in handler for type confirm", confirm)) tercio@0: end tercio@0: elseif type(confirm) == "function" then tercio@0: success, confirm = safecall(confirm, info, ...) tercio@0: if success and type(confirm) == "string" then tercio@0: confirmText = confirm tercio@0: confirm = true tercio@0: elseif not success then tercio@0: confirm = false tercio@0: end tercio@0: end tercio@0: tercio@0: --confirm if needed tercio@0: if type(confirm) == "boolean" then tercio@0: if confirm then tercio@0: if not confirmText then tercio@0: local name, desc = option.name, option.desc tercio@0: if type(name) == "function" then tercio@0: name = name(info) tercio@0: end tercio@0: if type(desc) == "function" then tercio@0: desc = desc(info) tercio@0: end tercio@0: confirmText = name tercio@0: if desc then tercio@0: confirmText = confirmText.." - "..desc tercio@0: end tercio@0: end tercio@0: tercio@0: local iscustom = user.rootframe:GetUserData("iscustom") tercio@0: local rootframe tercio@0: tercio@0: if iscustom then tercio@0: rootframe = user.rootframe tercio@0: end tercio@0: local basepath = user.rootframe:GetUserData("basepath") tercio@0: if type(func) == "string" then tercio@0: if handler and handler[func] then tercio@0: confirmPopup(user.appName, rootframe, basepath, info, confirmText, handler[func], handler, info, ...) tercio@0: else tercio@0: error(format("Method %s doesn't exist in handler for type func", func)) tercio@0: end tercio@0: elseif type(func) == "function" then tercio@0: confirmPopup(user.appName, rootframe, basepath, info, confirmText, func, info, ...) tercio@0: end tercio@0: --func will be called and info deleted when the confirm dialog is responded to tercio@0: return tercio@0: end tercio@0: end tercio@0: tercio@0: --call the function tercio@0: if type(func) == "string" then tercio@0: if handler and handler[func] then tercio@0: safecall(handler[func],handler, info, ...) tercio@0: else tercio@0: error(format("Method %s doesn't exist in handler for type func", func)) tercio@0: end tercio@0: elseif type(func) == "function" then tercio@0: safecall(func,info, ...) tercio@0: end tercio@0: tercio@0: tercio@0: tercio@0: local iscustom = user.rootframe:GetUserData("iscustom") tercio@0: local basepath = user.rootframe:GetUserData("basepath") or emptyTbl tercio@0: --full refresh of the frame, some controls dont cause this on all events tercio@0: if option.type == "color" then tercio@0: if event == "OnValueConfirmed" then tercio@0: tercio@0: if iscustom then tercio@0: AceConfigDialog:Open(user.appName, user.rootframe, unpack(basepath)) tercio@0: else tercio@0: AceConfigDialog:Open(user.appName, unpack(basepath)) tercio@0: end tercio@0: end tercio@0: elseif option.type == "range" then tercio@0: if event == "OnMouseUp" then tercio@0: if iscustom then tercio@0: AceConfigDialog:Open(user.appName, user.rootframe, unpack(basepath)) tercio@0: else tercio@0: AceConfigDialog:Open(user.appName, unpack(basepath)) tercio@0: end tercio@0: end tercio@0: --multiselects don't cause a refresh on 'OnValueChanged' only 'OnClosed' tercio@0: elseif option.type == "multiselect" then tercio@0: user.valuechanged = true tercio@0: else tercio@0: if iscustom then tercio@0: AceConfigDialog:Open(user.appName, user.rootframe, unpack(basepath)) tercio@0: else tercio@0: AceConfigDialog:Open(user.appName, unpack(basepath)) tercio@0: end tercio@0: end tercio@0: tercio@0: end tercio@0: del(info) tercio@0: end tercio@0: tercio@0: local function ActivateSlider(widget, event, value) tercio@0: local option = widget:GetUserData("option") tercio@0: local min, max, step = option.min or (not option.softMin and 0 or nil), option.max or (not option.softMax and 100 or nil), option.step tercio@0: if min then tercio@0: if step then tercio@0: value = math_floor((value - min) / step + 0.5) * step + min tercio@0: end tercio@0: value = math_max(value, min) tercio@0: end tercio@0: if max then tercio@0: value = math_min(value, max) tercio@0: end tercio@0: ActivateControl(widget,event,value) tercio@0: end tercio@0: tercio@0: --called from a checkbox that is part of an internally created multiselect group tercio@0: --this type is safe to refresh on activation of one control tercio@0: local function ActivateMultiControl(widget, event, ...) tercio@0: ActivateControl(widget, event, widget:GetUserData("value"), ...) tercio@0: local user = widget:GetUserDataTable() tercio@0: local iscustom = user.rootframe:GetUserData("iscustom") tercio@0: local basepath = user.rootframe:GetUserData("basepath") or emptyTbl tercio@0: if iscustom then tercio@0: AceConfigDialog:Open(user.appName, user.rootframe, unpack(basepath)) tercio@0: else tercio@0: AceConfigDialog:Open(user.appName, unpack(basepath)) tercio@0: end tercio@0: end tercio@0: tercio@0: local function MultiControlOnClosed(widget, event, ...) tercio@0: local user = widget:GetUserDataTable() tercio@0: if user.valuechanged then tercio@0: local iscustom = user.rootframe:GetUserData("iscustom") tercio@0: local basepath = user.rootframe:GetUserData("basepath") or emptyTbl tercio@0: if iscustom then tercio@0: AceConfigDialog:Open(user.appName, user.rootframe, unpack(basepath)) tercio@0: else tercio@0: AceConfigDialog:Open(user.appName, unpack(basepath)) tercio@0: end tercio@0: end tercio@0: end tercio@0: tercio@0: local function FrameOnClose(widget, event) tercio@0: local appName = widget:GetUserData("appName") tercio@0: AceConfigDialog.OpenFrames[appName] = nil tercio@0: gui:Release(widget) tercio@0: end tercio@0: tercio@0: local function CheckOptionHidden(option, options, path, appName) tercio@0: --check for a specific boolean option tercio@0: local hidden = pickfirstset(option.dialogHidden,option.guiHidden) tercio@0: if hidden ~= nil then tercio@0: return hidden tercio@0: end tercio@0: tercio@0: return GetOptionsMemberValue("hidden", option, options, path, appName) tercio@0: end tercio@0: tercio@0: local function CheckOptionDisabled(option, options, path, appName) tercio@0: --check for a specific boolean option tercio@0: local disabled = pickfirstset(option.dialogDisabled,option.guiDisabled) tercio@0: if disabled ~= nil then tercio@0: return disabled tercio@0: end tercio@0: tercio@0: return GetOptionsMemberValue("disabled", option, options, path, appName) tercio@0: end tercio@0: --[[ tercio@0: local function BuildTabs(group, options, path, appName) tercio@0: local tabs = new() tercio@0: local text = new() tercio@0: local keySort = new() tercio@0: local opts = new() tercio@0: tercio@0: BuildSortedOptionsTable(group, keySort, opts, options, path, appName) tercio@0: tercio@0: for i = 1, #keySort do tercio@0: local k = keySort[i] tercio@0: local v = opts[k] tercio@0: if v.type == "group" then tercio@0: path[#path+1] = k tercio@0: local inline = pickfirstset(v.dialogInline,v.guiInline,v.inline, false) tercio@0: local hidden = CheckOptionHidden(v, options, path, appName) tercio@0: if not inline and not hidden then tercio@0: tinsert(tabs, k) tercio@0: text[k] = GetOptionsMemberValue("name", v, options, path, appName) tercio@0: end tercio@0: path[#path] = nil tercio@0: end tercio@0: end tercio@0: tercio@0: del(keySort) tercio@0: del(opts) tercio@0: tercio@0: return tabs, text tercio@0: end tercio@0: ]] tercio@0: local function BuildSelect(group, options, path, appName) tercio@0: local groups = new() tercio@0: local order = new() tercio@0: local keySort = new() tercio@0: local opts = new() tercio@0: tercio@0: BuildSortedOptionsTable(group, keySort, opts, options, path, appName) tercio@0: tercio@0: for i = 1, #keySort do tercio@0: local k = keySort[i] tercio@0: local v = opts[k] tercio@0: if v.type == "group" then tercio@0: path[#path+1] = k tercio@0: local inline = pickfirstset(v.dialogInline,v.guiInline,v.inline, false) tercio@0: local hidden = CheckOptionHidden(v, options, path, appName) tercio@0: if not inline and not hidden then tercio@0: groups[k] = GetOptionsMemberValue("name", v, options, path, appName) tercio@0: tinsert(order, k) tercio@0: end tercio@0: path[#path] = nil tercio@0: end tercio@0: end tercio@0: tercio@0: del(opts) tercio@0: del(keySort) tercio@0: tercio@0: return groups, order tercio@0: end tercio@0: tercio@0: local function BuildSubGroups(group, tree, options, path, appName) tercio@0: local keySort = new() tercio@0: local opts = new() tercio@0: tercio@0: BuildSortedOptionsTable(group, keySort, opts, options, path, appName) tercio@0: tercio@0: for i = 1, #keySort do tercio@0: local k = keySort[i] tercio@0: local v = opts[k] tercio@0: if v.type == "group" then tercio@0: path[#path+1] = k tercio@0: local inline = pickfirstset(v.dialogInline,v.guiInline,v.inline, false) tercio@0: local hidden = CheckOptionHidden(v, options, path, appName) tercio@0: if not inline and not hidden then tercio@0: local entry = new() tercio@0: entry.value = k tercio@0: entry.text = GetOptionsMemberValue("name", v, options, path, appName) tercio@0: entry.icon = GetOptionsMemberValue("icon", v, options, path, appName) tercio@0: entry.iconCoords = GetOptionsMemberValue("iconCoords", v, options, path, appName) tercio@0: entry.disabled = CheckOptionDisabled(v, options, path, appName) tercio@0: if not tree.children then tree.children = new() end tercio@0: tinsert(tree.children,entry) tercio@0: if (v.childGroups or "tree") == "tree" then tercio@0: BuildSubGroups(v,entry, options, path, appName) tercio@0: end tercio@0: end tercio@0: path[#path] = nil tercio@0: end tercio@0: end tercio@0: tercio@0: del(keySort) tercio@0: del(opts) tercio@0: end tercio@0: tercio@0: local function BuildGroups(group, options, path, appName, recurse) tercio@0: local tree = new() tercio@0: local keySort = new() tercio@0: local opts = new() tercio@0: tercio@0: BuildSortedOptionsTable(group, keySort, opts, options, path, appName) tercio@0: tercio@0: for i = 1, #keySort do tercio@0: local k = keySort[i] tercio@0: local v = opts[k] tercio@0: if v.type == "group" then tercio@0: path[#path+1] = k tercio@0: local inline = pickfirstset(v.dialogInline,v.guiInline,v.inline, false) tercio@0: local hidden = CheckOptionHidden(v, options, path, appName) tercio@0: if not inline and not hidden then tercio@0: local entry = new() tercio@0: entry.value = k tercio@0: entry.text = GetOptionsMemberValue("name", v, options, path, appName) tercio@0: entry.icon = GetOptionsMemberValue("icon", v, options, path, appName) tercio@0: entry.disabled = CheckOptionDisabled(v, options, path, appName) tercio@0: tinsert(tree,entry) tercio@0: if recurse and (v.childGroups or "tree") == "tree" then tercio@0: BuildSubGroups(v,entry, options, path, appName) tercio@0: end tercio@0: end tercio@0: path[#path] = nil tercio@0: end tercio@0: end tercio@0: del(keySort) tercio@0: del(opts) tercio@0: return tree tercio@0: end tercio@0: tercio@0: local function InjectInfo(control, options, option, path, rootframe, appName) tercio@0: local user = control:GetUserDataTable() tercio@0: for i = 1, #path do tercio@0: user[i] = path[i] tercio@0: end tercio@0: user.rootframe = rootframe tercio@0: user.option = option tercio@0: user.options = options tercio@0: user.path = copy(path) tercio@0: user.appName = appName tercio@0: control:SetCallback("OnRelease", CleanUserData) tercio@0: control:SetCallback("OnLeave", OptionOnMouseLeave) tercio@0: control:SetCallback("OnEnter", OptionOnMouseOver) tercio@0: end tercio@0: tercio@0: tercio@0: --[[ tercio@0: options - root of the options table being fed tercio@0: container - widget that controls will be placed in tercio@0: rootframe - Frame object the options are in tercio@0: path - table with the keys to get to the group being fed tercio@0: --]] tercio@0: tercio@0: local function FeedOptions(appName, options,container,rootframe,path,group,inline) tercio@0: local keySort = new() tercio@0: local opts = new() tercio@0: tercio@0: BuildSortedOptionsTable(group, keySort, opts, options, path, appName) tercio@0: tercio@0: for i = 1, #keySort do tercio@0: local k = keySort[i] tercio@0: local v = opts[k] tercio@0: tinsert(path, k) tercio@0: local hidden = CheckOptionHidden(v, options, path, appName) tercio@0: local name = GetOptionsMemberValue("name", v, options, path, appName) tercio@0: if not hidden then tercio@0: if v.type == "group" then tercio@0: if inline or pickfirstset(v.dialogInline,v.guiInline,v.inline, false) then tercio@0: --Inline group tercio@0: local GroupContainer tercio@0: if name and name ~= "" then tercio@0: GroupContainer = gui:Create("InlineGroup") tercio@0: GroupContainer:SetTitle(name or "") tercio@0: else tercio@0: GroupContainer = gui:Create("SimpleGroup") tercio@0: end tercio@0: tercio@0: GroupContainer.width = "fill" tercio@0: GroupContainer:SetLayout("flow") tercio@0: container:AddChild(GroupContainer) tercio@0: FeedOptions(appName,options,GroupContainer,rootframe,path,v,true) tercio@0: end tercio@0: else tercio@0: --Control to feed tercio@0: local control tercio@0: tercio@0: local name = GetOptionsMemberValue("name", v, options, path, appName) tercio@0: tercio@0: if v.type == "execute" then tercio@0: tercio@0: local imageCoords = GetOptionsMemberValue("imageCoords",v, options, path, appName) tercio@0: local image, width, height = GetOptionsMemberValue("image",v, options, path, appName) tercio@0: tercio@0: if type(image) == "string" then tercio@0: control = gui:Create("Icon") tercio@0: if not width then tercio@0: width = GetOptionsMemberValue("imageWidth",v, options, path, appName) tercio@0: end tercio@0: if not height then tercio@0: height = GetOptionsMemberValue("imageHeight",v, options, path, appName) tercio@0: end tercio@0: if type(imageCoords) == "table" then tercio@0: control:SetImage(image, unpack(imageCoords)) tercio@0: else tercio@0: control:SetImage(image) tercio@0: end tercio@0: if type(width) ~= "number" then tercio@0: width = 32 tercio@0: end tercio@0: if type(height) ~= "number" then tercio@0: height = 32 tercio@0: end tercio@0: control:SetImageSize(width, height) tercio@0: control:SetLabel(name) tercio@0: else tercio@0: control = gui:Create("Button") tercio@0: control:SetText(name) tercio@0: end tercio@0: control:SetCallback("OnClick",ActivateControl) tercio@0: tercio@0: elseif v.type == "input" then tercio@0: local controlType = v.dialogControl or v.control or (v.multiline and "MultiLineEditBox") or "EditBox" tercio@0: control = gui:Create(controlType) tercio@0: if not control then tercio@0: geterrorhandler()(("Invalid Custom Control Type - %s"):format(tostring(controlType))) tercio@0: control = gui:Create(v.multiline and "MultiLineEditBox" or "EditBox") tercio@0: end tercio@0: tercio@0: if v.multiline and control.SetNumLines then tercio@0: control:SetNumLines(tonumber(v.multiline) or 4) tercio@0: end tercio@0: control:SetLabel(name) tercio@0: control:SetCallback("OnEnterPressed",ActivateControl) tercio@0: local text = GetOptionsMemberValue("get",v, options, path, appName) tercio@0: if type(text) ~= "string" then tercio@0: text = "" tercio@0: end tercio@0: control:SetText(text) tercio@0: tercio@0: elseif v.type == "toggle" then tercio@0: control = gui:Create("CheckBox") tercio@0: control:SetLabel(name) tercio@0: control:SetTriState(v.tristate) tercio@0: local value = GetOptionsMemberValue("get",v, options, path, appName) tercio@0: control:SetValue(value) tercio@0: control:SetCallback("OnValueChanged",ActivateControl) tercio@0: tercio@0: if v.descStyle == "inline" then tercio@0: local desc = GetOptionsMemberValue("desc", v, options, path, appName) tercio@0: control:SetDescription(desc) tercio@0: end tercio@0: tercio@0: local image = GetOptionsMemberValue("image", v, options, path, appName) tercio@0: local imageCoords = GetOptionsMemberValue("imageCoords", v, options, path, appName) tercio@0: tercio@0: if type(image) == "string" then tercio@0: if type(imageCoords) == "table" then tercio@0: control:SetImage(image, unpack(imageCoords)) tercio@0: else tercio@0: control:SetImage(image) tercio@0: end tercio@0: end tercio@0: elseif v.type == "range" then tercio@0: control = gui:Create("Slider") tercio@0: control:SetLabel(name) tercio@0: control:SetSliderValues(v.softMin or v.min or 0, v.softMax or v.max or 100, v.bigStep or v.step or 0) tercio@0: control:SetIsPercent(v.isPercent) tercio@0: local value = GetOptionsMemberValue("get",v, options, path, appName) tercio@0: if type(value) ~= "number" then tercio@0: value = 0 tercio@0: end tercio@0: control:SetValue(value) tercio@0: control:SetCallback("OnValueChanged",ActivateSlider) tercio@0: control:SetCallback("OnMouseUp",ActivateSlider) tercio@0: tercio@0: elseif v.type == "select" then tercio@0: local values = GetOptionsMemberValue("values", v, options, path, appName) tercio@0: if v.style == "radio" then tercio@0: local disabled = CheckOptionDisabled(v, options, path, appName) tercio@0: local width = GetOptionsMemberValue("width",v,options,path,appName) tercio@0: control = gui:Create("InlineGroup") tercio@0: control:SetLayout("Flow") tercio@0: control:SetTitle(name) tercio@0: control.width = "fill" tercio@0: tercio@0: control:PauseLayout() tercio@0: local optionValue = GetOptionsMemberValue("get",v, options, path, appName) tercio@0: local t = {} tercio@0: for value, text in pairs(values) do tercio@0: t[#t+1]=value tercio@0: end tercio@0: tsort(t) tercio@0: for k, value in ipairs(t) do tercio@0: local text = values[value] tercio@0: local radio = gui:Create("CheckBox") tercio@0: radio:SetLabel(text) tercio@0: radio:SetUserData("value", value) tercio@0: radio:SetUserData("text", text) tercio@0: radio:SetDisabled(disabled) tercio@0: radio:SetType("radio") tercio@0: radio:SetValue(optionValue == value) tercio@0: radio:SetCallback("OnValueChanged", ActivateMultiControl) tercio@0: InjectInfo(radio, options, v, path, rootframe, appName) tercio@0: control:AddChild(radio) tercio@0: if width == "double" then tercio@0: radio:SetWidth(width_multiplier * 2) tercio@0: elseif width == "half" then tercio@0: radio:SetWidth(width_multiplier / 2) tercio@0: elseif width == "full" then tercio@0: radio.width = "fill" tercio@0: else tercio@0: radio:SetWidth(width_multiplier) tercio@0: end tercio@0: end tercio@0: control:ResumeLayout() tercio@0: control:DoLayout() tercio@0: else tercio@0: local controlType = v.dialogControl or v.control or "Dropdown" tercio@0: control = gui:Create(controlType) tercio@0: if not control then tercio@0: geterrorhandler()(("Invalid Custom Control Type - %s"):format(tostring(controlType))) tercio@0: control = gui:Create("Dropdown") tercio@0: end tercio@0: local itemType = v.itemControl tercio@0: if itemType and not gui:GetWidgetVersion(itemType) then tercio@0: geterrorhandler()(("Invalid Custom Item Type - %s"):format(tostring(itemType))) tercio@0: itemType = nil tercio@0: end tercio@0: control:SetLabel(name) tercio@0: control:SetList(values, nil, itemType) tercio@0: local value = GetOptionsMemberValue("get",v, options, path, appName) tercio@0: if not values[value] then tercio@0: value = nil tercio@0: end tercio@0: control:SetValue(value) tercio@0: control:SetCallback("OnValueChanged", ActivateControl) tercio@0: end tercio@0: tercio@0: elseif v.type == "multiselect" then tercio@0: local values = GetOptionsMemberValue("values", v, options, path, appName) tercio@0: local disabled = CheckOptionDisabled(v, options, path, appName) tercio@0: tercio@0: local controlType = v.dialogControl or v.control tercio@0: tercio@0: local valuesort = new() tercio@0: if values then tercio@0: for value, text in pairs(values) do tercio@0: tinsert(valuesort, value) tercio@0: end tercio@0: end tercio@0: tsort(valuesort) tercio@0: tercio@0: if controlType then tercio@0: control = gui:Create(controlType) tercio@0: if not control then tercio@0: geterrorhandler()(("Invalid Custom Control Type - %s"):format(tostring(controlType))) tercio@0: end tercio@0: end tercio@0: if control then tercio@0: control:SetMultiselect(true) tercio@0: control:SetLabel(name) tercio@0: control:SetList(values) tercio@0: control:SetDisabled(disabled) tercio@0: control:SetCallback("OnValueChanged",ActivateControl) tercio@0: control:SetCallback("OnClosed", MultiControlOnClosed) tercio@0: local width = GetOptionsMemberValue("width",v,options,path,appName) tercio@0: if width == "double" then tercio@0: control:SetWidth(width_multiplier * 2) tercio@0: elseif width == "half" then tercio@0: control:SetWidth(width_multiplier / 2) tercio@0: elseif width == "full" then tercio@0: control.width = "fill" tercio@0: else tercio@0: control:SetWidth(width_multiplier) tercio@0: end tercio@0: --check:SetTriState(v.tristate) tercio@0: for i = 1, #valuesort do tercio@0: local key = valuesort[i] tercio@0: local value = GetOptionsMemberValue("get",v, options, path, appName, key) tercio@0: control:SetItemValue(key,value) tercio@0: end tercio@0: else tercio@0: control = gui:Create("InlineGroup") tercio@0: control:SetLayout("Flow") tercio@0: control:SetTitle(name) tercio@0: control.width = "fill" tercio@0: tercio@0: control:PauseLayout() tercio@0: local width = GetOptionsMemberValue("width",v,options,path,appName) tercio@0: for i = 1, #valuesort do tercio@0: local value = valuesort[i] tercio@0: local text = values[value] tercio@0: local check = gui:Create("CheckBox") tercio@0: check:SetLabel(text) tercio@0: check:SetUserData("value", value) tercio@0: check:SetUserData("text", text) tercio@0: check:SetDisabled(disabled) tercio@0: check:SetTriState(v.tristate) tercio@0: check:SetValue(GetOptionsMemberValue("get",v, options, path, appName, value)) tercio@0: check:SetCallback("OnValueChanged",ActivateMultiControl) tercio@0: InjectInfo(check, options, v, path, rootframe, appName) tercio@0: control:AddChild(check) tercio@0: if width == "double" then tercio@0: check:SetWidth(width_multiplier * 2) tercio@0: elseif width == "half" then tercio@0: check:SetWidth(width_multiplier / 2) tercio@0: elseif width == "full" then tercio@0: check.width = "fill" tercio@0: else tercio@0: check:SetWidth(width_multiplier) tercio@0: end tercio@0: end tercio@0: control:ResumeLayout() tercio@0: control:DoLayout() tercio@0: tercio@0: tercio@0: end tercio@0: tercio@0: del(valuesort) tercio@0: tercio@0: elseif v.type == "color" then tercio@0: control = gui:Create("ColorPicker") tercio@0: control:SetLabel(name) tercio@0: control:SetHasAlpha(GetOptionsMemberValue("hasAlpha",v, options, path, appName)) tercio@0: control:SetColor(GetOptionsMemberValue("get",v, options, path, appName)) tercio@0: control:SetCallback("OnValueChanged",ActivateControl) tercio@0: control:SetCallback("OnValueConfirmed",ActivateControl) tercio@0: tercio@0: elseif v.type == "keybinding" then tercio@0: control = gui:Create("Keybinding") tercio@0: control:SetLabel(name) tercio@0: control:SetKey(GetOptionsMemberValue("get",v, options, path, appName)) tercio@0: control:SetCallback("OnKeyChanged",ActivateControl) tercio@0: tercio@0: elseif v.type == "header" then tercio@0: control = gui:Create("Heading") tercio@0: control:SetText(name) tercio@0: control.width = "fill" tercio@0: tercio@0: elseif v.type == "description" then tercio@0: control = gui:Create("Label") tercio@0: control:SetText(name) tercio@0: tercio@0: local fontSize = GetOptionsMemberValue("fontSize",v, options, path, appName) tercio@0: if fontSize == "medium" then tercio@0: control:SetFontObject(GameFontHighlight) tercio@0: elseif fontSize == "large" then tercio@0: control:SetFontObject(GameFontHighlightLarge) tercio@0: else -- small or invalid tercio@0: control:SetFontObject(GameFontHighlightSmall) tercio@0: end tercio@0: tercio@0: local imageCoords = GetOptionsMemberValue("imageCoords",v, options, path, appName) tercio@0: local image, width, height = GetOptionsMemberValue("image",v, options, path, appName) tercio@0: tercio@0: if type(image) == "string" then tercio@0: if not width then tercio@0: width = GetOptionsMemberValue("imageWidth",v, options, path, appName) tercio@0: end tercio@0: if not height then tercio@0: height = GetOptionsMemberValue("imageHeight",v, options, path, appName) tercio@0: end tercio@0: if type(imageCoords) == "table" then tercio@0: control:SetImage(image, unpack(imageCoords)) tercio@0: else tercio@0: control:SetImage(image) tercio@0: end tercio@0: if type(width) ~= "number" then tercio@0: width = 32 tercio@0: end tercio@0: if type(height) ~= "number" then tercio@0: height = 32 tercio@0: end tercio@0: control:SetImageSize(width, height) tercio@0: end tercio@0: local width = GetOptionsMemberValue("width",v,options,path,appName) tercio@0: control.width = not width and "fill" tercio@0: end tercio@0: tercio@0: --Common Init tercio@0: if control then tercio@0: if control.width ~= "fill" then tercio@0: local width = GetOptionsMemberValue("width",v,options,path,appName) tercio@0: if width == "double" then tercio@0: control:SetWidth(width_multiplier * 2) tercio@0: elseif width == "half" then tercio@0: control:SetWidth(width_multiplier / 2) tercio@0: elseif width == "full" then tercio@0: control.width = "fill" tercio@0: else tercio@0: control:SetWidth(width_multiplier) tercio@0: end tercio@0: end tercio@0: if control.SetDisabled then tercio@0: local disabled = CheckOptionDisabled(v, options, path, appName) tercio@0: control:SetDisabled(disabled) tercio@0: end tercio@0: tercio@0: InjectInfo(control, options, v, path, rootframe, appName) tercio@0: container:AddChild(control) tercio@0: end tercio@0: tercio@0: end tercio@0: end tercio@0: tremove(path) tercio@0: end tercio@0: container:ResumeLayout() tercio@0: container:DoLayout() tercio@0: del(keySort) tercio@0: del(opts) tercio@0: end tercio@0: tercio@0: local function BuildPath(path, ...) tercio@0: for i = 1, select("#",...) do tercio@0: tinsert(path, (select(i,...))) tercio@0: end tercio@0: end tercio@0: tercio@0: tercio@0: local function TreeOnButtonEnter(widget, event, uniquevalue, button) tercio@0: local user = widget:GetUserDataTable() tercio@0: if not user then return end tercio@0: local options = user.options tercio@0: local option = user.option tercio@0: local path = user.path tercio@0: local appName = user.appName tercio@0: tercio@0: local feedpath = new() tercio@0: for i = 1, #path do tercio@0: feedpath[i] = path[i] tercio@0: end tercio@0: tercio@0: BuildPath(feedpath, ("\001"):split(uniquevalue)) tercio@0: local group = options tercio@0: for i = 1, #feedpath do tercio@0: if not group then return end tercio@0: group = GetSubOption(group, feedpath[i]) tercio@0: end tercio@0: tercio@0: local name = GetOptionsMemberValue("name", group, options, feedpath, appName) tercio@0: local desc = GetOptionsMemberValue("desc", group, options, feedpath, appName) tercio@0: tercio@0: GameTooltip:SetOwner(button, "ANCHOR_NONE") tercio@0: if widget.type == "TabGroup" then tercio@0: GameTooltip:SetPoint("BOTTOM",button,"TOP") tercio@0: else tercio@0: GameTooltip:SetPoint("LEFT",button,"RIGHT") tercio@0: end tercio@0: tercio@0: GameTooltip:SetText(name, 1, .82, 0, 1) tercio@0: tercio@0: if type(desc) == "string" then tercio@0: GameTooltip:AddLine(desc, 1, 1, 1, 1) tercio@0: end tercio@0: tercio@0: GameTooltip:Show() tercio@0: end tercio@0: tercio@0: local function TreeOnButtonLeave(widget, event, value, button) tercio@0: GameTooltip:Hide() tercio@0: end tercio@0: tercio@0: tercio@0: local function GroupExists(appName, options, path, uniquevalue) tercio@0: if not uniquevalue then return false end tercio@0: tercio@0: local feedpath = new() tercio@0: local temppath = new() tercio@0: for i = 1, #path do tercio@0: feedpath[i] = path[i] tercio@0: end tercio@0: tercio@0: BuildPath(feedpath, ("\001"):split(uniquevalue)) tercio@0: tercio@0: local group = options tercio@0: for i = 1, #feedpath do tercio@0: local v = feedpath[i] tercio@0: temppath[i] = v tercio@0: group = GetSubOption(group, v) tercio@0: tercio@0: if not group or group.type ~= "group" or CheckOptionHidden(group, options, temppath, appName) then tercio@0: del(feedpath) tercio@0: del(temppath) tercio@0: return false tercio@0: end tercio@0: end tercio@0: del(feedpath) tercio@0: del(temppath) tercio@0: return true tercio@0: end tercio@0: tercio@0: local function GroupSelected(widget, event, uniquevalue) tercio@0: tercio@0: local user = widget:GetUserDataTable() tercio@0: tercio@0: local options = user.options tercio@0: local option = user.option tercio@0: local path = user.path tercio@0: local rootframe = user.rootframe tercio@0: tercio@0: local feedpath = new() tercio@0: for i = 1, #path do tercio@0: feedpath[i] = path[i] tercio@0: end tercio@0: tercio@0: BuildPath(feedpath, ("\001"):split(uniquevalue)) tercio@0: local group = options tercio@0: for i = 1, #feedpath do tercio@0: group = GetSubOption(group, feedpath[i]) tercio@0: end tercio@0: widget:ReleaseChildren() tercio@0: AceConfigDialog:FeedGroup(user.appName,options,widget,rootframe,feedpath) tercio@0: tercio@0: del(feedpath) tercio@0: end tercio@0: tercio@0: tercio@0: tercio@0: --[[ tercio@0: -- INTERNAL -- tercio@0: This function will feed one group, and any inline child groups into the given container tercio@0: Select Groups will only have the selection control (tree, tabs, dropdown) fed in tercio@0: and have a group selected, this event will trigger the feeding of child groups tercio@0: tercio@0: Rules: tercio@0: If the group is Inline, FeedOptions tercio@0: If the group has no child groups, FeedOptions tercio@0: tercio@0: If the group is a tab or select group, FeedOptions then add the Group Control tercio@0: If the group is a tree group FeedOptions then tercio@0: its parent isnt a tree group: then add the tree control containing this and all child tree groups tercio@0: if its parent is a tree group, its already a node on a tree tercio@0: --]] tercio@0: tercio@0: function AceConfigDialog:FeedGroup(appName,options,container,rootframe,path, isRoot) tercio@0: local group = options tercio@0: --follow the path to get to the curent group tercio@0: local inline tercio@0: local grouptype, parenttype = options.childGroups, "none" tercio@0: tercio@0: tercio@0: for i = 1, #path do tercio@0: local v = path[i] tercio@0: group = GetSubOption(group, v) tercio@0: inline = inline or pickfirstset(v.dialogInline,v.guiInline,v.inline, false) tercio@0: parenttype = grouptype tercio@0: grouptype = group.childGroups tercio@0: end tercio@0: tercio@0: if not parenttype then tercio@0: parenttype = "tree" tercio@0: end tercio@0: tercio@0: --check if the group has child groups tercio@0: local hasChildGroups tercio@0: for k, v in pairs(group.args) do tercio@0: if v.type == "group" and not pickfirstset(v.dialogInline,v.guiInline,v.inline, false) and not CheckOptionHidden(v, options, path, appName) then tercio@0: hasChildGroups = true tercio@0: end tercio@0: end tercio@0: if group.plugins then tercio@0: for plugin, t in pairs(group.plugins) do tercio@0: for k, v in pairs(t) do tercio@0: if v.type == "group" and not pickfirstset(v.dialogInline,v.guiInline,v.inline, false) and not CheckOptionHidden(v, options, path, appName) then tercio@0: hasChildGroups = true tercio@0: end tercio@0: end tercio@0: end tercio@0: end tercio@0: tercio@0: container:SetLayout("flow") tercio@0: local scroll tercio@0: tercio@0: --Add a scrollframe if we are not going to add a group control, this is the inverse of the conditions for that later on tercio@0: if (not (hasChildGroups and not inline)) or (grouptype ~= "tab" and grouptype ~= "select" and (parenttype == "tree" and not isRoot)) then tercio@0: if container.type ~= "InlineGroup" and container.type ~= "SimpleGroup" then tercio@0: scroll = gui:Create("ScrollFrame") tercio@0: scroll:SetLayout("flow") tercio@0: scroll.width = "fill" tercio@0: scroll.height = "fill" tercio@0: container:SetLayout("fill") tercio@0: container:AddChild(scroll) tercio@0: container = scroll tercio@0: end tercio@0: end tercio@0: tercio@0: FeedOptions(appName,options,container,rootframe,path,group,nil) tercio@0: tercio@0: if scroll then tercio@0: container:PerformLayout() tercio@0: local status = self:GetStatusTable(appName, path) tercio@0: if not status.scroll then tercio@0: status.scroll = {} tercio@0: end tercio@0: scroll:SetStatusTable(status.scroll) tercio@0: end tercio@0: tercio@0: if hasChildGroups and not inline then tercio@0: local name = GetOptionsMemberValue("name", group, options, path, appName) tercio@0: if grouptype == "tab" then tercio@0: tercio@0: local tab = gui:Create("TabGroup") tercio@0: InjectInfo(tab, options, group, path, rootframe, appName) tercio@0: tab:SetCallback("OnGroupSelected", GroupSelected) tercio@0: tab:SetCallback("OnTabEnter", TreeOnButtonEnter) tercio@0: tab:SetCallback("OnTabLeave", TreeOnButtonLeave) tercio@0: tercio@0: local status = AceConfigDialog:GetStatusTable(appName, path) tercio@0: if not status.groups then tercio@0: status.groups = {} tercio@0: end tercio@0: tab:SetStatusTable(status.groups) tercio@0: tab.width = "fill" tercio@0: tab.height = "fill" tercio@0: tercio@0: local tabs = BuildGroups(group, options, path, appName) tercio@0: tab:SetTabs(tabs) tercio@0: tab:SetUserData("tablist", tabs) tercio@0: tercio@0: for i = 1, #tabs do tercio@0: local entry = tabs[i] tercio@0: if not entry.disabled then tercio@0: tab:SelectTab((GroupExists(appName, options, path,status.groups.selected) and status.groups.selected) or entry.value) tercio@0: break tercio@0: end tercio@0: end tercio@0: tercio@0: container:AddChild(tab) tercio@0: tercio@0: elseif grouptype == "select" then tercio@0: tercio@0: local select = gui:Create("DropdownGroup") tercio@0: select:SetTitle(name) tercio@0: InjectInfo(select, options, group, path, rootframe, appName) tercio@0: select:SetCallback("OnGroupSelected", GroupSelected) tercio@0: local status = AceConfigDialog:GetStatusTable(appName, path) tercio@0: if not status.groups then tercio@0: status.groups = {} tercio@0: end tercio@0: select:SetStatusTable(status.groups) tercio@0: local grouplist, orderlist = BuildSelect(group, options, path, appName) tercio@0: select:SetGroupList(grouplist, orderlist) tercio@0: select:SetUserData("grouplist", grouplist) tercio@0: select:SetUserData("orderlist", orderlist) tercio@0: tercio@0: local firstgroup = orderlist[1] tercio@0: if firstgroup then tercio@0: select:SetGroup((GroupExists(appName, options, path,status.groups.selected) and status.groups.selected) or firstgroup) tercio@0: end tercio@0: tercio@0: select.width = "fill" tercio@0: select.height = "fill" tercio@0: tercio@0: container:AddChild(select) tercio@0: tercio@0: --assume tree group by default tercio@0: --if parenttype is tree then this group is already a node on that tree tercio@0: elseif (parenttype ~= "tree") or isRoot then tercio@0: local tree = gui:Create("TreeGroup") tercio@0: InjectInfo(tree, options, group, path, rootframe, appName) tercio@0: tree:EnableButtonTooltips(false) tercio@0: tercio@0: tree.width = "fill" tercio@0: tree.height = "fill" tercio@0: tercio@0: tree:SetCallback("OnGroupSelected", GroupSelected) tercio@0: tree:SetCallback("OnButtonEnter", TreeOnButtonEnter) tercio@0: tree:SetCallback("OnButtonLeave", TreeOnButtonLeave) tercio@0: tercio@0: local status = AceConfigDialog:GetStatusTable(appName, path) tercio@0: if not status.groups then tercio@0: status.groups = {} tercio@0: end tercio@0: local treedefinition = BuildGroups(group, options, path, appName, true) tercio@0: tree:SetStatusTable(status.groups) tercio@0: tercio@0: tree:SetTree(treedefinition) tercio@0: tree:SetUserData("tree",treedefinition) tercio@0: tercio@0: for i = 1, #treedefinition do tercio@0: local entry = treedefinition[i] tercio@0: if not entry.disabled then tercio@0: tree:SelectByValue((GroupExists(appName, options, path,status.groups.selected) and status.groups.selected) or entry.value) tercio@0: break tercio@0: end tercio@0: end tercio@0: tercio@0: container:AddChild(tree) tercio@0: end tercio@0: end tercio@0: end tercio@0: tercio@0: local old_CloseSpecialWindows tercio@0: tercio@0: tercio@0: local function RefreshOnUpdate(this) tercio@0: for appName in pairs(this.closing) do tercio@0: if AceConfigDialog.OpenFrames[appName] then tercio@0: AceConfigDialog.OpenFrames[appName]:Hide() tercio@0: end tercio@0: if AceConfigDialog.BlizOptions and AceConfigDialog.BlizOptions[appName] then tercio@0: for key, widget in pairs(AceConfigDialog.BlizOptions[appName]) do tercio@0: if not widget:IsVisible() then tercio@0: widget:ReleaseChildren() tercio@0: end tercio@0: end tercio@0: end tercio@0: this.closing[appName] = nil tercio@0: end tercio@0: tercio@0: if this.closeAll then tercio@0: for k, v in pairs(AceConfigDialog.OpenFrames) do tercio@0: if not this.closeAllOverride[k] then tercio@0: v:Hide() tercio@0: end tercio@0: end tercio@0: this.closeAll = nil tercio@0: wipe(this.closeAllOverride) tercio@0: end tercio@0: tercio@0: for appName in pairs(this.apps) do tercio@0: if AceConfigDialog.OpenFrames[appName] then tercio@0: local user = AceConfigDialog.OpenFrames[appName]:GetUserDataTable() tercio@0: AceConfigDialog:Open(appName, unpack(user.basepath or emptyTbl)) tercio@0: end tercio@0: if AceConfigDialog.BlizOptions and AceConfigDialog.BlizOptions[appName] then tercio@0: for key, widget in pairs(AceConfigDialog.BlizOptions[appName]) do tercio@0: local user = widget:GetUserDataTable() tercio@0: if widget:IsVisible() then tercio@0: AceConfigDialog:Open(widget:GetUserData("appName"), widget, unpack(user.basepath or emptyTbl)) tercio@0: end tercio@0: end tercio@0: end tercio@0: this.apps[appName] = nil tercio@0: end tercio@0: this:SetScript("OnUpdate", nil) tercio@0: end tercio@0: tercio@0: -- Upgrade the OnUpdate script as well, if needed. tercio@0: if AceConfigDialog.frame:GetScript("OnUpdate") then tercio@0: AceConfigDialog.frame:SetScript("OnUpdate", RefreshOnUpdate) tercio@0: end tercio@0: tercio@0: --- Close all open options windows tercio@0: function AceConfigDialog:CloseAll() tercio@0: AceConfigDialog.frame.closeAll = true tercio@0: AceConfigDialog.frame:SetScript("OnUpdate", RefreshOnUpdate) tercio@0: if next(self.OpenFrames) then tercio@0: return true tercio@0: end tercio@0: end tercio@0: tercio@0: --- Close a specific options window. tercio@0: -- @param appName The application name as given to `:RegisterOptionsTable()` tercio@0: function AceConfigDialog:Close(appName) tercio@0: if self.OpenFrames[appName] then tercio@0: AceConfigDialog.frame.closing[appName] = true tercio@0: AceConfigDialog.frame:SetScript("OnUpdate", RefreshOnUpdate) tercio@0: return true tercio@0: end tercio@0: end tercio@0: tercio@0: -- Internal -- Called by AceConfigRegistry tercio@0: function AceConfigDialog:ConfigTableChanged(event, appName) tercio@0: AceConfigDialog.frame.apps[appName] = true tercio@0: AceConfigDialog.frame:SetScript("OnUpdate", RefreshOnUpdate) tercio@0: end tercio@0: tercio@0: reg.RegisterCallback(AceConfigDialog, "ConfigTableChange", "ConfigTableChanged") tercio@0: tercio@0: --- Sets the default size of the options window for a specific application. tercio@0: -- @param appName The application name as given to `:RegisterOptionsTable()` tercio@0: -- @param width The default width tercio@0: -- @param height The default height tercio@0: function AceConfigDialog:SetDefaultSize(appName, width, height) tercio@0: local status = AceConfigDialog:GetStatusTable(appName) tercio@0: if type(width) == "number" and type(height) == "number" then tercio@0: status.width = width tercio@0: status.height = height tercio@0: end tercio@0: end tercio@0: tercio@0: --- Open an option window at the specified path (if any). tercio@0: -- This function can optionally feed the group into a pre-created container tercio@0: -- instead of creating a new container frame. tercio@0: -- @paramsig appName [, container][, ...] tercio@0: -- @param appName The application name as given to `:RegisterOptionsTable()` tercio@0: -- @param container An optional container frame to feed the options into tercio@0: -- @param ... The path to open after creating the options window (see `:SelectGroup` for details) tercio@0: function AceConfigDialog:Open(appName, container, ...) tercio@0: if not old_CloseSpecialWindows then tercio@0: old_CloseSpecialWindows = CloseSpecialWindows tercio@0: CloseSpecialWindows = function() tercio@0: local found = old_CloseSpecialWindows() tercio@0: return self:CloseAll() or found tercio@0: end tercio@0: end tercio@0: local app = reg:GetOptionsTable(appName) tercio@0: if not app then tercio@0: error(("%s isn't registed with AceConfigRegistry, unable to open config"):format(appName), 2) tercio@0: end tercio@0: local options = app("dialog", MAJOR) tercio@0: tercio@0: local f tercio@0: tercio@0: local path = new() tercio@0: local name = GetOptionsMemberValue("name", options, options, path, appName) tercio@0: tercio@0: --If an optional path is specified add it to the path table before feeding the options tercio@0: --as container is optional as well it may contain the first element of the path tercio@0: if type(container) == "string" then tercio@0: tinsert(path, container) tercio@0: container = nil tercio@0: end tercio@0: for n = 1, select("#",...) do tercio@0: tinsert(path, (select(n, ...))) tercio@0: end tercio@0: tercio@0: --if a container is given feed into that tercio@0: if container then tercio@0: f = container tercio@0: f:ReleaseChildren() tercio@0: f:SetUserData("appName", appName) tercio@0: f:SetUserData("iscustom", true) tercio@0: if #path > 0 then tercio@0: f:SetUserData("basepath", copy(path)) tercio@0: end tercio@0: local status = AceConfigDialog:GetStatusTable(appName) tercio@0: if not status.width then tercio@0: status.width = 700 tercio@0: end tercio@0: if not status.height then tercio@0: status.height = 500 tercio@0: end tercio@0: if f.SetStatusTable then tercio@0: f:SetStatusTable(status) tercio@0: end tercio@0: if f.SetTitle then tercio@0: f:SetTitle(name or "") tercio@0: end tercio@0: else tercio@0: if not self.OpenFrames[appName] then tercio@0: f = gui:Create("Frame") tercio@0: self.OpenFrames[appName] = f tercio@0: else tercio@0: f = self.OpenFrames[appName] tercio@0: end tercio@0: f:ReleaseChildren() tercio@0: f:SetCallback("OnClose", FrameOnClose) tercio@0: f:SetUserData("appName", appName) tercio@0: if #path > 0 then tercio@0: f:SetUserData("basepath", copy(path)) tercio@0: end tercio@0: f:SetTitle(name or "") tercio@0: local status = AceConfigDialog:GetStatusTable(appName) tercio@0: f:SetStatusTable(status) tercio@0: end tercio@0: tercio@0: self:FeedGroup(appName,options,f,f,path,true) tercio@0: if f.Show then tercio@0: f:Show() tercio@0: end tercio@0: del(path) tercio@0: tercio@0: if AceConfigDialog.frame.closeAll then tercio@0: -- close all is set, but thats not good, since we're just opening here, so force it tercio@0: AceConfigDialog.frame.closeAllOverride[appName] = true tercio@0: end tercio@0: end tercio@0: tercio@0: -- convert pre-39 BlizOptions structure to the new format tercio@0: if oldminor and oldminor < 39 and AceConfigDialog.BlizOptions then tercio@0: local old = AceConfigDialog.BlizOptions tercio@0: local new = {} tercio@0: for key, widget in pairs(old) do tercio@0: local appName = widget:GetUserData("appName") tercio@0: if not new[appName] then new[appName] = {} end tercio@0: new[appName][key] = widget tercio@0: end tercio@0: AceConfigDialog.BlizOptions = new tercio@0: else tercio@0: AceConfigDialog.BlizOptions = AceConfigDialog.BlizOptions or {} tercio@0: end tercio@0: tercio@0: local function FeedToBlizPanel(widget, event) tercio@0: local path = widget:GetUserData("path") tercio@0: AceConfigDialog:Open(widget:GetUserData("appName"), widget, unpack(path or emptyTbl)) tercio@0: end tercio@0: tercio@0: local function ClearBlizPanel(widget, event) tercio@0: local appName = widget:GetUserData("appName") tercio@0: AceConfigDialog.frame.closing[appName] = true tercio@0: AceConfigDialog.frame:SetScript("OnUpdate", RefreshOnUpdate) tercio@0: end tercio@0: tercio@0: --- Add an option table into the Blizzard Interface Options panel. tercio@0: -- You can optionally supply a descriptive name to use and a parent frame to use, tercio@0: -- as well as a path in the options table.\\ tercio@0: -- If no name is specified, the appName will be used instead. tercio@0: -- tercio@0: -- If you specify a proper `parent` (by name), the interface options will generate a tercio@0: -- tree layout. Note that only one level of children is supported, so the parent always tercio@0: -- has to be a head-level note. tercio@0: -- tercio@0: -- This function returns a reference to the container frame registered with the Interface tercio@0: -- Options. You can use this reference to open the options with the API function tercio@0: -- `InterfaceOptionsFrame_OpenToCategory`. tercio@0: -- @param appName The application name as given to `:RegisterOptionsTable()` tercio@0: -- @param name A descriptive name to display in the options tree (defaults to appName) tercio@0: -- @param parent The parent to use in the interface options tree. tercio@0: -- @param ... The path in the options table to feed into the interface options panel. tercio@0: -- @return The reference to the frame registered into the Interface Options. tercio@0: function AceConfigDialog:AddToBlizOptions(appName, name, parent, ...) tercio@0: local BlizOptions = AceConfigDialog.BlizOptions tercio@0: tercio@0: local key = appName tercio@0: for n = 1, select("#", ...) do tercio@0: key = key.."\001"..select(n, ...) tercio@0: end tercio@0: tercio@0: if not BlizOptions[appName] then tercio@0: BlizOptions[appName] = {} tercio@0: end tercio@0: tercio@0: if not BlizOptions[appName][key] then tercio@0: local group = gui:Create("BlizOptionsGroup") tercio@0: BlizOptions[appName][key] = group tercio@0: group:SetName(name or appName, parent) tercio@0: tercio@0: group:SetTitle(name or appName) tercio@0: group:SetUserData("appName", appName) tercio@0: if select("#", ...) > 0 then tercio@0: local path = {} tercio@0: for n = 1, select("#",...) do tercio@0: tinsert(path, (select(n, ...))) tercio@0: end tercio@0: group:SetUserData("path", path) tercio@0: end tercio@0: group:SetCallback("OnShow", FeedToBlizPanel) tercio@0: group:SetCallback("OnHide", ClearBlizPanel) tercio@0: InterfaceOptions_AddCategory(group.frame) tercio@0: return group.frame tercio@0: else tercio@0: error(("%s has already been added to the Blizzard Options Window with the given path"):format(appName), 2) tercio@0: end tercio@0: end