Skip to content

Commit

Permalink
Bag size is now saved and loaded.
Browse files Browse the repository at this point in the history
Grid and OneBag views can no longer be dragged to resize (WIP)
  • Loading branch information
Cidan committed Nov 30, 2023
1 parent 8bdccb8 commit d77385a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
4 changes: 4 additions & 0 deletions core/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,14 @@ const.DATABASE_DEFAULTS = {
Backpack = {
columnCount = 3,
itemsPerRow = 5,
width = 700,
height = 500,
},
Bank = {
columnCount = 5,
itemsPerRow = 5,
width = 700,
height = 500,
}
},
views = {
Expand Down
17 changes: 16 additions & 1 deletion core/database.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local addon = LibStub('AceAddon-3.0'):GetAddon(addonName)
local const = addon:GetModule('Constants')

---@class Database: AceModule
---@field data databaseOptions
---@field private data databaseOptions
local DB = addon:NewModule('Database')

function DB:OnInitialize()
Expand Down Expand Up @@ -67,6 +67,21 @@ function DB:SetBagSizeItems(kind, count)
DB.data.profile.size[kind == const.BAG_KIND.BACKPACK and 'Backpack' or 'Bank'].itemsPerRow = count
end

---@param kind BagKind
---@return number, number
function DB:GetBagFrameSize(kind)
local s = DB.data.profile.size[kind == const.BAG_KIND.BACKPACK and 'Backpack' or 'Bank']
return s.width, s.height
end

---@param kind BagKind
---@param width number
---@param height number
function DB:SetBagFrameSize(kind, width, height)
DB.data.profile.size[kind == const.BAG_KIND.BACKPACK and 'Backpack' or 'Bank'].width = width
DB.data.profile.size[kind == const.BAG_KIND.BACKPACK and 'Backpack' or 'Bank'].height = height
end

---@param kind BagKind
---@return GridCompactStyle
function DB:GetBagCompaction(kind)
Expand Down
9 changes: 8 additions & 1 deletion frames/bag.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ local Window = LibStub('LibWindow-1.1')
---@field decorator Texture
---@field bg Texture
---@field moneyFrame Money
---@field resizeHandle Button
local bagProto = {}

function bagProto:Show()
Expand Down Expand Up @@ -176,10 +177,13 @@ function bagProto:Draw(dirtyItems)
end
self.recentItems.content:Wipe()
if database:GetBagView(self.kind) == const.BAG_VIEW.ONE_BAG then
self.resizeHandle:Hide()
views:OneBagView(self, dirtyItems)
elseif database:GetBagView(self.kind) == const.BAG_VIEW.SECTION_GRID then
self.resizeHandle:Hide()
views:GridView(self, dirtyItems)
elseif database:GetBagView(self.kind) == const.BAG_VIEW.LIST then
self.resizeHandle:Show()
views:ListView(self, dirtyItems)
end
local text = self.frame.SearchBox:GetText()
Expand Down Expand Up @@ -415,7 +419,10 @@ function bagFrame:Create(kind)
b:ToggleReagentBank()
end
end)
resize:MakeResizable(b.frame)
b.resizeHandle = resize:MakeResizable(b.frame, function()
local fw, fh = b.frame:GetSize()
database:SetBagFrameSize(b.kind, fw, fh)
end)
return b
end

Expand Down
6 changes: 5 additions & 1 deletion util/resize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ local addon = LibStub('AceAddon-3.0'):GetAddon(addonName)
local resize = addon:NewModule('Resize')

---@param frame Frame
function resize:MakeResizable(frame)
---@param onDone fun()
---@return Button
function resize:MakeResizable(frame, onDone)
frame:SetResizable(true)
frame:SetResizeBounds(300, 300)
local resizeHandle = CreateFrame("Button", nil, frame)
Expand All @@ -22,6 +24,7 @@ function resize:MakeResizable(frame)
end)
resizeHandle:SetScript("OnMouseUp", function(p)
p:GetParent():StopMovingOrSizing("BOTTOMRIGHT")
onDone()
end)
resizeHandle:SetScript("OnEnter", function(p)
p:SetAlpha(1)
Expand All @@ -30,4 +33,5 @@ function resize:MakeResizable(frame)
p:SetAlpha(0)
end)
resizeHandle:SetAlpha(0)
return resizeHandle
end
5 changes: 2 additions & 3 deletions views/listview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,8 @@ function views:ListView(bag, dirtyItems)
h = 40
end
bag.content:ShowScrollBar()
--TODO(lobato): Load this from the database.
bag.frame:SetWidth(600)
bag.frame:SetHeight(700)

bag.frame:SetSize(database:GetBagFrameSize(bag.kind))
end

--[[
Expand Down

0 comments on commit d77385a

Please sign in to comment.