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@175
|
7 local addonName, addonTable = ...
|
flickerstreak@175
|
8 local ReAction = addonTable.ReAction
|
flickerstreak@146
|
9 local L = ReAction.L
|
flickerstreak@146
|
10 local _G = _G
|
flickerstreak@146
|
11
|
flickerstreak@146
|
12 -- Bag button
|
flickerstreak@146
|
13 local Button = ReAction.Button.Bag
|
flickerstreak@146
|
14
|
flickerstreak@146
|
15 -- module declaration
|
flickerstreak@146
|
16 local moduleID = "Bag"
|
flickerstreak@146
|
17 local module = ReAction:NewModule( moduleID
|
flickerstreak@146
|
18 -- mixins go here
|
flickerstreak@146
|
19 )
|
flickerstreak@146
|
20
|
flickerstreak@146
|
21 -- handlers
|
flickerstreak@146
|
22 function module:OnInitialize()
|
flickerstreak@146
|
23 self.buttons = { }
|
flickerstreak@146
|
24
|
flickerstreak@146
|
25 ReAction.RegisterCallback(self, "OnCreateBar", "OnRefreshBar")
|
flickerstreak@146
|
26 ReAction.RegisterCallback(self, "OnDestroyBar")
|
flickerstreak@146
|
27 ReAction.RegisterCallback(self, "OnRefreshBar")
|
flickerstreak@146
|
28 end
|
flickerstreak@146
|
29
|
flickerstreak@146
|
30 function module:OnDestroyBar(event, bar, name)
|
flickerstreak@146
|
31 local btns = self.buttons[bar]
|
flickerstreak@146
|
32 if btns then
|
flickerstreak@146
|
33 for _,b in pairs(btns) do
|
flickerstreak@146
|
34 if b then
|
flickerstreak@146
|
35 b:Destroy()
|
flickerstreak@146
|
36 end
|
flickerstreak@146
|
37 end
|
flickerstreak@146
|
38 self.buttons[bar] = nil
|
flickerstreak@146
|
39 end
|
flickerstreak@146
|
40 end
|
flickerstreak@146
|
41
|
flickerstreak@146
|
42 function module:OnRefreshBar(event, bar, name)
|
flickerstreak@221
|
43 local config = bar:GetConfig()
|
flickerstreak@221
|
44 if config.type == moduleID then
|
flickerstreak@146
|
45 local btns = self.buttons[bar]
|
flickerstreak@146
|
46 if btns == nil then
|
flickerstreak@146
|
47 btns = { }
|
flickerstreak@146
|
48 self.buttons[bar] = btns
|
flickerstreak@146
|
49 end
|
flickerstreak@221
|
50 if not config.buttons then
|
flickerstreak@221
|
51 config.buttons = { }
|
flickerstreak@146
|
52 end
|
flickerstreak@221
|
53 local btnCfg = config.buttons
|
flickerstreak@146
|
54
|
flickerstreak@146
|
55 local r, c = bar:GetButtonGrid()
|
flickerstreak@146
|
56 local n = r*c
|
flickerstreak@146
|
57 for i = 1, n do
|
flickerstreak@146
|
58 if btnCfg[i] == nil then
|
flickerstreak@146
|
59 btnCfg[i] = {}
|
flickerstreak@146
|
60 end
|
flickerstreak@146
|
61 if btns[i] == nil then
|
flickerstreak@221
|
62 local success, r = pcall(Button.New,Button,i,btnCfg[i],bar,i>1 and btnCfg[i-1].bagID)
|
flickerstreak@146
|
63 if success and r then
|
flickerstreak@146
|
64 btns[i] = r
|
flickerstreak@146
|
65 bar:AddButton(i,r)
|
flickerstreak@146
|
66 else
|
flickerstreak@146
|
67 n = i - 1
|
flickerstreak@146
|
68 bar:ClipNButtons(n)
|
flickerstreak@146
|
69 break
|
flickerstreak@146
|
70 end
|
flickerstreak@146
|
71 end
|
flickerstreak@146
|
72 btns[i]:Refresh()
|
flickerstreak@146
|
73 end
|
flickerstreak@146
|
74 for i = n+1, #btns do
|
flickerstreak@146
|
75 if btns[i] then
|
flickerstreak@146
|
76 bar:RemoveButton(btns[i])
|
flickerstreak@146
|
77 btns[i] = btns[i]:Destroy()
|
flickerstreak@146
|
78 if btnCfg[i] then
|
flickerstreak@146
|
79 btnCfg[i] = nil
|
flickerstreak@146
|
80 end
|
flickerstreak@146
|
81 end
|
flickerstreak@146
|
82 end
|
flickerstreak@146
|
83 end
|
flickerstreak@146
|
84
|
flickerstreak@146
|
85 end
|
flickerstreak@146
|
86
|
flickerstreak@146
|
87
|
flickerstreak@146
|
88
|
flickerstreak@146
|
89 -- hook some functions to propagate to our bag buttons
|
flickerstreak@146
|
90 hooksecurefunc("Disable_BagButtons",
|
flickerstreak@146
|
91 function()
|
flickerstreak@146
|
92 for _, buttons in pairs(module.buttons) do
|
flickerstreak@146
|
93 for _, b in pairs(buttons) do
|
flickerstreak@146
|
94 local f = b:GetFrame()
|
flickerstreak@146
|
95 f:Disable()
|
flickerstreak@146
|
96 SetDesaturation(b.frames.icon,1)
|
flickerstreak@146
|
97 end
|
flickerstreak@146
|
98 end
|
flickerstreak@146
|
99 end)
|
flickerstreak@146
|
100
|
flickerstreak@146
|
101 hooksecurefunc("Enable_BagButtons",
|
flickerstreak@146
|
102 function()
|
flickerstreak@146
|
103 for _, buttons in pairs(module.buttons) do
|
flickerstreak@146
|
104 for _, b in pairs(buttons) do
|
flickerstreak@146
|
105 local f = b:GetFrame()
|
flickerstreak@146
|
106 f:Enable()
|
flickerstreak@146
|
107 SetDesaturation(b.frames.icon,nil)
|
flickerstreak@146
|
108 end
|
flickerstreak@146
|
109 end
|
flickerstreak@146
|
110 end)
|
flickerstreak@146
|
111
|
flickerstreak@146
|
112 hooksecurefunc("ContainerFrame_OnHide",
|
flickerstreak@146
|
113 function()
|
flickerstreak@146
|
114 for _, buttons in pairs(module.buttons) do
|
flickerstreak@146
|
115 for _, b in pairs(buttons) do
|
flickerstreak@146
|
116 b:Update()
|
flickerstreak@146
|
117 end
|
flickerstreak@146
|
118 end
|
flickerstreak@146
|
119 end)
|
flickerstreak@146
|
120
|
flickerstreak@146
|
121 hooksecurefunc("ContainerFrame_OnShow",
|
flickerstreak@146
|
122 function()
|
flickerstreak@146
|
123 for _, buttons in pairs(module.buttons) do
|
flickerstreak@146
|
124 for _, b in pairs(buttons) do
|
flickerstreak@146
|
125 b:Update()
|
flickerstreak@146
|
126 end
|
flickerstreak@146
|
127 end
|
flickerstreak@146
|
128 end)
|