some reordering and more options
This commit is contained in:
+160
-12
@@ -6,9 +6,130 @@ Bartender4.ActionBar = ActionBar
|
|||||||
|
|
||||||
local math_floor = math.floor
|
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
|
local initialPosition
|
||||||
do
|
do
|
||||||
@@ -26,7 +147,7 @@ function ActionBar:ApplyConfig(config)
|
|||||||
config = self.config
|
config = self.config
|
||||||
if not config.Position then initialPosition(self) end
|
if not config.Position then initialPosition(self) end
|
||||||
|
|
||||||
self:UpdateButtons(config.Buttons)
|
self:UpdateButtons()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Update the number of buttons in our bar, creating new ones if necessary
|
-- Update the number of buttons in our bar, creating new ones if necessary
|
||||||
@@ -60,19 +181,13 @@ function ActionBar:UpdateButtons(numbuttons)
|
|||||||
self:UpdateButtonLayout()
|
self:UpdateButtonLayout()
|
||||||
end
|
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
|
-- align the buttons and correct the size of the bar overlay frame
|
||||||
function ActionBar:UpdateButtonLayout()
|
function ActionBar:UpdateButtonLayout()
|
||||||
local numbuttons = self.config.Buttons
|
local numbuttons = self:GetButtons()
|
||||||
local buttons = self.buttons
|
local buttons = self.buttons
|
||||||
local pad = self:GetPadding()
|
local pad = self:GetPadding()
|
||||||
|
|
||||||
local Rows = self.config.Rows
|
local Rows = self:GetRows()
|
||||||
local ButtonPerRow = math_floor(numbuttons / Rows + 0.5) -- just a precaution
|
local ButtonPerRow = math_floor(numbuttons / Rows + 0.5) -- just a precaution
|
||||||
Rows = math_floor(numbuttons / ButtonPerRow + 0.5)
|
Rows = math_floor(numbuttons / ButtonPerRow + 0.5)
|
||||||
|
|
||||||
@@ -92,10 +207,16 @@ function ActionBar:UpdateButtonLayout()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--[[===================================================================================
|
||||||
|
ActionBar Config Interface
|
||||||
|
===================================================================================]]--
|
||||||
|
|
||||||
|
-- get the current padding
|
||||||
function ActionBar:GetPadding()
|
function ActionBar:GetPadding()
|
||||||
return self.config.Padding
|
return self.config.Padding
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- set the padding and refresh layout
|
||||||
function ActionBar:SetPadding(pad)
|
function ActionBar:SetPadding(pad)
|
||||||
if pad then
|
if pad then
|
||||||
self.config.Padding = pad
|
self.config.Padding = pad
|
||||||
@@ -103,10 +224,37 @@ function ActionBar:SetPadding(pad)
|
|||||||
self:UpdateButtonLayout()
|
self:UpdateButtonLayout()
|
||||||
end
|
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()
|
function ActionBar:GetAll()
|
||||||
return pairs(self.buttons)
|
return pairs(self.buttons)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- execute a member function on all buttons
|
||||||
function ActionBar:ForAll(method, ...)
|
function ActionBar:ForAll(method, ...)
|
||||||
for _, button in self:GetAll() do
|
for _, button in self:GetAll() do
|
||||||
local func = button[method]
|
local func = button[method]
|
||||||
|
|||||||
+5
-81
@@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
local BT4ActionBars = Bartender4:NewModule("ActionBars")
|
local BT4ActionBars = Bartender4:NewModule("ActionBars")
|
||||||
|
|
||||||
local ActionBar = Bartender4.ActionBar
|
local ActionBar, ActionBar_MT
|
||||||
local ActionBar_MT = {__index = ActionBar}
|
|
||||||
|
|
||||||
local stancedefaults = {
|
local stancedefaults = {
|
||||||
DRUID = { bear = 9, cat = 7, prowl = 8 },
|
DRUID = { bear = 9, cat = 7, prowl = 8 },
|
||||||
@@ -28,6 +27,9 @@ function BT4ActionBars:OnInitialize()
|
|||||||
Bartender4:RegisterDefaultsKey("ActionBars", defaults)
|
Bartender4:RegisterDefaultsKey("ActionBars", defaults)
|
||||||
|
|
||||||
self:SetupOptions()
|
self:SetupOptions()
|
||||||
|
|
||||||
|
ActionBar = Bartender4.ActionBar
|
||||||
|
ActionBar_MT = {__index = ActionBar}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- setup the 10 actionbars
|
-- setup the 10 actionbars
|
||||||
@@ -149,90 +151,12 @@ function BT4ActionBars:SetupOptions()
|
|||||||
Bartender4:RegisterModuleOptions("actionbars", self.options)
|
Bartender4:RegisterModuleOptions("actionbars", self.options)
|
||||||
end
|
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
|
-- Creates a new bar object based on the id and the specified config
|
||||||
function BT4ActionBars:Create(id, config)
|
function BT4ActionBars:Create(id, config)
|
||||||
local id = tostring(id)
|
local id = tostring(id)
|
||||||
local bar = setmetatable(Bartender4.Bar:Create(id, "SecureStateHeaderTemplate", config), ActionBar_MT)
|
local bar = setmetatable(Bartender4.Bar:Create(id, "SecureStateHeaderTemplate", config), ActionBar_MT)
|
||||||
|
|
||||||
local options = self:GetOptionsTable()
|
local options = bar:GetOptionsTable()
|
||||||
|
|
||||||
self.options.args[id] = {
|
self.options.args[id] = {
|
||||||
order = 10 + tonumber(id),
|
order = 10 + tonumber(id),
|
||||||
|
|||||||
@@ -7,7 +7,9 @@
|
|||||||
local Bar = CreateFrame("Button")
|
local Bar = CreateFrame("Button")
|
||||||
local Bar_MT = {__index = Bar}
|
local Bar_MT = {__index = Bar}
|
||||||
|
|
||||||
local barregistry = {}
|
--[[===================================================================================
|
||||||
|
Universal Bar Contructor
|
||||||
|
===================================================================================]]--
|
||||||
|
|
||||||
local defaults = {
|
local defaults = {
|
||||||
['**'] = {
|
['**'] = {
|
||||||
@@ -17,9 +19,11 @@ local defaults = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local barregistry = {}
|
||||||
Bartender4.Bar = {}
|
Bartender4.Bar = {}
|
||||||
Bartender4.Bar.defaults = defaults
|
Bartender4.Bar.defaults = defaults
|
||||||
Bartender4.Bar.prototype = Bar
|
Bartender4.Bar.prototype = Bar
|
||||||
|
Bartender4.Bar.barregistry = barregistry
|
||||||
function Bartender4.Bar:Create(id, template, config)
|
function Bartender4.Bar:Create(id, template, config)
|
||||||
id = tostring(id)
|
id = tostring(id)
|
||||||
assert(not barregistry[id], "duplicated entry in barregistry.")
|
assert(not barregistry[id], "duplicated entry in barregistry.")
|
||||||
@@ -54,31 +58,41 @@ function Bartender4.Bar:Create(id, template, config)
|
|||||||
return bar
|
return bar
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--[[===================================================================================
|
||||||
|
Bar Options
|
||||||
|
===================================================================================]]--
|
||||||
|
|
||||||
|
-- option utilty functions
|
||||||
local getBar, optGetter, optSetter, optionMap, callFunc
|
local getBar, optGetter, optSetter, optionMap, callFunc
|
||||||
do
|
do
|
||||||
|
-- maps option keys to function names
|
||||||
optionMap = {
|
optionMap = {
|
||||||
alpha = "ConfigAlpha",
|
alpha = "ConfigAlpha",
|
||||||
scale = "ConfigScale",
|
scale = "ConfigScale",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- retrieves a valid bar object from the barregistry table
|
||||||
function getBar(id)
|
function getBar(id)
|
||||||
local bar = barregistry[tostring(id)]
|
local bar = barregistry[tostring(id)]
|
||||||
assert(bar, "Invalid bar id in options table.")
|
assert(bar, "Invalid bar id in options table.")
|
||||||
return bar
|
return bar
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- calls a function on the bar
|
||||||
function callFunc(bar, type, option, ...)
|
function callFunc(bar, type, option, ...)
|
||||||
local func = type .. (optionMap[option] or option)
|
local func = type .. (optionMap[option] or option)
|
||||||
assert(bar[func], "Invalid get/set function.")
|
assert(bar[func], "Invalid get/set function.")
|
||||||
return bar[func](bar, ...)
|
return bar[func](bar, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- universal function to get a option
|
||||||
function optGetter(info)
|
function optGetter(info)
|
||||||
local bar = getBar(info[2])
|
local bar = getBar(info[2])
|
||||||
local option = info[#info]
|
local option = info[#info]
|
||||||
return callFunc(bar, "Get", option)
|
return callFunc(bar, "Get", option)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- universal function to set a option
|
||||||
function optSetter(info, ...)
|
function optSetter(info, ...)
|
||||||
local bar = getBar(info[2])
|
local bar = getBar(info[2])
|
||||||
local option = info[#info]
|
local option = info[#info]
|
||||||
@@ -86,9 +100,10 @@ do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Bartender4.Bar:GetOptionTable()
|
local options
|
||||||
if not self.options then
|
function Bar:GetOptionTable()
|
||||||
self.options = {
|
if not options then
|
||||||
|
options = {
|
||||||
general = {
|
general = {
|
||||||
type = "group",
|
type = "group",
|
||||||
cmdInline = true,
|
cmdInline = true,
|
||||||
@@ -133,9 +148,13 @@ function Bartender4.Bar:GetOptionTable()
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
return self.options
|
return options
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--[[===================================================================================
|
||||||
|
Universal Bar Prototype
|
||||||
|
===================================================================================]]--
|
||||||
|
|
||||||
local barOnEnter, barOnLeave, barOnDragStart, barOnDragStop, barOnClick
|
local barOnEnter, barOnLeave, barOnDragStart, barOnDragStop, barOnClick
|
||||||
do
|
do
|
||||||
function barOnEnter(self)
|
function barOnEnter(self)
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ Options.lua
|
|||||||
## Prototypes ##
|
## Prototypes ##
|
||||||
Bar.lua
|
Bar.lua
|
||||||
Button.lua
|
Button.lua
|
||||||
ActionBarPrototype.lua
|
|
||||||
|
|
||||||
## Modules ##
|
## Modules ##
|
||||||
|
ActionBarPrototype.lua
|
||||||
ActionBars.lua
|
ActionBars.lua
|
||||||
|
|||||||
Reference in New Issue
Block a user