[BIG UPDATE] Terminée fenêtre d'édition de carte
This commit is contained in:
parent
64f4875705
commit
543d12ff2e
|
@ -12,5 +12,6 @@
|
|||
hs_err_pid*
|
||||
/target/
|
||||
*.log
|
||||
*.png
|
||||
img.png
|
||||
image.png
|
||||
/maps/
|
||||
|
|
|
@ -52,4 +52,10 @@ public class Case
|
|||
c.collision = collision;
|
||||
return c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "{Case x=" + x + " y=" + y + " couche1=" + couche1 + " couche2=" + couche2 + " couche3=" + couche3 + " collision=" + collision.name().toUpperCase() + "}\n";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ import com.google.gson.GsonBuilder;
|
|||
|
||||
public class EditorAPI
|
||||
{
|
||||
private static File LAST_FILE;
|
||||
|
||||
public static RawMap toRawMap(int width, int height)
|
||||
{
|
||||
List<RawCase> cases = new ArrayList<RawCase>();
|
||||
|
@ -38,7 +40,7 @@ public class EditorAPI
|
|||
return RawMap.create(cases, width, height);
|
||||
}
|
||||
|
||||
private static Gson createGson()
|
||||
public static Gson createGson()
|
||||
{
|
||||
GsonBuilder builder = new GsonBuilder();
|
||||
|
||||
|
@ -66,20 +68,30 @@ public class EditorAPI
|
|||
{
|
||||
JFileChooser jfc = createJFC();
|
||||
File file = null;
|
||||
while (file == null)
|
||||
{
|
||||
jfc.showSaveDialog(null);
|
||||
file = jfc.getSelectedFile();
|
||||
}
|
||||
jfc.showSaveDialog(null);
|
||||
file = jfc.getSelectedFile();
|
||||
|
||||
if (file == null)
|
||||
return;
|
||||
|
||||
if (!file.getName().toLowerCase().endsWith(".gmap") && !file.getName().toLowerCase().endsWith(".dat"))
|
||||
{
|
||||
file = new File(file.getParentFile(), file.getName() + ".gmap");
|
||||
}
|
||||
|
||||
LAST_FILE = file;
|
||||
|
||||
save(file, map);
|
||||
}
|
||||
|
||||
public static void save(RawMap map)
|
||||
{
|
||||
if (LAST_FILE != null)
|
||||
save(LAST_FILE, map);
|
||||
else
|
||||
saveAs(map);
|
||||
}
|
||||
|
||||
public static void save(File file, RawMap map)
|
||||
{
|
||||
String json = createGson().toJson(map);
|
||||
|
@ -111,11 +123,13 @@ public class EditorAPI
|
|||
JFileChooser jfc = createJFC();
|
||||
File file = null;
|
||||
|
||||
while (file == null)
|
||||
{
|
||||
jfc.showOpenDialog(null);
|
||||
file = jfc.getSelectedFile();
|
||||
}
|
||||
jfc.showOpenDialog(null);
|
||||
file = jfc.getSelectedFile();
|
||||
|
||||
if (file == null)
|
||||
return null;
|
||||
|
||||
LAST_FILE = file;
|
||||
|
||||
return open(file);
|
||||
}
|
||||
|
@ -181,6 +195,8 @@ public class EditorAPI
|
|||
{
|
||||
g.drawLine(0, y, width, y);
|
||||
}
|
||||
|
||||
map.setFont(image);
|
||||
}
|
||||
|
||||
return new Map(map);
|
||||
|
|
|
@ -50,4 +50,16 @@ public class RawCase
|
|||
c.collision = collision;;
|
||||
return c;
|
||||
}
|
||||
|
||||
public static RawCase create(Case c)
|
||||
{
|
||||
RawCase raw = new RawCase();
|
||||
raw.x = c.getPosX();
|
||||
raw.y = c.getPosY();
|
||||
raw.couche1 = RawSprite.create(c.getCoucheOne());
|
||||
raw.couche2 = RawSprite.create(c.getCoucheTwo());
|
||||
raw.couche3 = RawSprite.create(c.getCoucheThree());
|
||||
raw.collision = c.getCollision();
|
||||
return raw;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package galaxyoyo.unknown.api.editor;
|
||||
|
||||
import galaxyoyo.unknown.editor.Map;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RawMap
|
||||
|
@ -43,4 +46,18 @@ public class RawMap
|
|||
{
|
||||
this.font = font;
|
||||
}
|
||||
|
||||
public static RawMap create(Map map)
|
||||
{
|
||||
RawMap raw = new RawMap();
|
||||
raw.width = map.getWidth();
|
||||
raw.height = map.getHeight();
|
||||
raw.cases = new ArrayList<RawCase>();
|
||||
for (Case c : map.getAllCases())
|
||||
{
|
||||
RawCase rc = RawCase.create(c);
|
||||
raw.cases.add(rc);
|
||||
}
|
||||
return raw;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,29 @@
|
|||
package galaxyoyo.unknown.api.editor;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import galaxyoyo.unknown.api.editor.sprites.Sprite;
|
||||
|
||||
public class RawSprite
|
||||
{
|
||||
private int primaryIndex = 0;
|
||||
private int secondaryIndex = 0;
|
||||
private String category = "blank";
|
||||
private int index = 0;
|
||||
|
||||
@Expose(serialize = false, deserialize = false)
|
||||
public static final RawSprite BLANK = new RawSprite();
|
||||
public static transient final RawSprite BLANK = new RawSprite();
|
||||
|
||||
public int getPrimaryIndex()
|
||||
public String getCategory()
|
||||
{
|
||||
return primaryIndex;
|
||||
return category;
|
||||
}
|
||||
|
||||
public int getSecondaryIndex()
|
||||
public int getIndex()
|
||||
{
|
||||
return secondaryIndex;
|
||||
return index;
|
||||
}
|
||||
|
||||
public static RawSprite create(Sprite spr)
|
||||
{
|
||||
RawSprite raw = new RawSprite();
|
||||
raw.category = spr.getCategory().getName();
|
||||
raw.index = spr.getIndex();
|
||||
return raw;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,32 @@
|
|||
package galaxyoyo.unknown.api.editor.sprites;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Sprite
|
||||
{
|
||||
public static final Sprite BLANK = new Sprite(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB), Category.create("blank", 0, new ArrayList<Sprite>()));
|
||||
private Category cat;
|
||||
public static final Sprite BLANK = new Sprite(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB), Category.create("blank", 0, new ArrayList<Sprite>()), 0);
|
||||
|
||||
static
|
||||
{
|
||||
Graphics2D g = BLANK.getImage().createGraphics();
|
||||
g.setComposite(AlphaComposite.Clear);
|
||||
g.setColor(new Color(0, true));
|
||||
g.fillRect(0, 0, 16, 16);
|
||||
}
|
||||
|
||||
private final Category cat;
|
||||
private final BufferedImage img;
|
||||
private final int index;
|
||||
|
||||
public Sprite(BufferedImage img, Category cat)
|
||||
public Sprite(BufferedImage img, Category cat, int index)
|
||||
{
|
||||
this.img = img;
|
||||
this.cat = cat;
|
||||
this.index = index;
|
||||
|
||||
if (!this.cat.getSprites().contains(this))
|
||||
this.cat.getSprites().add(this);
|
||||
|
@ -28,4 +41,32 @@ public class Sprite
|
|||
{
|
||||
return cat;
|
||||
}
|
||||
|
||||
public int getIndex()
|
||||
{
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return cat.hashCode() ^ getIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (!(o instanceof Sprite))
|
||||
return false;
|
||||
|
||||
Sprite other = (Sprite) o;
|
||||
|
||||
return hashCode() == other.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "{Sprite img=" + img + " cat=" + cat.getName() + "}";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ public class SpriteRegister
|
|||
int x = list.get(0).intValue();
|
||||
int y = list.get(1).intValue();
|
||||
BufferedImage child = img.getSubimage(x, y, 16, 16);
|
||||
new Sprite(child, cat);
|
||||
new Sprite(child, cat, nameToCoords.get(key).indexOf(list));
|
||||
}
|
||||
|
||||
sprites.put(key, cat);
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.awt.Color;
|
|||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
|
@ -56,6 +57,8 @@ public class Main
|
|||
*/
|
||||
public static void main(String ... args)
|
||||
{
|
||||
Locale.setDefault(Locale.FRANCE);
|
||||
|
||||
DEV = Main.class.getResource("/META-INF/MANIFEST.MF") == null;
|
||||
|
||||
Logger LOGGER = (Logger) LogManager.getRootLogger();
|
||||
|
@ -128,7 +131,7 @@ public class Main
|
|||
* @see #launchFrame()
|
||||
* @since 0.1-aplha
|
||||
*/
|
||||
private static void launchEditMode()
|
||||
public static void launchEditMode()
|
||||
{
|
||||
System.out.println("Lancement de l'\u00e9diteur de monde ...");
|
||||
int baseWidth;
|
||||
|
@ -139,9 +142,11 @@ public class Main
|
|||
{
|
||||
try
|
||||
{
|
||||
baseWidth = Integer.parseInt(JOptionPane.showInputDialog("Veuillez entrez le nombre de cases longueur de votre carte :")) * 16;
|
||||
if (baseWidth <= 0)
|
||||
baseWidth = Integer.parseInt(JOptionPane.showInputDialog("Veuillez entrez le nombre de cases longueur de votre carte (0 pour annuler) :")) * 16;
|
||||
if (baseWidth < 0)
|
||||
throw new NumberFormatException();
|
||||
if (baseWidth == 0)
|
||||
return;
|
||||
break;
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
|
@ -154,9 +159,11 @@ public class Main
|
|||
{
|
||||
try
|
||||
{
|
||||
baseHeight = Integer.parseInt(JOptionPane.showInputDialog("Veuillez entrez le nombre de cases hauteur de votre carte :")) * 16;
|
||||
if (baseHeight <= 0)
|
||||
baseHeight = Integer.parseInt(JOptionPane.showInputDialog("Veuillez entrez le nombre de cases hauteur de votre carte (0 pour annuler) :")) * 16;
|
||||
if (baseHeight < 0)
|
||||
throw new NumberFormatException();
|
||||
if (baseHeight == 0)
|
||||
return;
|
||||
break;
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
|
|
|
@ -1,25 +1,37 @@
|
|||
package galaxyoyo.unknown.editor;
|
||||
|
||||
import galaxyoyo.unknown.api.editor.EditorAPI;
|
||||
import galaxyoyo.unknown.api.editor.RawMap;
|
||||
import galaxyoyo.unknown.api.editor.sprites.Category;
|
||||
import galaxyoyo.unknown.api.editor.sprites.Sprite;
|
||||
import galaxyoyo.unknown.api.editor.sprites.SpriteRegister;
|
||||
import galaxyoyo.unknown.frame.listeners.CreateMapListener;
|
||||
import galaxyoyo.unknown.frame.listeners.MapMouseListener;
|
||||
import galaxyoyo.unknown.frame.listeners.OpenMapListener;
|
||||
import galaxyoyo.unknown.frame.listeners.SpriteMouseListener;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowListener;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
public class EditorFrame extends JFrame implements ComponentListener, MouseListener, ChangeListener
|
||||
public class EditorFrame extends JFrame implements ChangeListener, ActionListener, WindowListener
|
||||
{
|
||||
private static final long serialVersionUID = -2705122356101556462L;
|
||||
|
||||
|
@ -27,14 +39,22 @@ public class EditorFrame extends JFrame implements ComponentListener, MouseListe
|
|||
|
||||
private final JPanel content = new JPanel();
|
||||
|
||||
private JMenuBar menuBar = new JMenuBar();
|
||||
private JMenu fichier = new JMenu("Fichier");
|
||||
private JMenuItem nouveau = new JMenuItem("Nouveau");
|
||||
private JMenuItem open = new JMenuItem("Ouvrir");
|
||||
private JMenuItem save = new JMenuItem("Sauvegarder");
|
||||
private JMenuItem saveAs = new JMenuItem("Sauvegarder sous ...");
|
||||
private JMenuItem exit = new JMenuItem("Quitter");
|
||||
private final JTabbedPane tabs = new JTabbedPane();
|
||||
private final JPanel tabEvents = new JPanel();
|
||||
private final JPanel tabColl = new JPanel();
|
||||
private final JPanel mapPanel = new JPanel();
|
||||
private final MapPanel mapPanel = new MapPanel(this);
|
||||
private final JTabbedPane resources = new JTabbedPane();
|
||||
private final JPanel couche1 = new JPanel();
|
||||
private final JPanel couche2 = new JPanel();
|
||||
private final JPanel couche3 = new JPanel();
|
||||
private SpriteComp selectedSprite;
|
||||
|
||||
public EditorFrame(Map map)
|
||||
{
|
||||
|
@ -46,15 +66,43 @@ public class EditorFrame extends JFrame implements ComponentListener, MouseListe
|
|||
this.setLocationRelativeTo(null);
|
||||
content.setLayout(new BorderLayout());
|
||||
this.setContentPane(content);
|
||||
this.addComponentListener(this);
|
||||
this.setVisible(true);
|
||||
this.setVisible(false);
|
||||
|
||||
tabs.addTab("Carte", mapPanel);
|
||||
tabs.addTab("\u00c9vennments", tabEvents);
|
||||
tabs.addTab("Collisions", tabColl);
|
||||
tabs.addMouseListener(this);
|
||||
tabs.addChangeListener(this);
|
||||
nouveau.setMnemonic(KeyEvent.CTRL_DOWN_MASK + KeyEvent.VK_N);
|
||||
nouveau.addActionListener(new CreateMapListener());
|
||||
fichier.add(nouveau);
|
||||
|
||||
open.setMnemonic(KeyEvent.CTRL_DOWN_MASK + KeyEvent.VK_O);
|
||||
open.addActionListener(new OpenMapListener());
|
||||
fichier.add(open);
|
||||
|
||||
fichier.addSeparator();
|
||||
|
||||
save.setMnemonic(KeyEvent.CTRL_DOWN_MASK + KeyEvent.VK_S);
|
||||
save.addActionListener(this);
|
||||
fichier.add(save);
|
||||
|
||||
saveAs.setMnemonic(KeyEvent.CTRL_DOWN_MASK + KeyEvent.SHIFT_MASK + KeyEvent.VK_S);
|
||||
saveAs.addActionListener(this);
|
||||
fichier.add(saveAs);
|
||||
|
||||
fichier.addSeparator();
|
||||
|
||||
exit.setMnemonic(KeyEvent.CTRL_DOWN_MASK + KeyEvent.VK_Q);
|
||||
exit.addActionListener(this);
|
||||
fichier.add(exit);
|
||||
|
||||
menuBar.add(fichier);
|
||||
|
||||
this.setJMenuBar(menuBar);
|
||||
|
||||
mapPanel.addMouseListener(new MapMouseListener(mapPanel, this));
|
||||
mapPanel.addMouseMotionListener(new MapMouseListener(mapPanel, this));
|
||||
|
||||
tabs.addTab("Carte", new JScrollPane(mapPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
|
||||
tabs.addTab("\u00c9vennments", new JScrollPane(tabEvents));
|
||||
tabs.addTab("Collisions", new JScrollPane(tabColl));
|
||||
|
||||
content.add(tabs, BorderLayout.CENTER);
|
||||
|
||||
|
@ -73,37 +121,23 @@ public class EditorFrame extends JFrame implements ComponentListener, MouseListe
|
|||
resources.addTab("", new ImageIcon(getClass().getResource("/assets/unknown/textures/layer 1.png")), scroll1);
|
||||
resources.addTab("", new ImageIcon(getClass().getResource("/assets/unknown/textures/layer 2.png")), scroll2);
|
||||
resources.addTab("", new ImageIcon(getClass().getResource("/assets/unknown/textures/layer 3.png")), scroll3);
|
||||
resources.addMouseListener(this);
|
||||
resources.addChangeListener(this);
|
||||
resources.setBackgroundAt(0, Color.white);
|
||||
resources.setBackgroundAt(1, Color.white);
|
||||
resources.setBackgroundAt(2, Color.white);
|
||||
|
||||
content.add(resources, BorderLayout.EAST);
|
||||
|
||||
this.componentResized(null);
|
||||
resize();
|
||||
|
||||
drawResources();
|
||||
|
||||
drawMap();
|
||||
}
|
||||
|
||||
private void drawMap()
|
||||
{
|
||||
if (mapPanel.getGraphics() == null)
|
||||
{
|
||||
mapPanel.repaint();
|
||||
}
|
||||
|
||||
mapPanel.getGraphics().drawImage(map.getFont(), 0, 0, null);
|
||||
mapPanel.revalidate();
|
||||
mapPanel.repaint();
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
private void drawResources()
|
||||
{
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
couche1.removeAll();
|
||||
couche2.removeAll();
|
||||
couche3.removeAll();
|
||||
|
@ -124,22 +158,15 @@ public class EditorFrame extends JFrame implements ComponentListener, MouseListe
|
|||
{
|
||||
for (Sprite spr : cat.getSprites())
|
||||
{
|
||||
SpriteComp sprc1 = new SpriteComp(spr, 1);
|
||||
SpriteComp sprc2 = new SpriteComp(spr, 2);
|
||||
SpriteComp sprc3 = new SpriteComp(spr, 3);
|
||||
sprc1.setLocation(x, y);
|
||||
sprc2.setLocation(x, y);
|
||||
sprc3.setLocation(x, y);
|
||||
SpriteComp sprc1 = new SpriteComp(spr, 0);
|
||||
SpriteComp sprc2 = new SpriteComp(spr, 1);
|
||||
SpriteComp sprc3 = new SpriteComp(spr, 2);
|
||||
sprc1.addMouseListener(new SpriteMouseListener(sprc1, this));
|
||||
sprc2.addMouseListener(new SpriteMouseListener(sprc2, this));
|
||||
sprc3.addMouseListener(new SpriteMouseListener(sprc3, this));
|
||||
couche1.add(sprc1);
|
||||
couche2.add(sprc2);
|
||||
couche3.add(sprc3);
|
||||
|
||||
x += 48;
|
||||
if (couche1.getWidth() - x < 48)
|
||||
{
|
||||
x = 0;
|
||||
y += 48;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,22 +177,6 @@ public class EditorFrame extends JFrame implements ComponentListener, MouseListe
|
|||
couche2.repaint();
|
||||
couche3.repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentHidden(ComponentEvent paramComponentEvent)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentMoved(ComponentEvent paramComponentEvent)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentResized(ComponentEvent paramComponentEvent)
|
||||
{
|
||||
}
|
||||
|
||||
public void resize()
|
||||
{
|
||||
|
||||
|
@ -190,44 +201,120 @@ public class EditorFrame extends JFrame implements ComponentListener, MouseListe
|
|||
((JScrollPane) resources.getSelectedComponent()).getVerticalScrollBar().setValue(cursorPos);
|
||||
}
|
||||
|
||||
public Map getMap()
|
||||
{
|
||||
return map;
|
||||
}
|
||||
|
||||
public SpriteComp getSelectedSprite()
|
||||
{
|
||||
return selectedSprite;
|
||||
}
|
||||
|
||||
public void setSelectedSprite(SpriteComp sprite)
|
||||
{
|
||||
this.selectedSprite = sprite;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentShown(ComponentEvent paramComponentEvent)
|
||||
public void stateChanged(ChangeEvent event)
|
||||
{
|
||||
if (event.getSource() == resources)
|
||||
{
|
||||
if (getSelectedLayerIndex() == 0)
|
||||
{
|
||||
resources.setBackgroundAt(0, Color.white);
|
||||
resources.setBackgroundAt(1, Color.white);
|
||||
resources.setBackgroundAt(2, Color.white);
|
||||
}
|
||||
else if (getSelectedLayerIndex() == 1)
|
||||
{
|
||||
resources.setBackgroundAt(0, Color.black);
|
||||
resources.setBackgroundAt(1, Color.white);
|
||||
resources.setBackgroundAt(2, Color.white);
|
||||
}
|
||||
else if (getSelectedLayerIndex() == 2)
|
||||
{
|
||||
resources.setBackgroundAt(0, Color.black);
|
||||
resources.setBackgroundAt(1, Color.black);
|
||||
resources.setBackgroundAt(2, Color.white);
|
||||
}
|
||||
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
public int getSelectedLayerIndex()
|
||||
{
|
||||
return resources.getSelectedIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent event)
|
||||
{
|
||||
if (event.getSource() == save)
|
||||
{
|
||||
EditorAPI.save(RawMap.create(map));
|
||||
}
|
||||
else if (event.getSource() == saveAs)
|
||||
{
|
||||
EditorAPI.saveAs(RawMap.create(map));
|
||||
}
|
||||
else if (event.getSource() == exit)
|
||||
{
|
||||
int result = JOptionPane.showConfirmDialog(null, "Voulez-vous sauvegarder votre carte avant de quitter ? Toute modification sera perdue", "Confirmation", JOptionPane.YES_NO_CANCEL_OPTION);
|
||||
|
||||
if (result == 0)
|
||||
save.doClick();
|
||||
|
||||
if (result != 2)
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowActivated(WindowEvent event)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent paramMouseEvent)
|
||||
public void windowClosed(WindowEvent event)
|
||||
{
|
||||
this.componentResized(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent paramMouseEvent)
|
||||
public void windowClosing(WindowEvent event)
|
||||
{
|
||||
this.componentResized(null);
|
||||
int result = JOptionPane.showConfirmDialog(null, "Voulez-vous sauvegarder avant de quitter ?", "Confirmation", JOptionPane.YES_NO_CANCEL_OPTION);
|
||||
|
||||
if (result == 0)
|
||||
{
|
||||
EditorAPI.save(RawMap.create(map));
|
||||
}
|
||||
|
||||
if (result != 2)
|
||||
{
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent paramMouseEvent)
|
||||
public void windowDeactivated(WindowEvent event)
|
||||
{
|
||||
this.componentResized(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent paramMouseEvent)
|
||||
public void windowDeiconified(WindowEvent event)
|
||||
{
|
||||
this.componentResized(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent paramMouseEvent)
|
||||
public void windowIconified(WindowEvent event)
|
||||
{
|
||||
this.componentResized(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent paramChangeEvent)
|
||||
public void windowOpened(WindowEvent event)
|
||||
{
|
||||
this.componentResized(null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import galaxyoyo.unknown.api.editor.RawCase;
|
|||
import galaxyoyo.unknown.api.editor.RawMap;
|
||||
import galaxyoyo.unknown.api.editor.sprites.SpriteRegister;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -13,24 +12,28 @@ import java.util.List;
|
|||
|
||||
public class Map
|
||||
{
|
||||
@Deprecated
|
||||
private static List<Case> cases;
|
||||
private final EditorFrame frame;
|
||||
private int width;
|
||||
private int height;
|
||||
private List<Case> cases = new ArrayList<Case>();
|
||||
private java.util.Map<Point, Case> casesMap = new HashMap<Point, Case>();
|
||||
private java.util.Map<Integer, java.util.Map<Integer, Case>> casesMap = new HashMap<Integer, java.util.Map<Integer, Case>>();
|
||||
private transient BufferedImage font;
|
||||
|
||||
public Map(RawMap raw)
|
||||
{
|
||||
cases = new ArrayList<Case>();
|
||||
this.width = raw.getWidth();
|
||||
this.height = raw.getHeight();
|
||||
this.font = raw.getFont();
|
||||
|
||||
for (RawCase rc : raw.getCases())
|
||||
{
|
||||
cases.add(Case.create(rc.getPosX(), rc.getPosY(), SpriteRegister.getCategory(rc.getCoucheOne().getPrimaryIndex()).getSprites().get(rc.getCoucheOne().getSecondaryIndex()), SpriteRegister.getCategory(rc.getCoucheTwo().getPrimaryIndex()).getSprites().get(rc.getCoucheTwo().getSecondaryIndex()), SpriteRegister.getCategory(rc.getCoucheThree().getPrimaryIndex()).getSprites().get(rc.getCoucheThree().getSecondaryIndex()), rc.getCollision()));
|
||||
cases.add(Case.create(rc.getPosX(), rc.getPosY(), SpriteRegister.getCategory(rc.getCoucheOne().getCategory()).getSprites().get(rc.getCoucheOne().getIndex()), SpriteRegister.getCategory(rc.getCoucheTwo().getCategory()).getSprites().get(rc.getCoucheTwo().getIndex()), SpriteRegister.getCategory(rc.getCoucheThree().getCategory()).getSprites().get(rc.getCoucheThree().getIndex()), rc.getCollision()));
|
||||
}
|
||||
|
||||
reorganizeMap();
|
||||
|
||||
frame = new EditorFrame(this);
|
||||
|
||||
getFrame().setVisible(true);
|
||||
|
@ -53,12 +56,12 @@ public class Map
|
|||
|
||||
public Case getCase(int x, int y)
|
||||
{
|
||||
if (casesMap.isEmpty())
|
||||
{
|
||||
reorganizeMap();
|
||||
}
|
||||
return casesMap.getOrDefault(x, new HashMap<Integer, Case>()).get(y);
|
||||
}
|
||||
|
||||
return casesMap.get(new Point(x, y));
|
||||
public void setCase(int x, int y, Case c)
|
||||
{
|
||||
casesMap.get(x).put(y, c);
|
||||
}
|
||||
|
||||
public BufferedImage getFont()
|
||||
|
@ -73,9 +76,26 @@ public class Map
|
|||
|
||||
private void reorganizeMap()
|
||||
{
|
||||
for (int i = 0; i < width; ++i)
|
||||
{
|
||||
casesMap.put(i, new HashMap<Integer, Case>());
|
||||
}
|
||||
|
||||
for (Case c : cases)
|
||||
{
|
||||
casesMap.put(new Point(c.getPosX() - c.getPosX() % 16, c.getPosY() - c.getPosY() % 16), c);
|
||||
setCase(c.getPosX(), c.getPosY(), c);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Case> getAllCases()
|
||||
{
|
||||
List<Case> list = new ArrayList<Case>();
|
||||
|
||||
for (java.util.Map<Integer, Case> l : casesMap.values())
|
||||
{
|
||||
list.addAll(l.values());
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
package galaxyoyo.unknown.editor;
|
||||
|
||||
import galaxyoyo.unknown.api.editor.Case;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MapPanel extends JPanel
|
||||
{
|
||||
private static final long serialVersionUID = 2629019576253690557L;
|
||||
|
||||
private final EditorFrame frame;
|
||||
|
||||
public MapPanel(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;
|
||||
|
||||
BufferedImage image;
|
||||
|
||||
g.drawImage(c.getCoucheOne().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
|
||||
if (frame.getSelectedLayerIndex() != 0)
|
||||
{
|
||||
image = recalculateAplha(c.getCoucheOne().getImage(), 0);
|
||||
g.drawImage(image, x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
|
||||
}
|
||||
|
||||
if (isEmpty(c.getCoucheTwo().getImage()) || (frame.getSelectedLayerIndex() != 1 && frame.getSelectedLayerIndex() != 2))
|
||||
continue;
|
||||
|
||||
g.drawImage(c.getCoucheTwo().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
|
||||
if (frame.getSelectedLayerIndex() != 1)
|
||||
{
|
||||
image = recalculateAplha(c.getCoucheTwo().getImage(), 1);
|
||||
g.drawImage(image, x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
|
||||
}
|
||||
|
||||
if (isEmpty(c.getCoucheThree().getImage()) || frame.getSelectedLayerIndex() != 2)
|
||||
continue;
|
||||
|
||||
g.drawImage(c.getCoucheThree().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
|
||||
if (frame.getSelectedLayerIndex() != 2)
|
||||
{
|
||||
image = recalculateAplha(c.getCoucheThree().getImage(), 2);
|
||||
g.drawImage(image, x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private BufferedImage recalculateAplha(BufferedImage image, int couche)
|
||||
{
|
||||
BufferedImage img = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
|
||||
|
||||
for (int x = 0; x < image.getWidth(); ++x)
|
||||
{
|
||||
for (int y = 0; y < image.getHeight(); ++y)
|
||||
{
|
||||
Color ref = new Color(image.getRGB(x, y));
|
||||
int red = ref.getRed() / 2;
|
||||
int green = ref.getGreen() / 2;
|
||||
int blue = ref.getBlue() / 2;
|
||||
if (image.getRGB(x, y) == 0xFFFFFF)
|
||||
continue;
|
||||
Graphics2D g = img.createGraphics();
|
||||
g.setColor(new Color(red / 3 * couche == 2 ? 1 : 2, green / 3 * couche == 2 ? 1 : 2, blue / 3 * couche == 2 ? 1 : 2, 100));
|
||||
g.drawLine(x, y, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package galaxyoyo.unknown.editor;
|
||||
|
||||
import galaxyoyo.unknown.api.editor.sprites.Category;
|
||||
import galaxyoyo.unknown.api.editor.sprites.Sprite;
|
||||
import galaxyoyo.unknown.api.editor.sprites.SpriteRegister;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class ResourcePanel extends JPanel
|
||||
{
|
||||
private static final long serialVersionUID = -5616765551654915921L;
|
||||
|
||||
public void paintComponent(Graphics g)
|
||||
{
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
for (Category cat : SpriteRegister.getAllCategories())
|
||||
{
|
||||
for (Sprite spr : cat.getSprites())
|
||||
{
|
||||
g.drawImage(spr.getImage(), x, y, 64, 64, Color.black, null);
|
||||
|
||||
x += 80;
|
||||
|
||||
if (getWidth()- x < 80)
|
||||
{
|
||||
x = 0;
|
||||
y += 80;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@ public class SpriteComp extends JComponent
|
|||
|
||||
private final Sprite sprite;
|
||||
private final int couche;
|
||||
private boolean selected;
|
||||
|
||||
public SpriteComp(Sprite sprite, int couche)
|
||||
{
|
||||
|
@ -38,6 +39,16 @@ public class SpriteComp extends JComponent
|
|||
return couche;
|
||||
}
|
||||
|
||||
public boolean isSelected()
|
||||
{
|
||||
return selected;
|
||||
}
|
||||
|
||||
public void setSelected(boolean selected)
|
||||
{
|
||||
this.selected = selected;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g)
|
||||
{
|
||||
|
@ -46,5 +57,14 @@ public class SpriteComp extends JComponent
|
|||
g.setColor(Color.white);
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
g.drawImage(sprite.getImage(), 0, 0, 32, 32, Color.white, null);
|
||||
|
||||
if (isSelected())
|
||||
{
|
||||
g.setColor(Color.black);
|
||||
g.drawLine(0, 0, getWidth() - 1, 0);
|
||||
g.drawLine(0, 0, 0, getHeight() - 1);
|
||||
g.drawLine(0, getHeight() - 1, getWidth() - 1, getHeight() - 1);
|
||||
g.drawLine(getWidth() - 1, 0, getWidth() - 1, getHeight() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
package galaxyoyo.unknown.frame.listeners;
|
||||
|
||||
import galaxyoyo.unknown.api.editor.Case;
|
||||
import galaxyoyo.unknown.editor.EditorFrame;
|
||||
import galaxyoyo.unknown.editor.Map;
|
||||
import galaxyoyo.unknown.editor.MapPanel;
|
||||
|
||||
import java.awt.Cursor;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class MapMouseListener extends MouseAdapter
|
||||
{
|
||||
private final EditorFrame frame;
|
||||
private final MapPanel panel;
|
||||
|
||||
public MapMouseListener(MapPanel 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)
|
||||
{
|
||||
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((event.getX() - x + 2) / 34, (event.getY() - y + 2) / 34, n);
|
||||
panel.repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package galaxyoyo.unknown.frame.listeners;
|
||||
|
||||
import galaxyoyo.unknown.editor.EditorFrame;
|
||||
import galaxyoyo.unknown.editor.SpriteComp;
|
||||
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class SpriteMouseListener extends MouseAdapter
|
||||
{
|
||||
private final SpriteComp sprite;
|
||||
private final EditorFrame frame;
|
||||
|
||||
public SpriteMouseListener(SpriteComp sprc, EditorFrame frame)
|
||||
{
|
||||
this.sprite = sprc;
|
||||
this.frame = frame;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent event)
|
||||
{
|
||||
if (frame.getSelectedSprite() != null)
|
||||
{
|
||||
frame.getSelectedSprite().setSelected(false);
|
||||
frame.getSelectedSprite().repaint();
|
||||
}
|
||||
frame.setSelectedSprite(sprite);
|
||||
sprite.setSelected(true);
|
||||
sprite.repaint();
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 2.4 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.6 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
Binary file not shown.
After Width: | Height: | Size: 187 B |
|
@ -1,4 +1,7 @@
|
|||
{
|
||||
"blank": [
|
||||
[0,0]
|
||||
],
|
||||
"gazon": [
|
||||
[0,0],
|
||||
[0,16],
|
||||
|
|
Loading…
Reference in New Issue