Advertisement
ravneravn

turtle monitor control

Jun 22nd, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. mon = peripheral.wrap("top")
  2. term.redirect(mon)
  3. width, height = term.getSize()
  4. rednet.open("left")
  5. tY = 5
  6. mon.clear()
  7.  
  8.  
  9. function setColor(text, background)
  10. term.setTextColor(text)
  11. term.setBackgroundColor(background)
  12. end
  13.  
  14.  
  15. function mWrite(message, cX, cY, background, text)
  16. mon.setBackgroundColor(background)
  17. if text == nil then mon.setTextColor(colors.black)
  18. else mon.setTextColor(text)
  19. end
  20. mon.setCursorPos(cX, cY)
  21. mon.write(message)
  22. end
  23.  
  24.  
  25. function backgroundColor(color)
  26. mon.setBackgroundColor(color)
  27. mon.clear()
  28. end
  29.  
  30.  
  31. function text()
  32. mWrite("New mine", 5, 3, colors.lime, colors.black)
  33. mWrite("Download", 18, 3, colors.red, colors.black)
  34. end
  35.  
  36.  
  37. function wait()
  38. event, sid, mes, dis = os.pullEvent()
  39. if event == "rednet_message" then
  40. if tY == 20 then
  41. mon.clear()
  42. -- drawScreen()
  43. text()
  44. tY = 5
  45. end
  46. mWrite(mes, 3, tY, colors.black, colors.white)
  47. tY = tY + 1
  48. elseif event == "monitor_touch" and mes > 1 and mes < 14 then newMine()
  49. elseif event == "monitor_touch" and mes > 14 and mes < 27 then download()
  50. end
  51. end
  52.  
  53. function newMine()
  54. rednet.broadcast("go")
  55. sleep(1)
  56. mon.setBackgroundColor(colors.black)
  57. mon.clear()
  58. mWrite("1", 5, 3, colors.lime, colors.black)
  59. mWrite("2", 18, 3, colors.lime, colors.black)
  60. mWrite("3", 5, 10, colors.lime, colors.black)
  61. mWrite("4", 18, 10, colors.lime, colors.black)
  62. event, niu, argX, argY = os.pullEvent("monitor_touch")
  63. if argX > 0 and argX < 14 and argY > 0 and argY <7 then message = 1
  64. elseif argX > 14 and argX < 27 and argY > 0 and argY < 7 then message = 2
  65. elseif argX > 0 and argX < 14 and argY > 7 and argY <30 then message = 3
  66. elseif argX > 14 and argX < 27 and argY > 7 and argY <30 then message = 4
  67. end
  68. print(message)
  69. sleep(1)
  70. rednet.broadcast(message)
  71. mon.setBackgroundColor(colors.black)
  72. mon.clear()
  73. end
  74.  
  75.  
  76. function download()
  77. rednet.broadcast("download")
  78. mon.setBackgroundColor(colors.black)
  79. mon.clear()
  80. end
  81.  
  82. while true do
  83. text()
  84. wait()
  85. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement