diff --git a/src/main/java/galaxyoyo/unknown/editor/EditorFrame.java b/src/main/java/galaxyoyo/unknown/editor/EditorFrame.java index 39dc31d..3b4276c 100644 --- a/src/main/java/galaxyoyo/unknown/editor/EditorFrame.java +++ b/src/main/java/galaxyoyo/unknown/editor/EditorFrame.java @@ -21,6 +21,7 @@ import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.awt.image.BufferedImage; +import javax.swing.ButtonGroup; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JMenu; @@ -28,6 +29,7 @@ import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.JRadioButtonMenuItem; import javax.swing.JScrollPane; import javax.swing.JTabbedPane; import javax.swing.KeyStroke; @@ -51,6 +53,9 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene private final JMenuItem saveAs = new JMenuItem("Sauvegarder sous ..."); private final JMenuItem exit = new JMenuItem("Quitter"); private final JMenu selectionMode = new JMenu("Mode de s\u00e9lection"); + ButtonGroup group = new ButtonGroup(); + private final JRadioButtonMenuItem pen = new JRadioButtonMenuItem("Pinceau"); + private final JRadioButtonMenuItem pot = new JRadioButtonMenuItem("Pot de peinture"); private final JTabbedPane tabs = new JTabbedPane(); private final JPanel tabEvents = new JPanel(); private final CollidPanel tabColl; @@ -102,6 +107,14 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene fichier.add(exit); menuBar.add(fichier); + + pen.setSelected(true); + pen.addActionListener(this); + pot.addActionListener(this); + group.add(pen); + group.add(pot); + selectionMode.add(pen); + selectionMode.add(pot); tools.setMnemonic(KeyEvent.VK_O + KeyEvent.ALT_DOWN_MASK); @@ -204,6 +217,7 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene couche2.repaint(); couche3.repaint(); } + public void resize() { @@ -312,6 +326,11 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene dispose(); } } + + public int getSelectedPaintingMode() + { + return pen.isSelected() ? 0 : pot.isSelected() ? 1 : -1; + } @Override public void windowActivated(WindowEvent event) diff --git a/src/main/java/galaxyoyo/unknown/frame/listeners/MapMouseListener.java b/src/main/java/galaxyoyo/unknown/frame/listeners/MapMouseListener.java index 62301f5..99812e2 100644 --- a/src/main/java/galaxyoyo/unknown/frame/listeners/MapMouseListener.java +++ b/src/main/java/galaxyoyo/unknown/frame/listeners/MapMouseListener.java @@ -25,34 +25,73 @@ public class MapMouseListener extends MouseAdapter } @Override - public void mouseReleased(MouseEvent event) - { - Map map = getFrame().getMap(); - - int x = panel.getWidth() / 2 - map.getFont().getWidth(); - int y = panel.getHeight() / 2 - map.getFont().getHeight(); - Case c = null; - - if ((c = map.getCase((event.getX() - x + 2) / 34, (event.getY() - y + 2) / 34)) != null && event.getX() - x >= 2 && event.getY() - y >= 2) + public void mouseClicked(MouseEvent event) + { + if (frame.getSelectedPaintingMode() == 0) { - if (getFrame().getSelectedSprite() != null) - { - if (getFrame().getSelectedSprite().getCouche() - 1 > getFrame().getSelectedLayerIndex()) - return; - - Case n; - - switch (getFrame().getSelectedSprite().getCouche()) - { - case 0 : n = Case.create(c.getPosX(), c.getPosY(), getFrame().getSelectedSprite().getSprite(), c.getCoucheTwo(), c.getCoucheThree(), c.getCollision()); break; - case 1 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), getFrame().getSelectedSprite().getSprite(), c.getCoucheThree(), c.getCollision()); break; - case 2 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), getFrame().getSelectedSprite().getSprite(), c.getCollision()); break; - default : n = c; break; + Map map = getFrame().getMap(); + + int x = panel.getWidth() / 2 - map.getFont().getWidth(); + int y = panel.getHeight() / 2 - map.getFont().getHeight(); + Case c = null; + + if ((c = map.getCase((event.getX() - x + 2) / 34, (event.getY() - y + 2) / 34)) != null && event.getX() - x >= 2 && event.getY() - y >= 2) + { + if (getFrame().getSelectedSprite() != null) + { + if (getFrame().getSelectedSprite().getCouche() - 1 > getFrame().getSelectedLayerIndex()) + return; + + Case n; + + switch (getFrame().getSelectedSprite().getCouche()) + { + case 0 : n = Case.create(c.getPosX(), c.getPosY(), getFrame().getSelectedSprite().getSprite(), c.getCoucheTwo(), c.getCoucheThree(), c.getCollision()); break; + case 1 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), getFrame().getSelectedSprite().getSprite(), c.getCoucheThree(), c.getCollision()); break; + case 2 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), getFrame().getSelectedSprite().getSprite(), c.getCollision()); break; + default : n = c; break; + } + + map.setCase(n.getPosX(), n.getPosY(), n); + panel.repaint(); } - - map.setCase((event.getX() - x + 2) / 34, (event.getY() - y + 2) / 34, n); - panel.repaint(); } } + else if (frame.getSelectedPaintingMode() == 1) + { + for (Case c : getFrame().getMap().getAllCases()) + { + Map map = getFrame().getMap(); + + if (getFrame().getSelectedSprite() != null) + { + if (getFrame().getSelectedSprite().getCouche() - 1 > getFrame().getSelectedLayerIndex()) + return; + + Case n; + + switch (getFrame().getSelectedSprite().getCouche()) + { + case 0 : n = Case.create(c.getPosX(), c.getPosY(), getFrame().getSelectedSprite().getSprite(), c.getCoucheTwo(), c.getCoucheThree(), c.getCollision()); break; + case 1 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), getFrame().getSelectedSprite().getSprite(), c.getCoucheThree(), c.getCollision()); break; + case 2 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), getFrame().getSelectedSprite().getSprite(), c.getCollision()); break; + default : n = c; break; + } + + map.setCase(n.getPosX(), n.getPosY(), n); + } + } + + panel.repaint(); + } + } + + @Override + public void mouseDragged(MouseEvent event) + { + if (frame.getSelectedPaintingMode() == 0) + { + mouseClicked(event); + } } }