diff options
Diffstat (limited to 'src/main/java/net/sowgro/npehero/gui')
| -rwxr-xr-x | src/main/java/net/sowgro/npehero/gui/LevelSurround.java | 9 | ||||
| -rwxr-xr-x | src/main/java/net/sowgro/npehero/gui/SettingsEditor.java | 177 | 
2 files changed, 114 insertions, 72 deletions
diff --git a/src/main/java/net/sowgro/npehero/gui/LevelSurround.java b/src/main/java/net/sowgro/npehero/gui/LevelSurround.java index e6cc2f4..4b7cc75 100755 --- a/src/main/java/net/sowgro/npehero/gui/LevelSurround.java +++ b/src/main/java/net/sowgro/npehero/gui/LevelSurround.java @@ -3,6 +3,7 @@ package net.sowgro.npehero.gui;  import javafx.animation.AnimationTimer;  import javafx.scene.control.Label;  import javafx.scene.layout.*; +import javafx.scene.paint.Color;  import net.sowgro.npehero.Driver;  import net.sowgro.npehero.gameplay.SongPlayer;  import javafx.geometry.Insets; @@ -12,6 +13,7 @@ import javafx.scene.text.Text;  import net.sowgro.npehero.levelapi.Difficulty;  import net.sowgro.npehero.gameplay.ScoreController;  import net.sowgro.npehero.main.Page; +import net.sowgro.npehero.main.Settings;  import net.sowgro.npehero.main.Sound;  public class LevelSurround extends Page @@ -112,7 +114,12 @@ public class LevelSurround extends Page          var scale = content.prefHeightProperty().divide(720);          game.scaleXProperty().bind(scale);          game.scaleYProperty().bind(scale); -        game.getStyleClass().add("box"); +//        game.getStyleClass().add("box"); +//        game.setEffect(new BoxBlur()); +//        game.setBackground(Color.WHITE); +        BackgroundFill bgf = new BackgroundFill(Color.rgb(0, 0, 0, Settings.gameOpacity), null, null); +        game.setBackground(new Background(bgf)); +          BorderPane gameHolder = new BorderPane(game);          gameHolder.maxHeightProperty().bind(content.prefHeightProperty()); diff --git a/src/main/java/net/sowgro/npehero/gui/SettingsEditor.java b/src/main/java/net/sowgro/npehero/gui/SettingsEditor.java index e89dbc9..c5233b5 100755 --- a/src/main/java/net/sowgro/npehero/gui/SettingsEditor.java +++ b/src/main/java/net/sowgro/npehero/gui/SettingsEditor.java @@ -2,62 +2,37 @@ package net.sowgro.npehero.gui;  import javafx.geometry.Insets;  import javafx.geometry.Pos; +import javafx.scene.Node;  import javafx.scene.control.*; -import javafx.scene.layout.BorderPane;  import javafx.scene.layout.HBox;  import javafx.scene.layout.Pane;  import javafx.scene.layout.VBox; -import javafx.scene.text.Text;  import net.sowgro.npehero.Driver; -import net.sowgro.npehero.main.ErrorDisplay; -import net.sowgro.npehero.main.Page; -import net.sowgro.npehero.main.Settings; -import net.sowgro.npehero.main.Sound; +import net.sowgro.npehero.main.*;  import java.io.IOException;  public class SettingsEditor extends Page  {      private final HBox content = new HBox(); +    private final CheckBox forceDefaultColors; +    private final Slider gameOpacity; +    private final ColorPicker[] colorPickers; + +    record OptionEntry(String label, Node action) { }      public SettingsEditor()      { -        Text musicText = new Text(); -        musicText.setText("Music Volume"); -        musicText.getStyleClass().add("t3"); - -        Slider musicSlider = new Slider(); +        Slider musicSlider = new Slider(0.0, 1.0, 0);          musicSlider.valueProperty().bindBidirectional(Settings.musicVol); -        musicSlider.setMin(0.0); -        musicSlider.setMax(1.0);          CheckBox enableMenuMusic = new CheckBox("Enable Menu Music");          enableMenuMusic.selectedProperty().bindBidirectional(Settings.enableMenuMusic); -        VBox musicBox = new VBox(); -        musicBox.getChildren().addAll(musicText, musicSlider, enableMenuMusic); -        musicBox.getStyleClass().add("box"); -        musicBox.setPadding(new Insets(10)); - - -        Text SFXText = new Text(); -        SFXText.setText("Sound Effects Volume"); -        SFXText.getStyleClass().add("t3"); +        VBox musicBox = new VBox(musicSlider, enableMenuMusic); -        Slider SFXSlider = new Slider(); +        Slider SFXSlider = new Slider(0.0, 1.0, 0);          SFXSlider.valueProperty().bindBidirectional(Settings.effectsVol); -        SFXSlider.setMin(0.0); -        SFXSlider.setMax(1.0); - -        VBox SFXBox = new VBox(); -        SFXBox.getChildren().addAll(SFXText, SFXSlider); -        SFXBox.getStyleClass().add("box"); -        SFXBox.setPadding(new Insets(10)); - - -        Text fullText = new Text(); -        fullText.setText("Fullscreen mode"); -        fullText.getStyleClass().add("t3");          Button fullscreen = new Button();          fullscreen.setText("Toggle (F11)"); @@ -66,15 +41,6 @@ public class SettingsEditor extends Page              Driver.primaryStage.setFullScreen(!Driver.primaryStage.isFullScreen());          }); -        VBox fullBox = new VBox(); -        fullBox.getChildren().addAll(fullText,fullscreen); -        fullBox.getStyleClass().add("box"); -        fullBox.setPadding(new Insets(10)); - - -        Text controlsLabel = new Text("Key Bindings"); -        controlsLabel.getStyleClass().add("t3"); -          Button controlsButton = new Button();          controlsButton.setText("Edit");          controlsButton.setOnAction(_ -> { @@ -82,13 +48,6 @@ public class SettingsEditor extends Page              Driver.setMenu(new ControlEditor());          }); -        VBox controlsBox = new VBox(); -        controlsBox.getStyleClass().add("box"); -        controlsBox.getChildren().addAll(controlsLabel, controlsButton); -        controlsBox.setPadding(new Insets(10)); - -        Label scaleLabel = new Label("UI Scale"); -          ToggleButton[] scaleOptions = new ToggleButton[4];          for (int i = 0; i < scaleOptions.length; i++) {              var val = i * 0.5 + 0.5; @@ -107,36 +66,96 @@ public class SettingsEditor extends Page          tg.selectedToggleProperty().addListener((_, _, newt) -> {              Settings.guiScale.set((Double)newt.getUserData());          }); -          HBox scaleSlider = new HBox(scaleOptions); -        VBox scaleBox = new VBox(scaleLabel, scaleSlider); -        scaleBox.getStyleClass().add("box"); -        scaleBox.setPadding(new Insets(10)); +        colorPickers = new ColorPicker[] { +                new ColorPicker(Settings.defaultColors[0]), +                new ColorPicker(Settings.defaultColors[1]), +                new ColorPicker(Settings.defaultColors[2]), +                new ColorPicker(Settings.defaultColors[3]), +                new ColorPicker(Settings.defaultColors[4]) +        }; +        for (ColorPicker cp : colorPickers) { +            cp.getStyleClass().add("button"); +            cp.setMinHeight(60); +            cp.setMinWidth(60); +        } + +        HBox colorPickerBox = new HBox(); +        colorPickerBox.getChildren().addAll(colorPickers); +        colorPickerBox.setSpacing(10); + +        forceDefaultColors = new CheckBox("Force Default Colors"); +        forceDefaultColors.setSelected(Settings.forceDefaultColors); + +        Button resetColors = new Button("Reset"); +        resetColors.setOnAction(_ -> { +            for (int i = 0; i < colorPickers.length; i++) { +                colorPickers[i].setValue(Settings.DEFAULT_DEFAULT_COLORS[i]); +            } +        }); + +        VBox defaultColors = new VBox(colorPickerBox, forceDefaultColors, resetColors); +        defaultColors.setSpacing(10); + +        gameOpacity = new Slider(0.5, 1.0, 0.75); +        gameOpacity.setMajorTickUnit(0.25); +        gameOpacity.setMinorTickCount(1); +        gameOpacity.setSnapToTicks(true); + +        OptionEntry[][] optionEntries = { +                { +                        new OptionEntry("Music Volume", musicBox), +                        new OptionEntry("Sound Effects Volume", SFXSlider), +                        new OptionEntry("Fullscreen Mode", fullscreen), +                        new OptionEntry("Key Bindings", controlsButton), +                }, +                { +                        new OptionEntry("GUI Scale", scaleSlider), +                        new OptionEntry("Default Block Colors", defaultColors), +                        new OptionEntry("Game Opacity", gameOpacity) +                } +        }; +        HBox options = new HBox(); +        options.setSpacing(10); +        for (OptionEntry[] col : optionEntries) { +            VBox colBox = new VBox(); +            colBox.setSpacing(10); +            colBox.setPrefWidth(420); + +            for (OptionEntry option : col) { +                VBox optionBox = new VBox(new Label(option.label), option.action); +                optionBox.setPadding(new Insets(10)); +                optionBox.setSpacing(5); +                optionBox.getStyleClass().add("box"); +                colBox.getChildren().add(optionBox); +            } +            options.getChildren().add(colBox); +        } +        ScrollPane optionsScroll = new ScrollPane(options); +        optionsScroll.getStyleClass().remove("scroll-pane"); +        optionsScroll.setFitToWidth(true); +//        optionsScroll.setPrefWidth(450); + +        HBox main = new HBox(); +        main.getChildren().addAll(optionsScroll); +        main.setSpacing(10); +        main.maxWidthProperty().bind(content.widthProperty().multiply(0.95)); +        main.maxHeightProperty().bind(content.heightProperty().multiply(0.75));          Button exit = new Button();          exit.setText("Back"); -        exit.setOnAction(e -> { -            try { -                Settings.save(); -            } catch (IOException ex) { -                Driver.setMenu(new ErrorDisplay("Failed to save settings", ex, this)); -            } +        exit.setOnAction(_ -> {              Sound.playSfx(Sound.BACKWARD);              Driver.setMenu(new MainMenu());          }); -        BorderPane buttonBox = new BorderPane(); -        buttonBox.setLeft(exit); - -        VBox options = new VBox(); -        options.setSpacing(10); -        options.setAlignment(Pos.CENTER); -        options.getChildren().addAll(musicBox,SFXBox,fullBox,controlsBox, scaleBox, buttonBox); -//        options.setPrefWidth(450); -        options.prefHeightProperty().bind(content.prefHeightProperty()); +        VBox centerBox = new VBox(); +        centerBox.getChildren().addAll(main, exit); +        centerBox.setSpacing(10); +        centerBox.setAlignment(Pos.CENTER); -        content.getChildren().add(options); +        content.getChildren().add(centerBox);          content.setAlignment(Pos.CENTER);      } @@ -144,5 +163,21 @@ public class SettingsEditor extends Page      public Pane getContent() {          return content;      } + +    @Override +    public void onLeave() { +        Settings.forceDefaultColors = forceDefaultColors.isSelected(); +        Settings.defaultColors[0] = colorPickers[0].getValue(); +        Settings.defaultColors[1] = colorPickers[1].getValue(); +        Settings.defaultColors[2] = colorPickers[2].getValue(); +        Settings.defaultColors[3] = colorPickers[3].getValue(); +        Settings.defaultColors[4] = colorPickers[4].getValue(); +        Settings.gameOpacity = gameOpacity.getValue(); +        try { +            Settings.save(); +        } catch (IOException ex) { +            Driver.setMenu(new ErrorDisplay("Failed to save settings", ex, this)); +        } +    }  }  | 
