RobotBubble

NewMenu

Oct 31st, 2017
59
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. local nOption = 1
  13.  
  14. local function drawMenu()
  15. term.clear()
  16. term.setCursorPos(1,1)
  17. term.write("BBC V6.3")
  18. term.setCursorPos(1,2)
  19.  
  20. term.setCursorPos(w-11,1)
  21. if nOption == 1 then
  22. term.write("TurtleMenu")
  23. elseif nOption == 2 then
  24. term.write("Chat")
  25. elseif nOption == 3 then
  26. term.write("Calculator")
  27. elseif nOption == 4 then
  28. term.write("Notes")
  29. elseif nOption == 5 then
  30. term.write("Games")
  31. elseif nOption == 6 then
  32. term.write("Options")
  33. elseif nOption == 7 then
  34. term.write("Reboot")
  35. elseif nOption == 8 then
  36. term.write("Shutdown")
  37. else
  38. end
  39.  
  40. end
  41.  
  42. --GUI
  43. term.clear()
  44. local function drawFrontend()
  45. printCentered( math.floor(h/2) - 3, "")
  46. printCentered( math.floor(h/2) - 2, "" )
  47. printCentered( math.floor(h/2) - 1, "")
  48. printCentered( math.floor(h/2) + 0, ((nOption == 1) and "[ TurtleMenu ]") or "TurtleMenu" )
  49. printCentered( math.floor(h/2) + 1, ((nOption == 2) and "[ Chat ]") or "Chat" )
  50. printCentered( math.floor(h/2) + 2, ((nOption == 3) and "[ Calculator ]") or "Calculator" )
  51. printCentered( math.floor(h/2) + 3, ((nOption == 4) and "[ Notes ]") or "Notes" )
  52. printCentered( math.floor(h/2) + 4, ((nOption == 5) and "[ Games ]") or "Games" )
  53. printCentered( math.floor(h/2) + 5, ((nOption == 6) and "[ Options ]") or "Options" )
  54. printCentered( math.floor(h/2) + 6, ((nOption == 7) and "[ Reboot ]") or "Reboot" )
  55. printCentered( math.floor(h/2) + 7, ((nOption == 8) and "[ Shutdown ]") or "Shutdown" )
  56. end
  57.  
  58. --Display
  59. drawMenu()
  60. drawFrontend()
  61.  
  62. while true do
  63. local e,p = os.pullEvent()
  64. if e == "key" then
  65. local key = p
  66. if key == 17 or key == 200 then
  67.  
  68. if nOption > 1 then
  69. nOption = nOption - 1
  70. drawMenu()
  71. drawFrontend()
  72. end
  73. elseif key == 31 or key == 208 then
  74. if nOption < 4 then
  75. nOption = nOption + 1
  76. drawMenu()
  77. drawFrontend()
  78. end
  79. elseif key == 28 then
  80. --End should not be here!!
  81. break
  82. end --End should be here!!
  83. end
  84. end
  85. term.clear()
  86.  
  87. --Conditions
  88. if nOption == 1 then
  89. shell.run("turtlemenu")
  90. elseif nOption == 2 then
  91. shell.run("chat")
  92. elseif nOption == 3 then
  93. shell.run("calculator")
  94. elseif nOption == 4 then
  95. shell.run("notes")
  96. elseif nOption == 5 then
  97. shell.run("games")
  98. elseif nOption == 6 then
  99. shell.run("options")
  100. elseif nOption == 7 then
  101. os.reboot()
  102. elseif nOption == 8 then
  103. os.shutdown()
  104. else
  105. shell.run("menu")
  106. end
RAW Paste Data Copied