CS-Coursework/website/screens/signUpScreen.js

109 lines
3.2 KiB
JavaScript
Raw Normal View History

2022-11-28 11:04:49 +00:00
/**
* @file This file provides a way for the user to sign up for an account
* @author Arlo Filley
*
* TODO:
* - move into an seperated account page with signup and logout
* - make passwords not display plain text
*/
/**
* This class provides the textboxes and methods necessary for a user
* to sign up for a new account, which it should then log them into
*/
2022-11-06 23:52:00 +00:00
class SignUpScreen {
constructor() {
2022-11-11 13:04:13 +00:00
this.textboxes = [
2022-11-06 23:52:00 +00:00
new Textbox(
2022-11-28 11:04:49 +00:00
120, 250, 500, 100,0, true, "#000", false,
"#000", "#000", true
2022-11-06 23:52:00 +00:00
),
new Textbox(
2022-11-28 11:04:49 +00:00
120, 400, 500, 100, 0, true, "#000", false,
"000", "#000", false
2022-11-06 23:52:00 +00:00
)
]
2022-11-11 13:04:13 +00:00
this.buttons = [
new Button(
2022-11-28 11:04:49 +00:00
100, 200, 500, 100, 0, true, "#000", false,
"#000", "#fff", ""
2022-11-11 13:04:13 +00:00
),
new Button(
2022-11-28 11:04:49 +00:00
100, 350, 500, 100, 0, true, "#000", false,
"#000", "#fff", ""
2022-11-11 13:04:13 +00:00
),
new Button(
2022-11-28 11:04:49 +00:00
700, 300, 100, 50, 0, true, "#000", false,
"#000", "#00ff00", "Sign Up"
2022-11-11 13:04:13 +00:00
),
]
2022-11-18 14:51:05 +00:00
this.menu = new Menu();
2022-11-11 13:04:13 +00:00
this.activeTextBox = 0
// keeps track of which textbox the user last clicked on
2022-11-06 23:52:00 +00:00
}
/**
* Draws the SignUpScreen class with all
* appropriate elements
*/
draw() {
2022-11-11 13:04:13 +00:00
for (let i = 0; i < this.buttons.length; i++) {
this.buttons[i].draw();
}
for (let i = 0; i < this.textboxes.length; i++) {
this.textboxes[i].draw();
}
2022-12-01 14:41:14 +00:00
fill(user.colorScheme.text);
2022-11-11 13:04:13 +00:00
text("Username", 110, 175);
text("Password", 110, 325);
if (this.buttons[0].isPressed()) {
2022-11-18 12:27:54 +00:00
this.textboxes[this.activeTextBox].line = false;
2022-11-11 13:04:13 +00:00
this.activeTextBox=0;
2022-11-18 12:27:54 +00:00
this.textboxes[this.activeTextBox].line = true;
2022-11-11 13:04:13 +00:00
} else if (this.buttons[1].isPressed()) {
2022-11-18 12:27:54 +00:00
this.textboxes[this.activeTextBox].line = false;
2022-11-11 13:04:13 +00:00
this.activeTextBox=1;
2022-11-18 12:27:54 +00:00
this.textboxes[this.activeTextBox].line = true;
2022-11-11 13:04:13 +00:00
} else if (this.buttons[2].isPressed()) {
api.createUser(
this.textboxes[0].getWords(),
this.textboxes[1].getWords()
)
screenManager.setScreen(new StartScreen());
2022-11-18 14:51:05 +00:00
}
this.menu.draw();
2022-11-06 23:52:00 +00:00
}
/**
*
* @param {key} key
*/
2022-11-18 12:27:54 +00:00
letterTyped(key) {
if (key === "Tab" && this.activeTextBox === 0) {
this.textboxes[this.activeTextBox].line = false;
this.activeTextBox=1;
this.textboxes[this.activeTextBox].line = true;
} else if (key === "Tab" && this.activeTextBox === 1) {
this.textboxes[this.activeTextBox].line = false;
this.activeTextBox=0;
this.textboxes[this.activeTextBox].line = true;
} else if (key === "Enter") {
api.createUser(
this.textboxes[0].getWords(),
this.textboxes[1].getWords()
)
screenManager.setScreen(new StartScreen());
} else {
this.textboxes[this.activeTextBox].letterTyped(key);
}
2022-11-06 23:52:00 +00:00
}
}