Skip to content

Commit

Permalink
Updated TOC for 10.1.
Browse files Browse the repository at this point in the history
Readded Anchor mode, disabled by default for new installs.
  • Loading branch information
Cidan committed May 7, 2023
1 parent c09e86e commit e659a1e
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 7 deletions.
2 changes: 1 addition & 1 deletion AdiBags.toc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with AdiBags. If not, see <http://www.gnu.org/licenses/>.

## Interface: 100005
## Interface: 100100

## Title: AdiBags
## Notes: Adirelle's bag addon.
Expand Down
2 changes: 1 addition & 1 deletion AdiBags_Config/AdiBags_Config.toc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Interface: 100002
## Interface: 100100

## Title: AdiBags Configuration
## Notes: Adirelle's bag addon.
Expand Down
37 changes: 37 additions & 0 deletions config/Options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.'],
Expand Down Expand Up @@ -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.'],
Expand Down
2 changes: 2 additions & 0 deletions core/Constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -275,6 +276,7 @@ addon.DEFAULT_SETTINGS = {
},
rightClickConfig = true,
autoOpen = true,
hideAnchor = true,
autoDeposit = false,
compactLayout = false,
gridLayout = false,
Expand Down
2 changes: 0 additions & 2 deletions core/Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

--------------------------------------------------------------------------------
Expand Down
42 changes: 41 additions & 1 deletion core/Layout.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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

Expand Down
32 changes: 30 additions & 2 deletions widgets/AnchorWidget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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

0 comments on commit e659a1e

Please sign in to comment.