Advertisement
cronoise

train destinations

Apr 25th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local button         = {}
  2. local side           = "front"
  3. local mon            = peripheral.wrap("monitor_15")
  4. local textScale      = 1
  5. local trackreset     = "back"
  6.  
  7. ------------ color variables ------------
  8.  
  9. local btnTextColor   = colors.black
  10. local defaultBgColor = colors.black
  11. local headerColor    = colors.green
  12.  
  13. -----------------------------------------
  14. rs.setBundledOutput(side, 0)  
  15. term.clear()
  16. term.setCursorPos(1,1)
  17. mon.setBackgroundColor(defaultBgColor)
  18. mon.setTextScale(textScale)
  19. mon.clear()
  20.        
  21. function fillTable()
  22.    setTable("End",         switchOutput,  2, 9,  3,  5, colors.white,     colors.lightGray,    colors.green)
  23.    setTable("Nether",      switchOutput,  2, 9,  7,  9, colors.orange,    colors.lightGray,    colors.green)    
  24.    setTable("Desti 3",     switchOutput,  2, 9, 11, 13, colors.magenta,   colors.lightGray,    colors.green)
  25.    setTable("Desti 4",     switchOutput,  2, 9, 15, 17, colors.lightBlue, colors.lightGray,    colors.green)      
  26.    setTable("Desti 5",     switchOutput, 11, 19,  3,  5, colors.yellow,    colors.lightGray,    colors.green)
  27.    setTable("Desti 6",     switchOutput, 11, 19,  7,  9, colors.lime,      colors.lightGray,    colors.green)
  28.    setTable("Desti 7",     switchOutput, 11, 19, 11, 13, colors.pink,      colors.lightGray,    colors.green)
  29.    setTable("Desti 8",     switchOutput, 11, 19, 15, 17, colors.gray,      colors.lightGray,    colors.green)
  30.    setTable("Desti 9",     switchOutput, 21, 28,  3,  5, colors.lightGray, colors.lightGray,    colors.green)
  31.    setTable("Desti 10",    switchOutput, 21, 28,  7,  9, colors.cyan,      colors.lightGray,    colors.green)
  32.    setTable("Desti 11",    switchOutput, 21, 28, 11, 13, colors.purple,    colors.lightGray,    colors.green)
  33.    setTable("Desti 12",    switchOutput, 21, 28, 15, 17, colors.blue,      colors.lightGray,    colors.green)
  34. ---   setTable("empty",      switchOutput, 59, 69,  3,  5, colors.brown,     colors.lightGray,    colors.green)
  35. ---   setTable("empty",         switchOutput, 59, 69,  7,  9, colors.green,     colors.lightGray,    colors.green)
  36. ---   setTable("empty",         switchOutput, 59, 69, 11, 13, colors.red,       colors.lightGray,    colors.green)
  37. ---   setTable("empty",     switchOutput, 59, 69, 15, 17, colors.black,     colors.lightGray,    colors.green)
  38. ---   setTable("All ON",       turnAllOn,      3, 13,  3,  9, "" ,             colors.green, colors.green)
  39. ---   setTable("All OFF",      turnAllOff,     3, 13, 11, 17, "" ,             colors.lightGray, colors.lightGray)
  40. end
  41.  
  42. function setTable(name, func, xmin, xmax, ymin, ymax, color, btnOff, btnOn)
  43.    button[name]           = {}
  44.    button[name]["func"]   = func
  45.    button[name]["active"] = false
  46.    button[name]["xmin"]   = xmin
  47.    button[name]["ymin"]   = ymin
  48.    button[name]["xmax"]   = xmax
  49.    button[name]["ymax"]   = ymax
  50.    button[name]["color"]  = color
  51.    button[name]["btnOff"] = btnOff
  52.    button[name]["btnOn"]  = btnOn
  53. end
  54.  
  55. function switchOutput(color)
  56.    if rs.testBundledInput(side, color) then
  57.      rs.setBundledOutput(side, (rs.getBundledInput(side)-color))
  58.    else
  59.      rs.setBundledOutput(side, (rs.getBundledInput(side)+color))
  60.    end
  61.    rs.setOutput( "right", true)
  62.    sleep(.1)
  63.    rs.setOutput("right", false)
  64. end  
  65.  
  66. function fill(text, color, bData)
  67.    mon.setBackgroundColor(color)
  68.    mon.setTextColor(btnTextColor)
  69.    local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  70.    local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  71.    for j = bData["ymin"], bData["ymax"] do
  72.       mon.setCursorPos(bData["xmin"], j)
  73.       if j == yspot then
  74.          for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  75.             if k == xspot then
  76.                mon.write(text)
  77.             else
  78.                mon.write(" ")
  79.             end
  80.          end
  81.       else
  82.          for i = bData["xmin"], bData["xmax"] do
  83.             mon.write(" ")
  84.          end
  85.       end
  86.    end
  87.    mon.setBackgroundColor(defaultBgColor)
  88. end
  89.      
  90. function screen()
  91.    local currColor
  92.    for name,data in pairs(button) do
  93.       local on = data["active"]
  94.       if on == true then currColor = data["btnOn"] else currColor = data["btnOff"] end
  95.       fill(name, currColor, data)
  96.    end
  97. end
  98.      
  99. function checkxy(x, y)
  100.    for name, data in pairs(button) do
  101.       if y>=data["ymin"] and  y <= data["ymax"] then
  102.          if x>=data["xmin"] and x<= data["xmax"] then
  103.             data["func"](button[name]["color"])
  104.             data["active"] = not data["active"]
  105.          end
  106.       end
  107.    end
  108. end
  109.      
  110. function heading(text)
  111.    w, h = mon.getSize()
  112.    mon.setTextColor(headerColor)
  113.    mon.setCursorPos((w-string.len(text))/2+1, 1)
  114.    mon.write(text)
  115. end
  116.      
  117. fillTable()
  118. while true do
  119.    mon.clear()
  120.    heading("Select Destination")
  121.    screen()
  122.  
  123.    local e,side,x,y = os.pullEvent("monitor_touch")
  124.    checkxy(x,y)
  125.    mon.clear()
  126.    heading("Enjoy your ride!")
  127.    screen()
  128.  
  129.    local e,redstone = os.pullEvent("redstone")
  130.     if rs.getInput("back") == true then
  131.      rs.setBundledOutput("front", 0)
  132.      for name, data in pairs(button) do
  133.       data["active"] = false
  134.       mon.clear()
  135.      heading("Select Destination")
  136.      screen()
  137.      end
  138.     end
  139.  
  140.    sleep(.1)
  141. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement