Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- CONFIGURAZIONE
- -- Lato stampante
- LPT = "right"
- -- DICHIARAZIONE VARIABILI
- local utente = ""
- local punti = 0
- local motivo = ""
- local patente = false
- -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX
- local function drawPixelInternal(xPos, yPos)
- term.setCursorPos(xPos, yPos)
- term.write(" ")
- end
- local tColourLookup = {}
- for n = 1, 16 do
- tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
- end
- function drawFilledBox(startX, startY, endX, endY, nColour)
- if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
- "number" or type(endY) ~= "number" or
- (nColour ~= nil and type(nColour) ~= "number") then
- error("Expected startX, startY, endX, endY, colour", 2)
- end
- startX = math.floor(startX)
- startY = math.floor(startY)
- endX = math.floor(endX)
- endY = math.floor(endY)
- if nColour then term.setBackgroundColor(nColour) end
- if startX == endX and startY == endY then
- drawPixelInternal(startX, startY)
- return
- end
- local minX = math.min(startX, endX)
- if minX == startX then
- minY = startY
- maxX = endX
- maxY = endY
- else
- minY = endY
- maxX = startX
- maxY = startY
- end
- for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end
- end
- -- Icone
- function disegnaAvviso()
- drawFilledBox(5, 6, 13, 13, colours.yellow)
- for i = 7, 12, 1 do
- paintutils.drawPixel(9, i, colours.black)
- paintutils.drawPixel(9, 11, colours.yellow)
- end
- end
- function disegnaFoglio()
- drawFilledBox(4, 5, 18, 15, colours.white)
- paintutils.drawPixel(6, 12, colours.lime)
- paintutils.drawPixel(7, 13, colours.lime)
- paintutils.drawPixel(8, 14, colours.lime)
- px = 9
- py = 13
- for i = 1, 8, 1 do
- paintutils.drawPixel(px, py, colours.lime)
- px = px + 1
- py = py - 1
- end
- end
- function disegnaStampante()
- drawFilledBox(4, 10, 18, 15, colours.lightGrey)
- drawFilledBox(6, 6, 16, 10, colours.white)
- drawFilledBox(6, 14, 16, 14, colours.grey)
- end
- -- Funzione pulisci
- function clear()
- term.clear()
- term.setCursorPos(1, 1)
- end
- -- Funzioni colori
- function colore(sfumatura) term.setTextColour(sfumatura) end
- function fineColore() term.setTextColour(colours.white) end
- function sfondo(sfumaturaSfondo) term.setBackgroundColour(sfumaturaSfondo) end
- function fineSfondo() term.setBackgroundColour(colours.black) end
- -- Disegna il Titolo
- function disegnaTitolo()
- local tx, ty = term.getCursorPos()
- term.setCursorPos(1, 1)
- colore(colours.black)
- sfondo(colours.yellow)
- print(" Creazione Guidata Sanzione ")
- fineColore()
- fineSfondo()
- term.setCursorPos(tx, ty)
- end
- -- Schermata punti
- function finestrapunti()
- -- Schermata iniziale
- clear()
- sfondo(colours.black)
- term.clear()
- disegnaTitolo()
- term.setCursorPos(1, 3)
- print(
- "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.")
- -- Intestatario del contratto
- term.setCursorPos(1, 9)
- term.write("A carico di:")
- term.setCursorPos(15, 9)
- fineColore()
- if utente == nil or utente == "" then utente = read() end
- term.setCursorPos(15, 9)
- colore(colours.lime)
- term.write(utente)
- fineColore()
- term.setCursorPos(1, 11)
- term.write("Motivo:")
- term.setCursorPos(15, 11)
- fineColore()
- if motivo == nil or motivo == "" then motivo = read() end
- term.setCursorPos(15, 11)
- colore(colours.lime)
- term.write(motivo)
- fineColore()
- -- Lettura contatore punti
- colore(colours.white)
- term.setCursorPos(1, 13)
- term.write("Punti:")
- term.setCursorPos(15, 13)
- fineColore()
- puntiAccettato = false
- conteggioErrori = 0
- while puntiAccettato == false do
- punti = read()
- colore(colours.white)
- term.setCursorPos(14, 13)
- fineColore()
- if tonumber(punti) == "" or tonumber(punti) == nil or
- tonumber(punti) < 0 then
- term.setCursorPos(15, 13)
- colore(colours.red)
- term.write("Il dato immesso non corrisponde ")
- fineColore()
- sleep(2)
- term.setCursorPos(15, 13)
- term.write(" ")
- term.setCursorPos(15, 13)
- else
- term.setCursorPos(15, 13)
- colore(colours.lime)
- term.write(punti .. " Wh")
- puntiAccettato = true
- end
- end
- -- Calcolo totale contatore punti
- importo = 2000 * punti
- end
- -- MAIN LOOP
- -- DEL PROGRAMMA
- -- Stampante
- lpt = peripheral.wrap(LPT)
- sfondo(colors.black)
- clear()
- local dialogoAltroCont = false
- while dialogoAltroCont == false do
- finestrapunti()
- dialogoAltroCont = true
- end
- clear()
- disegnaTitolo()
- sleep(0.5)
- fineSfondo()
- fineColore()
- clear()
- disegnaTitolo()
- term.setCursorPos(1, 3)
- print("Riepilogo:\n")
- -- Controllo variabili
- if punti == nil or punti == "" then punti = 0 end
- if importo == nil or importo == "" then importo = 0 end
- colore(colors.lightGray)
- print("Sanzione")
- fineColore()
- print(" Punti : " .. punti)
- print(" Importo : " .. importo .. " IC\n")
- colore(colors.lightGray)
- term.setCursorPos(26, 5)
- print("Motivo")
- fineColore()
- term.setCursorPos(27, 6)
- print(motivo)
- term.setCursorPos(9, 17)
- sfondo(colors.red)
- colore(colors.black)
- term.write(" Annulla ")
- term.setCursorPos(28, 17)
- sfondo(colors.lime)
- colore(colors.black)
- term.write(" Conferma ")
- fineColore()
- fineSfondo()
- local scelta = false
- while scelta == false do
- event, key, x, y = os.pullEvent("mouse_click")
- if event == "mouse_click" and x > 9 and x < 23 and y == 17 then
- scelta = true
- continua = false
- elseif event == "mouse_click" and x > 28 and x < 42 and y == 17 then
- scelta = true
- continua = true
- end
- end
- clear()
- if continua == true then
- -- Recupera data
- local phpdate = http.get("http://172.16.20.220/data.php?q=rgr")
- local date = phpdate.readAll()
- phpdate.close()
- -- Stampa
- stampantePronta = false
- while stampantePronta == false do
- if lpt.getPaperLevel() == 0 then
- clear()
- disegnaTitolo()
- disegnaAvviso()
- fineColore()
- fineSfondo()
- term.setCursorPos(22, 9)
- term.write("Inserire")
- term.setCursorPos(22, 10)
- term.write("carta")
- term.setCursorPos(22, 11)
- term.write("nella stampante")
- term.setCursorPos(22, 13)
- sfondo(colors.lime)
- term.write(" OK ")
- fineSfondo()
- attesa = false
- while attesa == false do
- event, key, x, y = os.pullEvent("mouse_click")
- if event == "mouse_click" and x > 22 and x < 31 and y == 13 then
- attesa = true
- end
- end
- elseif lpt.getInkLevel() == 0 then
- clear()
- disegnaTitolo()
- disegnaAvviso()
- fineColore()
- fineSfondo()
- term.setCursorPos(22, 9)
- term.write("Inserire")
- term.setCursorPos(22, 10)
- term.write("inchiostro")
- term.setCursorPos(22, 11)
- term.write("nella stampante")
- term.setCursorPos(22, 13)
- sfondo(colors.lime)
- term.write(" OK ")
- fineSfondo()
- attesa = false
- while attesa == false do
- event, key, x, y = os.pullEvent("mouse_click")
- if event == "mouse_click" and x > 22 and x < 31 and y == 13 then
- attesa = true
- end
- end
- else
- stampantePronta = true
- end
- end
- clear()
- disegnaTitolo()
- disegnaStampante()
- fineColore()
- fineSfondo()
- term.setCursorPos(22, 9)
- term.write("Stampa")
- term.setCursorPos(22, 10)
- term.write("sanzione")
- term.setCursorPos(22, 11)
- term.write("in corso")
- term.setCursorPos(22, 13)
- lpt.newPage()
- lpt.setPageTitle("Sanzione ANSF")
- lpt.write("----| A N S F |----")
- lpt.setCursorPos(1,3)
- lpt.write("Autorità Nazionale")
- lpt.setCursorPos(1,4)
- lpt.write("Sicurezza Ferroviaria")
- lpt.setCursorPos(1,6)
- lpt.write("Sanzione a carico di:")
- lpt.setCursorPos(1,7)
- lpt.write(utente)
- lpt.setCursorPos(1,9)
- lpt.write("Punti: ")
- lpt.setCursorPos(7,9)
- lpt.write(punti)
- lpt.setCursorPos(1,11)
- lpt.write("Importo da pagare:")
- lpt.setCursorPos(1,12)
- lpt.write(importo.." IC")
- lpt.setCursorPos(1,14)
- lpt.write("Entro 3 giorni dal:")
- lpt.setCursorPos(1,15)
- lpt.write(date)
- lpt.setCursorPos(1,17)
- lpt.write("Motivo:")
- lpt.setCursorPos(1,18)
- lpt.write(motivo)
- lpt.endPage()
- motivo = string.gsub(motivo, "%s", "%20")
- endpoint = http.get("http://172.16.20.227/~fabrimat/rgr/fine.php?player="..utente.."&reason="..motivo.."&points="..punti)
- endpoint.readAll()
- endpoint.close()
- sleep(2)
- end
Add Comment
Please, Sign In to add comment