Add touch to Overview
This commit is contained in:
+21
-17
@@ -1,5 +1,6 @@
|
||||
local mon = peripheral.find("monitor")
|
||||
assert(mon, "Kein Monitor gefunden")
|
||||
local monName = peripheral.getName(mon)
|
||||
|
||||
mon.setTextScale(0.5)
|
||||
|
||||
@@ -283,11 +284,12 @@ end
|
||||
|
||||
local function drawOverview()
|
||||
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.
|
||||
|
||||
frame.buffer:clear()
|
||||
|
||||
for i = 1, math.min(math.max(#items, 9), 9) do
|
||||
for i = 1, visibleItemCount do
|
||||
local item = getItemById(items[i])
|
||||
local icon = getItemIcon(item) or getFallbackIcon()
|
||||
drawItem(icon, 4+(8+4)*((i-1)%3), 2+(5+1)*math.floor((i-1)/3), math.random(0, 1000000000000))
|
||||
@@ -295,24 +297,26 @@ local function drawOverview()
|
||||
|
||||
assertBufferValid(frame)
|
||||
frame:drawBuffer()
|
||||
|
||||
while true do
|
||||
local _, side, x, y = os.pullEvent("monitor_touch")
|
||||
|
||||
if side == monName then
|
||||
local col = math.floor((x - 4) / 12)
|
||||
local row = math.floor((y - 2) / 6)
|
||||
|
||||
if col >= 0 and col < 3 and row >= 0 and row < 3 then
|
||||
local index = row * 3 + col + 1
|
||||
|
||||
if index <= visibleItemCount then
|
||||
drawPage(items[index])
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
drawOverview()
|
||||
|
||||
sleep(10)
|
||||
|
||||
local i = 0
|
||||
while i < 10 do
|
||||
drawPage("minecraft:iron_block")
|
||||
sleep(1)
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
i = 0
|
||||
while i < 10 do
|
||||
drawPage("minecraft:gold_block")
|
||||
sleep(1)
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
term.redirect(oldTerm)
|
||||
|
||||
Reference in New Issue
Block a user