annotate modules/Totem.lua @ 222:d08a74e86c96

un-namespace totem, pet, stance, vehicle exit
author Flick <flickerstreak@gmail.com>
date Sun, 21 Nov 2010 14:42:38 -0800
parents e63aefb8a555
children c4b134512c50
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:OnEnable()
flickerstreak@218 34 ReAction:RegisterBarType(Button)
flickerstreak@161 35 end
flickerstreak@161 36
flickerstreak@161 37 function module:OnDisable()
flickerstreak@218 38 ReAction:UnregisterBarType(Button)
flickerstreak@161 39 end
flickerstreak@161 40
flickerstreak@161 41 function module:OnDestroyBar(event, bar, name)
flickerstreak@161 42 local btns = self.buttons[bar]
flickerstreak@161 43 if btns then
flickerstreak@161 44 for _,b in pairs(btns) do
flickerstreak@161 45 if b then
flickerstreak@161 46 b:Destroy()
flickerstreak@161 47 end
flickerstreak@161 48 end
flickerstreak@161 49 self.buttons[bar] = nil
flickerstreak@161 50 end
flickerstreak@161 51 end
flickerstreak@161 52
flickerstreak@161 53 function module:OnRefreshBar(event, bar, name)
flickerstreak@222 54 local config = bar:GetConfig()
flickerstreak@222 55 if config.type == moduleID then
flickerstreak@161 56 local btns = self.buttons[bar]
flickerstreak@161 57 if btns == nil then
flickerstreak@161 58 btns = { }
flickerstreak@161 59 self.buttons[bar] = btns
flickerstreak@161 60 end
flickerstreak@222 61 if not config.buttons then
flickerstreak@222 62 config.buttons = { }
flickerstreak@161 63 end
flickerstreak@222 64 local btnCfg = config.buttons
flickerstreak@161 65
flickerstreak@161 66 local r, c = bar:GetButtonGrid()
flickerstreak@163 67 local n = min(r*c,6)
flickerstreak@163 68 Button.SetupBarHeader(bar)
flickerstreak@161 69 for i = 1, n do
flickerstreak@161 70 if btnCfg[i] == nil then
flickerstreak@161 71 btnCfg[i] = {}
flickerstreak@161 72 end
flickerstreak@164 73 if not btns[i] then
flickerstreak@161 74 local success, r = pcall(Button.New,Button,i,btnCfg,bar)
flickerstreak@163 75 if success then
flickerstreak@161 76 btns[i] = r
flickerstreak@163 77 if r then
flickerstreak@163 78 bar:AddButton(i,r)
flickerstreak@163 79 end
flickerstreak@161 80 else
flickerstreak@161 81 geterrorhandler()(r)
flickerstreak@161 82 n = i - 1
flickerstreak@161 83 bar:ClipNButtons(n)
flickerstreak@161 84 break
flickerstreak@161 85 end
flickerstreak@161 86 end
flickerstreak@163 87 if btns[i] then
flickerstreak@163 88 btns[i]:Refresh()
flickerstreak@163 89 end
flickerstreak@161 90 end
flickerstreak@161 91 for i = n+1, #btns do
flickerstreak@161 92 if btns[i] then
flickerstreak@161 93 bar:RemoveButton(btns[i])
flickerstreak@161 94 btns[i] = btns[i]:Destroy()
flickerstreak@161 95 if btnCfg[i] then
flickerstreak@161 96 btnCfg[i] = nil
flickerstreak@161 97 end
flickerstreak@161 98 end
flickerstreak@161 99 end
flickerstreak@161 100 end
flickerstreak@161 101
flickerstreak@161 102 end
flickerstreak@161 103
flickerstreak@162 104 function module:UPDATE_MULTI_CAST_ACTIONBAR()
flickerstreak@162 105 if not InCombatLockdown() then
flickerstreak@162 106 for bar in pairs(self.buttons) do
flickerstreak@162 107 self:OnRefreshBar("OnRefreshBar", bar, bar:GetName())
flickerstreak@162 108 end
flickerstreak@162 109 end
flickerstreak@162 110 end
flickerstreak@162 111
flickerstreak@162 112 function module:PLAYER_ENTERING_WORLD()
flickerstreak@162 113 for bar in pairs(self.buttons) do
flickerstreak@162 114 self:OnRefreshBar("OnRefreshBar", bar, bar:GetName())
flickerstreak@162 115 end
flickerstreak@162 116 end
flickerstreak@162 117
flickerstreak@161 118