- split actionbar module and prototype into independent files
- added meta functions to update bars/buttons - first options
This commit is contained in:
+92
-81
@@ -2,13 +2,9 @@
|
||||
|
||||
local BT4ActionBars = Bartender4:NewModule("ActionBars")
|
||||
|
||||
local Bar = Bartender4.Bar.prototype
|
||||
local ActionBar = setmetatable({}, {__index = Bar})
|
||||
|
||||
local ActionBar = Bartender4.ActionBar
|
||||
local ActionBar_MT = {__index = ActionBar}
|
||||
|
||||
local math_floor = math.floor
|
||||
|
||||
local stancedefaults = {
|
||||
DRUID = { bear = 9, cat = 7, prowl = 8 },
|
||||
WARRIOR = { battle = 7, def = 8, berserker = 9 },
|
||||
@@ -33,6 +29,8 @@ local defaults = {
|
||||
function BT4ActionBars:OnInitialize()
|
||||
self.db = Bartender4.db
|
||||
Bartender4:RegisterDefaultsKey("ActionBars", defaults)
|
||||
|
||||
self:SetupOptions()
|
||||
end
|
||||
|
||||
-- setup the 10 actionbars
|
||||
@@ -58,15 +56,98 @@ function BT4ActionBars:ApplyConfig()
|
||||
end
|
||||
end
|
||||
|
||||
local initialPosition
|
||||
do
|
||||
-- Sets the Bar to its initial Position in the Center of the Screen
|
||||
function initialPosition(bar)
|
||||
bar:ClearSetPoint("CENTER", 0, -250 + (bar.id-1) * 38)
|
||||
bar:SavePosition()
|
||||
function BT4ActionBars:UpdateButtons()
|
||||
for i,v in ipairs(self.actionbars) do
|
||||
for j,button in ipairs(v.buttons) do
|
||||
button:UpdateAction(force)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function BT4ActionBars:GetAll()
|
||||
return pairs(self.actionbars)
|
||||
end
|
||||
|
||||
function BT4ActionBars:ForAll(method, ...)
|
||||
for _, bar in self:GetAll() do
|
||||
local func = bar[method]
|
||||
if func then
|
||||
func(bar, ...)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function BT4ActionBars:ForAllButtons(...)
|
||||
self:ForAll("ForAll", ...)
|
||||
end
|
||||
|
||||
local getFunc, setFunc
|
||||
do
|
||||
function getFunc(info)
|
||||
return (info.arg and Bartender4.db.profile[info.arg] or Bartender4.db.profile[info[#info]])
|
||||
end
|
||||
|
||||
function setFunc(info, value)
|
||||
local key = info.arg or info[#info]
|
||||
Bartender4.db.profile[key] = value
|
||||
end
|
||||
end
|
||||
|
||||
function BT4ActionBars:SetupOptions()
|
||||
self.options = {
|
||||
type = "group",
|
||||
--cmdInline = true,
|
||||
name = "Action Bars",
|
||||
get = getFunc,
|
||||
set = setFunc,
|
||||
args = {
|
||||
range = {
|
||||
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)
|
||||
setFunc(info, 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,
|
||||
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",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
Bartender4:RegisterModuleOptions("actionbars", self.options)
|
||||
end
|
||||
|
||||
|
||||
-- Creates a new bar object based on the id and the specified config
|
||||
function BT4ActionBars:Create(id, config)
|
||||
@@ -79,73 +160,3 @@ function BT4ActionBars:Create(id, config)
|
||||
|
||||
return bar
|
||||
end
|
||||
|
||||
--[[
|
||||
Bar Prototype Functions
|
||||
]]
|
||||
|
||||
-- Apply the specified config to the bar and refresh all settings
|
||||
function ActionBar:ApplyConfig(config)
|
||||
Bar.ApplyConfig(self, config)
|
||||
|
||||
config = self.config
|
||||
if not config.Position then initialPosition(self) end
|
||||
|
||||
self:UpdateButtons(config.Buttons)
|
||||
end
|
||||
|
||||
-- Update the number of buttons in our bar, creating new ones if necessary
|
||||
function ActionBar:UpdateButtons(numbuttons)
|
||||
if numbuttons then
|
||||
self.config.Buttons = numbuttons
|
||||
else
|
||||
numbuttons = self.config.Buttons
|
||||
end
|
||||
|
||||
local buttons = self.buttons or {}
|
||||
|
||||
-- create more buttons if needed
|
||||
for i = (#buttons+1), numbuttons do
|
||||
buttons[i] = Bartender4.Button:Create(i, self)
|
||||
end
|
||||
|
||||
-- show active buttons
|
||||
for i = 1, numbuttons do
|
||||
buttons[i]:Show()
|
||||
end
|
||||
|
||||
-- hide inactive buttons
|
||||
for i = (numbuttons + 1), #buttons do
|
||||
buttons[i]:Hide()
|
||||
end
|
||||
|
||||
self.buttons = buttons
|
||||
|
||||
self:UpdateButtonLayout()
|
||||
end
|
||||
|
||||
-- align the buttons and correct the size of the bar overlay frame
|
||||
function ActionBar:UpdateButtonLayout()
|
||||
local numbuttons = self.config.Buttons
|
||||
local buttons = self.buttons
|
||||
local pad = self.config.Padding
|
||||
|
||||
local Rows = self.config.Rows
|
||||
local ButtonPerRow = math_floor(numbuttons / Rows + 0.5) -- just a precaution
|
||||
Rows = math_floor(numbuttons / ButtonPerRow + 0.5)
|
||||
|
||||
self:SetSize((36 + pad) * ButtonPerRow - pad + 8, (36 + pad) * Rows - pad + 8)
|
||||
|
||||
-- anchor button 1 to the topleft corner of the bar
|
||||
buttons[1]:ClearSetPoint("TOPLEFT", self, "TOPLEFT", 6, -3)
|
||||
-- and anchor all other buttons relative to our button 1
|
||||
for i = 2, numbuttons do
|
||||
-- jump into a new row
|
||||
if ((i-1) % ButtonPerRow) == 0 then
|
||||
buttons[i]:ClearSetPoint("TOPLEFT", buttons[i-ButtonPerRow], "BOTTOMLEFT", 0, -pad)
|
||||
-- align to the previous button
|
||||
else
|
||||
buttons[i]:ClearSetPoint("TOPLEFT", buttons[i-1], "TOPRIGHT", pad, 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user