Advertisement
HangMan23

numpad.lua

Feb 7th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.28 KB | None | 0 0
  1. local fs = require("filesystem")
  2. local gpu = require("component").gpu
  3. local term = require("term")
  4. local event = require("event")
  5. local io = require("io")
  6. local unicode = require("unicode")
  7. local computer = require("computer")
  8. local shell = require("shell")
  9.  
  10. arg = shell.parse(...)
  11.  
  12. if arg[1] == "res" then res = true else res = false end
  13.  
  14. function draw(mas)
  15.  
  16. for i = 1, #mas do
  17.  
  18. if mas [i][9] ~= false then
  19.  
  20. local posX = mas[i][1] + mas[i][3] / 2 - unicode.wlen(mas[i][7]) / 2
  21. local posY = mas[i][2] + mas[i][4] / 2
  22.  
  23. gpu.setBackground(mas[i][5])
  24. gpu.setForeground(mas[i][6])
  25. gpu.fill(mas[i][1], mas[i][2], mas[i][3], mas[i][4], " ")
  26. gpu.set(posX, posY, mas[i][7])
  27.  
  28. end
  29.  
  30. end
  31.  
  32. end
  33.  
  34. function ev(...)
  35.  
  36. local args = {...}
  37.  
  38. local close = false
  39.  
  40. while not close do
  41.  
  42. local _, _, x, y = event.pull(0, "touch")
  43.  
  44. if x ~= nil and y ~= nil then
  45.  
  46. for i = 1, #args do
  47.  
  48. local mas = args[i]
  49.  
  50. for j = 1, #mas do
  51.  
  52. if x >= mas[j][1] and x <= mas[j][1] + mas[j][3] - 1 and y >= mas[j][2] and y <= mas[j][2] + mas[j][4] - 1 and mas[j][9] ~= false then mas[j][8]() end
  53.  
  54. end
  55.  
  56. if mas.close == true then close = true end
  57.  
  58. end
  59.  
  60. end
  61.  
  62. end
  63.  
  64. end
  65.  
  66. function getPassword(path)
  67.  
  68. file = io.open(path, "r")
  69. password = file:read()
  70. file:close()
  71. return password
  72.  
  73. end
  74.  
  75. function setPassword(path, password)
  76.  
  77. file = io.open(path, "w")
  78. file:write(password)
  79. file:close()
  80.  
  81. end
  82.  
  83. pass = ""
  84.  
  85. function pClear()
  86.  
  87. pass = ""
  88. pField[2][5] = 0x86ff80
  89. pField[1][7] = pass
  90. draw(pField)
  91. os.sleep(0.2)
  92. pField[2][5] = 0x00ff00
  93. draw(pField)
  94.  
  95. end
  96.  
  97. pField = {
  98. {1, 1, 4, 1, 0xffffff, 0x000000, pass, justFunction},
  99. {9, 1, 4, 1, 0x00ff00, 0xffffff, "CL", pClear},
  100. {17, 1, 2, 1, 0xffffff, 0x000000, "", checkPass},
  101. {19, 1, 2, 1, 0x000000, 0x000000, "", settings}
  102. }
  103.  
  104. sField = {
  105. {1, 1, 14, 1, 0x323232, 0xffffff, "Password: " .. getPassword("/home/Data/password"), changePassword},
  106. {1, 3, 2, 1, 0xff8000, 0xffffff, "OK", returnToNump}
  107. }
  108.  
  109. function justFunction() end
  110.  
  111. function settings()
  112.  
  113. if pass == getPassword("/home/Data/password") then
  114.  
  115. if not res then gpu.setResolution(14, 3) end
  116. pass = ""
  117. buttons1.close = true
  118. gpu.setBackground(0x323232)
  119. term.clear()
  120. draw(sField)
  121. ev(sField)
  122.  
  123. end
  124.  
  125. end
  126.  
  127. function returnToNump()
  128.  
  129. buttons1.close = false
  130. pass = ""
  131. pField[1][7] = ""
  132. sField.close = true
  133. for i = 1, #pField do pField[i][9] = true end
  134. if not res then gpu.setResolution(20, 17) end
  135. pField[3][8] = checkPass
  136. gpu.setBackground(0x323232)
  137. term.clear()
  138. draw(buttons1)
  139. draw(pField)
  140. ev(buttons1, pField)
  141.  
  142. end
  143.  
  144. function pDone()
  145.  
  146. buttons1.close = true
  147. sField.close = false
  148. setPassword("/home/Data/password", pass)
  149. sField[1][7] = "Password: " .. pass
  150. if not res then gpu.setResolution(14, 3) end
  151. gpu.setBackground(0x323232)
  152. term.clear()
  153. draw(sField)
  154. ev(sField)
  155.  
  156. end
  157.  
  158. function changePassword()
  159.  
  160. if not res then gpu.setResolution(20, 17) end
  161. gpu.setBackground(0x323232)
  162. term.clear()
  163. pField[4][9] = false
  164. draw(buttons1)
  165. draw(pField)
  166. sField.close = true
  167. buttons1.close = false
  168. pField[3][8] = pDone
  169. ev(buttons1, pField)
  170.  
  171. end
  172.  
  173. function checkPass()
  174.  
  175. if pass == getPassword("/home/Data/password") then
  176.  
  177. pass = ""
  178. pField[1][7] = pass
  179. draw(pField)
  180. pField[3][5] = 0x00ff00
  181. draw(pField)
  182. os.sleep(0.2)
  183. pField[3][5] = 0xffffff
  184. draw(pField)
  185. assert(loadfile("/home/Data/Unlock"))()
  186.  
  187. else
  188.  
  189. pField[3][5] = 0xff0000
  190. draw(pField)
  191. os.sleep(0.2)
  192. pField[3][5] = 0xffffff
  193. draw(pField)
  194.  
  195. end
  196.  
  197. end
  198.  
  199. function b1()
  200.  
  201. buttons1[1][5] = 0xffd15c
  202. draw(buttons1)
  203. os.sleep(0.2)
  204. buttons1[1][5] = 0xff8000
  205. draw(buttons1)
  206. if unicode.wlen(pass) < 4 then pass = pass .. "1" end
  207. pField[1][7] = pass
  208. draw(pField)
  209.  
  210. end
  211.  
  212. function b2()
  213.  
  214. buttons1[2][5] = 0xffd15c
  215. draw(buttons1)
  216. os.sleep(0.2)
  217. buttons1[2][5] = 0xff8000
  218. draw(buttons1)
  219. if unicode.wlen(pass) < 4 then pass = pass .. "2" end
  220. pField[1][7] = pass
  221. draw(pField)
  222.  
  223. end
  224.  
  225. function b3()
  226.  
  227. buttons1[3][5] = 0xffd15c
  228. draw(buttons1)
  229. os.sleep(0.2)
  230. buttons1[3][5] = 0xff8000
  231. draw(buttons1)
  232. if unicode.wlen(pass) < 4 then pass = pass .. "3" end
  233. pField[1][7] = pass
  234. draw(pField)
  235.  
  236. end
  237.  
  238. function b4()
  239.  
  240. buttons1[4][5] = 0xffd15c
  241. draw(buttons1)
  242. os.sleep(0.2)
  243. buttons1[4][5] = 0xff8000
  244. draw(buttons1)
  245. if unicode.wlen(pass) < 4 then pass = pass .. "4" end
  246. pField[1][7] = pass
  247. draw(pField)
  248.  
  249. end
  250.  
  251. function b5()
  252.  
  253. buttons1[5][5] = 0xffd15c
  254. draw(buttons1)
  255. os.sleep(0.2)
  256. buttons1[5][5] = 0xff8000
  257. draw(buttons1)
  258. if unicode.wlen(pass) < 4 then pass = pass .. "5" end
  259. pField[1][7] = pass
  260. draw(pField)
  261.  
  262. end
  263.  
  264. function b6()
  265.  
  266. assert(loadfile("/bin/mkdir.lua"))()
  267. buttons1[6][5] = 0xffd15c
  268. draw(buttons1)
  269. os.sleep(0.2)
  270. buttons1[6][5] = 0xff8000
  271. draw(buttons1)
  272. if unicode.wlen(pass) < 4 then pass = pass .. "6" end
  273. pField[1][7] = pass
  274. draw(pField)
  275.  
  276. end
  277.  
  278. function b7()
  279.  
  280. buttons1[7][5] = 0xffd15c
  281. draw(buttons1)
  282. os.sleep(0.2)
  283. buttons1[7][5] = 0xff8000
  284. draw(buttons1)
  285. if unicode.wlen(pass) < 4 then pass = pass .. "7" end
  286. pField[1][7] = pass
  287. draw(pField)
  288.  
  289. end
  290.  
  291. function b8()
  292.  
  293. buttons1[8][5] = 0xffd15c
  294. draw(buttons1)
  295. os.sleep(0.2)
  296. buttons1[8][5] = 0xff8000
  297. draw(buttons1)
  298. if unicode.wlen(pass) < 4 then pass = pass .. "8" end
  299. pField[1][7] = pass
  300. draw(pField)
  301.  
  302. end
  303.  
  304. function b9()
  305.  
  306. buttons1[9][5] = 0xffd15c
  307. draw(buttons1)
  308. os.sleep(0.2)
  309. buttons1[9][5] = 0xff8000
  310. draw(buttons1)
  311. if unicode.wlen(pass) < 4 then pass = pass .. "9" end
  312. pField[1][7] = pass
  313. draw(pField)
  314.  
  315. end
  316.  
  317. function b10()
  318.  
  319. buttons1[10][5] = 0xffd15c
  320. draw(buttons1)
  321. os.sleep(0.2)
  322. buttons1[10][5] = 0xff8000
  323. draw(buttons1)
  324. if unicode.wlen(pass) < 4 then pass = pass .. "*" end
  325. pField[1][7] = pass
  326. draw(pField)
  327.  
  328. end
  329.  
  330. function b11()
  331.  
  332. buttons1[11][5] = 0xffd15c
  333. draw(buttons1)
  334. os.sleep(0.2)
  335. buttons1[11][5] = 0xff8000
  336. draw(buttons1)
  337. if unicode.wlen(pass) < 4 then pass = pass .. "0" end
  338. pField[1][7] = pass
  339. draw(pField)
  340.  
  341. end
  342.  
  343. function b12()
  344.  
  345. buttons1[12][5] = 0xffd15c
  346. draw(buttons1)
  347. os.sleep(0.2)
  348. buttons1[12][5] = 0xff8000
  349. draw(buttons1)
  350. if unicode.wlen(pass) < 4 then pass = pass .. "#" end
  351. pField[1][7] = pass
  352. draw(pField)
  353.  
  354. end
  355.  
  356. buttons1 = {
  357. {1, 3, 6, 3, 0xff8000, 0xffffff, "1", b1},
  358. {8, 3, 6, 3, 0xff8000, 0xffffff, "2", b2},
  359. {15, 3, 6, 3, 0xff8000, 0xffffff, "3", b3},
  360. {1, 7, 6, 3, 0xff8000, 0xffffff, "4", b4},
  361. {8, 7, 6, 3, 0xff8000, 0xffffff, "5", b5},
  362. {15, 7, 6, 3, 0xff8000, 0xffffff, "6", b6},
  363. {1, 11, 6, 3, 0xff8000, 0xffffff, "7", b7},
  364. {8, 11, 6, 3, 0xff8000, 0xffffff, "8", b8},
  365. {15, 11, 6, 3, 0xff8000, 0xffffff, "9", b9},
  366. {1, 15, 6, 3, 0xff8000, 0xffffff, "*", b10},
  367. {8, 15, 6, 3, 0xff8000, 0xffffff, "0", b11},
  368. {15, 15, 6, 3, 0xff8000, 0xffffff, "#", b12}
  369. }
  370.  
  371. ------------------------------------------------------------------------------------
  372.  
  373. if not res then gpu.setResolution(20, 17) end
  374. gpu.setBackground(0x323232)
  375. term.clear()
  376.  
  377. draw(buttons1)
  378. draw(pField)
  379. ev(buttons1, pField)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement