From d0c8c685ab0a1ed7391550daaefc59003919939c Mon Sep 17 00:00:00 2001 From: kske Date: Wed, 2 Sep 2020 10:07:02 +0200 Subject: [PATCH] Fix LoginScene popping --- .../main/java/envoy/client/ui/SceneContext.java | 14 ++++++++++++-- client/src/main/java/envoy/client/ui/Startup.java | 7 +++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/client/src/main/java/envoy/client/ui/SceneContext.java b/client/src/main/java/envoy/client/ui/SceneContext.java index 39096d1..c25d525 100644 --- a/client/src/main/java/envoy/client/ui/SceneContext.java +++ b/client/src/main/java/envoy/client/ui/SceneContext.java @@ -124,8 +124,12 @@ public final class SceneContext { * @since Envoy Client v0.1-beta */ public void pop() { - if (!sceneStack.isEmpty()) sceneStack.pop(); - if (!controllerStack.isEmpty()) controllerStack.pop(); + + // Pop scene and controller + sceneStack.pop(); + controllerStack.pop(); + + // Apply new scene if present if (!sceneStack.isEmpty()) { final var newScene = sceneStack.peek(); stage.setScene(newScene); @@ -160,4 +164,10 @@ public final class SceneContext { * @since Envoy Client v0.1-beta */ public Stage getStage() { return stage; } + + /** + * @return whether the scene stack is empty + * @since Envoy Client v0.2-beta + */ + public boolean isEmpty() { return sceneStack.isEmpty(); } } diff --git a/client/src/main/java/envoy/client/ui/Startup.java b/client/src/main/java/envoy/client/ui/Startup.java index 370215c..e42d8e9 100644 --- a/client/src/main/java/envoy/client/ui/Startup.java +++ b/client/src/main/java/envoy/client/ui/Startup.java @@ -172,7 +172,6 @@ public final class Startup extends Application { try { localDB.initializeUserStorage(); localDB.loadUserData(); - context.initWriteProxy(); } catch (final FileNotFoundException e) { // The local database file has not yet been created, probably first login } catch (final Exception e) { @@ -180,6 +179,7 @@ public final class Startup extends Application { logger.log(Level.WARNING, "Could not load local database: ", e); } + context.initWriteProxy(); localDB.synchronize(); if (client.isOnline()) context.getWriteProxy().flushCache(); @@ -193,8 +193,11 @@ public final class Startup extends Application { .forEach(u -> u.setStatus(UserStatus.OFFLINE)); final var stage = context.getStage(); + + // Pop LoginScene if present + if (!context.getSceneContext().isEmpty()) context.getSceneContext().pop(); + // Load ChatScene - context.getSceneContext().pop(); stage.setMinHeight(400); stage.setMinWidth(843); context.getSceneContext().load(SceneContext.SceneInfo.CHAT_SCENE);