PigNationAU

.menu

Jul 17th, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2.  
  3. local w,h = term.getSize()
  4. function printCentered (y,s)
  5. local x = math.floor((w - string.len(s) /2))
  6. term.setCursorPos(x.y)
  7. term.clearLine()
  8. term.write(s)
  9. end
  10.  
  11. local nOption = 1
  12.  
  13. local function drawMenu()
  14. term.clear()
  15. term.setCursorPos(1,1)
  16. term.write("PigNet V1")
  17.  
  18. term.setCursorPos(w-11,1)
  19. if nOption == 1 then
  20. term.write("Command")
  21. elseif nOption == 2 then
  22. term.write("Programs")
  23. elseif nOption == 3 then
  24. term.write("Shutdown")
  25. elseif nOption == 4 then
  26. term.write("Uninstall")
  27. else
  28. end
  29. end
  30.  
  31. term.clear
  32. local function drawFrontend()
  33. printCentered(math.floor(h/2) - 3, "")
  34. printCentered(math.floor(h/2) - 2, "Start Menu"
  35. printCentered(math.floor(h/2) - 1, ""
  36. printCentered(math.floor(h/2) + 0, ((nOption == 1) and "[ Command ]") or "Command"
  37. printCentered(math.floor(h/2) + 1, ((nOption == 2)and "[ Programs ]") or "Programs"
  38. printCentered(math.floor(h/2) + 2, ((nOption == 3) and "[ Shutdown ]") or "Shutdown"
  39. printCentered(math.floor(h/2) + 3, ((nOption == 4)and "[ Uninstall]") or "Uninstall"
  40. end
  41.  
  42.  
  43. Menu()
  44. drawFrontend()
  45.  
  46. while true do
  47. local e,p = os.pullEvent()
  48. if e == "key" then
  49. local key == p
  50. if key == 17 or key == 200 then
  51.  
  52. if nOption > 1 then
  53. nOption = nOPtion - 1
  54. drawMenu()
  55. drawFrontend()
  56. end
  57. elseif key == 31 or key == 208 then
  58. if nOption < 4 then
  59. nOption = nOption + 1
  60. drawMenu()
  61. drawFrontend()
  62. end
  63. end
  64. elseif key == 28 then
  65. break
  66. end
  67. end
  68. end
  69. end
  70. term.clear
  71.  
  72. --conditions
  73. if nOption == 1 then
  74. shell.run("os/.command")
  75. elseif Noption == 2 then
  76. shell.run("os/.programs")
  77. elseif nOption == 3 then
  78. os.shutdown()
  79. else
  80. shell.run("os/.uninstall")
  81. end
Advertisement
Add Comment
Please, Sign In to add comment