diff modules/ReAction_PetAction/ReAction_PetAction.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 44649a10378d
children 06cd74bdc7da
line wrap: on
line diff
--- a/modules/ReAction_PetAction/ReAction_PetAction.lua	Tue May 13 16:42:52 2008 +0000
+++ b/modules/ReAction_PetAction/ReAction_PetAction.lua	Thu May 22 22:02:08 2008 +0000
@@ -27,7 +27,15 @@
     }
   )
   self.buttons = { }
-  self.options = setmetatable({},{__mode="k"})
+
+  ReAction:RegisterBarOptionGenerator(self, "GetBarOptions")
+
+  ReAction.RegisterCallback(self, "OnCreateBar")
+  ReAction.RegisterCallback(self, "OnDestroyBar")
+  ReAction.RegisterCallback(self, "OnRefreshBar")
+  ReAction.RegisterCallback(self, "OnEraseBar")
+  ReAction.RegisterCallback(self, "OnRenameBar")
+  ReAction.RegisterCallback(self, "OnConfigModeChanged")
 end
 
 function module:OnEnable()
@@ -45,27 +53,26 @@
   ReAction:UnregisterBarType(L["Pet Action Bar"])
 end
 
-function module:ApplyToBar(bar)
+function module:OnCreateBar(event, bar, name)
   if bar.config.type == moduleID then
     -- auto show/hide when pet exists
     bar:GetFrame():SetAttribute("unit","pet")
     RegisterUnitWatch(bar:GetFrame())
-    self:RefreshBar(bar)
+    self:OnRefreshBar(event, bar, name)
   end
 end
 
-function module:RefreshBar(bar)
+function module:OnRefreshBar(event, bar, name)
   if bar.config.type == moduleID 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] = {}
+    if profile.buttons[name] == nil then
+      profile.buttons[name] = {}
     end
-    local btnCfg = profile.buttons[barName]
+    local btnCfg = profile.buttons[name]
 
     local r, c = bar:GetButtonGrid()
     local n = r*c
@@ -93,7 +100,7 @@
   end
 end
 
-function module:RemoveFromBar(bar)
+function module:OnDestroyBar(event, bar, name)
   if self.buttons[bar] then
     local btns = self.buttons[bar]
     for _,b in pairs(btns) do
@@ -105,18 +112,18 @@
   end
 end
 
-function module:EraseBarConfig(barName)
-  self.db.profile.buttons[barName] = nil
+function module:OnEraseBar(event, bar, name)
+  self.db.profile.buttons[name] = nil
 end
 
-function module:RenameBarConfig(oldname, newname)
+function module:OnRenameBar(event, bar, oldname, newname)
   local b = self.db.profile.buttons
   b[newname], b[oldname] = b[oldname], nil
 end
 
 
-function module:ApplyConfigMode(mode,bars)
-  for _, bar in pairs(bars) do
+function module:OnConfigModeChanged(event, mode)
+  for _, bar in ReAction:IterateBars() do
     if bar and self.buttons[bar] then
       for _, b in pairs(self.buttons[bar]) do
         if b then
@@ -160,16 +167,13 @@
 
 ---- Options ----
 function module:GetBarOptions(bar)
-  if not self.options[bar] then
-    self.options[bar] = {
-      type = "group",
-      name = L["Pet Buttons"],
-      hidden = function() return bar.config.type ~= moduleID end,
-      args = {
-      }
+  return {
+    type = "group",
+    name = L["Pet Buttons"],
+    hidden = function() return bar.config.type ~= moduleID end,
+    args = {
     }
-  end
-  return self.options[bar]
+  }
 end