CS-Coursework/websites/Typing/ui_elements/timemenu.js

61 lines
2.0 KiB
JavaScript
Raw Normal View History

2022-11-28 11:04:49 +00:00
/**
* @file This file provides a time menu class for editing the length of a test
* @author Arlo Filley
*
* TODO:
* - implement visual changes (borders, etc)
* - replace with methods with getters and setters
* - highlight which option the user has chosen in some way
*/
/**
* this class displays a dropdown menu for the user where
* they can edit the duration of a test
*/
2022-11-04 12:18:45 +00:00
class TimeMenu {
constructor() {
2022-11-18 14:51:05 +00:00
this.buttons = [
2023-09-05 08:52:28 +01:00
new Button(900, 250, 100, 30, "15s"),
new Button(900, 280, 100, 30, "30s"),
new Button(900, 310, 100, 30, "45s"),
new Button(900, 340, 100, 30, "60s"),
2022-11-18 14:51:05 +00:00
];
2022-11-28 11:04:49 +00:00
this.topButton = this.buttons[0];
2023-09-05 08:52:28 +01:00
this.dropDownButton = new Button(1000, 250, 30, 30, "v")
2022-11-18 14:51:05 +00:00
this.dropdown = false;
}
draw() {
if (this.dropdown) {
for (let i = 0; i < this.buttons.length; i++) {
2022-11-28 11:04:49 +00:00
this.buttons[i].draw()
}
if (this.buttons[0].isPressed() && user.time != 15) {
user.time = 15;
2023-09-05 08:52:28 +01:00
this.topButton = new Button(900, 250, 100, 30, "15s");
2022-11-28 11:04:49 +00:00
this.dropdown = false;
} else if (this.buttons[1].isPressed()) {
user.time = 30;
2023-09-05 08:52:28 +01:00
this.topButton = new Button(900, 250, 100, 30, "30s");
2022-11-28 11:04:49 +00:00
this.dropdown = false;
} else if (this.buttons[2].isPressed()) {
user.time = 45;
2023-09-05 08:52:28 +01:00
this.topButton = new Button(900, 250, 100, 30, "45s");
2022-11-28 11:04:49 +00:00
this.dropdown = false;
} else if (this.buttons[3].isPressed()) {
user.time = 60;
2023-09-05 08:52:28 +01:00
this.topButton = new Button(900, 250, 100, 30, "60s");
2022-11-28 11:04:49 +00:00
this.dropdown = false;
2022-11-18 14:51:05 +00:00
}
2022-11-28 11:04:49 +00:00
} else {
this.topButton.draw();
}
2022-11-04 12:18:45 +00:00
2023-09-05 08:52:28 +01:00
this.dropDownButton.draw();
if (this.dropDownButton.isPressed()) {
2022-11-18 14:51:05 +00:00
this.dropdown = true;
2023-09-05 08:52:28 +01:00
} else if (mouseIsPressed) { this.dropdown = false };
2022-11-04 12:18:45 +00:00
}
}