AdventurousMR

.screens

Dec 29th, 2020 (edited)
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.06 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2.  
  3. local w,h = term.getSize()
  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. function printRight(y,s)
  13.     local x = math.floor((w - string.len(s)) / 2)
  14.     term.setCursorPos(x , y)
  15.     term.clearLine()
  16.     term.write(s)
  17. end
  18.  
  19. function printLeft (y,s)
  20.     local x = math.floor((w - string.len(s)) / 2)
  21.     term.setCursorPos(x - 18 , y)
  22.     term.clearLine()
  23.     term.write(s)
  24. end
  25.  
  26. local nOption = 1
  27.  
  28. local function drawMenu()
  29.     term.clear()
  30.     term.setCursorPos(1,1)
  31.     term.write("Atlantica OS v1.1")
  32. end
  33.  
  34.  
  35.  
  36. term.clear()
  37. local function drawFrontend()
  38.         printCentered(math.floor(h/2) - 3, "")
  39.     printCentered(math.floor(h/2) - 2, "Screens")
  40.         printCentered(math.floor(h/2) - 1, "")
  41.     printCentered(math.floor(h/2) + 0, ((nOption == 1) and "[ Main Screens ]") or "Main Screens" )
  42.         printCentered(math.floor(h/2) + 1, "")
  43.     printCentered(math.floor(h/2) + 2, ((nOption == 2) and "[ Path Screen ]") or "Path Screen" )
  44.         printCentered(math.floor(h/2) + 3, "")
  45.     printCentered(math.floor(h/2) + 4, ((nOption == 3) and "[ Back ]") or "Back" )
  46. end
  47.  
  48. drawMenu()
  49. drawFrontend()
  50.  
  51. while true do
  52.     local e,p = os.pullEvent()
  53.         if e == "key" then
  54.             local key = p
  55.             if  key == 17 or key == 200 then
  56.                
  57.                 if nOption > 1 then
  58.                     nOption = nOption -1
  59.                     drawMenu()
  60.                     drawFrontend()
  61.                     end
  62.                 elseif key == 31 or key == 208 then
  63.                     if nOption < 3 then
  64.                     nOption = nOption + 1
  65.                     drawMenu()
  66.                     drawFrontend()
  67.                     end
  68.  
  69.             elseif key == 28 then
  70.                 break
  71.                 end
  72.             end
  73.         end
  74. term.clear()
  75.  
  76. if nOption == 1 then
  77.     shell.run(".msg")
  78. elseif nOption == 2 then
  79.     shell.run(".Test")
  80. else
  81.     shell.run(".programs")
  82. end
Advertisement
Add Comment
Please, Sign In to add comment