Skip to content

Commit 1718e07

Browse files
committed
Add Clam, Disenchant, and Pick Lock buttons
#32, #15, #23
1 parent 93e100b commit 1718e07

13 files changed

+358
-75
lines changed

Bagshui.lua

+2
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,11 @@ local bagshuiEnvironment = {
319319
itemLink = "", -- Item link (|cffffffff|Hitem:12345:0:0:0|h[Name]|h|r).
320320
itemString = "", -- Item string (item:12345:0:0:0).
321321
locked = 0,
322+
lockPickable = 0,
322323
maxStackCount = 0,
323324
minLevel = "",
324325
name = "",
326+
openable = 0,
325327
quality = 1,
326328
qualityLocalized = "",
327329
readable = 0,

Components/Inventory.Layout.lua

+86-49
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,9 @@ function Inventory:UpdateWindow()
482482
self.hasHiddenGroups = false -- Updated in this function.
483483
self.hasHiddenItems = false -- Updated in GetGroupItemCountForLayout().
484484
self.hasChanges = false -- Updated in AssignItemsToSlots().
485+
self.hasOpenables = false -- Updated in AssignItemsToSlots().
486+
self.nextOpenableItemBagNum = nil -- Updated in AssignItemsToSlots().
487+
self.nextOpenableItemSlotNum = nil -- Updated in AssignItemsToSlots().
485488

486489
-- Full reset of empty slot stack counts is needed so that the tracking of which
487490
-- bag they represent is rebuilt.
@@ -1005,48 +1008,6 @@ function Inventory:UpdateWindow()
10051008
uiFrames.bagBar:Hide()
10061009
end
10071010

1008-
-- Variables for hearthstone button position based on whether money frame is shown.
1009-
local hearthButtonAnchorToFrame = uiButtons.toolbar.hearthstone.bagshuiData.defaultAnchorToFrame
1010-
local hearthButtonAnchorToPoint = uiButtons.toolbar.hearthstone.bagshuiData.defaultAnchorToPoint
1011-
1012-
-- Show/hide Money frame.
1013-
if self.settings.showMoney then
1014-
uiFrames.money:Show()
1015-
uiFrames.money:SetAlpha(self.editMode and 0.2 or 1)
1016-
-- Use label colors for money text.
1017-
for _, text in pairs(uiFrames.money.bagshuiData.texts) do
1018-
text:SetTextColor(self.settings.groupLabelDefault[1], self.settings.groupLabelDefault[2], self.settings.groupLabelDefault[3], self.settings.groupLabelDefault[4])
1019-
end
1020-
else
1021-
uiFrames.money:Hide()
1022-
-- Move the hearthstone button to the money frame's position.
1023-
_, hearthButtonAnchorToFrame, hearthButtonAnchorToPoint = uiFrames.money:GetPoint(1)
1024-
end
1025-
1026-
-- Show/hide Hearthstone button.
1027-
if
1028-
self.hearthButton
1029-
and self.settings.showFooter
1030-
and self.settings.showHearthstone
1031-
and self.hearthstoneItemRef
1032-
then
1033-
uiButtons.toolbar.hearthstone:SetPoint(
1034-
"RIGHT",
1035-
hearthButtonAnchorToFrame,
1036-
hearthButtonAnchorToPoint,
1037-
uiButtons.toolbar.hearthstone.bagshuiData.defaultXOffset,
1038-
0
1039-
)
1040-
uiButtons.toolbar.hearthstone:Show()
1041-
1042-
-- Display cooldown.
1043-
local cooldownStart, cooldownDuration, isOnCooldown = _G.GetContainerItemCooldown(self.hearthstoneItemRef.bagNum, self.hearthstoneItemRef.slotNum)
1044-
self.ui:SetIconButtonCooldown(uiButtons.toolbar.hearthstone, cooldownStart, cooldownDuration, isOnCooldown)
1045-
1046-
else
1047-
uiButtons.toolbar.hearthstone:Hide()
1048-
end
1049-
10501011
-- Apply bag bar scaling and opacity.
10511012
local bagBarScale = (itemSlotSize / uiButtons.itemSlots[1].bagshuiData.originalSizeAdjusted) * BsSkin.bagBarScale
10521013
uiFrames.bagBar:SetScale(bagBarScale)
@@ -1061,7 +1022,6 @@ function Inventory:UpdateWindow()
10611022
end
10621023
end
10631024

1064-
10651025
-- Determine footer height based on whether the bag bar is visible.
10661026
local footerHeight = self.settings.showBagBar
10671027
and (uiButtons.itemSlots[1].bagshuiData.originalSizeAdjusted * bagBarScale) -- Bag bar visible.
@@ -1276,6 +1236,16 @@ function Inventory:AssignItemsToSlots(
12761236
self.hasChanges = true
12771237
end
12781238

1239+
-- Should the Clam button be enabled?
1240+
if item.openable == 1 then
1241+
self.hasOpenables = true
1242+
-- The first openable item we come across will be the one the Clam button targets.
1243+
if not self.nextOpenableItemBagNum then
1244+
self.nextOpenableItemBagNum = item.bagNum
1245+
self.nextOpenableItemSlotNum = item.slotNum
1246+
end
1247+
end
1248+
12791249
-- Increment counters.
12801250
itemsPlacedInCurrentRow = itemsPlacedInCurrentRow + 1
12811251
currentItemSlotButtonNum = currentItemSlotButtonNum + 1
@@ -1951,7 +1921,7 @@ function Inventory:UpdateToolbar()
19511921
self.ui:SetIconButtonColors(button)
19521922
end
19531923

1954-
-- State buttons.
1924+
-- State buttons .
19551925
self:SetToolbarButtonState(toolbarButtons.offline, (not self.online))
19561926
self:SetToolbarButtonState(toolbarButtons.error, (string.len(self.errorText or "") > 0))
19571927
self:SetToolbarButtonState(toolbarButtons.editMode, self.editMode, nil, self.editMode)
@@ -1980,9 +1950,75 @@ function Inventory:UpdateToolbar()
19801950
toolbarButtons.offline.bagshuiData.tooltipText = nil
19811951
end
19821952

1953+
-- Money frame.
1954+
if self.settings.showMoney then
1955+
self.ui.frames.money:Show()
1956+
self.ui.frames.money:SetAlpha(self.editMode and 0.2 or 1)
1957+
-- Use label colors for money text.
1958+
for _, text in pairs(self.ui.frames.money.bagshuiData.texts) do
1959+
text:SetTextColor(self.settings.groupLabelDefault[1], self.settings.groupLabelDefault[2], self.settings.groupLabelDefault[3], self.settings.groupLabelDefault[4])
1960+
end
1961+
else
1962+
self.ui.frames.money:Hide()
1963+
end
1964+
1965+
-- Hearthstone button.
1966+
if
1967+
self.hearthButton
1968+
and self.settings.showFooter
1969+
and self.settings.showHearthstone
1970+
and self.hearthstoneItemRef
1971+
then
1972+
toolbarButtons.hearthstone:Show()
1973+
1974+
-- Display cooldown.
1975+
local cooldownStart, cooldownDuration, isOnCooldown = _G.GetContainerItemCooldown(self.hearthstoneItemRef.bagNum, self.hearthstoneItemRef.slotNum)
1976+
self.ui:SetIconButtonCooldown(toolbarButtons.hearthstone, cooldownStart, cooldownDuration, isOnCooldown)
1977+
1978+
else
1979+
toolbarButtons.hearthstone:Hide()
1980+
end
1981+
1982+
-- Clam (open container) button.
1983+
self:SetToolbarButtonState(
1984+
toolbarButtons.clam,
1985+
(
1986+
self.clamButton
1987+
and self.settings.showClam
1988+
or false
1989+
),
1990+
self.hasOpenables and not self.editMode
1991+
)
1992+
1993+
-- Disenchant button.
1994+
self:SetToolbarButtonState(
1995+
toolbarButtons.disenchant,
1996+
(
1997+
self.disenchantButton
1998+
and BsCharacter.spellNamesToIds[toolbarButtons.disenchant.bagshuiData.spellName]
1999+
and self.settings.showDisenchant
2000+
or false
2001+
),
2002+
not self.editMode
2003+
)
2004+
2005+
-- Pick Lock button.
2006+
self:SetToolbarButtonState(
2007+
toolbarButtons.pickLock,
2008+
(
2009+
self.pickLockButton
2010+
and BsCharacter.spellNamesToIds[toolbarButtons.pickLock.bagshuiData.spellName]
2011+
and self.settings.showPickLock
2012+
or false
2013+
),
2014+
not self.editMode
2015+
)
2016+
2017+
19832018
-- Re-anchor all toolbar widgets based on visibility.
1984-
self:UpdateToolbarAnchoring(self.ui.ordering.leftToolbar, "LEFT")
1985-
self:UpdateToolbarAnchoring(self.ui.ordering.rightToolbar, "RIGHT")
2019+
self:UpdateToolbarAnchoring(self.ui.ordering.topLeftToolbar, "LEFT")
2020+
self:UpdateToolbarAnchoring(self.ui.ordering.topRightToolbar, "RIGHT")
2021+
self:UpdateToolbarAnchoring(self.ui.ordering.bottomRightToolbar, "RIGHT")
19862022

19872023
-- Disable unusable stuff in Edit Mode.
19882024
local editModeState = (self.editMode) and "Disable" or "Enable"
@@ -2055,7 +2091,8 @@ end
20552091
---@param widgetList (table|number)[] WoW UI widgets, in display order. Numbers are spacing directives that override the default.
20562092
---@param anchorPoint "LEFT"|"RIGHT" Place to anchor each widget. This point will be anchored to the opposing point of the previous widget.
20572093
function Inventory:UpdateToolbarAnchoring(widgetList, anchorPoint)
2058-
local defaultOffset = (anchorPoint == "RIGHT" and -1 or 1) * BsSkin.toolbarSpacing
2094+
local invert = (anchorPoint == "RIGHT" and -1 or 1)
2095+
local defaultOffset = invert * BsSkin.toolbarSpacing
20592096
local nextOffset
20602097

20612098
-- Go through the list of widgets in order, but skip the first one since
@@ -2064,8 +2101,8 @@ function Inventory:UpdateToolbarAnchoring(widgetList, anchorPoint)
20642101
local widget = widgetList[widgetPosition]
20652102
-- Ignore spacing directives when finding widgets.
20662103
if type(widget) == "table" and widget:IsShown() then
2067-
-- Assume default spacing.
2068-
nextOffset = defaultOffset
2104+
-- Assume default spacing, adjusted if customized for the widget.
2105+
nextOffset = defaultOffset + (widget.bagshuiData and widget.bagshuiData.autoLayoutXOffset or 0)
20692106
-- Walk backwards through the list of widgets and anchor to the first visible one.
20702107
for anchorPosition = widgetPosition - 1, 1, -1 do
20712108

0 commit comments

Comments
 (0)