Skip to content

Commit

Permalink
Revert "Smooth Drawing (#696)"
Browse files Browse the repository at this point in the history
This reverts commit fde068c.
  • Loading branch information
Cidan committed Sep 13, 2024
1 parent 9571bc0 commit 0637586
Show file tree
Hide file tree
Showing 6 changed files with 273 additions and 358 deletions.
14 changes: 1 addition & 13 deletions data/slots.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,7 @@ end

---@return ItemData[], ItemData[], ItemData[]
function SlotInfo:GetChangeset()
local added = {}
local removed = {}
local updated = {}
for _, item in pairs(self.addedItems) do
table.insert(added, item)
end
for _, item in pairs(self.removedItems) do
table.insert(removed, item)
end
for _, item in pairs(self.updatedItems) do
table.insert(updated, item)
end
return added, removed, updated
return self.addedItems, self.removedItems, self.updatedItems
end

---@param ctx Context
Expand Down
40 changes: 17 additions & 23 deletions frames/bag.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ local tabs = addon:GetModule('Tabs')
---@field menuList MenuList[]
---@field toRelease Item[]
---@field toReleaseSections Section[]
---@field views table<BagView, View[]>
---@field views table<BagView, View>
---@field loaded boolean
---@field windowGrouping WindowGrouping
---@field sideAnchor Frame
Expand Down Expand Up @@ -300,20 +300,23 @@ end
---@param slotInfo SlotInfo
---@param callback fun()
function bagFrame.bagProto:Draw(ctx, slotInfo, callback)
local viewList = self.views[database:GetBagView(self.kind)]
local updateView = viewList[1] == self.currentView and viewList[2] or viewList[1]
local previousView = self.currentView
local view = self.views[database:GetBagView(self.kind)]

--if self.currentView and self.currentView:GetBagView() ~= updateView:GetBagView() then
-- self.currentView:Wipe(ctx)
-- self.currentView:GetContent():Hide()
--end
if view == nil then
assert(view, "No view found for bag view: "..database:GetBagView(self.kind))
return
end

if self.currentView and self.currentView:GetBagView() ~= view:GetBagView() then
self.currentView:Wipe(ctx)
self.currentView:GetContent():Hide()
end

debug:StartProfile('Bag Render %d', self.kind)
updateView:Render(ctx, self, slotInfo, function()
view:Render(ctx, self, slotInfo, function()
debug:EndProfile('Bag Render %d', self.kind)
updateView:GetContent():Show()
self.currentView = updateView
view:GetContent():Show()
self.currentView = view
self.frame:SetScale(database:GetBagSizeInfo(self.kind, database:GetBagView(self.kind)).scale / 100)
local text = searchBox:GetText()
if text ~= "" and text ~= nil then
Expand All @@ -326,16 +329,7 @@ function bagFrame.bagProto:Draw(ctx, slotInfo, callback)
end
events:SendMessage(ctx, 'bag/RedrawIcons', self)
events:SendMessage(ctx, 'bag/Rendered', self, slotInfo)
if previousView then
previousView:GetContent():Hide()
if previousView:GetBagView() == updateView:GetBagView() then
previousView:Render(ctx, self, slotInfo, callback)
else
callback()
end
else
callback()
end
callback()
end)
end

Expand Down Expand Up @@ -557,8 +551,8 @@ function bagFrame:Create(ctx, kind)
--end)

b.views = {
[const.BAG_VIEW.SECTION_GRID] = {views:NewGrid(f, b.kind), views:NewGrid(f, b.kind)},
[const.BAG_VIEW.SECTION_ALL_BAGS] = {views:NewBagView(f, b.kind), views:NewBagView(f, b.kind)},
[const.BAG_VIEW.SECTION_GRID] = views:NewGrid(f, b.kind),
[const.BAG_VIEW.SECTION_ALL_BAGS] = views:NewBagView(f, b.kind),
}

-- Register the bag frame so that window positions are saved.
Expand Down
5 changes: 0 additions & 5 deletions frames/section.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,6 @@ function sectionProto:ReleaseAllCells(ctx)
end
end

---@return Cell[]|Item[]|Section[]|any[]
function sectionProto:GetCellList()
return self.content.cells
end

function sectionProto:Wipe()
self.content:Wipe()
self.frame:Hide()
Expand Down
183 changes: 76 additions & 107 deletions views/bagview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,20 @@ local database = addon:GetModule('Database')
---@class Sort: AceModule
local sort = addon:GetModule('Sort')

---@class Async: AceModule
local async = addon:GetModule('Async')

---@class Localization: AceModule
local L = addon:GetModule('Localization')

---@param view View
local function Wipe(view, _)
---@param ctx Context
local function Wipe(view, ctx)
view.content:Wipe()
view.itemCount = 0
--for _, section in pairs(view.sections) do
-- section:ReleaseAllCells(ctx)
-- section:Release(ctx)
--end
--wipe(view.sections)
--wipe(view.itemsByBagAndSlot)
end

---@param ctx Context
---@param view View
local function WipeSections(ctx, view)
debug:StartProfile('Bag View Sections Wipe')
for _, section in pairs(view.sections) do
async:RawBatch(ctx, 10, section:GetCellList(), function(bctx, cell)
cell:Release(bctx)
end)
section:ReleaseAllCells(ctx)
section:Release(ctx)
end
wipe(view.sections)
wipe(view.itemsByBagAndSlot)
debug:EndProfile('Bag View Sections Wipe')
end

---@param bagid number
Expand Down Expand Up @@ -156,99 +139,85 @@ local function BagView(view, ctx, bag, slotInfo, callback)

local added, removed, changed = slotInfo:GetChangeset()

async:Chain(ctx, nil,
function(ectx)
if ectx:GetBool('wipe') then
debug:StartProfile('Wipe Loop')
view:Wipe(ectx)
WipeSections(ectx, view)
debug:EndProfile('Wipe Loop')
end
end,
function(ectx)
async:RawBatch(ectx, 15, removed, function(bctx, item)
ClearButton(bctx, view, item)
end)
end,
function(ectx)
async:RawBatch(ectx, 15, added, function(bctx, item)
CreateButton(bctx, view, item)
end)
end,
function(ectx)
async:RawBatch(ectx, 15, changed, function(bctx, item)
UpdateButton(bctx, view, item.slotkey)
end)
end,
function(ectx)
for bagid, emptyBagData in pairs(slotInfo.emptySlotByBagAndSlot) do
for slotid, data in pairs(emptyBagData) do
local slotkey = view:GetSlotKey(data)
if C_Container.GetBagName(bagid) ~= nil then
local itemButton = view.itemsByBagAndSlot[slotkey] --[[@as Item]]
if itemButton == nil then
itemButton = itemFrame:Create(ectx)
view.itemsByBagAndSlot[slotkey] = itemButton
end
itemButton:SetFreeSlots(ectx, bagid, slotid, -1)
local section = view:GetOrCreateSection(ectx, GetBagName(bagid))
section:AddCell(slotkey, itemButton)
for _, item in pairs(removed) do
ClearButton(ctx, view, item)
end

for _, item in pairs(added) do
CreateButton(ctx, view, item)
end

for _, item in pairs(changed) do
UpdateButton(ctx, view, item.slotkey)
end

for bagid, emptyBagData in pairs(slotInfo.emptySlotByBagAndSlot) do
for slotid, data in pairs(emptyBagData) do
local slotkey = view:GetSlotKey(data)
if C_Container.GetBagName(bagid) ~= nil then
local itemButton = view.itemsByBagAndSlot[slotkey] --[[@as Item]]
if itemButton == nil then
itemButton = itemFrame:Create(ctx)
view.itemsByBagAndSlot[slotkey] = itemButton
end
itemButton:SetFreeSlots(ctx, bagid, slotid, -1)
local section = view:GetOrCreateSection(ctx, GetBagName(bagid))
section:AddCell(slotkey, itemButton)
end
end
end

for _, item in pairs(view.itemsByBagAndSlot) do
item:UpdateCount(ectx)
end
for _, item in pairs(view.itemsByBagAndSlot) do
item:UpdateCount(ctx)
end

for sectionName, section in pairs(view:GetAllSections()) do
if section:GetCellCount() == 0 then
debug:Log("RemoveSection", "Removed because empty", sectionName)
view:RemoveSection(sectionName)
section:ReleaseAllCells(ectx)
section:Release(ectx)
else
debug:Log("KeepSection", "Section kept because not empty", sectionName)
section:SetMaxCellWidth(sizeInfo.itemsPerRow)
section:Draw(bag.kind, database:GetBagView(bag.kind), true)
end
end
view.content.maxCellWidth = sizeInfo.columnCount
-- Sort the sections.
view.content:Sort(function(a, b)
return sort.SortSectionsAlphabetically(view.kind, a, b)
end)
debug:StartProfile('Content Draw Stage')
local w, h = view.content:Draw({
cells = view.content.cells,
maxWidthPerRow = ((37 + 4) * sizeInfo.itemsPerRow) + 16,
columns = sizeInfo.columnCount,
})
debug:EndProfile('Content Draw Stage')
-- Reposition the content frame if the recent items section is empty.
if w < 160 then
w = 160
end
if bag.tabs and w < bag.tabs.width then
w = bag.tabs.width
end
if h == 0 then
h = 40
end
if database:GetInBagSearch() then
h = h + 20
for sectionName, section in pairs(view:GetAllSections()) do
if section:GetCellCount() == 0 then
debug:Log("RemoveSection", "Removed because empty", sectionName)
view:RemoveSection(sectionName)
section:ReleaseAllCells(ctx)
section:Release(ctx)
else
debug:Log("KeepSection", "Section kept because not empty", sectionName)
section:SetMaxCellWidth(sizeInfo.itemsPerRow)
section:Draw(bag.kind, database:GetBagView(bag.kind), true)
end
view.content:HideScrollBar()
--TODO(lobato): Implement SafeSetSize that prevents the window from being larger
-- than the screen space.
bag.frame:SetWidth(w + const.OFFSETS.BAG_LEFT_INSET + -const.OFFSETS.BAG_RIGHT_INSET)
local bagHeight = h +
const.OFFSETS.BAG_BOTTOM_INSET + -const.OFFSETS.BAG_TOP_INSET +
const.OFFSETS.BOTTOM_BAR_HEIGHT + const.OFFSETS.BOTTOM_BAR_BOTTOM_INSET
bag.frame:SetHeight(bagHeight)
UpdateViewSize(view)
end, callback)

end
view.content.maxCellWidth = sizeInfo.columnCount
-- Sort the sections.
view.content:Sort(function(a, b)
return sort.SortSectionsAlphabetically(view.kind, a, b)
end)
debug:StartProfile('Content Draw Stage')
local w, h = view.content:Draw({
cells = view.content.cells,
maxWidthPerRow = ((37 + 4) * sizeInfo.itemsPerRow) + 16,
columns = sizeInfo.columnCount,
})
debug:EndProfile('Content Draw Stage')
-- Reposition the content frame if the recent items section is empty.
if w < 160 then
w = 160
end
if bag.tabs and w < bag.tabs.width then
w = bag.tabs.width
end
if h == 0 then
h = 40
end
if database:GetInBagSearch() then
h = h + 20
end
view.content:HideScrollBar()
--TODO(lobato): Implement SafeSetSize that prevents the window from being larger
-- than the screen space.
bag.frame:SetWidth(w + const.OFFSETS.BAG_LEFT_INSET + -const.OFFSETS.BAG_RIGHT_INSET)
local bagHeight = h +
const.OFFSETS.BAG_BOTTOM_INSET + -const.OFFSETS.BAG_TOP_INSET +
const.OFFSETS.BOTTOM_BAR_HEIGHT + const.OFFSETS.BOTTOM_BAR_BOTTOM_INSET
bag.frame:SetHeight(bagHeight)
UpdateViewSize(view)
callback()
end

---@param parent Frame
Expand Down
Loading

0 comments on commit 0637586

Please sign in to comment.