Add back button
This commit is contained in:
+29
-1
@@ -1,6 +1,7 @@
|
|||||||
local mon = peripheral.find("monitor")
|
local mon = peripheral.find("monitor")
|
||||||
assert(mon, "Kein Monitor gefunden")
|
assert(mon, "Kein Monitor gefunden")
|
||||||
local monName = peripheral.getName(mon)
|
local monName = peripheral.getName(mon)
|
||||||
|
local SCREEN_WIDTH = 40
|
||||||
|
|
||||||
mon.setTextScale(0.5)
|
mon.setTextScale(0.5)
|
||||||
|
|
||||||
@@ -17,6 +18,8 @@ local baseItemIds
|
|||||||
local itemById
|
local itemById
|
||||||
local defaultBaseId
|
local defaultBaseId
|
||||||
local fallbackIcon = false
|
local fallbackIcon = false
|
||||||
|
local backButton = false
|
||||||
|
local drawOverview
|
||||||
|
|
||||||
local function ensureChainsLoaded()
|
local function ensureChainsLoaded()
|
||||||
if not chainItemsByBaseId then
|
if not chainItemsByBaseId then
|
||||||
@@ -124,6 +127,18 @@ local function getFallbackIcon()
|
|||||||
return fallbackIcon
|
return fallbackIcon
|
||||||
end
|
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 function imageSize(img)
|
||||||
local w, h = 0, 0
|
local w, h = 0, 0
|
||||||
|
|
||||||
@@ -267,8 +282,12 @@ end
|
|||||||
local function drawPage(base_id)
|
local function drawPage(base_id)
|
||||||
local pageItems = getPageItems(base_id)
|
local pageItems = getPageItems(base_id)
|
||||||
local defaultIcon = getFallbackIcon()
|
local defaultIcon = getFallbackIcon()
|
||||||
|
local backIcon = getBackButton()
|
||||||
|
local backWidth, backHeight = imageSize(backIcon)
|
||||||
|
local backX = SCREEN_WIDTH - backWidth + 1
|
||||||
|
|
||||||
frame.buffer:clear()
|
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.
|
-- 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)
|
assertBufferValid(frame)
|
||||||
frame:drawBuffer()
|
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
|
end
|
||||||
|
|
||||||
local function drawOverview()
|
drawOverview = function()
|
||||||
local items = getBaseItemIds()
|
local items = getBaseItemIds()
|
||||||
local visibleItemCount = math.min(math.max(#items, 9), 9)
|
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.
|
-- 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.
|
||||||
|
|||||||
Reference in New Issue
Block a user