diff --git a/ActionBars.lua b/ActionBars.lua index f8be626..358a50c 100644 --- a/ActionBars.lua +++ b/ActionBars.lua @@ -1,19 +1,41 @@ ---[[ $Id: Bartender3.lua 49922 2007-09-26 20:15:15Z nevcairiel $ ]] +--[[ $Id$ ]] local BT4ActionBars = Bartender4:NewModule("ActionBars") -local Bar = Bartender4.Bar +local Bar = Bartender4.Bar.prototype local ActionBar = setmetatable({}, {__index = Bar}) local ActionBar_MT = {__index = ActionBar} +local defaults = { + profile = { + Bars = { + ['**'] = { + Scale = 1, + Alpha = 1, + } + } + } +} + local actionbars = {} function BT4ActionBars:OnInitialize() + self.db = Bartender4.db:RegisterNamespace("ActionBars", defaults) + for i=1,10 do - actionbars[i] = ActionBar:Create(i) + actionbars[i] = ActionBar:Create(i, self.db.profile.Bars[i]) end end -function ActionBar:Create(id) - local bar = setmetatable(Bar:Create(id, "SecureStateDriverTemplate"), ActionBar_MT) +function ActionBar:Create(id, config) + local bar = setmetatable(Bartender4.Bar:Create(id, "SecureStateDriverTemplate", config), ActionBar_MT) + if not config.x or not config.y then + bar:SetPoint("CENTER", 0, -250 + (id-1) * 38) + bar:SavePosition() + else + bar:LoadPosition() + end + bar:Unlock() + + return bar end diff --git a/Bar.lua b/Bar.lua index 52b8730..a70ee49 100644 --- a/Bar.lua +++ b/Bar.lua @@ -4,7 +4,7 @@ --[[ $Id$ ]] -local Bar = CreateFrame("Frame") +local Bar = CreateFrame("Button") local Bar_MT = {__index = Bar} local function createOptions(id) @@ -12,8 +12,9 @@ local function createOptions(id) end Bartender4.Bar = {} -function Bartender4.Bar:Create(id, template) - local bar = setmetatable(CreateFrame("Frame", ("BT4Bar%s"):format(id), UIParent, template), Bar_MT) +Bartender4.Bar.prototype = Bar +function Bartender4.Bar:Create(id, template, config) + local bar = setmetatable(CreateFrame("Button", ("BT4Bar%s"):format(id), UIParent, template), Bar_MT) bar:EnableMouse(false) bar:SetMovable(true) @@ -29,19 +30,20 @@ function Bartender4.Bar:Create(id, template) }) bar:SetBackdropColor(0, 0, 0, 0) bar:SetBackdropBorderColor(0.5, 0.5, 0, 0) - bar.Text = frame:CreateFontString(nil, "ARTWORK") + bar.Text = bar:CreateFontString(nil, "ARTWORK") bar.Text:SetFontObject(GameFontNormal) bar.Text:SetText("Bar "..id) bar.Text:Hide() bar.Text:ClearAllPoints() bar.Text:SetPoint("CENTER", bar, "CENTER") + bar.config = config bar.options = createOptions(id) return bar end -local barOnEnter, barOnLeave, barOnDragStart, barOnDragStop +local barOnEnter, barOnLeave, barOnDragStart, barOnDragStop, barOnClick do function barOnEnter(self) self:SetBackdropBorderColor(0.5, 0.5, 0, 1) @@ -54,11 +56,19 @@ do function barOnDragStart(self) self:StartMoving() self:SetBackdropBorderColor(0, 0, 0, 0) + self.isMoving = true end function barOnDragStop(self) - self:StopMovingOrSizing() - self:SavePosition() + if self.isMoving then + self:StopMovingOrSizing() + self:SavePosition() + end + end + + function barOnClick(self) + -- TODO: Hide/Show bar on Click + -- TODO: Once dropdown config is stable, show dropdown on rightclick end end @@ -68,7 +78,7 @@ function Bar:Unlock() self:SetScript("OnLeave", barOnLeave) self:SetScript("OnDragStart", barOnDragStart) self:SetScript("OnDragStop", barOnDragStop) - self:SetScript("OnClick", nil) + self:SetScript("OnClick", barOnClick) self.Text:Show() self:SetFrameLevel(5) @@ -80,6 +90,7 @@ function Bar:Unlock() end function Bar:Lock() + barOnDragStop(self) self:EnableMouse(false) self:SetScript("OnEnter", nil) self:SetScript("OnLeave", nil) @@ -93,7 +104,7 @@ function Bar:Lock() end function Bar:LoadPosition() - local x, y, s = self.config.PosX, self.config.PosY, self:GetEffectiveScale() + local x, y, s = self.config.x, self.config.y, self:GetEffectiveScale() x, y = x/s, y/s self:ClearAllPoints() self:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", x, y) @@ -103,6 +114,11 @@ function Bar:SavePosition() local x, y = self:GetLeft(), self:GetBottom() local s = self:GetEffectiveScale() x, y = x*s, y*s - self.config.PosX = x - self.config.PosY = y + self.config.x = x + self.config.y = y +end + +function Bar:SetSize(width, height) + self:SetWidth(width) + self:SetHeight(height or width) end diff --git a/Bartender4.toc b/Bartender4.toc index 9d28679..5abbc0d 100644 --- a/Bartender4.toc +++ b/Bartender4.toc @@ -8,4 +8,11 @@ ## X-License: BSD ## Version: 4.0 +## Core ## Bartender4.lua + +## Prototypes ## +Bar.lua + +## Modules ## +ActionBars.lua