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/main/java/net/sowgro/npehero/editor/DiffEditor.java | |
parent | 0adf0b43c9ace0899383299bd6e857806e9a1818 (diff) | |
download | NPEhero-8dd5ddc54f2a38d6c803a2e602898c3b5292f094.tar.gz NPEhero-8dd5ddc54f2a38d6c803a2e602898c3b5292f094.tar.bz2 NPEhero-8dd5ddc54f2a38d6c803a2e602898c3b5292f094.zip |
Redesign LevelEditor and DiffEditor
Diffstat (limited to 'src/main/java/net/sowgro/npehero/editor/DiffEditor.java')
-rwxr-xr-x | src/main/java/net/sowgro/npehero/editor/DiffEditor.java | 163 |
1 files changed, 67 insertions, 96 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 |