diff options
author | sowgro <tpoke.ferrari@gmail.com> | 2024-10-14 16:24:47 -0400 |
---|---|---|
committer | sowgro <tpoke.ferrari@gmail.com> | 2024-10-14 16:24:47 -0400 |
commit | 8dd5ddc54f2a38d6c803a2e602898c3b5292f094 (patch) | |
tree | c230867c2a1dea6518e9c6ddc39facfb045c5d56 /src | |
parent | 0adf0b43c9ace0899383299bd6e857806e9a1818 (diff) | |
download | NPEhero-8dd5ddc54f2a38d6c803a2e602898c3b5292f094.tar.gz NPEhero-8dd5ddc54f2a38d6c803a2e602898c3b5292f094.tar.bz2 NPEhero-8dd5ddc54f2a38d6c803a2e602898c3b5292f094.zip |
Redesign LevelEditor and DiffEditor
Diffstat (limited to 'src')
4 files changed, 191 insertions, 274 deletions
diff --git a/src/main/java/net/sowgro/npehero/editor/DiffEditor.java b/src/main/java/net/sowgro/npehero/editor/DiffEditor.java index 2b67013..c4bcdbb 100755 --- a/src/main/java/net/sowgro/npehero/editor/DiffEditor.java +++ b/src/main/java/net/sowgro/npehero/editor/DiffEditor.java @@ -1,18 +1,16 @@ package net.sowgro.npehero.editor; -import javafx.beans.binding.DoubleBinding; import javafx.geometry.Insets; import javafx.geometry.Pos; +import javafx.scene.Node; import javafx.scene.control.*; import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; -import javafx.scene.paint.Color; import net.sowgro.npehero.Driver; -import net.sowgro.npehero.gameplay.Block; +import net.sowgro.npehero.gui.LeaderboardView; import net.sowgro.npehero.gui.LevelSurround; import javafx.scene.layout.VBox; import net.sowgro.npehero.levelapi.Difficulty; -import net.sowgro.npehero.levelapi.Note; import net.sowgro.npehero.main.*; import java.io.IOException; @@ -20,29 +18,27 @@ import java.io.IOException; public class DiffEditor extends Page { private final TextField titleEntry; - Difficulty diff; - ScrollPane scroll; + private final Difficulty diff; + private final ValidIndicator validNotes = new ValidIndicator(); - HBox content = new HBox(); + private final HBox content = new HBox(); - public Page prev; + record OptionEntry(String label, Node action, ValidIndicator vi) { + OptionEntry(String label, Node action) { + this(label, action, null); + } + } public DiffEditor(Difficulty diff, Page prev) { this.diff = diff; - this.prev = prev; - - Label optionsLabel = new Label("Options"); - Label folderNameLabel = new Label("Folder name"); TextField folderName = new TextField(diff.thisDir.getName()); folderName.setDisable(true); - Label titleLabel = new Label("Title"); titleEntry = new TextField(diff.title); - Label scoresLabel = new Label("Scores"); - Button clearScores = new Button("Clear leaderboard"); - clearScores.setOnAction(_ -> { + Button clearLeaderboard = new Button("Clear"); + clearLeaderboard.setOnAction(_ -> { Sound.playSfx(Sound.FORWARD); diff.leaderboard.entries.clear(); try { @@ -50,10 +46,20 @@ public class DiffEditor extends Page } catch (IOException e) { Driver.setMenu(new ErrorDisplay("Failed to clear the leaderboard:\n"+e, this)); } + clearLeaderboard.setDisable(diff.leaderboard.entries.isEmpty()); }); + clearLeaderboard.setDisable(diff.leaderboard.entries.isEmpty()); - Label playLabel = new Label("Play"); - Button playLevel = new Button("Play level"); + Button viewLeaderboard = new Button("View"); + viewLeaderboard.setOnAction(_ -> { + Sound.playSfx(Sound.FORWARD); + Driver.setMenu(new LeaderboardView(diff, this)); + }); + + HBox leaderboardActions = new HBox(viewLeaderboard, clearLeaderboard); + leaderboardActions.setSpacing(10); + + Button playLevel = new Button("Play"); playLevel.setOnAction(_ -> { Sound.playSfx(Sound.FORWARD); if (diff.isValid() && diff.level.isValid()) { @@ -64,32 +70,25 @@ public class DiffEditor extends Page } }); - VBox options = new VBox(folderNameLabel, folderName, titleLabel, titleEntry, scoresLabel, clearScores, playLabel, playLevel); - options.setSpacing(10); -// options.getStyleClass().add("box"); -// options.setPadding(new Insets(5)); - - ScrollPane optionsScroll = new ScrollPane(options); - - Button editNotes = new Button("Edit notes"); + Button editNotes = new Button("Edit Notes"); editNotes.setOnAction(_ -> { Sound.playSfx(Sound.FORWARD); if (diff.level.song == null) { Driver.setMenu(new ErrorDisplay("You must import a song file before editing the notes!", this)); return; } - if (diff.bpm != 0.0) { - Driver.setMenu(new ErrorDisplay( - "Note:\nThe new notes editor does not support bpm and beat based songs. If you continue, the notes will be converted.", - this, - new NotesEditor2(diff, this) - )); - return; - } +// if (diff.bpm != 0.0) { +// Driver.setMenu(new ErrorDisplay( +// "Note:\nThe new notes editor does not support bpm and beat based songs. If you continue, the notes will be converted.", +// this, +// new NotesEditor2(diff, this) +// )); +// return; +// } Driver.setMenu(new NotesEditor2(diff, this)); }); - Button oldEditNotes = new Button("Edit notes (legacy)"); + Button oldEditNotes = new Button("Edit legacy"); oldEditNotes.setOnAction(_ -> { Sound.playSfx(Sound.FORWARD); Driver.setMenu(new ErrorDisplay( @@ -99,56 +98,40 @@ public class DiffEditor extends Page ); }); - HBox scrollContent = new HBox(); - scroll = new ScrollPane(scrollContent); - scroll.setFitToWidth(true); - scroll.getStyleClass().remove("scroll-pane"); - scroll.getStyleClass().add("box"); -// scroll.setPrefHeight(400); -// System.out.println("dbg"+scroll.heightProperty()); - // TODO scroll.heightProperty is 0 here until the window is resized, idk what to do - scroll.prefWidthProperty().bind(scroll.heightProperty().multiply(0.66)); - - Pane[] lanes = new Pane[5]; - for (int i = 0; i < lanes.length; i++) { - lanes[i] = new Pane(); - } - - scrollContent.getChildren().addAll(lanes); - scrollContent.setSpacing(5); - scrollContent.setAlignment(Pos.CENTER); - - diff.notes.list.forEach(n -> lanes[n.lane].getChildren().add(drawBlock(n))); - - VBox notePreview = new VBox(); - - ValidIndicator validNotes = new ValidIndicator(); - if (diff.notes.list.isEmpty()) { - validNotes.setInvalid("This difficulty does not contain any notes!"); + HBox noteActions = new HBox(playLevel, editNotes/*, oldEditNotes*/); + noteActions.setSpacing(10); + + OptionEntry[] optionsEntries = { + new OptionEntry("Folder name", folderName), + new OptionEntry("Title", titleEntry), + new OptionEntry("Scores", leaderboardActions), + new OptionEntry("Notes", noteActions, validNotes), + }; + VBox options = new VBox(); + for (OptionEntry option : optionsEntries) { + Label label = new Label(option.label); + HBox labelBox = new HBox(label); + labelBox.setSpacing(5); + if (option.vi != null) { + labelBox.getChildren().add(option.vi); + } + VBox optionBox = new VBox(labelBox, option.action); + optionBox.setPadding(new Insets(10)); + optionBox.setSpacing(5); + optionBox.getStyleClass().add("box"); + options.getChildren().add(optionBox); } - HBox notesLabel = new HBox(new Label("Notes"), validNotes); - Pane scrollHolder = new Pane(scroll); - scroll.prefHeightProperty().bind(scrollHolder.heightProperty()); - scrollHolder.setPrefHeight(400); - notePreview.getChildren().addAll(notesLabel, scrollHolder, editNotes, oldEditNotes); - notePreview.setSpacing(10); - - VBox left = new VBox(); - left.getChildren().addAll(/*optionsLabel, */optionsScroll); options.setSpacing(10); - optionsScroll.setPrefWidth(350); + + ScrollPane optionsScroll = new ScrollPane(options); optionsScroll.getStyleClass().remove("scroll-pane"); -// optionsScroll.getStyleClass().add("box"); optionsScroll.setFitToWidth(true); -// optionsScroll.setPadding(new Insets(5)); -// optionsft.setPrefHeight(); + optionsScroll.setPrefWidth(500); HBox main = new HBox(); - main.getChildren().addAll(left, notePreview); + main.getChildren().addAll(optionsScroll); main.setSpacing(10); -// main.prefHeightProperty().bind(content.heightProperty().multiply(0.75)); main.maxWidthProperty().bind(content.widthProperty().multiply(0.95)); -// optionsScroll.prefHeightProperty().bind(main.heightProperty()); Button exit = new Button(); exit.setText("Back"); @@ -176,6 +159,13 @@ public class DiffEditor extends Page } @Override + public void onView() { + if (diff.notes.list.isEmpty()) { + validNotes.setInvalid("This difficulty does not contain any notes!"); + } + } + + @Override public void onLeave() { diff.title = titleEntry.getText(); try { @@ -184,23 +174,4 @@ public class DiffEditor extends Page e.printStackTrace(); //TODO } } - - // Duplicates of NotesEditor2 methods, should be made generic and combined - private Block drawBlock(Note n) { - Color color = diff.level.colors[n.lane]; - Block b = new Block(color, false, n); - var sizeBind = scroll.widthProperty().divide(8); - b.heightProperty().bind(sizeBind); - b.widthProperty().bind(sizeBind); - var arcBind = scroll.widthProperty().divide(30); - b.arcHeightProperty().bind(arcBind); - b.arcWidthProperty().bind(arcBind); - b.strokeWidthProperty().bind(scroll.widthProperty().divide(120)); - b.layoutYProperty().bind(secondToScreenPos(n.time.add(0))); - return b; - } - - private DoubleBinding secondToScreenPos(DoubleBinding second) { - return scroll.heightProperty().multiply(second).multiply(0.9); - } }
\ No newline at end of file diff --git a/src/main/java/net/sowgro/npehero/editor/LevelEditor.java b/src/main/java/net/sowgro/npehero/editor/LevelEditor.java index 0578d31..1f30006 100755 --- a/src/main/java/net/sowgro/npehero/editor/LevelEditor.java +++ b/src/main/java/net/sowgro/npehero/editor/LevelEditor.java @@ -2,14 +2,14 @@ package net.sowgro.npehero.editor; import java.io.IOException; -import javafx.beans.property.ReadOnlyStringWrapper; +import javafx.geometry.Insets; import javafx.geometry.Pos; +import javafx.scene.Node; import javafx.scene.control.*; import javafx.scene.layout.*; 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.*; @@ -22,31 +22,32 @@ public class LevelEditor extends Page private final TextField artistEntry; private final TextField descEntry; private final ColorPicker[] colorsPickers; - private final TableView<Difficulty> diffList; - Level level; + private final Level level; - private HBox content = new HBox(); + private final HBox content = new HBox(); - public LevelEditor(Level level, Page prev) - { + record OptionEntry(String label, Node action, ValidIndicator vi) { + OptionEntry(String label, Node action) { + this(label, action, null); + } + } + + + public LevelEditor(Level level, Page prev) { this.level = level; - Label folderNameLabel = new Label("Folder name"); + TextField folderName = new TextField(); if (level.dir != null) { folderName.setText(level.dir.getName()); folderName.setDisable(true); } - Label titleLabel = new Label("Title"); titleEntry = new TextField(level.title); - Label artistLabel = new Label("Artist"); artistEntry = new TextField(level.artist); - Label descLabel = new Label("Description"); descEntry = new TextField(level.desc); - Label colorsLabel = new Label("Colors"); colorsPickers = new ColorPicker[] { new ColorPicker(level.colors[0]), new ColorPicker(level.colors[1]), @@ -64,121 +65,26 @@ public class LevelEditor extends Page colorPickerBox.getChildren().addAll(colorsPickers); colorPickerBox.setSpacing(10); - Label backgroundLabel = new Label("Background Image"); - FileChooser backgroundChooser = new FileChooser(); - backgroundChooser.getExtensionFilters().add(new ExtensionFilter("Image Files (*.png, *.jpg, *.gif)", "*.png", "*.jpg", "*.gif")); - Button backgroundImport = new Button("Import"); - Button backgroundRemove = new Button("Remove"); - backgroundImport.setOnAction(_ -> { - Sound.playSfx(Sound.FORWARD); - var f = backgroundChooser.showOpenDialog(Driver.primaryStage); - if (f == null) { - return; - } - try { - level.addFile(f, Level.BACKGROUND_FILE); - } catch (IOException e) { - // TODO - e.printStackTrace(); - } - backgroundRemove.setDisable(level.background == null); - }); - backgroundRemove.setOnAction(_ -> { - Sound.playSfx(Sound.FORWARD); - try { - level.removeFile(Level.BACKGROUND_FILE); - } catch (IOException e) { - // TODO - e.printStackTrace(); - } - backgroundRemove.setDisable(level.background == null); - }); - backgroundRemove.setDisable(level.background == null); - - Label previewLabel = new Label("Preview Image"); - FileChooser previewChooser = new FileChooser(); - previewChooser.getExtensionFilters().add(new ExtensionFilter("Image Files (*.png, *.jpg, *.gif)", "*.png", "*.jpg", "*.gif")); - Button previewImport = new Button("Import"); - Button previewRemove = new Button("Remove"); - previewImport.setOnAction(_ -> { - Sound.playSfx(Sound.FORWARD); - var f = previewChooser.showOpenDialog(Driver.primaryStage); - if (f == null) { - return; - } - try { - level.addFile(f, Level.PREVIEW_FILE); - } catch (IOException e) { - e.printStackTrace(); // TODO - } - previewRemove.setDisable(level.preview == null); - }); - previewRemove.setOnAction(_ -> { - Sound.playSfx(Sound.FORWARD); - try { - level.removeFile(Level.PREVIEW_FILE); - } catch (IOException e) { - e.printStackTrace(); // TODO - } - previewRemove.setDisable(level.preview == null); - }); - previewRemove.setDisable(level.preview == null); - - HBox songLabel = new HBox(new Label("Song File"), songValid); - FileChooser songChooser = new FileChooser(); - songChooser.getExtensionFilters().add(new ExtensionFilter("Audio Files (*.wav, *.mp3, *.aac)", "*.wav", "*.mp3", "*.aac")); - Button songImport = new Button("Import"); - Button songRemove = new Button("Remove"); - songImport.setOnAction(_ -> { - Sound.playSfx(Sound.FORWARD); - var f = songChooser.showOpenDialog(Driver.primaryStage); - try { - level.addFile(f, Level.SONG_FILE); - } catch (IOException e) { - e.printStackTrace(); // TODO - } - songRemove.setDisable(level.song == null); - }); - songRemove.setOnAction(_ -> { - Sound.playSfx(Sound.FORWARD); - try { - level.removeFile(Level.SONG_FILE); - } catch (IOException e) { - e.printStackTrace(); // TODO - } - songRemove.setDisable(level.song == null); - }); - songRemove.setDisable(level.song == null); - - HBox diffLabel = new HBox(new Label("Difficulties"), diffsInvalid); - diffLabel.setSpacing(5); - - - diffList = new TableView<>(); - - TableColumn<Difficulty,String> diffCol = new TableColumn<>("Difficulty"); - TableColumn<Difficulty,String> validCol = new TableColumn<>("Valid?"); - - diffCol.prefWidthProperty().bind(diffList.widthProperty().multiply(0.45)); - validCol.prefWidthProperty().bind(diffList.widthProperty().multiply(0.45)); - - diffList.getColumns().add(diffCol); - diffList.getColumns().add(validCol); - - diffCol.setCellValueFactory(data -> new ReadOnlyStringWrapper(data.getValue().title)); - validCol.setCellValueFactory(data -> new ReadOnlyStringWrapper(data.getValue().isValid() ? "Yes" : "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 ; - }); + Node songFile = createFileImportBox( + Level.SONG_FILE, + level.song, + "Audio Files (*.wav, *.mp3, *.aac)", + new String[]{"*.wav", "*.mp3", "*.aac"} + ); + + Node previewImage = createFileImportBox( + Level.PREVIEW_FILE, + level.preview, + "Image Files (*.png, *.jpg, *.gif)", + new String[]{"*.png", "*.jpg", "*.gif"} + ); + + Node backgroundImage = createFileImportBox( + Level.BACKGROUND_FILE, + level.background, + "Image Files (*.png, *.jpg, *.gif)", + new String[]{"*.png", "*.jpg", "*.gif"} + ); Button newDiffs = new Button("Edit difficulties"); newDiffs.setOnAction(_ -> { @@ -186,49 +92,57 @@ public class LevelEditor extends Page Driver.setMenu(new DiffList(level, this)); }); - diffList.setSelectionModel(null); - - - var b1 = new HBox(songImport, songRemove); - b1.setSpacing(10); - var b2 = new HBox(previewImport, previewRemove); - b2.setSpacing(10); - var b3 = new HBox(backgroundImport, backgroundRemove); - b3.setSpacing(10); - VBox optionsBox = new VBox(folderNameLabel, folderName, titleLabel, titleEntry, artistLabel, artistEntry, descLabel, descEntry, - songLabel, b1, previewLabel, b2, backgroundLabel, b3, colorsLabel, colorPickerBox/*, new Separator(Orientation.HORIZONTAL), save*/); - optionsBox.setSpacing(10); -// left.setPrefWidth(300); -// optionsBox.setPadding(new Insets(5)); - - ScrollPane leftScroll = new ScrollPane(optionsBox); - leftScroll.getStyleClass().remove("scroll-pane"); -// leftScroll.getStyleClass().add("box"); -// leftScroll.setPadding(new Insets(5)); - leftScroll.setFitToWidth(true); - leftScroll.setPrefWidth(400); - -// VBox center = new VBox(); -// center.setSpacing(10); -// center.setPrefWidth(300); - - VBox right = new VBox(diffLabel, diffList,newDiffs); - right.setSpacing(10); -// right.setPrefWidth(325); + OptionEntry[][] optionEntries = { + { + new OptionEntry("Folder", folderName), + new OptionEntry("Title", titleEntry), + new OptionEntry("Artist", artistEntry), + new OptionEntry("Description", descEntry), + new OptionEntry("Difficulties", newDiffs, diffsInvalid) + }, + { + new OptionEntry("Song File", songFile, songValid), + new OptionEntry("Preview Image", previewImage), + new OptionEntry("Background Image", backgroundImage), + new OptionEntry("Block Colors", colorPickerBox), + } + }; + HBox options = new HBox(); + for (OptionEntry[] col : optionEntries) { + VBox colBox = new VBox(); + colBox.setSpacing(10); + colBox.setPrefWidth(400); + for (OptionEntry option : col) { + Label label = new Label(option.label); + HBox labelBox = new HBox(label); + labelBox.setSpacing(5); + if (option.vi != null) { + labelBox.getChildren().add(option.vi); + } + VBox optionBox = new VBox(labelBox, option.action); + optionBox.setPadding(new Insets(10)); + optionBox.setSpacing(5); + optionBox.getStyleClass().add("box"); + colBox.getChildren().add(optionBox); + } + options.getChildren().add(colBox); + } + options.setSpacing(10); - Label optionsLable = new Label("Options"); - VBox left = new VBox(/*optionsLable, */leftScroll); - left.setSpacing(10); + ScrollPane optionsScroll = new ScrollPane(options); + optionsScroll.getStyleClass().remove("scroll-pane"); + optionsScroll.setFitToWidth(true); +// optionsScroll.setPrefWidth(1100); HBox mainBox = new HBox(); - mainBox.getChildren().addAll(left, right); + mainBox.getChildren().addAll(optionsScroll); mainBox.setSpacing(10); - mainBox.prefHeightProperty().bind(content.heightProperty().multiply(0.75)); + mainBox.maxHeightProperty().bind(content.heightProperty().multiply(0.75)); mainBox.maxWidthProperty().bind(content.widthProperty().multiply(0.95)); Button exit = new Button(); exit.setText("Back"); - exit.setOnAction(e -> { + exit.setOnAction(_ -> { Sound.playSfx(Sound.BACKWARD); Driver.setMenu(prev); }); @@ -253,8 +167,18 @@ public class LevelEditor extends Page @Override public void onView() { - diffList.refresh(); - validate(); + // 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!"); + } else { + songValid.setValid(); + } } @Override @@ -269,20 +193,42 @@ public class LevelEditor extends Page level.colors[4] = colorsPickers[4].getValue(); try { level.writeMetadata(); - } catch (IOException ex) { - // TODO + } catch (IOException e) { + e.printStackTrace(); // TODO } - 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!"); - } + private Node createFileImportBox(String filename, Object dest, String extDesc, String[] extensions) { + FileChooser fileChooser = new FileChooser(); + fileChooser.getExtensionFilters().add(new ExtensionFilter(extDesc, extensions)); + Button importButton = new Button("Import"); + Button removeButton = new Button("Remove"); + importButton.setOnAction(_ -> { + Sound.playSfx(Sound.FORWARD); + var f = fileChooser.showOpenDialog(Driver.primaryStage); + if (f == null) { + return; + } + try { + level.addFile(f, filename); + } catch (IOException e) { + e.printStackTrace(); // TODO + } + removeButton.setDisable(dest == null); + }); + removeButton.setOnAction(_ -> { + Sound.playSfx(Sound.FORWARD); + try { + level.removeFile(filename); + } catch (IOException e) { + e.printStackTrace(); // TODO + } + removeButton.setDisable(dest == null); + }); + removeButton.setDisable(dest == null); + + var b1 = new HBox(importButton, removeButton); + b1.setSpacing(10); + return b1; } }
\ No newline at end of file diff --git a/src/main/java/net/sowgro/npehero/editor/NotesEditor2.java b/src/main/java/net/sowgro/npehero/editor/NotesEditor2.java index 50bfbcb..6e58ae6 100644 --- a/src/main/java/net/sowgro/npehero/editor/NotesEditor2.java +++ b/src/main/java/net/sowgro/npehero/editor/NotesEditor2.java @@ -222,7 +222,7 @@ public class NotesEditor2 extends Page { // TODO } Sound.playSfx(Sound.BACKWARD); - Driver.setMenu(new DiffEditor(diff, prev.prev)); + Driver.setMenu(prev); }); HBox buttons = new HBox(save, exit); diff --git a/src/main/java/net/sowgro/npehero/main/ValidIndicator.java b/src/main/java/net/sowgro/npehero/main/ValidIndicator.java index 79df643..f2b38d2 100644 --- a/src/main/java/net/sowgro/npehero/main/ValidIndicator.java +++ b/src/main/java/net/sowgro/npehero/main/ValidIndicator.java @@ -30,7 +30,7 @@ public class ValidIndicator extends Region { SVGPath diffLabelIcon = new SVGPath(); diffLabelIcon.setContent(pathFromSvg(Driver.getResource("error.svg"))); this.setShape(diffLabelIcon); - this.setBackground(Background.fill(Color.web("#a70000"))); + this.setBackground(Background.fill(Color.RED)); Tooltip.install(this, diffLabelTooltip); } |