use plugins to merge options together

This commit is contained in:
Hendrik Leppkes
2007-12-08 13:47:19 +00:00
parent caa746668c
commit cf182cdd74
3 changed files with 179 additions and 41 deletions
+75 -37
View File
@@ -11,11 +11,8 @@ local stancedefaults = {
ROGUE = { stealth = 7 }
}
local defaults = {
local defaults = Bartender4:Merge({
['**'] = {
Enabled = true,
Scale = 1,
Alpha = 1,
Buttons = 12,
Padding = 2,
Rows = 1,
@@ -24,7 +21,7 @@ local defaults = {
[1] = {
Stances = stancedefaults,
},
}
}, Bartender4.Bar.defaults)
function BT4ActionBars:OnInitialize()
self.db = Bartender4.db
@@ -93,49 +90,57 @@ function BT4ActionBars:SetupOptions()
self.options = {
order = 20,
type = "group",
--cmdInline = true,
-- cmdInline = true,
name = "Action Bars",
get = getFunc,
args = {
range = {
general = {
order = 1,
name = "Out of Range Indicator",
desc = "Configure how the Out of Range Indicator should display on the buttons.",
type = "select",
style = "dropdown",
arg = "OutOfRange",
set = function(info, value)
Bartender4.db.profile.OutOfRange = value
BT4ActionBars:ForAllButtons("UpdateUsable")
end,
values = { none = "No Display", button = "Full Button Mode", hotkey = "Hotkey Mode" },
},
colors = {
order = 2,
type = "group",
guiInline = true,
name = "Colors",
get = function(info)
local color = Bartender4.db.profile.Colors[info[#info]]
return color.r, color.g, color.b
end,
set = function(info, r, g, b)
local color = Bartender4.db.profile.Colors[info[#info]]
color.r, color.g, color.b = r, g, b
BT4ActionBars:ForAllButtons("UpdateUsable")
end,
name = "General Options",
args = {
range = {
order = 1,
type = "color",
name = "Out of Range Indicator",
desc = "Specify the Color of the Out of Range Indicator",
desc = "Configure how the Out of Range Indicator should display on the buttons.",
type = "select",
style = "dropdown",
arg = "OutOfRange",
set = function(info, value)
Bartender4.db.profile.OutOfRange = value
BT4ActionBars:ForAllButtons("UpdateUsable")
end,
values = { none = "No Display", button = "Full Button Mode", hotkey = "Hotkey Mode" },
},
mana = {
colors = {
order = 2,
type = "color",
name = "Out of Mana Indicator",
desc = "Specify the Color of the Out of Mana Indicator",
type = "group",
guiInline = true,
name = "Colors",
get = function(info)
local color = Bartender4.db.profile.Colors[info[#info]]
return color.r, color.g, color.b
end,
set = function(info, r, g, b)
local color = Bartender4.db.profile.Colors[info[#info]]
color.r, color.g, color.b = r, g, b
BT4ActionBars:ForAllButtons("UpdateUsable")
end,
args = {
range = {
order = 1,
type = "color",
name = "Out of Range Indicator",
desc = "Specify the Color of the Out of Range Indicator",
},
mana = {
order = 2,
type = "color",
name = "Out of Mana Indicator",
desc = "Specify the Color of the Out of Mana Indicator",
},
},
},
},
},
@@ -144,11 +149,44 @@ function BT4ActionBars:SetupOptions()
Bartender4:RegisterModuleOptions("actionbars", self.options)
end
function BT4ActionBars:GetOptionsTable()
if not self.baroptions then
self.baroptions = {
swap = {
type = "group",
name = "Page Swapping",
order = 5,
args = {
},
},
}
end
return self.baroptions
end
-- Creates a new bar object based on the id and the specified config
function BT4ActionBars:Create(id, config)
local id = tostring(id)
local bar = setmetatable(Bartender4.Bar:Create(id, "SecureStateHeaderTemplate", config), ActionBar_MT)
local baroptions = Bartender4.Bar:GetOptionsTable()
local actionbaroptions = self:GetOptionsTable()
self.options.args[id] = {
order = 10 + tonumber(id),
type = "group",
name = ("Bar %s"):format(id),
desc = ("Configure Bar %s"):format(id),
plugins = {
bar = baroptions,
actionbar = actionbaroptions,
},
args = { },
childGroups = "tab",
}
bar:ApplyConfig()
-- debugging
--bar:Unlock()
+91 -4
View File
@@ -7,14 +7,26 @@
local Bar = CreateFrame("Button")
local Bar_MT = {__index = Bar}
local function createOptions(id)
end
local barregistry = {}
local defaults = {
['**'] = {
Enabled = true,
Scale = 1,
Alpha = 1,
}
}
Bartender4.Bar = {}
Bartender4.Bar.defaults = defaults
Bartender4.Bar.prototype = Bar
function Bartender4.Bar:Create(id, template, config)
id = tostring(id)
if barregistry[id] then
error(("A bar with id %s has already been registered."):format(id), 2)
end
local bar = setmetatable(CreateFrame("Button", ("BT4Bar%s"):format(id), UIParent, template), Bar_MT)
barregistry[id] = bar
bar.id = id
bar:EnableMouse(false)
@@ -39,11 +51,74 @@ function Bartender4.Bar:Create(id, template, config)
bar.Text:SetPoint("CENTER", bar, "CENTER")
bar.config = config
bar.options = createOptions(id)
return bar
end
local getBar, optGetter, optSetter, optionMap
do
optionMap = {
alpha = "Alpha",
}
function getBar(id)
local bar = barregistry[tostring(id)]
assert(bar, "Invalid bar id in options table.")
return bar
end
function callFunc(bar, type, option, ...)
local func = type .. "Config" .. optionMap[option]
assert(bar[func], "Invalid get/set function.")
return bar[func](bar, ...)
end
function optGetter(info)
local bar = getBar(info[#info-2])
local option = info[#info]
return callFunc(bar, "Get", option)
end
function optSetter(info, ...)
local bar = getBar(info[#info-2])
local option = info[#info]
return callFunc(bar, "Set", option, ...)
end
end
function Bartender4.Bar:GetOptionsTable()
if not self.options then
self.options = {
general = {
order = 1,
type = "group",
name = "General Options",
cmdInline = true,
args = {
alpha = {
name = "Alpha",
desc = "Configure the alpha of the bar.",
type = "range",
min = .1, max = 1, bigStep = 0.1,
get = optGetter,
set = optSetter,
},
}
},
align = {
order = 10,
type = "group",
name = "Alignment",
args = {
}
},
}
end
return self.options
end
local barOnEnter, barOnLeave, barOnDragStart, barOnDragStop, barOnClick
do
function barOnEnter(self)
@@ -136,6 +211,18 @@ function Bar:SetSize(width, height)
self:SetHeight(height or width)
end
function Bar:GetConfigAlpha()
return self.config.Alpha
end
function Bar:SetConfigAlpha(alpha)
if alpha then
self.config.Alpha = alpha
end
self:SetAlpha(self.config.Alpha)
end
--[[
Lazyness functions
]]
+13
View File
@@ -13,6 +13,7 @@ function Bartender4:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("Bartender4DB")
self.db.RegisterCallback(self, "OnProfileChanged", "UpdateModuleConfigs")
self.db.RegisterCallback(self, "OnProfileCopied", "UpdateModuleConfigs")
self.db.RegisterCallback(self, "OnProfileReset", "UpdateModuleConfigs")
self:SetupOptions()
end
@@ -38,3 +39,15 @@ function Bartender4:Update()
end
end
end
function Bartender4:Merge(target, source)
if not target then target = {} end
for k,v in pairs(source) do
if type(v) == "table" then
target[k] = self:Merge(target[k], v)
elseif not target[k] then
target[k] = v
end
end
return target
end