Mercurial > wow > reaction
comparison modules/ReAction_ConfigUI/ReAction_ConfigUI.lua @ 28:21bcaf8215ff
- converted to Ace3
- rearranged file layout
- configGUI menus not working right now
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Mon, 17 Mar 2008 18:24:53 +0000 |
parents | bf997ea151ca |
children | 0d95ce7a9ec2 |
comparison
equal
deleted
inserted
replaced
27:f1e838841ce1 | 28:21bcaf8215ff |
---|---|
28 local _G = _G | 28 local _G = _G |
29 local Waterfall = AceLibrary("Waterfall-1.0") | 29 local Waterfall = AceLibrary("Waterfall-1.0") |
30 local Dewdrop = AceLibrary("Dewdrop-2.0") | 30 local Dewdrop = AceLibrary("Dewdrop-2.0") |
31 local print = ReAction.print | 31 local print = ReAction.print |
32 local InCombatLockdown = InCombatLockdown | 32 local InCombatLockdown = InCombatLockdown |
33 local BarModule = ReAction:GetModule("Bar") | |
34 | 33 |
35 -- module declaration | 34 -- module declaration |
36 local moduleID = "ConfigUI" | 35 local moduleID = "ConfigUI" |
37 local module = ReAction:NewModule( moduleID, | 36 local module = ReAction:NewModule( moduleID, |
38 "AceConsole-2.0", -- temp | 37 "AceEvent-3.0" |
39 "AceEvent-2.0" | |
40 -- mixins go here | 38 -- mixins go here |
41 ) | 39 ) |
42 | 40 |
43 module.globalOptions = { | 41 module.globalOptions = { |
44 type = "group", | 42 type = "group", |
95 } | 93 } |
96 } | 94 } |
97 | 95 |
98 -- module methods | 96 -- module methods |
99 function module:OnInitialize() | 97 function module:OnInitialize() |
100 self.db = ReAction:AcquireDBNamespace(moduleID) | 98 self.db = ReAction.db:RegisterNamespace( moduleID, |
101 ReAction:RegisterDefaults(moduleID,"profile", | |
102 { | 99 { |
103 | 100 profile = { } |
104 } | 101 } |
105 ) | 102 ) |
106 | |
107 -- temp: this will be moved to main ReAction.lua later in a more efficient AceConsole-less implementation | |
108 -- that can load the ConfigUI module on demand | |
109 -- NOTE: this inserts an 'about' command that we don't want | |
110 self:RegisterChatCommand( {L["/reaction"], L["/rxn"]}, self.globalOptions, "REACTION" ) | |
111 end | 103 end |
112 | 104 |
113 function module:OnEnable() | 105 function module:OnEnable() |
114 self:RegisterEvent("PLAYER_REGEN_DISABLED") | 106 self:RegisterEvent("PLAYER_REGEN_DISABLED") |
115 Waterfall:Register("ReAction", | 107 Waterfall:Register("ReAction", |
134 Waterfall:Close("ReAction") | 126 Waterfall:Close("ReAction") |
135 end | 127 end |
136 end | 128 end |
137 | 129 |
138 function module:SetConfigMode( mode ) | 130 function module:SetConfigMode( mode ) |
139 BarModule:CallMethodOnAllBars("ShowControls",mode) | 131 ReAction:CallMethodOnAllBars("ShowControls",mode) |
140 ReAction:CallMethodOnAllModules("ApplyConfigMode",mode,BarModule.bars) | 132 ReAction:CallMethodOnAllModules("ApplyConfigMode",mode,ReAction.bars) |
141 self.configMode = mode | 133 self.configMode = mode |
142 end | 134 end |
143 | 135 |
144 function module:ApplyConfigMode( mode, bars ) | 136 function module:ApplyConfigMode( mode, bars ) |
145 if not(mode) then | 137 if not(mode) then |
159 | 151 |
160 local function refreshWaterfall() | 152 local function refreshWaterfall() |
161 module:RefreshConfig() | 153 module:RefreshConfig() |
162 end | 154 end |
163 | 155 |
156 local function SafeCall(module, method, ...) | |
157 if module and type(module[method]) == "function" then | |
158 return module[method](...) | |
159 end | |
160 end | |
161 | |
164 function module:RefreshOptions() | 162 function module:RefreshOptions() |
165 local opts = self.configOptions.args | 163 local opts = self.configOptions.args |
166 | 164 |
167 for _, m in ReAction:IterateModulesWithMethod("GetGlobalOptions") do | 165 for _, m in ReAction:IterateModules() do |
168 local o = m:GetGlobalOptions(self) | 166 local o = SafeCall(m,"GetGlobalOptions",self) |
169 if o then | 167 if o then |
170 for k, v in pairs(o) do | 168 for k, v in pairs(o) do |
171 opts.global.args[k] = v | 169 opts.global.args[k] = v |
172 end | 170 end |
173 end | 171 end |
174 end | 172 end |
175 | 173 |
176 for _, m in ReAction:IterateModulesWithMethod("GetGlobalBarOptions") do | 174 for _, m in ReAction:IterateModules() do |
177 local o = m:GetGlobalBarOptions(self) | 175 local o = SafeCall(m,"GetGlobalBarOptions",self) |
178 if o then | 176 if o then |
179 for k, v in pairs(o) do | 177 for k, v in pairs(o) do |
180 opts.bar.args[k] = v | 178 opts.bar.args[k] = v |
181 end | 179 end |
182 end | 180 end |
183 end | 181 end |
184 | 182 |
185 for _, m in ReAction:IterateModulesWithMethod("GetModuleOptions") do | 183 for _, m in ReAction:IterateModules() do |
186 local o = m:GetModuleOptions(self) | 184 local o = SafeCall(m,"GetModuleOptions",self) |
187 if o then | 185 if o then |
188 for k, v in pairs(o) do | 186 for k, v in pairs(o) do |
189 opts.module.args[k] = v | 187 opts.module.args[k] = v |
190 end | 188 end |
191 end | 189 end |
192 end | 190 end |
193 | 191 |
194 local barOpts = opts.bar.args | 192 local barOpts = opts.bar.args |
195 for name, bar in pairs(BarModule.bars) do | 193 for name, bar in pairs(ReAction.bars) do |
196 if bar then | 194 if bar then |
197 if barOpts[name] == nil then | 195 if barOpts[name] == nil then |
198 barOpts[name] = { | 196 barOpts[name] = { |
199 type = "group", | 197 type = "group", |
200 name = name, | 198 name = name, |
201 desc = name, | 199 desc = name, |
202 handler = bar, | 200 handler = bar, |
203 args = { } | 201 args = { |
202 delete = { | |
203 type = "execute", | |
204 name = L["Delete Bar"], | |
205 desc = L["Remove the bar from the current profile"], | |
206 func = function() ReAction:EraseBar(bar); self:RefreshConfig() end | |
207 }, | |
208 rename = { | |
209 type = "text", | |
210 name = L["Rename Bar"], | |
211 desc = L["Set a name for the bar"], | |
212 get = "GetName", | |
213 set = function(name) ReAction:RenameBar(bar,name); self:RefreshConfig() end | |
214 } | |
215 } | |
204 } | 216 } |
205 end | 217 end |
206 if bar.modConfigOpts == nil then | 218 if bar.modConfigOpts == nil then |
207 bar.modConfigOpts = { } | 219 bar.modConfigOpts = { } |
208 end | 220 end |
209 for _, m in ReAction:IterateModulesWithMethod("GetBarConfigOptions") do | 221 for _, m in ReAction:IterateModules() do |
210 local o = m:GetBarConfigOptions(bar,self) | 222 local o = SafeCall(m,"GetBarConfigOptions",bar,self) |
211 if o then | 223 if o then |
212 for k, v in pairs(o) do | 224 for k, v in pairs(o) do |
213 barOpts[name].args[k] = v | 225 barOpts[name].args[k] = v |
214 end | 226 end |
215 end | 227 end |
216 end | 228 end |
217 end | 229 end |
218 end | 230 end |
219 -- remove obsolete bar tables | 231 -- remove obsolete bar tables |
220 for name, opt in pairs(barOpts) do | 232 for name, opt in pairs(barOpts) do |
221 if opt.type == "group" and BarModule.bars[name] == nil then | 233 if opt.type == "group" and ReAction.bars[name] == nil then |
222 barOpts[name] = nil | 234 barOpts[name] = nil |
223 end | 235 end |
224 end | 236 end |
225 end | 237 end |
226 | 238 |
260 | 272 |
261 -- | 273 -- |
262 -- Bar config overlay | 274 -- Bar config overlay |
263 -- | 275 -- |
264 -- import some of these for small OnUpdate performance boost | 276 -- import some of these for small OnUpdate performance boost |
265 local Bar = BarModule.BarClass.prototype | 277 local Bar = ReAction.Bar.prototype |
266 local GetSize = Bar.GetSize | 278 local GetSize = Bar.GetSize |
267 local GetButtonSize = Bar.GetButtonSize | 279 local GetButtonSize = Bar.GetButtonSize |
268 local GetButtonGrid = Bar.GetButtonGrid | 280 local GetButtonGrid = Bar.GetButtonGrid |
269 local SetSize = Bar.SetSize | 281 local SetSize = Bar.SetSize |
270 local SetButtonSize = Bar.SetButtonSize | 282 local SetButtonSize = Bar.SetButtonSize |
278 local function StoreExtents(bar) | 290 local function StoreExtents(bar) |
279 local f = bar.frame | 291 local f = bar.frame |
280 local point, relativeTo, relativePoint, x, y = f:GetPoint(1) | 292 local point, relativeTo, relativePoint, x, y = f:GetPoint(1) |
281 relativeTo = relativeTo or f:GetParent() | 293 relativeTo = relativeTo or f:GetParent() |
282 local anchorTo | 294 local anchorTo |
283 for name, b in pairs(BarModule.bars) do | 295 for name, b in pairs(ReAction.bars) do |
284 if b then | 296 if b then |
285 if b:GetFrame() == relativeTo then | 297 if b:GetFrame() == relativeTo then |
286 anchorTo = name | 298 anchorTo = name |
287 break | 299 break |
288 end | 300 end |
532 | 544 |
533 control:SetScript("OnEnter", | 545 control:SetScript("OnEnter", |
534 function() | 546 function() |
535 -- add bar type and status information to name | 547 -- add bar type and status information to name |
536 local name = bar.name | 548 local name = bar.name |
537 for _, m in ReAction:IterateModulesWithMethod("GetBarNameModifier") do | 549 for _, m in ReAction:IterateModules() do |
538 local suffix = m:GetBarNameModifier(bar) | 550 local suffix = SafeCall(m,"GetBarNameModifier",bar) |
539 if suffix then | 551 if suffix then |
540 name = format("%s %s",name,suffix) | 552 name = format("%s %s",name,suffix) |
541 end | 553 end |
542 end | 554 end |
543 | 555 |
582 name = L["Configure..."], | 594 name = L["Configure..."], |
583 desc = L["Open the configuration dialogue for this bar"], | 595 desc = L["Open the configuration dialogue for this bar"], |
584 func = function() module:OpenConfig(self) end, | 596 func = function() module:OpenConfig(self) end, |
585 disabled = InCombatLockdown, | 597 disabled = InCombatLockdown, |
586 order = 1 | 598 order = 1 |
587 } | 599 }, |
600 delete = { | |
601 type = "execute", | |
602 name = L["Delete Bar"], | |
603 desc = L["Remove the bar from the current profile"], | |
604 func = function() ReAction:EraseBar(self) end, | |
605 order = 2 | |
606 }, | |
588 } | 607 } |
589 } | 608 } |
590 end | 609 end |
591 if self.modMenuOpts == nil then | 610 if self.modMenuOpts == nil then |
592 self.modMenuOpts = { } | 611 self.modMenuOpts = { } |
593 end | 612 end |
594 for _, m in ReAction:IterateModulesWithMethod("GetBarMenuOptions") do | 613 for _, m in ReAction:IterateModules() do |
595 for k, v in pairs(m:GetBarMenuOptions(self, module)) do | 614 local opts = SafeCall(m,"GetBarMenuOptions",self,module) |
596 self.menuOpts.args[k] = v | 615 if opts then |
616 for k, v in pairs(opts) do | |
617 self.menuOpts.args[k] = v | |
618 end | |
597 end | 619 end |
598 end | 620 end |
599 Dewdrop:Open(self.controlFrame, "children", self.menuOpts, "cursorX", true, "cursorY", true) | 621 Dewdrop:Open(self.controlFrame, "children", self.menuOpts, "cursorX", true, "cursorY", true) |
600 end | 622 end |
601 | 623 |