annotate modules/Bag.lua @ 167:eab7e7642dd6

Rewrote MultiCastButton to show prior to learning a summon ability, cleaned up implementation. NOTE: a typo fix will invalidate any existing keybindings to totem buttons.
author Flick <flickerstreak@gmail.com>
date Tue, 19 Oct 2010 16:49:40 +0000
parents 901c91dc1bf2
children df68b5a40490
rev   line source
flickerstreak@146 1 --[[
flickerstreak@146 2 ReAction Bag button module
flickerstreak@146 3
flickerstreak@146 4 --]]
flickerstreak@146 5
flickerstreak@146 6 -- local imports
flickerstreak@146 7 local ReAction = ReAction
flickerstreak@146 8 local L = ReAction.L
flickerstreak@146 9 local _G = _G
flickerstreak@146 10
flickerstreak@146 11 -- Bag button
flickerstreak@146 12 local Button = ReAction.Button.Bag
flickerstreak@146 13
flickerstreak@146 14 -- module declaration
flickerstreak@146 15 local moduleID = "Bag"
flickerstreak@146 16 local module = ReAction:NewModule( moduleID
flickerstreak@146 17 -- mixins go here
flickerstreak@146 18 )
flickerstreak@146 19
flickerstreak@146 20 -- handlers
flickerstreak@146 21 function module:OnInitialize()
flickerstreak@146 22 self.db = ReAction.db:RegisterNamespace( moduleID,
flickerstreak@146 23 {
flickerstreak@146 24 profile = {
flickerstreak@146 25 buttons = { }
flickerstreak@146 26 }
flickerstreak@146 27 }
flickerstreak@146 28 )
flickerstreak@146 29
flickerstreak@146 30 self.buttons = { }
flickerstreak@146 31
flickerstreak@146 32 ReAction.RegisterCallback(self, "OnCreateBar", "OnRefreshBar")
flickerstreak@146 33 ReAction.RegisterCallback(self, "OnDestroyBar")
flickerstreak@146 34 ReAction.RegisterCallback(self, "OnRefreshBar")
flickerstreak@146 35 ReAction.RegisterCallback(self, "OnEraseBar")
flickerstreak@146 36 ReAction.RegisterCallback(self, "OnRenameBar")
flickerstreak@146 37 end
flickerstreak@146 38
flickerstreak@146 39 function module:OnEnable()
flickerstreak@146 40 ReAction:RegisterBarType(L["Bag Bar"],
flickerstreak@146 41 {
flickerstreak@146 42 type = moduleID ,
flickerstreak@146 43 defaultButtonSize = 30,
flickerstreak@146 44 defaultBarRows = 1,
flickerstreak@146 45 defaultBarCols = 6,
flickerstreak@146 46 defaultBarSpacing = 4
flickerstreak@146 47 })
flickerstreak@146 48 end
flickerstreak@146 49
flickerstreak@146 50 function module:OnDisable()
flickerstreak@146 51 ReAction:UnregisterBarType(L["Bag Bar"])
flickerstreak@146 52 end
flickerstreak@146 53
flickerstreak@146 54 function module:OnDestroyBar(event, bar, name)
flickerstreak@146 55 local btns = self.buttons[bar]
flickerstreak@146 56 if btns then
flickerstreak@146 57 for _,b in pairs(btns) do
flickerstreak@146 58 if b then
flickerstreak@146 59 b:Destroy()
flickerstreak@146 60 end
flickerstreak@146 61 end
flickerstreak@146 62 self.buttons[bar] = nil
flickerstreak@146 63 end
flickerstreak@146 64 end
flickerstreak@146 65
flickerstreak@146 66 function module:OnRefreshBar(event, bar, name)
flickerstreak@146 67 if bar.config.type == moduleID then
flickerstreak@146 68 local btns = self.buttons[bar]
flickerstreak@146 69 if btns == nil then
flickerstreak@146 70 btns = { }
flickerstreak@146 71 self.buttons[bar] = btns
flickerstreak@146 72 end
flickerstreak@146 73 local profile = self.db.profile
flickerstreak@146 74 if profile.buttons[name] == nil then
flickerstreak@146 75 profile.buttons[name] = {}
flickerstreak@146 76 end
flickerstreak@146 77 local btnCfg = profile.buttons[name]
flickerstreak@146 78
flickerstreak@146 79 local r, c = bar:GetButtonGrid()
flickerstreak@146 80 local n = r*c
flickerstreak@146 81 for i = 1, n do
flickerstreak@146 82 if btnCfg[i] == nil then
flickerstreak@146 83 btnCfg[i] = {}
flickerstreak@146 84 end
flickerstreak@146 85 if btns[i] == nil then
flickerstreak@146 86 local success, r = pcall(Button.New,Button,i,profile,bar,i>1 and btnCfg[i-1].bagID)
flickerstreak@146 87 if success and r then
flickerstreak@146 88 btns[i] = r
flickerstreak@146 89 bar:AddButton(i,r)
flickerstreak@146 90 else
flickerstreak@146 91 n = i - 1
flickerstreak@146 92 bar:ClipNButtons(n)
flickerstreak@146 93 break
flickerstreak@146 94 end
flickerstreak@146 95 end
flickerstreak@146 96 btns[i]:Refresh()
flickerstreak@146 97 end
flickerstreak@146 98 for i = n+1, #btns do
flickerstreak@146 99 if btns[i] then
flickerstreak@146 100 bar:RemoveButton(btns[i])
flickerstreak@146 101 btns[i] = btns[i]:Destroy()
flickerstreak@146 102 if btnCfg[i] then
flickerstreak@146 103 btnCfg[i] = nil
flickerstreak@146 104 end
flickerstreak@146 105 end
flickerstreak@146 106 end
flickerstreak@146 107 end
flickerstreak@146 108
flickerstreak@146 109 end
flickerstreak@146 110
flickerstreak@146 111 function module:OnEraseBar(event, bar, name)
flickerstreak@146 112 self.db.profile.buttons[name] = nil
flickerstreak@146 113 end
flickerstreak@146 114
flickerstreak@146 115 function module:OnRenameBar(event, bar, oldName, newName)
flickerstreak@146 116 local b = self.db.profile.buttons
flickerstreak@146 117 b[newname], b[oldname] = b[oldname], nil
flickerstreak@146 118 end
flickerstreak@146 119
flickerstreak@146 120
flickerstreak@146 121 -- hook some functions to propagate to our bag buttons
flickerstreak@146 122 hooksecurefunc("Disable_BagButtons",
flickerstreak@146 123 function()
flickerstreak@146 124 for _, buttons in pairs(module.buttons) do
flickerstreak@146 125 for _, b in pairs(buttons) do
flickerstreak@146 126 local f = b:GetFrame()
flickerstreak@146 127 f:Disable()
flickerstreak@146 128 SetDesaturation(b.frames.icon,1)
flickerstreak@146 129 end
flickerstreak@146 130 end
flickerstreak@146 131 end)
flickerstreak@146 132
flickerstreak@146 133 hooksecurefunc("Enable_BagButtons",
flickerstreak@146 134 function()
flickerstreak@146 135 for _, buttons in pairs(module.buttons) do
flickerstreak@146 136 for _, b in pairs(buttons) do
flickerstreak@146 137 local f = b:GetFrame()
flickerstreak@146 138 f:Enable()
flickerstreak@146 139 SetDesaturation(b.frames.icon,nil)
flickerstreak@146 140 end
flickerstreak@146 141 end
flickerstreak@146 142 end)
flickerstreak@146 143
flickerstreak@146 144 hooksecurefunc("ContainerFrame_OnHide",
flickerstreak@146 145 function()
flickerstreak@146 146 for _, buttons in pairs(module.buttons) do
flickerstreak@146 147 for _, b in pairs(buttons) do
flickerstreak@146 148 b:Update()
flickerstreak@146 149 end
flickerstreak@146 150 end
flickerstreak@146 151 end)
flickerstreak@146 152
flickerstreak@146 153 hooksecurefunc("ContainerFrame_OnShow",
flickerstreak@146 154 function()
flickerstreak@146 155 for _, buttons in pairs(module.buttons) do
flickerstreak@146 156 for _, b in pairs(buttons) do
flickerstreak@146 157 b:Update()
flickerstreak@146 158 end
flickerstreak@146 159 end
flickerstreak@146 160 end)