summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/subconscious/graphics/BattleScene.java1
-rw-r--r--src/subconscious/graphics/GameWindow.java4
-rw-r--r--src/subconscious/graphics/MainMenuScene.java15
-rw-r--r--src/subconscious/graphics/MapScene.java4
-rw-r--r--src/subconscious/graphics/Scene.java19
-rw-r--r--src/subconscious/graphics/WorldScene.java37
-rw-r--r--src/subconscious/graphics/widget/ActorInfo.java40
7 files changed, 101 insertions, 19 deletions
diff --git a/src/subconscious/graphics/BattleScene.java b/src/subconscious/graphics/BattleScene.java
index 6cc38c9..dbbae1e 100644
--- a/src/subconscious/graphics/BattleScene.java
+++ b/src/subconscious/graphics/BattleScene.java
@@ -90,7 +90,6 @@ public class BattleScene extends MapScene implements ActionListener {
bottomPanel.add(passButton);
this.add(bottomPanel, BorderLayout.PAGE_END);
- this.add(this.canvas, BorderLayout.CENTER);
}
@Override
diff --git a/src/subconscious/graphics/GameWindow.java b/src/subconscious/graphics/GameWindow.java
index b26d6a4..c3d5474 100644
--- a/src/subconscious/graphics/GameWindow.java
+++ b/src/subconscious/graphics/GameWindow.java
@@ -25,10 +25,10 @@ public class GameWindow extends Frame implements WindowListener {
private Panel root;
// reference to the current scene which is NOT on the stack
- private Scene scene = null;
+ private volatile Scene scene = null;
private Thread sceneThread = null;
// stack of loaded scenes in the background that are paused
- private Stack<SimpleEntry<Scene, Thread>> loadedScenes = new Stack<>();
+ private volatile Stack<SimpleEntry<Scene, Thread>> loadedScenes = new Stack<>();
private volatile Game game;
diff --git a/src/subconscious/graphics/MainMenuScene.java b/src/subconscious/graphics/MainMenuScene.java
index 9526b17..2996b32 100644
--- a/src/subconscious/graphics/MainMenuScene.java
+++ b/src/subconscious/graphics/MainMenuScene.java
@@ -28,8 +28,8 @@ public class MainMenuScene extends Scene implements ActionListener {
// build Menu card
this.setLayout(new GridLayout(3, 1));
- Button editor = new Button("Editor");
- editor.setActionCommand("btn-editor");
+ Button editor = new Button("World");
+ editor.setActionCommand("btn-world");
editor.addActionListener(this);
Button battle = new Button("Battle");
@@ -60,13 +60,14 @@ public class MainMenuScene extends Scene implements ActionListener {
return;
}
- if (e.getActionCommand().equals("btn-editor")) {
- // TODO: fix editor
- // this.loadScene(new MapEditorScene());
+ if (e.getActionCommand().equals("btn-world")) {
+ // TODO: change
+ this.game.setState(Game.State.WORLD);
+ this.requestScene(new WorldScene(this.game, "demo-world"));
} else if (e.getActionCommand().equals("btn-battle")) {
- this.game.start();
// TODO: change
- this.requestScene(new BattleScene(this.game, "demo"));
+ this.game.setState(Game.State.BATTLE);
+ this.requestScene(new BattleScene(this.game, "demo-battle"));
}
}
diff --git a/src/subconscious/graphics/MapScene.java b/src/subconscious/graphics/MapScene.java
index ecac56d..43a982d 100644
--- a/src/subconscious/graphics/MapScene.java
+++ b/src/subconscious/graphics/MapScene.java
@@ -10,6 +10,7 @@ import java.awt.Point;
import java.awt.Graphics2D;
import java.awt.BasicStroke;
import java.awt.Dimension;
+import java.awt.GridLayout;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
@@ -55,6 +56,9 @@ public abstract class MapScene extends Scene {
this.game = g;
this.map = this.game.getMap();
+ this.setLayout(new GridLayout(1,1));
+ this.add(this.canvas);
+
this.updateCanvasSize(this.canvasSize);
}
diff --git a/src/subconscious/graphics/Scene.java b/src/subconscious/graphics/Scene.java
index 50ef323..74330ff 100644
--- a/src/subconscious/graphics/Scene.java
+++ b/src/subconscious/graphics/Scene.java
@@ -105,15 +105,7 @@ public abstract class Scene extends Panel
this.build();
// TODO: this will be controlled in the settings
- this.widgets.add(new PerfView("default-perfview", 0, 0));
-
- // cache dynamic widgets
- // TODO: add Scene.addWidget(Widget w) to update these caches
- for (Widget w : this.widgets) {
- if (w instanceof Dynamic) {
- this.dynamicWidgetsCache.add(w);
- }
- }
+ this.addWidget(new PerfView("default-perfview", 0, 0));
}
public Scene(Game game) {
@@ -146,6 +138,15 @@ public abstract class Scene extends Panel
}
}
+ /* widgets management */
+ protected void addWidget(Widget widget) {
+ this.widgets.add(widget);
+
+ if (widget instanceof Dynamic) {
+ this.dynamicWidgetsCache.add(widget);
+ }
+ }
+
/* request scenes */
protected synchronized void requestPrevScene() {
this.requestedPrevScene = true;
diff --git a/src/subconscious/graphics/WorldScene.java b/src/subconscious/graphics/WorldScene.java
new file mode 100644
index 0000000..86e398f
--- /dev/null
+++ b/src/subconscious/graphics/WorldScene.java
@@ -0,0 +1,37 @@
+package subconscious.graphics;
+
+import subconscious.Game;
+
+import subconscious.graphics.widget.ActorInfo;
+
+import java.awt.Graphics2D;
+
+
+@SuppressWarnings("serial")
+public class WorldScene extends MapScene {
+
+ public WorldScene(Game game, String label) {
+ super(game, label);
+ }
+
+ @Override
+ public void build() {
+ this.addWidget(
+ new ActorInfo(
+ "actorinfo", 0, 0,
+ this.canvasSize.width/5,
+ this.canvasSize.height/5
+ )
+ );
+ }
+
+ @Override
+ public void render(Graphics2D g) {
+ super.render(g);
+ }
+
+ @Override
+ public void update(long deltaNanoTime) {
+
+ }
+} \ No newline at end of file
diff --git a/src/subconscious/graphics/widget/ActorInfo.java b/src/subconscious/graphics/widget/ActorInfo.java
new file mode 100644
index 0000000..eb265de
--- /dev/null
+++ b/src/subconscious/graphics/widget/ActorInfo.java
@@ -0,0 +1,40 @@
+package subconscious.graphics.widget;
+
+import subconscious.Actor;
+import subconscious.graphics.Palette;
+
+import java.awt.Graphics2D;
+
+
+public class ActorInfo extends Widget {
+
+ public final int INNER_BORDER = 10;
+
+ protected Actor observingActor = null;
+
+ public ActorInfo(String uniqueName, int x, int y, int width, int height) {
+ super(uniqueName, x, y, width, height);
+ }
+
+ @Override
+ public void render(Graphics2D g) {
+ // background
+ g.setColor(Palette.WHITE_T);
+ g.fillRect(0, 0, this.width, this.height);
+ // border
+ g.setColor(Palette.BLACK);
+ g.drawRect(0, 0, this.width, this.height);
+
+ if (observingActor == null)
+ return;
+
+ g.drawString("HP",
+ INNER_BORDER,
+ INNER_BORDER
+ );
+ }
+
+ public void setActor(Actor actor) {
+ this.observingActor = actor;
+ }
+} \ No newline at end of file