summaryrefslogtreecommitdiffstats
path: root/src/subconscious/graphics/GameWindow.java
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2018-11-21 13:22:57 +0100
committerNao Pross <naopross@thearcway.org>2018-11-21 13:22:57 +0100
commitbac7678e923e197a64e534cd4f93fae7822806ed (patch)
tree42fdc9e81c6d783f95cf4604c822237d01430e22 /src/subconscious/graphics/GameWindow.java
parentFix InvalidStateException at scene loading, add Scene.requestScene() (diff)
downloadSubconscious-java-bac7678e923e197a64e534cd4f93fae7822806ed.tar.gz
Subconscious-java-bac7678e923e197a64e534cd4f93fae7822806ed.zip
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)
Diffstat (limited to 'src/subconscious/graphics/GameWindow.java')
-rw-r--r--src/subconscious/graphics/GameWindow.java31
1 files changed, 16 insertions, 15 deletions
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, Thread>(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) {}