-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainMenu.java
167 lines (143 loc) · 4.96 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
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
import greenfoot.Color;
import greenfoot.Greenfoot;
import greenfoot.GreenfootImage;
import greenfoot.World;
import javax.swing.*;
import java.io.File;
import java.util.ArrayList;
/**
* Main song selection menu.
*
* @author Team APCSA 2019
* @author Andy Ge
* @author Andrew Vittiglio
* @author Steve Rosario
* @author Yijie Gui
* @author Russell Doucet
* @author William LoGiudice
* @author Maanik George
* @author Mr. Gilmore (Teacher)
* @version 2019-05-24 20:37
*/
public class MainMenu extends World
{
/**
* Constructor for objects of class MainMenu.
*/
public MainMenu()
{
super(Constants.WIDTH, Constants.HEIGHT, 1);
// Get the beatmap sets.
ArrayList<File> beatmapSets = BeatmapReader.listBeatmapSets();
// Draw the background
drawBackground();
// Put song selection buttons in.
putSongSelectionButtons(beatmapSets);
}
/**
* Draw the background
*/
private void drawBackground()
{
// Draw wallpaper
{
GreenfootImage wallpaper = new GreenfootImage(Images.WALLPAPER);
int origWidth = wallpaper.getWidth();
int origHeight = wallpaper.getHeight();
wallpaper.scale((int) (1.0 * origWidth / origHeight * Constants.HEIGHT), Constants.HEIGHT);
getBackground().drawImage(wallpaper, 0, 0);
}
// Darken wallpaper with a black overlay
{
Images.BLACK.scale(Constants.WIDTH, Constants.HEIGHT);
Images.BLACK.setTransparency(Constants.GRAPHIC_WALLPAPER_DARKEN);
getBackground().drawImage(Images.BLACK, 0, 0);
}
// Draw "Song Select"
{
// Get text and make an image
GreenfootImage text = new GreenfootImage("Song Select", 20, Color.WHITE, null);
// Calculate the x and y that the text is centered within a separation space.
int x = Constants.WIDTH / 2 - text.getWidth() / 2;
int y = (Constants.SELECTION_TOP_PADDING + Constants.SELECTION_MIN_SPACING) / 2 - text.getHeight() / 2;
// Draw it
getBackground().drawImage(text, x, y);
}
// Put in Key bind editors
{
for (int i = 0; i < Constants.NUM_COLS; i++)
{
KeyBindEditor keyBindEditor = new KeyBindEditor(i);
addObject(keyBindEditor, 0, 0);
keyBindEditor.init();
}
}
}
/**
* Put the song selection buttons, MainMenuSongCover, in the world.
*
* @param beatmapSets Beatmap sets
*/
private void putSongSelectionButtons(ArrayList<File> beatmapSets)
{
for (int i = 0; i < beatmapSets.size(); i++)
{
File beatmapSetDirectory = beatmapSets.get(i);
MainMenuSongCover songSelect = new MainMenuSongCover(beatmapSetDirectory, i);
addObject(songSelect, 0, 0);
songSelect.init();
}
}
/**
* Show a dialog to select song. This method is used before this
* menu existed.
*/
@Deprecated
public static void launchSongSelectionDialog()
{
// Optimization: Use a different thread.
new Thread(() ->
{
// List beatmap sets.
ArrayList<File> beatmapSets = BeatmapReader.listBeatmapSets();
StringBuilder text = new StringBuilder("Please choose a beatmap.\nAvailable Beatmaps:\n");
for (File beatmapSet : beatmapSets)
{
text.append("- ").append(beatmapSet.getName()).append("\n");
}
text.append("Please input the beatmap ID:");
// Read user input
String beatmapId = JOptionPane.showInputDialog(text);
// Verify input
File beatmapSet = BeatmapReader.findBeatmapSetById(beatmapId);
if (beatmapSet == null)
{
JOptionPane.showMessageDialog(null, "Error: Beatmap not found.");
throw new RuntimeException("Error: Beatmap not found.");
}
// List difficulties
ArrayList<String> diffs = BeatmapReader.listDifficulties(beatmapSet);
text = new StringBuilder("Please choose a difficulty:\n");
for (String diff : diffs)
{
text.append("- ").append(diff).append("\n");
}
text.append("Please input the difficulty of your choice:");
// Read user input
String difficulty = JOptionPane.showInputDialog(text);
// Make world
BeatmapWorld beatmapWorld = new BeatmapWorld(beatmapSet, difficulty);
Greenfoot.setWorld(beatmapWorld);
beatmapWorld.startGame();
}).start();
}
/**
* Launch the world as fast as possible.
*/
public static void launchTest()
{
BeatmapWorld world = new BeatmapWorld("398366", "Normal");
Greenfoot.setWorld(world);
world.startGame();
}
}