view Options.lua @ 273:07a1cbf38812

Merge
author Flick
date Wed, 11 May 2011 09:54:18 -0700
parents 741c4f9b251e
children 36a29870bf34
line wrap: on
line source
local addonName, addonTable = ...
local ReAction = addonTable.ReAction
local L = ReAction.L
local InCombatLockdown = InCombatLockdown


local configID = "ReAction"
local displayName = L["ReAction"]


function ReAction:InitializeOptions()
  local AceConfigReg    = LibStub("AceConfigRegistry-3.0")
  local AceConfigDialog = LibStub("AceConfigDialog-3.0")

  local options = {
    type = "group",
    name = displayName,
    handler = self,
    args = {
      general = {
        type = "group",
        name = displayName,
        args = {
          _desc = {
            type     = "description",
            name     = L["Customizable replacement for Blizzard's Action Bars"],
            order    = 1,
          },
          unlock = {
            type     = "toggle",
            name     = L["Unlock Bars"],
            desc     = L["Unlock bars for dragging and resizing with the mouse"],
            get      = "GetConfigMode",
            set      = "OptionSetConfigMode",
            width    = "full",
            disabled = InCombatLockdown,
            order    = 2,
          },
          hide = {
            type     = "toggle",
            name     = L["Hide Blizzard Action Bars"],
            desc     = L["Hide the default main bar and extra action bars"],
            get      = "OptionGetHideBlizzardBars",
            set      = "OptionSetHideBlizzardBars",
            disabled = InCombatLockdown,
            width    = "full",
            order    = 3,
          },
          hideVehicle = {
            type     = "toggle",
            name     = L["Hide Blizzard Vehicle Bar"],
            desc     = L["Hide the default vechicle action bar"],
            get      = "OptionGetHideBlizzardVehicleBar",
            set      = "OptionSetHideBlizzardVehicleBar",
            disabled = function() return InCombatLockdown() or ReAction:OptionGetHideBlizzardBars() == false end,
            width    = "full",
            order    = 4,
          },
          edit = {
            type     = "execute",
            name     = L["Edit Bars..."],
            desc     = L["Show the ReAction Bar Editor dialogue"],
            func     = "OptionShowEditor",
            order    = 5,
          },
          keybind = {
            type     = "execute",
            name     = L["Key Bindings"],
            desc     = L["Show the keybinding dialogue"],
            func     = "OptionLaunchKeybindMode",
            order    = 6,
          },
          skipProfileWarning = {
            type     = "toggle",
            name     = L["Skip profile keybind warning"],
            desc     = L["Don't show a warning about updating keybinds when switching profiles"],
            get      = "OptionGetSkipKeybindWarning",
            set      = "OptionSetSkipKeybindWarning",
            width    = "double",
            order    = 7,
          },
        }
      },
      profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db),
    }
  }

  AceConfigReg:RegisterOptionsTable(configID,options)

  local f = AceConfigDialog:AddToBlizOptions(configID, displayName, nil, "general")

  if f and f.obj then
    f.obj:SetCallback("default", 
      function() 
        self.db:ResetProfile()
        AceConfigReg:NotifyChange(configID)
      end )
  end

  AceConfigDialog:AddToBlizOptions(configID, options.args.profiles.name, configID, "profiles")

  SlashCmdList["REACTION"] = function(option)
    option = string.match(option or "", "^%s*(%S+)")
    if option == "config" or option == "options" then
      ReAction:ShowOptions()
    elseif option == "edit" then
      ReAction:ShowEditor()
    elseif option == "unlock" then
      ReAction:SetConfigMode(true)
    elseif option == "lock" then
      ReAction:SetConfigMode(false)
    elseif option == "kb" then
      ReAction:SetKeybindMode(true)
    else
      print(("%s %s %s"):format(L["ReAction"], ReAction.version, L["Usage:"]))
      print("/rxn config")
      print("/rxn edit")
      print("/rxn lock")
      print("/rxn unlock")
      print("/rxn kb")
    end
  end

  _G["SLASH_REACTION1"] = "/reaction"
  _G["SLASH_REACTION2"] = "/rxn"

  StaticPopupDialogs["REACTION_KB_WARN"] = {
    text = L["ReAction profile changed: check your keybinds, they may need to be updated."],
    button1 = L["OK"],
    hideOnEscape = true,
    enterClicksFirstButton = true,
    timeout = 0,
    showAlert = true,
    whileDead = true,
  }

  -- reroute blizzard action bar config to ReAction config window
  InterfaceOptionsActionBarsPanel:HookScript("OnShow", 
    function() 
      if ReAction:OptionGetHideBlizzardBars() then
        ReAction:ShowOptions()
      end
    end )
end


function ReAction:ShowOptions()
  InterfaceOptionsFrame_OpenToCategory(configID)
end


function ReAction:OptionSetConfigMode(info, value)
  self:SetConfigMode(value) 
end


function ReAction:OptionShowEditor()
  self:ShowEditor()
  InterfaceOptionsFrame:Hide()
end


function ReAction:OptionLaunchKeybindMode()
  self:SetKeybindMode(true)
end


function ReAction:OptionGetSkipKeybindWarning()
  return self.db.global.skipKeybindWarning
end


function ReAction:OptionSetSkipKeybindWarning(info, value)
  self.db.global.skipKeybindWarning = value
end


function ReAction:OptionSetHideBlizzardBars( info, hide )
  self.db.profile.options.hideBlizzardBars = hide
  self:ManageBlizzardBars()
end

function ReAction:OptionGetHideBlizzardBars()
  return self.db.profile.options.hideBlizzardBars
end

function ReAction:OptionSetHideBlizzardVehicleBar( info, hide )
  self.db.profile.options.hideBlizzardVehicleBar = hide
  self:ManageBlizzardBars()
end

function ReAction:OptionGetHideBlizzardVehicleBar()
  return self.db.profile.options.hideBlizzardVehicleBar
end


-- export to LDB
local LDB = LibStub:GetLibrary("LibDataBroker-1.1")
if LDB then
  LDB:NewDataObject( "ReAction", 
  {
    type = "launcher", 
    icon = "Interface\\Icons\\INV_Qiraj_JewelEncased",

    OnClick = function( frame, button )
      if not InCombatLockdown() then
        if IsAltKeyDown() then
          ReAction:SetKeybindMode( not ReAction:GetKeybindMode() )
        elseif IsShiftKeyDown() then
          ReAction:SetConfigMode( not ReAction:GetConfigMode() )
        elseif button == "RightButton" then
          ReAction:ShowEditor()
        else
          ReAction:ShowOptions()
        end
      else
        ReAction:UserError(L["ReAction: can't configure in combat"])
      end
    end,

      -- this isn't included in the 'launcher' type LDB spec but it seems all launcher displays use it
    OnTooltipShow = function( tooltip )
      tooltip:AddLine(format("|cffffffff%s|r %s",L["Click"],L["for options"]))
      tooltip:AddLine(format("|cffffd200%s|r %s",L["Right-click"],L["for bar editor dialog"]))
      tooltip:AddLine(format("|cff00ff00%s|r %s",L["Shift-click"],L["to unlock bars"]))
      tooltip:AddLine(format("|cff00cccc%s|r %s",L["Alt-click"],L["for keybind mode"]))
    end,

  })
end