changeset 48:7b7d178dec52

Implemented bar-type selection, extended CreateBar functionality
author Flick <flickerstreak@gmail.com>
date Sat, 12 Apr 2008 00:15:09 +0000
parents e12b736c23c3
children dcf8116560a1
files ReAction.lua locale/enUS.lua modules/ReAction_Action/ReAction_Action.lua modules/ReAction_ConfigUI/ReAction_ConfigUI.lua
diffstat 4 files changed, 99 insertions(+), 93 deletions(-) [+]
line wrap: on
line diff
--- a/ReAction.lua	Fri Apr 11 22:21:28 2008 +0000
+++ b/ReAction.lua	Sat Apr 12 00:15:09 2008 +0000
@@ -147,6 +147,7 @@
 
   self.bars = {}
   self.options = {}
+  self.defaultBarConfig = {}
 
   self:RegisterOptions("global", self, {
     unlock = {
@@ -245,9 +246,33 @@
 end
 
 
-function ReAction:CreateBar(name, defaultConfig, prefix)
+function ReAction:CreateBar(name, ...)
+  local config = select(1,...)
+  if config and type(config) ~= "table" then
+    bartype = select(1,...)
+    if type(bartype) ~= "string" then
+      error("ReAction:CreateBar() - first argument must be a config table or a default config type string")
+    end
+    config = self.defaultBarConfig[bartype]
+    if not config then
+      error(("ReAction:CreateBar() - unknown bar type '%s'"):format(bartype))
+    end
+    config = DeepCopy(config)
+    config.btnRows    = select(2,...) or config.btnRows    or 1
+    config.btnColumns = select(3,...) or config.btnColumns or 12
+    config.btnWidth   = select(4,...) or config.btnWidth   or 36
+    config.btnHeight  = select(4,...) or config.btnHeight  or 36
+    config.spacing    = select(5,...) or config.spacing    or 3
+    config.width      = config.width or config.btnColumns*(config.btnWidth + config.spacing) + 1
+    config.height     = config.height or config.btnRows*(config.btnHeight + config.spacing) + 1
+    config.anchor     = config.anchor or "BOTTOM"
+    config.anchorTo   = config.anchorTo or "UIParent"
+    config.relativePoint = config.relativePoint or "BOTTOM"
+    config.y          = config.y or 200
+    config.x          = config.x or 0
+  end
   local profile = self.db.profile
-  defaultConfig = defaultConfig or profile.defaultBar
+  config = config or DeepCopy(profile.defaultBar)
   prefix = prefix or L["Bar "]
   if not name then
     i = 1
@@ -256,7 +281,7 @@
       i = i + 1
     until self.bars[name] == nil
   end
-  profile.bars[name] = profile.bars[name] or DeepCopy(defaultConfig)
+  profile.bars[name] = profile.bars[name] or config
   local bar = self.Bar:new( name, profile.bars[name] )  -- ReAction.Bar defined in Bar.lua
   self:CallMethodOnAllModules("ApplyToBar", bar)
   self.bars[name] = bar
@@ -299,6 +324,22 @@
   end
 end
 
+function ReAction:RegisterDefaultBarConfig( name, config, isDefaultChoice )
+  self.defaultBarConfig[name] = config
+  if isDefaultChoice then
+    self.defaultBarConfigChoice = name
+  end
+  self:RefreshOptions()
+end
+
+function ReAction:UnregisterDefaultBarConfig( name )
+  self.defaultBarConfig[name] = nil
+  if self.defaultBarConfigChoice == name then
+    self.defaultBarConfigChoice = nil
+  end
+  self:RefreshOptions()
+end
+
 -- See modules/ReAction_ConfigUI for valid options contexts.
 function ReAction:RegisterOptions(context, module, opts)
   if module == nil or context == nil then
@@ -320,14 +361,6 @@
   end
 end
 
-function ReAction:GetOptionContextList()
-  local c = {}
-  for k in self.options do
-    tinsert(c,k)
-  end
-  return c
-end
-
 function ReAction:RefreshOptions()
   self.callbacks:Fire("OnOptionsRefreshed")
 end
--- a/locale/enUS.lua	Fri Apr 11 22:21:28 2008 +0000
+++ b/locale/enUS.lua	Sat Apr 12 00:15:09 2008 +0000
@@ -32,8 +32,7 @@
 "Hide the default main bar and extra action bars",
 
 -- modules/ReAction_Action
-"New Action Bar",
-"Create a new bar of standard action buttons",
+"Action Bar",
 
 -- modules/ReAction_ConfigUI
 "Customizable replacement for Blizzard's Action Bars",
--- a/modules/ReAction_Action/ReAction_Action.lua	Fri Apr 11 22:21:28 2008 +0000
+++ b/modules/ReAction_Action/ReAction_Action.lua	Sat Apr 12 00:15:09 2008 +0000
@@ -31,43 +31,49 @@
 end
 
 function module:OnEnable()
+  ReAction:RegisterDefaultBarConfig(L["Action Bar"], { type = "actionbar" }, true)
 end
 
 function module:OnDisable()
+  ReAction:UnregisterDefaultBarConfig(L["Action Bar"])
 end
 
 function module:ApplyToBar(bar)
-  self:RefreshBar(bar)
+  if bar.config.type == "actionbar" then
+    self:RefreshBar(bar)
+  end
 end
 
 function module:RefreshBar(bar)
-  if self.buttons[bar] == nil then
-    self.buttons[bar] = { }
-  end
-  local btns = self.buttons[bar]
-  local profile = self.db.profile
-  local barName = bar:GetName()
-  if profile.buttons[barName] == nil then
-    profile.buttons[barName] = {}
-  end
-  local btnCfg = profile.buttons[barName]
+  if bar.config.type == "actionbar" then
+    if self.buttons[bar] == nil then
+      self.buttons[bar] = { }
+    end
+    local btns = self.buttons[bar]
+    local profile = self.db.profile
+    local barName = bar:GetName()
+    if profile.buttons[barName] == nil then
+      profile.buttons[barName] = {}
+    end
+    local btnCfg = profile.buttons[barName]
 
-  local r, c = bar:GetButtonGrid()
-  local n = r*c
-  for i = 1, n do
-    if btnCfg[i] == nil then
-      btnCfg[i] = {}
+    local r, c = bar:GetButtonGrid()
+    local n = r*c
+    for i = 1, n do
+      if btnCfg[i] == nil then
+        btnCfg[i] = {}
+      end
+      if btns[i] == nil then
+        btns[i] = self.BtnClass:new(bar,i,btnCfg[i])
+      else
+        btns[i]:Refresh(bar,i)
+      end
     end
-    if btns[i] == nil then
-      btns[i] = self.BtnClass:new(bar,i,btnCfg[i])
-    else
-      btns[i]:Refresh(bar,i)
-    end
-  end
-  for i = n+1, #btns do
-    btns[i] = btns[i]:Destroy()
-    if btnCfg[i] then
-      btnCfg[i] = nil
+    for i = n+1, #btns do
+      btns[i] = btns[i]:Destroy()
+      if btnCfg[i] then
+        btnCfg[i] = nil
+      end
     end
   end
 end
@@ -88,6 +94,11 @@
   self.db.profile.buttons[barName] = nil
 end
 
+function module:RenameBarConfig(oldname, newname)
+  local b = self.db.profile.buttons
+  b[newname], b[oldname] = b[oldname], nil
+end
+
 function module:ApplyConfigMode(mode,bars)
   for _, btns in pairs(self.buttons) do
     if btn then
@@ -113,41 +124,6 @@
   end
 end
 
-function module:GetGlobalBarOptions(opts)  
-  if self.globalBarOpts == nil then
-    self.globalBarOpts = {
-      newActionBar = {
-        type = "execute",
-        name = L["New Action Bar"],
-        desc = L["Create a new bar of standard action buttons"],
-        func = function()
-                 ReAction:CreateBar()
-               end,
-        disabled = InCombatLockdown,
-      }
-    }
-  end
-  return self.globalBarOpts
-end
-
-function module:GetBarMenuOptions(bar)
-  if not bar.modMenuOpts[moduleID] then
-    bar.modMenuOpts[moduleID] = {
-    }
-  end
-  return bar.modMenuOpts[moduleID]
-end
-
-function module:GetBarConfigOptions(bar)
-  if not bar.modConfigOpts[moduleID] then
-    bar.modConfigOpts[moduleID] = {
-    }
-  end
-  return bar.modConfigOpts[moduleID]
-end
-
-
-
 -- use-count of action IDs
 local ActionIDList = setmetatable( {}, {
   __index = function(self, idx)
--- a/modules/ReAction_ConfigUI/ReAction_ConfigUI.lua	Fri Apr 11 22:21:28 2008 +0000
+++ b/modules/ReAction_ConfigUI/ReAction_ConfigUI.lua	Sat Apr 12 00:15:09 2008 +0000
@@ -48,7 +48,8 @@
 end
 
 function module:OnOptionsRefreshed(evt)
-  -- TODO: refresh options frame (just OpenConfig again?)
+  AceConfigReg:NotifyChange("ReAction")
+  AceConfigReg:NotifyChange("ReAction-Layout")
 end
 
 function module:OnCreateBar(evt, bar)
@@ -156,7 +157,7 @@
           ReAction:SetConfigMode(false)
         end )
       self.editor = ed
-      AceConfigDialog:SetDefaultSize("ReAction-Layout", 600, 450)
+      AceConfigDialog:SetDefaultSize("ReAction-Layout", 640, 420)
     end
 
     AceConfigDialog:Open("ReAction-Layout", self.editor)
@@ -173,24 +174,21 @@
 
 function module:GetBarTypes()
   local opts = self.optBarTypes or { }
-  self.optBarTypes = opts
-
-  -- TODO: get these from module registration somehow
-  opts[1] = "foo"
-  
+  self.optBarTypes = { }
+  for k,v in pairs(opts) do
+    opts[k] = nil
+  end
+  for k in pairs(ReAction.defaultBarConfig) do
+    opts[k] = k
+  end
   return opts
 end
 
 function module:CreateBar()
-  local name = self.tmpBarName
-  local type = self.tmpBarType
-
-  self.tmpBarName = nil
-  self.tmpBarType = nil
-
-  -- TODO: get from module registration
-  -- TODO: use rows/cols info
-  ReAction:CreateBar(name)
+  if self.tmpBarType and self.tmpBarType ~= "" then
+    ReAction:CreateBar(self.tmpBarName, self.tmpBarType, self.tmpBarRows, self.tmpBarCols, self.tmpBarSize, self.tmpBarSpacing)
+    self.tmpBarName = nil
+  end
 end
 
 function module:InitializeOptions()
@@ -305,14 +303,14 @@
             self:OpenConfig()
             -- you can't close a dialog in response to an options click, because the end of the 
             -- handler for all the button events calls lib:Open()
-            -- So, schedule a close on the next appropriate event
+            -- So, schedule a close on the next OnUpdate
             if self.db.profile.editorCloseOnLaunch then
               self.editor.selfClosePending = true
             end
           end,
         order = 2
       },
-      closThis = {
+      closeThis = {
         type = "toggle",
         name = L["Close on Launch"],
         desc = L["Close the Layout Editor when opening the ReAction global Interface Options"],
@@ -341,7 +339,7 @@
           type = {
             type = "select",
             name = L["Button Type"],
-            get  = function() return self.tmpBarType or "" end,
+            get  = function() return self.tmpBarType or ReAction.defaultBarConfigChoice or "" end,
             set  = function(info, val) self.tmpBarType = val end,
             values = "GetBarTypes",
             order = 3,