flickerstreak@161: --[[ flickerstreak@161: ReAction Totem button module flickerstreak@161: flickerstreak@161: --]] flickerstreak@161: flickerstreak@161: -- local imports flickerstreak@161: local ReAction = ReAction flickerstreak@161: local L = ReAction.L flickerstreak@161: local _G = _G flickerstreak@161: flickerstreak@161: -- button flickerstreak@161: local Button = ReAction.Button.MultiCast flickerstreak@161: flickerstreak@161: -- module declaration flickerstreak@161: local moduleID = "Totem" flickerstreak@161: local module = ReAction:NewModule( moduleID, flickerstreak@161: "AceEvent-3.0" flickerstreak@161: -- mixins go here flickerstreak@161: ) flickerstreak@161: flickerstreak@161: -- handlers flickerstreak@161: function module:OnInitialize() flickerstreak@161: self.db = ReAction.db:RegisterNamespace( moduleID, flickerstreak@161: { flickerstreak@161: profile = { flickerstreak@161: buttons = { } flickerstreak@161: } flickerstreak@161: } flickerstreak@161: ) flickerstreak@161: flickerstreak@161: self.buttons = { } flickerstreak@161: flickerstreak@161: ReAction:RegisterOptions(self, self:GetOptions()) flickerstreak@161: flickerstreak@161: ReAction.RegisterCallback(self, "OnCreateBar", "OnRefreshBar") flickerstreak@161: ReAction.RegisterCallback(self, "OnDestroyBar") flickerstreak@161: ReAction.RegisterCallback(self, "OnRefreshBar") flickerstreak@161: ReAction.RegisterCallback(self, "OnEraseBar") flickerstreak@161: ReAction.RegisterCallback(self, "OnRenameBar") flickerstreak@161: flickerstreak@161: -- TODO: register for learning new spells flickerstreak@161: end flickerstreak@161: flickerstreak@161: function module:OnEnable() flickerstreak@161: ReAction:RegisterBarType(L["Totem Bar"], flickerstreak@161: { flickerstreak@161: type = moduleID , flickerstreak@161: defaultButtonSize = 36, flickerstreak@161: defaultBarRows = 1, flickerstreak@161: defaultBarCols = 6, flickerstreak@161: defaultBarSpacing = 3 flickerstreak@161: }) flickerstreak@161: flickerstreak@161: end flickerstreak@161: flickerstreak@161: function module:OnDisable() flickerstreak@161: ReAction:UnregisterBarType(L["Totem Bar"]) flickerstreak@161: end flickerstreak@161: flickerstreak@161: function module:OnDestroyBar(event, bar, name) flickerstreak@161: local btns = self.buttons[bar] flickerstreak@161: if btns then flickerstreak@161: for _,b in pairs(btns) do flickerstreak@161: if b then flickerstreak@161: b:Destroy() flickerstreak@161: end flickerstreak@161: end flickerstreak@161: self.buttons[bar] = nil flickerstreak@161: end flickerstreak@161: end flickerstreak@161: flickerstreak@161: function module:OnRefreshBar(event, bar, name) flickerstreak@161: if bar.config.type == moduleID then flickerstreak@161: local btns = self.buttons[bar] flickerstreak@161: if btns == nil then flickerstreak@161: btns = { } flickerstreak@161: self.buttons[bar] = btns flickerstreak@161: end flickerstreak@161: local profile = self.db.profile flickerstreak@161: if profile.buttons[name] == nil then flickerstreak@161: profile.buttons[name] = {} flickerstreak@161: end flickerstreak@161: local btnCfg = profile.buttons[name] flickerstreak@161: flickerstreak@161: local r, c = bar:GetButtonGrid() flickerstreak@161: local n = r*c flickerstreak@161: n = min(n,Button.SetupBarHeader(bar)) flickerstreak@161: for i = 1, n do flickerstreak@161: if btnCfg[i] == nil then flickerstreak@161: btnCfg[i] = {} flickerstreak@161: end flickerstreak@161: if btns[i] == nil then flickerstreak@161: local success, r = pcall(Button.New,Button,i,btnCfg,bar) flickerstreak@161: if success and r then flickerstreak@161: btns[i] = r flickerstreak@161: bar:AddButton(i,r) flickerstreak@161: else flickerstreak@161: geterrorhandler()(r) flickerstreak@161: n = i - 1 flickerstreak@161: bar:ClipNButtons(n) flickerstreak@161: break flickerstreak@161: end flickerstreak@161: end flickerstreak@161: btns[i]:Refresh() flickerstreak@161: end flickerstreak@161: for i = n+1, #btns do flickerstreak@161: if btns[i] then flickerstreak@161: bar:RemoveButton(btns[i]) flickerstreak@161: btns[i] = btns[i]:Destroy() flickerstreak@161: if btnCfg[i] then flickerstreak@161: btnCfg[i] = nil flickerstreak@161: end flickerstreak@161: end flickerstreak@161: end flickerstreak@161: end flickerstreak@161: flickerstreak@161: end flickerstreak@161: flickerstreak@161: function module:OnEraseBar(event, bar, name) flickerstreak@161: self.db.profile.buttons[name] = nil flickerstreak@161: end flickerstreak@161: flickerstreak@161: function module:OnRenameBar(event, bar, oldName, newName) flickerstreak@161: local b = self.db.profile.buttons flickerstreak@161: b[newname], b[oldname] = b[oldname], nil flickerstreak@161: end flickerstreak@161: flickerstreak@161: function module:RefreshAll() flickerstreak@161: for bar in pairs(self.buttons) do flickerstreak@161: self:OnRefreshBar(nil,bar,bar:GetName()) flickerstreak@161: end flickerstreak@161: end flickerstreak@161: flickerstreak@161: flickerstreak@161: ---- options ---- flickerstreak@161: function module:GetOptions() flickerstreak@161: return { flickerstreak@161: stance = flickerstreak@161: { flickerstreak@161: name = L["Totem Buttons"], flickerstreak@161: type = "group", flickerstreak@161: args = { flickerstreak@161: -- TODO flickerstreak@161: } flickerstreak@161: } flickerstreak@161: } flickerstreak@161: end