ICECreeper

Codedoor Setup

May 3rd, 2022 (edited)
1,122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.79 KB | None | 0 0
  1. -- SECONDARY
  2. step = 1
  3. keyc_allowed = true
  4. keyb_allowed = true
  5. keyn_allowed = true
  6.  
  7. function centerText(text)
  8.     local x,y = term.getSize()
  9.     local x2,y2 = term.getCursorPos()
  10.     term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  11.     write(text)
  12. end
  13. function writeMainScreen(clr, tittle, p1, p2a, p2b, drawNav)
  14.     term.clear()
  15.     paintutils.drawFilledBox(1, 1, 51, 3, clr)
  16.     term.setCursorPos(2, 2)
  17.     term.setTextColor(colors.white)
  18.     write(tittle)
  19.     term.setBackgroundColor(colors.white)
  20.     term.setTextColor(colors.gray)
  21.     paintutils.drawFilledBox(1, 4, 51, 19, colors.white)
  22.     term.setCursorPos(3, 6)
  23.     write(p1)
  24.     term.setCursorPos(3, 8)
  25.     write(p2a)
  26.     term.setCursorPos(3, 9)
  27.     write(p2b)
  28.     term.setCursorPos(1, 18)
  29.     term.setTextColor(colors.lightGray)
  30.     if drawNav == "full" then
  31.         centerText("[C] - Cancel      [B] - Back      [N] - Next")
  32.         keyc_allowed = true
  33.         keyb_allowed = true
  34.         keyn_allowed = true
  35.     end
  36.     if drawNav == "install" then
  37.         centerText("[C] - Cancel      [B] - Back      [N] - Install")
  38.         keyc_allowed = true
  39.         keyb_allowed = true
  40.         keyn_allowed = true
  41.     end
  42.     if drawNav == "cn" then
  43.         centerText("[C] - Cancel      [N] - Next")
  44.         keyc_allowed = true
  45.         keyb_allowed = false
  46.         keyn_allowed = true
  47.     end
  48.     if drawNav == "no" then
  49.         keyc_allowed = false
  50.         keyb_allowed = false
  51.         keyn_allowed = false
  52.     end
  53. end
  54. function writeSettingsScreen(clr, tittle, p1, drawNav)
  55.     term.clear()
  56.     paintutils.drawFilledBox(1, 1, 51, 3, clr)
  57.     term.setCursorPos(2, 2)
  58.     term.setTextColor(colors.white)
  59.     write(tittle)
  60.     term.setBackgroundColor(colors.white)
  61.     term.setTextColor(colors.gray)
  62.     paintutils.drawFilledBox(1, 4, 51, 19, colors.white)
  63.     term.setCursorPos(3, 6)
  64.     write(p1)
  65.     sleep(0.05)
  66.     term.setTextColor(colors.lightGray)
  67.     term.setCursorPos(8, 8)
  68.     write("Password: ")
  69.     term.setCursorPos(3, 10)
  70.     write("Redstone side: ")
  71.     term.setCursorPos(5, 12)
  72.     write("Opened time: ")
  73.     term.setTextColor(colors.gray)
  74.     term.setCursorPos(8, 8)
  75.     write("Password: ")
  76.     term.setTextColor(colors.black)
  77.     password = read("*")
  78.     term.setCursorPos(3, 10)
  79.     term.setTextColor(colors.gray)
  80.     write("Redstone side: ")
  81.     term.setTextColor(colors.black)
  82.     redside = read()
  83.     term.setCursorPos(5, 12)
  84.     term.setTextColor(colors.gray)
  85.     write("Opened time: ")
  86.     term.setTextColor(colors.black)
  87.     opentime = read()
  88.     term.setCursorPos(1, 18)
  89.     term.setTextColor(colors.lightGray)
  90.     if drawNav == "full" then
  91.         centerText("[C] - Cancel      [B] - Back      [N] - Next")
  92.         keyc_allowed = true
  93.         keyb_allowed = true
  94.         keyn_allowed = true
  95.     end
  96.     if drawNav == "cn" then
  97.         centerText("[C] - Cancel      [N] - Next")
  98.         keyc_allowed = true
  99.         keyb_allowed = false
  100.         keyn_allowed = true
  101.     end
  102.     if drawNav == "no" then
  103.         keyc_allowed = false
  104.         keyb_allowed = false
  105.         keyn_allowed = false
  106.     end
  107. end
  108. function writeErrorScreen(clr, tittle, p1a, p1b, drawNav)
  109.     is_error = true
  110.     term.clear()
  111.     paintutils.drawFilledBox(1, 1, 51, 3, clr)
  112.     term.setCursorPos(2, 2)
  113.     term.setTextColor(colors.white)
  114.     write(tittle)
  115.     term.setBackgroundColor(colors.white)
  116.     term.setTextColor(colors.gray)
  117.     paintutils.drawFilledBox(1, 4, 51, 19, colors.white)
  118.     term.setCursorPos(3, 6)
  119.     write(p1a)
  120.     term.setCursorPos(3, 7)
  121.     write(p1b)
  122.     term.setCursorPos(1, 18)
  123.     term.setTextColor(colors.lightGray)
  124.     if drawNav == "full" then
  125.         centerText("[C] - Cancel      [B] - Correct")
  126.         keyc_allowed = true
  127.         keyb_allowed = true
  128.         keyn_allowed = false
  129.     end
  130.     if drawNav == "no" then
  131.         keyc_allowed = false
  132.         keyb_allowed = false
  133.         keyn_allowed = false
  134.     end
  135. end
  136. function writeInstallScreen(clr, tittle, p1, drawNav)
  137.     term.clear()
  138.     paintutils.drawFilledBox(1, 1, 51, 3, clr)
  139.     term.setCursorPos(2, 2)
  140.     term.setTextColor(colors.white)
  141.     write(tittle)
  142.     term.setBackgroundColor(colors.white)
  143.     term.setTextColor(colors.gray)
  144.     paintutils.drawFilledBox(1, 4, 51, 19, colors.white)
  145.     term.setCursorPos(3, 6)
  146.     write(p1)
  147.     term.setCursorPos(1, 18)
  148.     term.setTextColor(colors.lightGray)
  149.     if drawNav == "full" then
  150.         centerText("[C] - Cancel")
  151.         keyc_allowed = true
  152.         keyb_allowed = false
  153.         keyn_allowed = false
  154.     end
  155.     if drawNav == "no" then
  156.         keyc_allowed = false
  157.         keyb_allowed = false
  158.         keyn_allowed = false
  159.     end
  160.     term.setCursorPos(3, 8)
  161.     term.setTextColor(colors.gray)
  162.     write("Downloading Codedoor...")
  163.     term.setTextColor(colors.white)
  164.     shell.run("pastebin", "get", "QXkP84KA", "startup.lua")
  165.     sleep(3)
  166.     term.setCursorPos(3, 8)
  167.     term.setTextColor(colors.gray)
  168.     write("Configuring Codedoor...")
  169.     setts = fs.open("/cdsettings.cfg", "w")
  170.     setts.writeLine(password)
  171.     setts.writeLine(redside)
  172.     setts.writeLine(opentime)
  173.     setts.close()
  174.     sleep(2)
  175.     step = step + 1
  176. end
  177. function writeFinishScreen(clr, tittle, p1a, p1b, p2a, p2b, drawNav)
  178.     finished = true
  179.     term.clear()
  180.     paintutils.drawFilledBox(1, 1, 51, 3, clr)
  181.     term.setCursorPos(2, 2)
  182.     term.setTextColor(colors.white)
  183.     write(tittle)
  184.     term.setBackgroundColor(colors.white)
  185.     term.setTextColor(colors.gray)
  186.     paintutils.drawFilledBox(1, 4, 51, 19, colors.white)
  187.     term.setCursorPos(3, 6)
  188.     write(p1a)
  189.     term.setCursorPos(3, 7)
  190.     write(p1b)
  191.     term.setCursorPos(3, 9)
  192.     write(p2a)
  193.     term.setCursorPos(3, 10)
  194.     write(p2b)
  195.     term.setCursorPos(1, 18)
  196.     term.setTextColor(colors.lightGray)
  197.     if drawNav == "full" then
  198.         centerText("[N] - Reboot")
  199.         keyc_allowed = false
  200.         keyb_allowed = false
  201.         keyn_allowed = true
  202.     end
  203.     if drawNav == "no" then
  204.         keyc_allowed = false
  205.         keyb_allowed = false
  206.         keyn_allowed = false
  207.     end
  208. end
  209.  
  210. -- MAIN PROGRAMM
  211. while true do
  212.     if step < 1 then
  213.         step = 1
  214.     end
  215.     if step > 5 then
  216.         step = 5
  217.     end
  218.     if is_error ~= true then
  219.         if step == 1 then
  220.             writeMainScreen(colors.blue, "Codedoor Installation Wizard", "Welcome to Codedoor Installation Wizard!", "This program will install Codedoor on your", "computer.", "cn")
  221.         end
  222.         if step == 2 then
  223.             writeSettingsScreen(colors.blue, "Codedoor Installation Wizard", "Let's configure your Codedoor!", "full")
  224.         end
  225.         if step == 3 then
  226.             writeMainScreen(colors.blue, "Codedoor Installation Wizard", "Everything is ready for installation!", "Press [N] when you are ready to install", "Codedoor on your computer.", "install")
  227.         end
  228.         if step == 4 then
  229.             writeInstallScreen(colors.cyan, "Codedoor Installation Wizard", "Installing Codedoor on your computer...", "no")
  230.         end
  231.         if step == 5 then
  232.             writeFinishScreen(colors.green, "Codedoor Installation Wizard", "Codedoor successfully installed on your", "computer.", "Press [N] to reboot your computer and start", "using app.", "full")
  233.         end
  234.     end
  235.  
  236.     while true do
  237.         local event, key = os.pullEvent( "key" )
  238.         if (key == keys.c) and (keyc_allowed == true) then
  239.             writeMainScreen(colors.red, "Codedoor Installation Wizard", "Installation canceled.", "Rebooting system...", "", "no")
  240.             sleep(2)
  241.             os.reboot()
  242.         end
  243.         if (key == keys.b) and (keyb_allowed == true) then
  244.             if is_error ~= true then
  245.                 step = step - 1
  246.             else
  247.                 is_error = false
  248.             end
  249.             break
  250.         end
  251.         if (key == keys.n) and (keyn_allowed == true) then
  252.             if finished ~= true then
  253.                 if step ~= 2 then
  254.                     step = step + 1
  255.                 else
  256.                     if password ~= "" then
  257.                         if (redside == "left") or (redside == "right") or (redside == "back") or (redside == "front") or (redside == "top") or (redside == "bottom") then
  258.                             if type(tonumber(opentime)) == "number" then
  259.                                 step = step + 1
  260.                             else
  261.                                 writeErrorScreen(colors.orange, "Codedoor Installation Wizard", "Error: Opened time isn't number.", "", "full")
  262.                             end
  263.                         else
  264.                             writeErrorScreen(colors.orange, "Codedoor Installation Wizard", "Error: Side specified incorrectly.", "(Can: left, right, back, front, top, bottom)", "full")
  265.                         end
  266.                     else
  267.                         writeErrorScreen(colors.orange, "Codedoor Installation Wizard", "Error: Password not set.", "", "full")
  268.                     end
  269.                 end
  270.             else
  271.                 os.reboot()
  272.             end
  273.             break
  274.         end
  275.     end
  276. end
Advertisement
Add Comment
Please, Sign In to add comment