diff --git a/core/constants.lua b/core/constants.lua index 8c85f9ad..20f6ee66 100644 --- a/core/constants.lua +++ b/core/constants.lua @@ -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 = { diff --git a/core/database.lua b/core/database.lua index 30cc2d32..aea5548f 100644 --- a/core/database.lua +++ b/core/database.lua @@ -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() @@ -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) diff --git a/frames/bag.lua b/frames/bag.lua index a29973b9..ad8f213a 100644 --- a/frames/bag.lua +++ b/frames/bag.lua @@ -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() @@ -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() @@ -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 diff --git a/util/resize.lua b/util/resize.lua index 130c8a01..a6285dba 100644 --- a/util/resize.lua +++ b/util/resize.lua @@ -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) @@ -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) @@ -30,4 +33,5 @@ function resize:MakeResizable(frame) p:SetAlpha(0) end) resizeHandle:SetAlpha(0) + return resizeHandle end diff --git a/views/listview.lua b/views/listview.lua index 752a5e98..68918a21 100644 --- a/views/listview.lua +++ b/views/listview.lua @@ -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 --[[