view 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 source
--[[
  ReAction Vehicle Exit button options module
--]]

-- local imports
local addonName, addonTable = ...
local ReAction = addonTable.ReAction
local L = ReAction.L

-- module declaration
local moduleID = "VehicleExit"
local module = ReAction:NewModule( moduleID )

-- Button class
local Button = ReAction.Button.VehicleExit

-- module methods
function module:OnInitialize()
  self.registered = { }
  self.buttons = { }

  ReAction:RegisterBarOptionGenerator(self, "GetBarOptions")
end

---- Options ----
local Handler = { }
local meta = { __index = Handler }

function Handler:New(bar)
  return setmetatable(
    {
      bar = bar
    }, meta)
end

function Handler:GetConfig()
  return self.bar:GetConfig()
end

function Handler:GetPassengerOnly()
  return not self:GetConfig().withControls
end

function Handler:SetPassengerOnly(info, value)
  self:GetConfig().withControls = not value
  Button:UpdateRegistration(self.bar)
end


function module:GetBarOptions(bar)
  if bar.config.type == moduleID then
    return {
      type = "group",
      name = L["Exit Vehicle"],
      handler = Handler:New(bar),
      args = {
        passengerOnly = {
          name = L["Show only when passenger"],
          desc = L["Only show the button when riding as a passenger in a vehicle (no vehicle controls)"],
          order = 2,
          width = "double",
          type = "toggle",
          get = "GetPassengerOnly",
          set = "SetPassengerOnly",
        },
      }
    }
  end
end