mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 19:04:49 +00:00
Merge remote-tracking branch 'origin/Settings' into UI
# Conflicts: # app/src/main/java/org/toop/app/App.java # app/src/main/java/org/toop/app/layer/layers/OptionsLayer.java # framework/src/main/java/org/toop/framework/audio/SoundManager.java
This commit is contained in:
@@ -13,16 +13,21 @@ 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.framework.audio.events.AudioEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
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;
|
||||
|
||||
@@ -32,7 +37,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());
|
||||
@@ -63,7 +75,6 @@ public final class App extends Application {
|
||||
|
||||
App.isQuitting = false;
|
||||
|
||||
new EventFlow().addPostEvent(new AudioEvents.StartBackgroundMusic()).asyncPostEvent();
|
||||
activate(new MainLayer());
|
||||
}
|
||||
|
||||
|
||||
@@ -4,18 +4,28 @@ import org.toop.app.App;
|
||||
import org.toop.app.layer.Container;
|
||||
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;
|
||||
|
||||
public final class OptionsLayer extends Layer {
|
||||
private static int currentVolume = 0;
|
||||
private static boolean isWindowed = true;
|
||||
private Locale currentLocale = AppContext.getLocale();
|
||||
private LocalizationAsset locale = ResourceManager.get("localization");
|
||||
|
||||
AppSettings appSettings = new AppSettings();
|
||||
SettingsAsset settings = appSettings.getPath();
|
||||
|
||||
private int currentVolume = settings.getVolume();
|
||||
private boolean isWindowed = !(settings.getFullscreen());
|
||||
|
||||
OptionsLayer() {
|
||||
super("options.css");
|
||||
@@ -59,6 +69,10 @@ public final class OptionsLayer extends Layer {
|
||||
}
|
||||
|
||||
AppContext.setLocale(locale);
|
||||
|
||||
this.currentLocale = AppContext.getLocale();
|
||||
this.locale = ResourceManager.get("localization");
|
||||
|
||||
App.reloadAll();
|
||||
});
|
||||
|
||||
@@ -79,12 +93,14 @@ public final class OptionsLayer extends Layer {
|
||||
});
|
||||
|
||||
languageBox.setValue(AppContext.getLocale());
|
||||
languageBox.setValue(currentLocale);
|
||||
}
|
||||
|
||||
private void addVolumeSlider(Container container) {
|
||||
container.addSlider(100, currentVolume, (volume) -> {
|
||||
currentVolume = volume;
|
||||
new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(volume.doubleValue())).asyncPostEvent();
|
||||
settings.setVolume(volume);
|
||||
new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(volume.doubleValue())).asyncPostEvent();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -92,6 +108,7 @@ public final class OptionsLayer extends Layer {
|
||||
container.addToggle(AppContext.getString("windowed"), AppContext.getString("fullscreen"), !isWindowed, (fullscreen) -> {
|
||||
isWindowed = !fullscreen;
|
||||
App.setFullscreen(fullscreen);
|
||||
});
|
||||
settings.setFullscreen(fullscreen);
|
||||
});
|
||||
}
|
||||
}
|
||||
50
app/src/main/java/org/toop/local/AppSettings.java
Normal file
50
app/src/main/java/org/toop/local/AppSettings.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package org.toop.local;
|
||||
|
||||
import org.toop.app.App;
|
||||
import org.toop.framework.asset.resources.SettingsAsset;
|
||||
import org.toop.framework.audio.events.AudioEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
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);
|
||||
new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(settingsData.volume)).asyncPostEvent();
|
||||
|
||||
}
|
||||
|
||||
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