Advertisement
Leon_Lejon

CC OS 2 os/.functions

May 17th, 2024 (edited)
683
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("DOS")
  27.     elseif nOption == 2 then
  28.         term.write("EXECUTIVE")
  29.     elseif nOption == 3 then
  30.         term.write("SHUTDOWN")
  31.     elseif nOption == 4 then
  32.         term.write("DISK")
  33.     elseif nOption == 5 then
  34.         term.write("SETTINGS")
  35.     else
  36.         end
  37. end    
  38.  
  39. --GUI
  40.  
  41. term.clear()
  42. local function drawFrontend()
  43.     printCentered(math.floor(h/2) -3, "")
  44.     printCentered(math.floor(h/2) -2, "START")
  45.     printCentered(math.floor(h/2) -1, "")
  46.     printCentered(math.floor(h/2) + 0, (nOption == 1 and "[ DOS ]") or "DOS")
  47.     printCentered(math.floor(h/2) + 1, (nOption == 2 and "[ EXECUTIVE ]") or "EXECUTIVE")
  48.     printCentered(math.floor(h/2) + 2, (nOption == 3 and "[ SHUTDOWN ]") or "SHUTDOWN")
  49.     printCentered(math.floor(h/2) + 3, (nOption == 4 and "[ DISK ]") or "DISK")
  50.     printCentered(math.floor(h/2) + 4, (nOption == 5 and "[ SETTINGS ]") or "SETTINGS")
  51. end
  52.  
  53. --Display
  54.  
  55. drawMenu()
  56. drawFrontend()
  57.  
  58. while true do
  59.     local e,p = os.pullEvent()
  60.         if e == "key" then
  61.             local key = p
  62.             if key == 17 or key == 200 then
  63.            
  64.                 if nOption > 1 then
  65.                     nOption = nOption -1
  66.                     drawMenu()
  67.                     drawFrontend()
  68.                 end
  69.             elseif key == 31 or key == 208 then
  70.                 if nOption < 5 then
  71.                     nOption = nOption +1
  72.                     drawMenu()
  73.                     drawFrontend()
  74.                 end
  75.         elseif key == 28 then
  76.             break
  77. end
  78. end
  79. end
  80.  
  81. term.clear()
  82.  
  83. --Conditions
  84. if nOption == 1 then
  85.     term.setBackgroundColor(colors.black)
  86.     shell.run("os/.DOS")
  87. elseif nOption == 2 then
  88.     shell.run("os/.EXECUTIVE")
  89. elseif nOption == 3 then
  90.     shell.run("os/.SHUTDOWN")
  91. elseif nOption == 4 then
  92.     term.setBackgroundColor(colors.black)
  93.     term.clear()
  94.     term.setCursorPos(1,1)
  95.     print("You are now in DOS mode. Write 'back' to return to interface")
  96.     print("---------------------------------------------------")
  97.     shell.run("chkdisk")
  98. else
  99.     shell.run("os/.settings")
  100. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement