Advertisement
pfgpastebin

GUI_OS Login

Sep 23rd, 2015
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. os.loadAPI("redbutton")
  2. local readAt = {1,1}
  3. local readNow = false
  4. local readFun = readOpt
  5. local readOpt = "btnWasRead"
  6. function buttonPressed(data)
  7. btn = data["btn"]
  8. txt = data["txt"]
  9. if(txt == "login")then
  10.  
  11. end
  12. if(txt == "user")then
  13. --readAt({data.btn.x,data.btn.y},userboxpressed,data.btn)--
  14. readAt = {data.btn.x,data.btn.y}--
  15. readFun = userboxpressed --
  16. readOpt = data.btn --
  17. readNow = true --
  18. end
  19. end
  20. function readAt(pos,fun,opt)
  21. readAt = pos
  22. readFun = fun
  23. readOpt = opt
  24. readNow = true
  25. end
  26. function drawButtons(btns)
  27. for key,value in pairs(btns) do --actualcode
  28. value["btn"]:draw()
  29. end
  30. end
  31. function userboxpressed(btn)
  32. btn:rename("")
  33. btn:draw()
  34. btn:rename(read())
  35. btn:draw()
  36. end
  37. term.clear()
  38. function btn()
  39.  
  40. btns = {
  41. {txt="login", btn=redbutton.addButton(5,5,15,0,colors.white,colors.blue,"Login")},
  42. {txt="user", btn=redbutton.addButton(3,3,16,0,colors.white,colors.blue,"Username")}
  43. }
  44. drawButtons(btns)
  45.  
  46. while true do
  47. ev = {os.pullEvent()}
  48. for key,value in pairs(btns) do --actualcode
  49. if(value["btn"]:pressed(ev))then
  50. buttonPressed(value)
  51. end
  52. end
  53. end
  54. end
  55. function readAt()
  56. while(true)do
  57. if(readNow)then
  58. term.setCursorPos(readAt[1],readAt[2])
  59. readFun(readOpt)
  60. readNow = false
  61. end
  62. sleep(0.2)
  63. end
  64. end
  65.  
  66. function readOpt(what)
  67. print("Error!")
  68. end
  69. parallel.waitForAny(btn,readAt)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement