annotate Libs/AceConfig-3.0/AceConfigDialog-3.0/AceConfigDialog-3.0.lua @ 0:fc346da3afd9

First commit Hot Corners standalone.
author tercio
date Fri, 08 Aug 2014 12:35:17 -0300
parents
children c31ee4251181
rev   line source
tercio@0 1 --- AceConfigDialog-3.0 generates AceGUI-3.0 based windows based on option tables.
tercio@0 2 -- @class file
tercio@0 3 -- @name AceConfigDialog-3.0
tercio@0 4 -- @release $Id: AceConfigDialog-3.0.lua 1089 2013-09-13 14:32:35Z nevcairiel $
tercio@0 5
tercio@0 6 local LibStub = LibStub
tercio@0 7 local MAJOR, MINOR = "AceConfigDialog-3.0", 58
tercio@0 8 local AceConfigDialog, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
tercio@0 9
tercio@0 10 if not AceConfigDialog then return end
tercio@0 11
tercio@0 12 AceConfigDialog.OpenFrames = AceConfigDialog.OpenFrames or {}
tercio@0 13 AceConfigDialog.Status = AceConfigDialog.Status or {}
tercio@0 14 AceConfigDialog.frame = AceConfigDialog.frame or CreateFrame("Frame")
tercio@0 15
tercio@0 16 AceConfigDialog.frame.apps = AceConfigDialog.frame.apps or {}
tercio@0 17 AceConfigDialog.frame.closing = AceConfigDialog.frame.closing or {}
tercio@0 18 AceConfigDialog.frame.closeAllOverride = AceConfigDialog.frame.closeAllOverride or {}
tercio@0 19
tercio@0 20 local gui = LibStub("AceGUI-3.0")
tercio@0 21 local reg = LibStub("AceConfigRegistry-3.0")
tercio@0 22
tercio@0 23 -- Lua APIs
tercio@0 24 local tconcat, tinsert, tsort, tremove, tsort = table.concat, table.insert, table.sort, table.remove, table.sort
tercio@0 25 local strmatch, format = string.match, string.format
tercio@0 26 local assert, loadstring, error = assert, loadstring, error
tercio@0 27 local pairs, next, select, type, unpack, wipe, ipairs = pairs, next, select, type, unpack, wipe, ipairs
tercio@0 28 local rawset, tostring, tonumber = rawset, tostring, tonumber
tercio@0 29 local math_min, math_max, math_floor = math.min, math.max, math.floor
tercio@0 30
tercio@0 31 -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
tercio@0 32 -- List them here for Mikk's FindGlobals script
tercio@0 33 -- GLOBALS: NORMAL_FONT_COLOR, GameTooltip, StaticPopupDialogs, ACCEPT, CANCEL, StaticPopup_Show
tercio@0 34 -- GLOBALS: PlaySound, GameFontHighlight, GameFontHighlightSmall, GameFontHighlightLarge
tercio@0 35 -- GLOBALS: CloseSpecialWindows, InterfaceOptions_AddCategory, geterrorhandler
tercio@0 36
tercio@0 37 local emptyTbl = {}
tercio@0 38
tercio@0 39 --[[
tercio@0 40 xpcall safecall implementation
tercio@0 41 ]]
tercio@0 42 local xpcall = xpcall
tercio@0 43
tercio@0 44 local function errorhandler(err)
tercio@0 45 return geterrorhandler()(err)
tercio@0 46 end
tercio@0 47
tercio@0 48 local function CreateDispatcher(argCount)
tercio@0 49 local code = [[
tercio@0 50 local xpcall, eh = ...
tercio@0 51 local method, ARGS
tercio@0 52 local function call() return method(ARGS) end
tercio@0 53
tercio@0 54 local function dispatch(func, ...)
tercio@0 55 method = func
tercio@0 56 if not method then return end
tercio@0 57 ARGS = ...
tercio@0 58 return xpcall(call, eh)
tercio@0 59 end
tercio@0 60
tercio@0 61 return dispatch
tercio@0 62 ]]
tercio@0 63
tercio@0 64 local ARGS = {}
tercio@0 65 for i = 1, argCount do ARGS[i] = "arg"..i end
tercio@0 66 code = code:gsub("ARGS", tconcat(ARGS, ", "))
tercio@0 67 return assert(loadstring(code, "safecall Dispatcher["..argCount.."]"))(xpcall, errorhandler)
tercio@0 68 end
tercio@0 69
tercio@0 70 local Dispatchers = setmetatable({}, {__index=function(self, argCount)
tercio@0 71 local dispatcher = CreateDispatcher(argCount)
tercio@0 72 rawset(self, argCount, dispatcher)
tercio@0 73 return dispatcher
tercio@0 74 end})
tercio@0 75 Dispatchers[0] = function(func)
tercio@0 76 return xpcall(func, errorhandler)
tercio@0 77 end
tercio@0 78
tercio@0 79 local function safecall(func, ...)
tercio@0 80 return Dispatchers[select("#", ...)](func, ...)
tercio@0 81 end
tercio@0 82
tercio@0 83 local width_multiplier = 170
tercio@0 84
tercio@0 85 --[[
tercio@0 86 Group Types
tercio@0 87 Tree - All Descendant Groups will all become nodes on the tree, direct child options will appear above the tree
tercio@0 88 - Descendant Groups with inline=true and thier children will not become nodes
tercio@0 89
tercio@0 90 Tab - Direct Child Groups will become tabs, direct child options will appear above the tab control
tercio@0 91 - Grandchild groups will default to inline unless specified otherwise
tercio@0 92
tercio@0 93 Select- Same as Tab but with entries in a dropdown rather than tabs
tercio@0 94
tercio@0 95
tercio@0 96 Inline Groups
tercio@0 97 - Will not become nodes of a select group, they will be effectivly part of thier parent group seperated by a border
tercio@0 98 - If declared on a direct child of a root node of a select group, they will appear above the group container control
tercio@0 99 - When a group is displayed inline, all descendants will also be inline members of the group
tercio@0 100
tercio@0 101 ]]
tercio@0 102
tercio@0 103 -- Recycling functions
tercio@0 104 local new, del, copy
tercio@0 105 --newcount, delcount,createdcount,cached = 0,0,0
tercio@0 106 do
tercio@0 107 local pool = setmetatable({},{__mode="k"})
tercio@0 108 function new()
tercio@0 109 --newcount = newcount + 1
tercio@0 110 local t = next(pool)
tercio@0 111 if t then
tercio@0 112 pool[t] = nil
tercio@0 113 return t
tercio@0 114 else
tercio@0 115 --createdcount = createdcount + 1
tercio@0 116 return {}
tercio@0 117 end
tercio@0 118 end
tercio@0 119 function copy(t)
tercio@0 120 local c = new()
tercio@0 121 for k, v in pairs(t) do
tercio@0 122 c[k] = v
tercio@0 123 end
tercio@0 124 return c
tercio@0 125 end
tercio@0 126 function del(t)
tercio@0 127 --delcount = delcount + 1
tercio@0 128 wipe(t)
tercio@0 129 pool[t] = true
tercio@0 130 end
tercio@0 131 -- function cached()
tercio@0 132 -- local n = 0
tercio@0 133 -- for k in pairs(pool) do
tercio@0 134 -- n = n + 1
tercio@0 135 -- end
tercio@0 136 -- return n
tercio@0 137 -- end
tercio@0 138 end
tercio@0 139
tercio@0 140 -- picks the first non-nil value and returns it
tercio@0 141 local function pickfirstset(...)
tercio@0 142 for i=1,select("#",...) do
tercio@0 143 if select(i,...)~=nil then
tercio@0 144 return select(i,...)
tercio@0 145 end
tercio@0 146 end
tercio@0 147 end
tercio@0 148
tercio@0 149 --gets an option from a given group, checking plugins
tercio@0 150 local function GetSubOption(group, key)
tercio@0 151 if group.plugins then
tercio@0 152 for plugin, t in pairs(group.plugins) do
tercio@0 153 if t[key] then
tercio@0 154 return t[key]
tercio@0 155 end
tercio@0 156 end
tercio@0 157 end
tercio@0 158
tercio@0 159 return group.args[key]
tercio@0 160 end
tercio@0 161
tercio@0 162 --Option member type definitions, used to decide how to access it
tercio@0 163
tercio@0 164 --Is the member Inherited from parent options
tercio@0 165 local isInherited = {
tercio@0 166 set = true,
tercio@0 167 get = true,
tercio@0 168 func = true,
tercio@0 169 confirm = true,
tercio@0 170 validate = true,
tercio@0 171 disabled = true,
tercio@0 172 hidden = true
tercio@0 173 }
tercio@0 174
tercio@0 175 --Does a string type mean a literal value, instead of the default of a method of the handler
tercio@0 176 local stringIsLiteral = {
tercio@0 177 name = true,
tercio@0 178 desc = true,
tercio@0 179 icon = true,
tercio@0 180 usage = true,
tercio@0 181 width = true,
tercio@0 182 image = true,
tercio@0 183 fontSize = true,
tercio@0 184 }
tercio@0 185
tercio@0 186 --Is Never a function or method
tercio@0 187 local allIsLiteral = {
tercio@0 188 type = true,
tercio@0 189 descStyle = true,
tercio@0 190 imageWidth = true,
tercio@0 191 imageHeight = true,
tercio@0 192 }
tercio@0 193
tercio@0 194 --gets the value for a member that could be a function
tercio@0 195 --function refs are called with an info arg
tercio@0 196 --every other type is returned
tercio@0 197 local function GetOptionsMemberValue(membername, option, options, path, appName, ...)
tercio@0 198 --get definition for the member
tercio@0 199 local inherits = isInherited[membername]
tercio@0 200
tercio@0 201
tercio@0 202 --get the member of the option, traversing the tree if it can be inherited
tercio@0 203 local member
tercio@0 204
tercio@0 205 if inherits then
tercio@0 206 local group = options
tercio@0 207 if group[membername] ~= nil then
tercio@0 208 member = group[membername]
tercio@0 209 end
tercio@0 210 for i = 1, #path do
tercio@0 211 group = GetSubOption(group, path[i])
tercio@0 212 if group[membername] ~= nil then
tercio@0 213 member = group[membername]
tercio@0 214 end
tercio@0 215 end
tercio@0 216 else
tercio@0 217 member = option[membername]
tercio@0 218 end
tercio@0 219
tercio@0 220 --check if we need to call a functon, or if we have a literal value
tercio@0 221 if ( not allIsLiteral[membername] ) and ( type(member) == "function" or ((not stringIsLiteral[membername]) and type(member) == "string") ) then
tercio@0 222 --We have a function to call
tercio@0 223 local info = new()
tercio@0 224 --traverse the options table, picking up the handler and filling the info with the path
tercio@0 225 local handler
tercio@0 226 local group = options
tercio@0 227 handler = group.handler or handler
tercio@0 228
tercio@0 229 for i = 1, #path do
tercio@0 230 group = GetSubOption(group, path[i])
tercio@0 231 info[i] = path[i]
tercio@0 232 handler = group.handler or handler
tercio@0 233 end
tercio@0 234
tercio@0 235 info.options = options
tercio@0 236 info.appName = appName
tercio@0 237 info[0] = appName
tercio@0 238 info.arg = option.arg
tercio@0 239 info.handler = handler
tercio@0 240 info.option = option
tercio@0 241 info.type = option.type
tercio@0 242 info.uiType = "dialog"
tercio@0 243 info.uiName = MAJOR
tercio@0 244
tercio@0 245 local a, b, c ,d
tercio@0 246 --using 4 returns for the get of a color type, increase if a type needs more
tercio@0 247 if type(member) == "function" then
tercio@0 248 --Call the function
tercio@0 249 a,b,c,d = member(info, ...)
tercio@0 250 else
tercio@0 251 --Call the method
tercio@0 252 if handler and handler[member] then
tercio@0 253 a,b,c,d = handler[member](handler, info, ...)
tercio@0 254 else
tercio@0 255 error(format("Method %s doesn't exist in handler for type %s", member, membername))
tercio@0 256 end
tercio@0 257 end
tercio@0 258 del(info)
tercio@0 259 return a,b,c,d
tercio@0 260 else
tercio@0 261 --The value isnt a function to call, return it
tercio@0 262 return member
tercio@0 263 end
tercio@0 264 end
tercio@0 265
tercio@0 266 --[[calls an options function that could be inherited, method name or function ref
tercio@0 267 local function CallOptionsFunction(funcname ,option, options, path, appName, ...)
tercio@0 268 local info = new()
tercio@0 269
tercio@0 270 local func
tercio@0 271 local group = options
tercio@0 272 local handler
tercio@0 273
tercio@0 274 --build the info table containing the path
tercio@0 275 -- pick up functions while traversing the tree
tercio@0 276 if group[funcname] ~= nil then
tercio@0 277 func = group[funcname]
tercio@0 278 end
tercio@0 279 handler = group.handler or handler
tercio@0 280
tercio@0 281 for i, v in ipairs(path) do
tercio@0 282 group = GetSubOption(group, v)
tercio@0 283 info[i] = v
tercio@0 284 if group[funcname] ~= nil then
tercio@0 285 func = group[funcname]
tercio@0 286 end
tercio@0 287 handler = group.handler or handler
tercio@0 288 end
tercio@0 289
tercio@0 290 info.options = options
tercio@0 291 info[0] = appName
tercio@0 292 info.arg = option.arg
tercio@0 293
tercio@0 294 local a, b, c ,d
tercio@0 295 if type(func) == "string" then
tercio@0 296 if handler and handler[func] then
tercio@0 297 a,b,c,d = handler[func](handler, info, ...)
tercio@0 298 else
tercio@0 299 error(string.format("Method %s doesn't exist in handler for type func", func))
tercio@0 300 end
tercio@0 301 elseif type(func) == "function" then
tercio@0 302 a,b,c,d = func(info, ...)
tercio@0 303 end
tercio@0 304 del(info)
tercio@0 305 return a,b,c,d
tercio@0 306 end
tercio@0 307 --]]
tercio@0 308
tercio@0 309 --tables to hold orders and names for options being sorted, will be created with new()
tercio@0 310 --prevents needing to call functions repeatedly while sorting
tercio@0 311 local tempOrders
tercio@0 312 local tempNames
tercio@0 313
tercio@0 314 local function compareOptions(a,b)
tercio@0 315 if not a then
tercio@0 316 return true
tercio@0 317 end
tercio@0 318 if not b then
tercio@0 319 return false
tercio@0 320 end
tercio@0 321 local OrderA, OrderB = tempOrders[a] or 100, tempOrders[b] or 100
tercio@0 322 if OrderA == OrderB then
tercio@0 323 local NameA = (type(tempNames[a]) == "string") and tempNames[a] or ""
tercio@0 324 local NameB = (type(tempNames[b]) == "string") and tempNames[b] or ""
tercio@0 325 return NameA:upper() < NameB:upper()
tercio@0 326 end
tercio@0 327 if OrderA < 0 then
tercio@0 328 if OrderB > 0 then
tercio@0 329 return false
tercio@0 330 end
tercio@0 331 else
tercio@0 332 if OrderB < 0 then
tercio@0 333 return true
tercio@0 334 end
tercio@0 335 end
tercio@0 336 return OrderA < OrderB
tercio@0 337 end
tercio@0 338
tercio@0 339
tercio@0 340
tercio@0 341 --builds 2 tables out of an options group
tercio@0 342 -- keySort, sorted keys
tercio@0 343 -- opts, combined options from .plugins and args
tercio@0 344 local function BuildSortedOptionsTable(group, keySort, opts, options, path, appName)
tercio@0 345 tempOrders = new()
tercio@0 346 tempNames = new()
tercio@0 347
tercio@0 348 if group.plugins then
tercio@0 349 for plugin, t in pairs(group.plugins) do
tercio@0 350 for k, v in pairs(t) do
tercio@0 351 if not opts[k] then
tercio@0 352 tinsert(keySort, k)
tercio@0 353 opts[k] = v
tercio@0 354
tercio@0 355 path[#path+1] = k
tercio@0 356 tempOrders[k] = GetOptionsMemberValue("order", v, options, path, appName)
tercio@0 357 tempNames[k] = GetOptionsMemberValue("name", v, options, path, appName)
tercio@0 358 path[#path] = nil
tercio@0 359 end
tercio@0 360 end
tercio@0 361 end
tercio@0 362 end
tercio@0 363
tercio@0 364 for k, v in pairs(group.args) do
tercio@0 365 if not opts[k] then
tercio@0 366 tinsert(keySort, k)
tercio@0 367 opts[k] = v
tercio@0 368
tercio@0 369 path[#path+1] = k
tercio@0 370 tempOrders[k] = GetOptionsMemberValue("order", v, options, path, appName)
tercio@0 371 tempNames[k] = GetOptionsMemberValue("name", v, options, path, appName)
tercio@0 372 path[#path] = nil
tercio@0 373 end
tercio@0 374 end
tercio@0 375
tercio@0 376 tsort(keySort, compareOptions)
tercio@0 377
tercio@0 378 del(tempOrders)
tercio@0 379 del(tempNames)
tercio@0 380 end
tercio@0 381
tercio@0 382 local function DelTree(tree)
tercio@0 383 if tree.children then
tercio@0 384 local childs = tree.children
tercio@0 385 for i = 1, #childs do
tercio@0 386 DelTree(childs[i])
tercio@0 387 del(childs[i])
tercio@0 388 end
tercio@0 389 del(childs)
tercio@0 390 end
tercio@0 391 end
tercio@0 392
tercio@0 393 local function CleanUserData(widget, event)
tercio@0 394
tercio@0 395 local user = widget:GetUserDataTable()
tercio@0 396
tercio@0 397 if user.path then
tercio@0 398 del(user.path)
tercio@0 399 end
tercio@0 400
tercio@0 401 if widget.type == "TreeGroup" then
tercio@0 402 local tree = user.tree
tercio@0 403 widget:SetTree(nil)
tercio@0 404 if tree then
tercio@0 405 for i = 1, #tree do
tercio@0 406 DelTree(tree[i])
tercio@0 407 del(tree[i])
tercio@0 408 end
tercio@0 409 del(tree)
tercio@0 410 end
tercio@0 411 end
tercio@0 412
tercio@0 413 if widget.type == "TabGroup" then
tercio@0 414 widget:SetTabs(nil)
tercio@0 415 if user.tablist then
tercio@0 416 del(user.tablist)
tercio@0 417 end
tercio@0 418 end
tercio@0 419
tercio@0 420 if widget.type == "DropdownGroup" then
tercio@0 421 widget:SetGroupList(nil)
tercio@0 422 if user.grouplist then
tercio@0 423 del(user.grouplist)
tercio@0 424 end
tercio@0 425 if user.orderlist then
tercio@0 426 del(user.orderlist)
tercio@0 427 end
tercio@0 428 end
tercio@0 429 end
tercio@0 430
tercio@0 431 -- - Gets a status table for the given appname and options path.
tercio@0 432 -- @param appName The application name as given to `:RegisterOptionsTable()`
tercio@0 433 -- @param path The path to the options (a table with all group keys)
tercio@0 434 -- @return
tercio@0 435 function AceConfigDialog:GetStatusTable(appName, path)
tercio@0 436 local status = self.Status
tercio@0 437
tercio@0 438 if not status[appName] then
tercio@0 439 status[appName] = {}
tercio@0 440 status[appName].status = {}
tercio@0 441 status[appName].children = {}
tercio@0 442 end
tercio@0 443
tercio@0 444 status = status[appName]
tercio@0 445
tercio@0 446 if path then
tercio@0 447 for i = 1, #path do
tercio@0 448 local v = path[i]
tercio@0 449 if not status.children[v] then
tercio@0 450 status.children[v] = {}
tercio@0 451 status.children[v].status = {}
tercio@0 452 status.children[v].children = {}
tercio@0 453 end
tercio@0 454 status = status.children[v]
tercio@0 455 end
tercio@0 456 end
tercio@0 457
tercio@0 458 return status.status
tercio@0 459 end
tercio@0 460
tercio@0 461 --- Selects the specified path in the options window.
tercio@0 462 -- The path specified has to match the keys of the groups in the table.
tercio@0 463 -- @param appName The application name as given to `:RegisterOptionsTable()`
tercio@0 464 -- @param ... The path to the key that should be selected
tercio@0 465 function AceConfigDialog:SelectGroup(appName, ...)
tercio@0 466 local path = new()
tercio@0 467
tercio@0 468
tercio@0 469 local app = reg:GetOptionsTable(appName)
tercio@0 470 if not app then
tercio@0 471 error(("%s isn't registed with AceConfigRegistry, unable to open config"):format(appName), 2)
tercio@0 472 end
tercio@0 473 local options = app("dialog", MAJOR)
tercio@0 474 local group = options
tercio@0 475 local status = self:GetStatusTable(appName, path)
tercio@0 476 if not status.groups then
tercio@0 477 status.groups = {}
tercio@0 478 end
tercio@0 479 status = status.groups
tercio@0 480 local treevalue
tercio@0 481 local treestatus
tercio@0 482
tercio@0 483 for n = 1, select("#",...) do
tercio@0 484 local key = select(n, ...)
tercio@0 485
tercio@0 486 if group.childGroups == "tab" or group.childGroups == "select" then
tercio@0 487 --if this is a tab or select group, select the group
tercio@0 488 status.selected = key
tercio@0 489 --children of this group are no longer extra levels of a tree
tercio@0 490 treevalue = nil
tercio@0 491 else
tercio@0 492 --tree group by default
tercio@0 493 if treevalue then
tercio@0 494 --this is an extra level of a tree group, build a uniquevalue for it
tercio@0 495 treevalue = treevalue.."\001"..key
tercio@0 496 else
tercio@0 497 --this is the top level of a tree group, the uniquevalue is the same as the key
tercio@0 498 treevalue = key
tercio@0 499 if not status.groups then
tercio@0 500 status.groups = {}
tercio@0 501 end
tercio@0 502 --save this trees status table for any extra levels or groups
tercio@0 503 treestatus = status
tercio@0 504 end
tercio@0 505 --make sure that the tree entry is open, and select it.
tercio@0 506 --the selected group will be overwritten if a child is the final target but still needs to be open
tercio@0 507 treestatus.selected = treevalue
tercio@0 508 treestatus.groups[treevalue] = true
tercio@0 509
tercio@0 510 end
tercio@0 511
tercio@0 512 --move to the next group in the path
tercio@0 513 group = GetSubOption(group, key)
tercio@0 514 if not group then
tercio@0 515 break
tercio@0 516 end
tercio@0 517 tinsert(path, key)
tercio@0 518 status = self:GetStatusTable(appName, path)
tercio@0 519 if not status.groups then
tercio@0 520 status.groups = {}
tercio@0 521 end
tercio@0 522 status = status.groups
tercio@0 523 end
tercio@0 524
tercio@0 525 del(path)
tercio@0 526 reg:NotifyChange(appName)
tercio@0 527 end
tercio@0 528
tercio@0 529 local function OptionOnMouseOver(widget, event)
tercio@0 530 --show a tooltip/set the status bar to the desc text
tercio@0 531 local user = widget:GetUserDataTable()
tercio@0 532 local opt = user.option
tercio@0 533 local options = user.options
tercio@0 534 local path = user.path
tercio@0 535 local appName = user.appName
tercio@0 536
tercio@0 537 GameTooltip:SetOwner(widget.frame, "ANCHOR_TOPRIGHT")
tercio@0 538 local name = GetOptionsMemberValue("name", opt, options, path, appName)
tercio@0 539 local desc = GetOptionsMemberValue("desc", opt, options, path, appName)
tercio@0 540 local usage = GetOptionsMemberValue("usage", opt, options, path, appName)
tercio@0 541 local descStyle = opt.descStyle
tercio@0 542
tercio@0 543 if descStyle and descStyle ~= "tooltip" then return end
tercio@0 544
tercio@0 545 GameTooltip:SetText(name, 1, .82, 0, 1)
tercio@0 546
tercio@0 547 if opt.type == "multiselect" then
tercio@0 548 GameTooltip:AddLine(user.text,0.5, 0.5, 0.8, 1)
tercio@0 549 end
tercio@0 550 if type(desc) == "string" then
tercio@0 551 GameTooltip:AddLine(desc, 1, 1, 1, 1)
tercio@0 552 end
tercio@0 553 if type(usage) == "string" then
tercio@0 554 GameTooltip:AddLine("Usage: "..usage, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, 1)
tercio@0 555 end
tercio@0 556
tercio@0 557 GameTooltip:Show()
tercio@0 558 end
tercio@0 559
tercio@0 560 local function OptionOnMouseLeave(widget, event)
tercio@0 561 GameTooltip:Hide()
tercio@0 562 end
tercio@0 563
tercio@0 564 local function GetFuncName(option)
tercio@0 565 local type = option.type
tercio@0 566 if type == "execute" then
tercio@0 567 return "func"
tercio@0 568 else
tercio@0 569 return "set"
tercio@0 570 end
tercio@0 571 end
tercio@0 572 local function confirmPopup(appName, rootframe, basepath, info, message, func, ...)
tercio@0 573 if not StaticPopupDialogs["ACECONFIGDIALOG30_CONFIRM_DIALOG"] then
tercio@0 574 StaticPopupDialogs["ACECONFIGDIALOG30_CONFIRM_DIALOG"] = {}
tercio@0 575 end
tercio@0 576 local t = StaticPopupDialogs["ACECONFIGDIALOG30_CONFIRM_DIALOG"]
tercio@0 577 for k in pairs(t) do
tercio@0 578 t[k] = nil
tercio@0 579 end
tercio@0 580 t.text = message
tercio@0 581 t.button1 = ACCEPT
tercio@0 582 t.button2 = CANCEL
tercio@0 583 t.preferredIndex = STATICPOPUP_NUMDIALOGS
tercio@0 584 local dialog, oldstrata
tercio@0 585 t.OnAccept = function()
tercio@0 586 safecall(func, unpack(t))
tercio@0 587 if dialog and oldstrata then
tercio@0 588 dialog:SetFrameStrata(oldstrata)
tercio@0 589 end
tercio@0 590 AceConfigDialog:Open(appName, rootframe, unpack(basepath or emptyTbl))
tercio@0 591 del(info)
tercio@0 592 end
tercio@0 593 t.OnCancel = function()
tercio@0 594 if dialog and oldstrata then
tercio@0 595 dialog:SetFrameStrata(oldstrata)
tercio@0 596 end
tercio@0 597 AceConfigDialog:Open(appName, rootframe, unpack(basepath or emptyTbl))
tercio@0 598 del(info)
tercio@0 599 end
tercio@0 600 for i = 1, select("#", ...) do
tercio@0 601 t[i] = select(i, ...) or false
tercio@0 602 end
tercio@0 603 t.timeout = 0
tercio@0 604 t.whileDead = 1
tercio@0 605 t.hideOnEscape = 1
tercio@0 606
tercio@0 607 dialog = StaticPopup_Show("ACECONFIGDIALOG30_CONFIRM_DIALOG")
tercio@0 608 if dialog then
tercio@0 609 oldstrata = dialog:GetFrameStrata()
tercio@0 610 dialog:SetFrameStrata("TOOLTIP")
tercio@0 611 end
tercio@0 612 end
tercio@0 613
tercio@0 614 local function ActivateControl(widget, event, ...)
tercio@0 615 --This function will call the set / execute handler for the widget
tercio@0 616 --widget:GetUserDataTable() contains the needed info
tercio@0 617 local user = widget:GetUserDataTable()
tercio@0 618 local option = user.option
tercio@0 619 local options = user.options
tercio@0 620 local path = user.path
tercio@0 621 local info = new()
tercio@0 622
tercio@0 623 local func
tercio@0 624 local group = options
tercio@0 625 local funcname = GetFuncName(option)
tercio@0 626 local handler
tercio@0 627 local confirm
tercio@0 628 local validate
tercio@0 629 --build the info table containing the path
tercio@0 630 -- pick up functions while traversing the tree
tercio@0 631 if group[funcname] ~= nil then
tercio@0 632 func = group[funcname]
tercio@0 633 end
tercio@0 634 handler = group.handler or handler
tercio@0 635 confirm = group.confirm
tercio@0 636 validate = group.validate
tercio@0 637 for i = 1, #path do
tercio@0 638 local v = path[i]
tercio@0 639 group = GetSubOption(group, v)
tercio@0 640 info[i] = v
tercio@0 641 if group[funcname] ~= nil then
tercio@0 642 func = group[funcname]
tercio@0 643 end
tercio@0 644 handler = group.handler or handler
tercio@0 645 if group.confirm ~= nil then
tercio@0 646 confirm = group.confirm
tercio@0 647 end
tercio@0 648 if group.validate ~= nil then
tercio@0 649 validate = group.validate
tercio@0 650 end
tercio@0 651 end
tercio@0 652
tercio@0 653 info.options = options
tercio@0 654 info.appName = user.appName
tercio@0 655 info.arg = option.arg
tercio@0 656 info.handler = handler
tercio@0 657 info.option = option
tercio@0 658 info.type = option.type
tercio@0 659 info.uiType = "dialog"
tercio@0 660 info.uiName = MAJOR
tercio@0 661
tercio@0 662 local name
tercio@0 663 if type(option.name) == "function" then
tercio@0 664 name = option.name(info)
tercio@0 665 elseif type(option.name) == "string" then
tercio@0 666 name = option.name
tercio@0 667 else
tercio@0 668 name = ""
tercio@0 669 end
tercio@0 670 local usage = option.usage
tercio@0 671 local pattern = option.pattern
tercio@0 672
tercio@0 673 local validated = true
tercio@0 674
tercio@0 675 if option.type == "input" then
tercio@0 676 if type(pattern)=="string" then
tercio@0 677 if not strmatch(..., pattern) then
tercio@0 678 validated = false
tercio@0 679 end
tercio@0 680 end
tercio@0 681 end
tercio@0 682
tercio@0 683 local success
tercio@0 684 if validated and option.type ~= "execute" then
tercio@0 685 if type(validate) == "string" then
tercio@0 686 if handler and handler[validate] then
tercio@0 687 success, validated = safecall(handler[validate], handler, info, ...)
tercio@0 688 if not success then validated = false end
tercio@0 689 else
tercio@0 690 error(format("Method %s doesn't exist in handler for type execute", validate))
tercio@0 691 end
tercio@0 692 elseif type(validate) == "function" then
tercio@0 693 success, validated = safecall(validate, info, ...)
tercio@0 694 if not success then validated = false end
tercio@0 695 end
tercio@0 696 end
tercio@0 697
tercio@0 698 local rootframe = user.rootframe
tercio@0 699 if type(validated) == "string" then
tercio@0 700 --validate function returned a message to display
tercio@0 701 if rootframe.SetStatusText then
tercio@0 702 rootframe:SetStatusText(validated)
tercio@0 703 else
tercio@0 704 -- TODO: do something else.
tercio@0 705 end
tercio@0 706 PlaySound("igPlayerInviteDecline")
tercio@0 707 del(info)
tercio@0 708 return true
tercio@0 709 elseif not validated then
tercio@0 710 --validate returned false
tercio@0 711 if rootframe.SetStatusText then
tercio@0 712 if usage then
tercio@0 713 rootframe:SetStatusText(name..": "..usage)
tercio@0 714 else
tercio@0 715 if pattern then
tercio@0 716 rootframe:SetStatusText(name..": Expected "..pattern)
tercio@0 717 else
tercio@0 718 rootframe:SetStatusText(name..": Invalid Value")
tercio@0 719 end
tercio@0 720 end
tercio@0 721 else
tercio@0 722 -- TODO: do something else
tercio@0 723 end
tercio@0 724 PlaySound("igPlayerInviteDecline")
tercio@0 725 del(info)
tercio@0 726 return true
tercio@0 727 else
tercio@0 728
tercio@0 729 local confirmText = option.confirmText
tercio@0 730 --call confirm func/method
tercio@0 731 if type(confirm) == "string" then
tercio@0 732 if handler and handler[confirm] then
tercio@0 733 success, confirm = safecall(handler[confirm], handler, info, ...)
tercio@0 734 if success and type(confirm) == "string" then
tercio@0 735 confirmText = confirm
tercio@0 736 confirm = true
tercio@0 737 elseif not success then
tercio@0 738 confirm = false
tercio@0 739 end
tercio@0 740 else
tercio@0 741 error(format("Method %s doesn't exist in handler for type confirm", confirm))
tercio@0 742 end
tercio@0 743 elseif type(confirm) == "function" then
tercio@0 744 success, confirm = safecall(confirm, info, ...)
tercio@0 745 if success and type(confirm) == "string" then
tercio@0 746 confirmText = confirm
tercio@0 747 confirm = true
tercio@0 748 elseif not success then
tercio@0 749 confirm = false
tercio@0 750 end
tercio@0 751 end
tercio@0 752
tercio@0 753 --confirm if needed
tercio@0 754 if type(confirm) == "boolean" then
tercio@0 755 if confirm then
tercio@0 756 if not confirmText then
tercio@0 757 local name, desc = option.name, option.desc
tercio@0 758 if type(name) == "function" then
tercio@0 759 name = name(info)
tercio@0 760 end
tercio@0 761 if type(desc) == "function" then
tercio@0 762 desc = desc(info)
tercio@0 763 end
tercio@0 764 confirmText = name
tercio@0 765 if desc then
tercio@0 766 confirmText = confirmText.." - "..desc
tercio@0 767 end
tercio@0 768 end
tercio@0 769
tercio@0 770 local iscustom = user.rootframe:GetUserData("iscustom")
tercio@0 771 local rootframe
tercio@0 772
tercio@0 773 if iscustom then
tercio@0 774 rootframe = user.rootframe
tercio@0 775 end
tercio@0 776 local basepath = user.rootframe:GetUserData("basepath")
tercio@0 777 if type(func) == "string" then
tercio@0 778 if handler and handler[func] then
tercio@0 779 confirmPopup(user.appName, rootframe, basepath, info, confirmText, handler[func], handler, info, ...)
tercio@0 780 else
tercio@0 781 error(format("Method %s doesn't exist in handler for type func", func))
tercio@0 782 end
tercio@0 783 elseif type(func) == "function" then
tercio@0 784 confirmPopup(user.appName, rootframe, basepath, info, confirmText, func, info, ...)
tercio@0 785 end
tercio@0 786 --func will be called and info deleted when the confirm dialog is responded to
tercio@0 787 return
tercio@0 788 end
tercio@0 789 end
tercio@0 790
tercio@0 791 --call the function
tercio@0 792 if type(func) == "string" then
tercio@0 793 if handler and handler[func] then
tercio@0 794 safecall(handler[func],handler, info, ...)
tercio@0 795 else
tercio@0 796 error(format("Method %s doesn't exist in handler for type func", func))
tercio@0 797 end
tercio@0 798 elseif type(func) == "function" then
tercio@0 799 safecall(func,info, ...)
tercio@0 800 end
tercio@0 801
tercio@0 802
tercio@0 803
tercio@0 804 local iscustom = user.rootframe:GetUserData("iscustom")
tercio@0 805 local basepath = user.rootframe:GetUserData("basepath") or emptyTbl
tercio@0 806 --full refresh of the frame, some controls dont cause this on all events
tercio@0 807 if option.type == "color" then
tercio@0 808 if event == "OnValueConfirmed" then
tercio@0 809
tercio@0 810 if iscustom then
tercio@0 811 AceConfigDialog:Open(user.appName, user.rootframe, unpack(basepath))
tercio@0 812 else
tercio@0 813 AceConfigDialog:Open(user.appName, unpack(basepath))
tercio@0 814 end
tercio@0 815 end
tercio@0 816 elseif option.type == "range" then
tercio@0 817 if event == "OnMouseUp" then
tercio@0 818 if iscustom then
tercio@0 819 AceConfigDialog:Open(user.appName, user.rootframe, unpack(basepath))
tercio@0 820 else
tercio@0 821 AceConfigDialog:Open(user.appName, unpack(basepath))
tercio@0 822 end
tercio@0 823 end
tercio@0 824 --multiselects don't cause a refresh on 'OnValueChanged' only 'OnClosed'
tercio@0 825 elseif option.type == "multiselect" then
tercio@0 826 user.valuechanged = true
tercio@0 827 else
tercio@0 828 if iscustom then
tercio@0 829 AceConfigDialog:Open(user.appName, user.rootframe, unpack(basepath))
tercio@0 830 else
tercio@0 831 AceConfigDialog:Open(user.appName, unpack(basepath))
tercio@0 832 end
tercio@0 833 end
tercio@0 834
tercio@0 835 end
tercio@0 836 del(info)
tercio@0 837 end
tercio@0 838
tercio@0 839 local function ActivateSlider(widget, event, value)
tercio@0 840 local option = widget:GetUserData("option")
tercio@0 841 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 842 if min then
tercio@0 843 if step then
tercio@0 844 value = math_floor((value - min) / step + 0.5) * step + min
tercio@0 845 end
tercio@0 846 value = math_max(value, min)
tercio@0 847 end
tercio@0 848 if max then
tercio@0 849 value = math_min(value, max)
tercio@0 850 end
tercio@0 851 ActivateControl(widget,event,value)
tercio@0 852 end
tercio@0 853
tercio@0 854 --called from a checkbox that is part of an internally created multiselect group
tercio@0 855 --this type is safe to refresh on activation of one control
tercio@0 856 local function ActivateMultiControl(widget, event, ...)
tercio@0 857 ActivateControl(widget, event, widget:GetUserData("value"), ...)
tercio@0 858 local user = widget:GetUserDataTable()
tercio@0 859 local iscustom = user.rootframe:GetUserData("iscustom")
tercio@0 860 local basepath = user.rootframe:GetUserData("basepath") or emptyTbl
tercio@0 861 if iscustom then
tercio@0 862 AceConfigDialog:Open(user.appName, user.rootframe, unpack(basepath))
tercio@0 863 else
tercio@0 864 AceConfigDialog:Open(user.appName, unpack(basepath))
tercio@0 865 end
tercio@0 866 end
tercio@0 867
tercio@0 868 local function MultiControlOnClosed(widget, event, ...)
tercio@0 869 local user = widget:GetUserDataTable()
tercio@0 870 if user.valuechanged then
tercio@0 871 local iscustom = user.rootframe:GetUserData("iscustom")
tercio@0 872 local basepath = user.rootframe:GetUserData("basepath") or emptyTbl
tercio@0 873 if iscustom then
tercio@0 874 AceConfigDialog:Open(user.appName, user.rootframe, unpack(basepath))
tercio@0 875 else
tercio@0 876 AceConfigDialog:Open(user.appName, unpack(basepath))
tercio@0 877 end
tercio@0 878 end
tercio@0 879 end
tercio@0 880
tercio@0 881 local function FrameOnClose(widget, event)
tercio@0 882 local appName = widget:GetUserData("appName")
tercio@0 883 AceConfigDialog.OpenFrames[appName] = nil
tercio@0 884 gui:Release(widget)
tercio@0 885 end
tercio@0 886
tercio@0 887 local function CheckOptionHidden(option, options, path, appName)
tercio@0 888 --check for a specific boolean option
tercio@0 889 local hidden = pickfirstset(option.dialogHidden,option.guiHidden)
tercio@0 890 if hidden ~= nil then
tercio@0 891 return hidden
tercio@0 892 end
tercio@0 893
tercio@0 894 return GetOptionsMemberValue("hidden", option, options, path, appName)
tercio@0 895 end
tercio@0 896
tercio@0 897 local function CheckOptionDisabled(option, options, path, appName)
tercio@0 898 --check for a specific boolean option
tercio@0 899 local disabled = pickfirstset(option.dialogDisabled,option.guiDisabled)
tercio@0 900 if disabled ~= nil then
tercio@0 901 return disabled
tercio@0 902 end
tercio@0 903
tercio@0 904 return GetOptionsMemberValue("disabled", option, options, path, appName)
tercio@0 905 end
tercio@0 906 --[[
tercio@0 907 local function BuildTabs(group, options, path, appName)
tercio@0 908 local tabs = new()
tercio@0 909 local text = new()
tercio@0 910 local keySort = new()
tercio@0 911 local opts = new()
tercio@0 912
tercio@0 913 BuildSortedOptionsTable(group, keySort, opts, options, path, appName)
tercio@0 914
tercio@0 915 for i = 1, #keySort do
tercio@0 916 local k = keySort[i]
tercio@0 917 local v = opts[k]
tercio@0 918 if v.type == "group" then
tercio@0 919 path[#path+1] = k
tercio@0 920 local inline = pickfirstset(v.dialogInline,v.guiInline,v.inline, false)
tercio@0 921 local hidden = CheckOptionHidden(v, options, path, appName)
tercio@0 922 if not inline and not hidden then
tercio@0 923 tinsert(tabs, k)
tercio@0 924 text[k] = GetOptionsMemberValue("name", v, options, path, appName)
tercio@0 925 end
tercio@0 926 path[#path] = nil
tercio@0 927 end
tercio@0 928 end
tercio@0 929
tercio@0 930 del(keySort)
tercio@0 931 del(opts)
tercio@0 932
tercio@0 933 return tabs, text
tercio@0 934 end
tercio@0 935 ]]
tercio@0 936 local function BuildSelect(group, options, path, appName)
tercio@0 937 local groups = new()
tercio@0 938 local order = new()
tercio@0 939 local keySort = new()
tercio@0 940 local opts = new()
tercio@0 941
tercio@0 942 BuildSortedOptionsTable(group, keySort, opts, options, path, appName)
tercio@0 943
tercio@0 944 for i = 1, #keySort do
tercio@0 945 local k = keySort[i]
tercio@0 946 local v = opts[k]
tercio@0 947 if v.type == "group" then
tercio@0 948 path[#path+1] = k
tercio@0 949 local inline = pickfirstset(v.dialogInline,v.guiInline,v.inline, false)
tercio@0 950 local hidden = CheckOptionHidden(v, options, path, appName)
tercio@0 951 if not inline and not hidden then
tercio@0 952 groups[k] = GetOptionsMemberValue("name", v, options, path, appName)
tercio@0 953 tinsert(order, k)
tercio@0 954 end
tercio@0 955 path[#path] = nil
tercio@0 956 end
tercio@0 957 end
tercio@0 958
tercio@0 959 del(opts)
tercio@0 960 del(keySort)
tercio@0 961
tercio@0 962 return groups, order
tercio@0 963 end
tercio@0 964
tercio@0 965 local function BuildSubGroups(group, tree, options, path, appName)
tercio@0 966 local keySort = new()
tercio@0 967 local opts = new()
tercio@0 968
tercio@0 969 BuildSortedOptionsTable(group, keySort, opts, options, path, appName)
tercio@0 970
tercio@0 971 for i = 1, #keySort do
tercio@0 972 local k = keySort[i]
tercio@0 973 local v = opts[k]
tercio@0 974 if v.type == "group" then
tercio@0 975 path[#path+1] = k
tercio@0 976 local inline = pickfirstset(v.dialogInline,v.guiInline,v.inline, false)
tercio@0 977 local hidden = CheckOptionHidden(v, options, path, appName)
tercio@0 978 if not inline and not hidden then
tercio@0 979 local entry = new()
tercio@0 980 entry.value = k
tercio@0 981 entry.text = GetOptionsMemberValue("name", v, options, path, appName)
tercio@0 982 entry.icon = GetOptionsMemberValue("icon", v, options, path, appName)
tercio@0 983 entry.iconCoords = GetOptionsMemberValue("iconCoords", v, options, path, appName)
tercio@0 984 entry.disabled = CheckOptionDisabled(v, options, path, appName)
tercio@0 985 if not tree.children then tree.children = new() end
tercio@0 986 tinsert(tree.children,entry)
tercio@0 987 if (v.childGroups or "tree") == "tree" then
tercio@0 988 BuildSubGroups(v,entry, options, path, appName)
tercio@0 989 end
tercio@0 990 end
tercio@0 991 path[#path] = nil
tercio@0 992 end
tercio@0 993 end
tercio@0 994
tercio@0 995 del(keySort)
tercio@0 996 del(opts)
tercio@0 997 end
tercio@0 998
tercio@0 999 local function BuildGroups(group, options, path, appName, recurse)
tercio@0 1000 local tree = new()
tercio@0 1001 local keySort = new()
tercio@0 1002 local opts = new()
tercio@0 1003
tercio@0 1004 BuildSortedOptionsTable(group, keySort, opts, options, path, appName)
tercio@0 1005
tercio@0 1006 for i = 1, #keySort do
tercio@0 1007 local k = keySort[i]
tercio@0 1008 local v = opts[k]
tercio@0 1009 if v.type == "group" then
tercio@0 1010 path[#path+1] = k
tercio@0 1011 local inline = pickfirstset(v.dialogInline,v.guiInline,v.inline, false)
tercio@0 1012 local hidden = CheckOptionHidden(v, options, path, appName)
tercio@0 1013 if not inline and not hidden then
tercio@0 1014 local entry = new()
tercio@0 1015 entry.value = k
tercio@0 1016 entry.text = GetOptionsMemberValue("name", v, options, path, appName)
tercio@0 1017 entry.icon = GetOptionsMemberValue("icon", v, options, path, appName)
tercio@0 1018 entry.disabled = CheckOptionDisabled(v, options, path, appName)
tercio@0 1019 tinsert(tree,entry)
tercio@0 1020 if recurse and (v.childGroups or "tree") == "tree" then
tercio@0 1021 BuildSubGroups(v,entry, options, path, appName)
tercio@0 1022 end
tercio@0 1023 end
tercio@0 1024 path[#path] = nil
tercio@0 1025 end
tercio@0 1026 end
tercio@0 1027 del(keySort)
tercio@0 1028 del(opts)
tercio@0 1029 return tree
tercio@0 1030 end
tercio@0 1031
tercio@0 1032 local function InjectInfo(control, options, option, path, rootframe, appName)
tercio@0 1033 local user = control:GetUserDataTable()
tercio@0 1034 for i = 1, #path do
tercio@0 1035 user[i] = path[i]
tercio@0 1036 end
tercio@0 1037 user.rootframe = rootframe
tercio@0 1038 user.option = option
tercio@0 1039 user.options = options
tercio@0 1040 user.path = copy(path)
tercio@0 1041 user.appName = appName
tercio@0 1042 control:SetCallback("OnRelease", CleanUserData)
tercio@0 1043 control:SetCallback("OnLeave", OptionOnMouseLeave)
tercio@0 1044 control:SetCallback("OnEnter", OptionOnMouseOver)
tercio@0 1045 end
tercio@0 1046
tercio@0 1047
tercio@0 1048 --[[
tercio@0 1049 options - root of the options table being fed
tercio@0 1050 container - widget that controls will be placed in
tercio@0 1051 rootframe - Frame object the options are in
tercio@0 1052 path - table with the keys to get to the group being fed
tercio@0 1053 --]]
tercio@0 1054
tercio@0 1055 local function FeedOptions(appName, options,container,rootframe,path,group,inline)
tercio@0 1056 local keySort = new()
tercio@0 1057 local opts = new()
tercio@0 1058
tercio@0 1059 BuildSortedOptionsTable(group, keySort, opts, options, path, appName)
tercio@0 1060
tercio@0 1061 for i = 1, #keySort do
tercio@0 1062 local k = keySort[i]
tercio@0 1063 local v = opts[k]
tercio@0 1064 tinsert(path, k)
tercio@0 1065 local hidden = CheckOptionHidden(v, options, path, appName)
tercio@0 1066 local name = GetOptionsMemberValue("name", v, options, path, appName)
tercio@0 1067 if not hidden then
tercio@0 1068 if v.type == "group" then
tercio@0 1069 if inline or pickfirstset(v.dialogInline,v.guiInline,v.inline, false) then
tercio@0 1070 --Inline group
tercio@0 1071 local GroupContainer
tercio@0 1072 if name and name ~= "" then
tercio@0 1073 GroupContainer = gui:Create("InlineGroup")
tercio@0 1074 GroupContainer:SetTitle(name or "")
tercio@0 1075 else
tercio@0 1076 GroupContainer = gui:Create("SimpleGroup")
tercio@0 1077 end
tercio@0 1078
tercio@0 1079 GroupContainer.width = "fill"
tercio@0 1080 GroupContainer:SetLayout("flow")
tercio@0 1081 container:AddChild(GroupContainer)
tercio@0 1082 FeedOptions(appName,options,GroupContainer,rootframe,path,v,true)
tercio@0 1083 end
tercio@0 1084 else
tercio@0 1085 --Control to feed
tercio@0 1086 local control
tercio@0 1087
tercio@0 1088 local name = GetOptionsMemberValue("name", v, options, path, appName)
tercio@0 1089
tercio@0 1090 if v.type == "execute" then
tercio@0 1091
tercio@0 1092 local imageCoords = GetOptionsMemberValue("imageCoords",v, options, path, appName)
tercio@0 1093 local image, width, height = GetOptionsMemberValue("image",v, options, path, appName)
tercio@0 1094
tercio@0 1095 if type(image) == "string" then
tercio@0 1096 control = gui:Create("Icon")
tercio@0 1097 if not width then
tercio@0 1098 width = GetOptionsMemberValue("imageWidth",v, options, path, appName)
tercio@0 1099 end
tercio@0 1100 if not height then
tercio@0 1101 height = GetOptionsMemberValue("imageHeight",v, options, path, appName)
tercio@0 1102 end
tercio@0 1103 if type(imageCoords) == "table" then
tercio@0 1104 control:SetImage(image, unpack(imageCoords))
tercio@0 1105 else
tercio@0 1106 control:SetImage(image)
tercio@0 1107 end
tercio@0 1108 if type(width) ~= "number" then
tercio@0 1109 width = 32
tercio@0 1110 end
tercio@0 1111 if type(height) ~= "number" then
tercio@0 1112 height = 32
tercio@0 1113 end
tercio@0 1114 control:SetImageSize(width, height)
tercio@0 1115 control:SetLabel(name)
tercio@0 1116 else
tercio@0 1117 control = gui:Create("Button")
tercio@0 1118 control:SetText(name)
tercio@0 1119 end
tercio@0 1120 control:SetCallback("OnClick",ActivateControl)
tercio@0 1121
tercio@0 1122 elseif v.type == "input" then
tercio@0 1123 local controlType = v.dialogControl or v.control or (v.multiline and "MultiLineEditBox") or "EditBox"
tercio@0 1124 control = gui:Create(controlType)
tercio@0 1125 if not control then
tercio@0 1126 geterrorhandler()(("Invalid Custom Control Type - %s"):format(tostring(controlType)))
tercio@0 1127 control = gui:Create(v.multiline and "MultiLineEditBox" or "EditBox")
tercio@0 1128 end
tercio@0 1129
tercio@0 1130 if v.multiline and control.SetNumLines then
tercio@0 1131 control:SetNumLines(tonumber(v.multiline) or 4)
tercio@0 1132 end
tercio@0 1133 control:SetLabel(name)
tercio@0 1134 control:SetCallback("OnEnterPressed",ActivateControl)
tercio@0 1135 local text = GetOptionsMemberValue("get",v, options, path, appName)
tercio@0 1136 if type(text) ~= "string" then
tercio@0 1137 text = ""
tercio@0 1138 end
tercio@0 1139 control:SetText(text)
tercio@0 1140
tercio@0 1141 elseif v.type == "toggle" then
tercio@0 1142 control = gui:Create("CheckBox")
tercio@0 1143 control:SetLabel(name)
tercio@0 1144 control:SetTriState(v.tristate)
tercio@0 1145 local value = GetOptionsMemberValue("get",v, options, path, appName)
tercio@0 1146 control:SetValue(value)
tercio@0 1147 control:SetCallback("OnValueChanged",ActivateControl)
tercio@0 1148
tercio@0 1149 if v.descStyle == "inline" then
tercio@0 1150 local desc = GetOptionsMemberValue("desc", v, options, path, appName)
tercio@0 1151 control:SetDescription(desc)
tercio@0 1152 end
tercio@0 1153
tercio@0 1154 local image = GetOptionsMemberValue("image", v, options, path, appName)
tercio@0 1155 local imageCoords = GetOptionsMemberValue("imageCoords", v, options, path, appName)
tercio@0 1156
tercio@0 1157 if type(image) == "string" then
tercio@0 1158 if type(imageCoords) == "table" then
tercio@0 1159 control:SetImage(image, unpack(imageCoords))
tercio@0 1160 else
tercio@0 1161 control:SetImage(image)
tercio@0 1162 end
tercio@0 1163 end
tercio@0 1164 elseif v.type == "range" then
tercio@0 1165 control = gui:Create("Slider")
tercio@0 1166 control:SetLabel(name)
tercio@0 1167 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 1168 control:SetIsPercent(v.isPercent)
tercio@0 1169 local value = GetOptionsMemberValue("get",v, options, path, appName)
tercio@0 1170 if type(value) ~= "number" then
tercio@0 1171 value = 0
tercio@0 1172 end
tercio@0 1173 control:SetValue(value)
tercio@0 1174 control:SetCallback("OnValueChanged",ActivateSlider)
tercio@0 1175 control:SetCallback("OnMouseUp",ActivateSlider)
tercio@0 1176
tercio@0 1177 elseif v.type == "select" then
tercio@0 1178 local values = GetOptionsMemberValue("values", v, options, path, appName)
tercio@0 1179 if v.style == "radio" then
tercio@0 1180 local disabled = CheckOptionDisabled(v, options, path, appName)
tercio@0 1181 local width = GetOptionsMemberValue("width",v,options,path,appName)
tercio@0 1182 control = gui:Create("InlineGroup")
tercio@0 1183 control:SetLayout("Flow")
tercio@0 1184 control:SetTitle(name)
tercio@0 1185 control.width = "fill"
tercio@0 1186
tercio@0 1187 control:PauseLayout()
tercio@0 1188 local optionValue = GetOptionsMemberValue("get",v, options, path, appName)
tercio@0 1189 local t = {}
tercio@0 1190 for value, text in pairs(values) do
tercio@0 1191 t[#t+1]=value
tercio@0 1192 end
tercio@0 1193 tsort(t)
tercio@0 1194 for k, value in ipairs(t) do
tercio@0 1195 local text = values[value]
tercio@0 1196 local radio = gui:Create("CheckBox")
tercio@0 1197 radio:SetLabel(text)
tercio@0 1198 radio:SetUserData("value", value)
tercio@0 1199 radio:SetUserData("text", text)
tercio@0 1200 radio:SetDisabled(disabled)
tercio@0 1201 radio:SetType("radio")
tercio@0 1202 radio:SetValue(optionValue == value)
tercio@0 1203 radio:SetCallback("OnValueChanged", ActivateMultiControl)
tercio@0 1204 InjectInfo(radio, options, v, path, rootframe, appName)
tercio@0 1205 control:AddChild(radio)
tercio@0 1206 if width == "double" then
tercio@0 1207 radio:SetWidth(width_multiplier * 2)
tercio@0 1208 elseif width == "half" then
tercio@0 1209 radio:SetWidth(width_multiplier / 2)
tercio@0 1210 elseif width == "full" then
tercio@0 1211 radio.width = "fill"
tercio@0 1212 else
tercio@0 1213 radio:SetWidth(width_multiplier)
tercio@0 1214 end
tercio@0 1215 end
tercio@0 1216 control:ResumeLayout()
tercio@0 1217 control:DoLayout()
tercio@0 1218 else
tercio@0 1219 local controlType = v.dialogControl or v.control or "Dropdown"
tercio@0 1220 control = gui:Create(controlType)
tercio@0 1221 if not control then
tercio@0 1222 geterrorhandler()(("Invalid Custom Control Type - %s"):format(tostring(controlType)))
tercio@0 1223 control = gui:Create("Dropdown")
tercio@0 1224 end
tercio@0 1225 local itemType = v.itemControl
tercio@0 1226 if itemType and not gui:GetWidgetVersion(itemType) then
tercio@0 1227 geterrorhandler()(("Invalid Custom Item Type - %s"):format(tostring(itemType)))
tercio@0 1228 itemType = nil
tercio@0 1229 end
tercio@0 1230 control:SetLabel(name)
tercio@0 1231 control:SetList(values, nil, itemType)
tercio@0 1232 local value = GetOptionsMemberValue("get",v, options, path, appName)
tercio@0 1233 if not values[value] then
tercio@0 1234 value = nil
tercio@0 1235 end
tercio@0 1236 control:SetValue(value)
tercio@0 1237 control:SetCallback("OnValueChanged", ActivateControl)
tercio@0 1238 end
tercio@0 1239
tercio@0 1240 elseif v.type == "multiselect" then
tercio@0 1241 local values = GetOptionsMemberValue("values", v, options, path, appName)
tercio@0 1242 local disabled = CheckOptionDisabled(v, options, path, appName)
tercio@0 1243
tercio@0 1244 local controlType = v.dialogControl or v.control
tercio@0 1245
tercio@0 1246 local valuesort = new()
tercio@0 1247 if values then
tercio@0 1248 for value, text in pairs(values) do
tercio@0 1249 tinsert(valuesort, value)
tercio@0 1250 end
tercio@0 1251 end
tercio@0 1252 tsort(valuesort)
tercio@0 1253
tercio@0 1254 if controlType then
tercio@0 1255 control = gui:Create(controlType)
tercio@0 1256 if not control then
tercio@0 1257 geterrorhandler()(("Invalid Custom Control Type - %s"):format(tostring(controlType)))
tercio@0 1258 end
tercio@0 1259 end
tercio@0 1260 if control then
tercio@0 1261 control:SetMultiselect(true)
tercio@0 1262 control:SetLabel(name)
tercio@0 1263 control:SetList(values)
tercio@0 1264 control:SetDisabled(disabled)
tercio@0 1265 control:SetCallback("OnValueChanged",ActivateControl)
tercio@0 1266 control:SetCallback("OnClosed", MultiControlOnClosed)
tercio@0 1267 local width = GetOptionsMemberValue("width",v,options,path,appName)
tercio@0 1268 if width == "double" then
tercio@0 1269 control:SetWidth(width_multiplier * 2)
tercio@0 1270 elseif width == "half" then
tercio@0 1271 control:SetWidth(width_multiplier / 2)
tercio@0 1272 elseif width == "full" then
tercio@0 1273 control.width = "fill"
tercio@0 1274 else
tercio@0 1275 control:SetWidth(width_multiplier)
tercio@0 1276 end
tercio@0 1277 --check:SetTriState(v.tristate)
tercio@0 1278 for i = 1, #valuesort do
tercio@0 1279 local key = valuesort[i]
tercio@0 1280 local value = GetOptionsMemberValue("get",v, options, path, appName, key)
tercio@0 1281 control:SetItemValue(key,value)
tercio@0 1282 end
tercio@0 1283 else
tercio@0 1284 control = gui:Create("InlineGroup")
tercio@0 1285 control:SetLayout("Flow")
tercio@0 1286 control:SetTitle(name)
tercio@0 1287 control.width = "fill"
tercio@0 1288
tercio@0 1289 control:PauseLayout()
tercio@0 1290 local width = GetOptionsMemberValue("width",v,options,path,appName)
tercio@0 1291 for i = 1, #valuesort do
tercio@0 1292 local value = valuesort[i]
tercio@0 1293 local text = values[value]
tercio@0 1294 local check = gui:Create("CheckBox")
tercio@0 1295 check:SetLabel(text)
tercio@0 1296 check:SetUserData("value", value)
tercio@0 1297 check:SetUserData("text", text)
tercio@0 1298 check:SetDisabled(disabled)
tercio@0 1299 check:SetTriState(v.tristate)
tercio@0 1300 check:SetValue(GetOptionsMemberValue("get",v, options, path, appName, value))
tercio@0 1301 check:SetCallback("OnValueChanged",ActivateMultiControl)
tercio@0 1302 InjectInfo(check, options, v, path, rootframe, appName)
tercio@0 1303 control:AddChild(check)
tercio@0 1304 if width == "double" then
tercio@0 1305 check:SetWidth(width_multiplier * 2)
tercio@0 1306 elseif width == "half" then
tercio@0 1307 check:SetWidth(width_multiplier / 2)
tercio@0 1308 elseif width == "full" then
tercio@0 1309 check.width = "fill"
tercio@0 1310 else
tercio@0 1311 check:SetWidth(width_multiplier)
tercio@0 1312 end
tercio@0 1313 end
tercio@0 1314 control:ResumeLayout()
tercio@0 1315 control:DoLayout()
tercio@0 1316
tercio@0 1317
tercio@0 1318 end
tercio@0 1319
tercio@0 1320 del(valuesort)
tercio@0 1321
tercio@0 1322 elseif v.type == "color" then
tercio@0 1323 control = gui:Create("ColorPicker")
tercio@0 1324 control:SetLabel(name)
tercio@0 1325 control:SetHasAlpha(GetOptionsMemberValue("hasAlpha",v, options, path, appName))
tercio@0 1326 control:SetColor(GetOptionsMemberValue("get",v, options, path, appName))
tercio@0 1327 control:SetCallback("OnValueChanged",ActivateControl)
tercio@0 1328 control:SetCallback("OnValueConfirmed",ActivateControl)
tercio@0 1329
tercio@0 1330 elseif v.type == "keybinding" then
tercio@0 1331 control = gui:Create("Keybinding")
tercio@0 1332 control:SetLabel(name)
tercio@0 1333 control:SetKey(GetOptionsMemberValue("get",v, options, path, appName))
tercio@0 1334 control:SetCallback("OnKeyChanged",ActivateControl)
tercio@0 1335
tercio@0 1336 elseif v.type == "header" then
tercio@0 1337 control = gui:Create("Heading")
tercio@0 1338 control:SetText(name)
tercio@0 1339 control.width = "fill"
tercio@0 1340
tercio@0 1341 elseif v.type == "description" then
tercio@0 1342 control = gui:Create("Label")
tercio@0 1343 control:SetText(name)
tercio@0 1344
tercio@0 1345 local fontSize = GetOptionsMemberValue("fontSize",v, options, path, appName)
tercio@0 1346 if fontSize == "medium" then
tercio@0 1347 control:SetFontObject(GameFontHighlight)
tercio@0 1348 elseif fontSize == "large" then
tercio@0 1349 control:SetFontObject(GameFontHighlightLarge)
tercio@0 1350 else -- small or invalid
tercio@0 1351 control:SetFontObject(GameFontHighlightSmall)
tercio@0 1352 end
tercio@0 1353
tercio@0 1354 local imageCoords = GetOptionsMemberValue("imageCoords",v, options, path, appName)
tercio@0 1355 local image, width, height = GetOptionsMemberValue("image",v, options, path, appName)
tercio@0 1356
tercio@0 1357 if type(image) == "string" then
tercio@0 1358 if not width then
tercio@0 1359 width = GetOptionsMemberValue("imageWidth",v, options, path, appName)
tercio@0 1360 end
tercio@0 1361 if not height then
tercio@0 1362 height = GetOptionsMemberValue("imageHeight",v, options, path, appName)
tercio@0 1363 end
tercio@0 1364 if type(imageCoords) == "table" then
tercio@0 1365 control:SetImage(image, unpack(imageCoords))
tercio@0 1366 else
tercio@0 1367 control:SetImage(image)
tercio@0 1368 end
tercio@0 1369 if type(width) ~= "number" then
tercio@0 1370 width = 32
tercio@0 1371 end
tercio@0 1372 if type(height) ~= "number" then
tercio@0 1373 height = 32
tercio@0 1374 end
tercio@0 1375 control:SetImageSize(width, height)
tercio@0 1376 end
tercio@0 1377 local width = GetOptionsMemberValue("width",v,options,path,appName)
tercio@0 1378 control.width = not width and "fill"
tercio@0 1379 end
tercio@0 1380
tercio@0 1381 --Common Init
tercio@0 1382 if control then
tercio@0 1383 if control.width ~= "fill" then
tercio@0 1384 local width = GetOptionsMemberValue("width",v,options,path,appName)
tercio@0 1385 if width == "double" then
tercio@0 1386 control:SetWidth(width_multiplier * 2)
tercio@0 1387 elseif width == "half" then
tercio@0 1388 control:SetWidth(width_multiplier / 2)
tercio@0 1389 elseif width == "full" then
tercio@0 1390 control.width = "fill"
tercio@0 1391 else
tercio@0 1392 control:SetWidth(width_multiplier)
tercio@0 1393 end
tercio@0 1394 end
tercio@0 1395 if control.SetDisabled then
tercio@0 1396 local disabled = CheckOptionDisabled(v, options, path, appName)
tercio@0 1397 control:SetDisabled(disabled)
tercio@0 1398 end
tercio@0 1399
tercio@0 1400 InjectInfo(control, options, v, path, rootframe, appName)
tercio@0 1401 container:AddChild(control)
tercio@0 1402 end
tercio@0 1403
tercio@0 1404 end
tercio@0 1405 end
tercio@0 1406 tremove(path)
tercio@0 1407 end
tercio@0 1408 container:ResumeLayout()
tercio@0 1409 container:DoLayout()
tercio@0 1410 del(keySort)
tercio@0 1411 del(opts)
tercio@0 1412 end
tercio@0 1413
tercio@0 1414 local function BuildPath(path, ...)
tercio@0 1415 for i = 1, select("#",...) do
tercio@0 1416 tinsert(path, (select(i,...)))
tercio@0 1417 end
tercio@0 1418 end
tercio@0 1419
tercio@0 1420
tercio@0 1421 local function TreeOnButtonEnter(widget, event, uniquevalue, button)
tercio@0 1422 local user = widget:GetUserDataTable()
tercio@0 1423 if not user then return end
tercio@0 1424 local options = user.options
tercio@0 1425 local option = user.option
tercio@0 1426 local path = user.path
tercio@0 1427 local appName = user.appName
tercio@0 1428
tercio@0 1429 local feedpath = new()
tercio@0 1430 for i = 1, #path do
tercio@0 1431 feedpath[i] = path[i]
tercio@0 1432 end
tercio@0 1433
tercio@0 1434 BuildPath(feedpath, ("\001"):split(uniquevalue))
tercio@0 1435 local group = options
tercio@0 1436 for i = 1, #feedpath do
tercio@0 1437 if not group then return end
tercio@0 1438 group = GetSubOption(group, feedpath[i])
tercio@0 1439 end
tercio@0 1440
tercio@0 1441 local name = GetOptionsMemberValue("name", group, options, feedpath, appName)
tercio@0 1442 local desc = GetOptionsMemberValue("desc", group, options, feedpath, appName)
tercio@0 1443
tercio@0 1444 GameTooltip:SetOwner(button, "ANCHOR_NONE")
tercio@0 1445 if widget.type == "TabGroup" then
tercio@0 1446 GameTooltip:SetPoint("BOTTOM",button,"TOP")
tercio@0 1447 else
tercio@0 1448 GameTooltip:SetPoint("LEFT",button,"RIGHT")
tercio@0 1449 end
tercio@0 1450
tercio@0 1451 GameTooltip:SetText(name, 1, .82, 0, 1)
tercio@0 1452
tercio@0 1453 if type(desc) == "string" then
tercio@0 1454 GameTooltip:AddLine(desc, 1, 1, 1, 1)
tercio@0 1455 end
tercio@0 1456
tercio@0 1457 GameTooltip:Show()
tercio@0 1458 end
tercio@0 1459
tercio@0 1460 local function TreeOnButtonLeave(widget, event, value, button)
tercio@0 1461 GameTooltip:Hide()
tercio@0 1462 end
tercio@0 1463
tercio@0 1464
tercio@0 1465 local function GroupExists(appName, options, path, uniquevalue)
tercio@0 1466 if not uniquevalue then return false end
tercio@0 1467
tercio@0 1468 local feedpath = new()
tercio@0 1469 local temppath = new()
tercio@0 1470 for i = 1, #path do
tercio@0 1471 feedpath[i] = path[i]
tercio@0 1472 end
tercio@0 1473
tercio@0 1474 BuildPath(feedpath, ("\001"):split(uniquevalue))
tercio@0 1475
tercio@0 1476 local group = options
tercio@0 1477 for i = 1, #feedpath do
tercio@0 1478 local v = feedpath[i]
tercio@0 1479 temppath[i] = v
tercio@0 1480 group = GetSubOption(group, v)
tercio@0 1481
tercio@0 1482 if not group or group.type ~= "group" or CheckOptionHidden(group, options, temppath, appName) then
tercio@0 1483 del(feedpath)
tercio@0 1484 del(temppath)
tercio@0 1485 return false
tercio@0 1486 end
tercio@0 1487 end
tercio@0 1488 del(feedpath)
tercio@0 1489 del(temppath)
tercio@0 1490 return true
tercio@0 1491 end
tercio@0 1492
tercio@0 1493 local function GroupSelected(widget, event, uniquevalue)
tercio@0 1494
tercio@0 1495 local user = widget:GetUserDataTable()
tercio@0 1496
tercio@0 1497 local options = user.options
tercio@0 1498 local option = user.option
tercio@0 1499 local path = user.path
tercio@0 1500 local rootframe = user.rootframe
tercio@0 1501
tercio@0 1502 local feedpath = new()
tercio@0 1503 for i = 1, #path do
tercio@0 1504 feedpath[i] = path[i]
tercio@0 1505 end
tercio@0 1506
tercio@0 1507 BuildPath(feedpath, ("\001"):split(uniquevalue))
tercio@0 1508 local group = options
tercio@0 1509 for i = 1, #feedpath do
tercio@0 1510 group = GetSubOption(group, feedpath[i])
tercio@0 1511 end
tercio@0 1512 widget:ReleaseChildren()
tercio@0 1513 AceConfigDialog:FeedGroup(user.appName,options,widget,rootframe,feedpath)
tercio@0 1514
tercio@0 1515 del(feedpath)
tercio@0 1516 end
tercio@0 1517
tercio@0 1518
tercio@0 1519
tercio@0 1520 --[[
tercio@0 1521 -- INTERNAL --
tercio@0 1522 This function will feed one group, and any inline child groups into the given container
tercio@0 1523 Select Groups will only have the selection control (tree, tabs, dropdown) fed in
tercio@0 1524 and have a group selected, this event will trigger the feeding of child groups
tercio@0 1525
tercio@0 1526 Rules:
tercio@0 1527 If the group is Inline, FeedOptions
tercio@0 1528 If the group has no child groups, FeedOptions
tercio@0 1529
tercio@0 1530 If the group is a tab or select group, FeedOptions then add the Group Control
tercio@0 1531 If the group is a tree group FeedOptions then
tercio@0 1532 its parent isnt a tree group: then add the tree control containing this and all child tree groups
tercio@0 1533 if its parent is a tree group, its already a node on a tree
tercio@0 1534 --]]
tercio@0 1535
tercio@0 1536 function AceConfigDialog:FeedGroup(appName,options,container,rootframe,path, isRoot)
tercio@0 1537 local group = options
tercio@0 1538 --follow the path to get to the curent group
tercio@0 1539 local inline
tercio@0 1540 local grouptype, parenttype = options.childGroups, "none"
tercio@0 1541
tercio@0 1542
tercio@0 1543 for i = 1, #path do
tercio@0 1544 local v = path[i]
tercio@0 1545 group = GetSubOption(group, v)
tercio@0 1546 inline = inline or pickfirstset(v.dialogInline,v.guiInline,v.inline, false)
tercio@0 1547 parenttype = grouptype
tercio@0 1548 grouptype = group.childGroups
tercio@0 1549 end
tercio@0 1550
tercio@0 1551 if not parenttype then
tercio@0 1552 parenttype = "tree"
tercio@0 1553 end
tercio@0 1554
tercio@0 1555 --check if the group has child groups
tercio@0 1556 local hasChildGroups
tercio@0 1557 for k, v in pairs(group.args) do
tercio@0 1558 if v.type == "group" and not pickfirstset(v.dialogInline,v.guiInline,v.inline, false) and not CheckOptionHidden(v, options, path, appName) then
tercio@0 1559 hasChildGroups = true
tercio@0 1560 end
tercio@0 1561 end
tercio@0 1562 if group.plugins then
tercio@0 1563 for plugin, t in pairs(group.plugins) do
tercio@0 1564 for k, v in pairs(t) do
tercio@0 1565 if v.type == "group" and not pickfirstset(v.dialogInline,v.guiInline,v.inline, false) and not CheckOptionHidden(v, options, path, appName) then
tercio@0 1566 hasChildGroups = true
tercio@0 1567 end
tercio@0 1568 end
tercio@0 1569 end
tercio@0 1570 end
tercio@0 1571
tercio@0 1572 container:SetLayout("flow")
tercio@0 1573 local scroll
tercio@0 1574
tercio@0 1575 --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 1576 if (not (hasChildGroups and not inline)) or (grouptype ~= "tab" and grouptype ~= "select" and (parenttype == "tree" and not isRoot)) then
tercio@0 1577 if container.type ~= "InlineGroup" and container.type ~= "SimpleGroup" then
tercio@0 1578 scroll = gui:Create("ScrollFrame")
tercio@0 1579 scroll:SetLayout("flow")
tercio@0 1580 scroll.width = "fill"
tercio@0 1581 scroll.height = "fill"
tercio@0 1582 container:SetLayout("fill")
tercio@0 1583 container:AddChild(scroll)
tercio@0 1584 container = scroll
tercio@0 1585 end
tercio@0 1586 end
tercio@0 1587
tercio@0 1588 FeedOptions(appName,options,container,rootframe,path,group,nil)
tercio@0 1589
tercio@0 1590 if scroll then
tercio@0 1591 container:PerformLayout()
tercio@0 1592 local status = self:GetStatusTable(appName, path)
tercio@0 1593 if not status.scroll then
tercio@0 1594 status.scroll = {}
tercio@0 1595 end
tercio@0 1596 scroll:SetStatusTable(status.scroll)
tercio@0 1597 end
tercio@0 1598
tercio@0 1599 if hasChildGroups and not inline then
tercio@0 1600 local name = GetOptionsMemberValue("name", group, options, path, appName)
tercio@0 1601 if grouptype == "tab" then
tercio@0 1602
tercio@0 1603 local tab = gui:Create("TabGroup")
tercio@0 1604 InjectInfo(tab, options, group, path, rootframe, appName)
tercio@0 1605 tab:SetCallback("OnGroupSelected", GroupSelected)
tercio@0 1606 tab:SetCallback("OnTabEnter", TreeOnButtonEnter)
tercio@0 1607 tab:SetCallback("OnTabLeave", TreeOnButtonLeave)
tercio@0 1608
tercio@0 1609 local status = AceConfigDialog:GetStatusTable(appName, path)
tercio@0 1610 if not status.groups then
tercio@0 1611 status.groups = {}
tercio@0 1612 end
tercio@0 1613 tab:SetStatusTable(status.groups)
tercio@0 1614 tab.width = "fill"
tercio@0 1615 tab.height = "fill"
tercio@0 1616
tercio@0 1617 local tabs = BuildGroups(group, options, path, appName)
tercio@0 1618 tab:SetTabs(tabs)
tercio@0 1619 tab:SetUserData("tablist", tabs)
tercio@0 1620
tercio@0 1621 for i = 1, #tabs do
tercio@0 1622 local entry = tabs[i]
tercio@0 1623 if not entry.disabled then
tercio@0 1624 tab:SelectTab((GroupExists(appName, options, path,status.groups.selected) and status.groups.selected) or entry.value)
tercio@0 1625 break
tercio@0 1626 end
tercio@0 1627 end
tercio@0 1628
tercio@0 1629 container:AddChild(tab)
tercio@0 1630
tercio@0 1631 elseif grouptype == "select" then
tercio@0 1632
tercio@0 1633 local select = gui:Create("DropdownGroup")
tercio@0 1634 select:SetTitle(name)
tercio@0 1635 InjectInfo(select, options, group, path, rootframe, appName)
tercio@0 1636 select:SetCallback("OnGroupSelected", GroupSelected)
tercio@0 1637 local status = AceConfigDialog:GetStatusTable(appName, path)
tercio@0 1638 if not status.groups then
tercio@0 1639 status.groups = {}
tercio@0 1640 end
tercio@0 1641 select:SetStatusTable(status.groups)
tercio@0 1642 local grouplist, orderlist = BuildSelect(group, options, path, appName)
tercio@0 1643 select:SetGroupList(grouplist, orderlist)
tercio@0 1644 select:SetUserData("grouplist", grouplist)
tercio@0 1645 select:SetUserData("orderlist", orderlist)
tercio@0 1646
tercio@0 1647 local firstgroup = orderlist[1]
tercio@0 1648 if firstgroup then
tercio@0 1649 select:SetGroup((GroupExists(appName, options, path,status.groups.selected) and status.groups.selected) or firstgroup)
tercio@0 1650 end
tercio@0 1651
tercio@0 1652 select.width = "fill"
tercio@0 1653 select.height = "fill"
tercio@0 1654
tercio@0 1655 container:AddChild(select)
tercio@0 1656
tercio@0 1657 --assume tree group by default
tercio@0 1658 --if parenttype is tree then this group is already a node on that tree
tercio@0 1659 elseif (parenttype ~= "tree") or isRoot then
tercio@0 1660 local tree = gui:Create("TreeGroup")
tercio@0 1661 InjectInfo(tree, options, group, path, rootframe, appName)
tercio@0 1662 tree:EnableButtonTooltips(false)
tercio@0 1663
tercio@0 1664 tree.width = "fill"
tercio@0 1665 tree.height = "fill"
tercio@0 1666
tercio@0 1667 tree:SetCallback("OnGroupSelected", GroupSelected)
tercio@0 1668 tree:SetCallback("OnButtonEnter", TreeOnButtonEnter)
tercio@0 1669 tree:SetCallback("OnButtonLeave", TreeOnButtonLeave)
tercio@0 1670
tercio@0 1671 local status = AceConfigDialog:GetStatusTable(appName, path)
tercio@0 1672 if not status.groups then
tercio@0 1673 status.groups = {}
tercio@0 1674 end
tercio@0 1675 local treedefinition = BuildGroups(group, options, path, appName, true)
tercio@0 1676 tree:SetStatusTable(status.groups)
tercio@0 1677
tercio@0 1678 tree:SetTree(treedefinition)
tercio@0 1679 tree:SetUserData("tree",treedefinition)
tercio@0 1680
tercio@0 1681 for i = 1, #treedefinition do
tercio@0 1682 local entry = treedefinition[i]
tercio@0 1683 if not entry.disabled then
tercio@0 1684 tree:SelectByValue((GroupExists(appName, options, path,status.groups.selected) and status.groups.selected) or entry.value)
tercio@0 1685 break
tercio@0 1686 end
tercio@0 1687 end
tercio@0 1688
tercio@0 1689 container:AddChild(tree)
tercio@0 1690 end
tercio@0 1691 end
tercio@0 1692 end
tercio@0 1693
tercio@0 1694 local old_CloseSpecialWindows
tercio@0 1695
tercio@0 1696
tercio@0 1697 local function RefreshOnUpdate(this)
tercio@0 1698 for appName in pairs(this.closing) do
tercio@0 1699 if AceConfigDialog.OpenFrames[appName] then
tercio@0 1700 AceConfigDialog.OpenFrames[appName]:Hide()
tercio@0 1701 end
tercio@0 1702 if AceConfigDialog.BlizOptions and AceConfigDialog.BlizOptions[appName] then
tercio@0 1703 for key, widget in pairs(AceConfigDialog.BlizOptions[appName]) do
tercio@0 1704 if not widget:IsVisible() then
tercio@0 1705 widget:ReleaseChildren()
tercio@0 1706 end
tercio@0 1707 end
tercio@0 1708 end
tercio@0 1709 this.closing[appName] = nil
tercio@0 1710 end
tercio@0 1711
tercio@0 1712 if this.closeAll then
tercio@0 1713 for k, v in pairs(AceConfigDialog.OpenFrames) do
tercio@0 1714 if not this.closeAllOverride[k] then
tercio@0 1715 v:Hide()
tercio@0 1716 end
tercio@0 1717 end
tercio@0 1718 this.closeAll = nil
tercio@0 1719 wipe(this.closeAllOverride)
tercio@0 1720 end
tercio@0 1721
tercio@0 1722 for appName in pairs(this.apps) do
tercio@0 1723 if AceConfigDialog.OpenFrames[appName] then
tercio@0 1724 local user = AceConfigDialog.OpenFrames[appName]:GetUserDataTable()
tercio@0 1725 AceConfigDialog:Open(appName, unpack(user.basepath or emptyTbl))
tercio@0 1726 end
tercio@0 1727 if AceConfigDialog.BlizOptions and AceConfigDialog.BlizOptions[appName] then
tercio@0 1728 for key, widget in pairs(AceConfigDialog.BlizOptions[appName]) do
tercio@0 1729 local user = widget:GetUserDataTable()
tercio@0 1730 if widget:IsVisible() then
tercio@0 1731 AceConfigDialog:Open(widget:GetUserData("appName"), widget, unpack(user.basepath or emptyTbl))
tercio@0 1732 end
tercio@0 1733 end
tercio@0 1734 end
tercio@0 1735 this.apps[appName] = nil
tercio@0 1736 end
tercio@0 1737 this:SetScript("OnUpdate", nil)
tercio@0 1738 end
tercio@0 1739
tercio@0 1740 -- Upgrade the OnUpdate script as well, if needed.
tercio@0 1741 if AceConfigDialog.frame:GetScript("OnUpdate") then
tercio@0 1742 AceConfigDialog.frame:SetScript("OnUpdate", RefreshOnUpdate)
tercio@0 1743 end
tercio@0 1744
tercio@0 1745 --- Close all open options windows
tercio@0 1746 function AceConfigDialog:CloseAll()
tercio@0 1747 AceConfigDialog.frame.closeAll = true
tercio@0 1748 AceConfigDialog.frame:SetScript("OnUpdate", RefreshOnUpdate)
tercio@0 1749 if next(self.OpenFrames) then
tercio@0 1750 return true
tercio@0 1751 end
tercio@0 1752 end
tercio@0 1753
tercio@0 1754 --- Close a specific options window.
tercio@0 1755 -- @param appName The application name as given to `:RegisterOptionsTable()`
tercio@0 1756 function AceConfigDialog:Close(appName)
tercio@0 1757 if self.OpenFrames[appName] then
tercio@0 1758 AceConfigDialog.frame.closing[appName] = true
tercio@0 1759 AceConfigDialog.frame:SetScript("OnUpdate", RefreshOnUpdate)
tercio@0 1760 return true
tercio@0 1761 end
tercio@0 1762 end
tercio@0 1763
tercio@0 1764 -- Internal -- Called by AceConfigRegistry
tercio@0 1765 function AceConfigDialog:ConfigTableChanged(event, appName)
tercio@0 1766 AceConfigDialog.frame.apps[appName] = true
tercio@0 1767 AceConfigDialog.frame:SetScript("OnUpdate", RefreshOnUpdate)
tercio@0 1768 end
tercio@0 1769
tercio@0 1770 reg.RegisterCallback(AceConfigDialog, "ConfigTableChange", "ConfigTableChanged")
tercio@0 1771
tercio@0 1772 --- Sets the default size of the options window for a specific application.
tercio@0 1773 -- @param appName The application name as given to `:RegisterOptionsTable()`
tercio@0 1774 -- @param width The default width
tercio@0 1775 -- @param height The default height
tercio@0 1776 function AceConfigDialog:SetDefaultSize(appName, width, height)
tercio@0 1777 local status = AceConfigDialog:GetStatusTable(appName)
tercio@0 1778 if type(width) == "number" and type(height) == "number" then
tercio@0 1779 status.width = width
tercio@0 1780 status.height = height
tercio@0 1781 end
tercio@0 1782 end
tercio@0 1783
tercio@0 1784 --- Open an option window at the specified path (if any).
tercio@0 1785 -- This function can optionally feed the group into a pre-created container
tercio@0 1786 -- instead of creating a new container frame.
tercio@0 1787 -- @paramsig appName [, container][, ...]
tercio@0 1788 -- @param appName The application name as given to `:RegisterOptionsTable()`
tercio@0 1789 -- @param container An optional container frame to feed the options into
tercio@0 1790 -- @param ... The path to open after creating the options window (see `:SelectGroup` for details)
tercio@0 1791 function AceConfigDialog:Open(appName, container, ...)
tercio@0 1792 if not old_CloseSpecialWindows then
tercio@0 1793 old_CloseSpecialWindows = CloseSpecialWindows
tercio@0 1794 CloseSpecialWindows = function()
tercio@0 1795 local found = old_CloseSpecialWindows()
tercio@0 1796 return self:CloseAll() or found
tercio@0 1797 end
tercio@0 1798 end
tercio@0 1799 local app = reg:GetOptionsTable(appName)
tercio@0 1800 if not app then
tercio@0 1801 error(("%s isn't registed with AceConfigRegistry, unable to open config"):format(appName), 2)
tercio@0 1802 end
tercio@0 1803 local options = app("dialog", MAJOR)
tercio@0 1804
tercio@0 1805 local f
tercio@0 1806
tercio@0 1807 local path = new()
tercio@0 1808 local name = GetOptionsMemberValue("name", options, options, path, appName)
tercio@0 1809
tercio@0 1810 --If an optional path is specified add it to the path table before feeding the options
tercio@0 1811 --as container is optional as well it may contain the first element of the path
tercio@0 1812 if type(container) == "string" then
tercio@0 1813 tinsert(path, container)
tercio@0 1814 container = nil
tercio@0 1815 end
tercio@0 1816 for n = 1, select("#",...) do
tercio@0 1817 tinsert(path, (select(n, ...)))
tercio@0 1818 end
tercio@0 1819
tercio@0 1820 --if a container is given feed into that
tercio@0 1821 if container then
tercio@0 1822 f = container
tercio@0 1823 f:ReleaseChildren()
tercio@0 1824 f:SetUserData("appName", appName)
tercio@0 1825 f:SetUserData("iscustom", true)
tercio@0 1826 if #path > 0 then
tercio@0 1827 f:SetUserData("basepath", copy(path))
tercio@0 1828 end
tercio@0 1829 local status = AceConfigDialog:GetStatusTable(appName)
tercio@0 1830 if not status.width then
tercio@0 1831 status.width = 700
tercio@0 1832 end
tercio@0 1833 if not status.height then
tercio@0 1834 status.height = 500
tercio@0 1835 end
tercio@0 1836 if f.SetStatusTable then
tercio@0 1837 f:SetStatusTable(status)
tercio@0 1838 end
tercio@0 1839 if f.SetTitle then
tercio@0 1840 f:SetTitle(name or "")
tercio@0 1841 end
tercio@0 1842 else
tercio@0 1843 if not self.OpenFrames[appName] then
tercio@0 1844 f = gui:Create("Frame")
tercio@0 1845 self.OpenFrames[appName] = f
tercio@0 1846 else
tercio@0 1847 f = self.OpenFrames[appName]
tercio@0 1848 end
tercio@0 1849 f:ReleaseChildren()
tercio@0 1850 f:SetCallback("OnClose", FrameOnClose)
tercio@0 1851 f:SetUserData("appName", appName)
tercio@0 1852 if #path > 0 then
tercio@0 1853 f:SetUserData("basepath", copy(path))
tercio@0 1854 end
tercio@0 1855 f:SetTitle(name or "")
tercio@0 1856 local status = AceConfigDialog:GetStatusTable(appName)
tercio@0 1857 f:SetStatusTable(status)
tercio@0 1858 end
tercio@0 1859
tercio@0 1860 self:FeedGroup(appName,options,f,f,path,true)
tercio@0 1861 if f.Show then
tercio@0 1862 f:Show()
tercio@0 1863 end
tercio@0 1864 del(path)
tercio@0 1865
tercio@0 1866 if AceConfigDialog.frame.closeAll then
tercio@0 1867 -- close all is set, but thats not good, since we're just opening here, so force it
tercio@0 1868 AceConfigDialog.frame.closeAllOverride[appName] = true
tercio@0 1869 end
tercio@0 1870 end
tercio@0 1871
tercio@0 1872 -- convert pre-39 BlizOptions structure to the new format
tercio@0 1873 if oldminor and oldminor < 39 and AceConfigDialog.BlizOptions then
tercio@0 1874 local old = AceConfigDialog.BlizOptions
tercio@0 1875 local new = {}
tercio@0 1876 for key, widget in pairs(old) do
tercio@0 1877 local appName = widget:GetUserData("appName")
tercio@0 1878 if not new[appName] then new[appName] = {} end
tercio@0 1879 new[appName][key] = widget
tercio@0 1880 end
tercio@0 1881 AceConfigDialog.BlizOptions = new
tercio@0 1882 else
tercio@0 1883 AceConfigDialog.BlizOptions = AceConfigDialog.BlizOptions or {}
tercio@0 1884 end
tercio@0 1885
tercio@0 1886 local function FeedToBlizPanel(widget, event)
tercio@0 1887 local path = widget:GetUserData("path")
tercio@0 1888 AceConfigDialog:Open(widget:GetUserData("appName"), widget, unpack(path or emptyTbl))
tercio@0 1889 end
tercio@0 1890
tercio@0 1891 local function ClearBlizPanel(widget, event)
tercio@0 1892 local appName = widget:GetUserData("appName")
tercio@0 1893 AceConfigDialog.frame.closing[appName] = true
tercio@0 1894 AceConfigDialog.frame:SetScript("OnUpdate", RefreshOnUpdate)
tercio@0 1895 end
tercio@0 1896
tercio@0 1897 --- Add an option table into the Blizzard Interface Options panel.
tercio@0 1898 -- You can optionally supply a descriptive name to use and a parent frame to use,
tercio@0 1899 -- as well as a path in the options table.\\
tercio@0 1900 -- If no name is specified, the appName will be used instead.
tercio@0 1901 --
tercio@0 1902 -- If you specify a proper `parent` (by name), the interface options will generate a
tercio@0 1903 -- tree layout. Note that only one level of children is supported, so the parent always
tercio@0 1904 -- has to be a head-level note.
tercio@0 1905 --
tercio@0 1906 -- This function returns a reference to the container frame registered with the Interface
tercio@0 1907 -- Options. You can use this reference to open the options with the API function
tercio@0 1908 -- `InterfaceOptionsFrame_OpenToCategory`.
tercio@0 1909 -- @param appName The application name as given to `:RegisterOptionsTable()`
tercio@0 1910 -- @param name A descriptive name to display in the options tree (defaults to appName)
tercio@0 1911 -- @param parent The parent to use in the interface options tree.
tercio@0 1912 -- @param ... The path in the options table to feed into the interface options panel.
tercio@0 1913 -- @return The reference to the frame registered into the Interface Options.
tercio@0 1914 function AceConfigDialog:AddToBlizOptions(appName, name, parent, ...)
tercio@0 1915 local BlizOptions = AceConfigDialog.BlizOptions
tercio@0 1916
tercio@0 1917 local key = appName
tercio@0 1918 for n = 1, select("#", ...) do
tercio@0 1919 key = key.."\001"..select(n, ...)
tercio@0 1920 end
tercio@0 1921
tercio@0 1922 if not BlizOptions[appName] then
tercio@0 1923 BlizOptions[appName] = {}
tercio@0 1924 end
tercio@0 1925
tercio@0 1926 if not BlizOptions[appName][key] then
tercio@0 1927 local group = gui:Create("BlizOptionsGroup")
tercio@0 1928 BlizOptions[appName][key] = group
tercio@0 1929 group:SetName(name or appName, parent)
tercio@0 1930
tercio@0 1931 group:SetTitle(name or appName)
tercio@0 1932 group:SetUserData("appName", appName)
tercio@0 1933 if select("#", ...) > 0 then
tercio@0 1934 local path = {}
tercio@0 1935 for n = 1, select("#",...) do
tercio@0 1936 tinsert(path, (select(n, ...)))
tercio@0 1937 end
tercio@0 1938 group:SetUserData("path", path)
tercio@0 1939 end
tercio@0 1940 group:SetCallback("OnShow", FeedToBlizPanel)
tercio@0 1941 group:SetCallback("OnHide", ClearBlizPanel)
tercio@0 1942 InterfaceOptions_AddCategory(group.frame)
tercio@0 1943 return group.frame
tercio@0 1944 else
tercio@0 1945 error(("%s has already been added to the Blizzard Options Window with the given path"):format(appName), 2)
tercio@0 1946 end
tercio@0 1947 end