From bac7678e923e197a64e534cd4f93fae7822806ed Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Wed, 21 Nov 2018 13:22:57 +0100 Subject: Disable Pause feature, add scene UNIQUE_NAME generator There is a bug with the management of the scenes that has to be solved before implementing the pause (and consequently PauseScene) --- src/subconscious/graphics/GameWindow.java | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'src/subconscious/graphics/GameWindow.java') diff --git a/src/subconscious/graphics/GameWindow.java b/src/subconscious/graphics/GameWindow.java index 8f24dac..65af798 100644 --- a/src/subconscious/graphics/GameWindow.java +++ b/src/subconscious/graphics/GameWindow.java @@ -63,14 +63,19 @@ public class GameWindow extends JFrame implements WindowListener { // ovserver of this.game private void loop() { // load the first scene - this.loadScene(new MenuScene(this.game, "mainmenu")); + this.loadScene(new MenuScene(this.game)); while (this.game.isRunning()) { // check if the scene has requested a new scene if (this.scene.isRequestingScene()) { this.loadScene(this.scene.getRequestedScene()); } - + + // check if the scene wants to die + if (this.scene.isRequestingPrevScene()) { + this.unloadScene(); + } + // check for game state change if (this.game.stateChanged()) { // Game.State newState = this.game.waitStateChange(); @@ -81,19 +86,13 @@ public class GameWindow extends JFrame implements WindowListener { throw new IllegalStateException(); } - // if unpaused unload PauseScene - if (lastState == Game.State.PAUSE) { - this.unloadScene(); - } - // MAIN_MENU is always the first scene if (newState == Game.State.MAIN_MENU) { this.unloadAllScenes(); } - // if paused load new PauseScene - else if (newState == Game.State.PAUSE) { - this.loadScene(new PauseScene(this.game, "pause")); - } + // else if (newState == Game.State.PAUSE) { + // this.scene.requestScene(new PauseScene(this.game, "from GameWindow")); + // } else if (newState == Game.State.CLOSING) { this.quit(); } @@ -109,6 +108,7 @@ public class GameWindow extends JFrame implements WindowListener { // if a scene is loaded push it onto the loadedScenes stack if (this.scene != null){ this.scene.pauseThread(); + this.scene.setVisible(false); this.loadedScenes.push(new SimpleEntry(scene, sceneThread)); } @@ -122,7 +122,7 @@ public class GameWindow extends JFrame implements WindowListener { // start scene this.sceneThread = new Thread(this.scene); // for debugging - this.sceneThread.setName("Scene [" + scene.UNIQUE_NAME + "]"); + this.sceneThread.setName(this.scene.UNIQUE_NAME); this.sceneThread.start(); this.scene.updateCanvasSize(this.getSize()); } @@ -149,7 +149,8 @@ public class GameWindow extends JFrame implements WindowListener { } // remove card from UI - this.root.remove(scene); + this.root.getLayout().removeLayoutComponent(this.scene); + this.root.remove(this.scene); if (this.loadedScenes.empty()) { throw new IllegalStateException(); @@ -160,6 +161,7 @@ public class GameWindow extends JFrame implements WindowListener { this.scene = sceneEntry.getKey(); this.sceneThread = sceneEntry.getValue(); + this.scene.setVisible(true); ((CardLayout) this.root.getLayout()).show(this.root, this.scene.UNIQUE_NAME); this.scene.resumeThread(); } @@ -181,8 +183,7 @@ public class GameWindow extends JFrame implements WindowListener { @Override public void windowDeactivated(WindowEvent e) { - if (this.game.getState() != Game.State.MAIN_MENU) - this.game.pause(); + // this.game.pause(); } @Override public void windowDeiconified(WindowEvent e) {} -- cgit v1.2.1