CS-Coursework/website/screens/profilescreen.js

48 lines
1.9 KiB
JavaScript
Raw Normal View History

2022-11-17 11:48:12 +00:00
class ProfileScreen {
constructor() {
this.buttons = [
new Button(0,0,100,30,0,true,"#fff",false,"#000","#000","Sign Up"),
new Button(110,0,100,30,0,true,"#fff",false,"#000","#000","Login"),
new Button(220,0,100,30,0,true,"#fff",false,"#000","#000","Logout"),
new Button(330,0,100,30,0,true,"#fff",false,"#000","#000","Profile"),
new Button(440,0,100,30,0,true,"#fff",false,"#000","#000","Test"),
2022-11-18 11:33:25 +00:00
new Button(550,0,140,30,0,true,"#fff",false,"#000","#000","Leaderboard"),
2022-11-17 11:48:12 +00:00
];
api.getUserTests();
}
draw() {
background("#eeeee4");
textSize(100);
textAlign(CENTER, CENTER);
fill("#000");
2022-11-17 12:10:54 +00:00
text("Profile", 0, 100, windowWidth, 120);
2022-11-18 11:33:25 +00:00
for (let i = 0; i < this.buttons.length; i++) {
this.buttons[i].draw()
}
2022-11-17 11:48:12 +00:00
if (this.buttons[0].isPressed()) {
screenManager.setScreen(new SignUpScreen());
} else if (this.buttons[1].isPressed()) {
screenManager.setScreen(new LoginScreen());
} else if (this.buttons[2].isPressed()) {
api.logout();
} else if (this.buttons[3].isPressed()) {
screenManager.setScreen(new ProfileScreen());
} else if (this.buttons[4].isPressed()) {
screenManager.setScreen(new TestScreen())
2022-11-18 11:33:25 +00:00
} else if (this.buttons[5].isPressed()) {
screenManager.setScreen(new LeaderboardScreen())
2022-11-17 11:48:12 +00:00
}
textSize(20);
fill("#000");
if (user.tests != undefined) {
for (let i = 0; i < user.tests.length; i++) {
text(`Tests ${i+1}: ${user.tests[i].wpm}wpm | Type: ${user.tests[i].test_type} | Time: ${user.tests[i].test_time} | Characters Typed: ${user.tests[i].test_length}`, 0, i*30+300, windowWidth, 30);
}
}
fill("#000");
2022-11-18 12:27:54 +00:00
text(`Logged in as ${user.username}`, windowWidth-400, 15);
2022-11-17 11:48:12 +00:00
}
}