Advertisement
guitarplayer616

COOK UI

May 29th, 2015
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local w, h = term.getSize()
  2. term.setBackgroundColor(colors.black)
  3. term.clear()
  4. turtle.select(1)
  5.  
  6. if not fs.exists("flame.nfp") then
  7.   shell.run("pastebin get uZVN5U2Y flame.nfp")
  8. end
  9.  
  10. if not fs.exists("recipes") then
  11.   fs.makeDir("recipes")
  12.   oTemp = fs.open("recipes/list", "w")
  13.   oTemp.writeLine("recipeslist = {}")
  14.   oTemp.flush()
  15.   oTemp.close()
  16. end
  17.  
  18. if not fs.exists("*crafting") then
  19.   oTemp = fs.open("*crafting", "w")
  20.   oTemp.writeLine("c7cccccc7c")
  21.   oTemp.writeLine("700c00c007")
  22.   oTemp.writeLine("c00c00c00c")
  23.   oTemp.writeLine("cccccccccc")
  24.   oTemp.writeLine("c00c00c00c")
  25.   oTemp.writeLine("c00c00c00c")
  26.   oTemp.writeLine("cccccccccc")
  27.   oTemp.writeLine("c00c00c00c")
  28.   oTemp.writeLine("700c00c007")
  29.   oTemp.writeLine("c7cccccc7c")
  30.   oTemp.flush()
  31.   oTemp.close()
  32. end
  33.  
  34. if not fs.exists("*smelting") then
  35.   oTemp = fs.open("*smelting", "w")
  36.   oTemp.writeLine("7777777777")
  37.   oTemp.writeLine("77ffffff77")
  38.   oTemp.writeLine("7ffffffff7")
  39.   oTemp.writeLine("7ffffffff7")
  40.   oTemp.writeLine("7777777777")
  41.   oTemp.writeLine("8888888888")
  42.   oTemp.writeLine("88ee4e1e88")
  43.   oTemp.writeLine("81e41ee4e8")
  44.   oTemp.writeLine("8ee1e4e148")
  45.   oTemp.writeLine("8888888888")
  46.   oTemp.flush()
  47.   oTemp.close()
  48. end
  49.  
  50.  
  51. local craftImg = paintutils.loadImage("*crafting")
  52. local smeltImg = paintutils.loadImage("*smelting")
  53. local flameImg = paintutils.loadImage("flame.nfp")
  54. local stringW = ""
  55. for i = 1, w do
  56.   stringW = stringW .. " "
  57. end
  58.  
  59. local offset = 0
  60. function words(string, x, y, txtcol, bakcol)
  61.   if txtcol then
  62.     term.setTextColor(txtcol)
  63.   end
  64.   if bakcol then
  65.     term.setBackgroundColor(bakcol)
  66.   end
  67.   if not tonumber(x) and x then
  68.     if string.sub(x, 0, 1) == "l" then
  69.       if x == "l" or x == "left" then
  70.         term.setCursorPos(1, y)
  71.       elseif string.sub(x, 3, 3) == "+" or string.sub(x, 6, 6) == "+" then
  72.         offset = tonumber(string.sub(x, 5, 5)) or tonumber(string.sub(x, 8, 8))
  73.         term.setCursorPos(1 + offset, y)
  74.       end
  75.     elseif string.sub(x, 0, 1) == "c" then
  76.       if x == "center" or x == "c" then
  77.         term.setCursorPos(w / 2 - #string / 2 + 1, y)
  78.       elseif string.sub(x, 3, 3) == "+" or string.sub(x, 8, 8) == "+" then
  79.         offset = tonumber(string.sub(x, 5, 5)) or tonumber(string.sub(x, 10, 10))
  80.         term.setCursorPos(w / 2 - #string / 2 + 1 + offset, y)
  81.       elseif string.sub(x, 3, 3) == "-" or string.sub(x, 8, 8) == "-" then
  82.         offset = tonumber(string.sub(x, 5, 5)) or tonumber(string.sub(x, 10, 10))
  83.         term.setCursorPos(w / 2 - #string / 2 + 1 - offset, y)
  84.       end
  85.     elseif string.sub(x, 0, 1) == "r" then
  86.       if x == "right" or x == "r" then
  87.         term.setCursorPos(w - #string + 1, y)
  88.       elseif string.sub(x, 3, 3) == "-" or string.sub(x, 7, 7) == "-" then
  89.         offset = tonumber(string.sub(x, 5, 5)) or tonumber(string.sub(x, 9, 9))
  90.         term.setCursorPos(w - #string + 1 - offset, y)
  91.       end
  92.     end
  93.   else
  94.     term.setCursorPos(x, y)
  95.   end
  96.   term.write(string)
  97. end
  98.  
  99. function clickCheck(x, y, x2, y2)
  100.   if clicked[3] >= x and clicked[3] <= x2 and clicked[4] >= y and clicked[4] <= y2 then
  101.     return true
  102.   else
  103.     return false
  104.   end
  105. end
  106.  
  107. function resetTxtBak()
  108.   term.setBackgroundColor(colors.black)
  109.   term.setTextColor(colors.white)
  110. end
  111.  
  112. function initializeTop()
  113.   words(header, "c", 1)
  114.   term.setCursorPos(1, 2)
  115.   for i = 1, w do
  116.     term.write("-")
  117.   end
  118. end
  119.  
  120. header = "RecipeHub"
  121. local action = nil
  122. local finished = false
  123. local ended = false
  124. local initializedMain = false
  125. while not ended do      ------======MAIN======------
  126.   while not initializedMain do
  127.     resetTxtBak()
  128.     term.clear()
  129.     paintutils.drawImage(flameImg, 15, 1)
  130.     header = "RecipeHub"
  131.     initializeTop()
  132.     paintutils.drawImage(craftImg, 1, 1)
  133.     paintutils.drawImage(smeltImg, w - 9, 1)
  134.     resetTxtBak()
  135.     words("Add a Recipe", "l + 3", h - 1)
  136.     words("Use a Recipe", "r - 3", h - 1)
  137.     words("Begin", "c", h - 2)
  138.     initializedMain = true
  139.   end
  140.   clicked = {os.pullEvent("mouse_click")}
  141.   if clickCheck(1,1,5,5) then
  142.     shell.run("pastebin run 7NqDsTQx")
  143.   end
  144.   if clickCheck(4, h - 1, 15, h - 1) then
  145.     words("Add a Recipe", "l + 3", h - 1, colors.white, colors.blue)
  146.     words("Use a Recipe", "r - 3", h - 1, colors.white, colors.black)
  147.     action = "add"
  148.   end
  149.   if clickCheck(w - 14, h - 1, w - 3, h - 1) then
  150.     words("Add a Recipe", "l + 3", h - 1, colors.white, colors.black)
  151.     words("Use a Recipe", "r - 3", h - 1, colors.white, colors.blue)
  152.     action = "use"
  153.   end
  154.   if clickCheck(18, h - 2, 22, h - 2) then
  155.     if action then
  156.       words("Begin", "c", h - 2, colors.green, colors.black)
  157.       sleep(.1)
  158.       local finished = false
  159.       local subfinished = false
  160.       local stage = 1
  161.       local change = 0
  162.       local iName = nil
  163.       local data = nil
  164.       local newRecipe = {}
  165.       resetTxtBak()
  166.       term.clear()
  167.       if action == "add" then        ------======ADD======------
  168.         action = nil
  169.         header = "Add a Recipe"
  170.         initializeTop()
  171.         words("Stage " .. tostring(stage), "l", 3)
  172.         words("Craft", "l + 5", 5)
  173.         words("Smelt", "r - 5", 5)
  174.         words("Name: ", "l", 7)
  175.         words("Record", "l", 9)
  176.         words("Back", "r", 1, colors.white, colors.black)
  177.         while not finished do
  178.           clicked = {os.pullEvent("mouse_click")}
  179.           if clickCheck(6, 5, 10, 5) then
  180.             words("Craft", "l + 5", 5, colors.white, colors.brown)
  181.             words("Smelt", "r - 5", 5, colors.white, colors.black)
  182.             action = "Craft"
  183.           end
  184.           if clickCheck(w - 10, 5, w - 5, 5) then
  185.             words("Craft", "l + 5", 5, colors.white, colors.black)
  186.             words("Smelt", "r - 5", 5, colors.orange, colors.gray)
  187.             action = "Smelt"
  188.           end
  189.           if clickCheck(1, 7, 12, 7) then
  190.             words(stringW, 1, 7, colors.yellow, colors.lightGray)
  191.             words("Name:", 1, 7)
  192.             term.setCursorPos(7, 7)
  193.             iName = read()
  194.             words(stringW, 1, 7, colors.white, colors.black)
  195.             words("Name:", 1, 7)
  196.             words(iName, "l + 6", 7)
  197.           end
  198.           if clickCheck(w - 3, 1, w, 1) then
  199.             words("Back", "r", 1, colors.white, colors.red)
  200.             sleep(.2)
  201.             initializedMain = false
  202.             finished = true
  203.           else
  204.             words("Back", "r", 1, colors.white, colors.black)
  205.           end
  206.           if clickCheck(1, 9, 6, 9) then
  207.             words("Record", "l", 9, colors.green, colors.black)
  208.             if action and iName then
  209.               change = 0
  210.               for i = 1, 9 do
  211.                 turtle.select(i + change)
  212.                 data = nil
  213.                 data = turtle.getItemDetail(i + change)
  214.                 if data then
  215.                   newRecipe[i + change] = tostring(data.name)
  216.                 end
  217.                 if i == 3 then change = 1 end
  218.                 if i == 6 then change = 2 end
  219.               end
  220.               shell.run("cd recipes")
  221.               oTemp = fs.open("recipes/temp", "w")
  222.               for line in io.lines("recipes/list") do
  223.                 oTemp.writeLine(line)
  224.               end
  225.               os.loadAPI("recipes/list")
  226.               local num = #list.recipeslist + 1
  227.               oTemp.writeLine("recipeslist[" .. num .. "] = {}")
  228.               for i, v in pairs(newRecipe) do
  229.                 oTemp.writeLine("recipeslist[" .. num .. "][" .. i .. "] = \"" .. v .. "\"")
  230.               end
  231.               oTemp.writeLine("recipeslist[" .. num .. "][12] = \"" .. action .. "\"")
  232.               oTemp.writeLine("recipeslist[" .. num .. "][13] = \"" .. iName .. "\"")
  233.               oTemp.flush()
  234.               oTemp.close()
  235.               shell.run("delete list")
  236.               shell.run("copy temp list")
  237.               shell.run("delete temp")
  238.               shell.run("cd /")
  239.               words("Record", "l", 9, colors.white, colors.black)
  240.               words("New Recipe", "l + 2", h - 1, colors.white, colors.black)
  241.               words("New Stage", "c", h - 1)
  242.               words("Finished", "r - 2", h - 1)
  243.               subfinished = false
  244.               while not subfinished do
  245.                 clicked = {os.pullEvent("mouse_click")}
  246.                 if clickCheck(3, h - 1, 12, h - 1) then
  247.                   words("New Recipe", "l + 2", h - 1, colors.yellow, colors.black)
  248.                   sleep(.2)
  249.                   subfinished = true
  250.                 end
  251.                 if clickCheck(15, h - 1, 23, h - 1) then
  252.                   words("New Stage", "c", h - 1, colors.orange, colors.black)
  253.                   sleep(.2)
  254.                   subfinished = true
  255.                   stage = stage + 1
  256.                 end
  257.                 if clickCheck(w - 9, h - 1, w - 2, h - 1) then
  258.                   words("Finished", "r - 2", h - 1, colors.red, colors.black)
  259.                   sleep(.2)
  260.                   initializedMain = false
  261.                   subfinished = true
  262.                   finished = true
  263.                 end
  264.               end
  265.               resetTxtBak()
  266.               term.clear()
  267.               action = nil
  268.               header = "Add a Recipe"
  269.               initializeTop()
  270.               words("Stage " .. tostring(stage), "l", 3)
  271.               words("Craft", "l + 5", 5)
  272.               words("Smelt", "r - 5", 5)
  273.               words("Name: ", "l", 7)
  274.               words("Record", "l", 9)
  275.               words("Back", "r", 1, colors.white, colors.black)
  276.             else
  277.               for i = 1, 2 do
  278.                 words("Record", 1, 9, colors.red, colors.black)
  279.                 sleep(.1)
  280.                 words("Record", 1, 9, colors.white, colors.black)
  281.                 sleep(.1)
  282.               end
  283.             end  
  284.           end
  285.         end
  286.       elseif action == "use" then      ------======USE======------
  287.         action = nil
  288.         local recipelength = 0
  289.         local activeitems = 0
  290.         header = "Use a Recipe"
  291.         local active = nil
  292.         initializeTop()
  293.         words("Back", "r", 1, colors.white, colors.black)
  294.         os.loadAPI("recipes/list")
  295.         for i = 1, #list.recipeslist do
  296.           words(list.recipeslist[i][13], "l", i + 2, colors.white, colors.black)
  297.         end
  298.         while not finished do
  299.           clicked = {os.pullEvent("mouse_click")}
  300.           if active and clickCheck(w - 5, active + 2, w, active + 2) then
  301.             words(list.recipeslist[active][12] .. "ing...", "r", active + 2, colors.cyan, colors.white)
  302.             sleep(.2)
  303.             if list.recipeslist[active][12] == "Craft" then    ------======CRAFTING======------
  304.               shell.run("go left 2")
  305.               activeitems = 0
  306.               turtle.select(13)
  307.               while activeitems ~= recipelength - 2 and turtle.suckUp() do
  308.                 data = turtle.getItemDetail(13)
  309.                 recipelength = 0
  310.                 for i, v in pairs(list.recipeslist[active]) do
  311.                   recipelength = recipelength + 1
  312.                   if data.name == v then
  313.                     activeitems = activeitems + 1
  314.                     turtle.transferTo(i, 1)
  315.                   end
  316.                 end
  317.                 turtle.drop()
  318.               end
  319.               if activeitems == recipelength - 2 then
  320.                 turtle.select(4)
  321.                 turtle.craft(1)
  322.               end
  323.               turtle.select(1)
  324.               while turtle.suck() do
  325.                 turtle.dropUp()
  326.               end
  327.               for i = 1, 16 do
  328.                 turtle.select(i)
  329.                 turtle.dropUp()
  330.               end
  331.               shell.run("go left 2")
  332.             elseif list.recipeslist[active][12] == "Smelt" then          ------======SMELTING======------
  333.               shell.run("go left 2")
  334.               activeitems = 0
  335.               turtle.select(13)
  336.               while activeitems ~= 2 and turtle.suckUp() do
  337.                 data = turtle.getItemDetail(13)
  338.                 recipelength = 0
  339.                 for i, v in pairs(list.recipeslist[active]) do
  340.                   recipelength = recipelength + 1
  341.                   if data.name == v then
  342.                     activeitems = activeitems + 1
  343.                     turtle.transferTo(i, 1)
  344.                   end
  345.                   if data.name == "minecraft:planks" then
  346.                     turtle.transferTo(15)
  347.                   end
  348.                 end
  349.                 turtle.drop()
  350.               end
  351.               if activeitems == 2 then
  352.                 turtle.select(13)
  353.                 while turtle.suck() do
  354.                   turtle.dropUp()
  355.                 end
  356.                 shell.run("go left forward up forward")
  357.                 turtle.select(1)
  358.                 turtle.dropDown(1)
  359.                 shell.run("go back down 2 forward")
  360.                 turtle.select(15)
  361.                 turtle.dropUp(1)
  362.                 while not turtle.suckUp() do
  363.                   sleep(1)
  364.                 end
  365.                 shell.run("go back up back left")
  366.                 for i = 1, 16 do
  367.                   turtle.select(i)
  368.                   turtle.dropUp()
  369.                 end
  370.               end
  371.             end
  372.           end
  373.           active = nil
  374.           for i = 1, #list.recipeslist do
  375.             if clickCheck(1, i + 2, w, i + 2) then
  376.               if list.recipeslist[i][12] == "Craft" then
  377.                 term.setBackgroundColor(colors.brown)
  378.                 term.setTextColor(colors.white)
  379.               elseif list.recipeslist[i][12] == "Smelt" then
  380.                 term.setBackgroundColor(colors.gray)
  381.                 term.setTextColor(colors.orange)
  382.               end
  383.               active = i
  384.               words(stringW, 1, i + 2)
  385.               words(list.recipeslist[i][12], "r", i + 2)
  386.               words(list.recipeslist[i][13], "l", i + 2)
  387.             else
  388.               words(stringW, 1, i + 2, colors.white, colors.black)
  389.               words(list.recipeslist[i][13], "l", i + 2)
  390.             end
  391.           end
  392.           if clickCheck(w - 3, 1, w, 1) then
  393.             words("Back", "r", 1, colors.white, colors.red)
  394.             sleep(.2)
  395.             initializedMain = false
  396.             finished = true
  397.           else
  398.             words("Back", "r", 1, colors.white, colors.black)
  399.           end
  400.         end
  401.       end
  402.     else
  403.       for i = 1, 2 do
  404.         words("Begin", "c", h - 2, colors.red, colors.black)
  405.         sleep(.1)
  406.         words("Begin", "c", h - 2, colors.white, colors.black)
  407.         sleep(.1)
  408.       end
  409.     end
  410.   end
  411. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement