blob: 5a606dc52d928d22e2b0e681d9ff98593bead99d (
plain) (
blame)
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
|
package net.sowgro.npehero.devmenu;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import javafx.geometry.Pos;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.media.Media;
import net.sowgro.npehero.gameplay.Timer;
import net.sowgro.npehero.Driver;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import net.sowgro.npehero.main.Control;
import net.sowgro.npehero.main.Difficulty;
import net.sowgro.npehero.main.Sound;
public class NotesEditor extends Pane
{
Text help;
String t1 = "Press Start to begin recording. Use the same keys. Note: existing notes will be overwritten.";
String t2 = "Now recording. Press Stop or " + Control.LEGACY_STOP.getKey().toString() + " to finish";
Difficulty diff;
Timer timer;
PrintWriter writer;
public NotesEditor(Difficulty diff, Pane prev) throws FileNotFoundException, UnsupportedEncodingException
{
this.diff = diff;
help = new Text(t1);
Text cur = new Text("-----");
Button start = new Button("Start");
start.setOnAction(e -> start());
start.setFocusTraversable(false);
Button stop = new Button("Stop");
stop.setOnAction(e -> stop());
stop.setFocusTraversable(false);
VBox main = new VBox();
main.getChildren().addAll(help,cur,start,stop);
Button exit = new Button();
exit.setText("Back");
exit.setOnAction(e -> {
Sound.playSfx(Sound.BACKWARD);
Driver.setMenu(prev);
});
VBox centerBox = new VBox();
centerBox.setAlignment(Pos.CENTER);
centerBox.setSpacing(10);
centerBox.getChildren().addAll(main,exit);
centerBox.setMinWidth(400);
HBox rootBox = new HBox();
rootBox.prefWidthProperty().bind(super.prefWidthProperty());
rootBox.prefHeightProperty().bind(super.prefHeightProperty());
rootBox.getChildren().add(centerBox);
rootBox.setAlignment(Pos.CENTER);
super.getChildren().add(rootBox);
writer = new PrintWriter(diff.notes.getFile(), "UTF-8");
Scene scene = Driver.primaryStage.getScene();
scene.addEventFilter(KeyEvent.KEY_PRESSED, e -> {
if (e.getCode() == Control.LANE0.getKey()) {
writer.println("d"+timer);
cur.setText("d"+timer);
}
if (e.getCode() == Control.LANE1.getKey()) {
writer.println("f"+timer);
cur.setText("f"+timer);
}
if (e.getCode() == Control.LANE2.getKey()) {
writer.println("s"+timer);
cur.setText("s"+timer);
}
if (e.getCode() == Control.LANE3.getKey()) {
writer.println("j"+timer);
cur.setText("j"+timer);
}
if (e.getCode() == Control.LANE4.getKey()) {
writer.println("k"+timer);
cur.setText("k"+timer);
}
if (e.getCode() == Control.LEGACY_STOP.getKey())
{
stop();
}
e.consume();
});
Driver.primaryStage.setOnCloseRequest(e -> stop());
}
private void start()
{
Sound.playSong(new Media(diff.level.song.toString()));
timer = new Timer(diff.bpm);
help.setText(t2);
}
private void stop()
{
try
{
Sound.stopSong();
diff.numBeats = (int)Double.parseDouble(timer.toString());
timer = null;
writer.close();
help.setText(t1);
}
catch (Exception e)
{
//System.err.println("tried to stop but already stopped");
}
}
}
|