Advertisement
9551

Untitled

Apr 4th, 2022
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.65 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=12,height=1
  13.     }
  14. })
  15. local child,window = frame.child,frame.window
  16. child.create.inputbox({
  17.     name="password_in",
  18.     x=3,y=3,width=12,
  19.     char_limit=20,
  20.     background_color=colors.white,
  21.     text_color=colors.black,
  22.     on_change_select=function(object,event,selected)
  23.         object.background_color=selected and colors.cyan or colors.white
  24.         if object.input == "wrong pass" then
  25.             child.gui.inputbox.password_in.replace_char="*"
  26.             child.gui.inputbox.password_in.input = ""
  27.             child.gui.inputbox.password_in.cursor_pos = 0
  28.         end
  29.     end,
  30.     replace_char="*"
  31. })
  32. local button = child.create.button({
  33.     x=11,y=5,width=5,height=1,
  34.     text=gui.text{
  35.         text="enter",
  36.         blit={
  37.             "fffff",
  38.             "ddddd"
  39.         }
  40.     },
  41.     on_click=function(object)
  42.         if child.gui.inputbox.password_in.input == "password123" then
  43.             local term = _G.term
  44.             term.clear()
  45.             term.setCursorPos(1,1)
  46.             term.setTextColor(colors.yellow)
  47.             term.write(_HOST:match("^%a+ %d-%.%d-%.%d%.-"))
  48.             term.setCursorPos(1,2)
  49.             os.pullEvent = oldPull
  50.             error()
  51.         else
  52.             child.gui.inputbox.password_in.replace_char = nil
  53.             child.gui.inputbox.password_in.input = "wrong pass"
  54.             child.gui.inputbox.password_in.cursor_pos = 10
  55.             child.gui.inputbox.password_in.selected = false
  56.             child.gui.inputbox.password_in.background_color = colors.white
  57.         end
  58.     end
  59. })
  60. child.create.button({
  61.     x=3,y=5,width=6,height=1,
  62.     text=gui.text{
  63.         text="cancel",
  64.         blit={
  65.             "ffffff",
  66.             "eeeeee"
  67.         }
  68.     },
  69.     on_click=function()
  70.         os.shutdown()
  71.     end
  72. })
  73. window.setBackgroundColor(colors.gray)
  74. window.clear()
  75. window.setCursorPos(1,1)
  76. window.setBackgroundColor(colors.lightGray)
  77. window.setTextColor(colors.gray)
  78. window.write("login"..("-"):rep(12))
  79. gui.update(0)
  80. child.gui.inputbox.password_in.selected = true
  81. while true do
  82.     term.setVisible(false)
  83.     term.clear()
  84.     local event = gui.update()
  85.     if event.name == "key" and event.key == keys.enter then
  86.         button.on_click(button)
  87.     end
  88.     term.setVisible(true)
  89. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement