Advertisement
Guest User

Untitled

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