Leon_Lejon

CC OS 2 os/.settings

Jun 17th, 2024 (edited)
904
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local w,h = term.getSize()
  2.  
  3. --Center Text
  4.  
  5. function printCentered (y,s)
  6.     local x = math.floor((w - string.len(s)) /2)
  7.     term.setCursorPos(x,y)
  8.     term.clearLine()
  9.     term.write(s)
  10. end
  11.  
  12. --Drawmenu
  13.  
  14. local nOption = 1
  15.  
  16. local function drawMenu()
  17.     term.setBackgroundColor(colors.cyan)
  18.     term.clear()
  19.     term.setCursorPos(1,1)
  20.     local logo = paintutils.loadImage("os/.logo")
  21.     paintutils.drawImage(logo, 1, 1)
  22.     term.setBackgroundColor(colors.cyan)
  23.    
  24.     term.setCursorPos(w-11,1)
  25.     if nOption == 1 then
  26.         term.write("Reset account")
  27.     elseif nOption == 2 then
  28.         term.write("Exit")
  29.     else
  30.         end
  31. end    
  32.  
  33. --GUI
  34.  
  35. term.clear()
  36. local function drawFrontend()
  37.     printCentered(math.floor(h/2) -3, "")
  38.     printCentered(math.floor(h/2) -2, "SETTINGS")
  39.     printCentered(math.floor(h/2) -1, "")
  40.     printCentered(math.floor(h/2) + 0, (nOption == 1 and "[ Reset account ]") or "Reset account")
  41.     printCentered(math.floor(h/2) + 1, (nOption == 2 and "[ Exit ]") or "Exit")
  42. end
  43.  
  44. --Display
  45.  
  46. drawMenu()
  47. drawFrontend()
  48.  
  49. while true do
  50.     local e,p = os.pullEvent()
  51.         if e == "key" then
  52.             local key = p
  53.             if key == keys.up or key == 200 then
  54.            
  55.                 if nOption > 1 then
  56.                     nOption = nOption -1
  57.                     drawMenu()
  58.                     drawFrontend()
  59.                 end
  60.             elseif key == keys.down or key == 208 then
  61.                 if nOption < 2 then
  62.                     nOption = nOption +1
  63.                     drawMenu()
  64.                     drawFrontend()
  65.                 end
  66.         elseif key == keys.enter then
  67.             break
  68. end
  69. end
  70. end
  71.  
  72. term.clear()
  73.  
  74. --Conditions
  75. if nOption == 1 then
  76.     term.clear()
  77.     term.setCursorPos(1,1)
  78.     print("Are you sure? Password and username will be wiped and reset! y/n")
  79.     alt = read()
  80.     if alt == "y" then
  81.         shell.run("os/setup")    
  82.     elseif alt == "n" then
  83.         print("Reset Aborted")
  84.         sleep(3)
  85.         shell.run("os/.functions")
  86.     end
  87. else
  88.     shell.run("os/.functions")
  89. end
Advertisement
Add Comment
Please, Sign In to add comment