Mercurial > wow > reaction
comparison classes/Button.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 | 1663c78a7f31 |
comparison
equal
deleted
inserted
replaced
233:9b9f5fc84d34 | 234:0e20f65375d5 |
---|---|
110 | 110 |
111 function Button:GetFrame() | 111 function Button:GetFrame() |
112 return self.frame | 112 return self.frame |
113 end | 113 end |
114 | 114 |
115 function Button:GetIndex() | |
116 return self.idx | |
117 end | |
118 | |
115 function Button:GetName() | 119 function Button:GetName() |
116 return self.name | 120 return self.name |
117 end | 121 end |
118 | 122 |
119 function Button:GetDefaultBarConfig() | 123 function Button:GetDefaultBarConfig() |
138 end | 142 end |
139 | 143 |
140 function Button:SetActionIDPool( poolID, maxID ) | 144 function Button:SetActionIDPool( poolID, maxID ) |
141 self.actionPoolID = poolID | 145 self.actionPoolID = poolID |
142 self.actionMaxID = maxID | 146 self.actionMaxID = maxID |
147 end | |
148 | |
149 function Button:SetupBar( bar ) | |
150 local config = bar:GetConfig() | |
151 if not config.buttons then | |
152 config.buttons = { } | |
153 end | |
154 local btnCfg = config.buttons | |
155 | |
156 local r, c = bar:GetButtonGrid() | |
157 local n = r*c | |
158 | |
159 local hint = nil | |
160 local i = 1 | |
161 repeat | |
162 local b = bar:GetButton(i) | |
163 if b then | |
164 if i > n then | |
165 bar:RemoveButton(b) | |
166 b:Destroy() | |
167 btnCfg[i] = nil | |
168 else | |
169 b:Refresh() | |
170 hint = b:GetActionID() | |
171 end | |
172 elseif i <= n then | |
173 local cfg = btnCfg[i] or { } | |
174 local success, r = pcall(self.New, self, cfg, bar, i, hint) -- note call semantics for derived class constructors | |
175 if success and r then | |
176 b = r | |
177 bar:AddButton(i,b) | |
178 btnCfg[i] = cfg | |
179 b:Refresh() | |
180 hint = b:GetActionID() | |
181 else | |
182 n = i - 1 | |
183 bar:ClipNButtons(n) | |
184 if not success then | |
185 geterrorhandler()(r) | |
186 end | |
187 end | |
188 end | |
189 i = i + 1 | |
190 until b == nil | |
143 end | 191 end |
144 | 192 |
145 function Button:AcquireActionID( id, hint, unique ) | 193 function Button:AcquireActionID( id, hint, unique ) |
146 local poolID = self.actionPoolID | 194 local poolID = self.actionPoolID |
147 local maxID = self.actionMaxID | 195 local maxID = self.actionMaxID |