Mercurial > wow > reaction
diff modules/ReAction_ConfigUI/ReAction_ConfigUI.lua @ 59:7430a8dd4e90
Added modular per-bar options
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Mon, 28 Apr 2008 23:34:17 +0000 |
parents | 20003239af0b |
children | 44649a10378d |
line wrap: on
line diff
--- a/modules/ReAction_ConfigUI/ReAction_ConfigUI.lua Mon Apr 28 21:08:35 2008 +0000 +++ b/modules/ReAction_ConfigUI/ReAction_ConfigUI.lua Mon Apr 28 23:34:17 2008 +0000 @@ -50,14 +50,54 @@ self:RegisterEvent("PLAYER_REGEN_DISABLED") end + +-- Creates a dispatcher to act as a handler and translate method calls from +-- handler:method(info,value) to module:method(bar,value). If the opts table has +-- a handler set, that will be used instead of module. +-- Note: we replace the top level table if it's a group, giving it a new handler. +local function CreateModuleBarDispatcher(module,bar,opts) + local g = { } + if opts.type == "group" then + for k,v in pairs(opts) do + g[k] = v + end + else + g.type = "group" + g.name = module:GetName() + g.args = { + arg1 = opts + } + end + local handler = opts.handler or module + g.handler = setmetatable( {}, { + __index = function(self, idx) + local f = rawget(self,idx) + if not f then + f = function(_, info, ...) + return handler[idx](handler, bar, ...) + end + rawset(self,idx,f) -- cache for future use + end + return f + end + }) + return g +end + + function module:OnOptionsRegistered(evt, context, module, opts) local c = self.configOptions.args[context] - if c then + if context == "bar" then + for name,bar in pairs(ReAction.bars) do + local key = self.barOptMap[name] + if key then + self.editorOpts.args[key].plugins[module:GetName()] = { [module:GetName()] = CreateModuleBarDispatcher(module,bar,opts) } + end + end + elseif c then for k, v in pairs(opts) do c.args[k] = v end - elseif c == "bar" then - end end @@ -70,14 +110,15 @@ local name = bar:GetName() -- AceConfig doesn't allow spaces, etc, in arg key names, and they must be -- unique strings. So generate a unique key (it can be whatever) for the bar + local args = self.editorOpts.args local key local i = 1 repeat key = ("bar%s"):format(i) i = i+1 - until self.editorOpts.args[key] == nil + until args[key] == nil self.barOptMap[name] = key - self.editorOpts.args[key] = { + args[key] = { type = "group", name = name, childGroups = "tab", @@ -85,6 +126,7 @@ general = { type = "group", name = L["General"], + order = 1, args = { name = { type = "input", @@ -171,8 +213,13 @@ }, }, }, + plugins = { }, + } - } + -- Create a dispatcher for all the module options tables registered to ReAction under the 'bar' context + for module, opts in pairs(ReAction:GetOptions("bar")) do + args[key].plugins[module:GetName()] = { [module:GetName()] = CreateModuleBarDispatcher(module, bar, opts) } + end end function module:OnEraseBar(evt, name)