Implement pages
This commit is contained in:
parent
24d60850e8
commit
b9582d8d4b
@ -70,15 +70,7 @@ local function loadState(fname, node)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local accessNode = Chest:fromPeripheral("minecraft:trapped_chest", true)
|
local function itemList(groups, wBudget, onClick)
|
||||||
---@diagnostic disable-next-line: need-check-nil
|
|
||||||
local controller = loadState(CACHE_FILE, accessNode:getInventory())
|
|
||||||
local monitor = peripheral.find("monitor")
|
|
||||||
|
|
||||||
local width, height = monitor.getSize()
|
|
||||||
|
|
||||||
|
|
||||||
local function itemList(groups, wBudget)
|
|
||||||
local bgColors = {
|
local bgColors = {
|
||||||
colors.gray,
|
colors.gray,
|
||||||
colors.black
|
colors.black
|
||||||
@ -119,9 +111,7 @@ local function itemList(groups, wBudget)
|
|||||||
countLabel
|
countLabel
|
||||||
},
|
},
|
||||||
vertical = false,
|
vertical = false,
|
||||||
onClick = function(table, x, y, source)
|
onClick = onClick
|
||||||
print("Clicked: "..group:getDisplayName())
|
|
||||||
end
|
|
||||||
}
|
}
|
||||||
table.insert(entries, list)
|
table.insert(entries, list)
|
||||||
end
|
end
|
||||||
@ -132,18 +122,79 @@ local function itemList(groups, wBudget)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local found = ItemGroup.collectStacks(controller:find(function(stack)
|
local function renderDefault(state, rootElement)
|
||||||
return not stack:isEmpty()
|
local event = {os.pullEvent()}
|
||||||
end))
|
local handled = rootElement:handleEvent(event)
|
||||||
|
if not handled and event[1] == "monitor_resize" then
|
||||||
|
local width, height = state.monitor.getSize()
|
||||||
|
if state.width ~= width or state.height ~= height then
|
||||||
|
state.width = width
|
||||||
|
state.height = height
|
||||||
|
|
||||||
table.sort(found, function(a, b) return a:getItemCount() > b:getItemCount() end)
|
-- Trigger re-render
|
||||||
|
rootElement:setDirty(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local subset = {}
|
if not handled then
|
||||||
for i=1,math.min(13, #found) do
|
os.queueEvent(table.unpack(event))
|
||||||
table.insert(subset, found[i])
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local listResult = itemList(subset, width)
|
local PAGES = {
|
||||||
|
MAIN = function(state)
|
||||||
|
local found = ItemGroup.collectStacks(state.controller:find(function(stack)
|
||||||
|
return not stack:isEmpty()
|
||||||
|
end))
|
||||||
|
|
||||||
listResult:setParent(monitor)
|
table.sort(found, function(a, b) return a:getItemCount() > b:getItemCount() end)
|
||||||
listResult:draw()
|
|
||||||
|
local subset = {}
|
||||||
|
for i=1,math.min(13, #found) do
|
||||||
|
table.insert(subset, found[i])
|
||||||
|
end
|
||||||
|
|
||||||
|
local listResult = itemList(subset, state.width, function(group, x, y, source)
|
||||||
|
print("Clicked: "..group:getDisplayName())
|
||||||
|
end)
|
||||||
|
listResult:setParent(state.monitor)
|
||||||
|
|
||||||
|
return function()
|
||||||
|
renderDefault(state, listResult)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
GROUP_DETAIL = function(state)
|
||||||
|
|
||||||
|
end,
|
||||||
|
|
||||||
|
REQUEST = function(state)
|
||||||
|
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
local accessNode = Chest:fromPeripheral("minecraft:trapped_chest", true)
|
||||||
|
---@diagnostic disable-next-line: need-check-nil
|
||||||
|
local controller = loadState(CACHE_FILE, accessNode:getInventory())
|
||||||
|
local monitor = peripheral.find("monitor")
|
||||||
|
local width, height = monitor.getSize()
|
||||||
|
|
||||||
|
local CONTROLLER_STATE = {
|
||||||
|
controller = controller,
|
||||||
|
width = width,
|
||||||
|
height = height,
|
||||||
|
monitor = monitor,
|
||||||
|
currentPage = "MAIN",
|
||||||
|
exit = false
|
||||||
|
}
|
||||||
|
|
||||||
|
os.queueEvent("dummy_event")
|
||||||
|
while not CONTROLLER_STATE.exit do
|
||||||
|
PAGES[CONTROLLER_STATE.currentPage](CONTROLLER_STATE)
|
||||||
|
|
||||||
|
if CONTROLLER_STATE.nextPage ~= nil then
|
||||||
|
CONTROLLER_STATE.currentPage = CONTROLLER_STATE.nextPage
|
||||||
|
CONTROLLER_STATE.nextPage = nil
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user