flickerstreak@159: --[[ flickerstreak@159: ReAction Vehicle Exit button module flickerstreak@159: flickerstreak@159: The button module implements a single button which you can use flickerstreak@159: to exit a vehicle that doesn't have controls (replacement for flickerstreak@159: MainMenuBarLeaveVehicleButton). flickerstreak@159: flickerstreak@159: --]] flickerstreak@159: flickerstreak@159: -- local imports flickerstreak@159: local ReAction = ReAction flickerstreak@159: local L = ReAction.L flickerstreak@159: flickerstreak@159: ReAction:UpdateRevision("$Revision: 200 $") flickerstreak@159: flickerstreak@159: -- module declaration flickerstreak@159: local moduleID = "VehicleExit" flickerstreak@159: local module = ReAction:NewModule( moduleID ) flickerstreak@159: flickerstreak@159: -- Button class flickerstreak@159: local Button = ReAction.Button.VehicleExit flickerstreak@159: flickerstreak@159: -- module methods flickerstreak@159: function module:OnInitialize() flickerstreak@159: self.db = ReAction.db:RegisterNamespace( moduleID, flickerstreak@159: { flickerstreak@159: profile = { flickerstreak@159: buttons = { } flickerstreak@159: } flickerstreak@159: } flickerstreak@159: ) flickerstreak@159: self.registered = { } flickerstreak@159: self.buttons = { } flickerstreak@159: flickerstreak@159: ReAction:RegisterBarOptionGenerator(self, "GetBarOptions") flickerstreak@159: flickerstreak@159: ReAction.RegisterCallback(self, "OnCreateBar") flickerstreak@159: ReAction.RegisterCallback(self, "OnDestroyBar") flickerstreak@159: ReAction.RegisterCallback(self, "OnRefreshBar") flickerstreak@159: ReAction.RegisterCallback(self, "OnEraseBar") flickerstreak@159: ReAction.RegisterCallback(self, "OnRenameBar") flickerstreak@159: end flickerstreak@159: flickerstreak@159: function module:OnEnable() flickerstreak@159: ReAction:RegisterBarType(L["Exit Vehicle Floater"], flickerstreak@159: { flickerstreak@159: type = moduleID , flickerstreak@159: defaultButtonSize = 36, flickerstreak@159: defaultBarRows = 1, flickerstreak@159: defaultBarCols = 1, flickerstreak@159: defaultBarSpacing = 3 flickerstreak@159: }) flickerstreak@159: end flickerstreak@159: flickerstreak@159: function module:OnDisable() flickerstreak@159: ReAction:UnregisterBarType(L["Exit Vehicle Floater"]) flickerstreak@159: end flickerstreak@159: flickerstreak@159: function module:OnCreateBar(event, bar, name) flickerstreak@159: if bar.config.type == moduleID then flickerstreak@159: self:OnRefreshBar(event, bar, name) flickerstreak@159: end flickerstreak@159: end flickerstreak@159: flickerstreak@159: function module:OnRefreshBar(event, bar, name) flickerstreak@159: if bar.config.type == moduleID then flickerstreak@159: local profile = self.db.profile flickerstreak@159: if profile.buttons[name] == nil then flickerstreak@159: profile.buttons[name] = {} flickerstreak@159: end flickerstreak@159: local btnCfg = profile.buttons[name] flickerstreak@159: flickerstreak@159: if profile.buttons[name] == nil then flickerstreak@159: profile.buttons[name] = { } flickerstreak@159: end flickerstreak@159: if self.buttons[bar] == nil then flickerstreak@159: local success, r = pcall(Button.New, Button, 1, profile.buttons[name], bar) flickerstreak@159: if success and r then flickerstreak@159: self.buttons[bar] = r flickerstreak@159: bar:AddButton(1,r) flickerstreak@159: end flickerstreak@159: else flickerstreak@159: self.buttons[bar]:Refresh() flickerstreak@159: end flickerstreak@159: bar:ClipNButtons(1) flickerstreak@159: self:UpdateRegistration(bar) flickerstreak@159: end flickerstreak@159: end flickerstreak@159: flickerstreak@159: function module:OnDestroyBar(event, bar, name) flickerstreak@159: if self.buttons[bar] then flickerstreak@159: self.buttons[bar]:Destroy() flickerstreak@159: self.buttons[bar] = nil flickerstreak@159: end flickerstreak@159: end flickerstreak@159: flickerstreak@159: function module:OnEraseBar(event, bar, name) flickerstreak@159: self.db.profile.buttons[name] = nil flickerstreak@159: end flickerstreak@159: flickerstreak@159: function module:OnRenameBar(event, bar, oldname, newname) flickerstreak@159: local b = self.db.profile.buttons flickerstreak@159: b[newname], b[oldname] = b[oldname], nil flickerstreak@159: end flickerstreak@159: flickerstreak@159: flickerstreak@159: function module:UpdateRegistration(bar) flickerstreak@159: -- auto show/hide when on a vehicle flickerstreak@159: local config = self.db.profile.buttons[bar:GetName()] flickerstreak@159: local f = bar:GetFrame() flickerstreak@159: if config.withControls then flickerstreak@159: if bar.vehicleExitStateRegistered then flickerstreak@159: UnregisterStateDriver(f, "unitexists") flickerstreak@159: bar.vehicleExitStateRegistered = false flickerstreak@159: end flickerstreak@159: bar:RegisterUnitWatch("vehicle",true) flickerstreak@159: else flickerstreak@159: bar:RegisterUnitWatch("vehicle",false) flickerstreak@159: if not bar.vehicleExitStateRegistered then flickerstreak@159: f:SetAttribute("unit","vehicle") flickerstreak@165: RegisterStateDriver(f, "unitexists", "[target=vehicle,exists,novehicleui] show; hide") -- spoof onstate-unitexists flickerstreak@159: bar.vehicleExitStateRegistered = true flickerstreak@159: end flickerstreak@159: end flickerstreak@159: end flickerstreak@159: flickerstreak@159: ---- Options ---- flickerstreak@159: local Handler = { } flickerstreak@159: local meta = { __index = Handler } flickerstreak@159: flickerstreak@159: function Handler:New(bar) flickerstreak@159: return setmetatable( flickerstreak@159: { flickerstreak@159: bar = bar flickerstreak@159: }, meta) flickerstreak@159: end flickerstreak@159: flickerstreak@159: function Handler:GetConfig() flickerstreak@159: return module.db.profile.buttons[self.bar:GetName()] flickerstreak@159: end flickerstreak@159: flickerstreak@159: function Handler:GetPassengerOnly() flickerstreak@159: return not self:GetConfig().withControls flickerstreak@159: end flickerstreak@159: flickerstreak@159: function Handler:SetPassengerOnly(info, value) flickerstreak@159: self:GetConfig().withControls = not value flickerstreak@159: module:UpdateRegistration(self.bar) flickerstreak@159: end flickerstreak@159: flickerstreak@159: flickerstreak@159: function module:GetBarOptions(bar) flickerstreak@159: if bar.config.type == moduleID then flickerstreak@159: return { flickerstreak@159: type = "group", flickerstreak@159: name = L["Exit Vehicle"], flickerstreak@159: handler = Handler:New(bar), flickerstreak@159: args = { flickerstreak@159: passengerOnly = { flickerstreak@159: name = L["Show only when passenger"], flickerstreak@159: desc = L["Only show the button when riding as a passenger in a vehicle (no vehicle controls)"], flickerstreak@159: order = 2, flickerstreak@159: width = "double", flickerstreak@159: type = "toggle", flickerstreak@159: get = "GetPassengerOnly", flickerstreak@159: set = "SetPassengerOnly", flickerstreak@159: }, flickerstreak@159: } flickerstreak@159: } flickerstreak@159: end flickerstreak@159: end flickerstreak@159: flickerstreak@159: