Advertisement
Guest User

Untitled

a guest
Jan 25th, 2015
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. local w,h = term.getSize()
  2.  
  3. function printCentred( y, s )
  4. local x = math.floor((w - string.len(s)) / 2)
  5. term.setCursorPos(x,y)
  6. term.clearLine()
  7. term.write( s )
  8. end
  9.  
  10. local nOption = 1
  11.  
  12. -- Display menu
  13. local function drawMenu()
  14. term.clear()
  15. term.setCursorPos(1,1)
  16. term.write( "Wok's Nuclear Reactor Control" )
  17.  
  18. term.setCursorPos(w-11,1)
  19. if nOption == 1 then
  20. term.write( "1" )
  21. elseif nOption == 2 then
  22. term.write( "2" )
  23. else
  24. term.write( "3" )
  25. end
  26. sleep(0)
  27. end
  28.  
  29. -- Display the frontend
  30. term.clear()
  31. local function drawFrontend()
  32. printCentred( math.floor(h/2) - 3, "" )
  33. printCentred( math.floor(h/2) - 2, "SELECT AN OPTION" )
  34. printCentred( math.floor(h/2) - 1, "" )
  35. printCentred( math.floor(h/2) + 0, ((nOption == 1) and "[ Bring Reactors Online ]") or "Bring Reactors Online" )
  36. printCentred( math.floor(h/2) + 1, ((nOption == 2) and "[ Take Reactors Offline ]") or "Take Reactors Offline" )
  37. printCentred( math.floor(h/2) + 2, ((nOption == 3) and "[ Logout ]") or "Logout" )
  38. printCentred( math.floor(h/2) + 3, "" )
  39. end
  40.  
  41.  
  42.  
  43.  
  44. -- Call functions for display menu
  45. drawMenu()
  46. drawFrontend()
  47.  
  48.  
  49.  
  50. while true do
  51. local e,p = os.pullEvent()
  52. if e == "key" then
  53. local key = p
  54. if key == 17 or key == 200 then
  55. -- Up
  56. if nOption > 1 then
  57. nOption = nOption - 1
  58. drawMenu()
  59. drawFrontend()
  60. end
  61. elseif key == 31 or key == 208 then
  62. -- Down
  63. if nOption < 3 then -- Change 3 by the number of option.
  64. nOption = nOption + 1
  65. drawMenu()
  66. drawFrontend()
  67. end
  68. elseif key == 28 then
  69. -- Enter
  70. break
  71. end
  72. end
  73. end
  74. term.clear()
  75.  
  76. -- Conditions
  77. if nOption == 1 then
  78. term.setCursorPos(1,1)
  79. print("Engaging reactors...")
  80. sleep(3)
  81. shell.run("r-on")
  82. print("Reactors Online.")
  83. shell.run("menu")
  84. elseif nOption == 2 then
  85. term.setCursorPos(1,1)
  86. print("Disengaging reactors...")
  87. sleep(2)
  88. print("Reactors Offline")
  89. shell.run("r-off")
  90. shell.run("menu")
  91. else
  92. term.setCursorPos(1,1)
  93. print("Logging out...")
  94. sleep(2)
  95. os.shutdown()
  96. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement