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.buttons = { } flickerstreak@161: flickerstreak@161: ReAction.RegisterCallback(self, "OnCreateBar", "OnRefreshBar") flickerstreak@161: ReAction.RegisterCallback(self, "OnDestroyBar") flickerstreak@161: ReAction.RegisterCallback(self, "OnRefreshBar") flickerstreak@161: flickerstreak@162: self:RegisterEvent("UPDATE_MULTI_CAST_ACTIONBAR","PLAYER_ENTERING_WORLD") 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@222: local config = bar:GetConfig() flickerstreak@222: if 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@222: if not config.buttons then flickerstreak@222: config.buttons = { } flickerstreak@161: end flickerstreak@222: local btnCfg = config.buttons 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@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: