Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function startup()
- rednet.open("back")
- printerStatus = "Connecting..."
- heartbeat = true
- heartbeatTimer = os.startTimer(1)
- rednet.send(22,"heartbeat")
- end
- function main()
- while true do
- info1,info2,info3,info4 = os.pullEvent()
- if info1 == "rednet_message" and info2 == 22 then
- if type(info3) == "table" then
- if info3["action"] == "sendingInfo" then
- if info3["infoType"] == "actionCount" then
- actionCount = info3["info"]
- term.setCursorPos(1,20)
- term.setTextColor(colors.white)
- term.write("Actions left: ")
- term.setTextColor(colors.green)
- term.write(actionCount)
- term.write(" ")
- end
- if info3["infoType"] == "printerStatus" then
- printerStatus = info3["info"]
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.black)
- term.write(" ")
- headline(printerStatus)
- end
- end
- end
- if info3 == "heartbeat" then
- if heartbeat then
- term.setCursorPos(26,1)
- term.setBackgroundColor(colors.green)
- term.write(" ")
- term.setBackgroundColor(colors.black)
- heartbeat = false
- else
- heartbeat = true
- term.setCursorPos(26,1)
- term.setBackgroundColor(colors.black)
- term.write(" ")
- end
- end
- end
- if info1 == "timer" and info2 == heartbeatTimer then
- rednet.send(22,"heartbeat")
- heartbeatTimer = os.startTimer(1)
- end
- if curEnv == "homeMenu" then
- if buttonCheck(4,4,12,6) then
- rednet.send(22,"start")
- end
- if buttonCheck(14,4,22,6) then
- rednet.send(22,"stop")
- end
- if buttonCheck(4,7,12,9) then
- moveMenu()
- end
- if buttonCheck(14,7,22,9) then
- rednet.send(22,"clear")
- end
- if buttonCheck(4,10,12,12) then
- rednet.send(22,"refuel")
- end
- if buttonCheck(14,10,22,12) then
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.write("Bridge length: ")
- term.setTextColor(colors.green)
- bridgeLen = math.floor(tonumber(read())/18)
- rednet.send(22,bridgeLen)
- homeMenu()
- end
- if buttonCheck(4,13,12,15) then
- rednet.send(22,"print")
- end
- end
- if curEnv == "moveMenu" then
- if buttonCheck(21,18,26,20) then
- homeMenu()
- end
- if buttonCheck(4,5,12,7) then
- rednet.send(22,"turtleTurn")
- end
- if buttonCheck(14,5,22,7) then
- rednet.send(22,"turtleForward")
- end
- if buttonCheck(4,8,12,10) then
- rednet.send(22,"turtleUp")
- end
- if buttonCheck(4,13,12,15) then
- rednet.send(22,"machineForward")
- end
- end
- end
- end
- function homeMenu()
- term.clear()
- curEnv = "homeMenu"
- headline(printerStatus)
- button("Start",4,4,12,6)
- button("Stop",14,4,22,6)
- button("Move",4,7,12,9)
- button("clear",14,7,22,9)
- button("Refuel",4,10,12,12)
- button("Set len",14,10,22,12)
- button("Print",4,13,12,15)
- term.setCursorPos(1,20)
- term.setTextColor(colors.white)
- term.write("Actions left: ")
- term.setTextColor(colors.green)
- term.write(actionCount)
- term.write(" ")
- end
- function moveMenu()
- term.clear()
- curEnv = "moveMenu"
- headline(printerStatus)
- term.setCursorPos(4,4)
- print("Turles:")
- button("Turn",4,5,12,7)
- button("Forward",14,5,22,7)
- button("Up",4,8,12,10)
- term.setCursorPos(4,12)
- term.setTextColor(colors.white)
- print("Machine:")
- button("Forward",4,13,12,15)
- button("Back",21,18,26,20)
- term.setCursorPos(1,20)
- term.setTextColor(colors.white)
- term.write("Actions left: ")
- term.setTextColor(colors.green)
- term.write(actionCount)
- term.write(" ")
- end
- -- buttons and all that stuff
- function headline(headline)
- width = term.getSize()
- headline_lenght=string.len(" "..headline.." ")
- headline_pos=(width/2)-(headline_lenght/2)+1
- term.setCursorPos(headline_pos,1)
- term.setBackgroundColor(colors.yellow)
- term.setTextColor(colors.blue)
- term.write(" "..headline.." ")
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- function button(button_text,button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,button_color)
- term.setTextColor(colors.green)
- if button_color~=nil then
- term.setTextColor(button_color)
- end
- square(button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,colors.black,"-","|")
- 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)
- term.write(button_text)
- end
- function buttonCheck(b_check_x1,b_check_y1,b_check_x2,b_check_y2)
- 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
- info1 = nil
- return true
- else
- return false
- end
- end
- function square(x1,y1,x2,y2,back_color_square,symbol_square_x,symbol_square_y,text_color)
- x_1=x1
- y_1=y1
- x_2=x2
- y_2=y2
- while x_1~=x2+1 do
- term.setBackgroundColor(back_color_square)
- term.setCursorPos(x_1,y_1)
- if text_color~=nil then
- term.setTextColor(text_color)
- end
- term.write(symbol_square_x)
- x_1=x_1+1
- end
- while y_1~=y2-1 do
- term.setCursorPos(x_1-1,y_1+1)
- term.write(symbol_square_y)
- y_1=y_1+1
- end
- x2=x2-1
- while x_2~=x1-1 do
- term.setCursorPos(x_2,y_2)
- term.write(symbol_square_x)
- x_2=x_2-1
- end
- while y_2~=y1+1 do
- term.setCursorPos(x_2+1,y_2-1)
- term.write(symbol_square_y)
- y_2=y_2-1
- end
- term.setBackgroundColor(colors.black)
- end
- ---------------------------------------
- startup()
- homeMenu()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement