Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local cmp = require('component')
- local event = require('event')
- local serialization = require('serialization')
- local gpu=cmp.gpu
- local filesystem=require('filesystem')
- local term =require('term')
- local computer = require('computer')
- local unicode = require('unicode')
- local draw = require('draw')
- local sides = require("sides")
- local note = require("note")
- local keyboard = require("keyboard")
- ------------
- local A,B=gpu.getResolution()
- local oldBack = gpu.getBackground()
- local oldFore = gpu.getForeground()
- local usersFile = 'users.list'
- ------------
- --gpu.setResolution(120,40)
- ------------
- local color={
- back=0xDCDCDC,
- line=0x505050,
- line_back=0,
- pass_field=0,
- enter_pass=0x898989,
- user_name=123123,
- user_frame=0x505050,
- right=0xFFA400,
- left=0xFFA400,
- color_ball=0xFFFFFF,
- back_ball=0
- }
- local buttonsUsers={
- {54,11,8,7}, -- Right
- {20,11,8,7}, -- Left
- {27,21,30,3} -- Password Field
- }
- local function saveTbl(tbl, fl)
- file = io.open(fl, 'w')
- file:write(serialization.serialize(tbl))
- file:close()
- end
- local function loadTbl(fl)
- file = io.open(fl, 'r')
- if not file then
- file = io.open(fl, 'w')
- file:write('{}')
- return {} else
- return serialization.unserialize(file:read('*a'))
- end
- file:close()
- end
- function getRawEvent(arr)
- local N = nil
- local key,_,x,y,clickMouse,name=event.pull()
- if key == 'touch' then
- for i=1,#arr do
- if x > arr[i][1]-1 and x < arr[i][1]+arr[i][3] and y > arr[i][2]-1 and y < arr[i][2]+arr[i][4] then
- N=i
- break
- end
- end
- end
- if N == nil then
- N = 0
- end
- return key,N,clickMouse,name
- end
- -- ? y=20
- function drawBalls(selectUser)
- balls=''
- ball=' ● '
- ball2=' • '
- for i=1,#users do
- if i == selectUser then
- balls=balls..ball
- else
- balls=balls..ball2
- end
- end
- draw.text(16,18,50,balls,color.back_ball,color.color_ball)
- end
- function enter(x,y,w,h,color_back,color_fore,userName)
- local password = users[userName][2]
- got=nil
- function drawTextInPass(x,y,w,h,txt,col)
- if unicode.len(txt) > w-3 then
- txt=unicode.sub(txt,unicode.len(txt)-(w-3),unicode.len(txt))
- end
- draw.field(x+1,y+1,w-2,1,' ',color.pass_field,color.enter_pass)
- draw.text(x+1,y+1,w-2,txt,color.pass_field,col)
- end
- draw.field(x,y,w,h,' ',color_back,color_fore)
- draw.clound('┌','┐','└','┘','│','─',x,y,w,h,color_back,0xAA0000)
- local function getKey(s)
- local key, _, x1 , code, _ = event.pull()
- if key == 'key_up' or key == 'touch' then
- return code , x1 , key
- end
- end
- local function enterPass(x,y,w,h)
- try = ""
- ex=true
- while ex do
- local err, f , x1 , key = pcall(getKey)
- if not err then
- return err, try
- end
- if f ~= nil and key == 'key_up' then --
- if keyboard.keys[f] == 'grave' then ex=false end
- if f < 60 and f > 0 then
- if keyboard.keys[f] == 'enter' then
- draw.clound('┌','┐','└','┘','│','─',x,y,w,h,color_back,color_fore)
- return err, try , 's'
- end
- if keyboard.keys[f] == 'back' then
- if unicode.len(try) > 0 then
- try=unicode.sub(try,0,unicode.len(try)-1)
- if try ~= nil then
- try2='' for l=1,unicode.len(try) do try2=try2..'*' end
- end
- drawTextInPass(x,y,w,h,try2,color_fore)
- else
- try = 'cancel'
- draw.clound('┌','┐','└','┘','│','─',x,y,w,h,color_back,color_fore)
- return err , try , 'f'
- end
- end
- if unicode.len(keyboard.keys[f]) == 1 then
- try = try..keyboard.keys[f]
- if try ~= nil then
- try2='' for l=1,unicode.len(try) do try2=try2..'*' end
- end
- drawTextInPass(x,y,w,h,try2,color_fore)
- elseif keyboard.keys[f] == 'space' then
- if try ~= nil then
- try2='' for l=1,unicode.len(try) do try2=try2..'*' end
- end
- drawTextInPass(x,y,w,h,try2,color_fore)
- elseif keyboard.keys[f] == 'minus' then
- if try ~= nil then
- try2='' for l=1,unicode.len(try) do try2=try2..'*' end
- end
- drawTextInPass(x,y,w,h,try2,color_fore)
- elseif keyboard.keys[f] == 'period' then
- if try ~= nil then
- try2='' for l=1,unicode.len(try) do try2=try2..'*' end
- end
- drawTextInPass(x,y,w,h,try2,color_fore)
- elseif keyboard.keys[f] == 'comma' then
- if try ~= nil then
- try2='' for l=1,unicode.len(try) do try2=try2..'*' end
- end
- drawTextInPass(x,y,w,h,try2,color_fore)
- elseif keyboard.keys[f] == 'slash' then
- if try ~= nil then
- try2='' for l=1,unicode.len(try) do try2=try2..'*' end
- end
- drawTextInPass(x,y,w,h,try2,color_fore)
- end
- end
- elseif key == 'touch' and f ~= nil then
- if x1 > x-1 and x1 < x+w and f > y-1 and f < y+h then
- --
- else
- draw.clound('┌','┐','└','┘','│','─',x,y,w,h,color_back,color_fore)
- try = nil
- return err, try , 's'
- end
- end
- end
- end --
- while true do
- err, try , got = enterPass(x,y,w,h)
- if got == 's' and try == password then -- success
- note.play(83, 0.3)
- note.play(90, 0.2)
- drawTextInPass(x,y,w,h,'Доступ разрешен!',0x00FF00)
- os.sleep(2.5)
- gpu.setBackground(oldBack)
- gpu.setForeground(oldFore)
- gpu.setResolution(A,B)
- term.clear()
- os.exit()
- elseif got == 's' and try ~= password then
- drawTextInPass(x,y,w,h,'',0xFFFFFF)
- try = nil
- break
- elseif got == 'f' then
- drawTextInPass(x,y,w,h,'',0xFFFFFF)
- try = nil
- break
- end
- end
- return try
- end
- function drawUsersList()
- selectUser=1
- drawBalls(selectUser)
- local function drawUser(selectUser)
- -- <user>
- draw.field(32,8,18,9,' ',color.user_frame,0x505050)
- draw.clound('┌','┐','└','┘','│','─',32,8,18,9,color.user_frame,0xFFFFFF)
- draw.text(33,12,16,users[selectUser][1],color.user_frame,color.user_name)
- -- </user>
- end
- drawUser(selectUser)
- -- <Right>
- draw.field(54,9,4,7,' ',color.right,0x505050)
- draw.field(58,10,2,5,' ',color.right,0x505050)
- draw.field(60,11,2,3,' ',color.right,0x505050)
- draw.field(62,12,1,1,' ',color.right,0x505050)
- -- </Right>
- -- <Left>
- draw.field(24,9,4,7,' ',color.left,0x505050)
- draw.field(22,10,2,5,' ',color.left,0x505050)
- draw.field(20,11,2,3,' ',color.left,0x505050)
- draw.field(19,12,1,1,' ',color.left,0x505050)
- -- </Left>
- -- <line>
- draw.field(15,19,50,1,'─',color.line_back,color.line)
- draw.field(15,6,50,1,'─',color.line_back,color.line)
- -- </line>
- -- <Password_Field>
- draw.field(26,21,30,3,' ',color.pass_field,0x505050)
- draw.clound('┌','┐','└','┘','│','─',26,21,30,3,color.pass_field,0xFFFFFF)
- draw.text(27,22,17,'Введите пароль...',color.pass_field,color.enter_pass)
- -- </Password_Field>
- while true do
- key,N,clickMouse,name=getRawEvent(buttonsUsers)
- if N == 1 then
- selectUser = selectUser+1
- if selectUser > #users then
- selectUser = #users
- end
- drawUser(selectUser)
- drawBalls(selectUser)
- elseif N == 2 then
- selectUser = selectUser-1
- if selectUser < 1 then
- selectUser = 1
- end
- drawUser(selectUser)
- drawBalls(selectUser)
- elseif N == 3 then
- enter(26,21,30,3,0,0xffffff,selectUser)
- end
- end
- end
- if filesystem.exists(usersFile) == true then
- term.clear()
- draw.err('Добро пожаловать!',1,2)
- term.clear()
- users=loadTbl(usersFile)
- drawUsersList()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement