diff options
| author | sowgro <tpoke.ferrari@gmail.com> | 2024-09-05 22:27:14 -0400 | 
|---|---|---|
| committer | sowgro <tpoke.ferrari@gmail.com> | 2024-09-05 22:27:14 -0400 | 
| commit | a645b476202bd5b44ab5c22253a70269409b5674 (patch) | |
| tree | 39a45622e6b9e8325a7bf13f626b902e7fed0a65 /src | |
| parent | d685d397573c43194fede9b2bbd3aee76d2cd9f8 (diff) | |
| download | NPEhero-a645b476202bd5b44ab5c22253a70269409b5674.tar.gz NPEhero-a645b476202bd5b44ab5c22253a70269409b5674.tar.bz2 NPEhero-a645b476202bd5b44ab5c22253a70269409b5674.zip | |
Add gui scale and other fixes
- add gui scaling and options in settings
- song with endTime of 0 will now properly get time from song length
- suppress unchecked warnings in levelapi
Diffstat (limited to 'src')
7 files changed, 51 insertions, 8 deletions
| diff --git a/src/main/java/net/sowgro/npehero/Driver.java b/src/main/java/net/sowgro/npehero/Driver.java index 411bf87..89381aa 100755 --- a/src/main/java/net/sowgro/npehero/Driver.java +++ b/src/main/java/net/sowgro/npehero/Driver.java @@ -54,6 +54,13 @@ public class Driver extends Application          StackPane root = new StackPane(backgroundImage2, backgroundImage, primaryPane);          Scene primaryScene = new Scene(root, 800,600); +        primaryPane.scaleXProperty().bind(Settings.guiScale); +        primaryPane.scaleYProperty().bind(Settings.guiScale); +        primaryPane.minHeightProperty().bind(root.heightProperty().divide(Settings.guiScale)); +        primaryPane.minWidthProperty() .bind(root.widthProperty() .divide(Settings.guiScale)); +        primaryPane.maxHeightProperty().bind(root.heightProperty().divide(Settings.guiScale)); +        primaryPane.maxWidthProperty() .bind(root.widthProperty() .divide(Settings.guiScale)); +  //        Cant figure out how to center this          backgroundImage.fitHeightProperty().bind(primaryScene.heightProperty());          backgroundImage2.fitHeightProperty().bind(primaryScene.heightProperty()); diff --git a/src/main/java/net/sowgro/npehero/gui/SettingsEditor.java b/src/main/java/net/sowgro/npehero/gui/SettingsEditor.java index f83a8a4..e89dbc9 100755 --- a/src/main/java/net/sowgro/npehero/gui/SettingsEditor.java +++ b/src/main/java/net/sowgro/npehero/gui/SettingsEditor.java @@ -2,9 +2,7 @@ package net.sowgro.npehero.gui;  import javafx.geometry.Insets;  import javafx.geometry.Pos; -import javafx.scene.control.Button; -import javafx.scene.control.CheckBox; -import javafx.scene.control.Slider; +import javafx.scene.control.*;  import javafx.scene.layout.BorderPane;  import javafx.scene.layout.HBox;  import javafx.scene.layout.Pane; @@ -89,6 +87,33 @@ public class SettingsEditor extends Page          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; +            ToggleButton tb = new ToggleButton((int)(val * 100) + "%"); +            tb.setUserData(val); +            tb.getStyleClass().remove("radio-button"); +            tb.getStyleClass().add("button"); +            if (val == Settings.guiScale.get()) { +                tb.setSelected(true); +            } +            scaleOptions[i] = tb; +        } + +        ToggleGroup tg = new ToggleGroup(); +        tg.getToggles().addAll(scaleOptions); +        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)); +          Button exit = new Button();          exit.setText("Back");          exit.setOnAction(e -> { @@ -107,9 +132,8 @@ public class SettingsEditor extends Page          VBox options = new VBox();          options.setSpacing(10);          options.setAlignment(Pos.CENTER); -        options.getChildren().addAll(musicBox,SFXBox,fullBox,controlsBox,buttonBox); -        options.maxWidthProperty().bind(content.prefWidthProperty().multiply(0.25)); -        options.setMinWidth(400); +        options.getChildren().addAll(musicBox,SFXBox,fullBox,controlsBox, scaleBox, buttonBox); +//        options.setPrefWidth(450);          options.prefHeightProperty().bind(content.prefHeightProperty());          content.getChildren().add(options); diff --git a/src/main/java/net/sowgro/npehero/levelapi/Difficulty.java b/src/main/java/net/sowgro/npehero/levelapi/Difficulty.java index c21ecf1..27f025a 100755 --- a/src/main/java/net/sowgro/npehero/levelapi/Difficulty.java +++ b/src/main/java/net/sowgro/npehero/levelapi/Difficulty.java @@ -50,6 +50,7 @@ public class Difficulty implements Comparable<Difficulty>          if (!jsonFile.exists()) {              return;          } +        @SuppressWarnings("unchecked")          Map<String, Object> data = jsonParser.fromJson(new FileReader(jsonFile), Map.class);          if (data == null) {              data = new HashMap<>(); @@ -85,6 +86,7 @@ public class Difficulty implements Comparable<Difficulty>          if (!jsonFile.exists() && !jsonFile.createNewFile()) {              throw new IOException("Could not create file " + jsonFile.getAbsolutePath());          } +        @SuppressWarnings("unchecked")          Map<String, Object> data = jsonParser.fromJson(new FileReader(jsonFile), Map.class); // start with previous values          if (data == null) {              data = new HashMap<>(); diff --git a/src/main/java/net/sowgro/npehero/levelapi/Leaderboard.java b/src/main/java/net/sowgro/npehero/levelapi/Leaderboard.java index bb1f30c..82f9aed 100644 --- a/src/main/java/net/sowgro/npehero/levelapi/Leaderboard.java +++ b/src/main/java/net/sowgro/npehero/levelapi/Leaderboard.java @@ -42,6 +42,7 @@ public class Leaderboard {       */      public void save() throws IOException {          file.createNewFile(); +        @SuppressWarnings("unchecked")          List<Map<String, Object>> data = json.fromJson(new FileReader(file), List.class);          for (LeaderboardEntry cur : entries) {              Map<String, Object> obj = new HashMap<>(); @@ -63,6 +64,7 @@ public class Leaderboard {          if (!file.exists()) {              return;          } +        @SuppressWarnings("unchecked")          List<Map<String, Object>> data = json.fromJson(new FileReader(file), List.class);          if (data == null) {              return; diff --git a/src/main/java/net/sowgro/npehero/levelapi/Level.java b/src/main/java/net/sowgro/npehero/levelapi/Level.java index c90fa47..9b54207 100755 --- a/src/main/java/net/sowgro/npehero/levelapi/Level.java +++ b/src/main/java/net/sowgro/npehero/levelapi/Level.java @@ -6,6 +6,7 @@ import com.google.gson.Gson;  import com.google.gson.GsonBuilder;  import javafx.scene.image.Image;  import javafx.scene.media.Media; +import javafx.scene.media.MediaPlayer;  import javafx.scene.paint.Color;  import java.nio.file.Files; @@ -69,6 +70,7 @@ public class Level implements Comparable<Level>{              if (fileName.contains(SONG_FILE)) {                  songFile = file;                  song = new Media(file.toURI().toString()); +                new MediaPlayer(song); // allows song.getDuration() to return              }              else if (fileName.contains(BACKGROUND_FILE)) {                  backgroundFile = file; @@ -90,6 +92,7 @@ public class Level implements Comparable<Level>{          if (!jsonFile.exists()) {              return;          } +        @SuppressWarnings("unchecked")          Map<String, Object> data = jsonParser.fromJson(new FileReader(jsonFile), Map.class);          title = (String) data.getOrDefault("title", title);          artist = (String) data.getOrDefault("artist", artist); @@ -126,6 +129,7 @@ public class Level implements Comparable<Level>{          if (!jsonFile.exists() && !jsonFile.createNewFile()) {              throw new IOException("Could not create file " + jsonFile.getAbsolutePath());          } +        @SuppressWarnings("unchecked")          Map<String, Object> data = jsonParser.fromJson(new FileReader(jsonFile), Map.class);          data.put("title", title);          data.put("artist", artist); diff --git a/src/main/java/net/sowgro/npehero/main/Control.java b/src/main/java/net/sowgro/npehero/main/Control.java index bb9710a..c842419 100644 --- a/src/main/java/net/sowgro/npehero/main/Control.java +++ b/src/main/java/net/sowgro/npehero/main/Control.java @@ -19,8 +19,8 @@ public enum Control {      LANE3           ("Lane 4", KeyCode.J),      LANE4           ("Lane 5", KeyCode.K),      DELETE_NOTE     ("Delete Note", KeyCode.DELETE), -    NOTE_UP         ("Move Note Up", KeyCode.EQUALS), -    NOTE_DOWN       ("Move Note Down", KeyCode.MINUS), +    NOTE_UP         ("Move Note Up", KeyCode.UP), +    NOTE_DOWN       ("Move Note Down", KeyCode.DOWN),      SCROLL_LOCK     ("Scroll Lock", KeyCode.L),      PLAY_PAUSE      ("Play / Pause", KeyCode.P),      CLEAR_SELECTION ("Clear Selection", KeyCode.ESCAPE), diff --git a/src/main/java/net/sowgro/npehero/main/Settings.java b/src/main/java/net/sowgro/npehero/main/Settings.java index 43dce5a..162f579 100755 --- a/src/main/java/net/sowgro/npehero/main/Settings.java +++ b/src/main/java/net/sowgro/npehero/main/Settings.java @@ -17,6 +17,7 @@ public class Settings  	public static SimpleDoubleProperty effectsVol = new SimpleDoubleProperty(1);  	public static SimpleDoubleProperty musicVol = new SimpleDoubleProperty(1);  	public static SimpleBooleanProperty enableMenuMusic = new SimpleBooleanProperty(true); +	public static SimpleDoubleProperty guiScale = new SimpleDoubleProperty(1);  	private static final Gson jsonParser = new GsonBuilder().serializeNulls().setPrettyPrinting().create();  	private static final File jsonFile = new File("settings.json"); @@ -25,10 +26,12 @@ public class Settings  	 * Reads json data from settings.json  	 */  	public static void read() throws Exception { +		@SuppressWarnings("unchecked")  		Map<String, Object> data = jsonParser.fromJson(new FileReader(jsonFile), Map.class);          effectsVol.set((Double) data.getOrDefault("effectsVol", 1.0));  		musicVol.set((Double) data.getOrDefault("musicVol", 1.0));  		enableMenuMusic.set((Boolean) data.getOrDefault("enableMenuMusic", true)); +		guiScale.set((Double) data.getOrDefault("guiScale", 1.0));  	}  	/** @@ -39,6 +42,7 @@ public class Settings  		data.put("effectsVol", effectsVol.get());  		data.put("musicVol", musicVol.get());  		data.put("enableMenuMusic", enableMenuMusic.get()); +		data.put("guiScale", guiScale.get());  		FileWriter fileWriter = new FileWriter(jsonFile);  		jsonParser.toJson(data, fileWriter);  		fileWriter.close(); | 
