craniumkid22

Turtles

Mar 10th, 2013
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.13 KB | None | 0 0
  1. term.setBackgroundColor(colors.green)
  2. term.clear()
  3. if rs.getInput("right") then
  4.     returnPad = true
  5. else
  6.     returnPad = false
  7. end
  8.  
  9. local com = peripheral.wrap("back")
  10.  
  11. local com = {}
  12. com.setCommand = function(command) write(command) end
  13. com.runCommand = function() write("Running command") end
  14.  
  15. --os.pullEvent = os.pullEventRaw
  16. local x, y = term.getSize()
  17. local menu = returnPad and {
  18.     {title = "Observation area",
  19.     comList = {
  20.         "/clear @p 402",
  21.         "/manuadd @p default",
  22.         "/tp @p " --return teleport
  23.         },
  24.     x1 = 3,
  25.     x2 = 18,
  26.     y = 9
  27.     }
  28. }
  29. or
  30. {
  31.      {title = "Turtle Free Play",
  32.     comList = {
  33.         "/give @p 402:258 1",
  34.         "/gamemode a @p",
  35.         "/manuadd @p turtle",
  36.         "/tp @p -296 26 160"
  37.         },
  38.     x1 = 3,
  39.     x2 = 18,
  40.     y = 8
  41.     },
  42.      {title = "Rednet Practice",
  43.     comList = {
  44.         "/give @p 402:258 1",
  45.         "/gamemode a @p",
  46.         "/manuadd @p turtle",
  47.         "/tp @p -296 26 160"
  48.         },
  49.     x1 = 3,
  50.     x2 = 17,
  51.     y = 9
  52.     },
  53.     {title = "Turtle Navigation",
  54.     comList = {
  55.         "/give @p 402:258 1",
  56.         "/gamemode a @p",
  57.         "/manuadd @p turtle",
  58.         "/tp @p -296 26 160"
  59.         },
  60.     x1 = 3,
  61.     x2 = 19,
  62.     y = 10
  63.     },
  64.     {title = "Redstone Practice",
  65.     comList = {
  66.         "/give @p 402:258 1",
  67.         "/gamemode a @p",
  68.         "/manuadd @p turtle",
  69.         "/tp @p -296 26 160"
  70.         },
  71.     x1 = 3,
  72.     x2 = 19,
  73.     y = 11
  74.     }
  75. }
  76.  
  77. local function gui(scroll, side)
  78.     for i = 1, y do
  79.         term.setBackgroundColor(colors.red)
  80.         term.setCursorPos(1, i)
  81.         write(" ")
  82.         term.setCursorPos(x, i)
  83.         write(" ")
  84.         term.setCursorPos(1, 1)
  85.         write(string.rep(" ", x))
  86.         term.setCursorPos(1, y)
  87.         write(string.rep(" ", x))
  88.     end
  89.     for i= 1, #menu do
  90.         term.setCursorPos(menu[i].x1, menu[i].y)
  91.         term.setBackgroundColor(colors.green)
  92.         write(menu[i].title)
  93.     end
  94.     term.setCursorPos(3, scroll + 7)
  95.     term.setBackgroundColor(colors.lightBlue)
  96.     write(menu[scroll].title)
  97.     local turtleImage = paintutils.loadImage("turtle"..side..".nfa")
  98.     paintutils.drawImage(turtleImage, 21, 2)
  99. end
  100.  
  101. local scroll = 1
  102. local side = 1
  103. gui(scroll, side)
  104. local sideTimer = nil
  105. while true do
  106.     if not sideTimer then
  107.         sideTimer = os.startTimer(1)
  108.     end
  109.     local events = {os.pullEvent()}
  110.     if events[1] == "mouse_click" and events[2] == 1 then
  111.         for i = 1, #menu do
  112.             if events[4] == menu[i].y then
  113.                 scroll = menu[i].y - 7
  114.                 for i = 1, #menu[scroll].comList do
  115.                     sleep(.05)
  116.                     com.setCommand(menu[scroll].comList[i])
  117.                     com.runCommand()
  118.                 end
  119.                 break
  120.             end
  121.         end
  122.         sideTimer = nil
  123.     elseif events[1] == "mouse_scroll" then
  124.         if events[2] == 1 then
  125.             scroll = scroll + 1
  126.         elseif events[2] == -1 then
  127.             scroll = scroll - 1
  128.         end
  129.     elseif events[1] == "timer" and events[2] == sideTimer then
  130.         side = side + 1
  131.         if side > 4 then side = 1 end
  132.         sleep(0)
  133.         sideTimer = nil
  134.     elseif events[1] == "key" then
  135.         if events[2] == 28 then
  136.             for i = 1, #menu[scroll].comList do
  137.                 sleep(.05)
  138.                 com.setCommand(menu[scroll].comList[i])
  139.                 com.runCommand()
  140.             end
  141.             sideTimer = nil
  142.         elseif events[2] == 200 then
  143.             scroll = scroll - 1
  144.         elseif events[2] == 208 then
  145.             scroll = scroll + 1
  146.         end
  147.     end
  148.     if scroll < 1 then scroll = 1 elseif scroll > #menu then scroll = #menu end
  149.     gui(scroll, side)
  150. end
  151. sleep(0)
Advertisement
Add Comment
Please, Sign In to add comment