changeset 218:e63aefb8a555

Demodularization of buttons - register class instead of config
author Flick <flickerstreak@gmail.com>
date Fri, 19 Nov 2010 23:06:24 -0800
parents 9c0691e91488
children a5d91d7fd485
files Editor.lua ReAction.lua classes/ActionButton.lua classes/BagButton.lua classes/Button.lua classes/MultiCastButton.lua classes/PetActionButton.lua classes/StanceButton.lua classes/VehicleExitButton.lua locale/enUS.lua modules/Action.lua modules/Bag.lua modules/PetAction.lua modules/Stance.lua modules/Totem.lua modules/VehicleExit.lua
diffstat 16 files changed, 183 insertions(+), 104 deletions(-) [+]
line wrap: on
line diff
--- a/Editor.lua	Fri Nov 19 15:27:23 2010 -0800
+++ b/Editor.lua	Fri Nov 19 23:06:24 2010 -0800
@@ -90,12 +90,12 @@
             name = L["Button Type"],
             get  = function() return self.tmp.barType or ReAction:GetDefaultBarType() or "" end,
             set  = function(info, val) 
-                     local c = ReAction:GetBarTypeConfig(val)
+                     local c = ReAction:GetDefaultBarConfig(val)
                      self.tmp.barType = val 
-                     self.tmp.barSize = c.defaultButtonSize or self.tmp.barSize
-                     self.tmp.barRows = c.defaultBarRows or self.tmp.barRows
-                     self.tmp.barCols = c.defaultBarCols or self.tmp.barCols
-                     self.tmp.barSpacing = c.defaultBarSpacing or self.tmp.barSpacing
+                     self.tmp.barSize = c.btnWidth or self.tmp.barSize
+                     self.tmp.barRows = c.btnRows or self.tmp.barRows
+                     self.tmp.barCols = c.btnColumns or self.tmp.barCols
+                     self.tmp.barSpacing = c.spacing or self.tmp.barSpacing
                    end,
             values = "GetBarTypes",
             order = 3,
--- a/ReAction.lua	Fri Nov 19 15:27:23 2010 -0800
+++ b/ReAction.lua	Fri Nov 19 23:06:24 2010 -0800
@@ -41,7 +41,7 @@
   self:UpgradeProfile()
 
   self.bars = { }
-  self.defaultBarConfig = { }
+  self.barTypes = { }
 
   self.LBF = LibStub("LibButtonFacade",true)
   if self.LBF then
@@ -144,16 +144,16 @@
   end
 
   if type(config) == "string" then
-    config = self.defaultBarConfig[config]
-    if not config then
-      error(("ReAction:CreateBar() - unknown bar type '%s'"):format(tostring(select(1,...))))
+    local class = self.barTypes[config]
+    if not class then
+      error(("ReAction:CreateBar() - unknown bar type '%s'"):format(config))
     end
-    config = tcopy(config)
-    config.btnRows    = select(1,...) or config.btnRows    or 1
-    config.btnColumns = select(2,...) or config.btnColumns or 12
-    config.btnWidth   = select(3,...) or config.btnWidth   or 36
-    config.btnHeight  = select(3,...) or config.btnHeight  or 36
-    config.spacing    = select(4,...) or config.spacing    or 3
+    config = tcopy(class:GetDefaultBarConfig())
+    config.btnRows    = select(1,...) or config.btnRows
+    config.btnColumns = select(2,...) or config.btnColumns
+    config.btnWidth   = select(3,...) or config.btnWidth
+    config.btnHeight  = select(3,...) or config.btnHeight
+    config.spacing    = select(4,...) or config.spacing
     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 "UIParent"
@@ -284,29 +284,31 @@
   ManageBlizzFrame(VehicleMenuBar, self.db.profile.options.hideBlizzardVehicleBar)
 end
 
-function ReAction:RegisterBarType( name, config, isDefaultChoice )
-  self.defaultBarConfig[name] = config
-  if isDefaultChoice then
-    self.defaultBarConfigChoice = name
+function ReAction:RegisterBarType( class, isDefault )
+  local name = class:GetBarType()
+  self.barTypes[name] = class
+  if isDefault then
+    self.defaultBarType = name
   end
   self:RefreshEditor()
 end
 
-function ReAction:UnregisterBarType( name )
-  self.defaultBarConfig[name] = nil
-  if self.defaultBarConfigChoice == name then
-    self.defaultBarConfigChoice = nil
+function ReAction:UnregisterBarType( class )
+  local name = class:GetBarType()
+  self.barTypes[name] = nil
+  if self.defaultBarType == name then
+    self.defaultBarType = nil
   end
   self:RefreshEditor()
 end
 
 function ReAction:IterateBarTypes()
-  return pairs(self.defaultBarConfig)
+  return pairs(self.barTypes)
 end
 
-function ReAction:GetBarTypeConfig(name)
-  if name then
-    return self.defaultBarConfig[name]
+function ReAction:GetDefaultBarConfig(barType)
+  if barType and self.barTypes[barType] then
+    return self.barTypes[barType]:GetDefaultBarConfig()
   end
 end
 
@@ -319,7 +321,7 @@
 end
 
 function ReAction:GetDefaultBarType()
-  return self.defaultBarConfigChoice
+  return self.defaultBarType
 end
 
 function ReAction:SetConfigMode( mode )
--- a/classes/ActionButton.lua	Fri Nov 19 15:27:23 2010 -0800
+++ b/classes/ActionButton.lua	Fri Nov 19 23:06:24 2010 -0800
@@ -170,8 +170,22 @@
 --
 -- Action Button class
 --
+local buttonTypeID = "Action"
 local Super = ReAction.Button
-local Action = setmetatable( { }, { __index = Super } )
+local Action = setmetatable( 
+  { 
+    defaultBarConfig = { 
+      type = buttonTypeID,
+      btnWidth = 36,
+      btnHeight = 36,
+      btnRows = 1,
+      btnColumns = 12,
+      spacing = 3
+    },
+
+    barType = L["Action Bar"]
+  },
+  { __index = Super } )
 ReAction.Button.Action = Action
 
 function Action:New( idx, barConfig, bar, idHint )
--- a/classes/BagButton.lua	Fri Nov 19 15:27:23 2010 -0800
+++ b/classes/BagButton.lua	Fri Nov 19 23:06:24 2010 -0800
@@ -15,8 +15,23 @@
 local CursorCanGoInSlot = CursorCanGoInSlot
 
 -- class declarations
+local buttonTypeID = "Bag"
 local Super    = ReAction.Button
-local BagBase  = setmetatable( { }, { __index = Super } )
+local BagBase  = setmetatable( 
+  { 
+    defaultBarConfig = { 
+      type = buttonTypeID,
+      btnWidth = 30,
+      btnHeight = 30,
+      btnRows = 1,
+      btnColumns = 6,
+      spacing = 4
+    },
+
+    barType = L["Bag Bar"],
+  },
+  { __index = Super } )
+
 local Bag      = setmetatable( { }, { __index = BagBase } )
 local Backpack = setmetatable( { }, { __index = BagBase } )
 local Keyring  = setmetatable( { }, { __index = BagBase } )
--- a/classes/Button.lua	Fri Nov 19 15:27:23 2010 -0800
+++ b/classes/Button.lua	Fri Nov 19 23:06:24 2010 -0800
@@ -22,7 +22,18 @@
 end
 
 -- Button class
-local Button = { } 
+local buttonTypeID = "Button"
+local Button = { 
+  defaultBarConfig = {
+    type = buttonTypeID,
+    btnWidth = 36,
+    btnHeight = 36,
+    btnRows = 1,
+    btnColumns = 12,
+    spacing = 3
+  },
+  barType = L["Button Bar"]
+} 
 
 ReAction.Button = Button -- export to ReAction
 
@@ -105,6 +116,14 @@
   return self.name
 end
 
+function Button:GetDefaultBarConfig()
+  return self.defaultBarConfig
+end
+
+function Button:GetBarType()
+  return self.barType
+end
+
 function Button:GetConfig()
   return self.config
 end
--- a/classes/MultiCastButton.lua	Fri Nov 19 15:27:23 2010 -0800
+++ b/classes/MultiCastButton.lua	Fri Nov 19 23:06:24 2010 -0800
@@ -300,9 +300,23 @@
 -- Inherits implementation methods from Action button class, but circumvents the constructor
 -- and redefines/removes some methods.
 --
+local buttonTypeID = "Totem"
 local Super = ReAction.Button
 local Action = ReAction.Button.Action
-local MultiCast = setmetatable( { }, { __index = Action } )
+local MultiCast = setmetatable( 
+  { 
+    defaultBarConfig = { 
+      type = buttonTypeID,
+      btnWidth = 36,
+      btnHeight = 36,
+      btnRows = 1,
+      btnColumns = 6,
+      spacing = 3
+    },
+
+    barType = L["Totem Bar"], 
+  },
+  { __index = Action } )
 ReAction.Button.MultiCast = MultiCast
 
 function MultiCast:New( idx, btnConfig, bar )
--- a/classes/PetActionButton.lua	Fri Nov 19 15:27:23 2010 -0800
+++ b/classes/PetActionButton.lua	Fri Nov 19 23:06:24 2010 -0800
@@ -56,8 +56,22 @@
 --
 -- Pet Action Button class
 --
+local buttonTypeID = "PetAction"
 local Super = ReAction.Button
-local Pet = setmetatable( { }, { __index = Super } )
+local Pet = setmetatable( 
+  { 
+    defaultBarConfig = { 
+      type = buttonTypeID,
+      btnWidth = 30,
+      btnHeight = 30,
+      btnRows = 1,
+      btnColumns = 10,
+      spacing = 8
+    },
+
+    barType = L["Pet Action Bar"], 
+  },
+  { __index = Super } )
 ReAction.Button.PetAction = Pet
 
 function Pet:New( idx, config, bar, idHint )
--- a/classes/StanceButton.lua	Fri Nov 19 15:27:23 2010 -0800
+++ b/classes/StanceButton.lua	Fri Nov 19 23:06:24 2010 -0800
@@ -31,8 +31,22 @@
 --
 -- Stance Button class
 --
+local buttonTypeID = "Stance"
 local Super = ReAction.Button
-local Stance = setmetatable( { }, { __index = Super } )
+local Stance = setmetatable(
+  { 
+    defaultConfig = { 
+      type = buttonTypeID,
+      btnHeight = 36,
+      btnWidth = 36,
+      btnRows = 1,
+      btnColumns = 6,
+      spacing = 3
+    }, 
+
+    barType = L["Stance Bar"], 
+  },
+  { __index = Super } )
 ReAction.Button.Stance = Stance
 
 function Stance:New( idx, moduleConfig, bar, idHint )
--- a/classes/VehicleExitButton.lua	Fri Nov 19 15:27:23 2010 -0800
+++ b/classes/VehicleExitButton.lua	Fri Nov 19 23:06:24 2010 -0800
@@ -1,12 +1,27 @@
 local addonName, addonTable = ...
 local ReAction = addonTable.ReAction
+local L = ReAction.L
 local format = string.format
 
 --
 -- VExitButton Button class
 --
+local buttonTypeID = "VehicleExit"
 local Super = ReAction.Button
-local VExitButton = setmetatable( { }, { __index = Super } )
+local VExitButton = setmetatable(
+  { 
+    defaultBarConfig = { 
+      type = buttonTypeID ,
+      btnWidth = 36,
+      btnHeight = 36,
+      btnRows = 1,
+      btnColumns = 1,
+      spacing = 3
+    },
+
+    barType = L["Exit Vehicle Floater"], 
+  }, 
+  { __index = Super } )
 ReAction.Button.VehicleExit = VExitButton
 
 function VExitButton:New( idx, config, bar )
--- a/locale/enUS.lua	Fri Nov 19 15:27:23 2010 -0800
+++ b/locale/enUS.lua	Fri Nov 19 23:06:24 2010 -0800
@@ -4,7 +4,6 @@
 for _, string in pairs({
 
 -- ReAction.lua
-"Bar ",
 "ReAction: name '%s' already in use",
 "ReAction config mode disabled during combat.",
 
@@ -80,13 +79,20 @@
 "Y offset",
 "Transparency",
 
--- PetActionButton.lua
-"Pet action ID range is 1-10",
-
--- ActionButton.lua
+-- classes/ActionButton.lua
+"Action Bar",
 "Action ID range is 1-120",
 
--- Overlay.lua
+-- classes/BagButton.lua --
+"Bag Bar",
+
+-- classes/Bar.lua
+"Hidden",
+
+-- classes/Button.lua --
+"Button Bar",
+
+-- classes/Overlay.lua
 "Hold Shift",
 "Hold Alt",
 "Right-click",
@@ -102,10 +108,20 @@
 "State",
 "State Scale Override",
 
--- Bar.lua
-"Hidden",
+-- classes/MultiCastButton.lua
+"Totem Bar",
 
--- State.lua
+-- classes/PetActionButton.lua
+"Pet Action Bar",
+"Pet action ID range is 1-10",
+
+-- classes/StanceButton.lua
+"Stance Bar",
+
+-- classes/VehicleExitButton.lua
+"Exit Vehicle Floater",
+
+-- modules/State.lua
 "State named '%s' already exists",
 "Battle Stance",
 "Defensive Stance",
@@ -187,8 +203,7 @@
 "Create State",
 "State named '%s' already exists",
 
--- Action
-"Action Bar",
+-- modules/Action.lua
 "Action Bars",
 "Hide Empty Buttons",
 "Lock Buttons",
@@ -219,12 +234,10 @@
 "Show Page #",
 "Action Buttons",
 
--- PetAction
-"Pet Action Bar",
+-- modules/PetAction.lua
 "Pet Buttons",
 
--- Stance
-"Stance Bar",
+-- modules/Stance.lua
 "Stance Buttons",
 "Show Aspects",
 "Show Hunter aspects as stances",
@@ -235,15 +248,7 @@
 "Hide Auras",
 "Do not show Paladin Auras as stances",
 
--- Totem
-"Totem Bar",
-"Totem Buttons",
-
--- Bag
-"Bag Bar",
-
--- VehicleExit
-"Exit Vehicle Floater",
+-- modules/VehicleExit.lua
 "Exit Vehicle",
 "Show only when passenger",
 "Only show the button when riding as a passenger in a vehicle (no vehicle controls)",
--- a/modules/Action.lua	Fri Nov 19 15:27:23 2010 -0800
+++ b/modules/Action.lua	Fri Nov 19 23:06:24 2010 -0800
@@ -38,19 +38,12 @@
 end
 
 function module:OnEnable()
-  ReAction:RegisterBarType(L["Action Bar"], 
-    { 
-      type = moduleID,
-      defaultButtonSize = 36,
-      defaultBarRows = 1,
-      defaultBarCols = 12,
-      defaultBarSpacing = 3
-    }, true)
+  ReAction:RegisterBarType(Button, true)
   ReAction:GetModule("State"):RegisterStateProperty("page", nil, PropHandler.GetOptions(), PropHandler)
 end
 
 function module:OnDisable()
-  ReAction:UnregisterBarType(L["Action Bar"])
+  ReAction:UnregisterBarType(Button)
   ReAction:GetModule("State"):UnregisterStateProperty("page")
 end
 
--- a/modules/Bag.lua	Fri Nov 19 15:27:23 2010 -0800
+++ b/modules/Bag.lua	Fri Nov 19 23:06:24 2010 -0800
@@ -38,18 +38,11 @@
 end
 
 function module:OnEnable()
-  ReAction:RegisterBarType(L["Bag Bar"], 
-    { 
-      type = moduleID ,
-      defaultButtonSize = 30,
-      defaultBarRows = 1,
-      defaultBarCols = 6,
-      defaultBarSpacing = 4
-    })
+  ReAction:RegisterBarType(Button)
 end
 
 function module:OnDisable()
-  ReAction:UnregisterBarType(L["Bag Bar"])
+  ReAction:UnregisterBarType(Button)
 end
 
 function module:OnDestroyBar(event, bar, name)
--- a/modules/PetAction.lua	Fri Nov 19 15:27:23 2010 -0800
+++ b/modules/PetAction.lua	Fri Nov 19 23:06:24 2010 -0800
@@ -54,18 +54,11 @@
 end
 
 function module:OnEnable()
-  ReAction:RegisterBarType(L["Pet Action Bar"], 
-    { 
-      type = moduleID ,
-      defaultButtonSize = 30,
-      defaultBarRows = 1,
-      defaultBarCols = 10,
-      defaultBarSpacing = 8
-    })
+  ReAction:RegisterBarType(Button)
 end
 
 function module:OnDisable()
-  ReAction:UnregisterBarType(L["Pet Action Bar"])
+  ReAction:UnregisterBarType(Button)
 end
 
 function module:OnCreateBar(event, bar, name)
--- a/modules/Stance.lua	Fri Nov 19 15:27:23 2010 -0800
+++ b/modules/Stance.lua	Fri Nov 19 23:06:24 2010 -0800
@@ -38,19 +38,11 @@
 end
 
 function module:OnEnable()
-  ReAction:RegisterBarType(L["Stance Bar"], 
-    { 
-      type = moduleID ,
-      defaultButtonSize = 36,
-      defaultBarRows = 1,
-      defaultBarCols = 6,
-      defaultBarSpacing = 3
-    })
-
+  ReAction:RegisterBarType(Button)
 end
 
 function module:OnDisable()
-  ReAction:UnregisterBarType(L["Stance Bar"])
+  ReAction:UnregisterBarType(Button)
 end
 
 function module:OnDestroyBar(event, bar, name)
--- a/modules/Totem.lua	Fri Nov 19 15:27:23 2010 -0800
+++ b/modules/Totem.lua	Fri Nov 19 23:06:24 2010 -0800
@@ -41,19 +41,11 @@
 end
 
 function module:OnEnable()
-  ReAction:RegisterBarType(L["Totem Bar"], 
-    { 
-      type = moduleID ,
-      defaultButtonSize = 36,
-      defaultBarRows = 1,
-      defaultBarCols = 6,
-      defaultBarSpacing = 3
-    })
-
+  ReAction:RegisterBarType(Button)
 end
 
 function module:OnDisable()
-  ReAction:UnregisterBarType(L["Totem Bar"])
+  ReAction:UnregisterBarType(Button)
 end
 
 function module:OnDestroyBar(event, bar, name)
--- a/modules/VehicleExit.lua	Fri Nov 19 15:27:23 2010 -0800
+++ b/modules/VehicleExit.lua	Fri Nov 19 23:06:24 2010 -0800
@@ -41,18 +41,11 @@
 end
 
 function module:OnEnable()
-  ReAction:RegisterBarType(L["Exit Vehicle Floater"], 
-    { 
-      type = moduleID ,
-      defaultButtonSize = 36,
-      defaultBarRows = 1,
-      defaultBarCols = 1,
-      defaultBarSpacing = 3
-    })
+  ReAction:RegisterBarType(Button)
 end
 
 function module:OnDisable()
-  ReAction:UnregisterBarType(L["Exit Vehicle Floater"])
+  ReAction:UnregisterBarType(Button)
 end
 
 function module:OnCreateBar(event, bar, name)