Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- books = {"First Age", "Second Age", "Third Age"}
- tArgs = {...}
- if #tArgs ~= 1 then
- print("Syntax: "..shell.getRunningProgram().." <side of monitor>")
- error()
- end
- monitor = peripheral.wrap(tArgs[1])
- monitor.setTextScale(0.5)
- chosenBook = 1
- function ifthenelse(one,two,three)
- if one then return two else return three end
- end
- for i=1,#books do
- if turtle.getItemCount(i) == 0 then
- chosenBook = i
- end
- end
- function drawButtons()
- local offsetX = 2
- local offsetY = 2
- for i=1,#books do
- monitor.setBackgroundColor(ifthenelse(i == chosenBook, colors.green, colors.red))
- for y=0,2 do
- monitor.setCursorPos(offsetX, offsetY + y)
- for x=0,12 do
- monitor.write(" ")
- end
- end
- local textOffset = math.floor((13 - #books[i]) / 2)
- monitor.setCursorPos(offsetX + textOffset, offsetY + 1)
- monitor.write(books[i])
- offsetY = offsetY + 4
- end
- end
- function checkButtons(x, y)
- local offsetX = 2
- local offsetY = 2
- for i=1,#books do
- if x >= offsetX and x <= offsetX + 12 then
- if y >= offsetY and y <= offsetY + 2 then
- turtle.suck()
- turtle.select(i)
- turtle.drop()
- chosenBook = i
- end
- end
- offsetY = offsetY + 4
- end
- end
- monitor.setBackgroundColor(colors.black)
- monitor.clear()
- drawButtons()
- while true do
- local event, side, xPos, yPos = os.pullEvent("monitor_touch")
- monitor.setBackgroundColor(colors.black)
- monitor.clear()
- checkButtons(xPos, yPos)
- drawButtons()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement