Mercurial > wow > reaction
diff modules/ReAction_Action/ReAction_Action.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_Action/ReAction_Action.lua Tue May 13 16:42:52 2008 +0000 +++ b/modules/ReAction_Action/ReAction_Action.lua Thu May 22 22:02:08 2008 +0000 @@ -27,7 +27,6 @@ } ) self.buttons = { } - self.options = setmetatable({},{__mode="k"}) ReAction:RegisterOptions(self, { [moduleID] = { @@ -43,6 +42,16 @@ } } }) + + ReAction:RegisterBarOptionGenerator(self, "GetBarOptions") + + ReAction.RegisterCallback(self, "OnCreateBar", "OnRefreshBar") + ReAction.RegisterCallback(self, "OnDestroyBar") + ReAction.RegisterCallback(self, "OnRefreshBar") + ReAction.RegisterCallback(self, "OnEraseBar") + ReAction.RegisterCallback(self, "OnRenameBar") + ReAction.RegisterCallback(self, "OnConfigModeChanged") + end function module:OnEnable() @@ -60,22 +69,17 @@ ReAction:UnregisterBarType(L["Action Bar"]) end -function module:ApplyToBar(bar) - self:RefreshBar(bar) -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 @@ -103,7 +107,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 @@ -115,11 +119,11 @@ 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 @@ -139,8 +143,8 @@ end 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 @@ -179,16 +183,13 @@ ---- Options ---- function module:GetBarOptions(bar) - if not self.options[bar] then - self.options[bar] = { - type = "group", - name = L["Action Buttons"], - hidden = function() return bar.config.type ~= moduleID end, - args = { - } + return { + type = "group", + name = L["Action Buttons"], + hidden = function() return bar.config.type ~= moduleID end, + args = { } - end - return self.options[bar] + } end