improved frame placement code, will take advantage of the build-in blizzy code to always save position relative to the nearest edge (or center)
This commit is contained in:
+31
-7
@@ -23,19 +23,43 @@ function BT4ActionBars:OnInitialize()
|
|||||||
self.db = Bartender4.db:RegisterNamespace("ActionBars", defaults)
|
self.db = Bartender4.db:RegisterNamespace("ActionBars", defaults)
|
||||||
|
|
||||||
for i=1,10 do
|
for i=1,10 do
|
||||||
actionbars[i] = ActionBar:Create(i, self.db.profile.Bars[i])
|
actionbars[i] = self:Create(i, self.db.profile.Bars[i])
|
||||||
|
end
|
||||||
|
|
||||||
|
self.db.RegisterCallback(self, "OnProfileChanged", "ApplyConfig")
|
||||||
|
self.db.RegisterCallback(self, "OnProfileCopied", "ApplyConfig")
|
||||||
|
end
|
||||||
|
|
||||||
|
function BT4ActionBars:OnEnable()
|
||||||
|
-- do stuff
|
||||||
|
end
|
||||||
|
|
||||||
|
function BT4ActionBars:ApplyConfig()
|
||||||
|
for i,v in ipairs(actionbars) do
|
||||||
|
v:ApplyConfig(self.db.profile.Bars[k])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ActionBar:Create(id, config)
|
local initialPosition
|
||||||
local bar = setmetatable(Bartender4.Bar:Create(id, "SecureStateDriverTemplate", config), ActionBar_MT)
|
do
|
||||||
if not config.x or not config.y then
|
function initialPosition(bar)
|
||||||
bar:SetPoint("CENTER", 0, -250 + (id-1) * 38)
|
bar:SetPoint("CENTER", 0, -250 + (bar.id-1) * 38)
|
||||||
bar:SavePosition()
|
bar:SavePosition()
|
||||||
else
|
|
||||||
bar:LoadPosition()
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
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()
|
||||||
|
-- for debugging only
|
||||||
bar:Unlock()
|
bar:Unlock()
|
||||||
|
|
||||||
return bar
|
return bar
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ActionBar:ApplyConfig(config)
|
||||||
|
Bar.ApplyConfig(self, config)
|
||||||
|
if not self.config.Position then initialPosition(self) end
|
||||||
|
end
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ Bartender4.Bar = {}
|
|||||||
Bartender4.Bar.prototype = Bar
|
Bartender4.Bar.prototype = Bar
|
||||||
function Bartender4.Bar:Create(id, template, config)
|
function Bartender4.Bar:Create(id, template, config)
|
||||||
local bar = setmetatable(CreateFrame("Button", ("BT4Bar%s"):format(id), UIParent, template), Bar_MT)
|
local bar = setmetatable(CreateFrame("Button", ("BT4Bar%s"):format(id), UIParent, template), Bar_MT)
|
||||||
|
bar.id = id
|
||||||
|
|
||||||
bar:EnableMouse(false)
|
bar:EnableMouse(false)
|
||||||
bar:SetMovable(true)
|
bar:SetMovable(true)
|
||||||
@@ -72,6 +73,14 @@ do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Bar:ApplyConfig(config)
|
||||||
|
if config then
|
||||||
|
self.config = config
|
||||||
|
end
|
||||||
|
self:Lock()
|
||||||
|
self:LoadPosition()
|
||||||
|
end
|
||||||
|
|
||||||
function Bar:Unlock()
|
function Bar:Unlock()
|
||||||
self:EnableMouse(true)
|
self:EnableMouse(true)
|
||||||
self:SetScript("OnEnter", barOnEnter)
|
self:SetScript("OnEnter", barOnEnter)
|
||||||
@@ -104,18 +113,23 @@ function Bar:Lock()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Bar:LoadPosition()
|
function Bar:LoadPosition()
|
||||||
local x, y, s = self.config.x, self.config.y, self:GetEffectiveScale()
|
if not self.config.Position then return end
|
||||||
|
local pos = self.config.Position
|
||||||
|
local x, y, s = pos.x, pos.y, UIParent:GetEffectiveScale()
|
||||||
|
local point, relPoint = pos.point, pos.relPoint
|
||||||
x, y = x/s, y/s
|
x, y = x/s, y/s
|
||||||
self:ClearAllPoints()
|
self:ClearAllPoints()
|
||||||
self:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", x, y)
|
self:SetPoint(point, UIParent, relPoint, x, y)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Bar:SavePosition()
|
function Bar:SavePosition()
|
||||||
local x, y = self:GetLeft(), self:GetBottom()
|
if not self.config.Position then self.config.Position = {} end
|
||||||
local s = self:GetEffectiveScale()
|
local pos = self.config.Position
|
||||||
|
local point, parent, relPoint, x, y = self:GetPoint()
|
||||||
|
local s = UIParent:GetEffectiveScale()
|
||||||
x, y = x*s, y*s
|
x, y = x*s, y*s
|
||||||
self.config.x = x
|
pos.x, pos.y = x, y
|
||||||
self.config.y = y
|
pos.point, pos.relPoint = point, relPoint
|
||||||
end
|
end
|
||||||
|
|
||||||
function Bar:SetSize(width, height)
|
function Bar:SetSize(width, height)
|
||||||
|
|||||||
Reference in New Issue
Block a user