comparison classes/ActionButton.lua @ 170:0030201b5fc2

use secure HasAction() (drycoded)
author Flick <flickerstreak@gmail.com>
date Tue, 19 Oct 2010 20:07:55 +0000
parents 8cc187143acd
children df68b5a40490
comparison
equal deleted inserted replaced
169:8cc187143acd 170:0030201b5fc2
58 end 58 end
59 59
60 self:SetAttribute("action",action) 60 self:SetAttribute("action",action)
61 61
62 if not self:GetAttribute("showgrid") then 62 if not self:GetAttribute("showgrid") then
63 local hasaction = (action > 120) or self:GetAttribute("hasaction-"..action)
64 local tempShow = self:GetAttribute("showgrid-temp") 63 local tempShow = self:GetAttribute("showgrid-temp")
65 local evtShow = self:GetAttribute("showgrid-event") 64 local evtShow = self:GetAttribute("showgrid-event")
66 if tempShow then tempShow = (tempShow > 0) end 65 if tempShow then tempShow = (tempShow > 0) end
67 if evtShow then evtShow = (evtShow > 0) end 66 if evtShow then evtShow = (evtShow > 0) end
68 67
69 if tempShow or evtShow or hasaction then 68 if tempShow or evtShow or HasAction(action) then
70 self:Show() 69 self:Show()
71 else 70 else
72 self:Hide() 71 self:Hide()
73 end 72 end
74 end 73 end
91 self:SetAttribute("showgrid-event",message) 90 self:SetAttribute("showgrid-event",message)
92 if not self:GetAttribute("showgrid") then 91 if not self:GetAttribute("showgrid") then
93 local count = message + (self:GetAttribute("showgrid-temp") or 0) 92 local count = message + (self:GetAttribute("showgrid-temp") or 0)
94 if count <= 0 then 93 if count <= 0 then
95 local action = self:GetAttribute("action") 94 local action = self:GetAttribute("action")
96 local hasaction = (action > 120) or self:GetAttribute("hasaction-"..action) 95 if HasAction(action) then
97 if hasaction then
98 self:Show() 96 self:Show()
99 else 97 else
100 self:Hide() 98 self:Hide()
101 end 99 end
102 else 100 else
108 local _onDragStart = -- function(self, button, kind, value, ...) 106 local _onDragStart = -- function(self, button, kind, value, ...)
109 [[ 107 [[
110 if lockButtons and (PlayerInCombat() or not lockButtonsCombat) and not IsModifiedClick("PICKUPACTION") then 108 if lockButtons and (PlayerInCombat() or not lockButtonsCombat) and not IsModifiedClick("PICKUPACTION") then
111 return kind, value, ... 109 return kind, value, ...
112 else 110 else
113 -- don't make any assumptions about hiding on grid show here, as we don't know if the
114 -- drag gets cancelled later.
115 return "action", self:GetAttribute("action") 111 return "action", self:GetAttribute("action")
116 end 112 end
117 ]] 113 ]]
118 114
119 local _onReceiveDrag = -- function(self, button, kind, value, ...) 115 local _onReceiveDrag = -- function(self, button, kind, value, ...)
120 [[ 116 [[
121 if kind ~= "spell" and kind ~= "item" and kind ~= "macro" then 117 if kind ~= "spell" and kind ~= "item" and kind ~= "macro" then
122 return kind, value, ... 118 return kind, value, ...
123 end 119 else
124 self:SetAttribute("hasaction-"..self:GetAttribute("action"),true) 120 return "action", self:GetAttribute("action")
125 return "action", self:GetAttribute("action") 121 end
126 ]] 122 ]]
127 123
128 -- 124 --
129 -- private 125 -- private
130 -- 126 --
131 local eventList = { 127 local eventList = {
132 "PLAYER_REGEN_ENABLED",
133 "PLAYER_ENTERING_WORLD", 128 "PLAYER_ENTERING_WORLD",
134 "ACTIONBAR_PAGE_CHANGED", 129 "ACTIONBAR_PAGE_CHANGED",
135 "ACTIONBAR_SLOT_CHANGED", 130 "ACTIONBAR_SLOT_CHANGED",
136 "UPDATE_BINDINGS", 131 "UPDATE_BINDINGS",
137 "ACTIONBAR_UPDATE_STATE", 132 "ACTIONBAR_UPDATE_STATE",
247 return self.barConfig 242 return self.barConfig
248 end 243 end
249 244
250 function Action:Refresh() 245 function Action:Refresh()
251 Super.Refresh(self) 246 Super.Refresh(self)
252 self:RefreshHasActionAttributes()
253 self:RefreshPages() 247 self:RefreshPages()
254 self:InstallVehicle() 248 self:InstallVehicle()
255 self:ShowGrid(not self:GetBarConfig().hideEmpty) 249 self:ShowGrid(not self:GetBarConfig().hideEmpty)
256 self:UpdateAction() 250 self:UpdateAction()
257 end 251 end
323 self.actionID = action 317 self.actionID = action
324 self:UpdateAll() 318 self:UpdateAll()
325 end 319 end
326 end 320 end
327 321
328 function Action:RefreshHasActionAttributes()
329 -- check if each action has an action or not, and flag an attribute
330 -- so that the showgrid secure handler can make decisions accordingly
331 local f = self:GetFrame()
332 local attr = "hasaction-"..self.config.actionID
333 local hasAction = HasAction(self.config.actionID)
334 if f:GetAttribute(attr) ~= hasAction then
335 f:SetAttribute(attr,hasAction) -- avoid setting attribute and triggering script handler unnecessarily
336 end
337 if self.config.pageactions then
338 for i = 1, self.nPages do
339 attr = "hasaction-"..self.config.pageactions[i]
340 hasAction = HasAction(self.config.pageactions[i])
341 if f:GetAttribute(attr) ~= hasAction then
342 f:SetAttribute(attr,hasAction)
343 end
344 end
345 end
346 end
347
348 function Action:UpdateShowGrid() 322 function Action:UpdateShowGrid()
349 -- this is a little bit complicated because there's no 323 if not InCombatLockdown() then
350 -- secure access to HasAction.
351 if InCombatLockdown() then
352 self.showgridPending = true -- handle after combat
353 else
354 self.showgridPending = false
355 self:RefreshHasActionAttributes()
356
357 -- the following is an out-of-combat show/hide to supplement the secure
358 -- handling and clean up after it when it guesses
359 local f = self:GetFrame() 324 local f = self:GetFrame()
360 local count = (f:GetAttribute("showgrid-event") or 0) + 325 local count = (f:GetAttribute("showgrid-event") or 0) +
361 (self.showGridTempCount or 0) + 326 (self.showGridTempCount or 0) +
362 (f:GetAttribute("showgrid") and 1 or 0) 327 (f:GetAttribute("showgrid") and 1 or 0)
363 328
783 if not IsAttackAction(self.actionID) then 748 if not IsAttackAction(self.actionID) then
784 self:SetFlash(false) 749 self:SetFlash(false)
785 end 750 end
786 end 751 end
787 752
788 function Action:PLAYER_REGEN_ENABLED()
789 if self.showgridPending then
790 self:UpdateShowGrid()
791 end
792 end
793
794 function Action:UNIT_INVENTORY_CHANGED(unit) 753 function Action:UNIT_INVENTORY_CHANGED(unit)
795 if unit == "player" then 754 if unit == "player" then
796 self:UpdateTooltip() 755 self:UpdateTooltip()
797 end 756 end
798 end 757 end