comparison modules/ReAction_ConfigUI/ReAction_ConfigUI.lua @ 63:768be7eb22a0

Converted several ReAction APIs to event-driven model instead of 'call-method-on-all-modules' model. Cleaned up a number of other architectural issues.
author Flick <flickerstreak@gmail.com>
date Thu, 22 May 2008 22:02:08 +0000
parents 2ee41dcd673f
children c8c8610fd864
comparison
equal deleted inserted replaced
62:f9cdb920470a 63:768be7eb22a0
83 AceConfigReg:RegisterOptionsTable(configName,ReAction.options) 83 AceConfigReg:RegisterOptionsTable(configName,ReAction.options)
84 self.frame = AceConfigDialog:AddToBlizOptions(configName, configName) 84 self.frame = AceConfigDialog:AddToBlizOptions(configName, configName)
85 self.frame.obj:SetCallback("default", 85 self.frame.obj:SetCallback("default",
86 function() 86 function()
87 ReAction.db:ResetProfile() 87 ReAction.db:ResetProfile()
88 self:OnOptionsRefreshed() 88 ReAction:RefreshOptions()
89 end ) 89 end )
90 end 90 end
91 91
92 92
93 93
94 94
95 -- Bar Editor -- 95 -- Bar Editor --
96 local function NewEditor() 96 local function NewEditor()
97 -- private variables 97 -- private variables
98 local editorName = "ReAction-Editor" 98 local editorName = "ReAction-Editor"
99 local barOptMap = { } 99 local barOptMap = setmetatable({},{__mode="v"})
100 local tmp = { } 100 local tmp = { }
101 local pointTable = { 101 local pointTable = {
102 CENTER = L["Center"], 102 CENTER = L["Center"],
103 LEFT = L["Left"], 103 LEFT = L["Left"],
104 RIGHT = L["Right"], 104 RIGHT = L["Right"],
124 if editor.closePending then 124 if editor.closePending then
125 InterfaceOptionsFrame:Hide() 125 InterfaceOptionsFrame:Hide()
126 editor.closePending = false 126 editor.closePending = false
127 end 127 end
128 if editor.selfClosePending then 128 if editor.selfClosePending then
129 ed:Hide() 129 editor:Hide()
130 AceConfigReg:NotifyChange(configName) 130 AceConfigReg:NotifyChange(configName)
131 editor.selfClosePending = false 131 editor.selfClosePending = false
132 end 132 end
133 end ) 133 end )
134 editor:SetCallback("OnClose", 134 editor:SetCallback("OnClose",
191 order = 2, 191 order = 2,
192 }, 192 },
193 type = { 193 type = {
194 type = "select", 194 type = "select",
195 name = L["Button Type"], 195 name = L["Button Type"],
196 get = function() return tmp.barType or ReAction.defaultBarConfigChoice or "" end, 196 get = function() return tmp.barType or ReAction:GetDefaultBarType() or "" end,
197 set = function(info, val) 197 set = function(info, val)
198 local c = ReAction.defaultBarConfig[val] 198 local c = ReAction:GetBarTypeConfig(val)
199 tmp.barType = val 199 tmp.barType = val
200 tmp.barSize = c.defaultButtonSize or tmp.barSize 200 tmp.barSize = c.defaultButtonSize or tmp.barSize
201 tmp.barRows = c.defaultBarRows or tmp.barRows 201 tmp.barRows = c.defaultBarRows or tmp.barRows
202 tmp.barCols = c.defaultBarCols or tmp.barCols 202 tmp.barCols = c.defaultBarCols or tmp.barCols
203 tmp.barSpacing = c.defaultBarSpacing or tmp.barSpacing 203 tmp.barSpacing = c.defaultBarSpacing or tmp.barSpacing
401 } 401 }
402 self:RefreshBarTree(bar) 402 self:RefreshBarTree(bar)
403 end 403 end
404 404
405 function editor:RefreshBarTree(bar) 405 function editor:RefreshBarTree(bar)
406 local opts = options.args[barOptMap[bar:GetName()]] 406 local key = barOptMap[bar:GetName()]
407 opts.plugins = { } 407 if key and options.args[key] then
408 for name, module in ReAction:IterateModules() do 408 options.args[key].plugins = ReAction:GenerateBarOptionsTable(bar)
409 if module.GetBarOptions then 409 AceConfigReg:NotifyChange(editorName)
410 opts.plugins[module:GetName()] = { [module:GetName()] = module:GetBarOptions(bar) }
411 end
412 end 410 end
413 end 411 end
414 412
415 function editor:OnCreateBar(evt, bar) 413 function editor:OnCreateBar(evt, bar)
416 self:CreateBarTree(bar) 414 self:CreateBarTree(bar)
415 end
416
417 function editor:OnDestroyBar(evt, bar, name)
418 local key = barOptMap[name]
419 if key then
420 options.args[key] = nil
421 end
422 self:Refresh()
417 end 423 end
418 424
419 function editor:OnEraseBar(evt, name) 425 function editor:OnEraseBar(evt, name)
420 local key = barOptMap[name] 426 local key = barOptMap[name]
421 barOptMap[name] = nil 427 barOptMap[name] = nil
432 options.args[key].name = newname 438 options.args[key].name = newname
433 self:Refresh() 439 self:Refresh()
434 end 440 end
435 end 441 end
436 442
443 function editor:OnBarOptionGeneratorRegistered(evt)
444 for name in pairs(barOptMap) do
445 local bar = ReAction:GetBar(name)
446 if bar then
447 self:RefreshBarTree(bar)
448 end
449 end
450 end
451
437 local _scratch = { } 452 local _scratch = { }
438 function editor:GetBarTypes() 453 function editor:GetBarTypes()
439 for k,v in pairs(_scratch) do 454 for k,v in pairs(_scratch) do
440 _scratch[k] = nil 455 _scratch[k] = nil
441 end 456 end
442 for k in pairs(ReAction.defaultBarConfig) do 457 return ReAction:GetBarTypeOptions(_scratch)
443 _scratch[k] = k
444 end
445 return _scratch
446 end 458 end
447 459
448 function editor:CreateBar() 460 function editor:CreateBar()
449 if tmp.barName and tmp.barName ~= "" then 461 if tmp.barName and tmp.barName ~= "" then
450 ReAction:CreateBar(tmp.barName, tmp.barType or ReAction.defaultBarConfigChoice, tmp.barRows, tmp.barCols, tmp.barSize, tmp.barSpacing) 462 ReAction:CreateBar(tmp.barName, tmp.barType or ReAction:GetDefaultBarType(), tmp.barRows, tmp.barCols, tmp.barSize, tmp.barSpacing)
451 tmp.barName = nil 463 tmp.barName = nil
452 end 464 end
453 end 465 end
454 466
455 ReAction.RegisterCallback(editor,"OnCreateBar") 467 ReAction.RegisterCallback(editor,"OnCreateBar")
468 ReAction.RegisterCallback(editor,"OnDestroyBar")
456 ReAction.RegisterCallback(editor,"OnEraseBar") 469 ReAction.RegisterCallback(editor,"OnEraseBar")
457 ReAction.RegisterCallback(editor,"OnRenameBar") 470 ReAction.RegisterCallback(editor,"OnRenameBar")
458 471 ReAction.RegisterCallback(editor,"OnBarOptionGeneratorRegistered")
459 for name, bar in pairs(ReAction.bars) do 472
473 for name, bar in ReAction:IterateBars() do
460 editor:CreateBarTree(bar) 474 editor:CreateBarTree(bar)
461 end 475 end
462 476
463 return editor 477 return editor
464 end 478 end
469 ReAction:UserError(L["ReAction config mode disabled during combat."]) 483 ReAction:UserError(L["ReAction config mode disabled during combat."])
470 else 484 else
471 if not self.editor then 485 if not self.editor then
472 self.editor = NewEditor() 486 self.editor = NewEditor()
473 end 487 end
488 -- TODO: figure out how to open to a particular bar: currently AceConfigDialogue doesn't support this
474 self.editor:Open() 489 self.editor:Open()
475 ReAction:SetConfigMode(true) 490 ReAction:SetConfigMode(true)
476 end 491 end
477 end 492 end
478 493