Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Sides
- local bundledInputSide = "bottom"
- local bundledOutputSide = "back"
- local monitorSide = "right"
- local ticketMachineSide = "top"
- local chestSide = "left"
- local locoChest = "SOUTH"
- local cartChest = "NORTH"
- -- Peripherals
- local monitor = peripheral.wrap( monitorSide )
- local chest = peripheral.wrap( chestSide )
- -- Touch Coords
- local buttonsStartX = 38
- local upButtonStartY = 8
- local okButtonStartY = 12
- local dwButtonStartY = 16
- -- Destination list
- local destinationListStartX = 4
- local destinationListStartY = 8
- local actualStationIdx = 1
- local ticketScreenActive = false
- -- List of all station short names used for tickets and time table
- local stationNames = {"RedwoodFactory", "SlimeVille", "EmeraldValley", "Coppertino"}
- -- List of all station full names for user choice
- local stationFullNames = {"Redwood Factory", "Slime Ville", "Emerald Valley", "Coppertino"}
- ---- Departures screen
- -- Prints text ODJAZDY
- function writeDepartures()
- monitor.setCursorPos( 9, 2 )
- monitor.blit(" ", "ffffffffffffffffffffffffffffffffff", "feeffeeefffeeeffeeffeeeefeeeffeffe")
- monitor.setCursorPos( 9, 3 )
- monitor.blit(" ", "ffffffffffffffffffffffffffffffffff", "effefeffeffffefeffeffffefeffefeffe")
- monitor.setCursorPos( 9, 4 )
- monitor.blit(" ", "ffffffffffffffffffffffffffffffffff", "effefeffeffffefeffefffeffeffeffeef")
- monitor.setCursorPos( 9, 5 )
- monitor.blit(" ", "ffffffffffffffffffffffffffffffffff", "effefeffefeffefeeeeffefffeffefffef")
- monitor.setCursorPos( 9, 6 )
- monitor.blit(" ", "ffffffffffffffffffffffffffffffffff", "feeffeeefffeeffeffefeeeefeeeffffef")
- end
- -- Prints time table
- function writeTimeTable()
- monitor.setBackgroundColor( colors.black )
- monitor.setTextColor( colors.white )
- monitor.setCursorPos( 5, 8 )
- monitor.write("Lp. | Kierunek | Do odjazdu")
- monitor.setCursorPos( 5, 9 )
- monitor.write("1 | ----------------------- | ----------")
- monitor.setCursorPos( 5, 10 )
- monitor.write("2 | ----------------------- | ----------")
- monitor.setCursorPos( 5, 11 )
- monitor.write("3 | ----------------------- | ----------")
- monitor.setCursorPos( 5, 12 )
- monitor.write("4 | ----------------------- | ----------")
- monitor.setCursorPos( 5, 13 )
- monitor.write("5 | ----------------------- | ----------")
- monitor.setCursorPos( 5, 14 )
- monitor.write("6 | ----------------------- | ----------")
- monitor.setCursorPos( 5, 15 )
- monitor.write("7 | ----------------------- | ----------")
- monitor.setCursorPos( 5, 16 )
- monitor.write("8 | ----------------------- | ----------")
- monitor.setCursorPos( 5, 17 )
- monitor.write("9 | ----------------------- | ----------")
- monitor.setCursorPos( 5, 18 )
- monitor.write("10 | ----------------------- | ----------")
- end
- ---- Tickets screen
- -- Prints text BILETY
- function writeTicketsHeader()
- monitor.setCursorPos( 13, 2 )
- monitor.blit(" ", "ffffffffffffffffffffffffff", "444ff4f4fff4444f44444f4ff4")
- monitor.setCursorPos( 13, 3 )
- monitor.blit(" ", "ffffffffffffffffffffffffff", "4ff4f4f4fff4ffffff4fff4ff4")
- monitor.setCursorPos( 13, 4 )
- monitor.blit(" ", "ffffffffffffffffffffffffff", "444ff4f4fff444ffff4ffff44f")
- monitor.setCursorPos( 13, 5 )
- monitor.blit(" ", "ffffffffffffffffffffffffff", "4ff4f4f4fff4ffffff4fffff4f")
- monitor.setCursorPos( 13, 6 )
- monitor.blit(" ", "ffffffffffffffffffffffffff", "444ff4f444f4444fff4fffff4f")
- end
- -- Prints UP button
- function writeUpButton()
- monitor.setCursorPos( buttonsStartX, upButtonStartY )
- monitor.blit(" ", "fffffff", "fff1fff")
- monitor.setCursorPos( buttonsStartX, upButtonStartY + 1 )
- monitor.blit(" ", "fffffff", "ff1f1ff")
- monitor.setCursorPos( buttonsStartX, upButtonStartY + 2 )
- monitor.blit(" ", "fffffff", "f1fff1f")
- end
- -- Prints OK button
- function writeOkButton()
- monitor.setCursorPos( buttonsStartX, okButtonStartY )
- monitor.blit(" ", "fffffff", "f5ff5f5")
- monitor.setCursorPos( buttonsStartX, okButtonStartY + 1 )
- monitor.blit(" ", "fffffff", "5f5f55f")
- monitor.setCursorPos( buttonsStartX, okButtonStartY + 2 )
- monitor.blit(" ", "fffffff", "f5ff5f5")
- end
- -- Prints DOWN button
- function writeDownButton()
- monitor.setCursorPos( buttonsStartX, dwButtonStartY )
- monitor.blit(" ", "fffffff", "f1fff1f")
- monitor.setCursorPos( buttonsStartX, dwButtonStartY + 1 )
- monitor.blit(" ", "fffffff", "ff1f1ff")
- monitor.setCursorPos( buttonsStartX, dwButtonStartY + 2 )
- monitor.blit(" ", "fffffff", "fff1fff")
- end
- -- Prints dest table header
- function writeDestTableHead()
- monitor.setBackgroundColor( colors.black )
- monitor.setTextColor( colors.white )
- monitor.setCursorPos( destinationListStartX, destinationListStartY + 0 )
- monitor.write("Lp. | Kierunek |")
- end
- -- Prints dest table
- function writeDestTable(startIdx)
- monitor.setBackgroundColor( colors.black )
- monitor.setTextColor( colors.white )
- local nameTrimmed = ""
- local number = ""
- for i=1, table.getn(stationNames) do
- if string.len(stationNames[i]) > 23 then
- nameTrimmed = string.sub(stationNames[i], 0, 23)
- else
- nameTrimmed = stationNames[i]
- end
- number = string.format("%d.", i)
- monitor.setCursorPos( destinationListStartX, destinationListStartY + i )
- monitor.write(" | |")
- monitor.setCursorPos( destinationListStartX, destinationListStartY + i )
- monitor.write(number)
- monitor.setCursorPos( destinationListStartX + 6, destinationListStartY + i )
- if(i == actualStationIdx) then
- monitor.setBackgroundColor( colors.white )
- monitor.setTextColor( colors.black )
- end
- monitor.write(nameTrimmed)
- if(i == actualStationIdx) then
- monitor.setBackgroundColor( colors.black )
- monitor.setTextColor( colors.white )
- end
- end
- end
- -- Print train fetched info
- function printTrainFetchedInfo()
- monitor.setBackgroundColor( colors.black )
- monitor.setTextColor( colors.white )
- monitor.write(" ")
- monitor.setCursorPos( 2, 16 )
- monitor.write(" ")
- monitor.setCursorPos( 2, 17 )
- monitor.write(" ")
- monitor.setCursorPos( 2, 18 )
- monitor.write(" ")
- end
- -- Fetches train using bundled output
- function fetchTrain()
- local trainFetched = false
- chest.pullItem(locoChest, 1, 1, 1)
- chest.pullItem(locoChest, 2, 1, 2)
- chest.pullItem(cartChest, 1, 1, 3)
- chest.pullItem(cartChest, 2, 1, 4)
- chest.pullItem(cartChest, 3, 1, 5)
- if (colors.test (redstone.getBundledInput(bundledInputSide), colors.blue)) then
- print("Pociag czeka na peronie odjazdow")
- else
- sleep(1)
- redstone.setBundledOutput(bundledOutputSide, colors.pink)
- sleep(1)
- trainFetched = true
- end
- redstone.setBundledOutput(bundledOutputSide, 0)
- return trainFetched
- end
- -- Adds actually fetched train to time table
- function addDeparture(name, timeLeft)
- monitor.setBackgroundColor( colors.black )
- monitor.setTextColor( colors.white )
- -- time
- local nameTrimmed = ""
- if string.len(name) > 23 then
- nameTrimmed = string.sub(name, 0, 23)
- else
- nameTrimmed = name
- end
- monitor.setCursorPos(11, 9)
- monitor.write(" ")
- monitor.setCursorPos(37, 9)
- monitor.write(" ")
- monitor.setCursorPos(11, 9)
- monitor.write(nameTrimmed)
- monitor.setCursorPos(37, 9)
- monitor.write(timeLeft)
- end
- -- Changes name of station in menu
- function changeChosenStation(name)
- monitor.setBackgroundColor( colors.black )
- monitor.setTextColor( colors.white )
- -- time
- local nameTrimmed = ""
- if string.len(name) > 17 then
- nameTrimmed = string.sub(name, 0, 17)
- else
- nameTrimmed = name
- end
- monitor.setCursorPos(8, 18)
- monitor.write(" ")
- monitor.setCursorPos(8, 18)
- monitor.write(nameTrimmed)
- end
- function swapUpStation()
- actualStationIdx = actualStationIdx - 1
- if (actualStationIdx == 0) then
- actualStationIdx = table.getn(stationNames)
- end
- writeDestTable(0)
- end
- function swapDownStation()
- actualStationIdx = actualStationIdx + 1
- if (actualStationIdx == table.getn(stationNames) + 1) then
- actualStationIdx = 1
- end
- writeDestTable(0)
- end
- function announceTrain(name)
- local timeLeft = 5
- local timeLeftText = string.format("%d s", timeLeft)
- local ticketPrinter = peripheral.wrap(ticketMachineSide)
- ticketPrinter.createTicket(name, 1)
- ticketPhase = 0
- while (timeLeft ~= 0) do
- timeLeftText = string.format("%d s", timeLeft)
- addDeparture(name, timeLeftText)
- timeLeft = timeLeft - 1
- sleep(1)
- if ticketPhase == 0 then
- redstone.setOutput("bottom", true)
- ticketPhase = ticketPhase + 1
- elseif ticketPhase == 1 then
- redstone.setOutput("bottom", false)
- ticketPhase = ticketPhase + 1
- end
- end
- addDeparture("-----------------------", "----------")
- end
- function printDeparturesScreen()
- monitor.clear()
- ticketScreenActive = false
- writeDepartures()
- writeTimeTable()
- end
- function printTicketBuyScreen()
- monitor.clear()
- ticketScreenActive = true
- writeTicketsHeader()
- writeUpButton()
- writeOkButton()
- writeDownButton()
- writeDestTableHead()
- writeDestTable(0)
- end
- function main()
- printTicketBuyScreen()
- while true do
- local event, p1, p2, p3, p4, p5 = os.pullEvent()
- if(event == "monitor_touch" and ticketScreenActive == true) then
- if(p1 == "right") then
- -- Buttons column
- if(p2 >= buttonsStartX and p2 <= buttonsStartX + 7) then
- -- Up button
- if(p3 >= upButtonStartY and p3 <= upButtonStartY + 3) then
- swapUpStation()
- elseif (p3 >= dwButtonStartY and p3 <= dwButtonStartY + 3) then
- swapDownStation()
- elseif (p3 >= okButtonStartY and p3 <= okButtonStartY + 3) then
- if fetchTrain() then
- printDeparturesScreen()
- announceTrain(stationNames[actualStationIdx])
- else
- sleep(5)
- end
- end
- end
- end
- elseif(event == "redstone") then
- if (colors.test (redstone.getBundledInput(bundledInputSide), colors.lime)) then
- printTicketBuyScreen()
- end
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment