From 13300aae6ed3de3c5859e0172c4562ab2940eeb9 Mon Sep 17 00:00:00 2001 From: Hendrik Leppkes Date: Tue, 11 Dec 2007 08:32:48 +0000 Subject: [PATCH] more work done --- ActionBarPrototype.lua | 35 ++++++++++++++------ ActionBars.lua | 72 +++++++++++++++++++++++++++++++++++------- Bar.lua | 22 +++++++++++++ Bartender4.lua | 2 +- Bartender4.toc | 2 +- 5 files changed, 109 insertions(+), 24 deletions(-) diff --git a/ActionBarPrototype.lua b/ActionBarPrototype.lua index 766ad08..3295365 100644 --- a/ActionBarPrototype.lua +++ b/ActionBarPrototype.lua @@ -10,7 +10,7 @@ local math_floor = math.floor ActionBar Options ===================================================================================]]-- -local module +local module = Bartender4:GetModule("ActionBars") -- option utilty functions local getBar, optGetter, optSetter, optionMap, callFunc @@ -20,13 +20,11 @@ do padding = "Padding", buttons = "Buttons", rows = "Rows", + enabled = "Enabled", } -- retrieves a valid bar object from the modules actionbars table function getBar(id) - if not module then - module = Bartender4:GetModule("ActionBars") - end local bar = module.actionbars[tonumber(id)] assert(bar, "Invalid bar id in options table.") return bar @@ -54,24 +52,31 @@ do end end -local baroptions - -- returns the option table used for all action bars -- creates it, if the first time called -- the Universal Bar option table is merged into this, alot of stuff gets inherited. -function ActionBar:GetOptionsTable() - if not baroptions then - baroptions = Bartender4:Merge({ +function module:GetOptionsTable() + if not self.baroptions then + self.baroptions = Bartender4:Merge({ general = { -- type = inherited -- name = inherited -- cmdInline = inherited order = 1, args = { + enabled = { + order = 1, + name = "Enabled", + desc = "Enable/Disable the bar.", + type = "toggle", + set = optSetter, + get = optGetter, + }, style = { -- type = inherited -- name = inherited -- inline = inherited + -- order = inherited (5) args = { padding = { type = "range", @@ -124,7 +129,7 @@ function ActionBar:GetOptionsTable() }, Bar.GetOptionTable(self)) end - return baroptions + return self.baroptions end --[[=================================================================================== @@ -245,6 +250,16 @@ function ActionBar:SetRows(rows) self:UpdateButtonLayout() end +function ActionBar:GetEnabled() + return true +end + +function ActionBar:SetEnabled(state) + if not state then + module:DisableBar(self.id) + end +end + --[[=================================================================================== Utility function ===================================================================================]]-- diff --git a/ActionBars.lua b/ActionBars.lua index 552b622..6999ca1 100644 --- a/ActionBars.lua +++ b/ActionBars.lua @@ -28,6 +28,7 @@ function BT4ActionBars:OnInitialize() self:SetupOptions() + -- fetch the prototype information ActionBar = Bartender4.ActionBar ActionBar_MT = {__index = ActionBar} end @@ -42,6 +43,8 @@ function BT4ActionBars:OnEnable() local config = self.db.profile.ActionBars[i] if config.Enabled then self.actionbars[i] = self:Create(i, config) + else + self:CreateBarOption(i, self.disabledoptions) end end first = nil @@ -50,8 +53,13 @@ end -- Applys the config in the current profile to all active Bars function BT4ActionBars:ApplyConfig() - for i,v in ipairs(self.actionbars) do - v:ApplyConfig(self.db.profile.ActionBars[i]) + for i=1,10 do + local config = self.db.profile.ActionBars[i] + if config.Enabled then + self:EnableBar(i) + else + self:DisableBar(i) + end end end @@ -149,6 +157,31 @@ function BT4ActionBars:SetupOptions() }, } Bartender4:RegisterModuleOptions("actionbars", self.options) + + + self.disabledoptions = { + enabled = { + type = "toggle", + name = "Enabled", + desc = "Enable/Disable the bar.", + set = function(info, v) if v then BT4ActionBars:EnableBar(info[2]) end end, + get = function() return false end, + } + } +end + +function BT4ActionBars:CreateBarOption(id, options) + id = tostring(id) + if not self.options.args[id] then + self.options.args[id] = { + order = 10 + tonumber(id), + type = "group", + name = ("Bar %s"):format(id), + desc = ("Configure Bar %s"):format(id), + childGroups = "tab", + } + end + self.options.args[id].args = options end -- Creates a new bar object based on the id and the specified config @@ -156,16 +189,7 @@ function BT4ActionBars:Create(id, config) local id = tostring(id) local bar = setmetatable(Bartender4.Bar:Create(id, "SecureStateHeaderTemplate", config), ActionBar_MT) - local options = bar:GetOptionsTable() - - self.options.args[id] = { - order = 10 + tonumber(id), - type = "group", - name = ("Bar %s"):format(id), - desc = ("Configure Bar %s"):format(id), - args = options, - childGroups = "tab", - } + self:CreateBarOption(id, self:GetOptionsTable()) bar:ApplyConfig() -- debugging @@ -173,3 +197,27 @@ function BT4ActionBars:Create(id, config) return bar end + +function BT4ActionBars:DisableBar(id) + id = tonumber(id) + local bar = self.actionbars[id] + if not bar then return end + + bar.config.Enabled = false + bar:Hide() + self:CreateBarOption(id, self.disabledoptions) +end + +function BT4ActionBars:EnableBar(id) + id = tonumber(id) + local bar = self.actionbars[id] + local config = self.db.profile.ActionBars[id] + config.Enabled = true + if not bar then + bar = self:Create(id, config) + self.actionbars[id] = bar + else + self:CreateBarOption(id, self:GetOptionsTable()) + end + bar:ApplyConfig(config) +end diff --git a/Bar.lua b/Bar.lua index fa25496..532b423 100644 --- a/Bar.lua +++ b/Bar.lua @@ -16,6 +16,7 @@ local defaults = { Enabled = true, Scale = 1, Alpha = 1, + Show = true, } } @@ -69,6 +70,7 @@ do optionMap = { alpha = "ConfigAlpha", scale = "ConfigScale", + show = "Show", } -- retrieves a valid bar object from the barregistry table @@ -110,6 +112,14 @@ function Bar:GetOptionTable() name = "General Settings", order = 1, args = { + show = { + order = 3, + type = "toggle", + name = "Shown", + desc = "Show/Hide the bar.", + get = optGetter, + set = optSetter, + }, style = { type = "group", name = "Style", @@ -188,6 +198,7 @@ function Bar:ApplyConfig(config) if config then self.config = config end + self:SetShow() self:Lock() self:LoadPosition() self:SetConfigScale() @@ -249,6 +260,17 @@ function Bar:SetSize(width, height) self:SetHeight(height or width) end +function Bar:GetShow() + return self.config.Show +end + +function Bar:SetShow(show) + if show ~= nil then + self.config.Show = show + end + self[self.config.Show and "Show" or "Hide"](self) +end + function Bar:GetConfigAlpha() return self.config.Alpha end diff --git a/Bartender4.lua b/Bartender4.lua index ed3dfb8..be64586 100644 --- a/Bartender4.lua +++ b/Bartender4.lua @@ -42,7 +42,7 @@ end function Bartender4:Merge(target, source) if not target then target = {} end - for k,v in pairs(source) do + for k,v in pairs(source) do if type(v) == "table" then target[k] = self:Merge(target[k], v) elseif not target[k] then diff --git a/Bartender4.toc b/Bartender4.toc index 4a15d78..13008fe 100644 --- a/Bartender4.toc +++ b/Bartender4.toc @@ -20,5 +20,5 @@ Bar.lua Button.lua ## Modules ## -ActionBarPrototype.lua ActionBars.lua +ActionBarPrototype.lua