Advertisement
fishermedders

Skynet GUI

Jun 5th, 2016
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. size = {term.getSize()}
  2.  
  3. users = {"fisher"}
  4. passwords = {"fisher"}
  5.  
  6. function drawBoxPos(x,y,x1,y1)
  7. cy = y
  8. term.setCursorPos(x,y)
  9. for i = 1,(y1-y)+1 do
  10. for i = 1,(x1-x) do
  11. term.write(" ")
  12. end
  13. cy = cy+1
  14. term.setCursorPos(x,cy)
  15. end
  16. end
  17.  
  18. function reset()
  19. term.setBackgroundColor(colors.lightGray)
  20. term.setCursorPos(2,12)
  21. for i = 1,size[1]-4 do
  22. term.write(" ")
  23. end
  24. term.setTextColor(colors.gray)
  25. term.setBackgroundColor(colors.gray)
  26. drawBoxPos(9,8,size[1]-1,8)
  27. term.setBackgroundColor(colors.lightGray)
  28. term.setCursorPos(3,8)
  29. print("USER:")
  30. term.setBackgroundColor(colors.gray)
  31. drawBoxPos(9,10,size[1]-1,10)
  32. term.setBackgroundColor(colors.lightGray)
  33. term.setCursorPos(3,10)
  34. print("PASS:")
  35. end
  36.  
  37. function loginScreen()
  38. term.setBackgroundColor(colors.white)
  39. term.clear()
  40. term.setBackgroundColor(colors.lightGray)
  41. drawBoxPos(2,2,size[1],size[2]-1)
  42. term.setCursorPos(1,size[2]-7)
  43. term.setBackgroundColor(colors.gray)
  44. drawBoxPos(((size[1]/2)-10)-1,2,((size[1]/2)+13)-1,4)
  45. term.setBackgroundColor(colors.red)
  46. drawBoxPos((size[1]/2)-10,1,(size[1]/2)+13,3)
  47. term.setTextColor(colors.gray)
  48. str = "Skynet Control Panel"
  49. term.setCursorPos((size[1]/2)-(#str/2) +1,2)
  50. term.write(str)
  51. term.setBackgroundColor(colors.lightGray)
  52. str = "User Account Information"
  53. term.setCursorPos((size[1]/2)-(#str/2) +1,6)
  54. term.write(str)
  55. term.setBackgroundColor(colors.gray)
  56. drawBoxPos(9,8,size[1]-1,8)
  57. term.setBackgroundColor(colors.lightGray)
  58. term.setCursorPos(3,8)
  59. print("USER:")
  60. term.setBackgroundColor(colors.gray)
  61. drawBoxPos(9,10,size[1]-1,10)
  62. term.setBackgroundColor(colors.lightGray)
  63. term.setCursorPos(3,10)
  64. print("PASS:")
  65. term.setBackgroundColor(colors.red)
  66. drawBoxPos(((size[1]/2)-9)-1,13,((size[1]/2)+13)-1,15)
  67. term.setTextColor(colors.gray)
  68. str = "Login to Skynet!"
  69. term.setCursorPos((size[1]/2)-(#str/2) +1,14)
  70. term.write(str)
  71. term.setBackgroundColor(colors.lightGray)
  72. str = "(c) 2016 Skynet - Innovate. Create. Defend."
  73. term.setCursorPos((size[1]/2)-(#str/2) +1,size[2]-2)
  74. term.write(str)
  75. while true do
  76. evnt = {os.pullEvent()}
  77. if evnt[1] == "mouse_click" then
  78. if evnt[3] > 8 and evnt[3] < size[1]-1 and evnt[4] == 8 then
  79. term.setBackgroundColor(colors.gray)
  80. term.setTextColor(colors.lightGray)
  81. term.setCursorPos(9,8)
  82. username = read()
  83. elseif evnt[3] > 8 and evnt[3] < size[1]-1 and evnt[4] == 10 then
  84. term.setBackgroundColor(colors.gray)
  85. term.setTextColor(colors.lightGray)
  86. term.setCursorPos(9,10)
  87. password = read("*")
  88. elseif evnt[3] > ((size[1]/2)-9)-2 and evnt[3] < ((size[1]/2)+13)-2 and evnt[4] > 12 and evnt[4] < 16 then
  89. if username ~= nil and password ~= nil then
  90. loggedin = false
  91. for i = 1,#users do
  92. if username == users[i] then
  93. if password == passwords[i] then
  94. term.setTextColor(colors.lime)
  95. term.setBackgroundColor(colors.lightGray)
  96. str = "Access Granted. Welcome back, "..username
  97. term.setCursorPos((size[1]/2)-(#str/2) +1,12)
  98. term.write(str)
  99. loggedin = true
  100. sleep(3)
  101. end
  102. end
  103. end
  104. if loggedin then
  105. break
  106. elseif loggedin == false then
  107. term.setTextColor(colors.red)
  108. term.setBackgroundColor(colors.lightGray)
  109. str = "Username or Password incorrect."
  110. term.setCursorPos((size[1]/2)-(#str/2) +1,12)
  111. term.write(str)
  112. sleep(2)
  113. reset()
  114. end
  115. elseif username == nil or password == nil then
  116. reset()
  117. term.setTextColor(colors.red)
  118. term.setBackgroundColor(colors.lightGray)
  119. str = "Username or Password not recognized."
  120. term.setCursorPos((size[1]/2)-(#str/2) +1,12)
  121. term.write(str)
  122. sleep(2)
  123. reset()
  124. end
  125. end
  126. end
  127. end
  128. end
  129.  
  130. loginScreen()
  131. term.setBackgroundColor(colors.black)
  132. term.clear()
  133. term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement