DOGGYWOOF

GUI android touchscreen lockscreen

Mar 12th, 2024
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. local buttons = {
  2. { name = "1", x = 7, y = 4, width = 4, height = 3, color = colors.lightBlue },
  3. { name = "2", x = 13, y = 4, width = 4, height = 3, color = colors.lightBlue },
  4. { name = "3", x = 19, y = 4, width = 4, height = 3, color = colors.lightBlue },
  5. { name = "4", x = 7, y = 8, width = 4, height = 3, color = colors.lightBlue },
  6. { name = "5", x = 13, y = 8, width = 4, height = 3, color = colors.lightBlue },
  7. { name = "6", x = 19, y = 8, width = 4, height = 3, color = colors.lightBlue },
  8. { name = "7", x = 7, y = 12, width = 4, height = 3, color = colors.lightBlue },
  9. { name = "8", x = 13, y = 12, width = 4, height = 3, color = colors.lightBlue },
  10. { name = "9", x = 19, y = 12, width = 4, height = 3, color = colors.lightBlue },
  11. { name = "C", x = 7, y = 16, width = 4, height = 3, color = colors.red },
  12. { name = "0", x = 13, y = 16, width = 4, height = 3, color = colors.lightBlue },
  13. { name = "E", x = 19, y = 16, width = 4, height = 3, color = colors.green }
  14. }
  15.  
  16. local pinFilePath = "/disk/security/PIN.config"
  17.  
  18. local function readPINFromFile()
  19. local file = fs.open(pinFilePath, "r")
  20. local pin = file and file.readLine() or "0000"
  21. if file then
  22. file.close()
  23. end
  24. return pin
  25. end
  26.  
  27. local correctPIN = readPINFromFile()
  28.  
  29. local function drawPINScreen(enteredPIN)
  30. term.setBackgroundColor(colors.gray)
  31. term.setTextColor(colors.white)
  32. term.clear()
  33.  
  34. -- Display "Enter PIN" at the top center
  35. term.setCursorPos((term.getSize() - #"Enter PIN") / 2 + 1, 1)
  36. write("Enter PIN")
  37.  
  38. -- Display entered PIN right under "Enter PIN" text
  39. term.setCursorPos((term.getSize() - #enteredPIN) / 2 + 1, 2)
  40. write(string.rep("*", #enteredPIN))
  41.  
  42. for _, button in ipairs(buttons) do
  43. paintutils.drawBox(button.x, button.y, button.x + button.width - 1, button.y + button.height - 1, button.color)
  44. term.setCursorPos(button.x + 1, button.y + 1)
  45. write(button.name)
  46. end
  47. end
  48.  
  49. local function handleButtonClick(button)
  50. if button.name == "C" then
  51. -- Clear button
  52. return "C"
  53. elseif button.name == "E" then
  54. -- Enter button
  55. return "E"
  56. else
  57. return tostring(button.name)
  58. end
  59. end
  60.  
  61. local function enterPIN()
  62. local enteredPIN = ""
  63. local attempts = 3
  64.  
  65. while attempts > 0 do
  66. drawPINScreen(enteredPIN)
  67. term.setCursorBlink(false)
  68. term.setCursorPos(1, 18)
  69.  
  70. local event, button, x, y = os.pullEvent("mouse_click")
  71.  
  72. if event == "mouse_click" then
  73. for _, btn in ipairs(buttons) do
  74. if x >= btn.x and x < btn.x + btn.width and y >= btn.y and y < btn.y + btn.height then
  75. local result = handleButtonClick(btn)
  76. if result == "E" then
  77. if enteredPIN == correctPIN then
  78. term.clear()
  79. term.setCursorPos(1, 1)
  80. print("Access Granted!")
  81. -- Perform actions upon successful entry
  82. return
  83. else
  84. term.clear()
  85. term.setCursorPos(1, 1)
  86. print("Incorrect PIN. Try again.")
  87. attempts = attempts - 1
  88. if attempts == 0 then
  89. print("Access Denied!")
  90. else
  91. print("Attempts remaining: " .. attempts)
  92. end
  93. sleep(2)
  94. enteredPIN = ""
  95. end
  96. elseif result == "C" then
  97. enteredPIN = ""
  98. else
  99. enteredPIN = enteredPIN .. result
  100. end
  101. break
  102. end
  103. end
  104. end
  105. end
  106. end
  107.  
  108. enterPIN()
  109.  
Add Comment
Please, Sign In to add comment