Advertisement
MajorVictory

TURTLE INTERACTIONS 0.9.2 (MV)

Aug 24th, 2013
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.18 KB | None | 0 0
  1. --VARIABLES
  2. local version = "TURTLE INTERACTIONS 0.9.2 (MV)"
  3. local w,h = term.getSize()
  4. local select, turtleslot = 1, 1
  5. local running = true
  6. local a, b, c, d, e, f, z = 6,7,8,9,10,11,h-2
  7. turtle.select(turtleslot)
  8.  
  9. --PRINT
  10.  
  11. local function printCentered(str, ypos)
  12.  term.setCursorPos(w/2 - #str/2, ypos)
  13.  term.write(str)
  14. end
  15.  
  16. local function printRight(str, ypos)
  17.  term.setCursorPos(w-#str, ypos)
  18.  term.write(str)
  19. end
  20.  
  21. function clearScreen()
  22.  term.clear()
  23.  term.setCursorPos(1,1)
  24.  term.clear()
  25. end
  26.  
  27. function drawHeader(title, line)
  28.     printCentered(title, line)
  29.     printCentered(string.rep("-", w), line+1)
  30.     printRight("Fuel: "..turtle.getFuelLevel(), line+2)
  31.  
  32.     term.setCursorPos(1, line+2)
  33.     term.write("\""..os.getComputerLabel().."\"")
  34. end
  35.  
  36. function drawCopyright()
  37.  printRight("by UNOBTANIUM", h)
  38. end
  39.  
  40.  
  41. -- MENUS
  42.  
  43. function drawMenuTurtleInteractions()
  44.  drawHeader(version, 1)
  45.  drawCopyright()
  46.  
  47.  if select == 1 then
  48.   printCentered("> Movement <", a)
  49.  else
  50.   printCentered("Movement", a)
  51.  end
  52.  if select == 2 then
  53.   printCentered("> Actions <", b)
  54.  else
  55.   printCentered("Actions", b)
  56.  end
  57.  if select == 3 then
  58.   printCentered("> Control <", c)
  59.  else
  60.   printCentered("Control", c)
  61.  end
  62.  if select == 4 then
  63.   printCentered("> Update <", d)
  64.  else
  65.   printCentered("Update", d)
  66.  end
  67.  if select == 5 then
  68.   printCentered("> Exit <", z)
  69.  else
  70.   printCentered("Exit", z)
  71.  end
  72. end
  73.  
  74. function drawMenuTurtleMovement()
  75.  drawHeader(version, 1)
  76.  drawHeader("TURTLE MOVEMENT", 3)
  77.  
  78.  if select == 1 then
  79.   printCentered("> Forward <", a)
  80.  else
  81.   printCentered("Forward", a)
  82.  end
  83.  if select == 2 then
  84.   printCentered("> Back <", b)
  85.  else
  86.   printCentered("Back", b)
  87.  end
  88.  if select == 3 then
  89.   printCentered("> Up <", c)
  90.  else
  91.   printCentered("Up", c)
  92.  end
  93.  if select == 4 then
  94.   printCentered("> Down <", d)
  95.  else
  96.   printCentered("Down", d)
  97.  end
  98.  if select == 5 then
  99.   printCentered("> Turn Left <", e)
  100.  else
  101.   printCentered("Turn Left", e)
  102.  end
  103.  if select == 6 then
  104.   printCentered("> Turn Right <", f)
  105.  else
  106.   printCentered("Turn Right", f)
  107.  end
  108.  if select == 7 then
  109.   printCentered("> Back <", 12)
  110.  else
  111.   printCentered("Back", 12)
  112.  end
  113. end
  114.  
  115. function drawMenuTurtleActions()
  116.  drawHeader(version, 1)
  117.  drawHeader("TURTLE ACTIONS", 3)
  118.  
  119.  if select == 1 then
  120.   printCentered("> Refuel <", a)
  121.  else
  122.   printCentered("Refuel", a)
  123.  end
  124.  if select == 2 then
  125.   printCentered("> Dig <", b)
  126.  else
  127.   printCentered("Dig", b)
  128.  end
  129.  if select == 3 then
  130.   printCentered("> Select <", c)
  131.  else
  132.   printCentered("Select", c)
  133.  end
  134.  if select == 4 then
  135.   printCentered("> Back <", z)
  136.  else
  137.   printCentered("Back", z)
  138.  end
  139. end
  140.  
  141. function drawMenuTurtleDig()
  142.  drawHeader(version, 1)
  143.  drawHeader("TURTLE DIG", 3)
  144.  
  145.  if select == 1 then
  146.   printCentered("> Up <", a)
  147.  else
  148.   printCentered("Up", a)
  149.  end
  150.  if select == 2 then
  151.   printCentered("> Front <", b)
  152.  else
  153.   printCentered("Front", b)
  154.  end
  155.  if select == 3 then
  156.   printCentered("> Down <", c)
  157.  else
  158.   printCentered("Down", c)
  159.  end
  160.  if select == 4 then
  161.   printCentered("> Back <", z)
  162.  else
  163.   printCentered("Back", z)
  164.  end
  165. end
  166.  
  167.  
  168. -- MENUSTATE
  169.  
  170. local menustate = "turtleinteractions"
  171.  
  172. local mopt = {
  173.  ["turtleinteractions"] = {
  174.   options = {"turtlemovement", "turtleactions", "control", "update", "quit"},
  175.   draw = drawMenuTurtleInteractions
  176.  },
  177.  ["turtlemovement"] = {
  178.   options = {"forward", "back", "up", "down", "left", "right" , "turtleinteractions"},
  179.   draw = drawMenuTurtleMovement
  180.  },
  181.  ["turtleactions"] = {
  182.   options = {"refuel", "turtledig", "select", "turtleinteractions"},
  183.   draw = drawMenuTurtleActions
  184.  },
  185.  ["turtledig"] = {
  186.   options = {"digup", "digfront", "digdown", "turtleactions"},
  187.   draw = drawMenuTurtleDig
  188.  }
  189. }
  190.  
  191. function runMenu()
  192.  while true do
  193.   clearScreen()
  194.   mopt[menustate].draw()
  195.  
  196.   local id, key = os.pullEvent("key")
  197.   if key == 200 then
  198.    select = select-1
  199.   end
  200.   if key == 208 then
  201.    select = select+1
  202.   end
  203.   if select == 0 then
  204.    select = #mopt[menustate].options
  205.   end
  206.   if select > #mopt[menustate].options then
  207.    select = 1
  208.   end
  209.   clearScreen()
  210.   if key == 28 then
  211.    if mopt[menustate].options[select] == "quit" then
  212.     running = false
  213.     break
  214.    elseif mopt[menustate].options[select] == "control" then
  215.     control()
  216.    elseif mopt[menustate].options[select] == "forward" then
  217.     turtle.forward()
  218.    elseif mopt[menustate].options[select] == "back" then
  219.     turtle.back()
  220.    elseif mopt[menustate].options[select] == "up" then
  221.     turtle.up()
  222.    elseif mopt[menustate].options[select] == "down" then
  223.     turtle.down()
  224.    elseif mopt[menustate].options[select] == "left" then
  225.     turtle.turnLeft()
  226.    elseif mopt[menustate].options[select] == "right" then
  227.     turtle.turnRight()
  228.    elseif mopt[menustate].options[select] == "refuel" then
  229.     turtle.refuel(1)
  230.    elseif mopt[menustate].options[select] == "select" then
  231.     turtleslot = turtleslot + 1
  232.     if turtleslot > 16 then turtleslot = 1 end
  233.     turtle.select(turtleslot)
  234.    elseif mopt[menustate].options[select] == "digup" then
  235.     turtle.digUp()
  236.    elseif mopt[menustate].options[select] == "digfront" then
  237.     turtle.dig()
  238.    elseif mopt[menustate].options[select] == "digdown" then
  239.     turtle.digDown()
  240.    elseif mopt[menustate].options[select] == "update" then
  241.     update()
  242.    elseif true then
  243.     menustate = mopt[menustate].options[select]
  244.     select = 1
  245.    end
  246.   end
  247.  end
  248. end
  249.  
  250. function update()
  251.     shell.run("delete", "startup")
  252.     shell.run("pastebin", "get M3D3RLCZ startup")
  253. end
  254.  
  255. function control()
  256.  local blockslot = 1
  257.  local mode = "move"
  258.  local working = true
  259.  turtle.select(blockslot)
  260.  
  261.  function info()
  262.   clearScreen()
  263.   print("Navigate with your keyboard.")
  264.   print("W A S D      -- Horizontal")
  265.   print("Space/SHIFT  -- Up/Down")
  266.   print("E            -- Switch Mode")
  267.   print("Q            -- Next Slot")
  268.   print("Ctrl         -- Exit Interface.")
  269.   print("")
  270.   print("Turtle Mode: " .. mode)
  271.  end
  272.  
  273.  while working do
  274.   info()
  275.   local id, key = os.pullEvent("key")
  276.   if key == 29 then
  277.    working = false
  278.   elseif key == 16 then
  279.    blockslot = blockslot + 1
  280.    if blockslot == 17 then
  281.     blockslot = 1
  282.    end
  283.    turtle.select(blockslot)
  284.   elseif key == 30 then
  285.    turtle.turnLeft()
  286.   elseif key == 31 then
  287.    turtle.back()
  288.   elseif key == 32 then
  289.    turtle.turnRight()
  290.  
  291.   elseif mode == "move" then
  292.    if key == 17 then
  293.     turtle.forward()
  294.    elseif key == 57 then
  295.     turtle.up()
  296.    elseif key == 42 then
  297.     turtle.down()
  298.    elseif key == 18 then
  299.     mode = "dig"
  300.    end
  301.  
  302.   elseif mode == "dig" then
  303.    if key == 17 then
  304.     turtle.dig()
  305.    elseif key == 57 then
  306.     turtle.digUp()
  307.    elseif key == 42 then
  308.     turtle.digDown()
  309.    elseif key == 18 then
  310.     mode = "place"
  311.    end
  312.  
  313.   elseif mode == "place" then
  314.    if key == 17 then
  315.     turtle.place()
  316.    elseif key == 57 then
  317.     turtle.placeUp()
  318.    elseif key == 42 then
  319.     turtle.placeDown()
  320.    elseif key == 18 then
  321.     mode = "movedig"
  322.    end
  323.  
  324.   elseif mode == "movedig" then
  325.    if key == 17 then
  326.     turtle.dig()
  327.     turtle.forward()
  328.    elseif key == 57 then
  329.     turtle.digUp()
  330.     turtle.up()
  331.    elseif key == 42 then
  332.     turtle.digDown()
  333.     turtle.down()
  334.    elseif key == 18 then
  335.     mode = "move"
  336.    end
  337.   end
  338.  end
  339. end
  340.  
  341. while running do
  342.  runMenu()
  343. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement