PeeWeeSweden

Untitled

Nov 6th, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.96 KB | None | 0 0
  1. --Desktop
  2.  
  3.  
  4. --VARS
  5. tBarC = 8  --titlebar color
  6. tBarTC = 1 --titlebar text color
  7. destBackgroundC = 1
  8. destTextColor = colors.black
  9.  
  10. DESTINATIONS = {}
  11. DESTINATIONS = {"Husby","Roffeborg","Petersburg","norr1","norr2","söder1","väst1","öst1","öst2","etc-","t.ex"}
  12. LISTED_DESTINATIONS = {}
  13. STATION = "Petersburg"
  14.  
  15. --FUNCTIONS
  16.  function titleBar()
  17.     term.redirect(monitor)
  18.     term.setBackgroundColor(tBarC)
  19.     term.setTextColor(tBarTC)
  20.     for i=1,4 do
  21.         term.setCursorPos(1,i)
  22.         term.clearLine()
  23.     end
  24.  
  25.     term.setCursorPos(1,1)
  26.     write("Welcome to Kunjuna RailNet!")
  27.     term.setCursorPos(3,2)
  28.     write("Select your destination, ")
  29.     term.setCursorPos(3,3)
  30.     write("then collect your ticket below!")
  31. end
  32.  
  33. function drawDestinations()
  34.     printedLines = 0
  35.     printedColumns = 0
  36.     printedObj = 0
  37.    
  38.     term.setBackgroundColor(destBackgroundC)
  39.     term.setTextColor(destTextColor)
  40.     for i=5,12 do
  41.         term.setCursorPos(1,i)
  42.         term.clearLine()
  43.     end
  44.  
  45.     for i=1,#DESTINATIONS do
  46.         if DESTINATIONS[i] ~= STATION then
  47.             term.setCursorPos(3+(printedColumns * 13),6 + printedLines)
  48.             printedLines = printedLines + 1
  49.             printedObj = printedObj + 1
  50.             write(DESTINATIONS[i])
  51.             LISTED_DESTINATIONS[printedObj] = DESTINATIONS[i]
  52.             if ( printedLines > 5 ) then    
  53.                 printedLines = 0
  54.                 printedColumns = printedColumns + 1
  55.             end
  56.         end
  57.     end
  58. end
  59.  
  60. function popup(msg,yPos)
  61.     term.setBackgroundColor(colors.green)
  62.     term.setTextColor(colors.yellow)
  63.     term.setCursorPos(1, yPos)
  64.     term.clearLine()
  65.     write(msg)
  66. end
  67.  
  68. function drawScreen()
  69.     titleBar()
  70.     drawDestinations()
  71. end
  72.  
  73. function refill()
  74.     popup("Refilling ticket machine!",9)
  75.     sleep(1)
  76.     redstone.setOutput("back",true)
  77.     sleep(4)
  78.     redstone.setOutput("back",false)
  79.     drawScreen()
  80. end
  81.  
  82. function printTicket()
  83.     --print ticket
  84.     popup("Please take your ticket!",12)
  85.     ticketMachine.createTicket(LISTED_DESTINATIONS[clicked])
  86.    
  87.     local tableInfo = ticketMachine.getStackInSlot(1)
  88.    
  89.     if tableInfo == nil then
  90.         refill()
  91.     elseif tableInfo["qty"] < 2 then
  92.         refill()
  93.     else
  94.         drawScreen()
  95.     end
  96.  end
  97.  
  98. -- MAIN
  99. monitor = peripheral.wrap("top")
  100. ticketMachine = peripheral.wrap("left")
  101.  
  102. monitor.setTextScale(1)
  103. drawScreen()
  104.  
  105. while true do
  106. --wait for user interaction (click on a name)
  107.     local event, side, X, Y = os.pullEventRaw()
  108.    
  109.     if event == "monitor_touch" and side == "top" then
  110.     --popup("Clicked "..X..", "..Y..".")
  111.  
  112.  
  113.         if Y > 5 then
  114.             clicked = Y - 5
  115.             if X > 13 then
  116.                 clicked = clicked + 6
  117.             end
  118.         end
  119.         popup("Printing ticket to "..LISTED_DESTINATIONS[clicked].."!",11)
  120.         sleep(1)
  121.         printTicket(LISTED_DESTINATIONS[clicked])
  122.         sleep(2)
  123.     end
  124. end
Advertisement
Add Comment
Please, Sign In to add comment