view modules/Stance.lua @ 162:fc08372f0c7a

- Fixed icon behavior with buttonfacade - Fixed bad usage of IsAttackAction() API (and various others) by trimming event list
author Flick <flickerstreak@gmail.com>
date Fri, 21 Aug 2009 23:50:17 +0000
parents 901c91dc1bf2
children df68b5a40490
line wrap: on
line source
--[[
  ReAction Stance button module

--]]

-- local imports
local ReAction = ReAction
local L = ReAction.L
local _G = _G

-- Stance button 
local Button = ReAction.Button.Stance

-- module declaration
local moduleID = "Stance"
local module = ReAction:NewModule( moduleID
  -- mixins go here
)

-- handlers
function module:OnInitialize()
  self.db = ReAction.db:RegisterNamespace( moduleID,
    {
      profile = { 
        buttons = { }
      }
    }
  )

  self.buttons = { }

  ReAction:RegisterOptions(self, self:GetOptions())

  ReAction.RegisterCallback(self, "OnCreateBar", "OnRefreshBar")
  ReAction.RegisterCallback(self, "OnDestroyBar")
  ReAction.RegisterCallback(self, "OnRefreshBar")
  ReAction.RegisterCallback(self, "OnEraseBar")
  ReAction.RegisterCallback(self, "OnRenameBar")
end

function module:OnEnable()
  ReAction:RegisterBarType(L["Stance Bar"], 
    { 
      type = moduleID ,
      defaultButtonSize = 36,
      defaultBarRows = 1,
      defaultBarCols = 8,
      defaultBarSpacing = 3
    })

end

function module:OnDisable()
  ReAction:UnregisterBarType(L["Stance Bar"])
end

function module:OnDestroyBar(event, bar, name)
  local btns = self.buttons[bar]
  if btns then
    for _,b in pairs(btns) do
      if b then
        b:Destroy()
      end
    end
    self.buttons[bar] = nil
  end
end

function module:OnRefreshBar(event, bar, name)
  if bar.config.type == moduleID then
    local btns = self.buttons[bar]
    if btns == nil then
      btns = { }
      self.buttons[bar] = btns
    end
    local profile = self.db.profile
    if profile.buttons[name] == nil then
      profile.buttons[name] = {}
    end
    local btnCfg = profile.buttons[name]

    local r, c = bar:GetButtonGrid()
    local n = r*c
    for i = 1, n do
      if btnCfg[i] == nil then
        btnCfg[i] = {}
      end
      if btns[i] == nil then
        local success, r = pcall(Button.New,Button,i,profile,bar,i>1 and btnCfg[i-1].stanceID)
        if success and r then
          btns[i] = r
          bar:AddButton(i,r)
        else
          n = i - 1
          bar:ClipNButtons(n)
          break
        end
      end
      btns[i]:Refresh()
    end
    for i = n+1, #btns do
      if btns[i] then
        bar:RemoveButton(btns[i])
        btns[i] = btns[i]:Destroy()
        if btnCfg[i] then
          btnCfg[i] = nil
        end
      end
    end
  end

end

function module:OnEraseBar(event, bar, name)
  self.db.profile.buttons[name] = nil
end

function module:OnRenameBar(event, bar, oldName, newName)
  local b = self.db.profile.buttons
  b[newname], b[oldname] = b[oldname], nil
end

function module:RefreshAll()
  for bar in pairs(self.buttons) do
    self:OnRefreshBar(nil,bar,bar:GetName())
  end
end


---- options ----
function module:GetOptions()
  return {
    stance = 
    {
      name = L["Stance Buttons"],
      type = "group",
      args = {
        showAspects = {
          name = L["Show Aspects"],
          desc = L["Show Hunter aspects as stances"],
          order = 1,
          width = "double",
          type = "toggle",
          set = function(info,value) self.db.profile.showHunterAspects = value; self:RefreshAll() end,
          get = function() return self.db.profile.showHunterAspects end,
        },
        hideMonkeyHawk = {
          name = L["Auto-hide Monkey/Hawk"],
          desc = L["Hide Aspect of the Monkey and Aspect of the Hawk, only when the hunter knows Aspect of the Dragonhawk"],
          order = 2,
          width = "double",
          type = "toggle",
          set = function(info,value) self.db.profile.hideMonkeyHawk = value; self:RefreshAll() end,
          get = function() return self.db.profile.hideMonkeyHawk end,
          disabled = function() return self.db.profile.showHunterAspects == false end,
        },
        hidePresences = {
          name = L["Hide Presences"],
          desc = L["Do not show Death Knight Presences as stances"],
          order = 3,
          width = "double",
          type = "toggle",
          set = function(info,value) self.db.profile.hideDKPresences = value; self:RefreshAll() end,
          get = function() return self.db.profile.hideDKPresences end,
        },
        hideAuras = {
          name = L["Hide Auras"],
          desc = L["Do not show Paladin Auras as stances"],
          order = 4,
          width = "double",
          type = "toggle",
          set = function(info,value) self.db.profile.hidePaladinAuras = value; self:RefreshAll() end,
          get = function() return self.db.profile.hidePaladinAuras end,
        },
      }
    }
  }
end