flickerstreak@134: --[[ flickerstreak@134: ReAction Stance button module flickerstreak@134: flickerstreak@134: --]] flickerstreak@134: flickerstreak@134: -- local imports flickerstreak@175: local addonName, addonTable = ... flickerstreak@175: local ReAction = addonTable.ReAction flickerstreak@134: local L = ReAction.L flickerstreak@134: local _G = _G flickerstreak@134: flickerstreak@134: -- Stance button flickerstreak@134: local Button = ReAction.Button.Stance flickerstreak@134: flickerstreak@134: -- module declaration flickerstreak@134: local moduleID = "Stance" flickerstreak@134: local module = ReAction:NewModule( moduleID flickerstreak@134: -- mixins go here flickerstreak@134: ) flickerstreak@134: flickerstreak@134: -- handlers flickerstreak@134: function module:OnInitialize() flickerstreak@134: self.db = ReAction.db:RegisterNamespace( moduleID, flickerstreak@134: { flickerstreak@134: profile = { flickerstreak@134: buttons = { } flickerstreak@134: } flickerstreak@134: } flickerstreak@134: ) flickerstreak@134: flickerstreak@134: self.buttons = { } flickerstreak@134: flickerstreak@134: ReAction.RegisterCallback(self, "OnCreateBar", "OnRefreshBar") flickerstreak@134: ReAction.RegisterCallback(self, "OnDestroyBar") flickerstreak@134: ReAction.RegisterCallback(self, "OnRefreshBar") flickerstreak@134: ReAction.RegisterCallback(self, "OnEraseBar") flickerstreak@134: ReAction.RegisterCallback(self, "OnRenameBar") flickerstreak@134: end flickerstreak@134: flickerstreak@134: function module:OnEnable() flickerstreak@218: ReAction:RegisterBarType(Button) flickerstreak@134: end flickerstreak@134: flickerstreak@134: function module:OnDisable() flickerstreak@218: ReAction:UnregisterBarType(Button) flickerstreak@134: end flickerstreak@134: flickerstreak@134: function module:OnDestroyBar(event, bar, name) flickerstreak@134: local btns = self.buttons[bar] flickerstreak@134: if btns then flickerstreak@134: for _,b in pairs(btns) do flickerstreak@134: if b then flickerstreak@134: b:Destroy() flickerstreak@134: end flickerstreak@134: end flickerstreak@134: self.buttons[bar] = nil flickerstreak@134: end flickerstreak@134: end flickerstreak@134: flickerstreak@134: function module:OnRefreshBar(event, bar, name) flickerstreak@134: if bar.config.type == moduleID then flickerstreak@134: local btns = self.buttons[bar] flickerstreak@134: if btns == nil then flickerstreak@134: btns = { } flickerstreak@134: self.buttons[bar] = btns flickerstreak@134: end flickerstreak@134: local profile = self.db.profile flickerstreak@134: if profile.buttons[name] == nil then flickerstreak@134: profile.buttons[name] = {} flickerstreak@134: end flickerstreak@134: local btnCfg = profile.buttons[name] flickerstreak@134: flickerstreak@134: local r, c = bar:GetButtonGrid() flickerstreak@134: local n = r*c flickerstreak@134: for i = 1, n do flickerstreak@134: if btnCfg[i] == nil then flickerstreak@134: btnCfg[i] = {} flickerstreak@134: end flickerstreak@134: if btns[i] == nil then flickerstreak@134: local success, r = pcall(Button.New,Button,i,profile,bar,i>1 and btnCfg[i-1].stanceID) flickerstreak@134: if success and r then flickerstreak@134: btns[i] = r flickerstreak@134: bar:AddButton(i,r) flickerstreak@134: else flickerstreak@134: n = i - 1 flickerstreak@134: bar:ClipNButtons(n) flickerstreak@134: break flickerstreak@134: end flickerstreak@134: end flickerstreak@134: btns[i]:Refresh() flickerstreak@134: end flickerstreak@134: for i = n+1, #btns do flickerstreak@134: if btns[i] then flickerstreak@134: bar:RemoveButton(btns[i]) flickerstreak@134: btns[i] = btns[i]:Destroy() flickerstreak@134: if btnCfg[i] then flickerstreak@134: btnCfg[i] = nil flickerstreak@134: end flickerstreak@134: end flickerstreak@134: end flickerstreak@134: end flickerstreak@134: flickerstreak@134: end flickerstreak@134: flickerstreak@134: function module:OnEraseBar(event, bar, name) flickerstreak@134: self.db.profile.buttons[name] = nil flickerstreak@134: end flickerstreak@134: flickerstreak@134: function module:OnRenameBar(event, bar, oldName, newName) flickerstreak@134: local b = self.db.profile.buttons flickerstreak@134: b[newname], b[oldname] = b[oldname], nil flickerstreak@134: end flickerstreak@134: flickerstreak@134: function module:RefreshAll() flickerstreak@134: for bar in pairs(self.buttons) do flickerstreak@134: self:OnRefreshBar(nil,bar,bar:GetName()) flickerstreak@134: end flickerstreak@134: end flickerstreak@134: