summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/subconscious/graphics/Fonts.java39
-rw-r--r--src/subconscious/graphics/Scene.java31
-rw-r--r--src/subconscious/graphics/WorldScene.java6
-rw-r--r--src/subconscious/graphics/widget/ActorInfo.java48
-rw-r--r--src/subconscious/graphics/widget/PerfView.java3
5 files changed, 90 insertions, 37 deletions
diff --git a/src/subconscious/graphics/Fonts.java b/src/subconscious/graphics/Fonts.java
new file mode 100644
index 0000000..58a31c3
--- /dev/null
+++ b/src/subconscious/graphics/Fonts.java
@@ -0,0 +1,39 @@
+package subconscious.graphics;
+
+import java.awt.Font;
+import java.awt.FontFormatException;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+
+public final class Fonts {
+ public static final float DEFAULT_FONT_SIZE = 15.0f;
+ public static final float TITLE_FONT_SIZE = 20.0f;
+
+ public static Font BASE;
+ public static Font DEFAULT;
+ public static Font TITLE;
+
+ private Fonts() {
+
+ }
+
+ static {
+ InputStream fontStream = Scene.class.getResourceAsStream("/subconscious/res/fonts/unscii-16.ttf");
+
+ assert fontStream != null;
+
+ try {
+ BASE = Font.createFont(Font.TRUETYPE_FONT, fontStream);
+ } catch (FontFormatException ex) {
+ ex.printStackTrace();
+ } catch (IOException ioex) {
+ ioex.printStackTrace();
+ }
+
+ DEFAULT = Fonts.BASE.deriveFont(Fonts.DEFAULT_FONT_SIZE);
+ TITLE = Fonts.BASE.deriveFont(Font.BOLD, Fonts.TITLE_FONT_SIZE);
+
+ }
+} \ No newline at end of file
diff --git a/src/subconscious/graphics/Scene.java b/src/subconscious/graphics/Scene.java
index 3849c24..1956c27 100644
--- a/src/subconscious/graphics/Scene.java
+++ b/src/subconscious/graphics/Scene.java
@@ -5,6 +5,7 @@ import subconscious.Game;
import subconscious.graphics.widget.Widget;
import subconscious.graphics.widget.Clickable;
import subconscious.graphics.widget.Dynamic;
+
import subconscious.graphics.widget.PerfView;
import java.util.ArrayList;
@@ -65,7 +66,7 @@ public abstract class Scene extends Panel
protected ArrayList<Widget> widgets = new ArrayList<>();
protected ArrayList<Widget> dynamicWidgetsCache = new ArrayList<>();
- // protected ArrayList<Widget> clickableWidgetsCache = new ArrayList<>();
+ protected ArrayList<Widget> clickableWidgetsCache = new ArrayList<>();
// Game is never cached in the local thread
protected volatile Game game;
@@ -82,9 +83,6 @@ public abstract class Scene extends Panel
protected Canvas canvas = new Canvas();
protected BufferStrategy buffer;
- protected Font font;
- protected final float defaultFontSize = 10.0f;
-
// TODO: make accessible from user settings
protected int guiSize = 2;
@@ -97,17 +95,6 @@ public abstract class Scene extends Panel
this.game = game;
// set default scene font unscii
- InputStream fontStream = Scene.class.getResourceAsStream("/subconscious/res/fonts/unscii-16.ttf");
-
- assert fontStream != null;
-
- try {
- this.font = Font.createFont(Font.TRUETYPE_FONT, fontStream);
- } catch (FontFormatException ex) {
- ex.printStackTrace();
- } catch (IOException ioex) {
- ioex.printStackTrace();
- }
// watch for resize
this.addComponentListener(this);
@@ -126,7 +113,7 @@ public abstract class Scene extends Panel
this.build();
// TODO: this will be controlled in the settings
- this.addWidget(new PerfView("default-perfview", 0, 0));
+ // this.addWidget(new PerfView("default-perfview", 0, 0));
}
public Scene(Game game) {
@@ -166,6 +153,10 @@ public abstract class Scene extends Panel
if (widget instanceof Dynamic) {
this.dynamicWidgetsCache.add(widget);
}
+
+ if (widget instanceof Clickable) {
+ this.clickableWidgetsCache.add(widget);
+ }
}
/* request scenes */
@@ -232,7 +223,7 @@ public abstract class Scene extends Panel
do {
Graphics2D g = (Graphics2D) this.buffer.getDrawGraphics();
g.addRenderingHints(this.RENDERING_HINTS);
- g.setFont(this.font.deriveFont(this.defaultFontSize));
+ g.setFont(Fonts.DEFAULT);
this.render(g);
this.renderWidgets(g);
g.dispose();
@@ -328,10 +319,8 @@ public abstract class Scene extends Panel
@Override
public void mouseClicked(MouseEvent e) {
// could be cached
- for (Widget w : this.widgets) {
- if (w instanceof Clickable) {
- ((Clickable) w).mouseClick(e.getPoint());
- }
+ for (Widget w : this.clickableWidgetsCache) {
+ ((Clickable) w).mouseClick(e.getPoint());
}
}
diff --git a/src/subconscious/graphics/WorldScene.java b/src/subconscious/graphics/WorldScene.java
index 56d15fc..4a375fa 100644
--- a/src/subconscious/graphics/WorldScene.java
+++ b/src/subconscious/graphics/WorldScene.java
@@ -12,17 +12,13 @@ public class WorldScene extends MapScene {
public WorldScene(Game game, String label) {
super(game, label);
-
- this.renderTileBorder = false;
}
@Override
public void build() {
this.addWidget(
new ActorInfo(
- "actorinfo", 0, 0,
- this.canvasSize.width/5,
- this.canvasSize.height/5
+ "actorinfo", 0, 0
)
);
}
diff --git a/src/subconscious/graphics/widget/ActorInfo.java b/src/subconscious/graphics/widget/ActorInfo.java
index eb265de..a43984b 100644
--- a/src/subconscious/graphics/widget/ActorInfo.java
+++ b/src/subconscious/graphics/widget/ActorInfo.java
@@ -1,40 +1,66 @@
package subconscious.graphics.widget;
import subconscious.Actor;
+
import subconscious.graphics.Palette;
+import subconscious.graphics.Fonts;
import java.awt.Graphics2D;
+import java.awt.Dimension;
public class ActorInfo extends Widget {
- public final int INNER_BORDER = 10;
+ public static final int BORDER = 10;
+ public static final int TEXT_LINES_SPACING = 5;
+ public static final int WIDTH = 250;
+ public static final int HEIGHT = 300;
protected Actor observingActor = null;
- public ActorInfo(String uniqueName, int x, int y, int width, int height) {
- super(uniqueName, x, y, width, height);
+ public ActorInfo(String uniqueName, int x, int y) {
+ super(uniqueName, x, y, ActorInfo.WIDTH, ActorInfo.HEIGHT);
}
@Override
public void render(Graphics2D g) {
- // background
+ // backgroundutf
g.setColor(Palette.WHITE_T);
- g.fillRect(0, 0, this.width, this.height);
+ g.fillRect(0, 0, ActorInfo.WIDTH, ActorInfo.HEIGHT);
+
// border
+ // g.setColor(Palette.BLACK);
+ // g.drawRect(0, 0, this.width, this.height);
+
g.setColor(Palette.BLACK);
- g.drawRect(0, 0, this.width, this.height);
- if (observingActor == null)
+ // draw title
+ g.setFont(Fonts.TITLE);
+ final int titleY = BORDER + g.getFontMetrics().getHeight();
+ g.drawString("Character", BORDER, titleY);
+
+ g.setFont(Fonts.DEFAULT);
+ final int postTitleY = BORDER * 2 + titleY;
+
+ if (observingActor == null) {
+ drawLineString(g, "No character selected", BORDER, postTitleY, 0);
return;
+ }
- g.drawString("HP",
- INNER_BORDER,
- INNER_BORDER
- );
+ // draw HP
+ drawLineString(g, "HP", BORDER, postTitleY, 0);
+
+ // TODO: show actor properties
}
public void setActor(Actor actor) {
this.observingActor = actor;
}
+
+
+ private void drawLineString(Graphics2D g, String text, int x, int y, int line) {
+ g.drawString(text, x,
+ y + (TEXT_LINES_SPACING + g.getFontMetrics().getHeight()) * line
+ );
+ }
} \ No newline at end of file
diff --git a/src/subconscious/graphics/widget/PerfView.java b/src/subconscious/graphics/widget/PerfView.java
index c7c9356..4483146 100644
--- a/src/subconscious/graphics/widget/PerfView.java
+++ b/src/subconscious/graphics/widget/PerfView.java
@@ -1,5 +1,6 @@
package subconscious.graphics.widget;
+import subconscious.graphics.Fonts;
import subconscious.graphics.Palette;
import java.awt.Graphics2D;
@@ -20,6 +21,8 @@ public class PerfView extends Widget implements Dynamic {
@Override
public void render(Graphics2D g) {
+ g.setFont(Fonts.DEFAULT);
+
String text = "DeltaTime (us): "
+ Long.toString(this.lastDeltaNanoTime/1000);