mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
settings
This commit is contained in:
@@ -10,16 +10,19 @@ import javafx.application.Application;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.stage.Stage;
|
||||
import org.toop.framework.asset.resources.SettingsAsset;
|
||||
import org.toop.local.AppSettings;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Stack;
|
||||
|
||||
public final class App extends Application {
|
||||
private static Stage stage;
|
||||
private static StackPane root;
|
||||
private static Stack<Layer> stack;
|
||||
|
||||
private static int width;
|
||||
private static int height;
|
||||
private static int height;
|
||||
private static int width;
|
||||
private static SettingsAsset settingsAsset;
|
||||
|
||||
private static boolean isQuitting;
|
||||
|
||||
@@ -29,7 +32,14 @@ public final class App extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws Exception {
|
||||
final StackPane root = new StackPane();
|
||||
|
||||
App.stage = stage;
|
||||
final StackPane root = new StackPane();
|
||||
App.root = root;
|
||||
App.stack = new Stack<>();
|
||||
|
||||
AppSettings settings = new AppSettings();
|
||||
settings.applySettings();
|
||||
|
||||
final Scene scene = new Scene(root);
|
||||
scene.getStylesheets().add(ResourceManager.get(CssAsset.class, "app.css").getUrl());
|
||||
@@ -48,13 +58,8 @@ public final class App extends Application {
|
||||
|
||||
stage.setScene(scene);
|
||||
stage.setResizable(false);
|
||||
|
||||
stage.show();
|
||||
|
||||
App.stage = stage;
|
||||
App.root = root;
|
||||
App.stack = new Stack<>();
|
||||
|
||||
App.width = (int) stage.getWidth();
|
||||
App.height = (int) stage.getHeight();
|
||||
|
||||
|
||||
@@ -6,12 +6,14 @@ import org.toop.app.layer.Layer;
|
||||
import org.toop.app.layer.containers.VerticalContainer;
|
||||
import org.toop.framework.asset.ResourceManager;
|
||||
import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
import org.toop.framework.asset.resources.SettingsAsset;
|
||||
import org.toop.framework.audio.events.AudioEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.ChoiceBox;
|
||||
import org.toop.local.AppSettings;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -19,8 +21,11 @@ public final class OptionsLayer extends Layer {
|
||||
private Locale currentLocale = AppContext.getLocale();
|
||||
private LocalizationAsset locale = ResourceManager.get("localization");
|
||||
|
||||
private static int currentVolume = 25;
|
||||
private static boolean isWindowed = true;
|
||||
AppSettings appSettings = new AppSettings();
|
||||
SettingsAsset settings = appSettings.getPath();
|
||||
|
||||
private int currentVolume = settings.getVolume();
|
||||
private boolean isWindowed = !(settings.getFullscreen());
|
||||
|
||||
OptionsLayer() {
|
||||
super("options.css");
|
||||
@@ -61,6 +66,8 @@ public final class OptionsLayer extends Layer {
|
||||
|
||||
AppContext.setLocale(locale);
|
||||
|
||||
settings.setLocale(locale.toLanguageTag());
|
||||
|
||||
this.currentLocale = AppContext.getLocale();
|
||||
this.locale = ResourceManager.get("localization");
|
||||
|
||||
@@ -70,14 +77,14 @@ public final class OptionsLayer extends Layer {
|
||||
for (final Locale localeFile : locale.getAvailableLocales()) {
|
||||
languageBox.getItems().add(localeFile);
|
||||
}
|
||||
|
||||
languageBox.setValue(currentLocale);
|
||||
}
|
||||
|
||||
private void addVolumeSlider(Container container) {
|
||||
container.addSlider(100, currentVolume, (volume) -> {
|
||||
currentVolume = volume;
|
||||
new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(volume.doubleValue() / 100.0)).asyncPostEvent();
|
||||
settings.setVolume(volume);
|
||||
new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(volume.doubleValue() / 100.0)).asyncPostEvent();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -85,6 +92,7 @@ public final class OptionsLayer extends Layer {
|
||||
container.addToggle("Windowed", "Fullscreen", !isWindowed, (fullscreen) -> {
|
||||
isWindowed = !fullscreen;
|
||||
App.setFullscreen(fullscreen);
|
||||
});
|
||||
settings.setFullscreen(fullscreen);
|
||||
});
|
||||
}
|
||||
}
|
||||
46
app/src/main/java/org/toop/local/AppSettings.java
Normal file
46
app/src/main/java/org/toop/local/AppSettings.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package org.toop.local;
|
||||
|
||||
import org.toop.app.App;
|
||||
import org.toop.framework.asset.resources.SettingsAsset;
|
||||
import org.toop.framework.settings.Settings;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Locale;
|
||||
|
||||
public class AppSettings {
|
||||
|
||||
private SettingsAsset settingsAsset;
|
||||
|
||||
public void applySettings() {
|
||||
SettingsAsset settings = getPath();
|
||||
if (!settings.isLoaded()) {
|
||||
settings.load();
|
||||
}
|
||||
Settings settingsData = settings.getContent();
|
||||
|
||||
AppContext.setLocale(Locale.of(settingsData.locale));
|
||||
App.setFullscreen(settingsData.fullScreen);
|
||||
}
|
||||
|
||||
public SettingsAsset getPath() {
|
||||
if (this.settingsAsset == null) {
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
String basePath;
|
||||
|
||||
if (os.contains("win")) {
|
||||
basePath = System.getenv("APPDATA");
|
||||
if (basePath == null) {
|
||||
basePath = System.getProperty("user.home");
|
||||
}
|
||||
} else if (os.contains("mac")) {
|
||||
basePath = System.getProperty("user.home") + "/Library/Application Support";
|
||||
} else {
|
||||
basePath = System.getProperty("user.home") + "/.config";
|
||||
}
|
||||
|
||||
File settingsFile = new File(basePath + File.separator + "ISY1" + File.separator + "settings.json");
|
||||
this.settingsAsset = new SettingsAsset(settingsFile);
|
||||
}
|
||||
return this.settingsAsset;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user