Mercurial > wow > reaction
diff 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 |
line wrap: on
line diff
--- a/classes/ActionButton.lua Wed Mar 04 21:19:32 2009 +0000 +++ b/classes/ActionButton.lua Thu Mar 05 01:28:48 2009 +0000 @@ -59,12 +59,19 @@ end self:SetAttribute("action",action) - local hasaction = (action > 120) or self:GetAttribute("hasaction-"..action) - if (self:GetAttribute("showgrid") + self:GetAttribute("showgrid-temp") == 0) and not hasaction then - self:Hide() - else - self:Show() + if not self:GetAttribute("showgrid") then + local hasaction = (action > 120) or self:GetAttribute("hasaction-"..action) + local tempShow = self:GetAttribute("showgrid-temp") + local evtShow = self:GetAttribute("showgrid-event") + if tempShow then tempShow = (tempShow > 0) end + if evtShow then evtShow = (evtShow > 0) end + + if tempShow or evtShow or hasaction then + self:Show() + else + self:Hide() + end end ]] @@ -83,18 +90,20 @@ local _childupdate_showgrid = -- function(self, snippetid, message) [[ - self:SetAttribute("showgrid-temp",message or 0) - local count = (message or 0) + (self:GetAttribute("showgrid") or 0) - if count == 0 then - local action = self:GetAttribute("action") - local hasaction = (action > 120) or self:GetAttribute("hasaction-"..action) - if hasaction then + self:SetAttribute("showgrid-event",message) + if not self:GetAttribute("showgrid") then + local count = message + (self:GetAttribute("showgrid-temp") or 0) + if count <= 0 then + local action = self:GetAttribute("action") + local hasaction = (action > 120) or self:GetAttribute("hasaction-"..action) + if hasaction then + self:Show() + else + self:Hide() + end + else self:Show() - else - self:Hide() end - else - self:Show() end ]] @@ -111,15 +120,11 @@ local _onReceiveDrag = -- function(self, button, kind, value, ...) [[ - if lockButtons and (PlayerInCombat() or not lockButtonsCombat) and not IsModifiedClick("PICKUPACTION") then - return kind, value, ... - else - if kind == "spell" or kind == "item" or kind == "macro" then - -- assume it's a valid action - self:SetAttribute("hasaction-"..self:GetAttribute("action"),true) - end - return "action", self:GetAttribute("action") + if kind == "spell" or kind == "item" or kind == "macro" then + -- assume it's a valid action + self:SetAttribute("hasaction-"..self:GetAttribute("action"),true) end + return "action", self:GetAttribute("action") ]] -- @@ -154,13 +159,14 @@ local Action = setmetatable( { }, { __index = Super } ) ReAction.Button.Action = Action -function Action:New( idx, config, bar, idHint ) +function Action:New( idx, barConfig, bar, idHint ) local name = format("ReAction_%s_Action_%d",bar:GetName(),idx) - self = Super.New(self, name, config, bar, idx, "SecureActionButtonTemplate, ActionButtonTemplate" ) + self = Super.New(self, name, barConfig, bar, idx, "SecureActionButtonTemplate, ActionButtonTemplate" ) local f = self:GetFrame() local barFrame = bar:GetFrame() + local config = self:GetConfig() local frames = { } self.frames = frames @@ -190,9 +196,12 @@ f:SetAttribute("useparent-unit", true) f:SetAttribute("action", config.actionID) f:SetAttribute("default-action", config.actionID) - f:SetAttribute("showgrid",0) + f:SetAttribute("bar-idx",idx) f:SetAttribute("showgrid-temp",0) - f:SetAttribute("bar-idx",idx) + f:SetAttribute("showgrid-event",0) + f:SetAttribute("showgrid",not self:GetBarConfig().hideEmpty) + + self:RefreshHasActionAttributes() -- non secure scripts f:SetScript("OnEvent", function(frame, ...) self:OnEvent(...) end) @@ -205,7 +214,7 @@ f:SetScript("OnReceiveDrag", function(frame) self:OnReceiveDrag() end) -- secure handlers - f:SetAttribute("_childupate", _childupdate) + f:SetAttribute("_childupdate", _childupdate) f:SetAttribute("_childupdate-showgrid",_childupdate_showgrid) barFrame:WrapScript(f, "OnDragStart", _onDragStart) barFrame:WrapScript(f, "OnReceiveDrag", _onReceiveDrag) @@ -222,13 +231,10 @@ bar:SkinButton(self) -- initial display - self:ShowGrid(not bar:GetConfig().hideEmpty) if ReAction:GetConfigMode() then - self:ShowGrid(true) + self:ShowGridTemp(true) end - f:Show() - self:Refresh() return self @@ -236,37 +242,64 @@ function Action:Destroy() local f = self:GetFrame() + local c = self:GetConfig() f:UnregisterAllEvents() f:SetAttribute("_childupdate-vehicle",nil) - self:ReleaseActionID(config.actionID) - if self.config.pageactions then - for _, id in ipairs(self.config.pageactions) do + self:ReleaseActionID(c.actionID) + if c.pageactions then + for _, id in ipairs(c.pageactions) do self:ReleaseActionID(id) end end - Super:Destroy() + Super.Destroy(self) end function Action:Refresh() self.bar:PlaceButton(self, 36, 36) self:RefreshPages() self:InstallVehicle() + self:ShowGrid(not self:GetBarConfig().hideEmpty) self:UpdateAction() end function Action:InstallVehicle() - if self.idx == 7 and self.bar:GetConfig().vehicle then + if self.idx == 7 and self:GetBarConfig().vehicle then -- install vehicle-exit button on 7th button (only) - f:SetAttribute("_childupdate-vehicle", _childupdate_vehicleExit) - barFrame.ShowVehicleExit = function(bar,show) + self:GetFrame():SetAttribute("_childupdate-vehicle", _childupdate_vehicleExit) + self:GetBar():GetFrame().ShowVehicleExit = function(bar,show) self:ShowVehicleExit(show) end else - f:SetAttribute("_childupdate-vehicle",nil) + self:GetFrame():SetAttribute("_childupdate-vehicle",nil) + end +end + +function Action:ShowGrid( show ) + if not InCombatLockdown() then + self.frame:SetAttribute("showgrid", show) + self:UpdateShowGrid() + end +end + +function Action:ShowGridTemp( show ) + -- This function only modifies the show-grid when out + -- of combat, and is ignored by the secure handler. Use + -- it for configuration modes. + if not InCombatLockdown() then + local count = self.showGridTempCount or 0 + if show then + count = count + 1 + else + count = count - 1 + end + if count < 0 then count = 0 end + self.showGridTempCount = count + self:GetFrame():SetAttribute("showgrid-temp",count) + self:UpdateShowGrid() end end @@ -293,28 +326,48 @@ end end +function Action:RefreshHasActionAttributes() + -- check if each action has an action or not, and flag an attribute + -- so that the showgrid secure handler can make decisions accordingly + local f = self:GetFrame() + local attr = "hasaction-"..self.config.actionID + local hasAction = HasAction(self.config.actionID) + if f:GetAttribute(attr) ~= hasAction then + f:SetAttribute(attr,hasAction) -- avoid setting attribute and triggering script handler unnecessarily + end + if self.config.pageactions then + for i = 1, self.nPages do + attr = "hasaction-"..self.config.pageactions[i] + hasAction = HasAction(self.config.pageactions[i]) + if f:GetAttribute(attr) ~= hasAction then + f:SetAttribute(attr,hasAction) + end + end + end +end + function Action:UpdateShowGrid() -- this is a little bit complicated because there's no - -- secure driver to handle show/hide grid events. + -- secure access to HasAction. if InCombatLockdown() then self.showgridPending = true -- handle after combat else self.showgridPending = false - -- check if each action has an action or not, and flag an attribute - -- so that the showgrid secure handler can make decisions accordingly - local f = self:GetFrame() - f:SetAttribute("hasaction-"..self.config.actionID, HasAction(self.config.actionID)) - if self.config.pageactions then - for i = 1, self.nPages do - f:SetAttribute("hasaction-"..self.config.pageactions[i], HasAction(self.config.pageactions[i])) - end - end + self:RefreshHasActionAttributes() + -- the following is an out-of-combat show/hide to supplement the secure -- handling and clean up after it when it guesses - if HasAction(self.actionID) then + local f = self:GetFrame() + local count = (f:GetAttribute("showgrid-event") or 0) + + (self.showGridTempCount or 0) + + (f:GetAttribute("showgrid") and 1 or 0) + + if count <= 0 and not HasAction(self.actionID) then + if f:IsShown() then + f:Hide() + end + elseif not f:IsShown() then f:Show() - else - f:Hide() end end end @@ -507,7 +560,7 @@ end function Action:RefreshPages( force ) - local nPages = self.bar:GetConfig().nPages + local nPages = self:GetBarConfig().nPages if nPages and (nPages ~= self.nPages or force) then local f = self:GetFrame() local c = self.config.pageactions @@ -532,11 +585,10 @@ end end -function Action.SetupBarHeader( bar ) -- call this as a static method +function Action.SetupBarHeader( bar, config ) -- call this as a static method local f = bar:GetFrame() - local c = bar:GetConfig() - f:SetAttribute("mindcontrol",c.mindcontrol) - f:SetAttribute("vehicle",c.vehicle) + f:SetAttribute("mindcontrol",config.mindcontrol) + f:SetAttribute("vehicle",config.vehicle) f:Execute( [[ doMindControl = self:GetAttribute("mindcontrol") @@ -547,8 +599,8 @@ f:SetAttribute("_onstate-mc", _onstate_mc) RegisterStateDriver(f, "mc", "[target=vehicle,exists] vehicle; [bonusbar:5] mc; none") - f:SetAttribute("lockbuttons",c.lockButtons) - f:SetAttribute("lockbuttonscombat",c.lockButtonsCombat) + f:SetAttribute("lockbuttons",config.lockButtons) + f:SetAttribute("lockbuttonscombat",config.lockButtonsCombat) f:Execute( [[ lockButtons = self:GetAttribute("lockbuttons") @@ -572,7 +624,7 @@ function Action:ShowVehicleExit(show) local f = self:GetFrame() local tx = f.vehicleExitTexture - if show and self.bar:GetConfig().vehicle then + if show and self:GetBarConfig().vehicle then if not tx then tx = f:CreateTexture(nil,"ARTWORK") tx:SetAllPoints() @@ -629,7 +681,7 @@ function Action:ACTIONBAR_SLOT_CHANGED(event, action) if action == 0 or action == self.actionID then - self:UpdateAction() + self:UpdateAll() end end