mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Added infinite boolean, fixed loading behaviour at startup
This commit is contained in:
@@ -45,6 +45,7 @@ public final class App extends Application {
|
|||||||
public void start(Stage stage) throws Exception {
|
public void start(Stage stage) throws Exception {
|
||||||
// Start loading localization
|
// Start loading localization
|
||||||
ResourceManager.loadAssets(new ResourceLoader("app/src/main/resources/localization"));
|
ResourceManager.loadAssets(new ResourceLoader("app/src/main/resources/localization"));
|
||||||
|
ResourceManager.loadAssets(new ResourceLoader("app/src/main/resources/style"));
|
||||||
|
|
||||||
final StackPane root = WidgetContainer.setup();
|
final StackPane root = WidgetContainer.setup();
|
||||||
final Scene scene = new Scene(root);
|
final Scene scene = new Scene(root);
|
||||||
@@ -67,8 +68,6 @@ public final class App extends Application {
|
|||||||
stage.setScene(scene);
|
stage.setScene(scene);
|
||||||
stage.setResizable(true);
|
stage.setResizable(true);
|
||||||
|
|
||||||
stage.show();
|
|
||||||
|
|
||||||
App.stage = stage;
|
App.stage = stage;
|
||||||
App.scene = scene;
|
App.scene = scene;
|
||||||
|
|
||||||
@@ -77,8 +76,10 @@ public final class App extends Application {
|
|||||||
|
|
||||||
App.isQuitting = false;
|
App.isQuitting = false;
|
||||||
|
|
||||||
|
AppSettings.applySettings();
|
||||||
|
|
||||||
LoadingWidget loading = new LoadingWidget(Primitive.text(
|
LoadingWidget loading = new LoadingWidget(Primitive.text(
|
||||||
"Loading...", false), 0, 0, Integer.MAX_VALUE // Just set a high default
|
"Loading...", false), 0, 0, Integer.MAX_VALUE, false // Just set a high default
|
||||||
);
|
);
|
||||||
|
|
||||||
WidgetContainer.add(Pos.CENTER, loading);
|
WidgetContainer.add(Pos.CENTER, loading);
|
||||||
@@ -88,7 +89,7 @@ public final class App extends Application {
|
|||||||
EventFlow loadingFlow = new EventFlow();
|
EventFlow loadingFlow = new EventFlow();
|
||||||
loadingFlow
|
loadingFlow
|
||||||
.listen(AssetLoaderEvents.LoadingProgressUpdate.class, e -> {
|
.listen(AssetLoaderEvents.LoadingProgressUpdate.class, e -> {
|
||||||
loading.setMaxAmount(e.isLoadingAmount()-1);
|
loading.setMaxAmount(e.isLoadingAmount());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
loading.setAmount(e.hasLoadedAmount());
|
loading.setAmount(e.hasLoadedAmount());
|
||||||
@@ -96,7 +97,7 @@ public final class App extends Application {
|
|||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.hasLoadedAmount() >= e.isLoadingAmount()-1) {
|
if (e.hasLoadedAmount() >= e.isLoadingAmount()) {
|
||||||
loading.triggerSuccess();
|
loading.triggerSuccess();
|
||||||
loadingFlow.unsubscribe("init_loading");
|
loadingFlow.unsubscribe("init_loading");
|
||||||
}
|
}
|
||||||
@@ -104,15 +105,17 @@ public final class App extends Application {
|
|||||||
}, false, "init_loading");
|
}, false, "init_loading");
|
||||||
|
|
||||||
// Start loading assets
|
// Start loading assets
|
||||||
ResourceManager.loadAssets(new ResourceLoader("app/src/main/resources/assets"));
|
new Thread(() -> ResourceManager.loadAssets(new ResourceLoader("app/src/main/resources/assets")))
|
||||||
|
.start();
|
||||||
|
stage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setOnLoadingSuccess(LoadingWidget loading) {
|
private void setOnLoadingSuccess(LoadingWidget loading) {
|
||||||
loading.setOnSuccess(() -> {
|
loading.setOnSuccess(() -> {
|
||||||
initSystems();
|
initSystems();
|
||||||
AppSettings.applySettings();
|
AppSettings.applyMusicVolumeSettings();
|
||||||
new EventFlow().addPostEvent(new AudioEvents.StartBackgroundMusic()).asyncPostEvent();
|
new EventFlow().addPostEvent(new AudioEvents.StartBackgroundMusic()).postEvent();
|
||||||
loading.hide();
|
loading.hide();
|
||||||
WidgetContainer.add(Pos.CENTER, new MainView());
|
WidgetContainer.add(Pos.CENTER, new MainView());
|
||||||
WidgetContainer.add(Pos.BOTTOM_RIGHT, new SongDisplay());
|
WidgetContainer.add(Pos.BOTTOM_RIGHT, new SongDisplay());
|
||||||
stage.setOnCloseRequest(event -> {
|
stage.setOnCloseRequest(event -> {
|
||||||
@@ -145,7 +148,14 @@ public final class App extends Application {
|
|||||||
).initListeners("medium-button-click.wav");
|
).initListeners("medium-button-click.wav");
|
||||||
|
|
||||||
}).start();
|
}).start();
|
||||||
}
|
|
||||||
|
// Threads must be ready, before continue, TODO use latch instead
|
||||||
|
try {
|
||||||
|
Thread.sleep(200);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void startQuit() {
|
public static void startQuit() {
|
||||||
if (isQuitting) {
|
if (isQuitting) {
|
||||||
|
|||||||
@@ -73,10 +73,10 @@ public final class Server {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int reconnectAttempts = 5;
|
final int reconnectAttempts = 10;
|
||||||
|
|
||||||
LoadingWidget loading = new LoadingWidget(
|
LoadingWidget loading = new LoadingWidget(
|
||||||
Primitive.text("connecting"), 0, 0, reconnectAttempts
|
Primitive.text("connecting"), 0, 0, reconnectAttempts, true
|
||||||
);
|
);
|
||||||
|
|
||||||
WidgetContainer.getCurrentView().transitionNext(loading);
|
WidgetContainer.getCurrentView().transitionNext(loading);
|
||||||
|
|||||||
@@ -127,7 +127,6 @@ public final class Primitive {
|
|||||||
|
|
||||||
slider.setOnMouseReleased(event -> {
|
slider.setOnMouseReleased(event -> {
|
||||||
playButtonSound();
|
playButtonSound();
|
||||||
System.out.println("I got called!");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return slider;
|
return slider;
|
||||||
@@ -150,7 +149,6 @@ public final class Primitive {
|
|||||||
choice.valueProperty().addListener((_, _, newValue) -> {
|
choice.valueProperty().addListener((_, _, newValue) -> {
|
||||||
onValueChanged.accept(newValue);
|
onValueChanged.accept(newValue);
|
||||||
playButtonSound();
|
playButtonSound();
|
||||||
System.out.println("hi i got called choice");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,13 +11,13 @@ import java.util.concurrent.Callable;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
public class LoadingWidget extends ViewWidget implements Update { // TODO make of widget type
|
public class LoadingWidget extends ViewWidget implements Update { // TODO make of widget type
|
||||||
|
private final Text loadingText; // TODO Make changeable
|
||||||
private final ProgressBar progressBar;
|
private final ProgressBar progressBar;
|
||||||
private final Text loadingText;
|
private final AtomicBoolean successTriggered = new AtomicBoolean(false);
|
||||||
|
private final AtomicBoolean failureTriggered = new AtomicBoolean(false);
|
||||||
|
|
||||||
private Runnable success = () -> {};
|
private Runnable success = () -> {};
|
||||||
private Runnable failure = () -> {};
|
private Runnable failure = () -> {};
|
||||||
private AtomicBoolean successTriggered = new AtomicBoolean(false);
|
|
||||||
private AtomicBoolean failureTriggered = new AtomicBoolean(false);
|
|
||||||
private int maxAmount;
|
private int maxAmount;
|
||||||
private int minAmount;
|
private int minAmount;
|
||||||
private int amount;
|
private int amount;
|
||||||
@@ -25,6 +25,8 @@ public class LoadingWidget extends ViewWidget implements Update { // TODO make o
|
|||||||
private Callable<Boolean> failureTrigger = () -> (amount < minAmount);
|
private Callable<Boolean> failureTrigger = () -> (amount < minAmount);
|
||||||
private float percentage = 0.0f;
|
private float percentage = 0.0f;
|
||||||
|
|
||||||
|
private boolean isInfiniteBar = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Widget that shows a loading bar.
|
* Widget that shows a loading bar.
|
||||||
@@ -34,13 +36,15 @@ public class LoadingWidget extends ViewWidget implements Update { // TODO make o
|
|||||||
* @param startAmount The starting amount.
|
* @param startAmount The starting amount.
|
||||||
* @param maxAmount The max amount.
|
* @param maxAmount The max amount.
|
||||||
*/
|
*/
|
||||||
public LoadingWidget(Text loadingText, int minAmount, int startAmount, int maxAmount) {
|
public LoadingWidget(Text loadingText, int minAmount, int startAmount, int maxAmount, boolean infiniteBar) {
|
||||||
|
isInfiniteBar = infiniteBar;
|
||||||
|
|
||||||
this.maxAmount = maxAmount;
|
this.maxAmount = maxAmount;
|
||||||
this.minAmount = minAmount;
|
this.minAmount = minAmount;
|
||||||
amount = startAmount;
|
amount = startAmount;
|
||||||
|
|
||||||
progressBar = new ProgressBar();
|
|
||||||
this.loadingText = loadingText;
|
this.loadingText = loadingText;
|
||||||
|
progressBar = new ProgressBar();
|
||||||
|
|
||||||
VBox box = Primitive.vbox(this.loadingText, progressBar);
|
VBox box = Primitive.vbox(this.loadingText, progressBar);
|
||||||
add(Pos.CENTER, box);
|
add(Pos.CENTER, box);
|
||||||
@@ -144,7 +148,6 @@ public class LoadingWidget extends ViewWidget implements Update { // TODO make o
|
|||||||
if (maxAmount != 0) {
|
if (maxAmount != 0) {
|
||||||
percentage = (float) amount / maxAmount;
|
percentage = (float) amount / maxAmount;
|
||||||
}
|
}
|
||||||
progressBar.setProgress(percentage);
|
if (!isInfiniteBar) progressBar.setProgress(percentage);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,18 +27,24 @@ public class AppSettings {
|
|||||||
|
|
||||||
AppContext.setLocale(Locale.of(settingsData.locale));
|
AppContext.setLocale(Locale.of(settingsData.locale));
|
||||||
App.setFullscreen(settingsData.fullScreen);
|
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());
|
App.setStyle(settingsAsset.getTheme(), settingsAsset.getLayoutSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void applyMusicVolumeSettings() {
|
||||||
|
Settings settingsData = settingsAsset.getContent();
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
public static SettingsAsset getPath() {
|
public static SettingsAsset getPath() {
|
||||||
if (settingsAsset == null) {
|
if (settingsAsset == null) {
|
||||||
String os = System.getProperty("os.name").toLowerCase();
|
String os = System.getProperty("os.name").toLowerCase();
|
||||||
|
|||||||
Reference in New Issue
Block a user