Advertisement
Theshadow989

[xOS] Main Menu

Dec 20th, 2015
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.69 KB | None | 0 0
  1. --[[
  2. Main Menu File
  3. Written by TheShadow989
  4. ]]--
  5.  
  6. os.pullEvent = os.pullEventRaw
  7.  
  8. local verNumber = "Alpha 1.24"
  9. local nOption = 1
  10.  
  11. rRead = fs.open("xos/.usertable", "r")
  12. users = textutils.unserialize(rRead.readAll())
  13. rRead.close()
  14. cu = tonumber(users[1])
  15. cs = tonumber(users[cu+1])
  16.  
  17. local w,h = term.getSize()
  18.  
  19. local function drawMenu()
  20.         local time = os.time()
  21.         local formattedTime = textutils.formatTime(time, false)
  22.  
  23.         term.clear()
  24.         term.setCursorPos(1,1)
  25.         term.write("Logged in as: ")
  26.         term.setTextColor( colors.red )
  27.         term.write(""..users[cu].."")
  28.         term.setTextColor( colors.white )
  29.         term.setCursorPos(1,2)
  30.         write(formattedTime)
  31.         term.setCursorPos(1,19)
  32.         term.write("xOS "..verNumber.." by TheShadow989")
  33.        
  34.         term.setCursorPos(w-11,1)
  35.         if nOption == 1 then
  36.            term.write("Command ")
  37.         elseif nOption == 2 then
  38.            term.write("Programs")
  39.         elseif nOption == 3 then
  40.            term.write("Accounts")
  41.         elseif nOption == 4 then
  42.            term.write("Details")
  43.         elseif nOption == 5 then
  44.            term.write("Shutdown")
  45.         else
  46.         end
  47. end
  48.  
  49. function printCentered(y,s)
  50.         local x = math.floor((w - string.len(s)) / 2)
  51.         term.setCursorPos(x,y)
  52.         term.clearLine()
  53.         term.write( s )
  54. end
  55.  
  56. term.clear()
  57.  
  58. local function drawFrontend()
  59.    printCentered( math.floor(h/2) - 4, "")
  60.    printCentered( math.floor(h/2) - 3, "Start Menu" )
  61.    printCentered( math.floor(h/2) - 2, "")
  62.    printCentered( math.floor(h/2) - 1, ((nOption == 1) and "[ Command  ]") or "Command " )
  63.    printCentered( math.floor(h/2) + 0, ((nOption == 2) and "[ Programs ]") or "Programs" )
  64.    printCentered( math.floor(h/2) + 1, ((nOption == 3) and "[ Accounts ]") or "Accounts" )
  65.    printCentered( math.floor(h/2) + 2, ((nOption == 4) and "[ Details  ]") or "Details " )
  66.    printCentered( math.floor(h/2) + 3, ((nOption == 5) and "[ Shutdown ]") or "Shutdown" )
  67.    printCentered( math.floor(h/2) + 4, "")
  68. end
  69.  
  70. drawMenu()
  71. drawFrontend()
  72.  
  73. while true do
  74.     local e,p = os.pullEvent()
  75.     if e == "key" then
  76.         local key = p
  77.         if key == 17 or key == 200 then
  78.             if nOption > 1 then
  79.                 nOption = nOption - 1
  80.                 drawMenu()
  81.                 drawFrontend()
  82.             end
  83.         elseif key == 31 or key == 208 then
  84.             if nOption < 5 then
  85.                 nOption = nOption + 1
  86.                 drawMenu()
  87.                 drawFrontend()
  88.             end
  89.         elseif key == 28 then
  90.             break
  91.         end
  92.     end
  93. end
  94. term.clear()
  95.  
  96. if nOption  == 1 then
  97.     shell.run("xos/.command")
  98. elseif nOption == 2 then
  99.     shell.run("xos/.programs")
  100. elseif nOption == 3 then
  101.     shell.run("xos/.accounts")
  102. elseif nOption == 4 then
  103.     shell.run("xos/.details")
  104. else
  105.     os.shutdown()
  106. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement