CS-Coursework/website/ui_elements/menu.js

42 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-11-28 11:04:49 +00:00
/**
* @file This file provides a menu class to allow the user to easily navigate the site
* @author Arlo Filley
*
* TODO:
* - more sensible button names for easier navigation
*/
/**
* this class provides a menu with all the relevent buttons the user will need,
* it also handles when the user presses a button, by creating the correct screen
*/
2022-11-18 14:51:05 +00:00
class Menu {
constructor() {
this.buttons = [
2022-11-28 11:04:49 +00:00
new Button(0, 0, 100, 30, 0, true, "#fff", false, "#000", "#000", "Account"),
new Button(101, 0, 130, 30, 0, true, "#fff", false, "#000", "#000", "Test Data"),
new Button(232, 0, 140, 30, 0, true, "#fff", false, "#000", "#000", "Start Test"),
new Button(373, 0, 140, 30, 0, true, "#fff", false, "#000", "#000", "Leaderboard"),
new Button(514, 0, 180, 30, 0, true, "#fff", false, "#000", "#000", "Test Settings")
2022-11-18 14:51:05 +00:00
]
}
draw() {
2022-11-28 11:04:49 +00:00
textAlign(CENTER, CENTER);
2022-11-18 14:51:05 +00:00
for (let i = 0; i < this.buttons.length; i++) {
this.buttons[i].draw()
}
if (this.buttons[0].isPressed()) {
2022-11-28 11:04:49 +00:00
screenManager.setScreen(new AccountScreen());
2022-11-18 14:51:05 +00:00
} else if (this.buttons[1].isPressed()) {
screenManager.setScreen(new ProfileScreen());
2022-11-28 11:04:49 +00:00
} else if (this.buttons[2].isPressed()) {
2022-11-18 14:51:05 +00:00
screenManager.setScreen(new TestScreen())
2022-11-28 11:04:49 +00:00
} else if (this.buttons[3].isPressed()) {
2022-11-18 14:51:05 +00:00
screenManager.setScreen(new LeaderboardScreen())
2022-11-28 11:04:49 +00:00
} else if (this.buttons[4].isPressed()) {
screenManager.setScreen(new settingsScreen())
2022-11-18 14:51:05 +00:00
}
}
}