This repository has been archived by the owner on Aug 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainMenu.java
140 lines (122 loc) · 3.01 KB
/
MainMenu.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* The main menu screen
*
* Last edit: 6/18/2020
* @author Celeste, Eric
* @version 1.1
* @since 1.0
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class MainMenu extends Menu {
/**
* Contains the main menu graphics / GUI
*/
private MenuDrawing drawing;
/**
* Dialogue message
*/
private Dialogue message;
/**
* Holds the available options on the main menu
*/
private final String [] OPTIONS = {"Instructions", "Train", "Play", "Quit"};
/**
* Initializes and displays the drawing to the frame
*/
public MainMenu() {
loadButtons(OPTIONS);
message = new Dialogue(User.firstMainMenu ? "Click on any of the menu options to enter its screen. Press enter to close this dialogue box. " : "");
drawing = new MainMenuDrawing();
Utility.changeDrawing(drawing);
bgm = new BGM("menus");
bgm.play();
}
/**
* Removes the drawing and removes listeners
*/
public void halt() {
CovidCashier.frame.remove(drawing);
for (Button btn : buttons) btn.deactivate();
message.deactivate();
User.firstMainMenu = false;
timer.stop();
}
/**
* GUI for the instructions
*/
public class MainMenuDrawing extends MenuDrawing {
/**
* Whether the message was just deactivated
*/
private boolean justDeactivated;
/**
* Object constructor. Uses the superclass's constructor
*/
public MainMenuDrawing() {
super();
message.activate();
justDeactivated = false;
}
/**
* GUI display of the main menu
* @param g the Graphics object to draw on
*/
@Override
public void display(Graphics g) {
g.setFont(Utility.TITLE_FONT_SMALL);
g.setColor(Color.black);
g.drawString("COVID Cashier", leftAlign, titleY);
drawReceipt(g);
if (!message.isEmpty() && !message.canProceed()) message.draw(g);
else if (!justDeactivated) {
justDeactivated = true;
for (Button btn : buttons) btn.activate();
message.deactivate();
}
boolean toReturn = false;
for (Button btn : buttons) {
btn.draw(g);
if (!toReturn && btn.isClicked()) {
btn.resetClicked();
if (btn.getName().toUpperCase().equals("PLAY") && !User.hasTrained) {
message = new Dialogue("You cannot enter the Live Level before undergoing training.");
message.activate();
justDeactivated = false;
repaint();
continue;
}
halt();
bgm.stop();
switch (btn.getName().toUpperCase()) {
case "INSTRUCTIONS":
new Instructions();
break;
case "TRAIN":
CovidCashier.setPastRestaurant(new Restaurant(true));
break;
case "PLAY":
CovidCashier.setPastRestaurant(new Restaurant(false));
break;
case "QUIT":
new Quit();
break;
}
toReturn = true;
}
}
if (toReturn) return;
refreshScreen();
}
/**
* Returns the y-coordinate of the title
* @return the MainMenuDrawing object's titleY attribute
*/
@Override
public int getTitleY() {
return titleY;
}
}
}