Mercurial > wow > reaction
diff modules/VehicleExit.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/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