Best fix for white screen at start

This commit is contained in:
lieght
2025-12-03 21:50:32 +01:00
parent 8d77f51355
commit f866eab8ba
3 changed files with 34 additions and 13 deletions

View File

@@ -1,5 +1,7 @@
package org.toop.app; package org.toop.app;
import javafx.application.Platform;
import javafx.scene.paint.Color;
import org.toop.Main; import org.toop.Main;
import org.toop.app.widget.Primitive; import org.toop.app.widget.Primitive;
import org.toop.app.widget.Widget; import org.toop.app.widget.Widget;
@@ -50,11 +52,13 @@ public final class App extends Application {
final StackPane root = WidgetContainer.setup(); final StackPane root = WidgetContainer.setup();
final Scene scene = new Scene(root); final Scene scene = new Scene(root);
stage.setOpacity(0.0);
stage.setTitle(AppContext.getString("app-title")); stage.setTitle(AppContext.getString("app-title"));
stage.titleProperty().bind(AppContext.bindToKey("app-title")); stage.titleProperty().bind(AppContext.bindToKey("app-title"));
stage.setWidth(1080); stage.setWidth(0);
stage.setHeight(720); stage.setHeight(0);
scene.getRoot(); scene.getRoot();
@@ -82,23 +86,37 @@ public final class App extends Application {
"Loading...", false), 0, 0, Integer.MAX_VALUE, false // Just set a high default "Loading...", false), 0, 0, Integer.MAX_VALUE, false // Just set a high default
); );
WidgetContainer.add(Pos.CENTER, loading); WidgetContainer.setCurrentView(loading);
setOnLoadingSuccess(loading); setOnLoadingSuccess(loading);
EventFlow loadingFlow = new EventFlow(); EventFlow loadingFlow = new EventFlow();
final boolean[] hasRun = {false};
loadingFlow loadingFlow
.listen(AssetLoaderEvents.LoadingProgressUpdate.class, e -> { .listen(AssetLoaderEvents.LoadingProgressUpdate.class, e -> {
loading.setMaxAmount(e.isLoadingAmount()); if (!hasRun[0]) {
hasRun[0] = true;
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
throw new RuntimeException(ex);
}
Platform.runLater(() -> stage.setOpacity(1.0));
}
Platform.runLater(() -> loading.setMaxAmount(e.isLoadingAmount()));
Platform.runLater(() -> {
try { try {
loading.setAmount(e.hasLoadedAmount()); loading.setAmount(e.hasLoadedAmount());
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
});
if (e.hasLoadedAmount() >= e.isLoadingAmount()) { if (e.hasLoadedAmount() >= e.isLoadingAmount()) {
loading.triggerSuccess(); Platform.runLater(loading::triggerSuccess);
loadingFlow.unsubscribe("init_loading"); loadingFlow.unsubscribe("init_loading");
} }
@@ -107,7 +125,9 @@ public final class App extends Application {
// Start loading assets // Start loading assets
new Thread(() -> ResourceManager.loadAssets(new ResourceLoader("app/src/main/resources/assets"))) new Thread(() -> ResourceManager.loadAssets(new ResourceLoader("app/src/main/resources/assets")))
.start(); .start();
stage.show(); stage.show();
} }
private void setOnLoadingSuccess(LoadingWidget loading) { private void setOnLoadingSuccess(LoadingWidget loading) {

View File

@@ -100,6 +100,7 @@ public final class Server {
loading.setOnFailure(() -> { loading.setOnFailure(() -> {
WidgetContainer.getCurrentView().transitionPrevious(); WidgetContainer.getCurrentView().transitionPrevious();
a.unsubscribe("connecting"); a.unsubscribe("connecting");
a.unsubscribe("startclient");
WidgetContainer.add( WidgetContainer.add(
Pos.CENTER, Pos.CENTER,
new ErrorPopup(AppContext.getString("connecting-failed") + " " + ip + ":" + port) new ErrorPopup(AppContext.getString("connecting-failed") + " " + ip + ":" + port)
@@ -151,8 +152,6 @@ public final class Server {
.listen(NetworkEvents.GameResultResponse.class, this::handleGameResult, false) .listen(NetworkEvents.GameResultResponse.class, this::handleGameResult, false)
.listen(NetworkEvents.GameMoveResponse.class, this::handleReceivedMove, false) .listen(NetworkEvents.GameMoveResponse.class, this::handleReceivedMove, false)
.listen(NetworkEvents.YourTurnResponse.class, this::handleYourTurn, false); .listen(NetworkEvents.YourTurnResponse.class, this::handleYourTurn, false);
startPopulateScheduler();
populateGameList();
} }
private void sendChallenge(String opponent) { private void sendChallenge(String opponent) {

View File

@@ -148,6 +148,8 @@ public class LoadingWidget extends ViewWidget implements Update { // TODO make o
if (maxAmount != 0) { if (maxAmount != 0) {
percentage = (float) amount / maxAmount; percentage = (float) amount / maxAmount;
} }
if (!isInfiniteBar) progressBar.setProgress(percentage); if (!isInfiniteBar) {
progressBar.setProgress(percentage);
}
} }
} }