Mercurial > wow > reaction
diff 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 |
line wrap: on
line diff
--- a/classes/BagButton.lua Tue Mar 22 11:48:09 2011 -0700 +++ b/classes/BagButton.lua Tue Mar 22 17:05:51 2011 -0700 @@ -16,6 +16,7 @@ -- class declarations local buttonTypeID = "Bag" +local weak = { __mode = "k" } local Super = ReAction.Button local BagBase = setmetatable( { @@ -30,7 +31,9 @@ }, barType = L["Bag Bar"], - buttonTypeID = buttonTypeID + buttonTypeID = buttonTypeID, + + allButtons = setmetatable( { }, weak ) }, { __index = Super } ) @@ -45,7 +48,7 @@ -- Bag Button base class -- -function BagBase:New( idx, btnCfg, bar, idHint ) +function BagBase:New( btnCfg, bar, idx, idHint ) local name = format("ReAction_%s_Bag_%d",bar:GetName(),idx) -- use a variable private leaf implementation class @@ -125,9 +128,17 @@ self:Refresh() + BagBase.allButtons[self] = true + return self end +function BagBase:Destroy() + BagBase.allButtons[self] = nil + Super.Destroy(self) +end + + function BagBase:GetActionID() return self.config.bagID end @@ -178,6 +189,10 @@ self:UpdateHotkey() end +function BagBase:IterateAllButtons() + return pairs(self.allButtons) +end + -- -- Bag Button class @@ -448,3 +463,37 @@ end end + + +-- hook some functions to propagate to our bag buttons +hooksecurefunc("Disable_BagButtons", + function() + for b in BagBase:IterateAllButtons() do + local f = b:GetFrame() + f:Disable() + SetDesaturation(b.frames.icon,1) + end + end) + +hooksecurefunc("Enable_BagButtons", + function() + for b in BagBase:IterateAllButtons() do + local f = b:GetFrame() + f:Enable() + SetDesaturation(b.frames.icon,nil) + end + end) + +hooksecurefunc("ContainerFrame_OnHide", + function() + for b in BagBase:IterateAllButtons() do + b:Update() + end + end) + +hooksecurefunc("ContainerFrame_OnShow", + function() + for b in BagBase:IterateAllButtons() do + b:Update() + end + end)