diff options
author | Nao Pross <naopross@thearcway.org> | 2018-02-10 19:40:08 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2018-02-10 19:40:08 +0100 |
commit | 221aec874940378f5d8b6411e8b5c141816d5a1e (patch) | |
tree | 4ca7cb54583d50666d4e17230a505739813a3ab5 /src/main/java/WorldScene.java | |
parent | Add missing @Override(s) (diff) | |
download | Subconscious-old-221aec874940378f5d8b6411e8b5c141816d5a1e.tar.gz Subconscious-old-221aec874940378f5d8b6411e8b5c141816d5a1e.zip |
Add simple mouseclick listener to scenes
Diffstat (limited to 'src/main/java/WorldScene.java')
-rw-r--r-- | src/main/java/WorldScene.java | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/src/main/java/WorldScene.java b/src/main/java/WorldScene.java index 2145234..829afbb 100644 --- a/src/main/java/WorldScene.java +++ b/src/main/java/WorldScene.java @@ -25,6 +25,13 @@ public class WorldScene extends Scene { this.actors.add(player); } + private Composite makeAlpha(Graphics2D g2d, float alpha) { + Composite originalComposite = g2d.getComposite(); + g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); + + return originalComposite; + } + @Override public void render(Graphics g) { Graphics2D g2d = (Graphics2D) g; @@ -46,12 +53,19 @@ public class WorldScene extends Scene { this.tileSize, this.tileSize ); - // draw grid - // composite (enable alpha) - Composite originalComposite = g2d.getComposite(); - g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f)); + Composite originalComposite = makeAlpha(g2d, .5f); + + if (tile.selected) { + g2d.setColor(Palette.RED); + g2d.fillRect( + this.tileSize * tile.x, + this.tileSize * tile.y, + this.tileSize, this.tileSize + ); + } - g2d.setPaint(Color.BLACK); + // draw grid (with composite) + g2d.setPaint(Palette.BLACK); g2d.drawRect( this.tileSize * tile.x, this.tileSize * tile.y, @@ -71,12 +85,23 @@ public class WorldScene extends Scene { g2d.setColor(Palette.RED); break; } - int gap = this.tileSize/10; + int gap = this.tileSize / 10; g2d.fillRect( (this.tileSize * actor.x) + gap, (this.tileSize * actor.y) + gap, - this.tileSize - gap*2, this.tileSize - gap*2 + this.tileSize - gap * 2, this.tileSize - gap * 2 ); } } + + @Override + public void mouseClicked(int x, int y) { + Tile tile = map.getTile( + (int) (x/(double)this.tileSize) + sceneXOffset, + (int) (y/(double)this.tileSize) + sceneYOffset + ); + + // TODO find clicked actor + tile.selected = !tile.selected; + } } |