diff --git a/AdiBags.toc b/AdiBags.toc index 57436811..0e372d71 100644 --- a/AdiBags.toc +++ b/AdiBags.toc @@ -17,7 +17,7 @@ # You should have received a copy of the GNU General Public License # along with AdiBags. If not, see . -## Interface: 100005 +## Interface: 100100 ## Title: AdiBags ## Notes: Adirelle's bag addon. diff --git a/AdiBags_Config/AdiBags_Config.toc b/AdiBags_Config/AdiBags_Config.toc index f6d1f3bd..627a1b9d 100644 --- a/AdiBags_Config/AdiBags_Config.toc +++ b/AdiBags_Config/AdiBags_Config.toc @@ -1,4 +1,4 @@ -## Interface: 100002 +## Interface: 100100 ## Title: AdiBags Configuration ## Notes: Adirelle's bag addon. diff --git a/config/Options.lua b/config/Options.lua index a7aa9ad8..13a6cc4e 100644 --- a/config/Options.lua +++ b/config/Options.lua @@ -300,6 +300,19 @@ end local function GetOptions() if options then return options end + + local lockOption = { + name = function() + return addon.anchor:IsShown() and L["Lock anchor"] or L["Unlock anchor"] + end, + desc = L["Click to toggle the bag anchor."], + type = 'execute', + order = 110, + func = function() + addon:ToggleAnchor() + end, + disabled = function(info) return (info.handler and info.handler:IsDisabled(info)) or addon.db.profile.positionMode ~= 'anchored' end, + } filterOptions._desc = { name = L['Filters are used to dispatch items in bag sections. One item can only appear in one section. If the same item is selected by several filters, the one with the highest priority wins.'], @@ -374,6 +387,30 @@ local function GetOptions() order = 100, inline = true, args = { + positionMode = { + name = L['Position mode'], + desc = L['Select how the bags are positionned.'], + type = 'select', + order = 100, + values = { + anchored = L['Anchored'], + manual = L['Manual'], + } + }, + toggleAnchor = lockOption, + reset = { + name = L['Reset position'], + desc = L['Click there to reset the bag positions and sizes.'], + type = 'execute', + order = 120, + func = function() addon:ResetBagPositions() end, + }, + hideAnchor = { + name = L['Do not show anchor point'], + desc = L['Hide the colored corner shown when you move the bag.'], + type = 'toggle', + order = 125, + }, scale = { name = L['Scale'], desc = L['Use this to adjust the bag scale.'], diff --git a/core/Constants.lua b/core/Constants.lua index 11bc815a..f739440e 100644 --- a/core/Constants.lua +++ b/core/Constants.lua @@ -192,6 +192,7 @@ addon.DEFAULT_SETTINGS = { bags = { ["*"] = true, }, + positionMode = "manual", positions = { anchor = { point = "BOTTOMRIGHT", xOffset = -32, yOffset = 200 }, Backpack = { point = "BOTTOMRIGHT", xOffset = -32, yOffset = 200 }, @@ -275,6 +276,7 @@ addon.DEFAULT_SETTINGS = { }, rightClickConfig = true, autoOpen = true, + hideAnchor = true, autoDeposit = false, compactLayout = false, gridLayout = false, diff --git a/core/Core.lua b/core/Core.lua index 532dd4ef..ddf35d9c 100644 --- a/core/Core.lua +++ b/core/Core.lua @@ -296,8 +296,6 @@ function addon:UpgradeProfile() addon.db.profile.theme.currentTheme = "legacy theme" addon:SaveTheme() end - addon.db.profile.hideAnchor = nil - addon.db.profile.positionMode = nil end -------------------------------------------------------------------------------- diff --git a/core/Layout.lua b/core/Layout.lua index d0237ebd..9ee8a419 100644 --- a/core/Layout.lua +++ b/core/Layout.lua @@ -58,6 +58,42 @@ function addon:CreateBagAnchor() self.anchor = anchor end +local function AnchoredBagLayout(self) + self.anchor:ApplySettings() + self:Debug("Anchor Bag Layout") + + local nextBag, data, firstIndex = self:IterateBags(true) + local index, bag = nextBag(data, firstIndex) + if not bag then return end + + local anchor = self.anchor + local anchorPoint = anchor:GetPosition() + + local frame = bag:GetFrame() + frame:ClearAllPoints() + self:Debug('AnchoredBagLayout', anchorPoint) + frame:SetPoint(anchorPoint, anchor, anchorPoint, 0, 0) + + local lastFrame = frame + index, bag = nextBag(data, index) + if not bag then return end + + local vPart = anchorPoint:match("TOP") or anchorPoint:match("BOTTOM") or "" + local hFrom, hTo, x = "LEFT", "RIGHT", 10 + if anchorPoint:match("RIGHT") then + hFrom, hTo, x = "RIGHT", "LEFT", -10 + end + local fromPoint = vPart..hFrom + local toPoint = vPart..hTo + + while bag do + local frame = bag:GetFrame() + frame:ClearAllPoints() + frame:SetPoint(fromPoint, lastFrame, toPoint, x / frame:GetScale(), 0) + lastFrame, index, bag = frame, nextBag(data, index) + end +end + local function ManualBagLayout(self) for index, bag in self:IterateBags(true) do bag:GetFrame().Anchor:ApplySettings() @@ -71,7 +107,11 @@ function addon:LayoutBags() bag:GetFrame():SetScale(scale) end end - ManualBagLayout(self) + if self.db.profile.positionMode == 'anchored' then + AnchoredBagLayout(self) + else + ManualBagLayout(self) + end self:SendMessage('AdiBags_ForceFullLayout') end diff --git a/widgets/AnchorWidget.lua b/widgets/AnchorWidget.lua index 30e8c369..88487469 100644 --- a/widgets/AnchorWidget.lua +++ b/widgets/AnchorWidget.lua @@ -123,6 +123,9 @@ function anchorProto:StartMoving(button) else target:StartMoving() end + if not addon.db.profile.hideAnchor then + self.corner:Show() + end if self.OnMovingStarted then self:OnMovingStarted() end @@ -136,6 +139,7 @@ function anchorProto:StopMoving() self.toggleMovable = nil target:SetMovable(false) end + self.corner:Hide() if target == self then anchorParentProto.StopMovingOrSizing(self) else @@ -167,9 +171,16 @@ function bagAnchorProto:OnCreate(parent, name, label) end function bagAnchorProto:UpdateOperatingMode() + if addon.db.profile.positionMode == "manual" then self:SetScript('OnMouseDown', self.StartMoving) self:SetScript('OnMouseUp', self.StopMoving) self:SetScript('OnHide', self.StopMoving) + else + self:StopMoving() + self:SetScript('OnMouseDown', nil) + self:SetScript('OnMouseUp', nil) + self:SetScript('OnHide', nil) + end end function bagAnchorProto:AdiBags_ConfigChanged(_, name) @@ -179,12 +190,29 @@ function bagAnchorProto:AdiBags_ConfigChanged(_, name) end function bagAnchorProto:OnClick(mouseButton) - return + if mouseButton == "RightButton" then + if IsAltKeyDown() then + if addon.db.profile.positionMode == "anchored" then + addon.db.profile.positionMode = "manual" + else + addon.db.profile.positionMode = "anchored" + end + addon:SendMessage('AdiBags_ConfigChanged', 'positionMode') + elseif addon.db.profile.positionMode == "anchored" then + addon:ToggleAnchor() + end + end end function bagAnchorProto:OnTooltipUpdate(tooltip) tooltip:AddLine(self.label, 1, 1, 1) - tooltip:AddLine(L['Drag to move this bag.']) + if addon.db.profile.positionMode == "manual" then + tooltip:AddLine(L['Drag to move this bag.']) + tooltip:AddLine(L['Alt-right-click to switch to anchored placement.']) + else + tooltip:AddLine(L['Right-click to (un)lock the bag anchor.']) + tooltip:AddLine(L['Alt-right-click to switch to manual placement.']) + end end function addon:CreateBagAnchorWidget(...) return bagAnchorClass:Create(...) end