Implement text on storage progress bar

This commit is contained in:
Gabriel Tofvesson 2024-10-26 19:22:35 +02:00
parent 7430c24798
commit f24d33eb77

View File

@ -20,6 +20,7 @@ local Padding = require("gfx.padding")
local Container = require("gfx.container") local Container = require("gfx.container")
local Element = require("gfx.element") local Element = require("gfx.element")
local Progress = require("gfx.progress") local Progress = require("gfx.progress")
local TextProgress = require("gfx.textprogress")
local Children = require("gfx.prop.children") local Children = require("gfx.prop.children")
local Orientation = require("gfx.prop.orientation") local Orientation = require("gfx.prop.orientation")
@ -234,13 +235,6 @@ local PAGES = {
end end
local storageSatProgress = Progress:new{
width = state.width,
height = 1
-- Percentage of storage slots occupied
}
---- BOTTOM BAR ---- BOTTOM BAR
local keyboardButton = Text:new{ local keyboardButton = Text:new{
id = "action_keyboard", id = "action_keyboard",
@ -357,6 +351,7 @@ local PAGES = {
end end
local storageSatProgress = TextProgress:new{}
local aboveEntries = { storageSatProgress } local aboveEntries = { storageSatProgress }
local belowEntries = { bottomBarList } local belowEntries = { bottomBarList }
local entries = {} local entries = {}
@ -513,14 +508,17 @@ local PAGES = {
-- Enumerate inventory stats -- Enumerate inventory stats
local emptyCount = 0 local emptyCount = 0
local totalCount = 0
pageState.stacks = ItemGroup.collectStacks(state.controller:find(function(stack) pageState.stacks = ItemGroup.collectStacks(state.controller:find(function(stack)
if stack:isEmpty() then if stack:isEmpty() then
emptyCount = emptyCount + 1 emptyCount = emptyCount + 1
return false return false
else else
totalCount = totalCount + 1
return matchFilter(pageState.filter, stack:getSimpleName()) or matchFilter(pageState.filter, stack:getDisplayName()) or (pageState.filter:find(":") ~= nil and matchFilter(pageState.filter, stack:getName())) return matchFilter(pageState.filter, stack:getSimpleName()) or matchFilter(pageState.filter, stack:getDisplayName()) or (pageState.filter:find(":") ~= nil and matchFilter(pageState.filter, stack:getName()))
end end
end)) end))
totalCount = totalCount + emptyCount
table.sort(pageState.stacks, SORT_MODE[pageState.sortMode]) table.sort(pageState.stacks, SORT_MODE[pageState.sortMode])
local lastPage = #pageState.stacks % groupEntryListBudget local lastPage = #pageState.stacks % groupEntryListBudget
@ -530,7 +528,17 @@ local PAGES = {
-- Set dynamic states for elements -- Set dynamic states for elements
sortButton:setText("<"..tostring(pageState.sortMode)..">") sortButton:setText("<"..tostring(pageState.sortMode)..">")
storageSatProgress:setProgress(1 - (emptyCount / #pageState.stacks)) local totalCountStr = tostring(totalCount)
local emptyCountStr = tostring(emptyCount)
storageSatProgress:setText(
emptyCountStr..
(" "):rep(math.max(0, math.floor(state.width / 2) - #emptyCountStr - 1))..
"/"..
(" "):rep(math.max(0, math.ceil(state.width / 2) - #totalCountStr))..
totalCountStr
)
storageSatProgress:setProgress(emptyCount / totalCount)
local basePageIndex = (pageState.currentPage - 1) * groupEntryListBudget local basePageIndex = (pageState.currentPage - 1) * groupEntryListBudget
for i=1,groupEntryListBudget do for i=1,groupEntryListBudget do