Ajouté modes de sélection : pinceau (linéaire/ponctuel) + pot de
peinture (remplir)
This commit is contained in:
parent
9e98b7546b
commit
1c2d673bec
|
@ -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;
|
||||
|
@ -103,6 +108,14 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene
|
|||
|
||||
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);
|
||||
|
||||
tools.add(selectionMode);
|
||||
|
@ -204,6 +217,7 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene
|
|||
couche2.repaint();
|
||||
couche3.repaint();
|
||||
}
|
||||
|
||||
public void resize()
|
||||
{
|
||||
|
||||
|
@ -313,6 +327,11 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene
|
|||
}
|
||||
}
|
||||
|
||||
public int getSelectedPaintingMode()
|
||||
{
|
||||
return pen.isSelected() ? 0 : pot.isSelected() ? 1 : -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowActivated(WindowEvent event)
|
||||
{
|
||||
|
|
|
@ -25,34 +25,73 @@ public class MapMouseListener extends MouseAdapter
|
|||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent event)
|
||||
public void mouseClicked(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)
|
||||
if (frame.getSelectedPaintingMode() == 0)
|
||||
{
|
||||
if (getFrame().getSelectedSprite() != null)
|
||||
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().getCouche() - 1 > getFrame().getSelectedLayerIndex())
|
||||
return;
|
||||
|
||||
Case n;
|
||||
|
||||
switch (getFrame().getSelectedSprite().getCouche())
|
||||
if (getFrame().getSelectedSprite() != null)
|
||||
{
|
||||
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;
|
||||
}
|
||||
if (getFrame().getSelectedSprite().getCouche() - 1 > getFrame().getSelectedLayerIndex())
|
||||
return;
|
||||
|
||||
map.setCase((event.getX() - x + 2) / 34, (event.getY() - y + 2) / 34, n);
|
||||
panel.repaint();
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue