flaunting

Untitled

Apr 22nd, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.83 KB | None | 0 0
  1. --Menu
  2.  
  3. function menu( title, ... )
  4. --edit the background color to make the GUI more unique
  5. term.setBackgroundColor( colors.black )
  6. local debug = false --#turn to true to see what it's thinking
  7. local tArgs = { ... }
  8. local pages = {[1]={}}
  9. for i = 1, #tArgs, 1 do
  10. if #pages[ #pages ] == 7 then
  11. pages[ #pages + 1 ] = {}
  12. end
  13. pages[ #pages ][ #pages[#pages] + 1 ] = tArgs[ i ]
  14. end
  15. local maxLen = 0
  16. for k, v in ipairs( tArgs ) do
  17. if #v > maxLen then maxLen = #v end
  18. end
  19. local maxx, maxy = term.getSize()
  20. if maxLen > maxx - 20 then
  21. error( 'largest string is too large', 2 )
  22. end
  23. local centerx = math.ceil( maxx/2 )
  24. local centery
  25. local yValue = {}
  26. local page = 1
  27. local selected = math.ceil( #pages[ page ] / 2 )
  28. local function render()
  29. local tbl = pages[ page ]
  30. centery = (maxy/2) - #tbl/2
  31. term.clear()
  32. term.setCursorPos( centerx - #title/2 + 1, 2 )
  33. term.write( title )
  34. for i = 1, #tbl do
  35. term.setCursorPos( centerx - (#tbl[i]/2), centery + i )
  36. yValue[ i ] = centery + i
  37. term.write( tbl[ i ] )
  38. end
  39. if pages[ page - 1 ] then
  40. term.setCursorPos( 3, centery + #tbl/2 + 1 )
  41. term.write( "previous" )
  42. end
  43. if pages[ page + 1 ] then
  44. term.setCursorPos( maxx - 5, centery + #tbl/2 + 1 )
  45. term.write( "next" )
  46. end
  47. local str = "(" .. page .. "/" .. #pages .. ")"
  48. term.setCursorPos( centerx - (#str/2), maxy )
  49. term.write( str )
  50. end
  51. while true do
  52. render()
  53. if debug then
  54. term.setCursorPos( 1, 1 )
  55. term.write( selected )
  56. term.setCursorPos( 1, 2 )
  57. term.write( page )
  58. end
  59. if term.isColor() then
  60. term.setTextColor( colors.yellow )
  61. end
  62. if selected == "previous" and not pages[ page - 1 ] then
  63. selected = math.ceil( #pages[ page ]/2 )
  64. elseif selected == "next" and not pages[ page + 1 ] then
  65. selected = math.ceil( #pages[ page ]/2 )
  66. end
  67. if type( selected ) == "number" then
  68. term.setCursorPos( centerx - (#pages[page][selected]/2) - 3, yValue[ selected ] )
  69. term.write( "[" )
  70. term.setCursorPos( centerx + (#pages[page][selected]/2) + 2, yValue[ selected ] )
  71. term.write( "]" )
  72. elseif selected == "previous" then
  73. term.setCursorPos( 1, centery + #pages[ page ]/2 + 1 )
  74. term.write( "[" )
  75. term.setCursorPos( 12, centery + #pages[ page ]/2 + 1 )
  76. term.write( "]" )
  77. elseif selected == "next" then
  78. term.setCursorPos( maxx - 7, centery + #pages[ page ]/2 + 1 )
  79. term.write( "[" )
  80. term.setCursorPos( maxx, centery + #pages[ page ]/2 + 1 )
  81. term.write( "]" )
  82. end
  83. if term.isColor() then
  84. term.setTextColor( colors.white )
  85. end
  86. local event, key = os.pullEvent( "key" )
  87. local old = selected
  88. if key == 200 and type( selected ) == "number" and pages[ page ][ selected - 1 ] then
  89. selected = selected - 1
  90. elseif key == 208 and type( selected ) == "number" and pages[ page ][ selected + 1 ] then
  91. selected = selected + 1
  92. elseif key == 28 then
  93. if type( selected ) == "number" then
  94. return pages[ page ][ selected ]
  95. elseif selected == "next" and pages[ page + 1 ] then
  96. page = page + 1
  97. elseif selected == "previous" and pages[ page - 1 ] then
  98. page = page - 1
  99. end
  100. elseif key == 203 then
  101. if selected == "next" then
  102. selected = math.ceil( #pages[ page ]/2 )
  103. elseif type( selected ) == "number" and pages[ page - 1 ] then
  104. selected = "previous"
  105. end
  106. elseif key == 205 then
  107. if selected == "previous" then
  108. selected = math.ceil( #pages[ page ]/2 )
  109. elseif type( selected ) == "number" and pages[ page + 1 ] then
  110. selected = "next"
  111. end
  112. end
  113. end
  114. end
  115.  
  116. --End
  117.  
  118. print("Welcome to the Immersive Engineering")
  119. print("Construction Program")
  120. print("Press enter to choose your structure...")
  121.  
  122. repeat
  123. local event, key = os.pullEvent("key")
  124. until key == keys.enter
  125.  
  126. local structure = menu("Choose a Structure", 'Harvester', 'Crusher', 'Diesel Gen', 'Coke Oven',
  127. 'Crude Blast Furnace', 'Improved Blast Furnace', 'Industrial Squeezer', 'Fermenter', 'Refinery',
  128. 'Arc Furnace', 'Excavator', 'Assembler', 'Bottling Machine', 'Metal Press' )
  129.  
  130. term.clear()
  131. term.setCursorPos(1,1)
  132.  
  133. if selection == "Harvester" then
  134. shell.run("harvester")
  135. end
  136.  
  137. elseif selection == "Crusher" then
  138. shell.run("crusher")
  139. end
  140.  
  141. elseif selection == "Diesel Gen" then
  142. shell.run("diesGen")
  143. end
  144.  
  145. elseif selection == "Coke Oven" then
  146. shell.run("cokeOven")
  147. end
  148.  
  149. elseif selection == "Crude Blast Furnace" then
  150. shell.run("crudeBlast")
  151. end
  152.  
  153. elseif selection == "Improved Blast Furnace" then
  154. shell.run("impBlast")
  155. end
  156.  
  157. elseif selection == "Industrial Squeezer" then
  158. shell.run("indSqueezer")
  159. end
  160.  
  161. elseif selection == "Fermenter" then
  162. shell.run("fermenter")
  163. end
  164.  
  165. elseif selection == "Arc Furnace" then
  166. shell.run("arcFurnace")
  167. end
  168.  
  169. elseif selection == "Excavator" then
  170. shell.run("excavator")
  171. end
  172.  
  173. elseif selection == "Assembler" then
  174. shell.run("assembler")
  175. end
  176.  
  177. elseif selection == "Bottling Machine" then
  178. shell.run("bottleMach")
  179. end
  180.  
  181. elseif selection == "Refinery" then
  182. shell.run("refinery")
  183. end
  184.  
  185. elseif selection == "Metal Press" then
  186. shell.run("metalPress")
  187. end
Advertisement
Add Comment
Please, Sign In to add comment