Advertisement
9551

Untitled

Apr 5th, 2022
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. local api = require("GuiH")
  2. local term = window.create(term.current(),1,1,term.getSize())
  3. local gui = api.create_gui(term)
  4. local w,h = term.getSize()
  5. local cx,cy = math.ceil(w/2-17/2),math.ceil(h/2-6/2)
  6. local oldPull = os.pullEvent
  7. os.pullEvent = os.pullEventRaw
  8. local frame = gui.create.frame({
  9. name="login_window",
  10. x=cx,y=cy,width=17,height=6,
  11. dragger={
  12. x=1,y=1,width=17,height=1
  13. },
  14. on_clickfunction(object,pos)
  15. local term = object.canvas.term_object
  16. local w,h = term.getSize()
  17. object.window.reposition(
  18. math.max(
  19. math.min(
  20. pos.x+object.positioning.width,
  21. w+1
  22. )-object.positioning.width,1
  23. ),
  24. math.max(
  25. math.min(
  26. pos.y+object.positioning.height,
  27. h+1
  28. )-object.positioning.height,1
  29. )
  30. )
  31. return true
  32. end
  33. })
  34. local child,window = frame.child,frame.window
  35. child.create.inputbox({
  36. name="password_in",
  37. x=3,y=3,width=12,
  38. char_limit=20,
  39. background_color=colors.white,
  40. text_color=colors.black,
  41. on_change_select=function(object,event,selected)
  42. object.background_color=selected and colors.cyan or colors.white
  43. if object.input == "wrong pass" then
  44. child.gui.inputbox.password_in.replace_char="*"
  45. child.gui.inputbox.password_in.input = ""
  46. child.gui.inputbox.password_in.cursor_pos = 0
  47. end
  48. end,
  49. replace_char="*"
  50. })
  51. local button = child.create.button({
  52. x=11,y=5,width=5,height=1,
  53. text=gui.text{
  54. text="enter",
  55. blit={
  56. "fffff",
  57. "ddddd"
  58. }
  59. },
  60. on_click=function(object)
  61. if child.gui.inputbox.password_in.input == "password123" then
  62. local term = _G.term
  63. term.clear()
  64. term.setCursorPos(1,1)
  65. term.setTextColor(colors.yellow)
  66. term.write(_HOST:match("^%a+ %d-%.%d-%.%d%.-"))
  67. term.setCursorPos(1,2)
  68. os.pullEvent = oldPull
  69. error()
  70. else
  71. child.gui.inputbox.password_in.replace_char = nil
  72. child.gui.inputbox.password_in.input = "wrong pass"
  73. child.gui.inputbox.password_in.cursor_pos = 10
  74. child.gui.inputbox.password_in.selected = false
  75. child.gui.inputbox.password_in.background_color = colors.white
  76. end
  77. end
  78. })
  79. child.create.button({
  80. x=3,y=5,width=6,height=1,
  81. text=gui.text{
  82. text="cancel",
  83. blit={
  84. "ffffff",
  85. "eeeeee"
  86. }
  87. },
  88. on_click=function()
  89. os.shutdown()
  90. end
  91. })
  92. window.setBackgroundColor(colors.gray)
  93. window.clear()
  94. window.setCursorPos(1,1)
  95. window.setBackgroundColor(colors.lightGray)
  96. window.setTextColor(colors.gray)
  97. window.write("login"..("-"):rep(12))
  98. gui.update(0)
  99. child.gui.inputbox.password_in.selected = true
  100. while true do
  101. term.setVisible(false)
  102. term.clear()
  103. local event = gui.update()
  104. if event.name == "key" and event.key == keys.enter then
  105. button.on_click(button)
  106. end
  107. term.setVisible(true)
  108. end
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement