Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local w,h = 26,20
- local pos = term.setCursorPos
- local bcolor = term.setBackgroundColor
- local tcolor = term.setTextColor
- local blink = term.setCursorBlink
- local buffer = term.current().setVisible
- local getpos = term.getCursorPos
- local getbcolor = term.getBackgroundColor
- local gettcolor = term.getTextColor
- local printslow = textutils.slowPrint
- local clr = term.clear
- local clrln = term.clearLine
- local keylock = {
- pins = 5,
- code = '92345',
- inp = ''
- }
- clrlny = function(y)
- local x,_ = getpos()
- pos(x,y)
- clrln()
- end
- cwrite = function(txt,y)
- pos((w/2 - #txt/2)+1, y)
- write(txt)
- end
- clrlnycolor = function(col,y) bcolor(col) clrlny(y) end
- box = paintutils.drawFilledBox
- hbox = paintutils.drawBox
- drawimage = function(img,x,y) paintutils.drawImage(paintutils.loadImage(img),x,y) end
- hbox(1,1,w,h,colors.green)
- local numpad = {
- {'1','2','3'},
- {'4','5','6'},
- {'7','8','9'},
- {' ','0',' '},
- }
- local running = true
- local yspace = 4
- local xspace = 8
- local center = (w/2) - (#numpad[1]+xspace-5/2)
- local yoffs = (h/2) - ((#numpad+yspace)/2)+1
- function drawnums()
- drawimage('scr.bg',0,0)
- bcolor(colors.lightBlue)
- tcolor(colors.black)
- cwrite("Enter Passcode",1)
- pos((w/2 - keylock.pins/2)+1,3)
- bcolor(colors.lightGray)
- tcolor(colors.gray)
- write(string.rep('_',keylock.pins))
- for y = 1, #numpad do
- for x = 1, #numpad[y] do
- if (numpad[y][x] ~= " ")then
- box(center+ ( (x-1)*xspace ) , yoffs+( (y-1)*yspace )-1, center+ ( (x-1)*xspace )+2 , yoffs+( (y-1)*yspace )+1,colors.black)
- pos(center+ ( (x-1)*xspace ) , yoffs+( (y-1)*yspace ) )
- term.blit(' ' .. numpad[y][x] .. ' ', '000','fff')
- end
- end
- end
- end
- function dispinp()
- pos((w/2 - keylock.pins/2)+1,3)
- bcolor(colors.lightGray)
- tcolor(colors.gray)
- write(string.rep('*',#keylock.inp))
- end
- function update(e)
- if(e[1] == "mouse_click")then
- local b = e[2]
- local mx = e[3]
- local my = e[4]
- if(mx >= center-1 and my >= yoffs-1)then
- for y = 1, #numpad do
- for x = 1, #numpad[y] do
- if (numpad[y][x] ~= " ")then
- if(mx >= center+ ( (x-1)*xspace )-1 and mx <= center+ ( (x-1)*xspace )+2
- and my >= yoffs+ ( (y-1)*yspace )-1 and my <= yoffs+ ( (y-1)*yspace )+1)then
- box(center+ ( (x-1)*xspace ) , yoffs+( (y-1)*yspace )-1, center+ ( (x-1)*xspace )+2 , yoffs+( (y-1)*yspace )+1,colors.white)
- pos(center+ ( (x-1)*xspace ) , yoffs+( (y-1)*yspace ) )
- term.blit(' ' .. numpad[y][x] .. ' ', 'fff','000')
- keylock.inp = keylock.inp .. numpad[y][x]
- dispinp()
- sleep(0.2)
- box(center+ ( (x-1)*xspace ) , yoffs+( (y-1)*yspace )-1, center+ ( (x-1)*xspace )+2 , yoffs+( (y-1)*yspace )+1,colors.black)
- pos(center+ ( (x-1)*xspace ) , yoffs+( (y-1)*yspace ) )
- term.blit(' ' .. numpad[y][x] .. ' ', '000','fff')
- if(#keylock.inp >= keylock.pins)then
- if(keylock.inp == keylock.code)then
- bcolor(colors.black)
- tcolor(colors.white)
- term.clear()
- pos(1,1)
- running = false
- return
- else
- local oldc = center
- center = center -1
- drawnums()
- sleep(0.2)
- center = center +2
- drawnums()
- sleep(0.2)
- center = center -1
- drawnums()
- sleep(0.2)
- center = center +1
- drawnums()
- sleep(0.2)
- center = oldc
- keylock.inp = ''
- drawnums()
- end
- end
- end
- end
- end
- end
- end
- end
- end
- --]] Transitions [[--
- function fadeIn(time)
- local ctbl = {
- 'black',
- 'gray',
- 'lightGray',
- 'white',
- }
- for i = 1, #ctbl do
- term.setBackgroundColor(colors[ ctbl[i] ])
- term.clear()
- sleep(time)
- end
- end
- function fadeOut(time)
- local ctbl = {
- 'white',
- 'lightGray',
- 'gray',
- 'black',
- }
- for i = 1, #ctbl do
- term.setBackgroundColor(colors[ ctbl[i] ])
- term.clear()
- sleep(time)
- end
- end
- function loop()
- while running do
- local ev = {os.pullEvent()}
- update(ev)
- end
- end
- drawnums()
- loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement