more work done
This commit is contained in:
+25
-10
@@ -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
|
||||
===================================================================================]]--
|
||||
|
||||
+60
-12
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+1
-1
@@ -20,5 +20,5 @@ Bar.lua
|
||||
Button.lua
|
||||
|
||||
## Modules ##
|
||||
ActionBarPrototype.lua
|
||||
ActionBars.lua
|
||||
ActionBarPrototype.lua
|
||||
|
||||
Reference in New Issue
Block a user