Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item bag slots count display #313

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions config/bags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,19 @@ function config:GetBagOptions(kind)
events:SendMessage('bags/FullRefreshAll')
end,
},
showBagSlotsUsed = {
type = "toggle",
name = L:G("Show Bag Slots Used"),
desc = L:G("Shows the count of bag slots occupied by a merged unstackable."),
order = 5,
get = function()
return DB:GetStackingOptions(kind).showBagSlotsUsed
end,
set = function(_, value)
DB:SetShowBagSlotsUsed(kind, value)
events:SendMessage('bags/FullRefreshAll')
end,
},
}
},
itemLevel = {
Expand Down
13 changes: 13 additions & 0 deletions config/classic/bags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,19 @@ function config:GetBagOptions(kind)
events:SendMessage('bags/FullRefreshAll')
end,
},
showBagSlotsUsed = {
type = "toggle",
name = L:G("Show Bag Slots Used"),
desc = L:G("Shows the count of bag slots occupied by a merged unstackable."),
order = 5,
get = function()
return DB:GetStackingOptions(kind).showBagSlotsUsed
end,
set = function(_, value)
DB:SetShowBagSlotsUsed(kind, value)
events:SendMessage('bags/FullRefreshAll')
end,
},
}
},
itemLevel = {
Expand Down
2 changes: 2 additions & 0 deletions core/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,14 @@ const.DATABASE_DEFAULTS = {
mergeUnstackable = true,
unmergeAtShop = true,
dontMergePartial = false,
showBagSlotsUsed = false,
},
[const.BAG_KIND.BANK] = {
mergeStacks = true,
mergeUnstackable = true,
unmergeAtShop = true,
dontMergePartial = false,
showBagSlotsUsed = false,
}
},
itemLevel = {
Expand Down
4 changes: 4 additions & 0 deletions core/database.lua
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ function DB:SetDontMergePartial(kind, value)
DB.data.profile.stacking[kind].dontMergePartial = value
end

function DB:SetShowBagSlotsUsed(kind, value)
DB.data.profile.stacking[kind].showBagSlotsUsed = value
end

function DB:GetShowKeybindWarning()
return DB.data.profile.showKeybindWarning
end
Expand Down
4 changes: 3 additions & 1 deletion data/items.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ local debug = addon:GetModule('Debug')
---@field isItemEmpty boolean
---@field kind BagKind
---@field newItemTime number
---@field stacks number
---@field stacks number Count of _additional_ bag slots represented by a view slot
-- e.g. three unstackable items in a merge-unstackable view will have a single view slot
-- with ItemData.stacks = 2
---@field stackedOn string
---@field stackedCount number
---@field itemLinkInfo ItemLinkInfo
Expand Down
6 changes: 6 additions & 0 deletions frames/classic/item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ function itemFrame.itemProto:SetFreeSlots(bagid, slotid, count, name)
self.button.BattlepayItemTexture:SetShown(false)
self.button.NewItemTexture:Hide()
self.ilvlText:SetText("")
self.stacksCountText:Hide()
self.LockTexture:Hide()
self.button.UpgradeIcon:SetShown(false)

Expand Down Expand Up @@ -220,6 +221,7 @@ function itemFrame.itemProto:ClearItem()
self.button.minDisplayCount = 1
self.button:Enable()
self.ilvlText:SetText("")
self.stacksCountText:SetText("")
self.LockTexture:Hide()
self:SetSize(37, 37)
self.button.UpgradeIcon:SetShown(false)
Expand Down Expand Up @@ -294,8 +296,12 @@ function itemFrame:_DoCreate()
button:SetScript("OnEnter", function() i:UpdateTooltip() i:OnEnter() end)
local ilvlText = button:CreateFontString(nil, "OVERLAY", "NumberFontNormal")
ilvlText:SetPoint("BOTTOMLEFT", 2, 2)
local stacksCountText = button:CreateFontString(nil, "OVERLAY", "NumberFontNormal")
stacksCountText:SetPoint("TOPRIGHT", -4.8, -2)
stacksCountText:SetTextColor(0.8, 0.8, 0.8, 1)

i.ilvlText = ilvlText
i.stacksCountText = stacksCountText

return i
end
Expand Down
19 changes: 19 additions & 0 deletions frames/item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ local debug = addon:GetModule('Debug')
---@field kind BagKind
---@field masqueGroup string
---@field ilvlText FontString
---@field stacksCountText FontString for tracking the bag slots represented by a view slot
---@field IconTexture Texture
---@field Count FontString
---@field Stock FontString
Expand Down Expand Up @@ -209,6 +210,7 @@ function itemFrame.itemProto:Lock()
SetItemButtonDesaturated(self.button, self.data.itemInfo.isLocked)
self.LockTexture:Show()
self.ilvlText:Hide()
self.stacksCountText:Hide()
database:SetItemLock(self.data.itemInfo.itemGUID, true)
end

Expand Down Expand Up @@ -268,8 +270,16 @@ function itemFrame.itemProto:DrawItemLevel()
end

function itemFrame.itemProto:UpdateCount()
local stackingOptions = database:GetStackingOptions(self.kind)
if self.data == nil or self.data.isItemEmpty then return end
local count = self.data.stackedCount or self.data.itemInfo.currentItemCount
if self.data.stacks > 0 and stackingOptions.showBagSlotsUsed then
-- since ItemData stacks is effectively _additional_ stacks to the base one, take its value + 1
self.stacksCountText:SetText(tostring(self.data.stacks + 1))
self.stacksCountText:Show()
else
self.stacksCountText:Hide()
end
SetItemButtonCount(self.button, count)
end

Expand Down Expand Up @@ -438,6 +448,8 @@ function itemFrame.itemProto:SetFreeSlots(bagid, slotid, count, name)
SetItemButtonDesaturated(self.button, false)
self.ilvlText:SetText("")
self.ilvlText:Hide()
self.stacksCountText:SetText("")
self.stacksCountText:Hide()
self.LockTexture:Hide()
self.button.UpgradeIcon:SetShown(false)

Expand Down Expand Up @@ -509,6 +521,8 @@ function itemFrame.itemProto:ClearItem()
self.button:Enable()
self.ilvlText:SetText("")
self.ilvlText:Hide()
self.stacksCountText:SetText("")
self.stacksCountText:Hide()
self.LockTexture:Hide()
self:ResetSize()
self.data = nil
Expand Down Expand Up @@ -605,6 +619,11 @@ function itemFrame:_DoCreate()
local ilvlText = button:CreateFontString(nil, "OVERLAY", "NumberFontNormal")
ilvlText:SetPoint("BOTTOMLEFT", 2, 2)
i.ilvlText = ilvlText

local stacksCountText = button:CreateFontString(nil, "OVERLAY", "NumberFontNormal")
stacksCountText:SetPoint("TOPRIGHT", -4.8, -2)
stacksCountText:SetTextColor(0.8, 0.8, 0.8, 1)
i.stacksCountText = stacksCountText

i.stacks = {}
i.stackCount = 1
Expand Down