Mercurial > wow > reaction
diff modules/PetAction.lua @ 234:0e20f65375d5
Reworked button creation to not use goofy event driven semantics.
author | Flick |
---|---|
date | Tue, 22 Mar 2011 17:05:51 -0700 |
parents | c4b134512c50 |
children |
line wrap: on
line diff
--- 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()