annotate modules/Totem.lua @ 229:b4c100011c75

don't register state namespace now that it's not being used
author Flick
date Tue, 22 Mar 2011 11:13:53 -0700
parents c4b134512c50
children
rev   line source
flickerstreak@161 1 --[[
flickerstreak@161 2 ReAction Totem button module
flickerstreak@161 3
flickerstreak@161 4 --]]
flickerstreak@161 5
flickerstreak@161 6 -- local imports
flickerstreak@175 7 local addonName, addonTable = ...
flickerstreak@175 8 local ReAction = addonTable.ReAction
flickerstreak@161 9 local L = ReAction.L
flickerstreak@161 10 local _G = _G
flickerstreak@161 11
flickerstreak@161 12 -- button
flickerstreak@161 13 local Button = ReAction.Button.MultiCast
flickerstreak@161 14
flickerstreak@161 15 -- module declaration
flickerstreak@161 16 local moduleID = "Totem"
flickerstreak@161 17 local module = ReAction:NewModule( moduleID,
flickerstreak@161 18 "AceEvent-3.0"
flickerstreak@161 19 -- mixins go here
flickerstreak@161 20 )
flickerstreak@161 21
flickerstreak@161 22 -- handlers
flickerstreak@161 23 function module:OnInitialize()
flickerstreak@161 24 self.buttons = { }
flickerstreak@161 25
flickerstreak@161 26 ReAction.RegisterCallback(self, "OnCreateBar", "OnRefreshBar")
flickerstreak@161 27 ReAction.RegisterCallback(self, "OnDestroyBar")
flickerstreak@161 28 ReAction.RegisterCallback(self, "OnRefreshBar")
flickerstreak@161 29
flickerstreak@162 30 self:RegisterEvent("UPDATE_MULTI_CAST_ACTIONBAR","PLAYER_ENTERING_WORLD")
flickerstreak@161 31 end
flickerstreak@161 32
flickerstreak@161 33 function module:OnDestroyBar(event, bar, name)
flickerstreak@161 34 local btns = self.buttons[bar]
flickerstreak@161 35 if btns then
flickerstreak@161 36 for _,b in pairs(btns) do
flickerstreak@161 37 if b then
flickerstreak@161 38 b:Destroy()
flickerstreak@161 39 end
flickerstreak@161 40 end
flickerstreak@161 41 self.buttons[bar] = nil
flickerstreak@161 42 end
flickerstreak@161 43 end
flickerstreak@161 44
flickerstreak@161 45 function module:OnRefreshBar(event, bar, name)
flickerstreak@222 46 local config = bar:GetConfig()
flickerstreak@222 47 if config.type == moduleID then
flickerstreak@161 48 local btns = self.buttons[bar]
flickerstreak@161 49 if btns == nil then
flickerstreak@161 50 btns = { }
flickerstreak@161 51 self.buttons[bar] = btns
flickerstreak@161 52 end
flickerstreak@222 53 if not config.buttons then
flickerstreak@222 54 config.buttons = { }
flickerstreak@161 55 end
flickerstreak@222 56 local btnCfg = config.buttons
flickerstreak@161 57
flickerstreak@161 58 local r, c = bar:GetButtonGrid()
flickerstreak@163 59 local n = min(r*c,6)
flickerstreak@163 60 Button.SetupBarHeader(bar)
flickerstreak@161 61 for i = 1, n do
flickerstreak@161 62 if btnCfg[i] == nil then
flickerstreak@161 63 btnCfg[i] = {}
flickerstreak@161 64 end
flickerstreak@164 65 if not btns[i] then
flickerstreak@161 66 local success, r = pcall(Button.New,Button,i,btnCfg,bar)
flickerstreak@163 67 if success then
flickerstreak@161 68 btns[i] = r
flickerstreak@163 69 if r then
flickerstreak@163 70 bar:AddButton(i,r)
flickerstreak@163 71 end
flickerstreak@161 72 else
flickerstreak@161 73 geterrorhandler()(r)
flickerstreak@161 74 n = i - 1
flickerstreak@161 75 bar:ClipNButtons(n)
flickerstreak@161 76 break
flickerstreak@161 77 end
flickerstreak@161 78 end
flickerstreak@163 79 if btns[i] then
flickerstreak@163 80 btns[i]:Refresh()
flickerstreak@163 81 end
flickerstreak@161 82 end
flickerstreak@161 83 for i = n+1, #btns do
flickerstreak@161 84 if btns[i] then
flickerstreak@161 85 bar:RemoveButton(btns[i])
flickerstreak@161 86 btns[i] = btns[i]:Destroy()
flickerstreak@161 87 if btnCfg[i] then
flickerstreak@161 88 btnCfg[i] = nil
flickerstreak@161 89 end
flickerstreak@161 90 end
flickerstreak@161 91 end
flickerstreak@161 92 end
flickerstreak@161 93
flickerstreak@161 94 end
flickerstreak@161 95
flickerstreak@162 96 function module:UPDATE_MULTI_CAST_ACTIONBAR()
flickerstreak@162 97 if not InCombatLockdown() then
flickerstreak@162 98 for bar in pairs(self.buttons) do
flickerstreak@162 99 self:OnRefreshBar("OnRefreshBar", bar, bar:GetName())
flickerstreak@162 100 end
flickerstreak@162 101 end
flickerstreak@162 102 end
flickerstreak@162 103
flickerstreak@162 104 function module:PLAYER_ENTERING_WORLD()
flickerstreak@162 105 for bar in pairs(self.buttons) do
flickerstreak@162 106 self:OnRefreshBar("OnRefreshBar", bar, bar:GetName())
flickerstreak@162 107 end
flickerstreak@162 108 end
flickerstreak@162 109
flickerstreak@161 110