Skip to content

Commit

Permalink
Section Drop and More (#242)
Browse files Browse the repository at this point in the history
* Fixed a small pawn bug with list view

* Added the ability to click and drag items onto section names to recategorize items from the bag view

* Fixed debug panel close button

* Fixed a bug where bag slots weren't redrawing when purchasing bag slots

* Fixed race condition on setting full refresh

* Added proper reagent bag free slot tooltip

* Free and release all free slot buttons when bag slot is shown
  • Loading branch information
Cidan authored Feb 25, 2024
1 parent ca2d17b commit 819b191
Show file tree
Hide file tree
Showing 20 changed files with 117 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
"error",
"type",
"CreateColor",
"LE_FRAME_TUTORIAL_MOUNT_EQUIPMENT_SLOT_FRAME"
"LE_FRAME_TUTORIAL_MOUNT_EQUIPMENT_SLOT_FRAME",
"GetText"
],
"Notes.notesLocation": ".notes",
"Lua.diagnostics.ignoredFiles": "Disable",
Expand Down
1 change: 1 addition & 0 deletions annotations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ BagBarExpandToggle = {}
---@class ScrollingFlatPanelTemplate: Frame
---@field ScrollBox WowScrollBox
---@field ScrollBar MinimalScrollBar
---@field ClosePanelButton Button

---@class DLAPI
DLAPI = {}
Expand Down
13 changes: 8 additions & 5 deletions config/bags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ local bucket = addon:GetModule('Bucket')
---@class Categories: AceModule
local categories = addon:GetModule('Categories')

---@class Events: AceModule
local events = addon:GetModule('Events')

---@class Items: AceModule
local items = addon:GetModule('Items')

Expand Down Expand Up @@ -54,7 +57,7 @@ function config:GetCustomCategoryOptions(kind)
end,
set = function(_, value)
categories:SetCategoryState(kind, value, not categories:IsCategoryEnabled(kind, value))
items:FullRefreshAll()
events:SendMessage('bags/FullRefreshAll')
end,
values = {}
}
Expand Down Expand Up @@ -92,7 +95,7 @@ function config:GetBagOptions(kind)
end,
set = function(_, value)
DB:SetCategoryFilter(kind, value, not DB:GetCategoryFilter(kind, value))
items:FullRefreshAll()
events:SendMessage('bags/FullRefreshAll')
end,
values = {
["RecentItems"] = L:G("Recent Items"),
Expand Down Expand Up @@ -180,7 +183,7 @@ function config:GetBagOptions(kind)
end,
set = function(_, value)
DB:SetItemLevelEnabled(kind, value)
items:FullRefreshAll()
events:SendMessage('bags/FullRefreshAll')
end,
},
color = {
Expand All @@ -193,7 +196,7 @@ function config:GetBagOptions(kind)
end,
set = function(_, value)
DB:SetItemLevelColorEnabled(kind, value)
items:FullRefreshAll()
events:SendMessage('bags/FullRefreshAll')
end,
},
}
Expand All @@ -210,7 +213,7 @@ function config:GetBagOptions(kind)
end,
set = function(_, value)
DB:SetBagView(kind, value)
items:FullRefreshAll()
events:SendMessage('bags/FullRefreshAll')
end,
values = {
[const.BAG_VIEW.SECTION_GRID] = L:G("Section Grid"),
Expand Down
13 changes: 8 additions & 5 deletions config/classic/bags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ local categories = addon:GetModule('Categories')
---@class Items: AceModule
local items = addon:GetModule('Items')

---@class Events: AceModule
local events = addon:GetModule('Events')

---@class Config: AceModule
local config = addon:GetModule('Config')

Expand Down Expand Up @@ -54,7 +57,7 @@ function config:GetCustomCategoryOptions(kind)
end,
set = function(_, value)
categories:SetCategoryState(kind, value, not categories:IsCategoryEnabled(kind, value))
items:FullRefreshAll()
events:SendMessage('bags/FullRefreshAll')
end,
values = {}
}
Expand Down Expand Up @@ -92,7 +95,7 @@ function config:GetBagOptions(kind)
end,
set = function(_, value)
DB:SetCategoryFilter(kind, value, not DB:GetCategoryFilter(kind, value))
items:FullRefreshAll()
events:SendMessage('bags/FullRefreshAll')
end,
values = {
["RecentItems"] = L:G("Recent Items"),
Expand Down Expand Up @@ -179,7 +182,7 @@ function config:GetBagOptions(kind)
end,
set = function(_, value)
DB:SetItemLevelEnabled(kind, value)
items:FullRefreshAll()
events:SendMessage('bags/FullRefreshAll')
end,
},
color = {
Expand All @@ -192,7 +195,7 @@ function config:GetBagOptions(kind)
end,
set = function(_, value)
DB:SetItemLevelColorEnabled(kind, value)
items:FullRefreshAll()
events:SendMessage('bags/FullRefreshAll')
end,
},
}
Expand All @@ -209,7 +212,7 @@ function config:GetBagOptions(kind)
end,
set = function(_, value)
DB:SetBagView(kind, value)
items:FullRefreshAll()
events:SendMessage('bags/FullRefreshAll')
end,
values = {
[const.BAG_VIEW.SECTION_GRID] = L:G("Section Grid"),
Expand Down
7 changes: 5 additions & 2 deletions config/itemlist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ local items = addon:GetModule('Items')
---@class Constants: AceModule
local const = addon:GetModule('Constants')

---@class Events: AceModule
local events = addon:GetModule('Events')

---@class Context: AceModule
local context = addon:GetModule('Context')

Expand Down Expand Up @@ -65,7 +68,7 @@ local function SetList(self, values)
local list = self:GetUserData("values")
DB:SaveItemToCategory(itemid, list.name)
self:SetList(DB:GetItemCategory(list.name))
items:FullRefreshAll()
events:SendMessage('bags/FullRefreshAll')
end

if #itemList == 0 then
Expand Down Expand Up @@ -108,7 +111,7 @@ local function SetList(self, values)
local list = self:GetUserData("values")
DB:DeleteItemFromCategory(v.itemInfo.itemID, list.name)
self:SetList(DB:GetItemCategory(list.name))
items:FullRefreshAll()
events:SendMessage('bags/FullRefreshAll')
end
}})
end
Expand Down
4 changes: 2 additions & 2 deletions data/categories.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ end
function categories:DeleteCategory(category)
database:DeleteItemCategory(category)
events:SendMessage('categories/Changed')
items:FullRefreshAll()
events:SendMessage('bags/FullRefreshAll')
end

-- GetCustomCategory returns the custom category for an item, or nil if it doesn't have one.
Expand Down Expand Up @@ -177,5 +177,5 @@ end
-- reprocessed and re-categorized.
function categories:ReprocessAllItems()
wipe(self.itemsWithNoCategory)
items:FullRefreshAll()
events:SendMessage('bags/FullRefreshAll')
end
5 changes: 5 additions & 0 deletions data/items.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ function items:OnEnable()
table.insert(eventList, 'PLAYERREAGENTBANKSLOTS_CHANGED')
end

events:RegisterMessage('bags/FullRefreshAll', function()
self:FullRefreshAll()
end)

events:GroupBucketEvent(eventList, {'bags/RefreshAll', 'bags/RefreshBackpack', 'bags/RefreshBank'}, function()
self:DoRefreshAll()
end)
Expand Down Expand Up @@ -126,6 +130,7 @@ function items:RefreshAll()
events:SendMessage('bags/RefreshAll')
end

---@private
-- FullRefreshAll will wipe the item cache and refresh all items in all bags.
function items:FullRefreshAll()
self.itemsByBagAndSlot = {}
Expand Down
7 changes: 7 additions & 0 deletions frames/bag.lua
Original file line number Diff line number Diff line change
Expand Up @@ -500,5 +500,12 @@ function bagFrame:Create(kind)
b.frame:SetTitle(L:G(kind == const.BAG_KIND.BACKPACK and "Backpack" or "Bank"))
end
end)

events:RegisterMessage('bags/FullRefreshAll', function()
if b.currentView then
b.currentView.fullRefresh = true
end
end)

return b
end
6 changes: 5 additions & 1 deletion frames/bagbutton.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ function BagButtonFrame.bagButtonProto:OnEnter()
return
elseif self.empty then
GameTooltip:SetOwner(self.frame, "ANCHOR_LEFT")
GameTooltip:SetText(L:G("Empty Bag Slot"), 1, 1, 1)
if const.BACKPACK_ONLY_REAGENT_BAGS[self.bag] then
GameTooltip:SetText(L:G("Empty Reagent Bag Slot"), 1, 1, 1)
else
GameTooltip:SetText(L:G("Empty Bag Slot"), 1, 1, 1)
end
GameTooltip:Show()
return
end
Expand Down
8 changes: 5 additions & 3 deletions frames/bagslots.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function BagSlots.bagSlotProto:Draw()
local w, h = self.content:Draw()
self.frame:SetWidth(w + const.OFFSETS.BAG_LEFT_INSET + -const.OFFSETS.BAG_RIGHT_INSET + 4)
self.frame:SetHeight(h + 42)
events:SendMessage('bags/FullRefreshAll')
end

function BagSlots.bagSlotProto:SetShown(shown)
Expand Down Expand Up @@ -100,7 +101,7 @@ function BagSlots:CreatePanel(kind)

b.fadeInGroup, b.fadeOutGroup = animations:AttachFadeAndSlideTop(b.frame)
b.fadeInGroup:HookScript("OnFinished", function()
items:FullRefreshAll()
events:SendMessage('bags/FullRefreshAll')
--[[
if b.kind == const.BAG_KIND.BACKPACK then
addon.Bags.Backpack:Refresh()
Expand All @@ -110,7 +111,7 @@ function BagSlots:CreatePanel(kind)
]]--
end)
b.fadeOutGroup:HookScript("OnFinished", function()
items:FullRefreshAll()
events:SendMessage('bags/FullRefreshAll')
--[[
if b.kind == const.BAG_KIND.BACKPACK and addon.Bags.Backpack then
addon.Bags.Backpack:Refresh()
Expand All @@ -119,7 +120,8 @@ function BagSlots:CreatePanel(kind)
end
]]--
end)
events:RegisterEvent("BAG_CONTAINER_UPDATE", function() b:Draw() end)
events:RegisterEvent('BAG_CONTAINER_UPDATE', function() b:Draw() end)
events:RegisterEvent('PLAYERBANKBAGSLOTS_CHANGED', function() b:Draw() end)
b.kind = kind
b.frame:Hide()
return b
Expand Down
4 changes: 2 additions & 2 deletions frames/classic/bagslots.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ function BagSlots:CreatePanel(kind)

b.fadeInGroup, b.fadeOutGroup = animations:AttachFadeAndSlideTop(b.frame)
b.fadeInGroup:HookScript("OnFinished", function()
items:FullRefreshAll()
events:SendMessage('bags/FullRefreshAll')
end)
b.fadeOutGroup:HookScript("OnFinished", function()
items:FullRefreshAll()
events:SendMessage('bags/FullRefreshAll')
end)
events:RegisterEvent("BAG_CONTAINER_UPDATE", function() b:Draw() end)
b.kind = kind
Expand Down
6 changes: 3 additions & 3 deletions frames/classic/context.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function context:CreateContextMenu(bag)
func = function()
context:Hide()
database:SetBagView(bag.kind, const.BAG_VIEW.ONE_BAG)
items:FullRefreshAll()
events:SendMessage('bags/FullRefreshAll')
end
},
{
Expand All @@ -147,7 +147,7 @@ function context:CreateContextMenu(bag)
database:SetBagView(bag.kind, const.BAG_VIEW.SECTION_GRID)
bag.drawOnClose = true
bag.currentItemCount = -1
items:FullRefreshAll()
events:SendMessage('bags/FullRefreshAll')
end
},
{
Expand All @@ -159,7 +159,7 @@ function context:CreateContextMenu(bag)
func = function()
context:Hide()
database:SetBagView(bag.kind, const.BAG_VIEW.LIST)
items:FullRefreshAll()
events:SendMessage('bags/FullRefreshAll')
end
}
}
Expand Down
6 changes: 3 additions & 3 deletions frames/context.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function context:CreateContextMenu(bag)
func = function()
context:Hide()
database:SetBagView(bag.kind, const.BAG_VIEW.ONE_BAG)
items:FullRefreshAll()
events:SendMessage('bags/FullRefreshAll')
end
},
{
Expand All @@ -146,7 +146,7 @@ function context:CreateContextMenu(bag)
func = function()
context:Hide()
database:SetBagView(bag.kind, const.BAG_VIEW.SECTION_GRID)
items:FullRefreshAll()
events:SendMessage('bags/FullRefreshAll')
end
},
{
Expand All @@ -158,7 +158,7 @@ function context:CreateContextMenu(bag)
func = function()
context:Hide()
database:SetBagView(bag.kind, const.BAG_VIEW.LIST)
items:FullRefreshAll()
events:SendMessage('bags/FullRefreshAll')
end
}
}
Expand Down
7 changes: 7 additions & 0 deletions frames/debug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,23 @@ function debugWindow:Create()
local view = CreateScrollBoxListLinearView()
view:SetElementInitializer("BetterBagsDebugListButton", initDebugListItem)
view:SetPadding(4,4,8,4,0)
view:SetExtent(20)
ScrollUtil.InitScrollBoxListWithScrollBar(self.frame.ScrollBox, self.frame.ScrollBar, view)
self.frame.ScrollBox:GetUpperShadowTexture():ClearAllPoints()
self.frame.ScrollBox:GetLowerShadowTexture():ClearAllPoints()
self.frame.ScrollBox:SetDataProvider(self.provider)

self.frame.ClosePanelButton:SetScript("OnClick", function()
database:SetDebugMode(false)
events:SendMessage('config/DebugMode', false)
end)

events:GroupBucketEvent({}, {'debug/LogAdded'}, function()
self.provider:InsertTable(self.cells)
wipe(self.cells)
self.frame.ScrollBox:ScrollToEnd()
end)

events:RegisterMessage('config/DebugMode', function(_, enabled)
if enabled then
self.frame:Show()
Expand Down
Loading

0 comments on commit 819b191

Please sign in to comment.