From 75deac4e1e4053841f3966928959c17cc6b92098 Mon Sep 17 00:00:00 2001 From: Hendrik Leppkes Date: Fri, 30 Nov 2007 17:43:02 +0000 Subject: [PATCH] nothing to see here, just storing progress before errors sneak in! --- ActionBars.lua | 55 ++++++++++++++++++++++++++++++++++++++++++++++++-- Bar.lua | 11 ++++++++-- Bartender4.toc | 1 + Button.lua | 34 +++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 Button.lua diff --git a/ActionBars.lua b/ActionBars.lua index 4abc621..9477dfa 100644 --- a/ActionBars.lua +++ b/ActionBars.lua @@ -13,6 +13,8 @@ local defaults = { ['**'] = { Scale = 1, Alpha = 1, + Buttons = 12, + Padding = 2, } } } @@ -41,7 +43,7 @@ end local initialPosition do function initialPosition(bar) - bar:SetPoint("CENTER", 0, -250 + (bar.id-1) * 38) + bar:ClearSetPoint("CENTER", 0, -250 + (bar.id-1) * 38) bar:SavePosition() end end @@ -59,5 +61,54 @@ end function ActionBar:ApplyConfig(config) Bar.ApplyConfig(self, config) - if not self.config.Position then initialPosition(self) end + + config = self.config + if not config.Position then initialPosition(self) end + + self:UpdateButtons(config.Buttons) +end + +function ActionBar:UpdateButtons(numbuttons) + local oldbuttons = self.config.Buttons + if numbuttons then + self.config.Buttons = numbuttons + else + numbuttons = self.config.Buttons + end + + local buttons = self.buttons or {} + + -- create more buttons if needed + if #buttons < numbuttons then + for i = (#buttons+1), numbuttons do + buttons[i] = Bartender4.Button:Create(i, self) + end + 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 + +function ActionBar:UpdateButtonLayout() + local numbuttons = self.config.Buttons + local buttons = self.buttons + local pad = self.config.Padding + + self:SetSize((36 + pad) * numbuttons + 8, 36 + 8) + + buttons[1]:ClearSetPoint("TOPLEFT", self, "TOPLEFT", 5, -3) + for i = 2, numbuttons do + buttons[i]:ClearSetPoint("TOPLEFT", buttons[i-1], "TOPRIGHT", pad, 0) + end end diff --git a/Bar.lua b/Bar.lua index dc51213..bc39b39 100644 --- a/Bar.lua +++ b/Bar.lua @@ -118,8 +118,7 @@ function Bar:LoadPosition() local x, y, s = pos.x, pos.y, UIParent:GetEffectiveScale() local point, relPoint = pos.point, pos.relPoint x, y = x/s, y/s - self:ClearAllPoints() - self:SetPoint(point, UIParent, relPoint, x, y) + self:ClearSetPoint(point, UIParent, relPoint, x, y) end function Bar:SavePosition() @@ -136,3 +135,11 @@ function Bar:SetSize(width, height) self:SetWidth(width) self:SetHeight(height or width) end + +--[[ + Lazyness functions +]] +function Bar:ClearSetPoint(...) + self:ClearAllPoints() + self:SetPoint(...) +end diff --git a/Bartender4.toc b/Bartender4.toc index 5abbc0d..0c98cfd 100644 --- a/Bartender4.toc +++ b/Bartender4.toc @@ -13,6 +13,7 @@ Bartender4.lua ## Prototypes ## Bar.lua +Button.lua ## Modules ## ActionBars.lua diff --git a/Button.lua b/Button.lua new file mode 100644 index 0000000..db4a31d --- /dev/null +++ b/Button.lua @@ -0,0 +1,34 @@ +--[[ + Action Button Template +]] + +--[[ $Id: Bar.lua 56326 2007-11-30 15:11:00Z nevcairiel $ ]] + +local Button = CreateFrame("CheckButton") +local Button_MT = {__index = Button} + +Bartender4.Button = {} +Bartender4.Button.prototype = Button +function Bartender4.Button:Create(id, parent) + local absid = (parent.id - 1) * 12 + id + local button = setmetatable(CreateFrame("CheckButton", ("BT4Button%d"):format(absid), parent, "ActionBarButtonTemplate"), Button_MT) + + button:SetAttribute("type", "action") + button:SetAttribute("useparent-unit", true) + button:SetAttribute("useparent-statebutton", true) + button:SetAttribute("useparent-actionpage", nil) + + button:SetAttribute("action", absid) + + this = button + ActionButton_UpdateAction() + + button:Show() + + return button +end + +function Button:ClearSetPoint(...) + self:ClearAllPoints() + self:SetPoint(...) +end