Add back button

This commit is contained in:
Max
2026-06-01 04:08:50 +02:00
parent f38cc53465
commit 1d3a507a06
+29 -1
View File
@@ -1,6 +1,7 @@
local mon = peripheral.find("monitor")
assert(mon, "Kein Monitor gefunden")
local monName = peripheral.getName(mon)
local SCREEN_WIDTH = 40
mon.setTextScale(0.5)
@@ -17,6 +18,8 @@ local baseItemIds
local itemById
local defaultBaseId
local fallbackIcon = false
local backButton = false
local drawOverview
local function ensureChainsLoaded()
if not chainItemsByBaseId then
@@ -124,6 +127,18 @@ local function getFallbackIcon()
return fallbackIcon
end
local function getBackButton()
if backButton == false then
backButton = parseNfpImage(table.concat({
"e e",
" e ",
"e e",
}, "\n"))
end
return backButton
end
local function imageSize(img)
local w, h = 0, 0
@@ -267,8 +282,12 @@ end
local function drawPage(base_id)
local pageItems = getPageItems(base_id)
local defaultIcon = getFallbackIcon()
local backIcon = getBackButton()
local backWidth, backHeight = imageSize(backIcon)
local backX = SCREEN_WIDTH - backWidth + 1
frame.buffer:clear()
drawNfpScaled(frame.buffer, backIcon, (backX - 1) * 2 + 1, 1)
-- TODO LATER get item counts from me-system using item ids. For now, just use random numbers.
@@ -280,9 +299,18 @@ local function drawPage(base_id)
assertBufferValid(frame)
frame:drawBuffer()
while true do
local _, side, x, y = os.pullEvent("monitor_touch")
if side == monName and x >= backX and x < backX + backWidth and y >= 1 and y <= backHeight then
drawOverview()
return
end
end
end
local function drawOverview()
drawOverview = function()
local items = getBaseItemIds()
local visibleItemCount = math.min(math.max(#items, 9), 9)
-- TODO LATER: get item counts from me-system using item, then sort items according to their counts and display the top 9. For now, just use random numbers.