comparison classes/ActionButton.lua @ 128:729232aeeb5e

Action Button rewrite. (note: pet actions are probably slightly broken right now, they haven't been updated yet)
author Flick <flickerstreak@gmail.com>
date Thu, 05 Mar 2009 01:28:48 +0000
parents 0c5017f6062d
children 28b430de5875
comparison
equal deleted inserted replaced
127:29dacbecdb52 128:729232aeeb5e
57 else 57 else
58 action = self:GetAttribute("default-action") 58 action = self:GetAttribute("default-action")
59 end 59 end
60 60
61 self:SetAttribute("action",action) 61 self:SetAttribute("action",action)
62 local hasaction = (action > 120) or self:GetAttribute("hasaction-"..action) 62
63 63 if not self:GetAttribute("showgrid") then
64 if (self:GetAttribute("showgrid") + self:GetAttribute("showgrid-temp") == 0) and not hasaction then 64 local hasaction = (action > 120) or self:GetAttribute("hasaction-"..action)
65 self:Hide() 65 local tempShow = self:GetAttribute("showgrid-temp")
66 else 66 local evtShow = self:GetAttribute("showgrid-event")
67 self:Show() 67 if tempShow then tempShow = (tempShow > 0) end
68 if evtShow then evtShow = (evtShow > 0) end
69
70 if tempShow or evtShow or hasaction then
71 self:Show()
72 else
73 self:Hide()
74 end
68 end 75 end
69 ]] 76 ]]
70 77
71 local _childupdate_vehicleExit = -- function(self, snippetid, message) 78 local _childupdate_vehicleExit = -- function(self, snippetid, message)
72 [[ 79 [[
81 control:CallMethod("ShowVehicleExit",show) 88 control:CallMethod("ShowVehicleExit",show)
82 ]] 89 ]]
83 90
84 local _childupdate_showgrid = -- function(self, snippetid, message) 91 local _childupdate_showgrid = -- function(self, snippetid, message)
85 [[ 92 [[
86 self:SetAttribute("showgrid-temp",message or 0) 93 self:SetAttribute("showgrid-event",message)
87 local count = (message or 0) + (self:GetAttribute("showgrid") or 0) 94 if not self:GetAttribute("showgrid") then
88 if count == 0 then 95 local count = message + (self:GetAttribute("showgrid-temp") or 0)
89 local action = self:GetAttribute("action") 96 if count <= 0 then
90 local hasaction = (action > 120) or self:GetAttribute("hasaction-"..action) 97 local action = self:GetAttribute("action")
91 if hasaction then 98 local hasaction = (action > 120) or self:GetAttribute("hasaction-"..action)
99 if hasaction then
100 self:Show()
101 else
102 self:Hide()
103 end
104 else
92 self:Show() 105 self:Show()
93 else 106 end
94 self:Hide()
95 end
96 else
97 self:Show()
98 end 107 end
99 ]] 108 ]]
100 109
101 local _onDragStart = -- function(self, button, kind, value, ...) 110 local _onDragStart = -- function(self, button, kind, value, ...)
102 [[ 111 [[
109 end 118 end
110 ]] 119 ]]
111 120
112 local _onReceiveDrag = -- function(self, button, kind, value, ...) 121 local _onReceiveDrag = -- function(self, button, kind, value, ...)
113 [[ 122 [[
114 if lockButtons and (PlayerInCombat() or not lockButtonsCombat) and not IsModifiedClick("PICKUPACTION") then 123 if kind == "spell" or kind == "item" or kind == "macro" then
115 return kind, value, ... 124 -- assume it's a valid action
116 else 125 self:SetAttribute("hasaction-"..self:GetAttribute("action"),true)
117 if kind == "spell" or kind == "item" or kind == "macro" then 126 end
118 -- assume it's a valid action 127 return "action", self:GetAttribute("action")
119 self:SetAttribute("hasaction-"..self:GetAttribute("action"),true)
120 end
121 return "action", self:GetAttribute("action")
122 end
123 ]] 128 ]]
124 129
125 -- 130 --
126 -- private 131 -- private
127 -- 132 --
152 -- 157 --
153 local Super = ReAction.Button 158 local Super = ReAction.Button
154 local Action = setmetatable( { }, { __index = Super } ) 159 local Action = setmetatable( { }, { __index = Super } )
155 ReAction.Button.Action = Action 160 ReAction.Button.Action = Action
156 161
157 function Action:New( idx, config, bar, idHint ) 162 function Action:New( idx, barConfig, bar, idHint )
158 local name = format("ReAction_%s_Action_%d",bar:GetName(),idx) 163 local name = format("ReAction_%s_Action_%d",bar:GetName(),idx)
159 164
160 self = Super.New(self, name, config, bar, idx, "SecureActionButtonTemplate, ActionButtonTemplate" ) 165 self = Super.New(self, name, barConfig, bar, idx, "SecureActionButtonTemplate, ActionButtonTemplate" )
161 166
162 local f = self:GetFrame() 167 local f = self:GetFrame()
163 local barFrame = bar:GetFrame() 168 local barFrame = bar:GetFrame()
169 local config = self:GetConfig()
164 170
165 local frames = { } 171 local frames = { }
166 self.frames = frames 172 self.frames = frames
167 frames.icon = _G[name.."Icon"] 173 frames.icon = _G[name.."Icon"]
168 frames.flash = _G[name.."Flash"] 174 frames.flash = _G[name.."Flash"]
188 f:SetAttribute("checkselfcast", true) 194 f:SetAttribute("checkselfcast", true)
189 f:SetAttribute("checkfocuscast", true) 195 f:SetAttribute("checkfocuscast", true)
190 f:SetAttribute("useparent-unit", true) 196 f:SetAttribute("useparent-unit", true)
191 f:SetAttribute("action", config.actionID) 197 f:SetAttribute("action", config.actionID)
192 f:SetAttribute("default-action", config.actionID) 198 f:SetAttribute("default-action", config.actionID)
193 f:SetAttribute("showgrid",0) 199 f:SetAttribute("bar-idx",idx)
194 f:SetAttribute("showgrid-temp",0) 200 f:SetAttribute("showgrid-temp",0)
195 f:SetAttribute("bar-idx",idx) 201 f:SetAttribute("showgrid-event",0)
202 f:SetAttribute("showgrid",not self:GetBarConfig().hideEmpty)
203
204 self:RefreshHasActionAttributes()
196 205
197 -- non secure scripts 206 -- non secure scripts
198 f:SetScript("OnEvent", function(frame, ...) self:OnEvent(...) end) 207 f:SetScript("OnEvent", function(frame, ...) self:OnEvent(...) end)
199 f:SetScript("OnEnter", function(frame) self:OnEnter() end) 208 f:SetScript("OnEnter", function(frame) self:OnEnter() end)
200 f:SetScript("OnLeave", function(frame) self:OnLeave() end) 209 f:SetScript("OnLeave", function(frame) self:OnLeave() end)
203 f:SetScript("OnUpdate", function(frame, elapsed) self:OnUpdate(elapsed) end) 212 f:SetScript("OnUpdate", function(frame, elapsed) self:OnUpdate(elapsed) end)
204 f:SetScript("OnDragStart", function(frame) self:OnDragStart() end) 213 f:SetScript("OnDragStart", function(frame) self:OnDragStart() end)
205 f:SetScript("OnReceiveDrag", function(frame) self:OnReceiveDrag() end) 214 f:SetScript("OnReceiveDrag", function(frame) self:OnReceiveDrag() end)
206 215
207 -- secure handlers 216 -- secure handlers
208 f:SetAttribute("_childupate", _childupdate) 217 f:SetAttribute("_childupdate", _childupdate)
209 f:SetAttribute("_childupdate-showgrid",_childupdate_showgrid) 218 f:SetAttribute("_childupdate-showgrid",_childupdate_showgrid)
210 barFrame:WrapScript(f, "OnDragStart", _onDragStart) 219 barFrame:WrapScript(f, "OnDragStart", _onDragStart)
211 barFrame:WrapScript(f, "OnReceiveDrag", _onReceiveDrag) 220 barFrame:WrapScript(f, "OnReceiveDrag", _onReceiveDrag)
212 221
213 -- event registration 222 -- event registration
220 229
221 -- attach to skinner 230 -- attach to skinner
222 bar:SkinButton(self) 231 bar:SkinButton(self)
223 232
224 -- initial display 233 -- initial display
225 self:ShowGrid(not bar:GetConfig().hideEmpty)
226 if ReAction:GetConfigMode() then 234 if ReAction:GetConfigMode() then
227 self:ShowGrid(true) 235 self:ShowGridTemp(true)
228 end 236 end
229
230 f:Show()
231 237
232 self:Refresh() 238 self:Refresh()
233 239
234 return self 240 return self
235 end 241 end
236 242
237 function Action:Destroy() 243 function Action:Destroy()
238 local f = self:GetFrame() 244 local f = self:GetFrame()
245 local c = self:GetConfig()
239 246
240 f:UnregisterAllEvents() 247 f:UnregisterAllEvents()
241 248
242 f:SetAttribute("_childupdate-vehicle",nil) 249 f:SetAttribute("_childupdate-vehicle",nil)
243 250
244 self:ReleaseActionID(config.actionID) 251 self:ReleaseActionID(c.actionID)
245 if self.config.pageactions then 252 if c.pageactions then
246 for _, id in ipairs(self.config.pageactions) do 253 for _, id in ipairs(c.pageactions) do
247 self:ReleaseActionID(id) 254 self:ReleaseActionID(id)
248 end 255 end
249 end 256 end
250 257
251 Super:Destroy() 258 Super.Destroy(self)
252 end 259 end
253 260
254 function Action:Refresh() 261 function Action:Refresh()
255 self.bar:PlaceButton(self, 36, 36) 262 self.bar:PlaceButton(self, 36, 36)
256 self:RefreshPages() 263 self:RefreshPages()
257 self:InstallVehicle() 264 self:InstallVehicle()
265 self:ShowGrid(not self:GetBarConfig().hideEmpty)
258 self:UpdateAction() 266 self:UpdateAction()
259 end 267 end
260 268
261 function Action:InstallVehicle() 269 function Action:InstallVehicle()
262 if self.idx == 7 and self.bar:GetConfig().vehicle then 270 if self.idx == 7 and self:GetBarConfig().vehicle then
263 -- install vehicle-exit button on 7th button (only) 271 -- install vehicle-exit button on 7th button (only)
264 f:SetAttribute("_childupdate-vehicle", _childupdate_vehicleExit) 272 self:GetFrame():SetAttribute("_childupdate-vehicle", _childupdate_vehicleExit)
265 barFrame.ShowVehicleExit = function(bar,show) 273 self:GetBar():GetFrame().ShowVehicleExit = function(bar,show)
266 self:ShowVehicleExit(show) 274 self:ShowVehicleExit(show)
267 end 275 end
268 else 276 else
269 f:SetAttribute("_childupdate-vehicle",nil) 277 self:GetFrame():SetAttribute("_childupdate-vehicle",nil)
278 end
279 end
280
281 function Action:ShowGrid( show )
282 if not InCombatLockdown() then
283 self.frame:SetAttribute("showgrid", show)
284 self:UpdateShowGrid()
285 end
286 end
287
288 function Action:ShowGridTemp( show )
289 -- This function only modifies the show-grid when out
290 -- of combat, and is ignored by the secure handler. Use
291 -- it for configuration modes.
292 if not InCombatLockdown() then
293 local count = self.showGridTempCount or 0
294 if show then
295 count = count + 1
296 else
297 count = count - 1
298 end
299 if count < 0 then count = 0 end
300 self.showGridTempCount = count
301 self:GetFrame():SetAttribute("showgrid-temp",count)
302 self:UpdateShowGrid()
270 end 303 end
271 end 304 end
272 305
273 function Action:UpdateAll() 306 function Action:UpdateAll()
274 self:UpdateActionIDLabel(ReAction:GetConfigMode()) 307 self:UpdateActionIDLabel(ReAction:GetConfigMode())
291 self.actionID = action 324 self.actionID = action
292 self:UpdateAll() 325 self:UpdateAll()
293 end 326 end
294 end 327 end
295 328
329 function Action:RefreshHasActionAttributes()
330 -- check if each action has an action or not, and flag an attribute
331 -- so that the showgrid secure handler can make decisions accordingly
332 local f = self:GetFrame()
333 local attr = "hasaction-"..self.config.actionID
334 local hasAction = HasAction(self.config.actionID)
335 if f:GetAttribute(attr) ~= hasAction then
336 f:SetAttribute(attr,hasAction) -- avoid setting attribute and triggering script handler unnecessarily
337 end
338 if self.config.pageactions then
339 for i = 1, self.nPages do
340 attr = "hasaction-"..self.config.pageactions[i]
341 hasAction = HasAction(self.config.pageactions[i])
342 if f:GetAttribute(attr) ~= hasAction then
343 f:SetAttribute(attr,hasAction)
344 end
345 end
346 end
347 end
348
296 function Action:UpdateShowGrid() 349 function Action:UpdateShowGrid()
297 -- this is a little bit complicated because there's no 350 -- this is a little bit complicated because there's no
298 -- secure driver to handle show/hide grid events. 351 -- secure access to HasAction.
299 if InCombatLockdown() then 352 if InCombatLockdown() then
300 self.showgridPending = true -- handle after combat 353 self.showgridPending = true -- handle after combat
301 else 354 else
302 self.showgridPending = false 355 self.showgridPending = false
303 -- check if each action has an action or not, and flag an attribute 356 self:RefreshHasActionAttributes()
304 -- so that the showgrid secure handler can make decisions accordingly 357
305 local f = self:GetFrame()
306 f:SetAttribute("hasaction-"..self.config.actionID, HasAction(self.config.actionID))
307 if self.config.pageactions then
308 for i = 1, self.nPages do
309 f:SetAttribute("hasaction-"..self.config.pageactions[i], HasAction(self.config.pageactions[i]))
310 end
311 end
312 -- the following is an out-of-combat show/hide to supplement the secure 358 -- the following is an out-of-combat show/hide to supplement the secure
313 -- handling and clean up after it when it guesses 359 -- handling and clean up after it when it guesses
314 if HasAction(self.actionID) then 360 local f = self:GetFrame()
361 local count = (f:GetAttribute("showgrid-event") or 0) +
362 (self.showGridTempCount or 0) +
363 (f:GetAttribute("showgrid") and 1 or 0)
364
365 if count <= 0 and not HasAction(self.actionID) then
366 if f:IsShown() then
367 f:Hide()
368 end
369 elseif not f:IsShown() then
315 f:Show() 370 f:Show()
316 else
317 f:Hide()
318 end 371 end
319 end 372 end
320 end 373 end
321 374
322 function Action:UpdateIcon() 375 function Action:UpdateIcon()
505 end 558 end
506 end 559 end
507 end 560 end
508 561
509 function Action:RefreshPages( force ) 562 function Action:RefreshPages( force )
510 local nPages = self.bar:GetConfig().nPages 563 local nPages = self:GetBarConfig().nPages
511 if nPages and (nPages ~= self.nPages or force) then 564 if nPages and (nPages ~= self.nPages or force) then
512 local f = self:GetFrame() 565 local f = self:GetFrame()
513 local c = self.config.pageactions 566 local c = self.config.pageactions
514 if nPages > 1 and not c then 567 if nPages > 1 and not c then
515 c = { } 568 c = { }
530 end 583 end
531 self.nPages = nPages 584 self.nPages = nPages
532 end 585 end
533 end 586 end
534 587
535 function Action.SetupBarHeader( bar ) -- call this as a static method 588 function Action.SetupBarHeader( bar, config ) -- call this as a static method
536 local f = bar:GetFrame() 589 local f = bar:GetFrame()
537 local c = bar:GetConfig() 590 f:SetAttribute("mindcontrol",config.mindcontrol)
538 f:SetAttribute("mindcontrol",c.mindcontrol) 591 f:SetAttribute("vehicle",config.vehicle)
539 f:SetAttribute("vehicle",c.vehicle)
540 f:Execute( 592 f:Execute(
541 [[ 593 [[
542 doMindControl = self:GetAttribute("mindcontrol") 594 doMindControl = self:GetAttribute("mindcontrol")
543 doVehicle = self:GetAttribute("vehicle") 595 doVehicle = self:GetAttribute("vehicle")
544 control:ChildUpdate() 596 control:ChildUpdate()
545 ]]) 597 ]])
546 598
547 f:SetAttribute("_onstate-mc", _onstate_mc) 599 f:SetAttribute("_onstate-mc", _onstate_mc)
548 RegisterStateDriver(f, "mc", "[target=vehicle,exists] vehicle; [bonusbar:5] mc; none") 600 RegisterStateDriver(f, "mc", "[target=vehicle,exists] vehicle; [bonusbar:5] mc; none")
549 601
550 f:SetAttribute("lockbuttons",c.lockButtons) 602 f:SetAttribute("lockbuttons",config.lockButtons)
551 f:SetAttribute("lockbuttonscombat",c.lockButtonsCombat) 603 f:SetAttribute("lockbuttonscombat",config.lockButtonsCombat)
552 f:Execute( 604 f:Execute(
553 [[ 605 [[
554 lockButtons = self:GetAttribute("lockbuttons") 606 lockButtons = self:GetAttribute("lockbuttons")
555 lockButtonsCombat = self:GetAttribute("lockbuttonscombat") 607 lockButtonsCombat = self:GetAttribute("lockbuttonscombat")
556 ]]) 608 ]])
570 622
571 623
572 function Action:ShowVehicleExit(show) 624 function Action:ShowVehicleExit(show)
573 local f = self:GetFrame() 625 local f = self:GetFrame()
574 local tx = f.vehicleExitTexture 626 local tx = f.vehicleExitTexture
575 if show and self.bar:GetConfig().vehicle then 627 if show and self:GetBarConfig().vehicle then
576 if not tx then 628 if not tx then
577 tx = f:CreateTexture(nil,"ARTWORK") 629 tx = f:CreateTexture(nil,"ARTWORK")
578 tx:SetAllPoints() 630 tx:SetAllPoints()
579 -- copied from Blizzard/VehicleMenuBar.lua SkinsData 631 -- copied from Blizzard/VehicleMenuBar.lua SkinsData
580 tx:SetTexture("Interface\\Vehicles\\UI-Vehicles-Button-Exit-Up") 632 tx:SetTexture("Interface\\Vehicles\\UI-Vehicles-Button-Exit-Up")
627 end 679 end
628 end 680 end
629 681
630 function Action:ACTIONBAR_SLOT_CHANGED(event, action) 682 function Action:ACTIONBAR_SLOT_CHANGED(event, action)
631 if action == 0 or action == self.actionID then 683 if action == 0 or action == self.actionID then
632 self:UpdateAction() 684 self:UpdateAll()
633 end 685 end
634 end 686 end
635 687
636 function Action:PLAYER_ENTERING_WORLD() 688 function Action:PLAYER_ENTERING_WORLD()
637 self:UpdateAction() 689 self:UpdateAction()