--[[ $Id$ ]] local BT4ActionBars = Bartender4:NewModule("ActionBars") local Bar = Bartender4.Bar.prototype local ActionBar = setmetatable({}, {__index = Bar}) 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 }, ROGUE = { stealth = 7 } } local defaults = { ['**'] = { Enabled = true, Scale = 1, Alpha = 1, Buttons = 12, Padding = 2, Rows = 1, HideMacrotext = false, }, [1] = { Stances = stancedefaults, }, } function BT4ActionBars:OnInitialize() self.db = Bartender4.db Bartender4:RegisterDefaultsKey("ActionBars", defaults) end -- setup the 10 actionbars local first = true function BT4ActionBars:OnEnable() if first then self.playerclass = select(2, UnitClass("player")) self.actionbars = {} for i=1,10 do local config = self.db.profile.ActionBars[i] if config.Enabled then self.actionbars[i] = self:Create(i, config) end end first = nil end 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]) 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() end end -- Creates a new bar object based on the id and the specified config function BT4ActionBars:Create(id, config) local bar = setmetatable(Bartender4.Bar:Create(id, "SecureStateDriverTemplate", config), ActionBar_MT) -- TODO: Setup Buttons and set bar width before pulling initial position bar:ApplyConfig() -- debugging --bar:Unlock() 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