diff options
-rw-r--r-- | src/subconscious/MapLoader.java | 18 | ||||
-rw-r--r-- | src/subconscious/graphics/MapEditorScene.java | 249 | ||||
-rw-r--r-- | src/subconscious/graphics/MapScene.java | 2 |
3 files changed, 1 insertions, 268 deletions
diff --git a/src/subconscious/MapLoader.java b/src/subconscious/MapLoader.java index b89f8b0..6fe1273 100644 --- a/src/subconscious/MapLoader.java +++ b/src/subconscious/MapLoader.java @@ -26,12 +26,7 @@ public class MapLoader { public MapLoader() { } - - // @Deprecated - public MapLoader(Object o) { - throw new UnsupportedOperationException(); - } - + public Map get(final String mapName) { return this.getAbsolute(MAPS_RESOURCES_PATH + mapName); } @@ -58,17 +53,6 @@ public class MapLoader { return this.gson.fromJson(json, Map.class); } - - // @Deprecated - public Map getMap() { - throw new UnsupportedOperationException(); - } - - // @Deprecated - public void saveMap(Map map) { - throw new UnsupportedOperationException(); - } - // public void saveMap(Map map) { // Gson gson = new Gson(); // String mapText = gson.toJson(map); diff --git a/src/subconscious/graphics/MapEditorScene.java b/src/subconscious/graphics/MapEditorScene.java deleted file mode 100644 index 0b6d8a8..0000000 --- a/src/subconscious/graphics/MapEditorScene.java +++ /dev/null @@ -1,249 +0,0 @@ -package subconscious.graphics; - -import subconscious.Actor; -import subconscious.Tile; -import subconscious.Map; -import subconscious.MapLoader; - -import java.util.ArrayList; - -import java.awt.Canvas; -import java.awt.Graphics2D; -import java.awt.Dimension; -import java.awt.BorderLayout; -import java.awt.GridLayout; -import java.awt.event.KeyEvent; -import java.awt.event.MouseEvent; -import java.awt.event.MouseWheelEvent; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.image.BufferStrategy; -import java.awt.geom.AffineTransform; -import java.awt.geom.Point2D; -import java.awt.geom.AffineTransform; -import java.awt.geom.NoninvertibleTransformException; - -import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JOptionPane; -import javax.swing.JLabel; -import javax.swing.JTextField; -import javax.swing.JFileChooser; -import javax.swing.JCheckBox; - -import java.lang.Integer; - - -@SuppressWarnings("serial") -public class MapEditorScene extends MapScene implements ActionListener { - private Tile.Type placingTile = Tile.Type.CLEAR; - private Actor placingActor = new Actor("", 0, false, 0); - private ArrayList<Object> actorFields = new ArrayList<>(); - private JFrame actorFrame; - private boolean nukeActor = false; - private AffineTransform tx = new AffineTransform(); - - public MapEditorScene() { - super(null, "map-editor"); - this.setLayout(new BorderLayout()); - - JPanel bottomPanel = new JPanel(); - bottomPanel.setLayout(new GridLayout(1,5)); - - JButton newButton = new JButton("New"); - newButton.setActionCommand("new"); - JButton tileButton = new JButton("Placing selector"); - tileButton.setActionCommand("tile"); - JButton exportButton = new JButton("Export"); - exportButton.setActionCommand("export"); - JButton importButton = new JButton("Import"); - importButton.setActionCommand("import"); - JButton actorButton = new JButton("Actors"); - actorButton.setActionCommand("actors"); - - newButton.addActionListener(this); - tileButton.addActionListener(this); - actorButton.addActionListener(this); - exportButton.addActionListener(this); - importButton.addActionListener(this); - - bottomPanel.add(newButton); - bottomPanel.add(tileButton); - bottomPanel.add(actorButton); - bottomPanel.add(exportButton); - bottomPanel.add(importButton); - - this.add(bottomPanel, BorderLayout.PAGE_END); - this.add(this.canvas, BorderLayout.CENTER); - } - - - @Override - protected void build() {} - - @Override - protected void render(Graphics2D g) {} - - @Override - protected void update(long deltaNanoTime) {}; - - @Override - public void mouseClicked(MouseEvent e) { - Point2D p = new Point2D.Double(e.getX(), e.getY()); - try { - p = this.tx.inverseTransform(p, null); - } catch (NoninvertibleTransformException ex) {} - try { - int x = (int) p.getX()/tileSize; - int y = (int) p.getY()/tileSize; - this.map.getTile(x, y); - if (this.placingTile != Tile.Type.NONE) { - this.map.getTile(x, y).setType(this.placingTile); - } else { - if (!this.nukeActor) { - Actor actor = this.placingActor; - actor.place(x, y); - this.map.addActor(actor); - } else { - Actor toNuke = this.placingActor; - for (Actor actor : this.map.getActors()) { - if (x == actor.getX() && y == actor.getY()) { - toNuke = actor; - } - } - this.map.removeActor(toNuke); - } - } - } catch (ArrayIndexOutOfBoundsException ex) { - System.out.println("no tile clicked"); - } catch (NullPointerException ext) { - System.out.println("map non existent"); - } - } - - @Override - public void actionPerformed(ActionEvent e) { - if ("new".equals(e.getActionCommand())) { - JTextField size = new JTextField(); - - JComponent[] inputs = new JComponent[] { - new JLabel("Size"), - size, - }; - - int result = JOptionPane.showConfirmDialog(null, inputs, "New map", JOptionPane.DEFAULT_OPTION); - if (result == JOptionPane.OK_OPTION) { - int sizeN = Integer.parseInt(size.getText()); - this.map = new Map(new Dimension(sizeN, sizeN)); - } - } else if ("tile".equals(e.getActionCommand())) { - String[] values = {"Clear", "Grass", "Water", "Mountain", "Actor", "Remove Actor"}; - - Object result = JOptionPane.showInputDialog(null, "Tile Type", "Tile Type Selector", JOptionPane.DEFAULT_OPTION, null, values, "0"); - if (result != null) { - String selected = result.toString(); - switch (selected) { - case "Clear": - this.placingTile = Tile.Type.CLEAR; - break; - case "Grass": - this.placingTile = Tile.Type.GRASS; - break; - case "Water": - this.placingTile = Tile.Type.WATER; - break; - case "Mountain": - this.placingTile = Tile.Type.MOUNTAIN; - break; - case "Actor": - this.placingTile = Tile.Type.NONE; - this.nukeActor = false; - break; - case "Remove Actor": - this.placingTile = Tile.Type.NONE; - this.nukeActor = true; - break; - - } - } - } else if ("export".equals(e.getActionCommand())) { - JFileChooser fc = new JFileChooser(); - fc.showSaveDialog(null); - - MapLoader mapLoader = new MapLoader(fc.getSelectedFile()); - mapLoader.saveMap(this.map); - } else if ("import".equals(e.getActionCommand())) { - JFileChooser fc = new JFileChooser(); - fc.showOpenDialog(null); - - MapLoader mapLoader = new MapLoader(fc.getSelectedFile()); - this.map = mapLoader.getMap(); - } else if ("actors".equals(e.getActionCommand())) { - JFrame actorFrame = new JFrame("Actors"); - actorFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - actorFrame.setSize(new Dimension(300, 400)); - actorFrame.setLocationRelativeTo(null); - - JPanel panel = new JPanel(); - panel.setLayout(new GridLayout(5,2)); - - JLabel lName = new JLabel("Name"); - JTextField name = new JTextField(); - JLabel lAgility = new JLabel("Agility"); - JTextField agility = new JTextField(); - JLabel lHp = new JLabel("max HP"); - JTextField hp = new JTextField(); - JCheckBox enemy = new JCheckBox("Enemy"); - JLabel empty = new JLabel(); - JButton ok = new JButton("Confirm"); - ok.setActionCommand("actOk"); - JButton cancel = new JButton("Cancel"); - cancel.setActionCommand("actCancel"); - - ArrayList<Object> actorFields = new ArrayList<>(); - actorFields.add(name); - actorFields.add(hp); - actorFields.add(agility); - actorFields.add(enemy); - this.actorFields = actorFields; - - ok.addActionListener(this); - cancel.addActionListener(this); - - panel.add(lName); - panel.add(name); - panel.add(lAgility); - panel.add(agility); - panel.add(lHp); - panel.add(hp); - panel.add(enemy); - panel.add(empty); - panel.add(ok); - panel.add(cancel); - - actorFrame.add(panel); - actorFrame.pack(); - actorFrame.setVisible(true); - - this.actorFrame = actorFrame; - } else if ("actOk".equals(e.getActionCommand())) { - JTextField nameField = (JTextField) this.actorFields.get(0); - String name = nameField.getText(); - JTextField hpField = (JTextField) this.actorFields.get(1); - int hp = Integer.parseInt(hpField.getText()); - JTextField agilityField = (JTextField) this.actorFields.get(2); - int agility = Integer.parseInt(agilityField.getText()); - JCheckBox enemyBox = (JCheckBox) this.actorFields.get(3); - Actor actor = new Actor(name, hp, enemyBox.isSelected(), agility); - this.placingActor = actor; - this.actorFrame.setVisible(false); - this.actorFrame.dispose(); - } else if ("actCancel".equals(e.getActionCommand())) { - this.actorFrame.setVisible(false); - this.actorFrame.dispose(); - } - - } -} diff --git a/src/subconscious/graphics/MapScene.java b/src/subconscious/graphics/MapScene.java index 77e0c92..ecac56d 100644 --- a/src/subconscious/graphics/MapScene.java +++ b/src/subconscious/graphics/MapScene.java @@ -28,8 +28,6 @@ import java.awt.geom.NoninvertibleTransformException; @SuppressWarnings("serial") public abstract class MapScene extends Scene { - // TODO: remove - // @Deprecated protected Map map; // used for rendering |