annotate modules/Stance.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@134 1 --[[
flickerstreak@134 2 ReAction Stance button module
flickerstreak@134 3
flickerstreak@134 4 --]]
flickerstreak@134 5
flickerstreak@134 6 -- local imports
flickerstreak@175 7 local addonName, addonTable = ...
flickerstreak@175 8 local ReAction = addonTable.ReAction
flickerstreak@134 9 local L = ReAction.L
flickerstreak@134 10 local _G = _G
flickerstreak@134 11
flickerstreak@134 12 -- Stance button
flickerstreak@134 13 local Button = ReAction.Button.Stance
flickerstreak@134 14
flickerstreak@134 15 -- module declaration
flickerstreak@134 16 local moduleID = "Stance"
flickerstreak@134 17 local module = ReAction:NewModule( moduleID
flickerstreak@134 18 -- mixins go here
flickerstreak@134 19 )
flickerstreak@134 20
flickerstreak@134 21 -- handlers
flickerstreak@134 22 function module:OnInitialize()
flickerstreak@134 23 self.buttons = { }
flickerstreak@134 24
flickerstreak@134 25 ReAction.RegisterCallback(self, "OnCreateBar", "OnRefreshBar")
flickerstreak@134 26 ReAction.RegisterCallback(self, "OnDestroyBar")
flickerstreak@134 27 ReAction.RegisterCallback(self, "OnRefreshBar")
flickerstreak@134 28 end
flickerstreak@134 29
flickerstreak@134 30 function module:OnEnable()
flickerstreak@218 31 ReAction:RegisterBarType(Button)
flickerstreak@134 32 end
flickerstreak@134 33
flickerstreak@134 34 function module:OnDisable()
flickerstreak@218 35 ReAction:UnregisterBarType(Button)
flickerstreak@134 36 end
flickerstreak@134 37
flickerstreak@134 38 function module:OnDestroyBar(event, bar, name)
flickerstreak@134 39 local btns = self.buttons[bar]
flickerstreak@134 40 if btns then
flickerstreak@134 41 for _,b in pairs(btns) do
flickerstreak@134 42 if b then
flickerstreak@134 43 b:Destroy()
flickerstreak@134 44 end
flickerstreak@134 45 end
flickerstreak@134 46 self.buttons[bar] = nil
flickerstreak@134 47 end
flickerstreak@134 48 end
flickerstreak@134 49
flickerstreak@134 50 function module:OnRefreshBar(event, bar, name)
flickerstreak@222 51 local config = bar:GetConfig()
flickerstreak@222 52 if config.type == moduleID then
flickerstreak@134 53 local btns = self.buttons[bar]
flickerstreak@134 54 if btns == nil then
flickerstreak@134 55 btns = { }
flickerstreak@134 56 self.buttons[bar] = btns
flickerstreak@134 57 end
flickerstreak@222 58 if not config.buttons then
flickerstreak@222 59 config.buttons = { }
flickerstreak@134 60 end
flickerstreak@222 61 local btnCfg = config.buttons
flickerstreak@134 62
flickerstreak@134 63 local r, c = bar:GetButtonGrid()
flickerstreak@134 64 local n = r*c
flickerstreak@134 65 for i = 1, n do
flickerstreak@134 66 if btnCfg[i] == nil then
flickerstreak@134 67 btnCfg[i] = {}
flickerstreak@134 68 end
flickerstreak@134 69 if btns[i] == nil then
flickerstreak@222 70 local success, r = pcall(Button.New,Button,i,btnCfg,bar,i>1 and btnCfg[i-1].stanceID)
flickerstreak@134 71 if success and r then
flickerstreak@134 72 btns[i] = r
flickerstreak@134 73 bar:AddButton(i,r)
flickerstreak@134 74 else
flickerstreak@134 75 n = i - 1
flickerstreak@134 76 bar:ClipNButtons(n)
flickerstreak@134 77 break
flickerstreak@134 78 end
flickerstreak@134 79 end
flickerstreak@134 80 btns[i]:Refresh()
flickerstreak@134 81 end
flickerstreak@134 82 for i = n+1, #btns do
flickerstreak@134 83 if btns[i] then
flickerstreak@134 84 bar:RemoveButton(btns[i])
flickerstreak@134 85 btns[i] = btns[i]:Destroy()
flickerstreak@134 86 if btnCfg[i] then
flickerstreak@134 87 btnCfg[i] = nil
flickerstreak@134 88 end
flickerstreak@134 89 end
flickerstreak@134 90 end
flickerstreak@134 91 end
flickerstreak@134 92
flickerstreak@134 93 end
flickerstreak@134 94