Advertisement
Guest User

recipe

a guest
May 27th, 2015
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.18 KB | None | 0 0
  1. local w, h = term.getSize()
  2. term.setBackgroundColor(colors.black)
  3. term.clear()
  4.  
  5. local offset = 0
  6. function words(string, x, y, txtcol, bakcol)
  7.   if txtcol then
  8.     term.setTextColor(txtcol)
  9.   end
  10.   if bakcol then
  11.     term.setBackgroundColor(bakcol)
  12.   end
  13.   if not tonumber(x) then
  14.     if string.sub(x, 0, 1) == "l" then
  15.       if x == "l" or x == "left" then
  16.         term.setCursorPos(1, y)
  17.       elseif string.sub(x, 3, 3) == "+" or string.sub(x, 6, 6) == "+" then
  18.         offset = tonumber(string.sub(x, 5, 5)) or tonumber(string.sub(x, 8, 8))
  19.         term.setCursorPos(1 + offset, y)
  20.       end
  21.     elseif string.sub(x, 0, 1) == "c" then
  22.       if x == "center" or x == "c" then
  23.         term.setCursorPos(w / 2 - #string / 2 + 1, y)
  24.       elseif string.sub(x, 3, 3) == "+" or string.sub(x, 8, 8) == "+" then
  25.         offset = tonumber(string.sub(x, 5, 5)) or tonumber(string.sub(x, 10, 10))
  26.         term.setCursorPos(w / 2 - #string / 2 + 1 + offset, y)
  27.       elseif string.sub(x, 3, 3) == "-" or string.sub(x, 8, 8) == "-" then
  28.         offset = tonumber(string.sub(x, 5, 5)) or tonumber(string.sub(x, 10, 10))
  29.         term.setCursorPos(w / 2 - #string / 2 + 1 - offset, y)
  30.       end
  31.     elseif string.sub(x, 0, 1) == "r" then
  32.       if x == "right" or x == "r" then
  33.         term.setCursorPos(w - #string + 1, y)
  34.       elseif string.sub(x, 3, 3) == "-" or string.sub(x, 7, 7) == "-" then
  35.         offset = tonumber(string.sub(x, 5, 5)) or tonumber(string.sub(x, 9, 9))
  36.         term.setCursorPos(w - #string + 1 - offset, y)
  37.       end
  38.     end
  39.   else
  40.     term.setCursorPos(x, y)
  41.   end
  42.   term.write(string)
  43. end
  44.  
  45. function clickCheck(x, y, x2, y2)
  46.   if clicked[3] >= x and clicked[3] <= x2 and clicked[4] >= y and clicked[4] <= y2 then
  47.     return true
  48.   else
  49.     return false
  50.   end
  51. end
  52.  
  53. function resetTxtBak()
  54.   term.setBackgroundColor(colors.black)
  55.   term.setTextColor(colors.white)
  56. end
  57.  
  58. local header = "Recipe Hub"
  59. function initializeTop()
  60.   words(header, "c", 1)
  61.   term.setCursorPos(1, 2)
  62.   for i = 1, w do
  63.     term.write("-")
  64.   end
  65. end
  66. initializeTop()
  67. words("Add a Recipe", "l + 3", 3)
  68. words("Use a Recipe", "r - 3", 3)
  69. words("Begin", "c", 4)
  70.  
  71. local action = nil
  72. local finished = false
  73. while not finished do
  74.   clicked = {os.pullEvent("mouse_click")}
  75.   if clickCheck(4, 3, 15, 3) then
  76.     words("Add a Recipe", "l + 3", 3, colors.white, colors.blue)
  77.     words("Use a Recipe", "r - 3", 3, colors.white, colors.black)
  78.     action = "add"
  79.   end
  80.   if clickCheck(w - 14, 3, w - 3, 3) then
  81.     words("Add a Recipe", "l + 3", 3, colors.white, colors.black)
  82.     words("Use a Recipe", "r - 3", 3, colors.white, colors.blue)
  83.     action = "use"
  84.   end
  85.   if clickCheck(18, 4, 22, 4) then
  86.     if action then
  87.       words("Begin", "c", 4, colors.green, colors.black)
  88.       sleep(.1)
  89.       finished = true
  90.     else
  91.       for i = 1, 2 do
  92.         words("Begin", "c", 4, colors.red, colors.black)
  93.         sleep(.1)
  94.         words("Begin", "c", 4, colors.white, colors.black)
  95.         sleep(.1)
  96.       end
  97.     end
  98.   end
  99. end
  100.  
  101. local finished = false
  102. local stage = 1
  103. local change = 0
  104. local data = nil
  105. local newRecipe = {}
  106. resetTxtBak()
  107. term.clear()
  108. if action == "add" then
  109.   action = nil
  110.   header = "Add a Recipe"
  111.   initializeTop()
  112.   words("Stage " .. tostring(stage), "l", 3)
  113.   words("Craft", "l + 5", 5)
  114.   words("Smelt", "r - 5", 5)
  115.   words("Record", "l", 7)
  116.   while not finished do
  117.     clicked = {os.pullEvent("mouse_click")}
  118.     if clickCheck(6, 5, 10, 5) then
  119.       words("Craft", "l + 5", 5, colors.white, colors.brown)
  120.       words("Smelt", "r - 5", 5, colors.white, colors.black)
  121.       action = "craft"
  122.     end
  123.     if clickCheck(w - 10, 5, w - 5, 5) then
  124.       words("Craft", "l + 5", 5, colors.white, colors.black)
  125.       words("Smelt", "r - 5", 5, colors.orange, colors.gray)
  126.       action = "smelt"
  127.     end
  128.     if clickCheck(1, 7, 6, 7) then
  129.       words("Record", "l", 7, colors.green, colors.black)
  130.       if action then
  131.         local change = 0
  132.         for i = 1, 9 do
  133.           turtle.select(i + change)
  134.           data = turtle.getItemDetail(i + change)
  135.           if data then
  136.             newRecipe[i] = tostring(data.name)
  137.           end
  138.           if i == 3 then change = 1 end
  139.           if i == 6 then change = 2 end
  140.         end
  141.         shell.run("cd recipes")
  142.         oTemp = fs.open("recipes/temp", "w")
  143.         for line in io.lines("recipes/list") do
  144.           oTemp.writeLine(line)
  145.         end
  146.         os.loadAPI("recipes/list")
  147.         local num = #list.recipeslist + 1
  148.         oTemp.writeLine("recipeslist[" .. num .. "] = {}")
  149.         for i, v in pairs(newRecipe) do
  150.           oTemp.writeLine("recipeslist[" .. num .. "][" .. i .. "] = " .. v)
  151.         end
  152.         oTemp.flush()
  153.         oTemp.close()
  154.         shell.run("delete list")
  155.         shell.run("copy temp list")
  156.         shell.run("delete temp")
  157.         shell.run("cd /")
  158.       else
  159.         for i = 1, 2 do
  160.           words("Record", 1, 5, colors.red, colors.black)
  161.           sleep(.1)
  162.           words("Record", 1, 5, colors.white, colors.black)
  163.           sleep(.1)
  164.         end
  165.       end  
  166.     end
  167.   end
  168. elseif action == "use" then
  169.   action = nil
  170.   header = "Use a Recipe"
  171.   initializeTop()
  172.  
  173. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement