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