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

-- local imports
local addonName, addonTable = ...
local ReAction = addonTable.ReAction
local L = ReAction.L
local _G = _G
local CreateFrame = CreateFrame
local format = string.format

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

-- Button class
local Button = ReAction.Button.PetAction


-- module methods
function module:OnInitialize()
  ReAction:RegisterBarOptionGenerator(self, "GetBarOptions")
end




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

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

function Handler:GetLockButtons()
  return self.config.lockButtons
end

function Handler:SetLockButtons(info, value)
  self.config.lockButtons = value
  Button:UpdateButtonLock(self.bar)
end

function Handler:GetLockButtonsCombat()
  return self.config.lockButtonsCombat
end

function Handler:SetLockButtonsCombat(info, value)
  self.config.lockButtonsCombat = value
  Button:UpdateButtonLock(self.bar)
end

function Handler:LockButtonsCombatDisabled()
  return not self.config.lockButtons
end


function module:GetBarOptions(bar)
  if bar.config.type == moduleID then
    return {
      type = "group",
      name = L["Pet Buttons"],
      handler = Handler:New(bar),
      args = {
        lockButtons = {
          name = L["Lock Buttons"],
          desc = L["Prevents picking up/dragging actions (use SHIFT to override this behavior)"],
          order = 2,
          type = "toggle",
          get = "GetLockButtons",
          set = "SetLockButtons",
        },
        lockOnlyCombat = {
          name = L["Only in Combat"],
          desc = L["Only lock the buttons when in combat"],
          order = 3,
          type = "toggle",
          disabled = "LockButtonsCombatDisabled",
          get = "GetLockButtonsCombat",
          set = "SetLockButtonsCombat",
        },
      }
    }
  end
end