view Buttons.lua @ 7:f920db5fc6b1

version 0.3
author Flick <flickerstreak@gmail.com>
date Tue, 20 Mar 2007 21:25:29 +0000
parents
children c05fd3e18b4f
line wrap: on
line source
-- Buttons.lua
--
-- Defines button types for use with the ReAction AddOn
--

local AceOO = AceLibrary("AceOO-2.0")

local Action = AceOO.Class(
  ReAction, 
  ReAction.ActionType, 
  ReAction.ActionDisplay, 
  ReAction.DefaultColorScheme
)

local PetAction = AceOO.Class(
  ReAction, 
  ReAction.PetActionType, 
  ReAction.PetActionDisplay, 
  ReAction.DefaultColorScheme
)


ReAction:AddButtonType( "Action",    Action,    120 )
ReAction:AddButtonType( "Pet Action", PetAction, 10  )



-----------------------
-- static class members
-----------------------
Action.defaultProfile = {
  type = "ReAction",
  subtype = "Action",
  ids = { },
  selfcast = nil,
  keyBindLoc = "TOPRIGHT",
  stackCountLoc = "BOTTOMRIGHT",
  showKeyBind = true,
  showStackCount = true,
  showMacroText = true,
  showGrid = false,
  showBorder = true,
  keyBindColorCode = false,
}

PetAction.defaultProfile = {
  type = "ReAction",
  subtype = "Pet Action",
  ids = { },
  keyBindLoc = "TOPRIGHT",
  showKeyBind = false,
  showGrid = false,
  showBorder = true,
  keyBindColorCode = false,
}



-----------------------
-- static class methods
-----------------------
function Action:GetDefaultProfile()
  return self.defaultProfile
end

function PetAction:GetDefaultProfile()
  return self.defaultProfile
end



local labelPlacementOptions = { 
  "TOP", 
  "BOTTOM", 
  "LEFT", 
  "RIGHT", 
  "TOPLEFT", 
  "TOPRIGHT", 
  "BOTTOMLEFT", 
  "BOTTOMRIGHT" 
}


function Action:GenerateOptionsTable( config, buttonListFunc )

  local function refresh()
    for _, b in pairs(buttonListFunc()) do
      b:UpdateAction()
      b:UpdateTooltip()
      b:UpdateDisplay()
    end
  end

  return {
    type = "group",
    args = {
      selfcast = {
        type = "text",
        name = "Self Cast",
        desc = "Choose a modifier key to hold down or an alternate button to click to self-cast spells. "..
               "'default' uses the settings in the Interface Options Advanced panel (use this to achieve 'smart self cast'). "..
               "'right-click' self-casting is not supported for multi-page bars.",
        get  = function() return config.selfcast or "default" end,
        set  = function(opt) 
          if opt == "default" then opt = nil end
          config.selfcast = opt
          for _, b in pairs(buttonListFunc()) do
            b:UpdateSelfcast()
          end
        end,
        validate = { "default", "none", "alt", "ctrl", "shift", "right-click" },
      },

      keyloc = {
        type = "text",
        name = "Hotkey Location",
        desc = "Sets hotkey location",
        get  = function() return config.keyBindLoc end,
        set  = function(loc) config.keyBindLoc = loc ; refresh() end,
        validate = labelPlacementOptions,
      },
      
      stackloc = {
        type = "text",
        name = "Stack Count Location",
        desc = "Sets stack count location",
        get  = function() return config.stackCountLoc end,
        set  = function(loc) config.stackCountLoc = loc ; refresh() end,
        validate = labelPlacementOptions,
      },

      showkeybind = {
        type = "toggle",
        name = "Show Hotkey",
        desc = "Toggle show/hide hot key labels",
        get  = function() return config.showKeyBind end,
        set  = function() config.showKeyBind = not config.showKeyBind ; refresh() end,
      },

      showstackcount = {
        type = "toggle",
        name = "Show Stack Count",
        desc = "Toggle show/hide stack count labels",
        get  = function() return config.showStackCount end,
        set  = function() config.showStackCount = not config.showStackCount ; refresh() end,
      },

      showmacrotext = {
        type = "toggle",
        name = "Show Macro Names",
        desc = "Toggle show/hide macro name labels",
        get  = function() return config.showMacroText end,
        set  = function() config.showMacroText = not config.showMacroText ; refresh() end,
      },

      showgrid = {
        type = "toggle",
        name = "Always Show Buttons",
        desc = "Show button placeholders when no action is assigned or on the cursor. Note that buttons are always shown when bars are unlocked.",
        get  = function() return config.showGrid end,
        set  = function() config.showGrid = not config.showGrid ; refresh() end,
      },

      colorhotkeys = {
        type = "toggle",
        name = "Colorize Hotkeys",
        desc = "Toggles coloring hotkeys based on the modifier key. Out-of-range coloring is always enabled.",
        get  = function() return config.keyBindColorCode end,
        set  = function() config.keyBindColorCode = not config.keyBindColorCode ; refresh() end,
      },

      --[[
      hideborder = {
        type = "toggle",
        name = "Hide Border",
        desc = "Toggles hiding of the button border frame.",
        get  = function() return not config.showBorder end,
        set  = function() config.showBorder = not config.showBorder ; refresh() end,
      },]]
    }
  }
end


function PetAction:GenerateOptionsTable( config, buttonListFunc )

  local function refresh()
    for _, b in pairs(buttonListFunc()) do
      b:UpdateAction()
      b:UpdateTooltip()
      b:UpdateDisplay()
    end
  end

  return {
    type = "group",
    args = {
      keyloc = {
        type = "text",
        name = "Hotkey Location",
        desc = "Sets hotkey location",
        get  = function() return config.keyBindLoc end,
        set  = function(loc) config.keyBindLoc = loc ; refresh() end,
        validate = { "TOP", "BOTTOM", "LEFT", "RIGHT", "TOPLEFT", "TOPRIGHT", "BOTTOMLEFT", "BOTTOMRIGHT" },
      },
      
      showkeybind = {
        type = "toggle",
        name = "Show Hotkey",
        desc = "Toggle show/hide hot key labels",
        get  = function() return config.showKeyBind end,
        set  = function() config.showKeyBind = not config.showGrid ; refresh() end,
      },

      showgrid = {
        type = "toggle",
        name = "Always Show Buttons",
        desc = "Show button placeholders when no action is assigned or on the cursor. Note that buttons are always shown when bars are unlocked.",
        get  = function() return config.showGrid end,
        set  = function() config.showGrid = not config.showGrid ; refresh() end,
      },

      colorhotkeys = {
        type = "toggle",
        name = "Colorize Hotkeys",
        desc = "Toggles coloring hotkeys based on the modifier key. Out-of-range coloring is always enabled.",
        get  = function() return config.keyBindColorCode end,
        set  = function() config.keyBindColorCode = not config.keyBindColorCode ; refresh() end,
      },

      --[[
      hideborder = {
        type = "toggle",
        name = "Hide Border",
        desc = "Toggles hiding of the button border frame.",
        get  = function() return not config.showBorder end,
        set  = function() config.showBorder = not config.showBorder ; refresh() end,
      },]]
    }
  }
end



----------------------
-- Instance methods
----------------------
function Action.prototype:init( id )
  Action.super.prototype.init(self)
  
  self:SetupDisplay("ReActionButton"..id)
  self:SetupAction()

  -- register button with ReBound for keybinding
  if ReBound then
    ReBound:AddKeybindTarget(self:GetActionFrame())
  end
end

function PetAction.prototype:init( id )
  Action.super.prototype.init(self)
  
  self:SetupDisplay("ReActionPetButton"..id)
  self:SetupAction()

  -- register button with ReBound for keybinding
  if ReBound then
    ReBound:AddKeybindTarget(self:GetActionFrame())
  end
end