diff options
author | Nao Pross <naopross@thearcway.org> | 2018-11-20 14:12:45 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2018-11-20 14:14:33 +0100 |
commit | 9d46cef9b9715f7937b3d31a20497de6900027f1 (patch) | |
tree | 0b793395f80b84ad12f99368f917f76e2fb21443 | |
parent | Separate MapLoader constructors (diff) | |
download | Subconscious-java-9d46cef9b9715f7937b3d31a20497de6900027f1.tar.gz Subconscious-java-9d46cef9b9715f7937b3d31a20497de6900027f1.zip |
Suppress serialVersionUID warning
-rw-r--r-- | src/subconscious/graphics/BattleScene.java | 9 | ||||
-rw-r--r-- | src/subconscious/graphics/GameWindow.java | 3 | ||||
-rw-r--r-- | src/subconscious/graphics/MapEditorScene.java | 1 | ||||
-rw-r--r-- | src/subconscious/graphics/MapScene.java | 66 | ||||
-rw-r--r-- | src/subconscious/graphics/Scene.java | 13 |
5 files changed, 52 insertions, 40 deletions
diff --git a/src/subconscious/graphics/BattleScene.java b/src/subconscious/graphics/BattleScene.java index 5199ecc..6d41c2d 100644 --- a/src/subconscious/graphics/BattleScene.java +++ b/src/subconscious/graphics/BattleScene.java @@ -28,6 +28,7 @@ import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; +@SuppressWarnings("serial") public class BattleScene extends MapScene { private enum Mode { @@ -260,13 +261,17 @@ public class BattleScene extends MapScene { public void mouseMoved(MouseEvent e) { this.realX = e.getX(); this.realY = e.getY(); + int tileSize = this.maxSize/10; Point2D p = new Point2D.Double(e.getX(), e.getY()); + try { p = this.tx.inverseTransform(p, null); } catch (NoninvertibleTransformException ex) {} + int x = (int) (p.getX()/tileSize); int y = (int) (p.getY()/tileSize); + try { Tile tile = this.map.getTile(x, y); if (x != this.previousX || y != this.previousY) { @@ -285,9 +290,9 @@ public class BattleScene extends MapScene { this.previousY = y; } } catch (ArrayIndexOutOfBoundsException ex) { - System.out.println("no tile clicked"); + // System.out.println("no tile clicked"); } catch (NullPointerException ext) { - System.out.println("map non existent"); + // System.out.println("map non existent"); } } diff --git a/src/subconscious/graphics/GameWindow.java b/src/subconscious/graphics/GameWindow.java index 4d2f91c..f7459fd 100644 --- a/src/subconscious/graphics/GameWindow.java +++ b/src/subconscious/graphics/GameWindow.java @@ -12,7 +12,7 @@ import javax.swing.JButton; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; - +@SuppressWarnings("serial") public class GameWindow extends JFrame implements ActionListener { public static final Dimension WINDOW_SIZE = new Dimension(600, 400); @@ -107,6 +107,7 @@ public class GameWindow extends JFrame implements ActionListener { ((CardLayout)this.root.getLayout()).show(this, MENU_CARD); } + // Action Listener for menu @Override public void actionPerformed(ActionEvent e) { if (e.getActionCommand().startsWith("btn")) { diff --git a/src/subconscious/graphics/MapEditorScene.java b/src/subconscious/graphics/MapEditorScene.java index d6e8be4..0f3674c 100644 --- a/src/subconscious/graphics/MapEditorScene.java +++ b/src/subconscious/graphics/MapEditorScene.java @@ -34,6 +34,7 @@ import javax.swing.JCheckBox; import java.lang.Integer; +@SuppressWarnings("serial") public class MapEditorScene extends MapScene { private Tile.Type placingTile = Tile.Type.CLEAR; private Actor placingActor = new Actor("", 0, false, 0); diff --git a/src/subconscious/graphics/MapScene.java b/src/subconscious/graphics/MapScene.java index 93508c4..6978e1f 100644 --- a/src/subconscious/graphics/MapScene.java +++ b/src/subconscious/graphics/MapScene.java @@ -5,6 +5,7 @@ import subconscious.Tile; import subconscious.Actor; import java.awt.Canvas; +import java.awt.Point; import java.awt.Graphics2D; import java.awt.BasicStroke; import java.awt.Dimension; @@ -31,34 +32,46 @@ import java.io.FileReader; import java.io.BufferedReader; import java.io.IOException; + +@SuppressWarnings("serial") public abstract class MapScene extends Scene implements ActionListener { protected Map map; + protected Point pan; + protected Point mouse; + protected int panX = 0; protected int panY = 0; + protected boolean zooming = false; protected boolean panning = false; protected double zoom = 1; protected int mouseX; protected int mouseY; - protected boolean zooming = false; - protected int maxSize; + protected AffineTransform tx = new AffineTransform(); public MapScene() { super(); - //this.map = new Map(new Dimension(10, 10)); + } + + protected void renderTiles(Graphics2D g) { + } + + protected void renderActors(Graphics2D g) { + } @Override protected void render() { + if (this.canvasSize.width < this.canvasSize.height) { - this.maxSize = WIDTH; + this.maxSize = this.canvasSize.width; } else { - this.maxSize = HEIGHT; + this.maxSize = this.canvasSize.height; } if (this.map == null) { @@ -66,23 +79,27 @@ public abstract class MapScene extends Scene implements ActionListener { } Graphics2D g = (Graphics2D) this.buffer.getDrawGraphics(); - //clear + + // clear g.setColor(Palette.BLACK); g.fillRect(0, 0, this.canvasSize.width, this.canvasSize.height); - //zoom and pan + // zoom and pan if (this.zooming) { Point2D p1 = new Point2D.Double(this.mouseX, this.mouseY); Point2D p2 = null; try { p2 = tx.inverseTransform(p1, null); } catch (NoninvertibleTransformException ex) {} + this.tx.setToIdentity(); this.tx.translate(p1.getX(), p1.getY()); this.tx.scale(this.zoom, this.zoom); this.tx.translate(-p2.getX(), -p2.getY()); + this.zooming = false; } + if (this.panning) { this.tx.translate(this.panX/this.zoom, this.panY/this.zoom); this.panning = false; @@ -92,8 +109,7 @@ public abstract class MapScene extends Scene implements ActionListener { g.transform(this.tx); - //draw tiles - int tileSize = this.maxSize / 10; + final int tileSize = this.maxSize / 10; for (Tile tile : this.map.getGrid()) { switch (tile.getType()) { case CLEAR: @@ -109,44 +125,35 @@ public abstract class MapScene extends Scene implements ActionListener { break; } - g.fillRect( - tileSize * tile.getX(), tileSize * tile.getY(), - tileSize, tileSize); + // base color + g.fillRect(tileSize * tile.x, tileSize * tile.y, tileSize, tileSize); + // selection if (tile.isSelected()) { g.setColor(Palette.ORANGE_T); - //g.fillRect(tileSize * tile.getX() + tileSize/4, tileSize * tile.getY() + tileSize/4, - // tileSize/2, tileSize/2); - g.fillRect( - tileSize * tile.getX(), tileSize * tile.getY(), - tileSize, tileSize); + g.fillRect(tileSize * tile.x, tileSize * tile.y, tileSize, tileSize); } - //TODO: set as class variables the storkes + // TODO: set as class variables the storkes + // under cursor if (tile.cursorOnIt()) { BasicStroke oldStroke = (BasicStroke) g.getStroke(); - g.setStroke(new BasicStroke( - 10.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL - )); + + g.setStroke(new BasicStroke(10.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); g.setColor(Palette.ORANGE); - g.drawRect( - tileSize * tile.getX(), tileSize * tile.getY(), - tileSize, tileSize); + g.drawRect(tileSize * tile.x, tileSize * tile.y, tileSize, tileSize); g.setStroke(oldStroke); } - g.setPaint(Palette.BLACK); - g.drawRect( - tileSize * tile.getX(), tileSize * tile.getY(), - tileSize, tileSize); + g.drawRect(tileSize * tile.x, tileSize * tile.y, tileSize, tileSize); } g.setColor(Palette.ORANGE); int maxBound = this.map.getSize()*tileSize; g.drawRect(0, 0, maxBound, maxBound); - //draw actors + // Draw actors g.setFont(g.getFont().deriveFont(g.getFont().getSize()*2.0F)); for (Actor actor: this.map.getActors()) { if (actor.isEnemy()) { @@ -223,6 +230,7 @@ public abstract class MapScene extends Scene implements ActionListener { @Override public void mouseMoved(MouseEvent e) { + } @Override diff --git a/src/subconscious/graphics/Scene.java b/src/subconscious/graphics/Scene.java index 6daf9c2..c49246b 100644 --- a/src/subconscious/graphics/Scene.java +++ b/src/subconscious/graphics/Scene.java @@ -20,6 +20,7 @@ import javax.swing.JPanel; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; +@SuppressWarnings("serial") public abstract class Scene extends JPanel implements Runnable, KeyListener, MouseListener, MouseMotionListener, MouseWheelListener, ComponentListener { @@ -54,13 +55,6 @@ public abstract class Scene extends JPanel this.canvas.addMouseWheelListener(this); } - private void initCanvasBuffer() { - this.canvas.createBufferStrategy(2); - this.buffer = this.canvas.getBufferStrategy(); - - this.canvas.requestFocus(); - } - public void run() { long beginLoopTime; long endLoopTime; @@ -68,7 +62,10 @@ public abstract class Scene extends JPanel long lastUpdateTime; long deltaLoop; - this.initCanvasBuffer(); + // initialize canvas buffer + this.canvas.createBufferStrategy(2); + this.buffer = this.canvas.getBufferStrategy(); + this.canvas.requestFocus(); this.running = true; this.paused = false; |