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
|
package net.sowgro.npehero.editor;
import java.io.File;
import java.io.IOException;
import javafx.beans.property.ReadOnlyStringWrapper;
import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.text.Text;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser.ExtensionFilter;
import net.sowgro.npehero.Driver;
import net.sowgro.npehero.levelapi.Difficulty;
import net.sowgro.npehero.levelapi.Level;
import net.sowgro.npehero.main.*;
public class LevelEditor extends Page
{
private final ValidIndicator songValid = new ValidIndicator();
private final ValidIndicator diffsInvalid = new ValidIndicator();
Level level;
private HBox content = new HBox();
private File selectedSong = null;
private File selectedPreview = null;
private File selectedBackground = null;
public LevelEditor(Level level, Page prev)
{
this.level = level;
Text folderNameLabel = new Text("Folder name");
TextField folderName = new TextField();
if (level.dir != null) {
folderName.setText(level.dir.getName());
folderName.setDisable(true);
}
Text titleLabel = new Text("Title");
TextField title = new TextField(level.title);
Text artistLabel = new Text("Artist");
TextField artist = new TextField(level.artist);
Text descLabel = new Text("Description");
TextField desc = new TextField(level.desc);
Text colorsLabel = new Text("Colors");
ColorPicker[] colorsPickers = new ColorPicker[] {
new ColorPicker(level.colors[0]),
new ColorPicker(level.colors[1]),
new ColorPicker(level.colors[2]),
new ColorPicker(level.colors[3]),
new ColorPicker(level.colors[4])
};
for (ColorPicker cp : colorsPickers) {
cp.getStyleClass().add("button");
}
HBox colorPickerBox = new HBox();
colorPickerBox.getChildren().addAll(colorsPickers);
HBox filesLabel = new HBox(new Text("Files"), songValid);
FileChooser backgroundChooser = new FileChooser();
backgroundChooser.getExtensionFilters().add(new ExtensionFilter("Image Files", "*.png", "*.jpg", "*.gif"));
Button backgroundButton = new Button("Background Image");
backgroundButton.setOnAction(_ -> selectedBackground = backgroundChooser.showOpenDialog(Driver.primaryStage));
FileChooser previewChooser = new FileChooser();
previewChooser.getExtensionFilters().add(new ExtensionFilter("Image Files", "*.png", "*.jpg", "*.gif"));
Button previewButton = new Button("Preview Image");
previewButton.setOnAction(_ -> selectedPreview = previewChooser.showOpenDialog(Driver.primaryStage));
FileChooser songChooser = new FileChooser();
songChooser.getExtensionFilters().add(new ExtensionFilter("Audio Files", "*.wav", "*.mp3", "*.aac"));
Button songButton = new Button("Song file");
songButton.setOnAction(_ -> selectedSong = songChooser.showOpenDialog(Driver.primaryStage));
HBox diffLabel = new HBox(new Text("Difficulties"), diffsInvalid);
diffLabel.setSpacing(5);
TableView<Difficulty> diffList = new TableView<>();
TableColumn<Difficulty,String> diffCol = new TableColumn<>("Difficulty");
TableColumn<Difficulty,String> validCol = new TableColumn<>("Valid?");
diffList.getColumns().add(diffCol);
diffList.getColumns().add(validCol);
diffCol.setCellValueFactory(data -> new ReadOnlyStringWrapper(data.getValue().title));
validCol.setCellValueFactory(data -> {
if (data.getValue().isValid()) {
return new ReadOnlyStringWrapper("Yes");
}
else {
return new ReadOnlyStringWrapper("No");
}
});
diffList.setItems(level.difficulties.list);
diffList.setRowFactory( _ -> {
TableRow<Difficulty> row = new TableRow<>();
row.setOnMouseClicked(event -> {
if (event.getClickCount() == 2 && (! row.isEmpty()) ) {
Difficulty rowData = row.getItem();
Driver.setMenu(new DiffEditor(rowData, this));
}
});
return row ;
});
Button newDiffs = new Button("Edit difficulties");
newDiffs.setOnAction(_ -> Driver.setMenu(new DiffList(level, this)));
diffList.setSelectionModel(null);
Button save = new Button("Save");
save.setOnAction(e -> { //assigns fields to values
level.title = title.getText();
level.artist = artist.getText();
level.desc = desc.getText();
level.colors[0] = colorsPickers[0].getValue();
level.colors[1] = colorsPickers[1].getValue();
level.colors[2] = colorsPickers[2].getValue();
level.colors[3] = colorsPickers[3].getValue();
level.colors[4] = colorsPickers[4].getValue();
try {
if (selectedBackground != null && selectedBackground.exists()) {
level.addFile(selectedBackground, "background");
}
if (selectedPreview != null && selectedPreview.exists()) {
level.addFile(selectedPreview, "preview");
}
if (selectedSong != null) {
level.addFile(selectedSong, "song");
}
} catch (Exception ex) {
// TODO
ex.printStackTrace();
}
try {
level.writeMetadata();
} catch (IOException ex) {
// TODO
ex.printStackTrace();
}
validate();
});
VBox left = new VBox(filesLabel, songButton, previewButton, backgroundButton, colorsLabel, colorPickerBox);
left.setSpacing(10);
left.setPrefWidth(300);
VBox center = new VBox(folderNameLabel,folderName,titleLabel,title,artistLabel,artist,descLabel,desc);
center.setSpacing(10);
center.setPrefWidth(300);
VBox right = new VBox(diffLabel,diffList,newDiffs);
right.setSpacing(10);
center.setPrefWidth(300);
HBox mainBox = new HBox();
mainBox.getChildren().addAll(left, center, right);
mainBox.setSpacing(30);
Button exit = new Button();
exit.setText("Back");
exit.setOnAction(e -> {
Sound.playSfx(Sound.BACKWARD);
Driver.setMenu(prev);
});
HBox bottom = new HBox(exit, save);
bottom.setAlignment(Pos.CENTER);
bottom.setSpacing(10);
VBox centerBox = new VBox();
centerBox.getChildren().addAll(mainBox, bottom);
centerBox.setSpacing(10);
centerBox.setAlignment(Pos.CENTER);
content.getChildren().add(centerBox);
content.setAlignment(Pos.CENTER);
}
@Override
public Pane getContent() {
return content;
}
@Override
public void onView() {
validate();
}
public void validate() {
if (level.difficulties.getValidList().isEmpty()) {
diffsInvalid.setInvalid("This level contains no valid difficulties!");
} else {
diffsInvalid.setValid();
}
if (level.song == null) {
songValid.setInvalid("Missing song file!");
}
}
}
|