Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Desktop
- --VARS
- tBarC = 8 --titlebar color
- tBarTC = 1 --titlebar text color
- destBackgroundC = 1
- destTextColor = colors.black
- DESTINATIONS = {}
- DESTINATIONS = {"Husby","Roffeborg","Petersburg","norr1","norr2","söder1","väst1","öst1","öst2","etc-","t.ex"}
- LISTED_DESTINATIONS = {}
- STATION = "Petersburg"
- --FUNCTIONS
- function titleBar()
- term.redirect(monitor)
- term.setBackgroundColor(tBarC)
- term.setTextColor(tBarTC)
- for i=1,4 do
- term.setCursorPos(1,i)
- term.clearLine()
- end
- term.setCursorPos(1,1)
- write("Welcome to Kunjuna RailNet!")
- term.setCursorPos(3,2)
- write("Select your destination, ")
- term.setCursorPos(3,3)
- write("then collect your ticket below!")
- end
- function drawDestinations()
- printedLines = 0
- printedColumns = 0
- printedObj = 0
- term.setBackgroundColor(destBackgroundC)
- term.setTextColor(destTextColor)
- for i=5,12 do
- term.setCursorPos(1,i)
- term.clearLine()
- end
- for i=1,#DESTINATIONS do
- if DESTINATIONS[i] ~= STATION then
- term.setCursorPos(3+(printedColumns * 13),6 + printedLines)
- printedLines = printedLines + 1
- printedObj = printedObj + 1
- write(DESTINATIONS[i])
- LISTED_DESTINATIONS[printedObj] = DESTINATIONS[i]
- if ( printedLines > 5 ) then
- printedLines = 0
- printedColumns = printedColumns + 1
- end
- end
- end
- end
- function popup(msg,yPos)
- term.setBackgroundColor(colors.green)
- term.setTextColor(colors.yellow)
- term.setCursorPos(1, yPos)
- term.clearLine()
- write(msg)
- end
- function drawScreen()
- titleBar()
- drawDestinations()
- end
- function refill()
- popup("Refilling ticket machine!",9)
- sleep(1)
- redstone.setOutput("back",true)
- sleep(4)
- redstone.setOutput("back",false)
- drawScreen()
- end
- function printTicket()
- --print ticket
- popup("Please take your ticket!",12)
- ticketMachine.createTicket(LISTED_DESTINATIONS[clicked])
- local tableInfo = ticketMachine.getStackInSlot(1)
- if tableInfo == nil then
- refill()
- elseif tableInfo["qty"] < 2 then
- refill()
- else
- drawScreen()
- end
- end
- -- MAIN
- monitor = peripheral.wrap("top")
- ticketMachine = peripheral.wrap("left")
- monitor.setTextScale(1)
- drawScreen()
- while true do
- --wait for user interaction (click on a name)
- local event, side, X, Y = os.pullEventRaw()
- if event == "monitor_touch" and side == "top" then
- --popup("Clicked "..X..", "..Y..".")
- if Y > 5 then
- clicked = Y - 5
- if X > 13 then
- clicked = clicked + 6
- end
- end
- popup("Printing ticket to "..LISTED_DESTINATIONS[clicked].."!",11)
- sleep(1)
- printTicket(LISTED_DESTINATIONS[clicked])
- sleep(2)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment