lego11

Multa

Mar 6th, 2021 (edited)
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.34 KB | None | 0 0
  1.  
  2.  
  3. -- CONFIGURAZIONE
  4. -- Lato stampante
  5. LPT = "right"
  6.  
  7. -- DICHIARAZIONE VARIABILI
  8. local utente = ""
  9. local punti = 0
  10. local motivo = ""
  11. local patente = false
  12.  
  13. -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX
  14. local function drawPixelInternal(xPos, yPos)
  15.     term.setCursorPos(xPos, yPos)
  16.     term.write(" ")
  17. end
  18. local tColourLookup = {}
  19. for n = 1, 16 do
  20.     tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
  21. end
  22. function drawFilledBox(startX, startY, endX, endY, nColour)
  23.     if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
  24.         "number" or type(endY) ~= "number" or
  25.         (nColour ~= nil and type(nColour) ~= "number") then
  26.         error("Expected startX, startY, endX, endY, colour", 2)
  27.     end
  28.  
  29.     startX = math.floor(startX)
  30.     startY = math.floor(startY)
  31.     endX = math.floor(endX)
  32.     endY = math.floor(endY)
  33.  
  34.     if nColour then term.setBackgroundColor(nColour) end
  35.     if startX == endX and startY == endY then
  36.         drawPixelInternal(startX, startY)
  37.         return
  38.     end
  39.  
  40.     local minX = math.min(startX, endX)
  41.     if minX == startX then
  42.         minY = startY
  43.         maxX = endX
  44.         maxY = endY
  45.     else
  46.         minY = endY
  47.         maxX = startX
  48.         maxY = startY
  49.     end
  50.  
  51.     for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end
  52. end
  53. -- Icone
  54. function disegnaAvviso()
  55.     drawFilledBox(5, 6, 13, 13, colours.yellow)
  56.     for i = 7, 12, 1 do
  57.         paintutils.drawPixel(9, i, colours.black)
  58.         paintutils.drawPixel(9, 11, colours.yellow)
  59.     end
  60. end
  61. function disegnaFoglio()
  62.     drawFilledBox(4, 5, 18, 15, colours.white)
  63.     paintutils.drawPixel(6, 12, colours.lime)
  64.     paintutils.drawPixel(7, 13, colours.lime)
  65.     paintutils.drawPixel(8, 14, colours.lime)
  66.     px = 9
  67.     py = 13
  68.     for i = 1, 8, 1 do
  69.         paintutils.drawPixel(px, py, colours.lime)
  70.         px = px + 1
  71.         py = py - 1
  72.     end
  73. end
  74.  
  75. function disegnaStampante()
  76.     drawFilledBox(4, 10, 18, 15, colours.lightGrey)
  77.     drawFilledBox(6, 6, 16, 10, colours.white)
  78.     drawFilledBox(6, 14, 16, 14, colours.grey)
  79. end
  80.  
  81. -- Funzione pulisci
  82. function clear()
  83.     term.clear()
  84.     term.setCursorPos(1, 1)
  85. end
  86.  
  87. -- Funzioni colori
  88. function colore(sfumatura) term.setTextColour(sfumatura) end
  89. function fineColore() term.setTextColour(colours.white) end
  90. function sfondo(sfumaturaSfondo) term.setBackgroundColour(sfumaturaSfondo) end
  91. function fineSfondo() term.setBackgroundColour(colours.black) end
  92.  
  93. -- Disegna il Titolo
  94. function disegnaTitolo()
  95.     local tx, ty = term.getCursorPos()
  96.     term.setCursorPos(1, 1)
  97.     colore(colours.black)
  98.     sfondo(colours.yellow)
  99.     print("            Creazione Guidata Sanzione               ")
  100.     fineColore()
  101.     fineSfondo()
  102.     term.setCursorPos(tx, ty)
  103. end
  104.  
  105. -- Schermata punti
  106. function finestrapunti()
  107.     -- Schermata iniziale
  108.     clear()
  109.     sfondo(colours.black)
  110.     term.clear()
  111.     disegnaTitolo()
  112.  
  113.     term.setCursorPos(1, 3)
  114.     print(
  115.         "Inserire i dati richiesti. Se il campo è corretto, diventerè verde. In caso contrario il computer chiederà di reinserire il dato. Per annullare premere CTRL+T.")
  116.     -- Intestatario del contratto
  117.     term.setCursorPos(1, 9)
  118.     term.write("A carico di:")
  119.     term.setCursorPos(15, 9)
  120.     fineColore()
  121.     if utente == nil or utente == "" then utente = read() end
  122.     term.setCursorPos(15, 9)
  123.     colore(colours.lime)
  124.     term.write(utente)
  125.     fineColore()
  126.     term.setCursorPos(1, 11)
  127.     term.write("Motivo:")
  128.     term.setCursorPos(15, 11)
  129.     fineColore()
  130.     if motivo == nil or motivo == "" then motivo = read() end
  131.     term.setCursorPos(15, 11)
  132.     colore(colours.lime)
  133.     term.write(motivo)
  134.     fineColore()
  135.  
  136.     -- Lettura contatore punti
  137.     colore(colours.white)
  138.     term.setCursorPos(1, 13)
  139.     term.write("Punti:")
  140.     term.setCursorPos(15, 13)
  141.     fineColore()
  142.     puntiAccettato = false
  143.     conteggioErrori = 0
  144.     while puntiAccettato == false do
  145.         punti = read()
  146.         colore(colours.white)
  147.         term.setCursorPos(14, 13)
  148.         fineColore()
  149.         if tonumber(punti) == "" or tonumber(punti) == nil or
  150.             tonumber(punti) < 0 then
  151.             term.setCursorPos(15, 13)
  152.             colore(colours.red)
  153.             term.write("Il dato immesso non corrisponde    ")
  154.             fineColore()
  155.             sleep(2)
  156.             term.setCursorPos(15, 13)
  157.             term.write("                                   ")
  158.             term.setCursorPos(15, 13)
  159.         else
  160.             term.setCursorPos(15, 13)
  161.             colore(colours.lime)
  162.             term.write(punti .. " Wh")
  163.             puntiAccettato = true
  164.  
  165.         end
  166.     end
  167.  
  168.     -- Calcolo totale contatore punti
  169.     importo = 2000 * punti
  170. end
  171.  
  172. -- MAIN LOOP
  173. -- DEL PROGRAMMA
  174.  
  175. -- Stampante
  176. lpt = peripheral.wrap(LPT)
  177.  
  178. sfondo(colors.black)
  179. clear()
  180.  
  181. local dialogoAltroCont = false
  182. while dialogoAltroCont == false do
  183.     finestrapunti()
  184.     dialogoAltroCont = true
  185. end
  186.  
  187. clear()
  188. disegnaTitolo()
  189. sleep(0.5)
  190.  
  191. fineSfondo()
  192. fineColore()
  193. clear()
  194. disegnaTitolo()
  195. term.setCursorPos(1, 3)
  196.  
  197. print("Riepilogo:\n")
  198.  
  199. -- Controllo variabili
  200.  
  201. if punti == nil or punti == "" then punti = 0 end
  202. if importo == nil or importo == "" then importo = 0 end
  203.  
  204. colore(colors.lightGray)
  205. print("Sanzione")
  206. fineColore()
  207. print(" Punti       : " .. punti)
  208. print(" Importo    : " .. importo .. " IC\n")
  209.  
  210. colore(colors.lightGray)
  211. term.setCursorPos(26, 5)
  212. print("Motivo")
  213. fineColore()
  214. term.setCursorPos(27, 6)
  215. print(motivo)
  216.  
  217. term.setCursorPos(9, 17)
  218. sfondo(colors.red)
  219. colore(colors.black)
  220. term.write("   Annulla    ")
  221. term.setCursorPos(28, 17)
  222. sfondo(colors.lime)
  223. colore(colors.black)
  224. term.write("   Conferma   ")
  225. fineColore()
  226. fineSfondo()
  227.  
  228. local scelta = false
  229. while scelta == false do
  230.     event, key, x, y = os.pullEvent("mouse_click")
  231.     if event == "mouse_click" and x > 9 and x < 23 and y == 17 then
  232.         scelta = true
  233.         continua = false
  234.     elseif event == "mouse_click" and x > 28 and x < 42 and y == 17 then
  235.         scelta = true
  236.         continua = true
  237.     end
  238. end
  239.  
  240. clear()
  241. if continua == true then
  242.     -- Recupera data
  243.     local phpdate = http.get("http://172.16.20.220/data.php?q=rgr")
  244.     local date = phpdate.readAll()
  245.     phpdate.close()
  246.  
  247.     -- Stampa
  248.     stampantePronta = false
  249.     while stampantePronta == false do
  250.         if lpt.getPaperLevel() == 0 then
  251.             clear()
  252.             disegnaTitolo()
  253.             disegnaAvviso()
  254.             fineColore()
  255.             fineSfondo()
  256.             term.setCursorPos(22, 9)
  257.             term.write("Inserire")
  258.             term.setCursorPos(22, 10)
  259.             term.write("carta")
  260.             term.setCursorPos(22, 11)
  261.             term.write("nella stampante")
  262.             term.setCursorPos(22, 13)
  263.             sfondo(colors.lime)
  264.             term.write("   OK   ")
  265.             fineSfondo()
  266.             attesa = false
  267.             while attesa == false do
  268.                 event, key, x, y = os.pullEvent("mouse_click")
  269.                 if event == "mouse_click" and x > 22 and x < 31 and y == 13 then
  270.                     attesa = true
  271.                 end
  272.             end
  273.  
  274.         elseif lpt.getInkLevel() == 0 then
  275.             clear()
  276.             disegnaTitolo()
  277.             disegnaAvviso()
  278.             fineColore()
  279.             fineSfondo()
  280.             term.setCursorPos(22, 9)
  281.             term.write("Inserire")
  282.             term.setCursorPos(22, 10)
  283.             term.write("inchiostro")
  284.             term.setCursorPos(22, 11)
  285.             term.write("nella stampante")
  286.             term.setCursorPos(22, 13)
  287.             sfondo(colors.lime)
  288.             term.write("   OK   ")
  289.             fineSfondo()
  290.             attesa = false
  291.             while attesa == false do
  292.                 event, key, x, y = os.pullEvent("mouse_click")
  293.                 if event == "mouse_click" and x > 22 and x < 31 and y == 13 then
  294.                     attesa = true
  295.                 end
  296.             end
  297.  
  298.         else
  299.             stampantePronta = true
  300.         end
  301.     end
  302.  
  303.     clear()
  304.     disegnaTitolo()
  305.     disegnaStampante()
  306.     fineColore()
  307.     fineSfondo()
  308.     term.setCursorPos(22, 9)
  309.     term.write("Stampa")
  310.     term.setCursorPos(22, 10)
  311.     term.write("sanzione")
  312.     term.setCursorPos(22, 11)
  313.     term.write("in corso")
  314.     term.setCursorPos(22, 13)
  315.     lpt.newPage()
  316.     lpt.setPageTitle("Sanzione ANSF")
  317.     lpt.write("----| A N S F |----")
  318.     lpt.setCursorPos(1,3)
  319.     lpt.write("Autorità Nazionale")
  320.     lpt.setCursorPos(1,4)
  321.     lpt.write("Sicurezza Ferroviaria")
  322.     lpt.setCursorPos(1,6)
  323.     lpt.write("Sanzione a carico di:")
  324.     lpt.setCursorPos(1,7)
  325.     lpt.write(utente)
  326.     lpt.setCursorPos(1,9)
  327.     lpt.write("Punti: ")
  328.     lpt.setCursorPos(7,9)
  329.     lpt.write(punti)
  330.     lpt.setCursorPos(1,11)
  331.     lpt.write("Importo da pagare:")
  332.     lpt.setCursorPos(1,12)
  333.     lpt.write(importo.." IC")
  334.     lpt.setCursorPos(1,14)
  335.     lpt.write("Entro 3 giorni dal:")
  336.     lpt.setCursorPos(1,15)
  337.     lpt.write(date)
  338.     lpt.setCursorPos(1,17)
  339.     lpt.write("Motivo:")
  340.     lpt.setCursorPos(1,18)
  341.     lpt.write(motivo)
  342.     lpt.endPage()
  343.  
  344.     motivo = string.gsub(motivo, "%s", "%20")
  345.     endpoint =  http.get("http://172.16.20.227/~fabrimat/rgr/fine.php?player="..utente.."&reason="..motivo.."&points="..punti)
  346.     endpoint.readAll()
  347.     endpoint.close()
  348.  
  349.     sleep(2)
  350. end
Add Comment
Please, Sign In to add comment