some reordering and more options

This commit is contained in:
Hendrik Leppkes
2007-12-09 11:45:03 +00:00
parent 675a871ada
commit 587c066fe5
4 changed files with 190 additions and 99 deletions
+160 -12
View File
@@ -6,9 +6,130 @@ Bartender4.ActionBar = ActionBar
local math_floor = math.floor
--[[
Bar Prototype Functions
]]
--[[===================================================================================
ActionBar Options
===================================================================================]]--
local module
-- option utilty functions
local getBar, optGetter, optSetter, optionMap, callFunc
do
-- maps option keys to function names
optionMap = {
padding = "Padding",
buttons = "Buttons",
rows = "Rows",
}
-- 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
end
-- calls a function on the bar
function callFunc(bar, type, option, ...)
local func = type .. (optionMap[option] or option)
assert(bar[func], "Invalid get/set function."..func)
return bar[func](bar, ...)
end
-- universal function to get a option
function optGetter(info)
local bar = getBar(info[2])
local option = info[#info]
return callFunc(bar, "Get", option)
end
-- universal function to set a option
function optSetter(info, ...)
local bar = getBar(info[2])
local option = info[#info]
return callFunc(bar, "Set", option, ...)
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({
general = {
-- type = inherited
-- name = inherited
-- cmdInline = inherited
order = 1,
args = {
style = {
-- type = inherited
-- name = inherited
-- inline = inherited
args = {
padding = {
type = "range",
name = "Padding",
desc = "Configure the padding of the buttons.",
min = -10, max = 20, step = 1,
set = optSetter,
get = optGetter,
},
},
},
layout = {
type = "group",
name = "Layout",
inline = true,
order = 10,
set = optSetter,
get = optGetter,
args = {
buttons = {
name = "Buttons",
desc = "Number of buttons.",
type = "range",
min = 1, max = 12, step = 1,
},
rows = {
name = "Rows",
desc = "Number of rows.",
type = "range",
min = 1, max = 12, step = 1,
},
},
}
},
},
swap = {
type = "group",
name = "Page Swapping",
cmdInline = true,
order = 2,
args = {},
},
align = {
-- type = inherited
-- name = inherited
-- cmdInline = inherited
order = 3,
args = {},
}
}, Bar.GetOptionTable(self))
end
return baroptions
end
--[[===================================================================================
ActionBar Prototype
===================================================================================]]--
local initialPosition
do
@@ -26,7 +147,7 @@ function ActionBar:ApplyConfig(config)
config = self.config
if not config.Position then initialPosition(self) end
self:UpdateButtons(config.Buttons)
self:UpdateButtons()
end
-- Update the number of buttons in our bar, creating new ones if necessary
@@ -60,19 +181,13 @@ function ActionBar:UpdateButtons(numbuttons)
self:UpdateButtonLayout()
end
ActionBar.SetButtons = ActionBar.UpdateButtons
function ActionBar:GetButtons()
return self.config.Buttons
end
-- align the buttons and correct the size of the bar overlay frame
function ActionBar:UpdateButtonLayout()
local numbuttons = self.config.Buttons
local numbuttons = self:GetButtons()
local buttons = self.buttons
local pad = self:GetPadding()
local Rows = self.config.Rows
local Rows = self:GetRows()
local ButtonPerRow = math_floor(numbuttons / Rows + 0.5) -- just a precaution
Rows = math_floor(numbuttons / ButtonPerRow + 0.5)
@@ -92,10 +207,16 @@ function ActionBar:UpdateButtonLayout()
end
end
--[[===================================================================================
ActionBar Config Interface
===================================================================================]]--
-- get the current padding
function ActionBar:GetPadding()
return self.config.Padding
end
-- set the padding and refresh layout
function ActionBar:SetPadding(pad)
if pad then
self.config.Padding = pad
@@ -103,10 +224,37 @@ function ActionBar:SetPadding(pad)
self:UpdateButtonLayout()
end
-- get the current number of buttons
function ActionBar:GetButtons()
return self.config.Buttons
end
-- set the number of buttons and refresh layout
ActionBar.SetButtons = ActionBar.UpdateButtons
-- get the current number of rows
function ActionBar:GetRows()
return self.config.Rows
end
-- set the number of rows and refresh layout
function ActionBar:SetRows(rows)
if rows then
self.config.Rows = rows
end
self:UpdateButtonLayout()
end
--[[===================================================================================
Utility function
===================================================================================]]--
-- get a iterator over all buttons
function ActionBar:GetAll()
return pairs(self.buttons)
end
-- execute a member function on all buttons
function ActionBar:ForAll(method, ...)
for _, button in self:GetAll() do
local func = button[method]
+5 -81
View File
@@ -2,8 +2,7 @@
local BT4ActionBars = Bartender4:NewModule("ActionBars")
local ActionBar = Bartender4.ActionBar
local ActionBar_MT = {__index = ActionBar}
local ActionBar, ActionBar_MT
local stancedefaults = {
DRUID = { bear = 9, cat = 7, prowl = 8 },
@@ -28,6 +27,9 @@ function BT4ActionBars:OnInitialize()
Bartender4:RegisterDefaultsKey("ActionBars", defaults)
self:SetupOptions()
ActionBar = Bartender4.ActionBar
ActionBar_MT = {__index = ActionBar}
end
-- setup the 10 actionbars
@@ -149,90 +151,12 @@ function BT4ActionBars:SetupOptions()
Bartender4:RegisterModuleOptions("actionbars", self.options)
end
local getBar, optGetter, optSetter, optionMap, callFunc
do
optionMap = {
padding = "Padding",
buttons = "Buttons",
}
function getBar(id)
local bar = BT4ActionBars.actionbars[tonumber(id)]
assert(bar, "Invalid bar id in options table.")
return bar
end
function callFunc(bar, type, option, ...)
local func = type .. (optionMap[option] or option)
assert(bar[func], "Invalid get/set function."..func)
return bar[func](bar, ...)
end
function optGetter(info)
local bar = getBar(info[2])
local option = info[#info]
return callFunc(bar, "Get", option)
end
function optSetter(info, ...)
local bar = getBar(info[2])
local option = info[#info]
return callFunc(bar, "Set", option, ...)
end
end
function BT4ActionBars:GetOptionsTable()
if not self.baroptions then
self.baroptions = Bartender4:Merge({
general = {
-- type = inherited
-- name = inherited
-- cmdInline = inherited
order = 1,
args = {
style = {
-- type = inherited
-- name = inherited
-- inline = inherited
args = {
padding = {
type = "range",
name = "Padding",
desc = "Configure the padding of the buttons.",
min = -10, max = 20, step = 1,
set = optSetter,
get = optGetter,
},
},
},
},
},
swap = {
type = "group",
name = "Page Swapping",
cmdInline = true,
order = 2,
args = {},
},
align = {
-- type = inherited
-- name = inherited
-- cmdInline = inherited
order = 3,
args = {},
}
}, Bartender4.Bar:GetOptionTable())
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 options = self:GetOptionsTable()
local options = bar:GetOptionsTable()
self.options.args[id] = {
order = 10 + tonumber(id),
+24 -5
View File
@@ -7,7 +7,9 @@
local Bar = CreateFrame("Button")
local Bar_MT = {__index = Bar}
local barregistry = {}
--[[===================================================================================
Universal Bar Contructor
===================================================================================]]--
local defaults = {
['**'] = {
@@ -17,9 +19,11 @@ local defaults = {
}
}
local barregistry = {}
Bartender4.Bar = {}
Bartender4.Bar.defaults = defaults
Bartender4.Bar.prototype = Bar
Bartender4.Bar.barregistry = barregistry
function Bartender4.Bar:Create(id, template, config)
id = tostring(id)
assert(not barregistry[id], "duplicated entry in barregistry.")
@@ -54,31 +58,41 @@ function Bartender4.Bar:Create(id, template, config)
return bar
end
--[[===================================================================================
Bar Options
===================================================================================]]--
-- option utilty functions
local getBar, optGetter, optSetter, optionMap, callFunc
do
-- maps option keys to function names
optionMap = {
alpha = "ConfigAlpha",
scale = "ConfigScale",
}
-- retrieves a valid bar object from the barregistry table
function getBar(id)
local bar = barregistry[tostring(id)]
assert(bar, "Invalid bar id in options table.")
return bar
end
-- calls a function on the bar
function callFunc(bar, type, option, ...)
local func = type .. (optionMap[option] or option)
assert(bar[func], "Invalid get/set function.")
return bar[func](bar, ...)
end
-- universal function to get a option
function optGetter(info)
local bar = getBar(info[2])
local option = info[#info]
return callFunc(bar, "Get", option)
end
-- universal function to set a option
function optSetter(info, ...)
local bar = getBar(info[2])
local option = info[#info]
@@ -86,9 +100,10 @@ do
end
end
function Bartender4.Bar:GetOptionTable()
if not self.options then
self.options = {
local options
function Bar:GetOptionTable()
if not options then
options = {
general = {
type = "group",
cmdInline = true,
@@ -133,9 +148,13 @@ function Bartender4.Bar:GetOptionTable()
}
end
return self.options
return options
end
--[[===================================================================================
Universal Bar Prototype
===================================================================================]]--
local barOnEnter, barOnLeave, barOnDragStart, barOnDragStop, barOnClick
do
function barOnEnter(self)
+1 -1
View File
@@ -18,7 +18,7 @@ Options.lua
## Prototypes ##
Bar.lua
Button.lua
ActionBarPrototype.lua
## Modules ##
ActionBarPrototype.lua
ActionBars.lua