Advertisement
Leonardvdj

MystPortal

May 26th, 2016 (edited)
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.52 KB | None | 0 0
  1. books = {"First Age", "Second Age", "Third Age"}
  2. tArgs = {...}
  3. if #tArgs ~= 1 then
  4.   print("Syntax: "..shell.getRunningProgram().." <side of monitor>")
  5.   error()
  6. end
  7.  
  8. monitor = peripheral.wrap(tArgs[1])
  9. monitor.setTextScale(0.5)
  10.  
  11. chosenBook = 1
  12.  
  13. function ifthenelse(one,two,three)
  14.    if one then return two else return three end
  15. end
  16.  
  17. for i=1,#books do
  18.    if turtle.getItemCount(i) == 0 then
  19.       chosenBook = i
  20.    end
  21. end
  22.  
  23. function drawButtons()
  24.   local offsetX = 2
  25.   local offsetY = 2
  26.   for i=1,#books do
  27.     monitor.setBackgroundColor(ifthenelse(i == chosenBook, colors.green, colors.red))
  28.     for y=0,2 do
  29.       monitor.setCursorPos(offsetX, offsetY + y)
  30.       for x=0,12 do
  31.         monitor.write(" ")
  32.       end
  33.     end
  34.     local textOffset = math.floor((13 - #books[i]) / 2)
  35.     monitor.setCursorPos(offsetX + textOffset, offsetY + 1)
  36.     monitor.write(books[i])
  37.     offsetY = offsetY + 4
  38.   end
  39. end
  40.  
  41. function checkButtons(x, y)
  42.   local offsetX = 2
  43.   local offsetY = 2
  44.   for i=1,#books do
  45.     if x >= offsetX and x <= offsetX + 12 then
  46.       if y >= offsetY and y <= offsetY + 2 then
  47.         turtle.suck()
  48.         turtle.select(i)
  49.         turtle.drop()
  50.         chosenBook = i
  51.       end
  52.     end
  53.     offsetY = offsetY + 4
  54.   end
  55. end
  56.  
  57. monitor.setBackgroundColor(colors.black)
  58. monitor.clear()
  59. drawButtons()
  60.  
  61. while true do
  62.   local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  63.   monitor.setBackgroundColor(colors.black)
  64.   monitor.clear()
  65.   checkButtons(xPos, yPos)
  66.   drawButtons()
  67. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement