Advertisement
Easyhun

Untitled

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