Advertisement
Corona

[Computercraft] Login Mask

Dec 14th, 2013
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.11 KB | None | 0 0
  1. --(C) Corona 2013
  2. --DO NOT STEAL THIS CODE!!!
  3. os.loadAPI(shell.dir().."/screen")
  4.  
  5. local version = 1.2
  6. local maxx,maxy = term.getSize()
  7. local cb = false
  8. local cp=1
  9. local tmpstr = ""
  10. local password = "Corona"
  11. local msg = "Please Log In:"
  12.  
  13. local loginButton = {x1=(maxx/2-15),x2=(maxx/2+15),y1=(maxy/2+6),y2=(maxy/2+10),color=colors.lightBlue,text="LOGIN"}
  14. local loginArea = {x1=(maxx/2-20),x2=(maxx/2+20),y1=(maxy/2),y2=(maxy/2+3),color=colors.lightBlue,text={}}
  15. local wrongPassword = {x1=(maxx/2-20),x2=(maxx/2+20),y1=(maxy/2-5),y2=(maxy/2+5),text="WRONG PASSWORD",color=colors.red}
  16.  
  17. function cls()
  18.   term.clear()
  19.   term.setCursorPos(1,1)
  20. end
  21. function empty(tab)
  22.   for i=1,#tab do
  23.     tab[i]=nil
  24.   end
  25. end
  26. function login()
  27.   term.setCursorPos(1,1)
  28.  
  29.   for i=1,#loginArea["text"] do
  30.     tmpstr = tmpstr..(loginArea["text"][i])
  31.   end
  32.   if tmpstr == password then
  33.     cls()
  34.     print("Correct Password! Login Mask Version "..version)
  35.     error()
  36.   end
  37.   term.setCursorBlink(false)
  38.   screen.drawButton(wrongPassword)
  39.   sleep(2)
  40.   tmpstr=""
  41.   cp=1
  42.   empty(loginArea["text"])
  43.   cls()
  44.   term.setCursorBlink(true)
  45. end
  46.  
  47.  
  48. cls()
  49. while true do
  50.  
  51.   term.setCursorPos(maxx/2-#msg/2,maxy/2-5)
  52.   term.write(msg)
  53.   screen.drawBox(loginArea)
  54.   screen.drawButton(loginButton)
  55.   screen.getFocus(loginArea)
  56.   local tx,ty = term.getCursorPos()
  57.   term.setCursorPos(tx+cp-1,ty)
  58.   local evn,mixed,x,y = os.pullEvent()
  59.   if evn == "mouse_click" then
  60.     if screen.pressed(loginButton,x,y) then
  61.       login()
  62.     end
  63.     if screen.pressed(loginArea,x,y) then
  64.       term.setCursorBlink(true)
  65.       cb = true
  66.     else
  67.       term.setCursorBlink(false)
  68.       cb = false
  69.     end
  70.   end
  71.   if (evn == "char") and (cb) and (cp<(loginArea["x2"]-loginArea["x1"]-1)) then
  72.     loginArea["text"][cp] = mixed
  73.     write("*")
  74.     cp = cp+1
  75.   end
  76.   if (evn == "key") and (cb) then
  77.     if (mixed == 14) and (cp>1) then
  78.       cp = cp-1
  79.       local xt,yt = term.getCursorPos()
  80.       term.setCursorPos(xt-1,yt)
  81.       write(" ")
  82.       loginArea["text"][cp] = nil
  83.       elseif mixed == 28 then
  84.       login()
  85.     end
  86.   end
  87. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement