changeset 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
files locale/enUS.lua modules/ReAction_Action/ReAction_Action.lua modules/ReAction_ConfigUI/ReAction_ConfigUI.lua modules/ReAction_PetAction/ReAction_PetAction.lua modules/ReAction_PossessBar/ReAction_PossessBar.lua
diffstat 5 files changed, 94 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/locale/enUS.lua	Mon Apr 28 21:08:35 2008 +0000
+++ b/locale/enUS.lua	Mon Apr 28 23:34:17 2008 +0000
@@ -38,13 +38,16 @@
 -- modules/ReAction_Action
 "Action Bar",
 "Hide Empty Buttons",
+"Action Buttons",
 
 -- modules/ReAction_PetAction
 "Pet Action Bar",
+"Pet Buttons",
 
 -- modules/ReAction_PossessBar
 "Possess Bar",
 "Hide Empty Possess Bar Buttons",
+"Possess Buttons",
 
 -- modules/ReAction_ConfigUI
 "Center",
--- a/modules/ReAction_Action/ReAction_Action.lua	Mon Apr 28 21:08:35 2008 +0000
+++ b/modules/ReAction_Action/ReAction_Action.lua	Mon Apr 28 23:34:17 2008 +0000
@@ -36,6 +36,14 @@
       set  = function(info, val) module:SetHideEmptyButtons(val) end,
     }
   })
+
+  ReAction:RegisterOptions("bar", self, {
+    type = "group",
+    name = L["Action Buttons"],
+    hidden = "BarOptionsHidden",
+    args = {
+    }
+  })
 end
 
 function module:OnEnable()
@@ -170,6 +178,11 @@
 end
 
 
+---- Options handlers ----
+function module:BarOptionsHidden(bar)
+  return bar.config.type ~= moduleID
+end
+
 
 -- use-count of action IDs
 local nActionIDs = 120
--- 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)
--- a/modules/ReAction_PetAction/ReAction_PetAction.lua	Mon Apr 28 21:08:35 2008 +0000
+++ b/modules/ReAction_PetAction/ReAction_PetAction.lua	Mon Apr 28 23:34:17 2008 +0000
@@ -30,6 +30,14 @@
 
   ReAction:RegisterOptions("global", self, {
   })
+
+  ReAction:RegisterOptions("bar", self, {
+    type = "group",
+    name = L["Pet Buttons"],
+    hidden = "BarOptionsHidden",
+    args = {
+    }
+  })
 end
 
 function module:OnEnable()
@@ -163,6 +171,11 @@
   end
 end
 
+---- Options handlers ----
+function module:BarOptionsHidden(bar)
+  return bar.config.type ~= moduleID
+end
+
 
 
 -- use-count of action IDs
--- a/modules/ReAction_PossessBar/ReAction_PossessBar.lua	Mon Apr 28 21:08:35 2008 +0000
+++ b/modules/ReAction_PossessBar/ReAction_PossessBar.lua	Mon Apr 28 23:34:17 2008 +0000
@@ -35,6 +35,14 @@
       set  = function(info, val) module:SetHideEmptyButtons(val) end,
     }
   })
+
+  ReAction:RegisterOptions("bar", self, {
+    type = "group",
+    name = L["Possess Buttons"],
+    hidden = "BarOptionsHidden",
+    args = {
+    }
+  })
 end
 
 function module:OnEnable()
@@ -248,6 +256,10 @@
   end
 end
 
+---- Options handlers ----
+function module:BarOptionsHidden(bar)
+  return bar.config.type ~= moduleID
+end
 
 
 -- use-count of action IDs