-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu.java
219 lines (191 loc) · 7.53 KB
/
Menu.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.BoxLayout;
import javax.swing.Box;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JScrollPane;
import javax.swing.BorderFactory;
import java.awt.event.ActionListener;
import java.awt.event.KeyListener;
import java.awt.Dimension;
import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Font;
import java.awt.Component;
import java.awt.BorderLayout;
/**
* Handles the main menu screen
*
* @author Dewan Mukto
* @version 2024-10-10
*/
public class Menu extends JPanel {
public Menu() {
setPreferredSize(new Dimension(800, 600));
setBackground(Color.BLACK);
setFocusable(true);
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); // Center everything vertically
// Add title "DELTA"
JLabel title = new JLabel("DELTA", SwingConstants.CENTER);
title.setFont(new Font("SansSerif", Font.BOLD, 48));
title.setForeground(Color.WHITE);
title.setAlignmentX(Component.CENTER_ALIGNMENT);
add(title);
// Add subtitle "Telekom" to fit the exact width of the title above
JLabel subtitle = new JLabel("Telekom", SwingConstants.CENTER);
subtitle.setFont(new Font("SansSerif", Font.PLAIN, 32));
subtitle.setForeground(Color.GRAY);
subtitle.setAlignmentX(Component.CENTER_ALIGNMENT);
add(subtitle);
add(Box.createRigidArea(new Dimension(0, 100))); // Plenty of space
// Rectangular buttons stacked in a column that change color slightly on hover
JButton playButton = createButton("Play");
playButton.addActionListener(e -> {
removeAll();
revalidate();
repaint();
Game gamePanel = new Game();
add(gamePanel);
gamePanel.requestFocusInWindow();
revalidate();
repaint();
});
add(playButton);
JButton helpButton = createButton("Help");
helpButton.addActionListener(e -> {
removeAll(); // Clear Menu
showHelpInfo(); // Show Help
revalidate();
repaint();
});
add(helpButton);
JButton exitButton = createButton("Exit");
exitButton.addActionListener(e -> terminate());
add(exitButton);
}
// Quick method to create buttons with hover effect
private JButton createButton(String text) {
JButton button = new JButton(text);
button.setAlignmentX(Component.CENTER_ALIGNMENT);
button.setMaximumSize(new Dimension(200, 40));
button.setBackground(Color.blue);
button.setForeground(Color.WHITE);
button.setFocusPainted(false);
button.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
button.setBackground(Color.getHSBColor(2.24f, 1.00f, 0.5882f));
}
public void mouseExited(MouseEvent e) {
button.setBackground(Color.blue);
}
});
return button;
}
private void showHelpInfo() {
setLayout(new BorderLayout());
// Add custom scroll bar to the right-side with rectangles
JEditorPane helpText = new JEditorPane();
helpText.setEditable(false);
helpText.setBackground(Color.BLACK);
helpText.setForeground(Color.WHITE);
helpText.setContentType("text/html");
helpText.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
helpText.setText("<html>"
+ "<center><font color='#cfcfcf'>v0.1.4</font></center>"
+ "<style>a { text-decoration: none; color: #aaabbd }</style>"
+ "<div style='padding: 10px; color: white;'>CONTROLS</div>"
+ "<div style='padding-left: 10px; color: #aaaaaa;'>"
+ "Use <font color='#ff0a45'>W,A,S,D</font> or <font color='#ff0a45'>arrow keys</font> to move<br>"
+ "Press <font color='#ff0a45'>E</font> to interact, use"
+ "</div><br><br>"
+ "<div style='padding: 10px; color: white;'>ABOUT</div>"
+ "<div style='padding-left: 10px; color: #aaaaaa;'>"
+ "Based on people I met in a real Discord server<br>"
+ "Developed by <font color='#ff0a45'>Dewan Mukto</font> (<a href='https://x.com/dewan_mukto'>@dewan_mukto</a>)<br>"
+ "Character sprites by <font color='#ff0a45'>Glitched Velocity</font> (<a href='https://x.com/VazahatJordan'>@VazahatJordan</a>)<br>"
+ "All other images are generated using fractals and math!<br>"
+ "Published by <font color='#ff0a45'>Muxday</font>"
+ "</div>"
+ "</html>");
JScrollPane scrollPane = new JScrollPane(helpText);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
scrollPane.getVerticalScrollBar().setUI(new CustomScrollBarUI());
add(scrollPane, BorderLayout.CENTER);
JButton backButton = createButton("Back");
backButton.addActionListener(e -> {
removeAll();
setLayout(new BoxLayout(Menu.this, BoxLayout.Y_AXIS));
reinitializeMenu();
revalidate();
repaint();
});
add(backButton, BorderLayout.SOUTH);
}
// Custom scroll bar UI with rectangles
private class CustomScrollBarUI extends javax.swing.plaf.basic.BasicScrollBarUI {
@Override
protected void configureScrollBarColors() {
thumbColor = Color.GRAY;
}
@Override
protected JButton createDecreaseButton(int orientation) {
return createInvisibleButton();
}
@Override
protected JButton createIncreaseButton(int orientation) {
return createInvisibleButton();
}
private JButton createInvisibleButton() {
JButton button = new JButton();
button.setPreferredSize(new Dimension(0, 0));
button.setVisible(false);
return button;
}
}
private void reinitializeMenu() {
// Add title "DELTA"
JLabel title = new JLabel("DELTA", SwingConstants.CENTER);
title.setFont(new Font("SansSerif", Font.BOLD, 48));
title.setForeground(Color.WHITE);
title.setAlignmentX(Component.CENTER_ALIGNMENT);
add(title);
// Add subtitle "Telekom" to fit the exact width of the title above
JLabel subtitle = new JLabel("Telekom", SwingConstants.CENTER);
subtitle.setFont(new Font("SansSerif", Font.PLAIN, 32));
subtitle.setForeground(Color.GRAY);
subtitle.setAlignmentX(Component.CENTER_ALIGNMENT);
add(subtitle);
add(Box.createRigidArea(new Dimension(0, 100))); // Plenty of space
// Rectangular buttons stacked in a column that change color slightly on hover
JButton playButton = createButton("Play");
playButton.addActionListener(e -> {
removeAll();
revalidate();
repaint();
Game gamePanel = new Game();
add(gamePanel);
gamePanel.requestFocusInWindow();
revalidate();
repaint();
});
add(playButton);
JButton helpButton = createButton("Help");
helpButton.addActionListener(e -> {
removeAll(); // Clear Menu
showHelpInfo(); // Show Help
revalidate();
repaint();
});
add(helpButton);
JButton exitButton = createButton("Exit");
exitButton.addActionListener(e -> terminate());
add(exitButton);
}
private void terminate() {
System.exit(0); // Close everything and quit the program
}
}