mirror of
https://github.com/ynerant/Level-Editor.git
synced 2024-11-26 05:13:48 +00:00
Édition de collision terminée
This commit is contained in:
parent
c745571cc9
commit
bb1727bed7
@ -2,5 +2,5 @@ package galaxyoyo.unknown.api.editor;
|
|||||||
|
|
||||||
public enum Collision
|
public enum Collision
|
||||||
{
|
{
|
||||||
FULL, LEFT, RIGHT, TOP, BOTTOM, ANY;
|
FULL, PARTIAL, ANY;
|
||||||
}
|
}
|
||||||
|
104
src/main/java/galaxyoyo/unknown/editor/CollidPanel.java
Normal file
104
src/main/java/galaxyoyo/unknown/editor/CollidPanel.java
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
package galaxyoyo.unknown.editor;
|
||||||
|
|
||||||
|
import galaxyoyo.unknown.api.editor.Case;
|
||||||
|
import galaxyoyo.unknown.api.editor.Collision;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
public class CollidPanel extends JPanel
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = -138754019431984881L;
|
||||||
|
|
||||||
|
private final EditorFrame frame;
|
||||||
|
|
||||||
|
public CollidPanel(EditorFrame frame)
|
||||||
|
{
|
||||||
|
super ();
|
||||||
|
this.frame = frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditorFrame getFrame()
|
||||||
|
{
|
||||||
|
return frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map getMap()
|
||||||
|
{
|
||||||
|
return frame.getMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintComponent(Graphics g)
|
||||||
|
{
|
||||||
|
g.fillRect(0, 0, getWidth(), getHeight());
|
||||||
|
BufferedImage img = getMap().getFont();
|
||||||
|
int x = getWidth() / 2 - img.getWidth();
|
||||||
|
int y = getHeight() / 2 - img.getHeight();
|
||||||
|
int width = img.getWidth() * 2;
|
||||||
|
int height = img.getHeight() * 2;
|
||||||
|
g.drawImage(getMap().getFont(), x, y, width, height, null);
|
||||||
|
|
||||||
|
for (Case c : getMap().getAllCases())
|
||||||
|
{
|
||||||
|
if (isEmpty(c.getCoucheOne().getImage()))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
g.drawImage(c.getCoucheOne().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
|
||||||
|
|
||||||
|
if (isEmpty(c.getCoucheTwo().getImage()))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
g.drawImage(c.getCoucheTwo().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
|
||||||
|
|
||||||
|
if (isEmpty(c.getCoucheThree().getImage()))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
g.drawImage(c.getCoucheThree().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Case c : getMap().getAllCases())
|
||||||
|
{
|
||||||
|
if (c.getCollision() != Collision.ANY)
|
||||||
|
{
|
||||||
|
BufferedImage alpha = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
|
||||||
|
|
||||||
|
if (c.getCollision() == Collision.FULL)
|
||||||
|
{
|
||||||
|
Graphics2D grap = alpha.createGraphics();
|
||||||
|
grap.setColor(new Color(0, 0, 0, 100));
|
||||||
|
grap.fillRect(0, 0, 16, 16);
|
||||||
|
grap.dispose();
|
||||||
|
}
|
||||||
|
else if (c.getCollision() == Collision.PARTIAL)
|
||||||
|
{
|
||||||
|
Graphics2D grap = alpha.createGraphics();
|
||||||
|
grap.setColor(new Color(255, 0, 255, 70));
|
||||||
|
grap.fillRect(0, 0, 16, 16);
|
||||||
|
grap.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
g.drawImage(alpha, x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isEmpty(BufferedImage image)
|
||||||
|
{
|
||||||
|
int allrgba = 0;
|
||||||
|
|
||||||
|
for (int x = 0; x < image.getWidth(); ++x)
|
||||||
|
{
|
||||||
|
for (int y = 0; y < image.getHeight(); ++y)
|
||||||
|
{
|
||||||
|
allrgba += image.getRGB(x, y) + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return allrgba == 0;
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@ import galaxyoyo.unknown.api.editor.RawMap;
|
|||||||
import galaxyoyo.unknown.api.editor.sprites.Category;
|
import galaxyoyo.unknown.api.editor.sprites.Category;
|
||||||
import galaxyoyo.unknown.api.editor.sprites.Sprite;
|
import galaxyoyo.unknown.api.editor.sprites.Sprite;
|
||||||
import galaxyoyo.unknown.api.editor.sprites.SpriteRegister;
|
import galaxyoyo.unknown.api.editor.sprites.SpriteRegister;
|
||||||
|
import galaxyoyo.unknown.frame.listeners.CollidMapMouseListener;
|
||||||
import galaxyoyo.unknown.frame.listeners.CreateMapListener;
|
import galaxyoyo.unknown.frame.listeners.CreateMapListener;
|
||||||
import galaxyoyo.unknown.frame.listeners.MapMouseListener;
|
import galaxyoyo.unknown.frame.listeners.MapMouseListener;
|
||||||
import galaxyoyo.unknown.frame.listeners.OpenMapListener;
|
import galaxyoyo.unknown.frame.listeners.OpenMapListener;
|
||||||
@ -48,7 +49,7 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene
|
|||||||
private JMenuItem exit = new JMenuItem("Quitter");
|
private JMenuItem exit = new JMenuItem("Quitter");
|
||||||
private final JTabbedPane tabs = new JTabbedPane();
|
private final JTabbedPane tabs = new JTabbedPane();
|
||||||
private final JPanel tabEvents = new JPanel();
|
private final JPanel tabEvents = new JPanel();
|
||||||
private final JPanel tabColl = new JPanel();
|
private final CollidPanel tabColl = new CollidPanel(this);
|
||||||
private final MapPanel mapPanel = new MapPanel(this);
|
private final MapPanel mapPanel = new MapPanel(this);
|
||||||
private final JTabbedPane resources = new JTabbedPane();
|
private final JTabbedPane resources = new JTabbedPane();
|
||||||
private final JPanel couche1 = new JPanel();
|
private final JPanel couche1 = new JPanel();
|
||||||
@ -64,6 +65,7 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene
|
|||||||
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
|
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
|
||||||
this.setLocationRelativeTo(null);
|
this.setLocationRelativeTo(null);
|
||||||
|
this.addWindowListener(this);
|
||||||
content.setLayout(new BorderLayout());
|
content.setLayout(new BorderLayout());
|
||||||
this.setContentPane(content);
|
this.setContentPane(content);
|
||||||
this.setVisible(true);
|
this.setVisible(true);
|
||||||
@ -100,9 +102,13 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene
|
|||||||
mapPanel.addMouseListener(new MapMouseListener(mapPanel, this));
|
mapPanel.addMouseListener(new MapMouseListener(mapPanel, this));
|
||||||
mapPanel.addMouseMotionListener(new MapMouseListener(mapPanel, this));
|
mapPanel.addMouseMotionListener(new MapMouseListener(mapPanel, this));
|
||||||
|
|
||||||
|
tabColl.addMouseListener(new CollidMapMouseListener(tabColl, this));
|
||||||
|
tabColl.addMouseMotionListener(new CollidMapMouseListener(tabColl, this));
|
||||||
|
|
||||||
tabs.addTab("Carte", new JScrollPane(mapPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
|
tabs.addTab("Carte", new JScrollPane(mapPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
|
||||||
tabs.addTab("\u00c9vennments", new JScrollPane(tabEvents));
|
tabs.addTab("\u00c9vennments", new JScrollPane(tabEvents));
|
||||||
tabs.addTab("Collisions", new JScrollPane(tabColl));
|
tabs.addTab("Collisions", new JScrollPane(tabColl));
|
||||||
|
tabs.addChangeListener(this);
|
||||||
|
|
||||||
content.add(tabs, BorderLayout.CENTER);
|
content.add(tabs, BorderLayout.CENTER);
|
||||||
|
|
||||||
@ -240,6 +246,15 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene
|
|||||||
resources.setBackgroundAt(2, Color.white);
|
resources.setBackgroundAt(2, Color.white);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
else if (event.getSource() == tabs)
|
||||||
|
{
|
||||||
|
resources.setEnabled(tabs.getSelectedIndex() == 0);
|
||||||
|
couche1.setEnabled(resources.isEnabled());
|
||||||
|
couche2.setEnabled(resources.isEnabled());
|
||||||
|
couche3.setEnabled(resources.isEnabled());
|
||||||
|
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,8 +48,8 @@ public class MapPanel extends JPanel
|
|||||||
// BufferedImage image;
|
// BufferedImage image;
|
||||||
|
|
||||||
g.drawImage(c.getCoucheOne().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
|
g.drawImage(c.getCoucheOne().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
|
||||||
if (frame.getSelectedLayerIndex() != 0)
|
/* if (frame.getSelectedLayerIndex() != 0)
|
||||||
/* {
|
{
|
||||||
image = recalculateAplha(c.getCoucheOne().getImage(), 0);
|
image = recalculateAplha(c.getCoucheOne().getImage(), 0);
|
||||||
g.drawImage(image, x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
|
g.drawImage(image, x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
|
||||||
}*/
|
}*/
|
||||||
|
@ -0,0 +1,69 @@
|
|||||||
|
package galaxyoyo.unknown.frame.listeners;
|
||||||
|
|
||||||
|
import galaxyoyo.unknown.api.editor.Case;
|
||||||
|
import galaxyoyo.unknown.api.editor.Collision;
|
||||||
|
import galaxyoyo.unknown.editor.CollidPanel;
|
||||||
|
import galaxyoyo.unknown.editor.EditorFrame;
|
||||||
|
import galaxyoyo.unknown.editor.Map;
|
||||||
|
|
||||||
|
import java.awt.Cursor;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
|
||||||
|
public class CollidMapMouseListener extends MouseAdapter
|
||||||
|
{
|
||||||
|
private final EditorFrame frame;
|
||||||
|
private final CollidPanel panel;
|
||||||
|
|
||||||
|
public CollidMapMouseListener(CollidPanel panel, EditorFrame frame)
|
||||||
|
{
|
||||||
|
this.frame = frame;
|
||||||
|
this.panel = panel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditorFrame getFrame()
|
||||||
|
{
|
||||||
|
return frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseMoved(MouseEvent event)
|
||||||
|
{
|
||||||
|
Map map = getFrame().getMap();
|
||||||
|
|
||||||
|
int x = panel.getWidth() / 2 - map.getFont().getWidth();
|
||||||
|
int y = panel.getHeight() / 2 - map.getFont().getHeight();
|
||||||
|
|
||||||
|
if (map.getCase((event.getX() - x - 2) / 34, (event.getY() - y - 2) / 34) != null && event.getX() - x >= 2 && event.getY() - y >= 2)
|
||||||
|
{
|
||||||
|
getFrame().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
getFrame().setCursor(Cursor.getDefaultCursor());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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)
|
||||||
|
{
|
||||||
|
int colIndex = c.getCollision().ordinal();
|
||||||
|
int newColIndex = colIndex + 1;
|
||||||
|
if (newColIndex >= Collision.values().length)
|
||||||
|
newColIndex = 0;
|
||||||
|
Collision col = Collision.values()[newColIndex];
|
||||||
|
Case n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), c.getCoucheThree(), col);
|
||||||
|
|
||||||
|
map.setCase((event.getX() - x + 2) / 34, (event.getY() - y + 2) / 34, n);
|
||||||
|
panel.repaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user