diff modules/HideBlizzard.lua @ 120:320a93c5f72c

Added option to hide the Blizzard vehicle bar Refactored HideBlizzard module
author Flick <flickerstreak@gmail.com>
date Fri, 06 Feb 2009 23:01:50 +0000
parents 410d036c43b2
children 61d89f0918ca
line wrap: on
line diff
--- a/modules/HideBlizzard.lua	Fri Feb 06 23:01:02 2009 +0000
+++ b/modules/HideBlizzard.lua	Fri Feb 06 23:01:50 2009 +0000
@@ -34,100 +34,99 @@
   self.hiddenFrame:Hide()
 
   ReAction:RegisterOptions(self, {
-      hideBlizzard = {
-        type = "toggle",
-        handler = 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  = function(info,value) self:SetHidden(value) end,
-        disabled = InCombatLockdown
+        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()
-  if self.db.profile.hide then
-    self:HideAll(true)
-  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 )
+  self:UpdateFrames()
 end
 
 function module:OnDisable()
-  self:ShowAll(true)
+  self:UpdateFrames(true)
 end
 
 function module:OnProfileChanged()
-  if self.db.profile.hide then
-    module:HideAll(true)
-  else
-    module:ShowAll(true)
-  end
+  self:UpdateFrames()
 end
 
 local frames = {
-  MainMenuBar,
-  MultiBarLeft,
-  MultiBarRight,
-  MultiBarBottomLeft,
-  MultiBarBottomRight,
-  -- possess bar frame needs to be pulled out separately: stash its children away
-  PossessBarLeft,
-  PossessBarRight,
-  PossessButton1,
-  PossessButton2
+  [ MainMenuBar         ] = { },
+  [ MultiBarLeft        ] = { },
+  [ MultiBarRight       ] = { },
+  [ MultiBarBottomLeft  ] = { },
+  [ MultiBarBottomRight ] = { },
+  [ VehicleMenuBar      ] = { field = "hideVehicle" },
 }
 
-local hidden = { }
+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
 
-function module:HideAll( force )
-  if not(self.db.profile.hide) or force then
-    self.db.profile.hide = true
-    for _, f in pairs(frames) do
-      hidden[f] = hidden[f] or { parent = f:GetParent(), wasShown = f:IsShown() }
-      f:SetParent(self.hiddenFrame)
-      f:Hide()
-    end
-  end
-  PossessBarFrame:SetParent(UIParent)
-  PossessBarFrame:EnableMouse(false)
-end
-
-function module:ShowAll( force )
-  PossessBarFrame:EnableMouse(true)
-  PossessBarFrame:SetParent(MainMenuBar)
-  if self.db.profile.hide or force then
-    self.db.profile.hide = false
-
-    for _, f in pairs(frames) do
-      local h = hidden[f]
-      if h then
-        f:SetParent(h.parent)
-        if h.wasShown then
-          f:Show()
-        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()
-  return self.db.profile.hide
+function module:IsHidden(info)
+  return self.db.profile.hide and self.db.profile[info[#info]]
 end
 
-function module:SetHidden(h)
-  if h then
-    self:HideAll()
-  else
-    self:ShowAll()
-  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 )