comparison classes/BagButton.lua @ 234:0e20f65375d5

Reworked button creation to not use goofy event driven semantics.
author Flick
date Tue, 22 Mar 2011 17:05:51 -0700
parents 158c9299185b
children
comparison
equal deleted inserted replaced
233:9b9f5fc84d34 234:0e20f65375d5
14 local PickupBagFromSlot = PickupBagFromSlot 14 local PickupBagFromSlot = PickupBagFromSlot
15 local CursorCanGoInSlot = CursorCanGoInSlot 15 local CursorCanGoInSlot = CursorCanGoInSlot
16 16
17 -- class declarations 17 -- class declarations
18 local buttonTypeID = "Bag" 18 local buttonTypeID = "Bag"
19 local weak = { __mode = "k" }
19 local Super = ReAction.Button 20 local Super = ReAction.Button
20 local BagBase = setmetatable( 21 local BagBase = setmetatable(
21 { 22 {
22 defaultBarConfig = { 23 defaultBarConfig = {
23 type = buttonTypeID, 24 type = buttonTypeID,
28 spacing = 4, 29 spacing = 4,
29 buttons = { } 30 buttons = { }
30 }, 31 },
31 32
32 barType = L["Bag Bar"], 33 barType = L["Bag Bar"],
33 buttonTypeID = buttonTypeID 34 buttonTypeID = buttonTypeID,
35
36 allButtons = setmetatable( { }, weak )
34 }, 37 },
35 { __index = Super } ) 38 { __index = Super } )
36 39
37 local Bag = setmetatable( { }, { __index = BagBase } ) 40 local Bag = setmetatable( { }, { __index = BagBase } )
38 local Backpack = setmetatable( { }, { __index = BagBase } ) 41 local Backpack = setmetatable( { }, { __index = BagBase } )
43 46
44 -- 47 --
45 -- Bag Button base class 48 -- Bag Button base class
46 -- 49 --
47 50
48 function BagBase:New( idx, btnCfg, bar, idHint ) 51 function BagBase:New( btnCfg, bar, idx, idHint )
49 local name = format("ReAction_%s_Bag_%d",bar:GetName(),idx) 52 local name = format("ReAction_%s_Bag_%d",bar:GetName(),idx)
50 53
51 -- use a variable private leaf implementation class 54 -- use a variable private leaf implementation class
52 -- unlike traditional OO programming, we can initialize the leaf 55 -- unlike traditional OO programming, we can initialize the leaf
53 -- class before initializing its parent 56 -- class before initializing its parent
123 self:GetFrame():Show() 126 self:GetFrame():Show()
124 end 127 end
125 128
126 self:Refresh() 129 self:Refresh()
127 130
131 BagBase.allButtons[self] = true
132
128 return self 133 return self
129 end 134 end
135
136 function BagBase:Destroy()
137 BagBase.allButtons[self] = nil
138 Super.Destroy(self)
139 end
140
130 141
131 function BagBase:GetActionID() 142 function BagBase:GetActionID()
132 return self.config.bagID 143 return self.config.bagID
133 end 144 end
134 145
174 GameTooltip:Hide() 185 GameTooltip:Hide()
175 end 186 end
176 187
177 function BagBase:UPDATE_BINDINGS() 188 function BagBase:UPDATE_BINDINGS()
178 self:UpdateHotkey() 189 self:UpdateHotkey()
190 end
191
192 function BagBase:IterateAllButtons()
193 return pairs(self.allButtons)
179 end 194 end
180 195
181 196
182 -- 197 --
183 -- Bag Button class 198 -- Bag Button class
446 self:GetFrame():Hide() 461 self:GetFrame():Hide()
447 end 462 end
448 end 463 end
449 end 464 end
450 465
466
467
468 -- hook some functions to propagate to our bag buttons
469 hooksecurefunc("Disable_BagButtons",
470 function()
471 for b in BagBase:IterateAllButtons() do
472 local f = b:GetFrame()
473 f:Disable()
474 SetDesaturation(b.frames.icon,1)
475 end
476 end)
477
478 hooksecurefunc("Enable_BagButtons",
479 function()
480 for b in BagBase:IterateAllButtons() do
481 local f = b:GetFrame()
482 f:Enable()
483 SetDesaturation(b.frames.icon,nil)
484 end
485 end)
486
487 hooksecurefunc("ContainerFrame_OnHide",
488 function()
489 for b in BagBase:IterateAllButtons() do
490 b:Update()
491 end
492 end)
493
494 hooksecurefunc("ContainerFrame_OnShow",
495 function()
496 for b in BagBase:IterateAllButtons() do
497 b:Update()
498 end
499 end)