Reload list on reload state

This commit is contained in:
Gabriel Tofvesson 2024-10-12 23:36:55 +02:00
parent 3a7b2cd252
commit 97b29a30a5

View File

@ -483,14 +483,17 @@ local PAGES = {
Prop.attach(
List:new{
id = tostring(i),
bgColor = (i % 2 == 0) and colors.gray or colors.black,
[Orientation:getId()] = Orientation.HORIZONTAL,
[Children:getId()] = {
Padding:new{
id = GroupEntryID.PADDING,
bgColor = (i % 2 == 0) and colors.gray or colors.black,
element = Text:new{ id = GroupEntryID.NAME }
},
Text:new{
id = GroupEntryID.COUNT
id = GroupEntryID.COUNT,
bgColor = (i % 2 == 0) and colors.gray or colors.black
}
}
},
@ -572,26 +575,25 @@ local PAGES = {
local function reloadState()
-- Enumerate inventory stats
local emptyCount = 0
local totalCount = 0
pageState.stacks = ItemGroup.collectStacks(state.controller:find(function(stack)
if stack:isEmpty() then
emptyCount = emptyCount + 1
return false
else
totalCount = totalCount + 1
local name = stack:getSimpleName()
return matchFilter(pageState.filter, name) or (name:find(":") ~= nil and matchFilter(pageState.filter, stack:getName()))
end
end))
totalCount = emptyCount + totalCount
table.sort(pageState.stacks, SORT_MODE[pageState.sortMode])
pageState.pages = math.ceil(totalCount / groupEntryListBudget)
local lastPage = #pageState.stacks % groupEntryListBudget
pageState.pages = (#pageState.stacks - lastPage) / groupEntryListBudget + (lastPage == 0 and 0 or 1)
-- Set dynamic states for elements
sortButton:setText("<"..tostring(pageState.sortMode)..">")
storageSatProgress:setProgress(1 - (emptyCount / totalCount))
storageSatProgress:setProgress(1 - (emptyCount / #pageState.stacks))
local basePageIndex = (pageState.currentPage - 1) * groupEntryListBudget
for i=1,groupEntryListBudget do
@ -613,7 +615,7 @@ local PAGES = {
nameText:setText(name)
namePadding:setPadding{ right = nameTextBudget - #name }
listEntry:adjustPositions()
listEntry:_reload()
listEntry:setOnClick(function()
state:setPage("GROUP_DETAIL", group)
return true