# HG changeset patch # User Flick # Date 1300838751 25200 # Node ID 0e20f65375d5c035d3aa7b79244d17a89d1b57f4 # Parent 9b9f5fc84d34f1d2c995310d5ecb687c3f72c5d8 Reworked button creation to not use goofy event driven semantics. diff -r 9b9f5fc84d34 -r 0e20f65375d5 ReAction.lua --- a/ReAction.lua Tue Mar 22 11:48:09 2011 -0700 +++ b/ReAction.lua Tue Mar 22 17:05:51 2011 -0700 @@ -185,7 +185,7 @@ end profile.bars[name] = config - local bar = self.Bar:New( name, config ) -- ReAction.Bar defined in Bar.lua + local bar = self.Bar:New( name, config, class ) -- ReAction.Bar defined in Bar.lua self.bars[name] = bar self.callbacks:Fire("OnCreateBar", bar, name) if self.configMode then diff -r 9b9f5fc84d34 -r 0e20f65375d5 classes/ActionButton.lua --- a/classes/ActionButton.lua Tue Mar 22 11:48:09 2011 -0700 +++ b/classes/ActionButton.lua Tue Mar 22 17:05:51 2011 -0700 @@ -192,15 +192,14 @@ ReAction.Button.Action = Action ReAction:RegisterBarType(Action, true) -function Action:New( idx, barConfig, bar, idHint ) +function Action:New( config, bar, idx, idHint ) local name = format("ReAction_%s_Action_%d",bar:GetName(),idx) - self = Super.New(self, name, barConfig.buttons[idx], bar, idx, "SecureActionButtonTemplate, ActionButtonTemplate" ) - self.barConfig = barConfig + self = Super.New(self, name, config, bar, idx, "SecureActionButtonTemplate, ActionButtonTemplate" ) + self.barConfig = bar:GetConfig() local f = self:GetFrame() local barFrame = bar:GetFrame() - local config = self:GetConfig() self.rangeTimer = TOOLTIP_UPDATE_TIME @@ -629,8 +628,11 @@ end end -function Action.SetupBarHeader( bar, config ) -- call this as a static method +function Action:SetupBar( bar ) + Super.SetupBar(self,bar) + local f = bar:GetFrame() + local config = bar:GetConfig() f:SetAttribute("mindcontrol",config.mindcontrol) f:SetAttribute("vehicle",config.vehicle) f:Execute( diff -r 9b9f5fc84d34 -r 0e20f65375d5 classes/BagButton.lua --- a/classes/BagButton.lua Tue Mar 22 11:48:09 2011 -0700 +++ b/classes/BagButton.lua Tue Mar 22 17:05:51 2011 -0700 @@ -16,6 +16,7 @@ -- class declarations local buttonTypeID = "Bag" +local weak = { __mode = "k" } local Super = ReAction.Button local BagBase = setmetatable( { @@ -30,7 +31,9 @@ }, barType = L["Bag Bar"], - buttonTypeID = buttonTypeID + buttonTypeID = buttonTypeID, + + allButtons = setmetatable( { }, weak ) }, { __index = Super } ) @@ -45,7 +48,7 @@ -- Bag Button base class -- -function BagBase:New( idx, btnCfg, bar, idHint ) +function BagBase:New( btnCfg, bar, idx, idHint ) local name = format("ReAction_%s_Bag_%d",bar:GetName(),idx) -- use a variable private leaf implementation class @@ -125,9 +128,17 @@ self:Refresh() + BagBase.allButtons[self] = true + return self end +function BagBase:Destroy() + BagBase.allButtons[self] = nil + Super.Destroy(self) +end + + function BagBase:GetActionID() return self.config.bagID end @@ -178,6 +189,10 @@ self:UpdateHotkey() end +function BagBase:IterateAllButtons() + return pairs(self.allButtons) +end + -- -- Bag Button class @@ -448,3 +463,37 @@ end end + + +-- hook some functions to propagate to our bag buttons +hooksecurefunc("Disable_BagButtons", + function() + for b in BagBase:IterateAllButtons() do + local f = b:GetFrame() + f:Disable() + SetDesaturation(b.frames.icon,1) + end + end) + +hooksecurefunc("Enable_BagButtons", + function() + for b in BagBase:IterateAllButtons() do + local f = b:GetFrame() + f:Enable() + SetDesaturation(b.frames.icon,nil) + end + end) + +hooksecurefunc("ContainerFrame_OnHide", + function() + for b in BagBase:IterateAllButtons() do + b:Update() + end + end) + +hooksecurefunc("ContainerFrame_OnShow", + function() + for b in BagBase:IterateAllButtons() do + b:Update() + end + end) diff -r 9b9f5fc84d34 -r 0e20f65375d5 classes/Bar.lua --- a/classes/Bar.lua Tue Mar 22 11:48:09 2011 -0700 +++ b/classes/Bar.lua Tue Mar 22 17:05:51 2011 -0700 @@ -184,12 +184,11 @@ ---- Bar class ---- local Bar = { } -local weak = { __mode = "k" } local frameList = { } ReAction.Bar = Bar -- export to ReAction -function Bar:New( name, config ) +function Bar:New( name, config, buttonClass ) if type(config) ~= "table" then error("ReAction.Bar: config table required") end @@ -197,11 +196,12 @@ -- create new self self = setmetatable( { - config = config, - name = name, - buttons = setmetatable( { }, weak ), - width = config.width or 480, - height = config.height or 40, + config = config, + name = name, + buttons = { }, + buttonClass = buttonClass, + width = config.width or 480, + height = config.height or 40, }, {__index = self} ) @@ -261,11 +261,16 @@ ReAction.RegisterCallback(self, "OnConfigModeChanged") + buttonClass:SetupBar(self) + return self end function Bar:Destroy() local f = self:GetFrame() + for idx, b in self:IterateButtons() do + b:Destroy() + end f:UnregisterAllEvents() self:ShowControls(false) ReAction.UnregisterAllCallbacks(self) @@ -302,7 +307,7 @@ -- LBF doesn't offer a method of renaming a group, so delete and remake the group. local c = self.config.ButtonFacade local g = ReAction.LBF:Group(L["ReAction"], name) - for b in self:IterateButtons() do + for idx, b in self:IterateButtons() do self.LBFGroup:RemoveButton(b:GetFrame(), true) g:AddButton(b:GetFrame()) end @@ -322,6 +327,10 @@ error("Invalid Bar object: used without initialization") end +function Bar:GetButton(idx) + return self.buttons[idx] +end + function Bar:GetConfig() return self.config end @@ -394,6 +403,7 @@ cfg.btnColumns = c cfg.spacing = s end + self.buttonClass:SetupBar(self) ReAction:RefreshBar(self) end @@ -409,7 +419,7 @@ end function Bar:IterateButtons() - -- iterator returns button, idx and does NOT iterate in index order + -- iterator returns idx, button, but does NOT iterate in index order return pairs(self.buttons) end @@ -420,7 +430,7 @@ function Bar:SetConfigMode(mode) self:SetSecureData("showAll",mode) self:ShowControls(mode) - for b in self:IterateButtons() do + for idx, b in self:IterateButtons() do b:ShowGridTemp(mode) b:UpdateActionIDLabel(mode) end @@ -428,7 +438,7 @@ function Bar:SetKeybindMode(mode) self:SetSecureData("showAll",mode) - for b in self:IterateButtons() do + for idx, b in self:IterateButtons() do b:SetKeybindMode(mode) end end @@ -473,8 +483,7 @@ function Bar:AddButton(idx, button) local f = self:GetFrame() - -- store in a weak reverse-index array - self.buttons[button] = idx + self.buttons[idx] = button -- Store a properly wrapped reference to the child frame as an attribute -- (accessible via "frameref-btn#") @@ -484,10 +493,10 @@ end function Bar:RemoveButton(button) - local idx = self.buttons[button] + local idx = button:GetIndex() if idx then self:GetFrame():SetAttribute(format("frameref-btn%d",idx),nil) - self.buttons[button] = nil + self.buttons[idx] = nil end if self.LBFGroup then self.LBFGroup:RemoveButton(button:GetFrame(),true) @@ -495,7 +504,7 @@ end function Bar:PlaceButton(button, baseW, baseH) - local idx = self.buttons[button] + local idx = button:GetIndex() if idx then local r, c, s = self:GetButtonGrid() local bh, bw = self:GetButtonSize() @@ -517,7 +526,7 @@ end function Bar:UpdateShowGrid() - for button in self:IterateButtons() do + for idx, button in self:IterateButtons() do button:UpdateShowGrid() end end @@ -675,7 +684,9 @@ f:SetAttribute("unit",unit) end if enable then - RegisterUnitWatch(self:GetFrame(),true) + if not self.unitwatch then + RegisterUnitWatch(self:GetFrame(),true) + end elseif self.unitwatch then UnregisterUnitWatch(self:GetFrame()) end diff -r 9b9f5fc84d34 -r 0e20f65375d5 classes/Button.lua --- a/classes/Button.lua Tue Mar 22 11:48:09 2011 -0700 +++ b/classes/Button.lua Tue Mar 22 17:05:51 2011 -0700 @@ -112,6 +112,10 @@ return self.frame end +function Button:GetIndex() + return self.idx +end + function Button:GetName() return self.name end @@ -142,6 +146,50 @@ self.actionMaxID = maxID end +function Button:SetupBar( bar ) + local config = bar:GetConfig() + if not config.buttons then + config.buttons = { } + end + local btnCfg = config.buttons + + local r, c = bar:GetButtonGrid() + local n = r*c + + local hint = nil + local i = 1 + repeat + local b = bar:GetButton(i) + if b then + if i > n then + bar:RemoveButton(b) + b:Destroy() + btnCfg[i] = nil + else + b:Refresh() + hint = b:GetActionID() + end + elseif i <= n then + local cfg = btnCfg[i] or { } + local success, r = pcall(self.New, self, cfg, bar, i, hint) -- note call semantics for derived class constructors + if success and r then + b = r + bar:AddButton(i,b) + btnCfg[i] = cfg + b:Refresh() + hint = b:GetActionID() + else + n = i - 1 + bar:ClipNButtons(n) + if not success then + geterrorhandler()(r) + end + end + end + i = i + 1 + until b == nil +end + function Button:AcquireActionID( id, hint, unique ) local poolID = self.actionPoolID local maxID = self.actionMaxID diff -r 9b9f5fc84d34 -r 0e20f65375d5 classes/MultiCastButton.lua --- a/classes/MultiCastButton.lua Tue Mar 22 11:48:09 2011 -0700 +++ b/classes/MultiCastButton.lua Tue Mar 22 17:05:51 2011 -0700 @@ -113,7 +113,7 @@ totemIDsBySlot[i] = self:GetAttribute("TOTEM_PRIORITY_"..i) end - -- these are set up in bar:SetupBarHeader() + -- these are set up in bar:SetupBar() flyoutChildren = flyoutChildren or newtable() summonSpells = summonSpells or newtable() ]] @@ -323,7 +323,7 @@ ReAction.Button.MultiCast = MultiCast ReAction:RegisterBarType(MultiCast) -function MultiCast:New( idx, btnConfig, bar ) +function MultiCast:New( btnConfig, bar, idx ) local maxIndex = bar.nTotemSlots or 0 if bar.summonSlot then maxIndex = maxIndex + 1 @@ -613,7 +613,9 @@ end end -function MultiCast.SetupBarHeader( bar ) -- call this as a static method +function MultiCast:SetupBar( bar ) + Super.SetupBar(self,bar) + local slot = 0 local nTotemSlots = 0 local summonSlot = nil @@ -757,6 +759,21 @@ flyout:UpdateTextures(slot) end + -- re-execute setup when new spells are loaded + if not f.events_registered then + f:RegisterEvent("UPDATE_MULTI_CAST_ACTIONBAR") + f:RegisterEvent("PLAYER_ENTERING_WORLD") + -- Bar.frame does not use OnEvent + f:SetScript("OnEvent", + function() + if not InCombatLockdown() then + self:SetupBar(bar) + end + end) + f.events_registered = true + end + + f:Execute(_bar_init) end diff -r 9b9f5fc84d34 -r 0e20f65375d5 classes/PetActionButton.lua --- a/classes/PetActionButton.lua Tue Mar 22 11:48:09 2011 -0700 +++ b/classes/PetActionButton.lua Tue Mar 22 17:05:51 2011 -0700 @@ -78,7 +78,7 @@ ReAction.Button.PetAction = Pet ReAction:RegisterBarType(Pet) -function Pet:New( idx, config, bar, idHint ) +function Pet:New( config, bar, idx, idHint ) local name = format("ReAction_%s_PetAction_%d",bar:GetName(),idx) self = Super.New(self, name, config, bar, idx, "SecureActionButtonTemplate, ActionButtonTemplate" ) @@ -160,6 +160,26 @@ return self end +function Pet:SetupBar(bar) + Super.SetupBar(self,bar) + + -- auto show/hide when pet exists + bar:RegisterUnitWatch("pet",true) + + self:UpdateButtonLock(bar) +end + +function Pet:UpdateButtonLock(bar) + local f = bar:GetFrame() + f:SetAttribute("lockbuttons",bar.config.lockButtons) + f:SetAttribute("lockbuttonscombat",bar.config.lockButtonsCombat) + f:Execute( + [[ + lockButtons = self:GetAttribute("lockbuttons") + lockButtonsCombat = self:GetAttribute("lockbuttonscombat") + ]]) +end + function Pet:Refresh() Super.Refresh(self) self:Update() diff -r 9b9f5fc84d34 -r 0e20f65375d5 classes/StanceButton.lua --- a/classes/StanceButton.lua Tue Mar 22 11:48:09 2011 -0700 +++ b/classes/StanceButton.lua Tue Mar 22 17:05:51 2011 -0700 @@ -52,7 +52,7 @@ ReAction.Button.Stance = Stance ReAction:RegisterBarType(Stance) -function Stance:New( idx, config, bar, idHint ) +function Stance:New( config, bar, idx, idHint ) local name = format("ReAction_%s_Stance_%d",bar:GetName(),idx) self = Super.New(self, name, config, bar, idx, "SecureActionButtonTemplate, ActionButtonTemplate" ) diff -r 9b9f5fc84d34 -r 0e20f65375d5 classes/VehicleExitButton.lua --- a/classes/VehicleExitButton.lua Tue Mar 22 11:48:09 2011 -0700 +++ b/classes/VehicleExitButton.lua Tue Mar 22 17:05:51 2011 -0700 @@ -28,7 +28,7 @@ ReAction.Button.VehicleExit = VExitButton ReAction:RegisterBarType(VExitButton) -function VExitButton:New( idx, config, bar ) +function VExitButton:New( config, bar, idx ) local name = format("ReAction_%s_VehicleExit_%d",bar:GetName(),idx) self = Super.New(self, name, config, bar, idx, "SecureFrameTemplate, ActionButtonTemplate", "Button") @@ -61,6 +61,11 @@ return self end +function VExitButton:SetupBar(bar) + Super.SetupBar(self,bar) + self:UpdateRegistration(bar) +end + function VExitButton:GetActionID() return 1 end @@ -80,3 +85,24 @@ function VExitButton:UPDATE_BINDINGS() self:UpdateHotkey() end + +function VExitButton:UpdateRegistration(bar) + -- auto show/hide when on a vehicle + local config = bar:GetConfig() + local f = bar:GetFrame() + if config.withControls then + if bar.vehicleExitStateRegistered then + UnregisterStateDriver(f, "unitexists") + bar.vehicleExitStateRegistered = false + end + bar:RegisterUnitWatch("vehicle",true) + else + bar:RegisterUnitWatch("vehicle",false) + if not bar.vehicleExitStateRegistered then + f:SetAttribute("unit","vehicle") + RegisterStateDriver(f, "unitexists", "[target=vehicle,exists,novehicleui] show; hide") -- spoof onstate-unitexists + bar.vehicleExitStateRegistered = true + end + end +end + diff -r 9b9f5fc84d34 -r 0e20f65375d5 modules/Action.lua --- a/modules/Action.lua Tue Mar 22 11:48:09 2011 -0700 +++ b/modules/Action.lua Tue Mar 22 17:05:51 2011 -0700 @@ -2,7 +2,6 @@ local ReAction = addonTable.ReAction local L = ReAction.L local _G = _G -local CreateFrame = CreateFrame local format = string.format local wipe = wipe @@ -22,10 +21,6 @@ self.handles = setmetatable({ }, weak) ReAction:RegisterBarOptionGenerator(self, "GetBarOptions") - - ReAction.RegisterCallback(self, "OnCreateBar") - ReAction.RegisterCallback(self, "OnRefreshBar") - ReAction.RegisterCallback(self, "OnDestroyBar") end function module:OnEnable() @@ -36,34 +31,12 @@ ReAction:GetModule("State"):UnregisterStateProperty("page") end -function module:OnCreateBar(event, bar, name) - if bar.config.type == moduleID then - if self.handles[bar] == nil then - self.handles[bar] = Handle:New(bar) - end - end -end - -function module:OnRefreshBar(event, bar, name) - if self.handles[bar] then - self.handles[bar]:Refresh() - end -end - -function module:OnDestroyBar(event, bar, name) - if self.handles[bar] then - self.handles[bar]:Destroy() - self.handles[bar] = nil - end -end ---- Interface ---- function module:GetBarOptions(bar) - local h = self.handles[bar] - if h then - return h:GetOptions() - end + self.handles[bar] = self.handles[bar] or Handle:New(bar) + return self.handles[bar]:GetOptions() end @@ -204,61 +177,16 @@ local meta = { __index = Handle } function Handle:New( bar ) - local config = bar:GetConfig() - local self = setmetatable( + return setmetatable( { bar = bar, - config = config, - btns = { } + config = bar:GetConfig(), }, meta) - - if self.config.buttons == nil then - self.config.buttons = { } - end - self:Refresh() - return self end function Handle:Refresh() - local r, c = self.bar:GetButtonGrid() - local n = r*c - local btnCfg = self.config.buttons - if n ~= #self.btns then - for i = 1, n do - if btnCfg[i] == nil then - btnCfg[i] = {} - end - if self.btns[i] == nil then - local lastButton = self:GetLastButton() - local hint = lastButton and lastButton.config.actionID - local b = Button:New(i, self.config, self.bar, hint) - self.btns[i] = b - self.bar:AddButton(i,b) - end - end - for i = n+1, #self.btns do - if self.btns[i] then - self.bar:RemoveButton(self.btns[i]) - self.btns[i]:Destroy() - self.btns[i] = nil - btnCfg[i] = nil - end - end - end - for _, b in ipairs(self.btns) do - b:Refresh() - end - Button.SetupBarHeader(self.bar,self.config) - self:UpdateButtonLock() - end - - function Handle:Destroy() - for _,b in pairs(self.btns) do - if b then - b:Destroy() - end - end + Button:SetupBar(bar) end function Handle:UpdateButtonLock() @@ -266,7 +194,7 @@ end function Handle:GetLastButton() - return self.btns[#self.btns] + return self.bar:GetButton(self.bar:GetNumButtons()) end -- options handlers @@ -282,7 +210,7 @@ function Handle:SetHideEmpty(info, value) if value ~= self.config.hideEmpty then self.config.hideEmpty = value - for _, b in pairs(self.btns) do + for _, b in self.bar:IterateButtons() do b:ShowGrid(not value) end end @@ -439,7 +367,7 @@ local col = self.selectedColumn or 1 local r, c = self.bar:GetButtonGrid() local n = (row-1) * c + col - local btn = self.btns[n] + local btn = self.bar:GetButton(n) if btn then return tostring(btn:GetActionID(self.selectedPage or 1)) end @@ -450,7 +378,7 @@ local col = self.selectedColumn or 1 local r, c = self.bar:GetButtonGrid() local n = (row-1) * c + col - local btn = self.btns[n] + local btn = self.bar:GetButton(n) if btn then btn:SetActionID(tonumber(value), self.selectedPage or 1) end @@ -472,7 +400,7 @@ local p = { } for i = 1, self.config.nPages or 1 do local b = { } - for _, btn in ipairs(self.btns) do + for _, btn in self.bar:IterateButtons() do table.insert(b, btn:GetActionID(i)) end table.insert(p, table.concat(b,",")) @@ -501,17 +429,17 @@ end function Handle:SetMultiID(info, value) - local p = ParseMultiID(#self.btns, self.config.nPages or 1, value) + local p = ParseMultiID(self.bar:GetNumButtons(), self.config.nPages or 1, value) for page, b in ipairs(p) do for button, id in ipairs(b) do - self.btns[button]:SetActionID(id, page) + self.bar:GetButton(button):SetActionID(id, page) end end end function Handle:ValidateMultiID(info, value) local bad = L["Invalid action ID list string"] - if value == nil or ParseMultiID(#self.btns, self.config.nPages or 1, value) == nil then + if value == nil or ParseMultiID(self.bar:GetNumButtons(), self.config.nPages or 1, value) == nil then return bad end return true diff -r 9b9f5fc84d34 -r 0e20f65375d5 modules/Bag.lua --- a/modules/Bag.lua Tue Mar 22 11:48:09 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,128 +0,0 @@ ---[[ - ReAction Bag button module - ---]] - --- local imports -local addonName, addonTable = ... -local ReAction = addonTable.ReAction -local L = ReAction.L -local _G = _G - --- Bag button -local Button = ReAction.Button.Bag - --- module declaration -local moduleID = "Bag" -local module = ReAction:NewModule( moduleID - -- mixins go here -) - --- handlers -function module:OnInitialize() - self.buttons = { } - - ReAction.RegisterCallback(self, "OnCreateBar", "OnRefreshBar") - ReAction.RegisterCallback(self, "OnDestroyBar") - ReAction.RegisterCallback(self, "OnRefreshBar") -end - -function module:OnDestroyBar(event, bar, name) - local btns = self.buttons[bar] - if btns then - for _,b in pairs(btns) do - if b then - b:Destroy() - end - end - self.buttons[bar] = nil - end -end - -function module:OnRefreshBar(event, bar, name) - local config = bar:GetConfig() - if config.type == moduleID then - local btns = self.buttons[bar] - if btns == nil then - btns = { } - self.buttons[bar] = btns - end - if not config.buttons then - config.buttons = { } - end - local btnCfg = config.buttons - - local r, c = bar:GetButtonGrid() - local n = r*c - for i = 1, n do - if btnCfg[i] == nil then - btnCfg[i] = {} - end - if btns[i] == nil then - local success, r = pcall(Button.New,Button,i,btnCfg[i],bar,i>1 and btnCfg[i-1].bagID) - if success and r then - btns[i] = r - bar:AddButton(i,r) - else - n = i - 1 - bar:ClipNButtons(n) - break - end - end - btns[i]:Refresh() - end - for i = n+1, #btns do - if btns[i] then - bar:RemoveButton(btns[i]) - btns[i] = btns[i]:Destroy() - if btnCfg[i] then - btnCfg[i] = nil - end - end - end - end - -end - - - --- hook some functions to propagate to our bag buttons -hooksecurefunc("Disable_BagButtons", - function() - for _, buttons in pairs(module.buttons) do - for _, b in pairs(buttons) do - local f = b:GetFrame() - f:Disable() - SetDesaturation(b.frames.icon,1) - end - end - end) - -hooksecurefunc("Enable_BagButtons", - function() - for _, buttons in pairs(module.buttons) do - for _, b in pairs(buttons) do - local f = b:GetFrame() - f:Enable() - SetDesaturation(b.frames.icon,nil) - end - end - end) - -hooksecurefunc("ContainerFrame_OnHide", - function() - for _, buttons in pairs(module.buttons) do - for _, b in pairs(buttons) do - b:Update() - end - end - end) - -hooksecurefunc("ContainerFrame_OnShow", - function() - for _, buttons in pairs(module.buttons) do - for _, b in pairs(buttons) do - b:Update() - end - end - end) diff -r 9b9f5fc84d34 -r 0e20f65375d5 modules/PetAction.lua --- a/modules/PetAction.lua Tue Mar 22 11:48:09 2011 -0700 +++ b/modules/PetAction.lua Tue Mar 22 17:05:51 2011 -0700 @@ -1,9 +1,5 @@ --[[ - ReAction Pet Action button module - - The button module implements standard action button functionality by wrapping Blizzard's - PetActionButton frame and associated functions. - + ReAction Pet Action button options module --]] -- local imports @@ -21,92 +17,12 @@ -- Button class local Button = ReAction.Button.PetAction --- private -local function UpdateButtonLock(bar) - local f = bar:GetFrame() - f:SetAttribute("lockbuttons",bar.config.lockButtons) - f:SetAttribute("lockbuttonscombat",bar.config.lockButtonsCombat) - f:Execute( - [[ - lockButtons = self:GetAttribute("lockbuttons") - lockButtonsCombat = self:GetAttribute("lockbuttonscombat") - ]]) -end -- module methods function module:OnInitialize() - self.buttons = { } - ReAction:RegisterBarOptionGenerator(self, "GetBarOptions") - - ReAction.RegisterCallback(self, "OnCreateBar") - ReAction.RegisterCallback(self, "OnDestroyBar") - ReAction.RegisterCallback(self, "OnRefreshBar") end -function module:OnCreateBar(event, bar, name) - if bar.config.type == moduleID then - -- auto show/hide when pet exists - bar:RegisterUnitWatch("pet",true) - self:OnRefreshBar(event, bar, name) - end -end - -function module:OnRefreshBar(event, bar, name) - local config = bar:GetConfig() - if config.type == moduleID then - if self.buttons[bar] == nil then - self.buttons[bar] = { } - end - local btns = self.buttons[bar] - if not config.buttons then - config.buttons = { } - end - local btnCfg = config.buttons - - local r, c = bar:GetButtonGrid() - local n = r*c - for i = 1, n do - if btnCfg[i] == nil then - btnCfg[i] = {} - end - if btns[i] == nil then - local success, r = pcall(Button.New,Button,i,btnCfg[i],bar,i>1 and btnCfg[i-1].actionID) - if success and r then - btns[i] = r - bar:AddButton(i,r) - else - n = i - 1 - bar:ClipNButtons(n) - break - end - end - btns[i]:Refresh() - end - for i = n+1, #btns do - if btns[i] then - bar:RemoveButton(btns[i]) - btns[i] = btns[i]:Destroy() - if btnCfg[i] then - btnCfg[i] = nil - end - end - end - UpdateButtonLock(bar) - end -end - -function module:OnDestroyBar(event, bar, name) - if self.buttons[bar] then - local btns = self.buttons[bar] - for _,b in pairs(btns) do - if b then - b:Destroy() - end - end - self.buttons[bar] = nil - end -end @@ -128,7 +44,7 @@ function Handler:SetLockButtons(info, value) self.config.lockButtons = value - UpdateButtonLock(self.bar) + Button:UpdateButtonLock(self.bar) end function Handler:GetLockButtonsCombat() @@ -137,7 +53,7 @@ function Handler:SetLockButtonsCombat(info, value) self.config.lockButtonsCombat = value - UpdateButtonLock(self.bar) + Button:UpdateButtonLock(self.bar) end function Handler:LockButtonsCombatDisabled() diff -r 9b9f5fc84d34 -r 0e20f65375d5 modules/Stance.lua --- a/modules/Stance.lua Tue Mar 22 11:48:09 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ ---[[ - ReAction Stance button module - ---]] - --- local imports -local addonName, addonTable = ... -local ReAction = addonTable.ReAction -local L = ReAction.L -local _G = _G - --- Stance button -local Button = ReAction.Button.Stance - --- module declaration -local moduleID = "Stance" -local module = ReAction:NewModule( moduleID - -- mixins go here -) - --- handlers -function module:OnInitialize() - self.buttons = { } - - ReAction.RegisterCallback(self, "OnCreateBar", "OnRefreshBar") - ReAction.RegisterCallback(self, "OnDestroyBar") - ReAction.RegisterCallback(self, "OnRefreshBar") -end - -function module:OnDestroyBar(event, bar, name) - local btns = self.buttons[bar] - if btns then - for _,b in pairs(btns) do - if b then - b:Destroy() - end - end - self.buttons[bar] = nil - end -end - -function module:OnRefreshBar(event, bar, name) - local config = bar:GetConfig() - if config.type == moduleID then - local btns = self.buttons[bar] - if btns == nil then - btns = { } - self.buttons[bar] = btns - end - if not config.buttons then - config.buttons = { } - end - local btnCfg = config.buttons - - local r, c = bar:GetButtonGrid() - local n = r*c - for i = 1, n do - if btnCfg[i] == nil then - btnCfg[i] = {} - end - if btns[i] == nil then - local success, r = pcall(Button.New,Button,i,btnCfg[i],bar,i>1 and btnCfg[i-1].stanceID) - if success and r then - btns[i] = r - bar:AddButton(i,r) - else - n = i - 1 - bar:ClipNButtons(n) - break - end - end - btns[i]:Refresh() - end - for i = n+1, #btns do - if btns[i] then - bar:RemoveButton(btns[i]) - btns[i] = btns[i]:Destroy() - if btnCfg[i] then - btnCfg[i] = nil - end - end - end - end - -end - diff -r 9b9f5fc84d34 -r 0e20f65375d5 modules/Totem.lua --- a/modules/Totem.lua Tue Mar 22 11:48:09 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,110 +0,0 @@ ---[[ - ReAction Totem button module - ---]] - --- local imports -local addonName, addonTable = ... -local ReAction = addonTable.ReAction -local L = ReAction.L -local _G = _G - --- button -local Button = ReAction.Button.MultiCast - --- module declaration -local moduleID = "Totem" -local module = ReAction:NewModule( moduleID, - "AceEvent-3.0" - -- mixins go here -) - --- handlers -function module:OnInitialize() - self.buttons = { } - - ReAction.RegisterCallback(self, "OnCreateBar", "OnRefreshBar") - ReAction.RegisterCallback(self, "OnDestroyBar") - ReAction.RegisterCallback(self, "OnRefreshBar") - - self:RegisterEvent("UPDATE_MULTI_CAST_ACTIONBAR","PLAYER_ENTERING_WORLD") -end - -function module:OnDestroyBar(event, bar, name) - local btns = self.buttons[bar] - if btns then - for _,b in pairs(btns) do - if b then - b:Destroy() - end - end - self.buttons[bar] = nil - end -end - -function module:OnRefreshBar(event, bar, name) - local config = bar:GetConfig() - if config.type == moduleID then - local btns = self.buttons[bar] - if btns == nil then - btns = { } - self.buttons[bar] = btns - end - if not config.buttons then - config.buttons = { } - end - local btnCfg = config.buttons - - local r, c = bar:GetButtonGrid() - local n = min(r*c,6) - Button.SetupBarHeader(bar) - for i = 1, n do - if btnCfg[i] == nil then - btnCfg[i] = {} - end - if not btns[i] then - local success, r = pcall(Button.New,Button,i,btnCfg,bar) - if success then - btns[i] = r - if r then - bar:AddButton(i,r) - end - else - geterrorhandler()(r) - n = i - 1 - bar:ClipNButtons(n) - break - end - end - if btns[i] then - btns[i]:Refresh() - end - end - for i = n+1, #btns do - if btns[i] then - bar:RemoveButton(btns[i]) - btns[i] = btns[i]:Destroy() - if btnCfg[i] then - btnCfg[i] = nil - end - end - end - end - -end - -function module:UPDATE_MULTI_CAST_ACTIONBAR() - if not InCombatLockdown() then - for bar in pairs(self.buttons) do - self:OnRefreshBar("OnRefreshBar", bar, bar:GetName()) - end - end -end - -function module:PLAYER_ENTERING_WORLD() - for bar in pairs(self.buttons) do - self:OnRefreshBar("OnRefreshBar", bar, bar:GetName()) - end -end - - diff -r 9b9f5fc84d34 -r 0e20f65375d5 modules/VehicleExit.lua --- a/modules/VehicleExit.lua Tue Mar 22 11:48:09 2011 -0700 +++ b/modules/VehicleExit.lua Tue Mar 22 17:05:51 2011 -0700 @@ -1,10 +1,5 @@ --[[ - ReAction Vehicle Exit button module - - The button module implements a single button which you can use - to exit a vehicle that doesn't have controls (replacement for - MainMenuBarLeaveVehicleButton). - + ReAction Vehicle Exit button options module --]] -- local imports @@ -25,67 +20,6 @@ self.buttons = { } ReAction:RegisterBarOptionGenerator(self, "GetBarOptions") - - ReAction.RegisterCallback(self, "OnCreateBar") - ReAction.RegisterCallback(self, "OnDestroyBar") - ReAction.RegisterCallback(self, "OnRefreshBar") -end - -function module:OnCreateBar(event, bar, name) - if bar.config.type == moduleID then - self:OnRefreshBar(event, bar, name) - end -end - -function module:OnRefreshBar(event, bar, name) - local config = bar:GetConfig() - if config.type == moduleID then - if not config.buttons then - config.buttons = { } - end - local btnCfg = config.buttons - btnCfg[1] = btnCfg[1] or { } - - if self.buttons[bar] == nil then - local success, r = pcall(Button.New, Button, 1, btnCfg[1], bar) - if success and r then - self.buttons[bar] = r - bar:AddButton(1,r) - end - else - self.buttons[bar]:Refresh() - end - bar:ClipNButtons(1) - self:UpdateRegistration(bar) - end -end - -function module:OnDestroyBar(event, bar, name) - if self.buttons[bar] then - self.buttons[bar]:Destroy() - self.buttons[bar] = nil - end -end - - -function module:UpdateRegistration(bar) - -- auto show/hide when on a vehicle - local config = bar:GetConfig() - local f = bar:GetFrame() - if config.withControls then - if bar.vehicleExitStateRegistered then - UnregisterStateDriver(f, "unitexists") - bar.vehicleExitStateRegistered = false - end - bar:RegisterUnitWatch("vehicle",true) - else - bar:RegisterUnitWatch("vehicle",false) - if not bar.vehicleExitStateRegistered then - f:SetAttribute("unit","vehicle") - RegisterStateDriver(f, "unitexists", "[target=vehicle,exists,novehicleui] show; hide") -- spoof onstate-unitexists - bar.vehicleExitStateRegistered = true - end - end end ---- Options ---- @@ -109,7 +43,7 @@ function Handler:SetPassengerOnly(info, value) self:GetConfig().withControls = not value - module:UpdateRegistration(self.bar) + Button:UpdateRegistration(self.bar) end