kamilosxd678

Untitled

Jan 19th, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.09 KB | None | 0 0
  1. -- Sides
  2. local bundledInputSide = "bottom"
  3. local bundledOutputSide = "back"
  4. local monitorSide = "right"
  5. local ticketMachineSide = "top"
  6. local chestSide = "left"
  7. local locoChest = "SOUTH"
  8. local cartChest = "NORTH"
  9. -- Peripherals
  10. local monitor = peripheral.wrap( monitorSide )
  11. local chest = peripheral.wrap( chestSide )
  12. -- Touch Coords
  13. local buttonsStartX = 38
  14. local upButtonStartY = 8
  15. local okButtonStartY = 12
  16. local dwButtonStartY = 16
  17. -- Destination list
  18. local destinationListStartX = 4
  19. local destinationListStartY = 8
  20. local actualStationIdx = 1
  21.  
  22. local ticketScreenActive = false
  23.  
  24. -- List of all station short names used for tickets and time table
  25. local stationNames = {"RedwoodFactory", "SlimeVille", "EmeraldValley", "Coppertino"}
  26. -- List of all station full names for user choice
  27. local stationFullNames = {"Redwood Factory", "Slime Ville", "Emerald Valley", "Coppertino"}
  28.  
  29. ---- Departures screen
  30. -- Prints text ODJAZDY
  31. function writeDepartures()
  32. monitor.setCursorPos( 9, 2 )
  33. monitor.blit(" ", "ffffffffffffffffffffffffffffffffff", "feeffeeefffeeeffeeffeeeefeeeffeffe")
  34. monitor.setCursorPos( 9, 3 )
  35. monitor.blit(" ", "ffffffffffffffffffffffffffffffffff", "effefeffeffffefeffeffffefeffefeffe")
  36. monitor.setCursorPos( 9, 4 )
  37. monitor.blit(" ", "ffffffffffffffffffffffffffffffffff", "effefeffeffffefeffefffeffeffeffeef")
  38. monitor.setCursorPos( 9, 5 )
  39. monitor.blit(" ", "ffffffffffffffffffffffffffffffffff", "effefeffefeffefeeeeffefffeffefffef")
  40. monitor.setCursorPos( 9, 6 )
  41. monitor.blit(" ", "ffffffffffffffffffffffffffffffffff", "feeffeeefffeeffeffefeeeefeeeffffef")
  42. end
  43.  
  44. -- Prints time table
  45. function writeTimeTable()
  46. monitor.setBackgroundColor( colors.black )
  47. monitor.setTextColor( colors.white )
  48.  
  49. monitor.setCursorPos( 5, 8 )
  50. monitor.write("Lp. | Kierunek | Do odjazdu")
  51. monitor.setCursorPos( 5, 9 )
  52. monitor.write("1 | ----------------------- | ----------")
  53. monitor.setCursorPos( 5, 10 )
  54. monitor.write("2 | ----------------------- | ----------")
  55. monitor.setCursorPos( 5, 11 )
  56. monitor.write("3 | ----------------------- | ----------")
  57. monitor.setCursorPos( 5, 12 )
  58. monitor.write("4 | ----------------------- | ----------")
  59. monitor.setCursorPos( 5, 13 )
  60. monitor.write("5 | ----------------------- | ----------")
  61. monitor.setCursorPos( 5, 14 )
  62. monitor.write("6 | ----------------------- | ----------")
  63. monitor.setCursorPos( 5, 15 )
  64. monitor.write("7 | ----------------------- | ----------")
  65. monitor.setCursorPos( 5, 16 )
  66. monitor.write("8 | ----------------------- | ----------")
  67. monitor.setCursorPos( 5, 17 )
  68. monitor.write("9 | ----------------------- | ----------")
  69. monitor.setCursorPos( 5, 18 )
  70. monitor.write("10 | ----------------------- | ----------")
  71. end
  72.  
  73. ---- Tickets screen
  74. -- Prints text BILETY
  75. function writeTicketsHeader()
  76. monitor.setCursorPos( 13, 2 )
  77. monitor.blit(" ", "ffffffffffffffffffffffffff", "444ff4f4fff4444f44444f4ff4")
  78. monitor.setCursorPos( 13, 3 )
  79. monitor.blit(" ", "ffffffffffffffffffffffffff", "4ff4f4f4fff4ffffff4fff4ff4")
  80. monitor.setCursorPos( 13, 4 )
  81. monitor.blit(" ", "ffffffffffffffffffffffffff", "444ff4f4fff444ffff4ffff44f")
  82. monitor.setCursorPos( 13, 5 )
  83. monitor.blit(" ", "ffffffffffffffffffffffffff", "4ff4f4f4fff4ffffff4fffff4f")
  84. monitor.setCursorPos( 13, 6 )
  85. monitor.blit(" ", "ffffffffffffffffffffffffff", "444ff4f444f4444fff4fffff4f")
  86. end
  87.  
  88. -- Prints UP button
  89. function writeUpButton()
  90. monitor.setCursorPos( buttonsStartX, upButtonStartY )
  91. monitor.blit(" ", "fffffff", "fff1fff")
  92. monitor.setCursorPos( buttonsStartX, upButtonStartY + 1 )
  93. monitor.blit(" ", "fffffff", "ff1f1ff")
  94. monitor.setCursorPos( buttonsStartX, upButtonStartY + 2 )
  95. monitor.blit(" ", "fffffff", "f1fff1f")
  96. end
  97.  
  98. -- Prints OK button
  99. function writeOkButton()
  100. monitor.setCursorPos( buttonsStartX, okButtonStartY )
  101. monitor.blit(" ", "fffffff", "f5ff5f5")
  102. monitor.setCursorPos( buttonsStartX, okButtonStartY + 1 )
  103. monitor.blit(" ", "fffffff", "5f5f55f")
  104. monitor.setCursorPos( buttonsStartX, okButtonStartY + 2 )
  105. monitor.blit(" ", "fffffff", "f5ff5f5")
  106. end
  107.  
  108. -- Prints DOWN button
  109. function writeDownButton()
  110. monitor.setCursorPos( buttonsStartX, dwButtonStartY )
  111. monitor.blit(" ", "fffffff", "f1fff1f")
  112. monitor.setCursorPos( buttonsStartX, dwButtonStartY + 1 )
  113. monitor.blit(" ", "fffffff", "ff1f1ff")
  114. monitor.setCursorPos( buttonsStartX, dwButtonStartY + 2 )
  115. monitor.blit(" ", "fffffff", "fff1fff")
  116. end
  117.  
  118. -- Prints dest table header
  119. function writeDestTableHead()
  120. monitor.setBackgroundColor( colors.black )
  121. monitor.setTextColor( colors.white )
  122.  
  123. monitor.setCursorPos( destinationListStartX, destinationListStartY + 0 )
  124. monitor.write("Lp. | Kierunek |")
  125. end
  126.  
  127. -- Prints dest table
  128. function writeDestTable(startIdx)
  129. monitor.setBackgroundColor( colors.black )
  130. monitor.setTextColor( colors.white )
  131.  
  132. local nameTrimmed = ""
  133. local number = ""
  134.  
  135. for i=1, table.getn(stationNames) do
  136. if string.len(stationNames[i]) > 23 then
  137. nameTrimmed = string.sub(stationNames[i], 0, 23)
  138. else
  139. nameTrimmed = stationNames[i]
  140. end
  141.  
  142. number = string.format("%d.", i)
  143.  
  144. monitor.setCursorPos( destinationListStartX, destinationListStartY + i )
  145. monitor.write(" | |")
  146. monitor.setCursorPos( destinationListStartX, destinationListStartY + i )
  147. monitor.write(number)
  148. monitor.setCursorPos( destinationListStartX + 6, destinationListStartY + i )
  149.  
  150. if(i == actualStationIdx) then
  151. monitor.setBackgroundColor( colors.white )
  152. monitor.setTextColor( colors.black )
  153. end
  154.  
  155. monitor.write(nameTrimmed)
  156.  
  157. if(i == actualStationIdx) then
  158. monitor.setBackgroundColor( colors.black )
  159. monitor.setTextColor( colors.white )
  160. end
  161. end
  162. end
  163.  
  164. -- Print train fetched info
  165. function printTrainFetchedInfo()
  166. monitor.setBackgroundColor( colors.black )
  167. monitor.setTextColor( colors.white )
  168.  
  169. monitor.write(" ")
  170. monitor.setCursorPos( 2, 16 )
  171. monitor.write(" ")
  172. monitor.setCursorPos( 2, 17 )
  173. monitor.write(" ")
  174. monitor.setCursorPos( 2, 18 )
  175. monitor.write(" ")
  176. end
  177.  
  178. -- Fetches train using bundled output
  179. function fetchTrain()
  180. local trainFetched = false
  181.  
  182. chest.pullItem(locoChest, 1, 1, 1)
  183. chest.pullItem(locoChest, 2, 1, 2)
  184. chest.pullItem(cartChest, 1, 1, 3)
  185. chest.pullItem(cartChest, 2, 1, 4)
  186. chest.pullItem(cartChest, 3, 1, 5)
  187.  
  188. if (colors.test (redstone.getBundledInput(bundledInputSide), colors.blue)) then
  189. print("Pociag czeka na peronie odjazdow")
  190. else
  191. sleep(1)
  192. redstone.setBundledOutput(bundledOutputSide, colors.pink)
  193. sleep(1)
  194. trainFetched = true
  195. end
  196.  
  197. redstone.setBundledOutput(bundledOutputSide, 0)
  198.  
  199. return trainFetched
  200. end
  201.  
  202. -- Adds actually fetched train to time table
  203. function addDeparture(name, timeLeft)
  204. monitor.setBackgroundColor( colors.black )
  205. monitor.setTextColor( colors.white )
  206.  
  207. -- time
  208. local nameTrimmed = ""
  209.  
  210. if string.len(name) > 23 then
  211. nameTrimmed = string.sub(name, 0, 23)
  212. else
  213. nameTrimmed = name
  214. end
  215.  
  216. monitor.setCursorPos(11, 9)
  217. monitor.write(" ")
  218. monitor.setCursorPos(37, 9)
  219. monitor.write(" ")
  220.  
  221. monitor.setCursorPos(11, 9)
  222. monitor.write(nameTrimmed)
  223. monitor.setCursorPos(37, 9)
  224. monitor.write(timeLeft)
  225. end
  226.  
  227. -- Changes name of station in menu
  228. function changeChosenStation(name)
  229. monitor.setBackgroundColor( colors.black )
  230. monitor.setTextColor( colors.white )
  231.  
  232. -- time
  233. local nameTrimmed = ""
  234.  
  235. if string.len(name) > 17 then
  236. nameTrimmed = string.sub(name, 0, 17)
  237. else
  238. nameTrimmed = name
  239. end
  240.  
  241. monitor.setCursorPos(8, 18)
  242. monitor.write(" ")
  243.  
  244. monitor.setCursorPos(8, 18)
  245. monitor.write(nameTrimmed)
  246. end
  247.  
  248. function swapUpStation()
  249. actualStationIdx = actualStationIdx - 1
  250.  
  251. if (actualStationIdx == 0) then
  252. actualStationIdx = table.getn(stationNames)
  253. end
  254.  
  255. writeDestTable(0)
  256. end
  257.  
  258. function swapDownStation()
  259. actualStationIdx = actualStationIdx + 1
  260.  
  261. if (actualStationIdx == table.getn(stationNames) + 1) then
  262. actualStationIdx = 1
  263. end
  264.  
  265. writeDestTable(0)
  266. end
  267.  
  268. function announceTrain(name)
  269. local timeLeft = 5
  270. local timeLeftText = string.format("%d s", timeLeft)
  271. local ticketPrinter = peripheral.wrap(ticketMachineSide)
  272. ticketPrinter.createTicket(name, 1)
  273.  
  274. ticketPhase = 0
  275.  
  276. while (timeLeft ~= 0) do
  277. timeLeftText = string.format("%d s", timeLeft)
  278. addDeparture(name, timeLeftText)
  279. timeLeft = timeLeft - 1
  280. sleep(1)
  281.  
  282. if ticketPhase == 0 then
  283. redstone.setOutput("bottom", true)
  284. ticketPhase = ticketPhase + 1
  285. elseif ticketPhase == 1 then
  286. redstone.setOutput("bottom", false)
  287. ticketPhase = ticketPhase + 1
  288. end
  289. end
  290.  
  291. addDeparture("-----------------------", "----------")
  292. end
  293.  
  294. function printDeparturesScreen()
  295. monitor.clear()
  296. ticketScreenActive = false
  297. writeDepartures()
  298. writeTimeTable()
  299. end
  300.  
  301. function printTicketBuyScreen()
  302. monitor.clear()
  303. ticketScreenActive = true
  304. writeTicketsHeader()
  305. writeUpButton()
  306. writeOkButton()
  307. writeDownButton()
  308. writeDestTableHead()
  309. writeDestTable(0)
  310. end
  311.  
  312. function main()
  313. printTicketBuyScreen()
  314.  
  315. while true do
  316. local event, p1, p2, p3, p4, p5 = os.pullEvent()
  317. if(event == "monitor_touch" and ticketScreenActive == true) then
  318. if(p1 == "right") then
  319. -- Buttons column
  320. if(p2 >= buttonsStartX and p2 <= buttonsStartX + 7) then
  321. -- Up button
  322. if(p3 >= upButtonStartY and p3 <= upButtonStartY + 3) then
  323. swapUpStation()
  324. elseif (p3 >= dwButtonStartY and p3 <= dwButtonStartY + 3) then
  325. swapDownStation()
  326. elseif (p3 >= okButtonStartY and p3 <= okButtonStartY + 3) then
  327. if fetchTrain() then
  328. printDeparturesScreen()
  329. announceTrain(stationNames[actualStationIdx])
  330. else
  331. sleep(5)
  332. end
  333. end
  334. end
  335. end
  336. elseif(event == "redstone") then
  337. if (colors.test (redstone.getBundledInput(bundledInputSide), colors.lime)) then
  338. printTicketBuyScreen()
  339. end
  340. end
  341. end
  342. end
  343.  
  344. main()
Advertisement
Add Comment
Please, Sign In to add comment