Mercurial > wow > reaction
comparison 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 |
comparison
equal
deleted
inserted
replaced
58:20003239af0b | 59:7430a8dd4e90 |
---|---|
48 ReAction.RegisterCallback(self,"OnRenameBar") | 48 ReAction.RegisterCallback(self,"OnRenameBar") |
49 self:InitializeOptions() | 49 self:InitializeOptions() |
50 self:RegisterEvent("PLAYER_REGEN_DISABLED") | 50 self:RegisterEvent("PLAYER_REGEN_DISABLED") |
51 end | 51 end |
52 | 52 |
53 | |
54 -- Creates a dispatcher to act as a handler and translate method calls from | |
55 -- handler:method(info,value) to module:method(bar,value). If the opts table has | |
56 -- a handler set, that will be used instead of module. | |
57 -- Note: we replace the top level table if it's a group, giving it a new handler. | |
58 local function CreateModuleBarDispatcher(module,bar,opts) | |
59 local g = { } | |
60 if opts.type == "group" then | |
61 for k,v in pairs(opts) do | |
62 g[k] = v | |
63 end | |
64 else | |
65 g.type = "group" | |
66 g.name = module:GetName() | |
67 g.args = { | |
68 arg1 = opts | |
69 } | |
70 end | |
71 local handler = opts.handler or module | |
72 g.handler = setmetatable( {}, { | |
73 __index = function(self, idx) | |
74 local f = rawget(self,idx) | |
75 if not f then | |
76 f = function(_, info, ...) | |
77 return handler[idx](handler, bar, ...) | |
78 end | |
79 rawset(self,idx,f) -- cache for future use | |
80 end | |
81 return f | |
82 end | |
83 }) | |
84 return g | |
85 end | |
86 | |
87 | |
53 function module:OnOptionsRegistered(evt, context, module, opts) | 88 function module:OnOptionsRegistered(evt, context, module, opts) |
54 local c = self.configOptions.args[context] | 89 local c = self.configOptions.args[context] |
55 if c then | 90 if context == "bar" then |
91 for name,bar in pairs(ReAction.bars) do | |
92 local key = self.barOptMap[name] | |
93 if key then | |
94 self.editorOpts.args[key].plugins[module:GetName()] = { [module:GetName()] = CreateModuleBarDispatcher(module,bar,opts) } | |
95 end | |
96 end | |
97 elseif c then | |
56 for k, v in pairs(opts) do | 98 for k, v in pairs(opts) do |
57 c.args[k] = v | 99 c.args[k] = v |
58 end | 100 end |
59 elseif c == "bar" then | |
60 | |
61 end | 101 end |
62 end | 102 end |
63 | 103 |
64 function module:OnOptionsRefreshed(evt) | 104 function module:OnOptionsRefreshed(evt) |
65 AceConfigReg:NotifyChange("ReAction") | 105 AceConfigReg:NotifyChange("ReAction") |
68 | 108 |
69 function module:OnCreateBar(evt, bar) | 109 function module:OnCreateBar(evt, bar) |
70 local name = bar:GetName() | 110 local name = bar:GetName() |
71 -- AceConfig doesn't allow spaces, etc, in arg key names, and they must be | 111 -- AceConfig doesn't allow spaces, etc, in arg key names, and they must be |
72 -- unique strings. So generate a unique key (it can be whatever) for the bar | 112 -- unique strings. So generate a unique key (it can be whatever) for the bar |
113 local args = self.editorOpts.args | |
73 local key | 114 local key |
74 local i = 1 | 115 local i = 1 |
75 repeat | 116 repeat |
76 key = ("bar%s"):format(i) | 117 key = ("bar%s"):format(i) |
77 i = i+1 | 118 i = i+1 |
78 until self.editorOpts.args[key] == nil | 119 until args[key] == nil |
79 self.barOptMap[name] = key | 120 self.barOptMap[name] = key |
80 self.editorOpts.args[key] = { | 121 args[key] = { |
81 type = "group", | 122 type = "group", |
82 name = name, | 123 name = name, |
83 childGroups = "tab", | 124 childGroups = "tab", |
84 args = { | 125 args = { |
85 general = { | 126 general = { |
86 type = "group", | 127 type = "group", |
87 name = L["General"], | 128 name = L["General"], |
129 order = 1, | |
88 args = { | 130 args = { |
89 name = { | 131 name = { |
90 type = "input", | 132 type = "input", |
91 name = L["Rename Bar"], | 133 name = L["Rename Bar"], |
92 get = function() return bar:GetName() end, | 134 get = function() return bar:GetName() end, |
169 order = 3 | 211 order = 3 |
170 }, | 212 }, |
171 }, | 213 }, |
172 }, | 214 }, |
173 }, | 215 }, |
174 | 216 plugins = { }, |
175 } | 217 } |
218 | |
219 -- Create a dispatcher for all the module options tables registered to ReAction under the 'bar' context | |
220 for module, opts in pairs(ReAction:GetOptions("bar")) do | |
221 args[key].plugins[module:GetName()] = { [module:GetName()] = CreateModuleBarDispatcher(module, bar, opts) } | |
222 end | |
176 end | 223 end |
177 | 224 |
178 function module:OnEraseBar(evt, name) | 225 function module:OnEraseBar(evt, name) |
179 local key = self.barOptMap[name] | 226 local key = self.barOptMap[name] |
180 self.barOptMap[name] = nil | 227 self.barOptMap[name] = nil |