diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/subconscious/Map.java | 6 | ||||
-rw-r--r-- | src/subconscious/graphics/Scene.java | 29 | ||||
-rw-r--r-- | src/subconscious/graphics/WorldScene.java | 10 | ||||
-rw-r--r-- | src/subconscious/graphics/widget/ActorInfo.java | 11 | ||||
-rw-r--r-- | src/subconscious/graphics/widget/TerrainInfo.java | 55 | ||||
-rw-r--r-- | src/subconscious/graphics/widget/Widget.java | 11 |
6 files changed, 98 insertions, 24 deletions
diff --git a/src/subconscious/Map.java b/src/subconscious/Map.java index 21b9ae5..4fd4d00 100644 --- a/src/subconscious/Map.java +++ b/src/subconscious/Map.java @@ -1,6 +1,8 @@ package subconscious; +import java.awt.Point; import java.awt.Dimension; + import java.util.ArrayList; public class Map { @@ -127,6 +129,10 @@ public class Map { return this.grid[x * this.size.width + y]; } + public Tile getTile(Point pos) { + return getTile(pos.x, pos.y); + } + public int getSize() { return this.size.width; } diff --git a/src/subconscious/graphics/Scene.java b/src/subconscious/graphics/Scene.java index 711a60f..3747318 100644 --- a/src/subconscious/graphics/Scene.java +++ b/src/subconscious/graphics/Scene.java @@ -74,10 +74,10 @@ public abstract class Scene extends Panel RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED ); - protected EnumMap<Widget.Anchor, Point> widgetAnchors = new EnumMap<Widget.Anchor, Point>(Widget.Anchor.class); - protected ArrayList<Widget> widgets = new ArrayList<>(); - protected ArrayList<Widget> dynamicWidgetsCache = new ArrayList<>(); - protected ArrayList<Widget> clickableWidgetsCache = new ArrayList<>(); + protected final EnumMap<Widget.Anchor, Point> widgetAnchors = new EnumMap<Widget.Anchor, Point>(Widget.Anchor.class); + private ArrayList<Widget> widgets = new ArrayList<>(); + private ArrayList<Widget> dynamicWidgetsCache = new ArrayList<>(); + private ArrayList<Widget> clickableWidgetsCache = new ArrayList<>(); // Game is never cached in the local thread protected volatile Game game; @@ -160,7 +160,7 @@ public abstract class Scene extends Panel protected void renderWidgets(Graphics2D g) { for (Widget w : this.widgets) { - Point absPos = this.widgetAnchors.get(w.getAnchor()); + Point absPos = new Point(this.widgetAnchors.get(w.getAnchor())); absPos.translate(w.getX(), w.getY()); Graphics2D widgetGraphics = (Graphics2D) g.create( @@ -185,6 +185,11 @@ public abstract class Scene extends Panel } } + protected void removeWidget(Widget widget) { + // TODO + throw new UnsupportedOperationException("TODO"); + } + /* request scenes */ protected synchronized void requestPrevScene() { this.requestedPrevScene = true; @@ -333,14 +338,14 @@ public abstract class Scene extends Panel public synchronized void updateCanvasSize(Dimension newSize) { this.canvasSize = newSize; - this.widgetAnchors.get(Widget.Anchor.SO).move(0, this.canvasSize.height); - this.widgetAnchors.get(Widget.Anchor.S ).move(this.canvasSize.width / 2, this.canvasSize.height); - this.widgetAnchors.get(Widget.Anchor.SE).move(this.canvasSize.width, this.canvasSize.height); - this.widgetAnchors.get(Widget.Anchor.E ).move(this.canvasSize.width, this.canvasSize.width); - this.widgetAnchors.get(Widget.Anchor.NE).move(this.canvasSize.width, 0); - this.widgetAnchors.get(Widget.Anchor.N ).move(this.canvasSize.width / 2, 0); + this.widgetAnchors.get(Widget.Anchor.SO).move(0, newSize.height); + this.widgetAnchors.get(Widget.Anchor.S ).move(newSize.width / 2, newSize.height); + this.widgetAnchors.get(Widget.Anchor.SE).move(newSize.width, newSize.height); + this.widgetAnchors.get(Widget.Anchor.E ).move(newSize.width, newSize.width / 2); + this.widgetAnchors.get(Widget.Anchor.NE).move(newSize.width, 0); + this.widgetAnchors.get(Widget.Anchor.N ).move(newSize.width / 2, 0); this.widgetAnchors.get(Widget.Anchor.NO).move(0, 0); - this.widgetAnchors.get(Widget.Anchor.O ).move(0, this.canvasSize.height / 2); + this.widgetAnchors.get(Widget.Anchor.O ).move(0, newSize.height / 2); } /* key listener */ diff --git a/src/subconscious/graphics/WorldScene.java b/src/subconscious/graphics/WorldScene.java index f23aa06..995efd5 100644 --- a/src/subconscious/graphics/WorldScene.java +++ b/src/subconscious/graphics/WorldScene.java @@ -4,6 +4,7 @@ import subconscious.Game; import subconscious.Actor; import subconscious.graphics.widget.ActorInfo; +import subconscious.graphics.widget.TerrainInfo; import java.awt.Graphics2D; import java.awt.Point; @@ -14,7 +15,7 @@ import java.awt.event.MouseEvent; public class WorldScene extends MapScene { protected ActorInfo actorInfoWidget; - + protected TerrainInfo terrainInfoWidget; public WorldScene(Game game, String label) { super(game, label); @@ -24,6 +25,9 @@ public class WorldScene extends MapScene { public void build() { this.actorInfoWidget = new ActorInfo("actorinfo"); this.addWidget(this.actorInfoWidget); + + this.terrainInfoWidget = new TerrainInfo("terraininfo"); + this.addWidget(this.terrainInfoWidget); } @Override @@ -42,14 +46,15 @@ public class WorldScene extends MapScene { Point tileUnderCursor = this.tileAtCoordinates(e.getPoint()); if (tileUnderCursor == null) { + this.terrainInfoWidget.unsetTile(); return; } // System.out.println(this.map.getTile(tileUnderCursor.x, tileUnderCursor.y).type); // update ActorInfo widget - this.actorInfoWidget.unsetActor(); for (Actor actor : this.map.getActors()) { + this.actorInfoWidget.unsetActor(); if (actor.getPoint().equals(tileUnderCursor)) { this.actorInfoWidget.setActor(actor); break; @@ -57,5 +62,6 @@ public class WorldScene extends MapScene { } // update tileType widget + this.terrainInfoWidget.setTile(this.map.getTile(tileUnderCursor)); } }
\ No newline at end of file diff --git a/src/subconscious/graphics/widget/ActorInfo.java b/src/subconscious/graphics/widget/ActorInfo.java index 10bba9f..d381cd2 100644 --- a/src/subconscious/graphics/widget/ActorInfo.java +++ b/src/subconscious/graphics/widget/ActorInfo.java @@ -11,8 +11,6 @@ import java.awt.Dimension; public class ActorInfo extends Widget { - 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 = 100; @@ -24,7 +22,7 @@ public class ActorInfo extends Widget { @Override public void render(Graphics2D g) { - // backgroundutf + // background g.setColor(Palette.WHITE_T); g.fillRect(0, 0, ActorInfo.WIDTH, ActorInfo.HEIGHT); @@ -61,11 +59,4 @@ public class ActorInfo extends Widget { public synchronized void unsetActor() { this.observingActor = null; } - - - 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/TerrainInfo.java b/src/subconscious/graphics/widget/TerrainInfo.java new file mode 100644 index 0000000..9e1ab90 --- /dev/null +++ b/src/subconscious/graphics/widget/TerrainInfo.java @@ -0,0 +1,55 @@ +package subconscious.graphics.widget; + +import subconscious.Tile; + +import subconscious.graphics.Palette; +import subconscious.graphics.Fonts; + +import java.awt.Graphics2D; + + +public class TerrainInfo extends Widget { + + public static final int WIDTH = 250; + public static final int HEIGHT = 100; + + protected Tile observingTile = null; + + public TerrainInfo(String uniqueName) { + super(uniqueName, -WIDTH, -HEIGHT, WIDTH, HEIGHT); + this.anchor = Widget.Anchor.SE; + } + + @Override + public void render(Graphics2D g) { + // background + g.setColor(Palette.WHITE_T); + g.fillRect(0, 0, TerrainInfo.WIDTH, TerrainInfo.HEIGHT); + + g.setColor(Palette.BLACK); + + g.setFont(Fonts.TITLE); + final int titleY = BORDER + g.getFontMetrics().getHeight(); + g.drawString("Tile", BORDER, titleY); + + g.setFont(Fonts.DEFAULT); + final int postTitleY = BORDER * 2 + titleY; + + if (this.observingTile == null) { + drawLineString(g, "No tile selected", BORDER, postTitleY, 0); + return; + } + + drawLineString(g, "Type: " + this.observingTile.getType().name(), BORDER, postTitleY, 0); + // TODO: fix argument on .getCost(null) + drawLineString(g, "Cost: " + Double.toString(this.observingTile.getCost(null)), BORDER, postTitleY, 1); + } + + public void setTile(Tile tile) { + this.observingTile = tile; + } + + public void unsetTile() { + this.observingTile = null; + } +}
\ No newline at end of file diff --git a/src/subconscious/graphics/widget/Widget.java b/src/subconscious/graphics/widget/Widget.java index 0da1b40..4b97769 100644 --- a/src/subconscious/graphics/widget/Widget.java +++ b/src/subconscious/graphics/widget/Widget.java @@ -6,6 +6,10 @@ import java.awt.Point; public abstract class Widget { + + public static final int BORDER = 10; + public static final int TEXT_LINES_SPACING = 5; + public enum Anchor { SO, S, SE, E, NE, N, NO, O } @@ -29,6 +33,13 @@ public abstract class Widget { // at the widget's coordinates with the widget's size public abstract void render(Graphics2D g); + /* helper methods */ + protected void drawLineString(Graphics2D g, String text, int x, int y, int line) { + g.drawString(text, x, + y + (TEXT_LINES_SPACING + g.getFontMetrics().getHeight()) * line + ); + } + /* accessors */ public Rectangle getRect() { return new Rectangle(this.x, this.y, this.width, this.height); |