Advertisement
Jonas_spielt

TRIS.app

Mar 24th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.67 KB | None | 0 0
  1. local haltestellen = {}
  2. haltestellen["hbf_u_gruen_1"] = "HBF 1"
  3. haltestellen["hbf_u_gruen_2"] = "HBF 2"
  4. haltestellen["ubahn_arena_1"] = "Fraser Ave 1"
  5. haltestellen["ubahn_arena_2"] = "Fraser Ave 2"
  6. haltestellen["ubahn_larsen_ave_1"] = "Larsen Ave 1"
  7. haltestellen["ubahn_larsen_ave_2"] = "Larsen Ave 2"
  8. haltestellen["u_bibliothek_1"] = "Harbour St 1"
  9. haltestellen["u_bibliothek_2"] = "Harbour St 2"
  10. haltestellen["uni_u_gruen_1"] = "Uni 1"
  11. haltestellen["uni_u_gruen_2"] = "Uni 2"
  12.  
  13. if not fs.exists("./icons/TRIS.icon") then
  14.     local handle = fs.open("./icons/TRIS.icon","w")
  15.     handle.writeLine(" 70 7b 70 70 80")
  16.     handle.writeLine(" 7bs70v70b70 7b")
  17.     handle.writeLine(" 70 80 70 7b 70")
  18.     handle.close()
  19. end
  20. local xsize, ysize = term.getSize()
  21. function drawTopBar()
  22.     paintutils.drawFilledBox(1,1,xsize,2,colors.lightBlue)
  23.     term.setCursorPos(3,2)
  24.     term.setTextColor(colors.white)
  25.     term.setBackgroundColor(colors.lightBlue)
  26.     term.write("Transportinfo")
  27. end
  28.  
  29. function drawCardsPage()
  30.     drawTopBar()
  31.     paintutils.drawFilledBox(1,3,xsize,ysize,colors.white)
  32.     term.setTextColor(colors.white)
  33.     term.setBackgroundColor(colors.lightGray)
  34.     paintutils.drawLine(1,3,xsize,3, colors.white)
  35.    
  36.     local newsicon = " 0e 0e 0e 0e 0e 0e 0e\n 0e 0e 0e 0e 0e 00 0e\n 0e 0e 0e 00 0e 00 0e\n 0e 00 0e 00 0e 00 0e\n 0e 0e 0e 0e 0e 0e 0e"
  37.     png.drawImageString(4,7,newsicon)
  38.     local stationicon = " 0d 0d 0d 0d 0d 0d 0d\n 0d 0b 0d 0d 0d 0d 0d\n 0d 00 0d 0e 0e 0e 0d\n 0d 00 0d 00 0d 00 0d\n 0d 0d 0d 0d 0d 0d 0d"
  39.     png.drawImageString(17,7,stationicon)
  40.     term.setTextColor(colors.black)
  41.     term.setBackgroundColor(colors.white)
  42.     term.setCursorPos(2,13)
  43.     term.write("Nachrichten    Station")
  44.  
  45.     term.setCursorPos(xsize/2-1,ysize)
  46.     term.setTextColor(colors.lightGray)
  47.     term.setBackgroundColor(colors.white)
  48.     term.write("()")
  49.     while true do
  50.         local event, button, x, y = os.pullEvent("mouse_click")
  51.         if x == xsize-1 and y == 2 then
  52.             drawAddCardPage()
  53.             return
  54.         elseif (x == xsize/2-1 or x == xsize/2) and y == ysize then
  55.             return
  56.         elseif x >= 4 and x <= 11 and y >= 7 and y <= 12 then
  57.             drawNewsPage()
  58.             return
  59.         elseif x >= 17 and x <= 21 and y >= 7 and y <= 12 then
  60.             drawStationPage()
  61.             return
  62.         end
  63.     end
  64. end
  65.  
  66. function drawNewsPage()
  67.     drawTopBar()
  68.     paintutils.drawFilledBox(1,3,xsize,ysize,colors.white)
  69.     term.setCursorPos(1,2)
  70.     term.setBackgroundColor(colors.lightBlue)
  71.     term.setTextColor(colors.white)
  72.     term.write("<")
  73.     term.setTextColor(colors.white)
  74.     term.setBackgroundColor(colors.lightGray)
  75.     paintutils.drawLine(1,3,xsize,3, colors.lightGray)
  76.     term.setCursorPos(3,3)
  77.     term.write("Nachrichten aendern")
  78.     term.setCursorPos(2,6)
  79.     term.setTextColor(colors.blue)
  80.     term.setBackgroundColor(colors.white)
  81.     term.write("Text:")
  82.     paintutils.drawLine(2,8,25,8,colors.gray)
  83.     term.setCursorPos(math.ceil(xsize/2)-3,10)
  84.     term.setBackgroundColor(colors.blue)
  85.     term.setTextColor(colors.white)
  86.     term.write("Senden")
  87.     term.setCursorPos(xsize/2-1,ysize)
  88.     term.setTextColor(colors.lightGray)
  89.     term.setBackgroundColor(colors.white)
  90.     term.write("()")
  91.     local text = ""
  92.     while true do
  93.         local event, button, x, y = os.pullEvent("mouse_click")
  94.         if x == 1 and y == 2 then
  95.             drawCardsPage()
  96.             return
  97.         elseif (x == xsize/2-1 or x == xsize/2) and y == ysize then
  98.             return
  99.         elseif x >= 2 and x <= 25 and y == 8 then
  100.             term.setCursorPos(2,8)
  101.             term.setBackgroundColor(colors.gray)
  102.             term.setTextColor(colors.lightGray)
  103.             text = read()
  104.         elseif x >= math.ceil(xsize/2)-3 and x <= math.ceil(xsize/2)+3 and y == 10 then
  105.             local tablex = {}
  106.             tablex["Protocol"] = "ctOS"
  107.             network.send("center.transport.ctOS","News.send",text,nil,tablex)
  108.             drawCardsPage()
  109.             return
  110.         end
  111.     end
  112. end
  113.  
  114. function drawStationPage()
  115.     local stations = {}
  116.     local i = 0
  117.     for k,v in pairs(haltestellen) do
  118.         stations[i] = k
  119.         i=i+1
  120.     end
  121.     drawTopBar()
  122.     paintutils.drawFilledBox(1,3,xsize,ysize,colors.white)
  123.     term.setCursorPos(1,2)
  124.     term.setBackgroundColor(colors.lightBlue)
  125.     term.setTextColor(colors.white)
  126.     term.write("<")
  127.     term.setTextColor(colors.white)
  128.     term.setBackgroundColor(colors.lightGray)
  129.     paintutils.drawLine(1,3,xsize,3, colors.lightGray)
  130.     term.setCursorPos(3,3)
  131.     term.write("Fahrt eintragen")
  132.     paintutils.drawLine(2,5,25,5,colors.gray)
  133.     term.setCursorPos(2,5)
  134.     term.setBackgroundColor(colors.gray)
  135.     term.setTextColor(colors.lightGray)
  136.     term.write("Haltestelle waehlen    v")
  137.     term.setCursorPos(2,7)
  138.     term.setTextColor(colors.blue)
  139.     term.setBackgroundColor(colors.white)
  140.     term.write("Uhrzeit:")
  141.     paintutils.drawLine(15,7,19,7,colors.gray)
  142.     term.setCursorPos(2,9)
  143.     term.setTextColor(colors.blue)
  144.     term.setBackgroundColor(colors.white)
  145.     term.write("Minuten:")
  146.     paintutils.drawLine(15,9,17,9,colors.gray)
  147.  
  148.     term.setCursorPos(2,11)
  149.     term.setTextColor(colors.blue)
  150.     term.setBackgroundColor(colors.white)
  151.     term.write("Text:")
  152.     paintutils.drawLine(2,13,25,13,colors.gray)
  153.     term.setCursorPos(math.ceil(xsize/2)-3,15)
  154.     term.setBackgroundColor(colors.blue)
  155.     term.setTextColor(colors.white)
  156.     term.write("Senden")
  157.     term.setCursorPos(xsize/2-1,ysize)
  158.     term.setTextColor(colors.lightGray)
  159.     term.setBackgroundColor(colors.white)
  160.     term.write("()")
  161.     local text = ""
  162.     local uhrzeit = nil
  163.     local delay = nil
  164.     while true do
  165.         local event, button, x, y = os.pullEvent("mouse_click")
  166.         if x == 1 and y == 2 then
  167.             drawCardsPage()
  168.             return
  169.         elseif (x == xsize/2-1 or x == xsize/2) and y == ysize then
  170.             return
  171.         elseif x >= 2 and x <= 25 and y == 13 then
  172.             term.setCursorPos(2,13)
  173.             term.setBackgroundColor(colors.gray)
  174.             term.setTextColor(colors.lightGray)
  175.             text = read()
  176.         elseif x >= 15 and x <= 19 and y == 7 then
  177.             term.setCursorPos(15,7)
  178.             term.setBackgroundColor(colors.gray)
  179.             term.setTextColor(colors.lightGray)
  180.             uhrzeit = read()
  181.         elseif x >= 15 and x <= 17 and y == 9 then
  182.             term.setCursorPos(15,9)
  183.             term.setBackgroundColor(colors.gray)
  184.             term.setTextColor(colors.lightGray)
  185.             delay = read()
  186.         elseif x >= 2 and x <= 25 and y == 5 then
  187.             paintutils.drawLine(2,5,25,5,colors.blue)
  188.             term.setCursorPos(2,5)
  189.             term.setBackgroundColor(colors.blue)
  190.             term.setTextColor(colors.white)
  191.             term.write(haltestellen[stations[0]])
  192.             i = 0
  193.             while true do
  194.                 local e, k, isHeld = os.pullEvent("key")
  195.                 if k == 28 then
  196.                     paintutils.drawLine(2,5,25,5,colors.gray)
  197.                     term.setCursorPos(2,5)
  198.                     term.setBackgroundColor(colors.gray)
  199.                     term.setTextColor(colors.lightGray)
  200.                     term.write(haltestellen[stations[i]])
  201.                     break
  202.                 end
  203.                 if k == 200 then
  204.                     i = i - 1
  205.                 elseif k == 208 then
  206.                     i = i + 1
  207.                 end
  208.                 if i < 0 then
  209.                     i = 0
  210.                 elseif i > table.getn(stations) then
  211.                     i = table.getn(stations)
  212.                 end
  213.                 paintutils.drawLine(2,5,25,5,colors.blue)
  214.                 term.setCursorPos(2,5)
  215.                 term.setBackgroundColor(colors.blue)
  216.                 term.setTextColor(colors.white)
  217.                 term.write(haltestellen[stations[i]])
  218.             end
  219.         elseif x >= math.ceil(xsize/2)-3 and x <= math.ceil(xsize/2)+3 and y == 15 then
  220.             local tablex = {}
  221.             tablex["Protocol"] = "ctOS"
  222.             local data = {}
  223.             data[1] = stations[i]
  224.             data[2] = text
  225.             if not uhrzeit == nil then
  226.                 request = "Arrivals.ByTime.send"
  227.                 data[3] = uhrzeit
  228.             else
  229.                 request = "Arrivals.ByDelay.send"
  230.                 data[3] = tonumber(delay)
  231.             end
  232.             network.send("center.transport.ctOS",request,data,nil,tablex)
  233.             drawCardsPage()
  234.             return
  235.         end
  236.     end
  237. end
  238.  
  239. function drawAddCardPage()
  240.     drawTopBar()
  241.     paintutils.drawFilledBox(1,3,xsize,ysize,colors.white)
  242.     term.setCursorPos(1,2)
  243.     term.setBackgroundColor(colors.lime)
  244.     term.setTextColor(colors.white)
  245.     term.write("<")
  246.     term.setTextColor(colors.white)
  247.     term.setBackgroundColor(colors.lightGray)
  248.     paintutils.drawLine(1,3,xsize,3, colors.lightGray)
  249.     term.setCursorPos(3,3)
  250.     term.write("Konto hinzufuegen")
  251.     term.setCursorPos(2,6)
  252.     term.setTextColor(colors.blue)
  253.     term.setBackgroundColor(colors.white)
  254.     term.write("Kontonummer:")
  255.     paintutils.drawLine(15,6,22,6,colors.gray)
  256.     term.setCursorPos(2,8)
  257.     term.setTextColor(colors.blue)
  258.     term.setBackgroundColor(colors.white)
  259.     term.write("PIN:")
  260.     paintutils.drawLine(15,8,18,8,colors.gray)
  261.     term.setCursorPos(math.ceil(xsize/2)-5,10)
  262.     term.setBackgroundColor(colors.lightGray)
  263.     term.setTextColor(colors.white)
  264.     term.write("Hinzufuegen")
  265.     term.setCursorPos(xsize/2-1,ysize)
  266.     term.setTextColor(colors.lightGray)
  267.     term.setBackgroundColor(colors.white)
  268.     term.write("()")
  269.     local pin = nil
  270.     local knummer = nil
  271.     while true do
  272.         local event, button, x, y = os.pullEvent("mouse_click")
  273.         if x == 1 and y == 2 then
  274.             drawCardsPage()
  275.             return
  276.         elseif (x == xsize/2-1 or x == xsize/2) and y == ysize then
  277.             return
  278.         elseif x >= 15 and x <= 22 and y == 6 then
  279.             term.setCursorPos(15,6)
  280.             term.setBackgroundColor(colors.gray)
  281.             term.setTextColor(colors.lightGray)
  282.             knummer = read()
  283.             if pin and knummer then
  284.                 term.setCursorPos(math.ceil(xsize/2)-5,10)
  285.                 term.setBackgroundColor(colors.lime)
  286.                 term.setTextColor(colors.white)
  287.                 term.write("Hinzufuegen")
  288.             end
  289.         elseif x >= 15 and x <= 18 and y == 8 then
  290.             term.setCursorPos(15,8)
  291.             term.setBackgroundColor(colors.gray)
  292.             term.setTextColor(colors.lightGray)
  293.             pin = read("o")
  294.             if pin and knummer then
  295.                 term.setCursorPos(math.ceil(xsize/2)-5,10)
  296.                 term.setBackgroundColor(colors.lime)
  297.                 term.setTextColor(colors.white)
  298.                 term.write("Hinzufuegen")
  299.             end
  300.         elseif x >= math.ceil(xsize/2)-5 and x <= math.ceil(xsize/2)+5 and y == 10 then
  301.             if pin and knummer then
  302.                 term.setCursorPos(9,10)
  303.                 term.setBackgroundColor(colors.white)
  304.                 term.clearLine()
  305.                 term.setBackgroundColor(colors.blue)
  306.                 term.setTextColor(colors.white)
  307.                 term.write("Pruefen...")
  308.                 local tablex = {}
  309.                 tablex["ResponseID"] = rid
  310.                 tablex["Protocol"] = "ctOS"
  311.                 local rid = network.send("server.bankomat.ctOS","User.getData",knummer,nil,tablex)
  312.                 while true do
  313.                     local event, mSide, channel, rchannel, message = network.receive(10)
  314.                     if event == "modem_message" and message["Request"] == "User.getData.Response" and message["Sender"] == "server.bankomat.ctOS" and message["nMessageID"] == rid then
  315.                         if type(message["Data"]) ~= "nil" then
  316.                             if pin == tostring(message["Data"]["PIN"]) then
  317.                                 local tablex = {}
  318.                                 tablex["name"] = knummer
  319.                                 tablex["pin"] = tostring(message["Data"]["PIN"])
  320.                                 table.insert(cards, tablex)
  321.                                 local h = fs.open("storage/bankomat/."..knummer..".bankomat", "w")
  322.                                 h.write(pin)
  323.                                 h.close()
  324.                                 term.setCursorPos(8,10)
  325.                                 term.setBackgroundColor(colors.white)
  326.                                 term.clearLine()
  327.                                 term.setBackgroundColor(colors.lime)
  328.                                 term.setTextColor(colors.white)
  329.                                 term.write("Hinzugefuegt")
  330.                                 sleep(5)
  331.                                 drawAddCardPage()
  332.                                 break
  333.                             else
  334.                                 term.setCursorPos(9,10)
  335.                                 term.setBackgroundColor(colors.white)
  336.                                 term.clearLine()
  337.                                 term.setBackgroundColor(colors.red)
  338.                                 term.setTextColor(colors.white)
  339.                                 term.write("Inkorrekt")
  340.                                 sleep(5)
  341.                                 drawAddCardPage()
  342.                                 break
  343.                             end
  344.                         else
  345.                             term.setCursorPos(9,10)
  346.                             term.setBackgroundColor(colors.white)
  347.                             term.clearLine()
  348.                             term.setBackgroundColor(colors.red)
  349.                             term.setTextColor(colors.white)
  350.                             term.write("Inkorrekt")
  351.                             sleep(5)
  352.                             drawAddCardPage()
  353.                             break
  354.                         end
  355.                     elseif event == "timer" then
  356.                         term.setCursorPos(7,10)
  357.                         term.setBackgroundColor(colors.white)
  358.                         term.clearLine()
  359.                         term.setBackgroundColor(colors.red)
  360.                         term.setTextColor(colors.white)
  361.                         term.write("Netzwerkfehler")
  362.                         sleep(5)
  363.                         drawAddCardPage()
  364.                         break
  365.                     end
  366.                 end
  367.             end
  368.         end
  369.     end
  370. end
  371. term.setBackgroundColor(colors.white)
  372. term.clear()
  373. drawCardsPage()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement