view modules/HideBlizzard.lua @ 148:de1da46dadb3

moved unitwatch handling into bar
author Flick <flickerstreak@gmail.com>
date Fri, 08 May 2009 00:06:53 +0000
parents 320a93c5f72c
children 61d89f0918ca
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 ReAction = ReAction
local L = ReAction.L

ReAction:UpdateRevision("$Revision$")

-- 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()

  ReAction:RegisterOptions(self, {
      hide = {
        name = L["Hide Blizzard Action Bars"],
        desc = L["Hide the default main bar and extra action bars"],
        type = "toggle",
        order = 10,
        width = "double",
        handler = self,
        get  = "IsHidden",
        set  = "SetHidden",
        disabled = "OptionDisabled",
      },
      hideVehicle = {
        name = L["Hide Blizzard Vehicle Bar"],
        desc = L["Hide the default vechicle action bar"],
        type = "toggle",
        order = 11,
        width = "double",
        handler = self,
        get  = "IsHidden",
        set  = "SetHidden",
        disabled = "OptionDisabled",
      },
    }, true) -- global

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)
  return self.db.profile.hide and self.db.profile[info[#info]]
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:ShowConfig()
    end
  end )