Mercurial > wow > reaction
comparison modules/ReAction_Action/ReAction_Action.lua @ 75:06cd74bdc7da
- Cleaned up Bar interface
- Move all attribute setting from Bar into State
- Separated Moonkin and Tree of Life
- Removed PossessBar module
- Added some infrastructure for paged/mind control support to Action
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Mon, 16 Jun 2008 18:46:08 +0000 |
parents | 768be7eb22a0 |
children | da8ba8783924 |
comparison
equal
deleted
inserted
replaced
74:00e28094e1a3 | 75:06cd74bdc7da |
---|---|
15 | 15 |
16 -- module declaration | 16 -- module declaration |
17 local moduleID = "Action" | 17 local moduleID = "Action" |
18 local module = ReAction:NewModule( moduleID ) | 18 local module = ReAction:NewModule( moduleID ) |
19 | 19 |
20 -- private -- | |
21 local function GetBarConfig(bar) | |
22 return module.db.profile.bars[bar:GetName()] | |
23 end | |
24 | |
25 local function RefreshLite(bar) | |
26 local btns = module.buttons[bar] | |
27 if btns then | |
28 for _, b in ipairs(btns) do | |
29 b:Refresh() | |
30 end | |
31 end | |
32 end | |
33 | |
34 | |
20 -- module methods | 35 -- module methods |
21 function module:OnInitialize() | 36 function module:OnInitialize() |
22 self.db = ReAction.db:RegisterNamespace( moduleID, | 37 self.db = ReAction.db:RegisterNamespace( moduleID, |
23 { | 38 { |
24 profile = { | 39 profile = { |
25 buttons = { } | 40 buttons = { }, |
41 bars = { }, | |
26 } | 42 } |
27 } | 43 } |
28 ) | 44 ) |
29 self.buttons = { } | 45 self.buttons = { } |
30 | 46 |
77 local btns = self.buttons[bar] | 93 local btns = self.buttons[bar] |
78 local profile = self.db.profile | 94 local profile = self.db.profile |
79 if profile.buttons[name] == nil then | 95 if profile.buttons[name] == nil then |
80 profile.buttons[name] = {} | 96 profile.buttons[name] = {} |
81 end | 97 end |
98 if profile.bars[name] == nil then | |
99 profile.bars[name] = {} | |
100 end | |
82 local btnCfg = profile.buttons[name] | 101 local btnCfg = profile.buttons[name] |
102 local barCfg = profile.bars[name] | |
83 | 103 |
84 local r, c = bar:GetButtonGrid() | 104 local r, c = bar:GetButtonGrid() |
85 local n = r*c | 105 local n = r*c |
86 for i = 1, n do | 106 for i = 1, n do |
87 if btnCfg[i] == nil then | 107 if btnCfg[i] == nil then |
88 btnCfg[i] = {} | 108 btnCfg[i] = {} |
89 end | 109 end |
90 if btns[i] == nil then | 110 if btns[i] == nil then |
91 local ok, b = pcall(self.BtnClass.new, self.BtnClass, bar, i, btnCfg[i]) | 111 local ok, b = pcall(self.BtnClass.New, self.BtnClass, bar, i, btnCfg[i], barCfg) |
92 if ok and b then | 112 if ok and b then |
93 btns[i] = b | 113 btns[i] = b |
94 end | 114 bar:AddButton(i,b) |
95 else | 115 end |
96 btns[i]:Refresh(bar,i) | |
97 end | 116 end |
98 end | 117 end |
99 for i = n+1, #btns do | 118 for i = n+1, #btns do |
100 if btns[i] then | 119 if btns[i] then |
120 bar:RemoveButton(btns[i]) | |
101 btns[i] = btns[i]:Destroy() | 121 btns[i] = btns[i]:Destroy() |
102 if btnCfg[i] then | 122 if btnCfg[i] then |
103 btnCfg[i] = nil | 123 btnCfg[i] = nil |
104 end | 124 end |
105 end | 125 end |
106 end | 126 end |
127 RefreshLite(bar) | |
107 end | 128 end |
108 end | 129 end |
109 | 130 |
110 function module:OnDestroyBar(event, bar, name) | 131 function module:OnDestroyBar(event, bar, name) |
111 if self.buttons[bar] then | 132 if self.buttons[bar] then |
119 end | 140 end |
120 end | 141 end |
121 | 142 |
122 function module:OnEraseBar(event, bar, name) | 143 function module:OnEraseBar(event, bar, name) |
123 self.db.profile.buttons[name] = nil | 144 self.db.profile.buttons[name] = nil |
145 self.db.profile.bars[name] = nil | |
124 end | 146 end |
125 | 147 |
126 function module:OnRenameBar(event, bar, oldname, newname) | 148 function module:OnRenameBar(event, bar, oldname, newname) |
127 local b = self.db.profile.buttons | 149 local b = self.db.profile.buttons |
150 b[newname], b[oldname] = b[oldname], nil | |
151 | |
152 b = self.db.profile.bars | |
128 b[newname], b[oldname] = b[oldname], nil | 153 b[newname], b[oldname] = b[oldname], nil |
129 end | 154 end |
130 | 155 |
131 function module:SetHideEmptyButtons(hide) | 156 function module:SetHideEmptyButtons(hide) |
132 if hide ~= self.db.profile.hideEmptyButtons then | 157 if hide ~= self.db.profile.hideEmptyButtons then |
161 end | 186 end |
162 end | 187 end |
163 | 188 |
164 function module:showActionIDLabel(button) | 189 function module:showActionIDLabel(button) |
165 if not button.actionIDLabel and button:GetActionID() then | 190 if not button.actionIDLabel and button:GetActionID() then |
166 local label = button:GetFrame():CreateFontString(nil,"OVERLAY","GameFontNormalLarge") | 191 local f = button:GetFrame() |
192 local label = f:CreateFontString(nil,"OVERLAY","GameFontNormalLarge") | |
167 label:SetAllPoints() | 193 label:SetAllPoints() |
168 label:SetJustifyH("CENTER") | 194 label:SetJustifyH("CENTER") |
169 label:SetShadowColor(0,0,0,1) | 195 label:SetShadowColor(0,0,0,1) |
170 label:SetShadowOffset(2,-2) | 196 label:SetShadowOffset(2,-2) |
171 label:SetText(tostring(button:GetActionID())) | 197 label:SetText(tostring(button:GetActionID())) |
172 button.actionIDLabel = label | 198 button.actionIDLabel = label |
199 f:HookScript("OnAttributeChanged", | |
200 function(frame, attr, value) | |
201 if attr == "state-parent" then | |
202 label:SetText(tostring(button:GetActionID())) | |
203 end | |
204 end) | |
173 end | 205 end |
174 button.actionIDLabel:Show() | 206 button.actionIDLabel:Show() |
175 end | 207 end |
176 | 208 |
177 function module:hideActionIDLabel(button) | 209 function module:hideActionIDLabel(button) |
228 | 260 |
229 | 261 |
230 ------ Button class ------ | 262 ------ Button class ------ |
231 local Button = { } | 263 local Button = { } |
232 | 264 |
233 local function Constructor( self, bar, idx, config ) | 265 local function Constructor( self, bar, idx, config, barConfig ) |
234 self.bar, self.idx, self.config = bar, idx, config | 266 self.bar, self.idx, self.config, self.barConfig = bar, idx, config, barConfig |
235 | 267 |
236 local barFrame = bar:GetFrame() | 268 local barFrame = bar:GetFrame() |
237 | 269 |
238 config.name = config.name or ("ReAction_%s_%d"):format(bar:GetName(),idx) | 270 config.name = config.name or ("ReAction_%s_%d"):format(bar:GetName(),idx) |
239 self.name = config.name | 271 self.name = config.name |
240 config.actionID = ActionIDList[config.actionID] -- gets a free one if none configured | 272 config.actionID = ActionIDList[config.actionID] -- gets a free one if none configured |
273 self.nPages = 1 | |
241 | 274 |
242 local f = CreateFrame("CheckButton", self.name, barFrame, "ActionBarButtonTemplate") | 275 local f = CreateFrame("CheckButton", self.name, barFrame, "ActionBarButtonTemplate") |
243 | 276 |
244 -- TODO: re-implement ActionButton event handlers that don't do secure stuff | 277 -- TODO: re-implement ActionButton event handlers that don't do secure stuff |
245 | 278 |
246 -- this will probably cause taint, using right now for display/debugging purposes | 279 -- this will probably cause taint and/or performance problems, using right now for display/debugging purposes |
247 f:SetScript("OnAttributeChanged", ActionButton_UpdateAction) | 280 f:SetScript("OnAttributeChanged", ActionButton_UpdateAction) |
281 | |
248 f:SetAttribute("action", config.actionID) | 282 f:SetAttribute("action", config.actionID) |
283 -- install mind control action support for all buttons here just for simplicity | |
284 if self.idx <= 12 then | |
285 f:SetAttribute("action-mc", 120 + self.idx) | |
286 end | |
249 | 287 |
250 barFrame:SetAttribute("addchild",f) | 288 barFrame:SetAttribute("addchild",f) |
251 | 289 |
252 self.frame = f | 290 self.frame = f |
253 self:Refresh(bar,idx) | 291 self:Refresh() |
254 | 292 |
255 if not module.db.profile.hideEmptyButtons then | 293 if not module.db.profile.hideEmptyButtons then |
256 ActionButton_ShowGrid(self.frame) | 294 ActionButton_ShowGrid(self.frame) |
257 end | 295 end |
258 | 296 |
272 _G[self.name] = nil | 310 _G[self.name] = nil |
273 end | 311 end |
274 if self.config.actionID then | 312 if self.config.actionID then |
275 ActionIDList[self.config.actionID] = nil | 313 ActionIDList[self.config.actionID] = nil |
276 end | 314 end |
315 if self.config.pages then | |
316 for _, id in ipairs(self.config.pages) do | |
317 ActionIDList[id] = nil | |
318 end | |
319 end | |
277 self.frame = nil | 320 self.frame = nil |
278 self.config = nil | 321 self.config = nil |
279 self.bar = nil | 322 self.bar = nil |
280 end | 323 end |
281 | 324 |
282 function Button:Refresh(bar,idx) | 325 function Button:Refresh() |
283 bar:PlaceButton(self.frame, idx, 36, 36) | 326 local f = self.frame |
327 self.bar:PlaceButton(self, 36, 36) | |
328 if self.barConfig.mckeybinds then | |
329 f:SetAttribute("bindings-mc", self.barConfig.mckeybinds[self.idx]) | |
330 end | |
331 self:RefreshPages() | |
284 end | 332 end |
285 | 333 |
286 function Button:GetFrame() | 334 function Button:GetFrame() |
287 return self.frame | 335 return self.frame |
288 end | 336 end |
290 function Button:GetName() | 338 function Button:GetName() |
291 return self.name | 339 return self.name |
292 end | 340 end |
293 | 341 |
294 function Button:GetActionID() | 342 function Button:GetActionID() |
295 return self.config.actionID | 343 return SecureButton_GetModifiedAttribute(self.frame, "action") |
296 end | 344 end |
297 | 345 |
346 function Button:RefreshPages() | |
347 local nPages = 1 --self.bar:GetNumPages() | |
348 if nPages ~= self.nPages then | |
349 local f = self:GetFrame() | |
350 local c = self.config.pages | |
351 if nPages > 1 and not c then | |
352 c = { } | |
353 self.config.pages = c | |
354 end | |
355 for i = 1, nPages do | |
356 c[i] = ActionIDList[c[i]] -- gets a free one if none configured | |
357 f:SetAttribute(("action-page%d"):format(i)) | |
358 end | |
359 for i = nPages+1, #c do | |
360 ActionIDList[c[i]] = nil | |
361 c[i] = nil | |
362 f:SetAttribute(("action-page%d"):format(i)) | |
363 end | |
364 | |
365 -- TODO: | |
366 -- apply next-page, prev-page, and direct-page keybinds (via bar:SetStateKeybind abstraction) | |
367 end | |
368 end | |
298 | 369 |
299 -- export as a class-factory to module | 370 -- export as a class-factory to module |
300 module.BtnClass = { | 371 module.BtnClass = { |
301 new = function(self, ...) | 372 New = function(self, ...) |
302 local x = { } | 373 local x = { } |
303 for k,v in pairs(Button) do | 374 for k,v in pairs(Button) do |
304 x[k] = v | 375 x[k] = v |
305 end | 376 end |
306 Constructor(x, ...) | 377 Constructor(x, ...) |