Merge remote-tracking branch 'origin/185-networkingeventlistener' into UI

# Conflicts:
#	app/src/main/java/org/toop/app/App.java
#	app/src/main/java/org/toop/app/layer/layers/ConnectedLayer.java
#	app/src/main/java/org/toop/app/layer/layers/MainLayer.java
#	app/src/main/java/org/toop/app/layer/layers/OptionsPopup.java
#	app/src/main/java/org/toop/app/layer/layers/game/TicTacToeLayer.java
#	app/src/main/java/org/toop/local/AppSettings.java
This commit is contained in:
lieght
2025-10-15 21:05:01 +02:00
72 changed files with 2972 additions and 1838 deletions

View File

@@ -1,11 +1,13 @@
package org.toop;
import org.toop.app.App;
import org.toop.framework.audio.SoundManager;
import org.toop.framework.audio.*;
import org.toop.framework.networking.NetworkingClientEventListener;
import org.toop.framework.networking.NetworkingClientManager;
import org.toop.framework.networking.NetworkingInitializationException;
import org.toop.framework.resource.ResourceLoader;
import org.toop.framework.resource.ResourceManager;
import org.toop.framework.resource.resources.MusicAsset;
import org.toop.framework.resource.resources.SoundEffectAsset;
public final class Main {
static void main(String[] args) {
@@ -13,9 +15,25 @@ public final class Main {
App.run(args);
}
private static void initSystems() throws NetworkingInitializationException {
private static void initSystems() {
ResourceManager.loadAssets(new ResourceLoader("app/src/main/resources/assets"));
new Thread(NetworkingClientManager::new).start();
new Thread(SoundManager::new).start();
new Thread(() -> new NetworkingClientEventListener(new NetworkingClientManager())).start();
new Thread(() -> {
MusicManager<MusicAsset> musicManager = new MusicManager<>(ResourceManager.getAllOfTypeAndRemoveWrapper(MusicAsset.class), true);
SoundEffectManager<SoundEffectAsset> soundEffectManager = new SoundEffectManager<>(ResourceManager.getAllOfType(SoundEffectAsset.class));
AudioVolumeManager audioVolumeManager = new AudioVolumeManager()
.registerManager(VolumeControl.MASTERVOLUME, musicManager)
.registerManager(VolumeControl.MASTERVOLUME, soundEffectManager)
.registerManager(VolumeControl.FX, soundEffectManager)
.registerManager(VolumeControl.MUSIC, musicManager);
new AudioEventListener<>(
musicManager,
soundEffectManager,
audioVolumeManager
).initListeners("medium-button-click.wav");
}).start();
}
}

View File

@@ -1,8 +1,15 @@
package org.toop.app;
import org.toop.app.view.ViewStack;
import org.toop.app.view.views.MainView;
import org.toop.app.view.views.QuitView;
import java.util.Stack;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import org.toop.app.layer.Layer;
import org.toop.app.layer.layers.MainLayer;
import org.toop.app.layer.layers.QuitPopup;
import org.toop.framework.audio.VolumeControl;
import org.toop.framework.audio.events.AudioEvents;
import org.toop.framework.eventbus.EventFlow;
import org.toop.framework.resource.ResourceManager;
@@ -10,110 +17,154 @@ import org.toop.framework.resource.resources.CssAsset;
import org.toop.local.AppContext;
import org.toop.local.AppSettings;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public final class App extends Application {
private static Stage stage;
private static Scene scene;
private static Stage stage;
private static Scene scene;
private static StackPane root;
private static Stack<Layer> stack;
private static int height;
private static int width;
private static boolean isQuitting;
private static boolean isQuitting;
public static void run(String[] args) {
launch(args);
}
public static void run(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
@Override
public void start(Stage stage) throws Exception {
final StackPane root = new StackPane();
final Scene scene = new Scene(root);
ViewStack.setup(scene);
final Scene scene = new Scene(root);
stage.setTitle(AppContext.getString("app-title"));
stage.setWidth(1080);
stage.setHeight(720);
stage.setTitle(AppContext.getString("appTitle"));
stage.setWidth(1080);
stage.setHeight(720);
stage.setOnCloseRequest(event -> {
event.consume();
startQuit();
});
stage.setOnCloseRequest(
event -> {
event.consume();
stage.setScene(scene);
stage.setResizable(false);
if (!isQuitting) {
quitPopup();
}
});
stage.show();
stage.setScene(scene);
stage.setResizable(false);
App.stage = stage;
App.scene = scene;
stage.show();
App.width = (int)stage.getWidth();
App.height = (int)stage.getHeight();
App.stage = stage;
App.scene = scene;
App.root = root;
App.isQuitting = false;
App.stack = new Stack<>();
AppSettings.applySettings();
new EventFlow().addPostEvent(new AudioEvents.StartBackgroundMusic()).asyncPostEvent();
App.width = (int) stage.getWidth();
App.height = (int) stage.getHeight();
ViewStack.push(new MainView());
}
App.isQuitting = false;
public static void startQuit() {
if (isQuitting) {
return;
}
new EventFlow().addPostEvent(new AudioEvents.StartBackgroundMusic()).postEvent();
ViewStack.push(new QuitView());
isQuitting = true;
}
final AppSettings settings = new AppSettings();
settings.applySettings();
public static void stopQuit() {
ViewStack.pop();
isQuitting = false;
}
activate(new MainLayer());
}
public static void quit() {
ViewStack.cleanup();
stage.close();
}
public static void activate(Layer layer) {
Platform.runLater(
() -> {
popAll();
push(layer);
});
}
public static void reload() {
stage.setTitle(AppContext.getString("app-title"));
ViewStack.reload();
}
public static void push(Layer layer) {
Platform.runLater(
() -> {
root.getChildren().addLast(layer.getLayer());
stack.push(layer);
});
}
public static void setFullscreen(boolean fullscreen) {
stage.setFullScreen(fullscreen);
public static void pop() {
Platform.runLater(
() -> {
root.getChildren().removeLast();
stack.pop();
width = (int) stage.getWidth();
height = (int) stage.getHeight();
isQuitting = false;
});
}
reload();
}
public static void popAll() {
Platform.runLater(
() -> {
final int childrenCount = root.getChildren().size();
public static void setStyle(String theme, String layoutSize) {
final int stylesCount = scene.getStylesheets().size();
for (int i = 0; i < childrenCount; i++) {
try {
root.getChildren().removeLast();
} catch (Exception e) {
IO.println(e); // TODO: Use logger
}
}
for (int i = 0; i < stylesCount; i++) {
scene.getStylesheets().removeLast();
}
stack.removeAllElements();
});
}
scene.getStylesheets().add(ResourceManager.<CssAsset>get("general.css").getUrl());
scene.getStylesheets().add(ResourceManager.<CssAsset>get(theme + ".css").getUrl());
scene.getStylesheets().add(ResourceManager.<CssAsset>get(layoutSize + ".css").getUrl());
public static void quitPopup() {
Platform.runLater(
() -> {
push(new QuitPopup());
isQuitting = true;
});
}
reload();
}
public static void quit() {
new EventFlow().addPostEvent(new AudioEvents.StopAudioManager()).postEvent();
stage.close();
}
public static int getWidth() {
return width;
}
public static void reloadAll() {
stage.setTitle(AppContext.getString("appTitle"));
public static int getHeight() {
return height;
}
}
for (final Layer layer : stack) {
layer.reload();
}
}
public static void setFullscreen(boolean fullscreen) {
stage.setFullScreen(fullscreen);
width = (int) stage.getWidth();
height = (int) stage.getHeight();
reloadAll();
}
public static void setStyle(String theme, String layoutSize) {
final int stylesCount = scene.getStylesheets().size();
for (int i = 0; i < stylesCount; i++) {
scene.getStylesheets().removeLast();
}
scene.getStylesheets().add(ResourceManager.<CssAsset>get(theme + ".css").getUrl());
scene.getStylesheets().add(ResourceManager.<CssAsset>get(layoutSize + ".css").getUrl());
reloadAll();
}
public static int getWidth() {
return width;
}
public static int getHeight() {
return height;
}
}

View File

@@ -1,6 +1,9 @@
package org.toop.local;
import java.io.File;
import java.util.Locale;
import org.toop.app.App;
import org.toop.framework.audio.VolumeControl;
import org.toop.framework.audio.events.AudioEvents;
import org.toop.framework.eventbus.EventFlow;
import org.toop.framework.resource.ResourceManager;
@@ -8,59 +11,57 @@ import org.toop.framework.resource.ResourceMeta;
import org.toop.framework.resource.resources.SettingsAsset;
import org.toop.framework.settings.Settings;
import java.io.File;
import java.util.Locale;
public class AppSettings {
private static SettingsAsset settingsAsset;
public static void applySettings() {
settingsAsset = getPath();
if (!settingsAsset.isLoaded()) {
settingsAsset.load();
}
private SettingsAsset settingsAsset;
Settings settingsData = settingsAsset.getContent();
public void applySettings() {
this.settingsAsset = getPath();
if (!this.settingsAsset.isLoaded()) {
this.settingsAsset.load();
}
AppContext.setLocale(Locale.of(settingsData.locale));
App.setFullscreen(settingsData.fullScreen);
new EventFlow()
.addPostEvent(new AudioEvents.ChangeVolume(settingsData.volume))
.asyncPostEvent();
new EventFlow()
.addPostEvent(new AudioEvents.ChangeFxVolume(settingsData.fxVolume))
.asyncPostEvent();
new EventFlow()
.addPostEvent(new AudioEvents.ChangeMusicVolume(settingsData.musicVolume))
.asyncPostEvent();
App.setStyle(settingsAsset.getTheme(), settingsAsset.getLayoutSize());
}
Settings settingsData = this.settingsAsset.getContent();
public static SettingsAsset getPath() {
if (settingsAsset == null) {
String os = System.getProperty("os.name").toLowerCase();
String basePath;
AppContext.setLocale(Locale.of(settingsData.locale));
App.setFullscreen(settingsData.fullScreen);
new EventFlow()
.addPostEvent(new AudioEvents.ChangeVolume(settingsData.volume, VolumeControl.MASTERVOLUME))
.asyncPostEvent();
new EventFlow()
.addPostEvent(new AudioEvents.ChangeVolume(settingsData.fxVolume, VolumeControl.FX))
.asyncPostEvent();
new EventFlow()
.addPostEvent(new AudioEvents.ChangeVolume(settingsData.musicVolume, VolumeControl.MUSIC))
.asyncPostEvent();
App.setStyle(settingsAsset.getTheme(), settingsAsset.getLayoutSize());
}
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";
}
public SettingsAsset getPath() {
if (this.settingsAsset == null) {
String os = System.getProperty("os.name").toLowerCase();
String basePath;
File settingsFile =
new File(basePath + File.separator + "ISY1" + File.separator + "settings.json");
// this.settingsAsset = new SettingsAsset(settingsFile);
ResourceManager.addAsset(new ResourceMeta<>("settings.json", new SettingsAsset(settingsFile)));
}
return ResourceManager.get("settings.json");
}
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";
}
public static SettingsAsset getSettings() {
return settingsAsset;
}
}
File settingsFile =
new File(basePath + File.separator + "ISY1" + File.separator + "settings.json");
return new SettingsAsset(settingsFile);
// this.settingsAsset = new SettingsAsset(settingsFile); // TODO
// ResourceManager.addAsset(new ResourceMeta<>("settings.json", new SettingsAsset(settingsFile))); // TODO
}
return this.settingsAsset;
// return ResourceManager.get("settings.json"); // TODO
}
}