Advertisement
paramus

Turtle manager

Feb 6th, 2025 (edited)
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.22 KB | Gaming | 0 0
  1. local backColor = colors.white
  2. local TurtleID
  3.  
  4. function Gui()
  5.     term.setBackgroundColor(backColor)
  6.     term.clear()
  7.    
  8.     --Title
  9.     paintutils.drawPixel(4,2,backColor)
  10.     term.setCursorPos(4,2)
  11.     term.setTextColor(colors.black)
  12.     term.write("-Turtle manager-")
  13.    
  14.     --Exit Button
  15.     paintutils.drawPixel(2,2,colors.red)
  16.     term.setCursorPos(2,2)
  17.     term.setTextColor(colors.white)
  18.     term.write("x")
  19.    
  20.     --List Button
  21.     paintutils.drawPixel(2,4,colors.yellow)
  22.     term.setCursorPos(2,4)
  23.     term.setTextColor(colors.white)
  24.     term.write("List")
  25.    
  26.     --Control Button
  27.     paintutils.drawPixel(2,6,colors.yellow)
  28.     term.setCursorPos(2,6)
  29.     term.setTextColor(colors.white)
  30.     term.write("Control turtle")
  31. end
  32.  
  33. function ListGui()
  34.     --Get turtles data from rednet
  35.    
  36.     local lsTurtles = {{"Enie",true}, {"Minie",false}, {"Miny",false}, {"Mou",true}} --Get with rednet
  37.     local loop = true
  38.     while(loop) do
  39.         term.setBackgroundColor(backColor)
  40.         term.clear()
  41.  
  42.         --Title
  43.         paintutils.drawPixel(4,2,backColor)
  44.         term.setCursorPos(4,2)
  45.         term.setTextColor(colors.black)
  46.         term.write("-Turtle list-")
  47.  
  48.         --Return Button
  49.         paintutils.drawPixel(2,2,colors.red)
  50.         term.setCursorPos(2,2)
  51.         term.setTextColor(colors.white)
  52.         term.write("<")
  53.        
  54.         --List of turtles
  55.         for i=1,#lsTurtles,1 do
  56.             local y = i+3
  57.             if (y%2 ~= 0) then y=y+1 end
  58.            
  59.             --Name
  60.             paintutils.drawPixel(4,y,colors.cyan)
  61.             term.setCursorPos(4,y)
  62.             term.setTextColor(colors.gray)
  63.             term.write(lsTurtles[i][1])
  64.                
  65.             --Resume/stop Button
  66.             term.setTextColor(colors.white)
  67.             if (lsTurtles[i][2]==true) then
  68.                 paintutils.drawPixel(2,y,colors.green)
  69.                 term.setCursorPos(2,y)
  70.                 term.write(">")
  71.             else
  72.                 paintutils.drawPixel(2,y,colors.yellow)
  73.                 term.setCursorPos(2,y)
  74.                 term.write("#")
  75.             end
  76.         end
  77.        
  78.         --Button click
  79.         local e,b,x,y = os.pullEvent("mouse_click")
  80.         if (x==2 and y==2) then
  81.             loop = false
  82.         elseif (x==2 and y>=4) then
  83.            
  84.         end
  85.     end
  86. end
  87.  
  88. function ControlGui()
  89.     rednet.open("back")
  90.    
  91.     local loop = true
  92.     while(loop) do
  93.         term.setBackgroundColor(backColor)
  94.         term.clear()
  95.  
  96.         --Title
  97.         paintutils.drawPixel(4,2,backColor)
  98.         term.setCursorPos(4,2)
  99.         term.setTextColor(colors.black)
  100.         term.write("-Turtle control-")
  101.  
  102.         --Return Button
  103.         paintutils.drawPixel(2,2,colors.red)
  104.         term.setCursorPos(2,2)
  105.         term.setTextColor(colors.white)
  106.         term.write("<")
  107.        
  108.         --ID Container
  109.         paintutils.drawPixel(2,4,backColor)
  110.         term.setCursorPos(2,4)
  111.         term.setTextColor(colors.black)
  112.         term.write("ID")
  113.         paintutils.drawLine(5,4,10,4,colors.black)
  114.         term.setTextColor(colors.white)
  115.         term.setCursorPos(5,4)
  116.         term.write(TurtleID)
  117.        
  118.         --Fuel level
  119.         paintutils.drawPixel(2,4,backColor)
  120.         term.setCursorPos(12,4)
  121.         term.setTextColor(colors.black)
  122.         term.write("Fuel:")
  123.         term.setCursorPos(18,4)
  124.        
  125.         rednet.send(TurtleID, "FuelLevel")
  126.         local ID, Msg = rednet.receive()      
  127.         term.write(tonumber(Msg))
  128.        
  129.         --Turn left
  130.         paintutils.drawFilledBox(2,6,6,8,colors.yellow)
  131.         term.setTextColor(colors.white)
  132.         term.setCursorPos(2,7)
  133.         term.write("Left")
  134.        
  135.         --Turn right
  136.         paintutils.drawFilledBox(21,6,25,8,colors.yellow)
  137.         term.setTextColor(colors.white)
  138.         term.setCursorPos(21,7)
  139.         term.write("Right")
  140.        
  141.         --Go Up
  142.         paintutils.drawFilledBox(11,6,16,6,colors.yellow)
  143.         term.setTextColor(colors.white)
  144.         term.setCursorPos(13,6)
  145.         term.write("Up")
  146.        
  147.         --Go Down
  148.         paintutils.drawFilledBox(11,8,16,8,colors.yellow)
  149.         term.setTextColor(colors.white)
  150.         term.setCursorPos(12,8)
  151.         term.write("Down")
  152.        
  153.         --Start
  154.         paintutils.drawPixel(2,10,colors.green)
  155.         term.setTextColor(colors.white)
  156.         term.setCursorPos(2,10)
  157.         term.write("Start")
  158.        
  159.         --Stop
  160.         paintutils.drawPixel(8,10,colors.green)
  161.         term.setTextColor(colors.white)
  162.         term.setCursorPos(8,10)
  163.         term.write("Stop")
  164.        
  165.         --Stop
  166.         paintutils.drawPixel(13,10,colors.green)
  167.         term.setTextColor(colors.white)
  168.         term.setCursorPos(13,10)
  169.         term.write("Forward")
  170.        
  171.         --Button click
  172.         local e,b,x,y = os.pullEvent("mouse_click")
  173.         if (x==2 and y==2) then
  174.             loop = false
  175.         elseif (x>=5 and x<=10 and y==4) then -- Input ID
  176.             term.setBackgroundColor(colors.black)
  177.             term.setTextColor(colors.white)
  178.             term.setCursorPos(5,4)
  179.             TurtleID = tonumber(read())
  180.         elseif (x>=2 and x<=6 and y>=6 and y<=8) then --Turn left
  181.             rednet.send(TurtleID, "TurnLeft")
  182.         elseif (x>=21 and x<=25 and y>=6 and y<=8) then --Turn left
  183.             rednet.send(TurtleID, "TurnRight")
  184.         elseif (x>=11 and x<=16 and y==6) then -- Move Up
  185.             rednet.send(TurtleID, "MoveUp")
  186.         elseif (x>=11 and x<=16 and y==8) then -- Move Down
  187.             rednet.send(TurtleID, "MoveDown")
  188.         elseif (x>=2 and x<=6 and y==10) then -- Start
  189.             rednet.send(TurtleID, "Start")
  190.         elseif (x>=8 and x<=11 and y==10) then -- Start
  191.             rednet.send(TurtleID, "Stop")
  192.         elseif (x>=13 and x<=19 and y==10) then -- Start
  193.             rednet.send(TurtleID, "MoveForward")
  194.         end
  195.     end
  196.    
  197.     rednet.close()
  198. end
  199.  
  200. function Events(x,y)
  201.     if (x==2 and y==2) then
  202.         error("",0)
  203.     elseif (y==4 and x>=2 and x<=5) then
  204.         ListGui()
  205.     elseif (y==6 and x>=2 and x<=8) then
  206.         ControlGui()
  207.     end
  208. end
  209.  
  210. -- Main --
  211. while(true) do
  212.     Gui()
  213.     local e,b,x,y = os.pullEvent("mouse_click")
  214.     Events(x,y)
  215. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement