Advertisement
Chaos_Cash

Printer Control Pocket

Aug 27th, 2024 (edited)
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. function startup()
  2. rednet.open("back")
  3.  
  4. printerStatus = "Connecting..."
  5. heartbeat = true
  6. heartbeatTimer = os.startTimer(1)
  7.  
  8. rednet.send(22,"heartbeat")
  9. end
  10.  
  11.  
  12.  
  13. function main()
  14.  
  15. while true do
  16. info1,info2,info3,info4 = os.pullEvent()
  17.  
  18. if info1 == "rednet_message" and info2 == 22 then
  19.  
  20. if type(info3) == "table" then
  21.  
  22.  
  23. if info3["action"] == "sendingInfo" then
  24.  
  25. if info3["infoType"] == "actionCount" then
  26. actionCount = info3["info"]
  27. term.setCursorPos(1,20)
  28. term.setTextColor(colors.white)
  29. term.write("Actions left: ")
  30. term.setTextColor(colors.green)
  31. term.write(actionCount)
  32. term.write(" ")
  33. end
  34.  
  35. if info3["infoType"] == "printerStatus" then
  36. printerStatus = info3["info"]
  37. term.setCursorPos(1,1)
  38. term.setBackgroundColor(colors.black)
  39. term.write(" ")
  40. headline(printerStatus)
  41. end
  42.  
  43. end
  44.  
  45.  
  46. end
  47.  
  48.  
  49. if info3 == "heartbeat" then
  50. if heartbeat then
  51. term.setCursorPos(26,1)
  52. term.setBackgroundColor(colors.green)
  53. term.write(" ")
  54. term.setBackgroundColor(colors.black)
  55. heartbeat = false
  56. else
  57. heartbeat = true
  58. term.setCursorPos(26,1)
  59. term.setBackgroundColor(colors.black)
  60. term.write(" ")
  61. end
  62. end
  63.  
  64. end
  65.  
  66.  
  67. if info1 == "timer" and info2 == heartbeatTimer then
  68. rednet.send(22,"heartbeat")
  69. heartbeatTimer = os.startTimer(1)
  70. end
  71.  
  72.  
  73.  
  74. if curEnv == "homeMenu" then
  75. if buttonCheck(4,4,12,6) then
  76. rednet.send(22,"start")
  77. end
  78.  
  79. if buttonCheck(14,4,22,6) then
  80. rednet.send(22,"stop")
  81. end
  82.  
  83. if buttonCheck(4,7,12,9) then
  84. moveMenu()
  85. end
  86.  
  87. if buttonCheck(14,7,22,9) then
  88. rednet.send(22,"clear")
  89. end
  90.  
  91. if buttonCheck(4,10,12,12) then
  92. rednet.send(22,"refuel")
  93. end
  94.  
  95. if buttonCheck(14,10,22,12) then
  96. term.clear()
  97. term.setCursorPos(1,1)
  98. term.setTextColor(colors.white)
  99. term.setBackgroundColor(colors.black)
  100. term.write("Bridge length: ")
  101. term.setTextColor(colors.green)
  102. bridgeLen = math.floor(tonumber(read())/18)
  103. rednet.send(22,bridgeLen)
  104. homeMenu()
  105. end
  106.  
  107. if buttonCheck(4,13,12,15) then
  108. rednet.send(22,"print")
  109. end
  110. end
  111.  
  112.  
  113. if curEnv == "moveMenu" then
  114. if buttonCheck(21,18,26,20) then
  115. homeMenu()
  116. end
  117.  
  118. if buttonCheck(4,5,12,7) then
  119. rednet.send(22,"turtleTurn")
  120. end
  121.  
  122. if buttonCheck(14,5,22,7) then
  123. rednet.send(22,"turtleForward")
  124. end
  125.  
  126. if buttonCheck(4,8,12,10) then
  127. rednet.send(22,"turtleUp")
  128. end
  129.  
  130. if buttonCheck(4,13,12,15) then
  131. rednet.send(22,"machineForward")
  132. end
  133. end
  134.  
  135. end
  136.  
  137. end
  138.  
  139.  
  140.  
  141. function homeMenu()
  142. term.clear()
  143. curEnv = "homeMenu"
  144.  
  145. headline(printerStatus)
  146. button("Start",4,4,12,6)
  147. button("Stop",14,4,22,6)
  148. button("Move",4,7,12,9)
  149. button("clear",14,7,22,9)
  150. button("Refuel",4,10,12,12)
  151. button("Set len",14,10,22,12)
  152. button("Print",4,13,12,15)
  153.  
  154. term.setCursorPos(1,20)
  155. term.setTextColor(colors.white)
  156. term.write("Actions left: ")
  157. term.setTextColor(colors.green)
  158. term.write(actionCount)
  159. term.write(" ")
  160.  
  161. end
  162.  
  163.  
  164.  
  165. function moveMenu()
  166. term.clear()
  167. curEnv = "moveMenu"
  168.  
  169. headline(printerStatus)
  170. term.setCursorPos(4,4)
  171. print("Turles:")
  172. button("Turn",4,5,12,7)
  173. button("Forward",14,5,22,7)
  174. button("Up",4,8,12,10)
  175. term.setCursorPos(4,12)
  176. term.setTextColor(colors.white)
  177. print("Machine:")
  178. button("Forward",4,13,12,15)
  179. button("Back",21,18,26,20)
  180.  
  181. term.setCursorPos(1,20)
  182. term.setTextColor(colors.white)
  183. term.write("Actions left: ")
  184. term.setTextColor(colors.green)
  185. term.write(actionCount)
  186. term.write(" ")
  187.  
  188. end
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195. -- buttons and all that stuff
  196.  
  197. function headline(headline)
  198. width = term.getSize()
  199. headline_lenght=string.len(" "..headline.." ")
  200. headline_pos=(width/2)-(headline_lenght/2)+1
  201. term.setCursorPos(headline_pos,1)
  202. term.setBackgroundColor(colors.yellow)
  203. term.setTextColor(colors.blue)
  204. term.write(" "..headline.." ")
  205. term.setBackgroundColor(colors.black)
  206. term.setTextColor(colors.white)
  207. end
  208.  
  209.  
  210.  
  211. function button(button_text,button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,button_color)
  212. term.setTextColor(colors.green)
  213.  
  214. if button_color~=nil then
  215. term.setTextColor(button_color)
  216. end
  217.  
  218. square(button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,colors.black,"-","|")
  219. term.setCursorPos(math.ceil(button_pos_x1-string.len(button_text)/2+(button_pos_x2-button_pos_x1)/2),button_pos_y1+(button_pos_y2-button_pos_y1)/2)
  220. term.write(button_text)
  221. end
  222.  
  223.  
  224.  
  225. function buttonCheck(b_check_x1,b_check_y1,b_check_x2,b_check_y2)
  226. if info1=="mouse_click" and info3 > b_check_x1-1 and info3 < b_check_x2+1 and info4 > b_check_y1-1 and info4 < b_check_y2+1 then
  227. info1 = nil
  228. return true
  229. else
  230. return false
  231. end
  232. end
  233.  
  234.  
  235.  
  236. function square(x1,y1,x2,y2,back_color_square,symbol_square_x,symbol_square_y,text_color)
  237. x_1=x1
  238. y_1=y1
  239. x_2=x2
  240. y_2=y2
  241. while x_1~=x2+1 do
  242. term.setBackgroundColor(back_color_square)
  243. term.setCursorPos(x_1,y_1)
  244. if text_color~=nil then
  245. term.setTextColor(text_color)
  246. end
  247. term.write(symbol_square_x)
  248. x_1=x_1+1
  249. end
  250.  
  251. while y_1~=y2-1 do
  252. term.setCursorPos(x_1-1,y_1+1)
  253. term.write(symbol_square_y)
  254. y_1=y_1+1
  255. end
  256. x2=x2-1
  257. while x_2~=x1-1 do
  258. term.setCursorPos(x_2,y_2)
  259. term.write(symbol_square_x)
  260. x_2=x_2-1
  261. end
  262.  
  263. while y_2~=y1+1 do
  264. term.setCursorPos(x_2+1,y_2-1)
  265. term.write(symbol_square_y)
  266. y_2=y_2-1
  267. end
  268. term.setBackgroundColor(colors.black)
  269. end
  270.  
  271.  
  272. ---------------------------------------
  273.  
  274.  
  275. startup()
  276. homeMenu()
  277. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement