Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local guiElements = {}
- local loginScreen = {}
- local function initLoginScreen()
- local bg = gui_rect.new()
- bg:init(0, 0, S_WIDTH + 1, S_HEIGHT + 1)
- bg.bgColor = colors.cyan
- local userLabel = gui_label.new()
- userLabel:init("Username: ", S_WIDTH / 2 - 10, S_HEIGHT / 2 + 2, 10, 1)
- userLabel.bgColor = bg.bgColor
- local userField = gui_textfield.new()
- userField:init("", S_WIDTH / 2 + 1, S_HEIGHT / 2 + 2, 15, 1)
- local passLabel = gui_label.new()
- passLabel:init("Password: ", S_WIDTH / 2 - 10, S_HEIGHT / 2 + 2 + 2, 10, 1)
- passLabel.bgColor = bg.bgColor
- local passField = gui_textfield.new()
- passField:init("", S_WIDTH / 2 + 1, S_HEIGHT / 2 + 2 + 2, 15, 1)
- passField.replaceChar = "*"
- table.insert(loginScreen, bg)
- table.insert(loginScreen, userLabel)
- table.insert(loginScreen, userField)
- table.insert(loginScreen, passLabel)
- table.insert(loginScreen, passField)
- local cancelButton = gui_button.new()
- cancelButton:init("Cancel", S_WIDTH / 2 - 10, S_HEIGHT / 2 + 2 + 2 + 2, 8, 3)
- cancelButton.onClick = function(self, x, y)
- cleanExit()
- end
- cancelButton.textColor = bg.bgColor
- table.insert(loginScreen, cancelButton)
- local loginButton = gui_button.new()
- loginButton:init("Log in", S_WIDTH / 2 + 8, S_HEIGHT / 2 + 2 + 2 + 2, 8, 3)
- loginButton.onClick = function(loginB, x, y)
- -- PERFORM LOGIN STUFF
- if success then
- -- Perform success stuff
- else
- userField.editable = false
- passField.editable = false
- loginButton.clickable = false
- cancelButton.clickable = false
- local msg = createMessageBox("Failure", errorMessage, "error")
- msg.msgBoxQuit.onClick = function(self, x, y)
- userField.editable = true
- passField.editable = true
- loginButton.clickable = true
- cancelButton.clickable = true
- for _, el in pairs(msg) do
- el.visible = false
- end
- end
- for _, el in pairs(msg) do
- table.insert(loginScreen, el)
- end
- end
- end
- loginButton.textColor = bg.bgColor
- table.insert(loginScreen, loginButton)
- end
- initLoginScreen()
- guiElements = loginScreen
- for _, el in ipairs(guiElements) do
- el:draw()
- end
- -------------------------------------------------------------
- -------------------------------------------------------------
- -- GUI Control loop --
- -------------------------------------------------------------
- -------------------------------------------------------------
- while true do
- local ev, p1, p2, p3, p4 = os.pullEvent()
- local gui_ev = gui_event.new()
- if ev == "mouse_click" then
- gui_ev.button = p1
- if p1 == 3 then
- gui_ev.button = BUTTON_W
- end
- gui_ev.x = p2
- gui_ev.y = p3
- for _, el in ipairs(guiElements) do
- el:onMouseEvent(gui_ev)
- end
- elseif ev == "mouse_scroll" then
- gui_ev.button = p1 == 1 and BUTTON_W_DOWN or BUTTON_W_UP
- gui_ev.x = p2
- gui_ev.y = p3
- for _, el in ipairs(guiElements) do
- el:onMouseEvent(gui_ev)
- end
- elseif ev == "key" then
- gui_ev.key = p1
- for _, el in ipairs(guiElements) do
- el:onKeyEvent(gui_ev)
- end
- end
- for _, el in ipairs(guiElements) do
- el:draw()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement