lego11

ACC Thwolle

Feb 8th, 2021 (edited)
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.01 KB | None | 0 0
  1. function clear()
  2.     term.clear()
  3.     term.setCursorPos(1, 1)
  4. end
  5.  
  6. -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX
  7. local function drawPixelInternal(xPos, yPos)
  8.     term.setCursorPos(xPos, yPos)
  9.     term.write(" ")
  10. end
  11.  
  12. local tColourLookup = {}
  13. for n = 1, 16 do
  14.     tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
  15. end
  16.  
  17. function drawFilledBox(startX, startY, endX, endY, nColour)
  18.     if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
  19.         "number" or type(endY) ~= "number" or
  20.         (nColour ~= nil and type(nColour) ~= "number") then
  21.         error("Expected startX, startY, endX, endY, colour", 2)
  22.     end
  23.  
  24.     startX = math.floor(startX)
  25.     startY = math.floor(startY)
  26.     endX = math.floor(endX)
  27.     endY = math.floor(endY)
  28.  
  29.     if nColour then term.setBackgroundColor(nColour) end
  30.     if startX == endX and startY == endY then
  31.         drawPixelInternal(startX, startY)
  32.         return
  33.     end
  34.  
  35.     local minX = math.min(startX, endX)
  36.     if minX == startX then
  37.         minY = startY
  38.         maxX = endX
  39.         maxY = endY
  40.     else
  41.         minY = endY
  42.         maxX = startX
  43.         maxY = startY
  44.     end
  45.  
  46.     for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end
  47. end
  48.  
  49. function testo(sfumatura) term.setTextColour(sfumatura) end
  50.  
  51. function sfondo(sfumaturaSfondo) term.setBackgroundColour(sfumaturaSfondo) end
  52.  
  53. function disegnaDeviatoio(x, y, colore, lato)
  54.     if colors.test(rs.getBundledInput("bottom"), colore) then
  55.         term.setCursorPos(x, y)
  56.         if lato == "dx" then
  57.             term.write("/")
  58.         else
  59.             term.write("\\")
  60.         end
  61.     else
  62.         term.setCursorPos(x, y)
  63.         term.write("-")
  64.     end
  65. end
  66.  
  67. function disegnaSegnale(x, y, colore)
  68.     if colors.test(rs.getBundledInput("bottom"), colore) then
  69.         paintutils.drawPixel(x, y, colors.lime)
  70.     else
  71.         paintutils.drawPixel(x, y, colors.red)
  72.     end
  73. end
  74.  
  75. function disegnaSegnaleDoppio(x, y, colore1, colore2)
  76.     if colors.test(rs.getBundledInput("bottom"), colore1) then
  77.         paintutils.drawPixel(x, y, colors.red)
  78.         paintutils.drawPixel(x, y+1, colors.lime)
  79.     else
  80.         paintutils.drawPixel(x, y, colors.lime)
  81.         paintutils.drawPixel(x, y+1, colors.black)
  82.     end
  83. end
  84.  
  85. function disegnaQLV()
  86.     sfondo(colors.white)
  87.     testo(colors.black)
  88.     clear()
  89.     term.setCursorPos(1, 1)
  90.     qlv = paintutils.loadImage("qlv")
  91.     paintutils.drawImage(qlv, 1, 1)
  92.  
  93.     -- Segnali
  94.     --protezione S1
  95.     sfondo(colors.white)
  96.     testo(colors.black)
  97.     term.setCursorPos(3, 10)
  98.     term.write("|")
  99.     disegnaSegnaleDoppio(3, 8, colors.white)
  100.     sfondo(colors.white)
  101.     testo(colors.black)
  102.     term.setCursorPos(5, 10)
  103.     term.write("|")
  104.     disegnaSegnale(5, 9, colors.lightBlue)
  105.     sfondo(colors.white)
  106.     testo(colors.black)
  107.     term.setCursorPos(48, 10)
  108.     term.write("|")
  109.     disegnaSegnale(48, 9, colors.orange)
  110.     sfondo(colors.white)
  111.     testo(colors.black)
  112.     term.setCursorPos(48, 16)
  113.     term.write("|")
  114.     disegnaSegnale(48, 15, colors.magenta)
  115.     sfondo(colors.white)
  116.     testo(colors.green)
  117.  
  118.     -- numeri binari
  119.     term.setCursorPos(24, 6)
  120.     term.write("IV")
  121.     term.setCursorPos(24, 8)
  122.     term.write("III")
  123.     term.setCursorPos(24, 10)
  124.     term.write("II")
  125.     term.setCursorPos(25, 12)
  126.     term.write("I")
  127.  
  128.     -- origini itinerari
  129.     testo(colors.red)
  130.     term.setCursorPos(2, 12)
  131.     term.write("1")
  132.     term.setCursorPos(46, 10)
  133.     term.write("2")
  134.     term.setCursorPos(46, 14)
  135.     term.write("3")
  136.  
  137.     --FV e destinazioni
  138.     testo(colors.black)
  139.     term.setCursorPos(2, 15)
  140.     term.write("Piana                 F V")
  141.     term.setCursorPos(2, 16)
  142.     term.write("di Odessa")
  143.     term.setCursorPos(40, 18)
  144.     term.write("New R. Dateo")
  145.     term.setCursorPos(45, 7)
  146.     term.write("Tangara")
  147.  
  148.     --Pulsanti
  149.     sfondo(colours.red)
  150.     testo(colors.white)
  151.     term.setCursorPos(2, 2)
  152.     -- 2 -> 11, 2
  153.     term.write(" TLBCA 1 ")
  154.     term.setCursorPos(12, 2)
  155.     -- 12 -> 21, 2
  156.     term.write(" TLBCA 2 ")
  157.     term.setCursorPos(22, 2)
  158.     -- 22 -> 31, 2
  159.     term.write(" TLBCA 3 ")
  160.     sfondo(colors.cyan)
  161.     term.setCursorPos(2, 4)
  162.     -- 2 -> 7, 4
  163.     term.write(" 1-I ")
  164.     term.setCursorPos(8, 4)
  165.     -- 7 -> 13, 4
  166.     term.write(" 1-II ")
  167.    
  168.     --Deviatoi
  169.     --Comunicazione 01a/b
  170.     sfondo(colors.gray)
  171.     disegnaDeviatoio(9, 11, colors.white, "sx")
  172.     disegnaDeviatoio(9, 13, colors.white, "sx")
  173.     --Comunicazione 03a/b (fissa)
  174.     term.setCursorPos(45, 11)
  175.     term.write("\\")
  176.     term.setCursorPos(45, 13)
  177.     term.write("\\")
  178.  
  179. end
  180.  
  181.  
  182.  
  183. function disegnaConferma(domanda)
  184.     drawFilledBox(14, 8, 37, 14, colors.lightBlue)
  185.     term.setCursorPos(15, 9)
  186.     term.write("Eseguire il comando?")
  187.     term.setCursorPos(15, 10)
  188.     term.write(domanda)
  189.     testo(colors.black)
  190.     sfondo(colors.red)
  191.     term.setCursorPos(16, 13)
  192.     term.write("   No   ")
  193.     testo(colors.black)
  194.     sfondo(colors.lime)
  195.     term.setCursorPos(28, 13)
  196.     term.write("   Si   ")
  197.     testo(colors.black)
  198.     sfondo(colors.white)
  199.  
  200.     local scelta = false
  201.     while scelta == false do
  202.         event, key, x, y = os.pullEvent("mouse_click")
  203.         if event == "mouse_click" and x > 16 and x < 24 and y == 13 then
  204.             scelta = true
  205.             return false
  206.         elseif event == "mouse_click" and x > 28 and x < 36 and y == 13 then
  207.             scelta = true
  208.             return true
  209.         end
  210.     end
  211. end
  212.  
  213. while true do
  214.     disegnaQLV()
  215.     event, par1, x, y = os.pullEvent()
  216.     if event == "mouse_click" then
  217.         if x < 11 and x > 2 and y == 2 and disegnaConferma("TLBCA 1") then
  218.             rs.setBundledOutput("bottom", colors.yellow)
  219.             rs.setOutput("top", true)
  220.             sleep(0.5)
  221.             rs.setOutput("top", false)
  222.             rs.setBundledOutput("bottom", 0)
  223.         end
  224.         if x < 21 and x > 12 and y == 2 and disegnaConferma("TLBCA 2") then
  225.             rs.setBundledOutput("bottom", colors.lime)
  226.             rs.setOutput("top", true)
  227.             sleep(0.5)
  228.             rs.setOutput("top", false)
  229.             rs.setBundledOutput("bottom", 0)
  230.         end
  231.         if x < 31 and x > 22 and y == 2 and disegnaConferma("TLBCA 3") then
  232.             rs.setBundledOutput("bottom", colors.pink)
  233.             rs.setOutput("top", true)
  234.             sleep(0.5)
  235.             rs.setOutput("top", false)
  236.             rs.setBundledOutput("bottom", 0)
  237.         end
  238.         if x < 7 and x > 2 and y == 4 then
  239.             rs.setBundledOutput("bottom", colors.gray)
  240.             rs.setOutput("top", true)
  241.             sleep(0.5)
  242.             rs.setOutput("top", false)
  243.             rs.setBundledOutput("bottom", 0)
  244.         end
  245.         if x < 13 and x > 8 and y == 4 then
  246.             rs.setBundledOutput("bottom", colors.lightGray)
  247.             rs.setOutput("top", true)
  248.             sleep(0.5)
  249.             rs.setOutput("top", false)
  250.             rs.setBundledOutput("bottom", 0)
  251.         end
  252.     end
  253. end
Add Comment
Please, Sign In to add comment