flickerstreak@161: --[[ flickerstreak@161: ReAction Totem button module flickerstreak@161: flickerstreak@161: --]] flickerstreak@161: flickerstreak@161: -- local imports flickerstreak@175: local addonName, addonTable = ... flickerstreak@175: local ReAction = addonTable.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.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@162: self:RegisterEvent("UPDATE_MULTI_CAST_ACTIONBAR","PLAYER_ENTERING_WORLD") 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@163: local n = min(r*c,6) flickerstreak@163: 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@164: if not btns[i] then flickerstreak@161: local success, r = pcall(Button.New,Button,i,btnCfg,bar) flickerstreak@163: if success then flickerstreak@161: btns[i] = r flickerstreak@163: if r then flickerstreak@163: bar:AddButton(i,r) flickerstreak@163: end 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@163: if btns[i] then flickerstreak@163: btns[i]:Refresh() flickerstreak@163: end 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@162: function module:UPDATE_MULTI_CAST_ACTIONBAR() flickerstreak@162: if not InCombatLockdown() then flickerstreak@162: for bar in pairs(self.buttons) do flickerstreak@162: self:OnRefreshBar("OnRefreshBar", bar, bar:GetName()) flickerstreak@162: end flickerstreak@162: end flickerstreak@162: end flickerstreak@162: flickerstreak@162: function module:PLAYER_ENTERING_WORLD() flickerstreak@162: for bar in pairs(self.buttons) do flickerstreak@162: self:OnRefreshBar("OnRefreshBar", bar, bar:GetName()) flickerstreak@162: end flickerstreak@162: end flickerstreak@162: flickerstreak@161: