view modules/HideBlizzard.lua @ 183:1696ff2c80cc

minor library rename/storage/cleanup
author Flick <flickerstreak@gmail.com>
date Fri, 22 Oct 2010 15:56:08 +0000
parents 55c2fc0c8d55
children
line wrap: on
line source
--[[
  ReAction 'Hide Blizzard' module

  Hides Blizzard action bars. This hides the extra action bars, stance bar, pet bar, and 
  main menu bar, which in turn hides the experience bar, bag bar, micro menu bar, and lag meter.

--]]

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

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


-- module methods
function module:OnInitialize()
  self.db = ReAction.db:RegisterNamespace( moduleID,
    { 
      profile = {
        hide = false
      }
    }
  )
  self.db.RegisterCallback(self,"OnProfileChanged")
  self.db.RegisterCallback(self,"OnProfileCopied", "OnProfileChanged")
  self.db.RegisterCallback(self,"OnProfileReset",  "OnProfileChanged")

  self.hiddenFrame = CreateFrame("Frame")
  self.hiddenFrame:Hide()

  -- It's fairly normal to use the Blizzard vehicle bar, and to have
  -- your regular buttons in the same location. If you do this, and don't
  -- bother to hide your buttons, they'll obscure some parts of the vehicle bar.
  VehicleMenuBar:SetFrameLevel(VehicleMenuBar:GetFrameLevel()+3)

end

function module:OnEnable()
  self:UpdateFrames()
end

function module:OnDisable()
  self:UpdateFrames(true)
end

function module:OnProfileChanged()
  self:UpdateFrames()
end

local frames = {
  [ MainMenuBar         ] = { },
  [ MultiBarLeft        ] = { },
  [ MultiBarRight       ] = { },
  [ MultiBarBottomLeft  ] = { },
  [ MultiBarBottomRight ] = { },
  [ VehicleMenuBar      ] = { field = "hideVehicle" },
}

function module:UpdateFrames( show )
  show = show or not self.db.profile.hide
  for frame, info in pairs(frames) do
    local show = show  -- make a local copy for this frame
    if info.field then
      show = show or not self.db.profile[info.field]
    end

    if show then
      if info.parent then
        frame:SetParent(info.parent)
      end
      if frame:IsShown() then
        frame:Show() -- refresh
      end
    else
      if not info.parent then
        info.parent = frame:GetParent()
      end
      frame:SetParent(self.hiddenFrame)
    end
  end
end

function module:IsHidden(info)
  if info then
    return self.db.profile.hide and self.db.profile[info[#info]]
  else
    return self.db.profile.hide
  end
end

function module:SetHidden(info,value)
  self.db.profile[info[#info]] = value
  self:UpdateFrames()
end

function module:OptionDisabled(info)
  local disabled = InCombatLockdown()
  if not disabled and info[#info] ~= "hide" then
    disabled = not self.db.profile.hide
  end
  return disabled
end


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