comparison modules/ReAction_Action/ReAction_Action.lua @ 63:768be7eb22a0

Converted several ReAction APIs to event-driven model instead of 'call-method-on-all-modules' model. Cleaned up a number of other architectural issues.
author Flick <flickerstreak@gmail.com>
date Thu, 22 May 2008 22:02:08 +0000
parents 44649a10378d
children 06cd74bdc7da
comparison
equal deleted inserted replaced
62:f9cdb920470a 63:768be7eb22a0
25 buttons = { } 25 buttons = { }
26 } 26 }
27 } 27 }
28 ) 28 )
29 self.buttons = { } 29 self.buttons = { }
30 self.options = setmetatable({},{__mode="k"})
31 30
32 ReAction:RegisterOptions(self, { 31 ReAction:RegisterOptions(self, {
33 [moduleID] = { 32 [moduleID] = {
34 type = "group", 33 type = "group",
35 name = L["Action Bars"], 34 name = L["Action Bars"],
41 set = function(info, val) module:SetHideEmptyButtons(val) end, 40 set = function(info, val) module:SetHideEmptyButtons(val) end,
42 } 41 }
43 } 42 }
44 } 43 }
45 }) 44 })
45
46 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions")
47
48 ReAction.RegisterCallback(self, "OnCreateBar", "OnRefreshBar")
49 ReAction.RegisterCallback(self, "OnDestroyBar")
50 ReAction.RegisterCallback(self, "OnRefreshBar")
51 ReAction.RegisterCallback(self, "OnEraseBar")
52 ReAction.RegisterCallback(self, "OnRenameBar")
53 ReAction.RegisterCallback(self, "OnConfigModeChanged")
54
46 end 55 end
47 56
48 function module:OnEnable() 57 function module:OnEnable()
49 ReAction:RegisterBarType(L["Action Bar"], 58 ReAction:RegisterBarType(L["Action Bar"],
50 { 59 {
58 67
59 function module:OnDisable() 68 function module:OnDisable()
60 ReAction:UnregisterBarType(L["Action Bar"]) 69 ReAction:UnregisterBarType(L["Action Bar"])
61 end 70 end
62 71
63 function module:ApplyToBar(bar) 72 function module:OnRefreshBar(event, bar, name)
64 self:RefreshBar(bar)
65 end
66
67 function module:RefreshBar(bar)
68 if bar.config.type == moduleID then 73 if bar.config.type == moduleID then
69 if self.buttons[bar] == nil then 74 if self.buttons[bar] == nil then
70 self.buttons[bar] = { } 75 self.buttons[bar] = { }
71 end 76 end
72 local btns = self.buttons[bar] 77 local btns = self.buttons[bar]
73 local profile = self.db.profile 78 local profile = self.db.profile
74 local barName = bar:GetName() 79 if profile.buttons[name] == nil then
75 if profile.buttons[barName] == nil then 80 profile.buttons[name] = {}
76 profile.buttons[barName] = {} 81 end
77 end 82 local btnCfg = profile.buttons[name]
78 local btnCfg = profile.buttons[barName]
79 83
80 local r, c = bar:GetButtonGrid() 84 local r, c = bar:GetButtonGrid()
81 local n = r*c 85 local n = r*c
82 for i = 1, n do 86 for i = 1, n do
83 if btnCfg[i] == nil then 87 if btnCfg[i] == nil then
101 end 105 end
102 end 106 end
103 end 107 end
104 end 108 end
105 109
106 function module:RemoveFromBar(bar) 110 function module:OnDestroyBar(event, bar, name)
107 if self.buttons[bar] then 111 if self.buttons[bar] then
108 local btns = self.buttons[bar] 112 local btns = self.buttons[bar]
109 for _,b in pairs(btns) do 113 for _,b in pairs(btns) do
110 if b then 114 if b then
111 b:Destroy() 115 b:Destroy()
113 end 117 end
114 self.buttons[bar] = nil 118 self.buttons[bar] = nil
115 end 119 end
116 end 120 end
117 121
118 function module:EraseBarConfig(barName) 122 function module:OnEraseBar(event, bar, name)
119 self.db.profile.buttons[barName] = nil 123 self.db.profile.buttons[name] = nil
120 end 124 end
121 125
122 function module:RenameBarConfig(oldname, newname) 126 function module:OnRenameBar(event, bar, oldname, newname)
123 local b = self.db.profile.buttons 127 local b = self.db.profile.buttons
124 b[newname], b[oldname] = b[oldname], nil 128 b[newname], b[oldname] = b[oldname], nil
125 end 129 end
126 130
127 function module:SetHideEmptyButtons(hide) 131 function module:SetHideEmptyButtons(hide)
137 end 141 end
138 self.db.profile.hideEmptyButtons = hide 142 self.db.profile.hideEmptyButtons = hide
139 end 143 end
140 end 144 end
141 145
142 function module:ApplyConfigMode(mode,bars) 146 function module:OnConfigModeChanged(event, mode)
143 for _, bar in pairs(bars) do 147 for _, bar in ReAction:IterateBars() do
144 if bar and self.buttons[bar] then 148 if bar and self.buttons[bar] then
145 for _, b in pairs(self.buttons[bar]) do 149 for _, b in pairs(self.buttons[bar]) do
146 if b then 150 if b then
147 if mode then 151 if mode then
148 ActionButton_ShowGrid(b.frame) 152 ActionButton_ShowGrid(b.frame)
177 end 181 end
178 182
179 183
180 ---- Options ---- 184 ---- Options ----
181 function module:GetBarOptions(bar) 185 function module:GetBarOptions(bar)
182 if not self.options[bar] then 186 return {
183 self.options[bar] = { 187 type = "group",
184 type = "group", 188 name = L["Action Buttons"],
185 name = L["Action Buttons"], 189 hidden = function() return bar.config.type ~= moduleID end,
186 hidden = function() return bar.config.type ~= moduleID end, 190 args = {
187 args = {
188 }
189 } 191 }
190 end 192 }
191 return self.options[bar]
192 end 193 end
193 194
194 195
195 -- use-count of action IDs 196 -- use-count of action IDs
196 local nActionIDs = 120 197 local nActionIDs = 120