1
0
mirror of https://github.com/ynerant/Level-Editor.git synced 2025-02-06 11:23:00 +00:00

Reformat code

This commit is contained in:
Yohann D'ANELLO 2020-02-25 00:23:01 +01:00
parent 397a2c337a
commit 6795917373
27 changed files with 1994 additions and 2090 deletions

View File

@ -2,60 +2,51 @@ package fr.ynerant.leveleditor.api.editor;
import fr.ynerant.leveleditor.api.editor.sprites.Sprite; import fr.ynerant.leveleditor.api.editor.sprites.Sprite;
public class Case public class Case {
{ private int x;
private int x; private int y;
private int y; private Sprite couche1;
private Sprite couche1; private Sprite couche2;
private Sprite couche2; private Sprite couche3;
private Sprite couche3; private Collision collision;
private Collision collision;
public int getPosX() public static Case create(int posX, int posY, Sprite couche1, Sprite couche2, Sprite couche3, Collision collision) {
{ Case c = new Case();
return x; c.x = posX;
} c.y = posY;
c.couche1 = couche1;
c.couche2 = couche2;
c.couche3 = couche3;
c.collision = collision;
return c;
}
public int getPosY() public int getPosX() {
{ return x;
return y; }
}
public Sprite getCoucheOne() public int getPosY() {
{ return y;
return couche1; }
}
public Sprite getCoucheTwo() public Sprite getCoucheOne() {
{ return couche1;
return couche2; }
}
public Sprite getCoucheThree() public Sprite getCoucheTwo() {
{ return couche2;
return couche3; }
}
public Collision getCollision() public Sprite getCoucheThree() {
{ return couche3;
return collision; }
}
public static Case create(int posX, int posY, Sprite couche1, Sprite couche2, Sprite couche3, Collision collision) public Collision getCollision() {
{ return collision;
Case c = new Case(); }
c.x = posX;
c.y = posY;
c.couche1 = couche1;
c.couche2 = couche2;
c.couche3 = couche3;
c.collision = collision;
return c;
}
@Override @Override
public String toString() public String toString() {
{ return "{Case x=" + x + " y=" + y + " couche1=" + couche1 + " couche2=" + couche2 + " couche3=" + couche3 + " collision=" + collision.name().toUpperCase() + "}\n";
return "{Case x=" + x + " y=" + y + " couche1=" + couche1 + " couche2=" + couche2 + " couche3=" + couche3 + " collision=" + collision.name().toUpperCase() + "}\n"; }
}
} }

View File

@ -1,6 +1,5 @@
package fr.ynerant.leveleditor.api.editor; package fr.ynerant.leveleditor.api.editor;
public enum Collision public enum Collision {
{ FULL, PARTIAL, ANY
FULL, PARTIAL, ANY;
} }

View File

@ -1,191 +1,161 @@
package fr.ynerant.leveleditor.api.editor; package fr.ynerant.leveleditor.api.editor;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import fr.ynerant.leveleditor.editor.Map; import fr.ynerant.leveleditor.editor.Map;
import java.awt.Color; import javax.swing.*;
import java.awt.Graphics2D; import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.BufferedInputStream; import java.io.*;
import java.io.BufferedOutputStream; import java.nio.charset.StandardCharsets;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
import javax.swing.JFileChooser; public class EditorAPI {
import javax.swing.filechooser.FileNameExtensionFilter; private static File LAST_FILE;
import com.google.gson.Gson; public static RawMap toRawMap(int width, int height) {
import com.google.gson.GsonBuilder; List<RawCase> cases = new ArrayList<RawCase>();
public class EditorAPI for (int y = 1; y < height; y += 16) {
{ for (int x = 1; x < width; x += 16) {
private static File LAST_FILE; RawCase c = RawCase.create(x / 16, y / 16, RawSprite.BLANK, RawSprite.BLANK, RawSprite.BLANK, Collision.ANY);
cases.add(c);
}
}
public static RawMap toRawMap(int width, int height) return RawMap.create(cases, width, height);
{ }
List<RawCase> cases = new ArrayList<RawCase>();
for (int y = 1; y < height; y += 16) public static Gson createGson() {
{ GsonBuilder builder = new GsonBuilder();
for (int x = 1; x < width; x += 16)
{
RawCase c = RawCase.create(x / 16, y / 16, RawSprite.BLANK, RawSprite.BLANK, RawSprite.BLANK, Collision.ANY);
cases.add(c);
}
}
return RawMap.create(cases, width, height); builder.enableComplexMapKeySerialization();
} builder.serializeNulls();
builder.setPrettyPrinting();
public static Gson createGson() return builder.create();
{ }
GsonBuilder builder = new GsonBuilder();
builder.enableComplexMapKeySerialization(); public static JFileChooser createJFC() {
builder.serializeNulls(); JFileChooser jfc = new JFileChooser();
builder.setPrettyPrinting();
return builder.create(); jfc.setFileFilter(new FileNameExtensionFilter("Fichiers monde (*.gmap, *.dat)", "gmap", "dat"));
} jfc.setFileHidingEnabled(true);
jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
File dir = new File("maps");
dir.mkdirs();
jfc.setCurrentDirectory(dir);
public static JFileChooser createJFC() return jfc;
{ }
JFileChooser jfc = new JFileChooser();
jfc.setFileFilter(new FileNameExtensionFilter("Fichiers monde (*.gmap, *.dat)", "gmap", "dat")); public static void saveAs(RawMap map) {
jfc.setFileHidingEnabled(true); JFileChooser jfc = createJFC();
jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); File file = null;
File dir = new File("maps"); jfc.showSaveDialog(null);
dir.mkdirs(); file = jfc.getSelectedFile();
jfc.setCurrentDirectory(dir);
return jfc; if (file == null)
} return;
public static void saveAs(RawMap map) if (!file.getName().toLowerCase().endsWith(".gmap") && !file.getName().toLowerCase().endsWith(".dat")) {
{ file = new File(file.getParentFile(), file.getName() + ".gmap");
JFileChooser jfc = createJFC(); }
File file = null;
jfc.showSaveDialog(null);
file = jfc.getSelectedFile();
if (file == null) LAST_FILE = file;
return;
if (!file.getName().toLowerCase().endsWith(".gmap") && !file.getName().toLowerCase().endsWith(".dat")) save(file, map);
{ }
file = new File(file.getParentFile(), file.getName() + ".gmap");
}
LAST_FILE = file; public static void save(RawMap map) {
if (LAST_FILE != null)
save(LAST_FILE, map);
else
saveAs(map);
}
save(file, map); public static void save(File file, RawMap map) {
} String json = createGson().toJson(map);
public static void save(RawMap map) try {
{ file.createNewFile();
if (LAST_FILE != null) BufferedOutputStream bos = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(file)));
save(LAST_FILE, map);
else
saveAs(map);
}
public static void save(File file, RawMap map) bos.write(json.getBytes(StandardCharsets.UTF_8));
{
String json = createGson().toJson(map);
try bos.close();
{ } catch (IOException ex) {
file.createNewFile(); ex.printStackTrace();
BufferedOutputStream bos = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(file))); }
}
bos.write(json.getBytes("UTF-8")); public static Map open() {
JFileChooser jfc = createJFC();
File file = null;
bos.close(); jfc.showOpenDialog(null);
} file = jfc.getSelectedFile();
catch (IOException ex)
{
ex.printStackTrace();
}
}
public static Map open() if (file == null)
{ return null;
JFileChooser jfc = createJFC();
File file = null;
jfc.showOpenDialog(null); LAST_FILE = file;
file = jfc.getSelectedFile();
if (file == null) return open(file);
return null; }
LAST_FILE = file; public static Map open(File f) {
String json = null;
try {
GZIPInputStream gis = new GZIPInputStream(new BufferedInputStream(new FileInputStream(f)));
byte[] bytes = new byte[512 * 1024];
int count = 0;
String text = "";
while ((count = gis.read(bytes)) != -1) {
text += new String(bytes, 0, count, StandardCharsets.UTF_8);
}
gis.close();
bytes = null;
return open(file); json = text;
} } catch (IOException e) {
e.printStackTrace();
}
public static Map open(File f) RawMap rm = createGson().fromJson(json, RawMap.class);
{
String json = null;
try
{
GZIPInputStream gis = new GZIPInputStream(new BufferedInputStream(new FileInputStream(f)));
byte[] bytes = new byte[512*1024];
int count = 0;
String text = "";
while ((count = gis.read(bytes)) != -1)
{
text += new String(bytes, 0, count, "UTF-8");
}
gis.close();
bytes = null;
json = text; return open(rm);
} }
catch (IOException e)
{
e.printStackTrace();
}
RawMap rm = createGson().fromJson(json, RawMap.class); public static Map open(RawMap map) {
if (map.getFont() == null) {
int baseWidth = map.getWidth();
int baseHeight = map.getHeight();
int width = baseWidth + (baseWidth / 16) + 1;
int height = baseHeight + (baseHeight / 16) + 1;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = image.createGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, width, height);
g.setColor(Color.black);
g.drawLine(0, 0, width, 0);
g.drawLine(0, 0, 0, height);
for (int x = 17; x <= width; x += 17) {
g.drawLine(x, 0, x, height);
}
return open(rm); for (int y = 17; y <= height; y += 17) {
} g.drawLine(0, y, width, y);
}
public static Map open(RawMap map) map.setFont(image);
{ }
if (map.getFont() == null)
{
int baseWidth = map.getWidth();
int baseHeight = map.getHeight();
int width = baseWidth + ((int) baseWidth / 16) + 1;
int height = baseHeight + ((int) baseHeight / 16) + 1;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = image.createGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, width, height);
g.setColor(Color.black);
g.drawLine(0, 0, width, 0);
g.drawLine(0, 0, 0, height);
for (int x = 17; x <= width; x += 17)
{
g.drawLine(x, 0, x, height);
}
for (int y = 17; y <= height; y += 17) return new Map(map);
{ }
g.drawLine(0, y, width, y);
}
map.setFont(image);
}
return new Map(map);
}
} }

View File

@ -1,65 +1,56 @@
package fr.ynerant.leveleditor.api.editor; package fr.ynerant.leveleditor.api.editor;
public class RawCase public class RawCase {
{ private int x;
private int x; private int y;
private int y; private RawSprite couche1;
private RawSprite couche1; private RawSprite couche2;
private RawSprite couche2; private RawSprite couche3;
private RawSprite couche3; private Collision collision;
private Collision collision;
public int getPosX() public static RawCase create(int posX, int posY, RawSprite couche1, RawSprite couche2, RawSprite couche3, Collision collision) {
{ RawCase c = new RawCase();
return x; c.x = posX;
} c.y = posY;
c.couche1 = couche1;
c.couche2 = couche2;
c.couche3 = couche3;
c.collision = collision;
return c;
}
public int getPosY() public static RawCase create(Case c) {
{ RawCase raw = new RawCase();
return y; 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;
}
public RawSprite getCoucheOne() public int getPosX() {
{ return x;
return couche1; }
}
public RawSprite getCoucheTwo() public int getPosY() {
{ return y;
return couche2; }
}
public RawSprite getCoucheThree() public RawSprite getCoucheOne() {
{ return couche1;
return couche3; }
}
public Collision getCollision() public RawSprite getCoucheTwo() {
{ return couche2;
return collision; }
}
public static RawCase create(int posX, int posY, RawSprite couche1, RawSprite couche2, RawSprite couche3, Collision collision) public RawSprite getCoucheThree() {
{ return couche3;
RawCase c = new RawCase(); }
c.x = posX;
c.y = posY;
c.couche1 = couche1;
c.couche2 = couche2;
c.couche3 = couche3;
c.collision = collision;;
return c;
}
public static RawCase create(Case c) public Collision getCollision() {
{ return collision;
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;
}
} }

View File

@ -6,58 +6,49 @@ import java.awt.image.BufferedImage;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class RawMap public class RawMap {
{ private List<RawCase> cases;
private List<RawCase> cases; private int width;
private int width; private int height;
private int height; private transient BufferedImage font;
private transient BufferedImage font;
public List<RawCase> getCases() public static RawMap create(List<RawCase> cases, int width, int height) {
{ RawMap rm = new RawMap();
return cases; rm.cases = cases;
} rm.width = width;
rm.height = height;
return rm;
}
public int getWidth() public static RawMap create(Map map) {
{ RawMap raw = new RawMap();
return width; 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;
}
public int getHeight() public List<RawCase> getCases() {
{ return cases;
return height; }
}
public static RawMap create(List<RawCase> cases, int width, int height) public int getWidth() {
{ return width;
RawMap rm = new RawMap(); }
rm.cases = cases;
rm.width = width;
rm.height = height;
return rm;
}
public BufferedImage getFont() public int getHeight() {
{ return height;
return font; }
}
public void setFont(BufferedImage font) public BufferedImage getFont() {
{ return font;
this.font = font; }
}
public static RawMap create(Map map) public void setFont(BufferedImage font) {
{ this.font = font;
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;
}
} }

View File

@ -2,28 +2,23 @@ package fr.ynerant.leveleditor.api.editor;
import fr.ynerant.leveleditor.api.editor.sprites.Sprite; import fr.ynerant.leveleditor.api.editor.sprites.Sprite;
public class RawSprite public class RawSprite {
{ public static transient final RawSprite BLANK = new RawSprite();
private String category = "blank"; private String category = "blank";
private int index = 0; private int index = 0;
public static transient final RawSprite BLANK = new RawSprite(); public static RawSprite create(Sprite spr) {
RawSprite raw = new RawSprite();
raw.category = spr.getCategory().getName();
raw.index = spr.getIndex();
return raw;
}
public String getCategory() public String getCategory() {
{ return category;
return category; }
}
public int getIndex() public int getIndex() {
{ return index;
return index; }
}
public static RawSprite create(Sprite spr)
{
RawSprite raw = new RawSprite();
raw.category = spr.getCategory().getName();
raw.index = spr.getIndex();
return raw;
}
} }

View File

@ -2,39 +2,33 @@ package fr.ynerant.leveleditor.api.editor.sprites;
import java.util.List; import java.util.List;
public class Category public class Category {
{ private List<Sprite> sprites;
private List<Sprite> sprites; private String name;
private String name; private int index;
private int index;
private Category() private Category() {
{ }
}
public String getName() public static Category create(String name, int index, List<Sprite> sprites) {
{ Category c = new Category();
return name;
}
public List<Sprite> getSprites() c.name = name;
{ c.index = index;
return sprites; c.sprites = sprites;
}
public int getIndex() return c;
{ }
return index;
}
public static Category create(String name, int index, List<Sprite> sprites) public String getName() {
{ return name;
Category c = new Category(); }
c.name = name; public List<Sprite> getSprites() {
c.index = index; return sprites;
c.sprites = sprites; }
return c; public int getIndex() {
} return index;
}
} }

View File

@ -1,72 +1,61 @@
package fr.ynerant.leveleditor.api.editor.sprites; package fr.ynerant.leveleditor.api.editor.sprites;
import java.awt.AlphaComposite; import java.awt.*;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.ArrayList; import java.util.ArrayList;
public class Sprite 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>()), 0);
public static final Sprite BLANK = new Sprite(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB), Category.create("blank", 0, new ArrayList<Sprite>()), 0);
static static {
{ Graphics2D g = BLANK.getImage().createGraphics();
Graphics2D g = BLANK.getImage().createGraphics(); g.setComposite(AlphaComposite.Clear);
g.setComposite(AlphaComposite.Clear); g.setColor(new Color(0, true));
g.setColor(new Color(0, true)); g.fillRect(0, 0, 16, 16);
g.fillRect(0, 0, 16, 16); }
}
private final Category cat; private final Category cat;
private final BufferedImage img; private final BufferedImage img;
private final int index; private final int index;
public Sprite(BufferedImage img, Category cat, int index) public Sprite(BufferedImage img, Category cat, int index) {
{ this.img = img;
this.img = img; this.cat = cat;
this.cat = cat; this.index = index;
this.index = index;
if (!this.cat.getSprites().contains(this)) if (!this.cat.getSprites().contains(this))
this.cat.getSprites().add(this); this.cat.getSprites().add(this);
} }
public BufferedImage getImage() public BufferedImage getImage() {
{ return this.img;
return this.img; }
}
public Category getCategory() public Category getCategory() {
{ return cat;
return cat; }
}
public int getIndex() public int getIndex() {
{ return index;
return index; }
}
@Override @Override
public int hashCode() public int hashCode() {
{ return cat.hashCode() ^ getIndex();
return cat.hashCode() ^ getIndex(); }
}
@Override @Override
public boolean equals(Object o) public boolean equals(Object o) {
{ if (!(o instanceof Sprite))
if (!(o instanceof Sprite)) return false;
return false;
Sprite other = (Sprite) o; Sprite other = (Sprite) o;
return hashCode() == other.hashCode(); return hashCode() == other.hashCode();
} }
@Override @Override
public String toString() public String toString() {
{ return "{Sprite img=" + img + " cat=" + cat.getName() + "}";
return "{Sprite img=" + img + " cat=" + cat.getName() + "}"; }
}
} }

View File

@ -1,175 +1,135 @@
package fr.ynerant.leveleditor.api.editor.sprites; package fr.ynerant.leveleditor.api.editor.sprites;
import com.google.gson.Gson;
import fr.ynerant.leveleditor.client.main.Main; import fr.ynerant.leveleditor.client.main.Main;
import org.apache.logging.log4j.LogManager;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.BufferedInputStream; import java.io.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.*;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import javax.imageio.ImageIO; public class SpriteRegister {
private static Map<String, List<List<Double>>> nameToCoords;
private static Map<String, Category> sprites = new HashMap<String, Category>();
import org.apache.logging.log4j.LogManager; public static void unpack() throws IOException, URISyntaxException {
if (Main.isInDevelopmentMode()) {
File dir = new File(SpriteRegister.class.getResource("/assets").toURI());
unpackDir(dir);
} else {
@SuppressWarnings("deprecation")
String path = URLDecoder.decode(SpriteRegister.class.getProtectionDomain().getCodeSource().getLocation().getPath());
path = path.substring(1);
File jarFile = new File(path);
import com.google.gson.Gson; if (jarFile.isFile()) {
JarFile jar = new JarFile(jarFile);
Enumeration<JarEntry> entries = jar.entries();
while (entries.hasMoreElements()) {
JarEntry je = entries.nextElement();
String name = je.getName();
if (name.startsWith("assets/")) {
File f = new File(name);
if (name.endsWith("/"))
f.mkdirs();
else if (!f.isFile())
Files.copy(jar.getInputStream(je), Paths.get(f.toURI()));
}
}
jar.close();
}
}
}
public class SpriteRegister private static void unpackDir(File dir) throws IOException {
{ for (File f : dir.listFiles()) {
private static Map<String, List<List<Double>>> nameToCoords; if (f.isDirectory()) {
private static Map<String, Category> sprites = new HashMap<String, Category>(); unpackDir(f);
continue;
}
public static void unpack() throws IOException, URISyntaxException String path = f.getAbsolutePath().substring(f.getAbsolutePath().indexOf(File.separatorChar + "assets") + 1);
{ File local = new File(path);
if (Main.isInDevelopmentMode()) local.getParentFile().mkdirs();
{ if (local.exists())
File dir = new File(SpriteRegister.class.getResource("/assets").toURI()); local.delete();
unpackDir(dir); Files.copy(Paths.get(f.toURI()), Paths.get(local.toURI()));
} }
else }
{
@SuppressWarnings("deprecation")
String path = URLDecoder.decode(SpriteRegister.class.getProtectionDomain().getCodeSource().getLocation().getPath());
path = path.substring(1, path.length());
File jarFile = new File(path);
if(jarFile.isFile()) @SuppressWarnings("unchecked")
{ public static void refreshAllSprites() {
JarFile jar = new JarFile(jarFile); if (nameToCoords != null && !nameToCoords.isEmpty() && !sprites.isEmpty()) {
Enumeration<JarEntry> entries = jar.entries(); return;
while (entries.hasMoreElements()) }
{
JarEntry je = entries.nextElement();
String name = je.getName();
if (name.startsWith("assets/"))
{
File f = new File(name);
if (name.endsWith("/"))
f.mkdirs();
else if (!f.isFile())
Files.copy(jar.getInputStream(je), Paths.get(f.toURI()));
}
}
jar.close();
}
}
}
private static void unpackDir(File dir) throws IOException File assetsDir = new File("assets");
{ List<String> assets = new ArrayList<String>();
for (File f : dir.listFiles())
{
if (f.isDirectory())
{
unpackDir(f);
continue;
}
String path = f.getAbsolutePath().substring(f.getAbsolutePath().indexOf(File.separatorChar + "assets") + 1); for (File dir : assetsDir.listFiles()) {
File local = new File(path); assets.add(dir.getName());
local.getParentFile().mkdirs(); }
if (local.exists())
local.delete();
Files.copy(Paths.get(f.toURI()), Paths.get(local.toURI()));
}
}
@SuppressWarnings("unchecked") for (String asset : assets) {
public static void refreshAllSprites() try {
{ File f = new File(assetsDir.getAbsolutePath() + "/" + asset + "/textures/sprites");
if (nameToCoords != null && !nameToCoords.isEmpty() && !sprites.isEmpty()) f.mkdirs();
{ BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(f, "sprites.json"))));
return; nameToCoords = new Gson().fromJson(br, Map.class);
} br.close();
File assetsDir = new File("assets"); for (String key : nameToCoords.keySet()) {
List<String> assets = new ArrayList<String>(); try {
for (File dir : assetsDir.listFiles()) BufferedInputStream is = new BufferedInputStream(new FileInputStream(new File(f, key + ".png")));
{ BufferedImage img = ImageIO.read(is);
assets.add(dir.getName()); Category cat = Category.create(key, new ArrayList<String>(nameToCoords.keySet()).indexOf(key), new ArrayList<Sprite>());
}
for (String asset : assets) for (List<Double> list : nameToCoords.get(key)) {
{ int x = list.get(0).intValue();
try int y = list.get(1).intValue();
{ BufferedImage child = img.getSubimage(x, y, 16, 16);
File f = new File(assetsDir.getAbsolutePath() + "/" + asset + "/textures/sprites"); new Sprite(child, cat, nameToCoords.get(key).indexOf(list));
f.mkdirs(); }
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(f, "sprites.json"))));
nameToCoords = new Gson().fromJson(br, Map.class);
br.close();
for (String key : nameToCoords.keySet()) sprites.put(key, cat);
{ } catch (Throwable t) {
try LogManager.getLogger("SpriteRegister").fatal("Erreur lors de la lecture du sprite '" + key + "'", t);
{ continue;
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
BufferedInputStream is = new BufferedInputStream(new FileInputStream(new File(f, key + ".png"))); public static Category getCategory(String name) {
BufferedImage img = ImageIO.read(is); return sprites.get(name);
Category cat = Category.create(key, new ArrayList<String>(nameToCoords.keySet()).indexOf(key), new ArrayList<Sprite>()); }
for (List<Double> list : nameToCoords.get(key)) public static Category getCategory(int index) {
{ return getCategory(new ArrayList<String>(sprites.keySet()).get(index));
int x = list.get(0).intValue(); }
int y = list.get(1).intValue();
BufferedImage child = img.getSubimage(x, y, 16, 16);
new Sprite(child, cat, nameToCoords.get(key).indexOf(list));
}
sprites.put(key, cat); public static List<Category> getAllCategories() {
} return new ArrayList<Category>(sprites.values());
catch (Throwable t) }
{
LogManager.getLogger("SpriteRegister").fatal("Erreur lors de la lecture du sprite '" + key + "'", t);
continue;
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
public static Category getCategory(String name) public static List<Sprite> getAllSprites() {
{ List<Sprite> list = new ArrayList<Sprite>();
return sprites.get(name);
}
public static Category getCategory(int index) for (Category c : sprites.values()) {
{ list.addAll(c.getSprites());
return getCategory(new ArrayList<String>(sprites.keySet()).get(index)); }
}
public static List<Category> getAllCategories() return list;
{ }
return new ArrayList<Category>(sprites.values());
}
public static List<Sprite> getAllSprites()
{
List<Sprite> list = new ArrayList<Sprite>();
for (Category c : sprites.values())
{
list.addAll(c.getSprites());
}
return list;
}
} }

View File

@ -3,16 +3,21 @@
*/ */
package fr.ynerant.leveleditor.client.main; package fr.ynerant.leveleditor.client.main;
import fr.ynerant.leveleditor.frame.MainFrame;
import fr.ynerant.leveleditor.api.editor.EditorAPI; import fr.ynerant.leveleditor.api.editor.EditorAPI;
import fr.ynerant.leveleditor.api.editor.RawMap; import fr.ynerant.leveleditor.api.editor.RawMap;
import fr.ynerant.leveleditor.api.editor.sprites.SpriteRegister; import fr.ynerant.leveleditor.api.editor.sprites.SpriteRegister;
import fr.ynerant.leveleditor.frame.MainFrame;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.appender.ConsoleAppender;
import org.apache.logging.log4j.core.layout.PatternLayout;
import java.awt.Color; import javax.swing.*;
import java.awt.Desktop; import java.awt.*;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -21,280 +26,232 @@ import java.net.URL;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.appender.ConsoleAppender;
import org.apache.logging.log4j.core.layout.PatternLayout;
/** /**
* Class principale qui lance le jeu * Class principale qui lance le jeu
*
* @author ÿnérant * @author ÿnérant
* @see #main(String...) * @see #main(String...)
*/ */
public class Main public class Main {
{ /**
/** * Variable disant si le jeu est en d&eacute;bogage ou non. S'active en ins&eacute;rant l'argument --debug dans le lancement.
* Variable disant si le jeu est en d&eacute;bogage ou non. S'active en ins&eacute;rant l'argument --debug dans le lancement. *
* @see #isInDebugMode() * @see #isInDebugMode()
* @see #main(String...) * @see #main(String...)
* @since 0.1-aplha * @since 0.1-aplha
*/ */
private static boolean DEBUG; private static boolean DEBUG;
/** /**
* Variable disant si le jeu est lanc&eacute; en d&eacute;veloppement ou non. * Variable disant si le jeu est lanc&eacute; en d&eacute;veloppement ou non.
* @see #isInDevelopmentMode() *
* @see #main(String...) * @see #isInDevelopmentMode()
* @since 0.1-aplha * @see #main(String...)
*/ * @since 0.1-aplha
private static boolean DEV; */
private static boolean DEV;
/** /**
* @param args arguments du jeu. Possibilit&eacute;s :<br>&nbsp;&nbsp;&nbsp;&nbsp;<strong>--edit</strong> lancera un &eacute;diteur<br>&nbsp;&nbsp;&nbsp;&nbsp;<strong>--help</strong> lance l'aide affichant toutes les options possibles * @param args arguments du jeu. Possibilit&eacute;s :<br>&nbsp;&nbsp;&nbsp;&nbsp;<strong>--edit</strong> lancera un &eacute;diteur<br>&nbsp;&nbsp;&nbsp;&nbsp;<strong>--help</strong> lance l'aide affichant toutes les options possibles
* @see #launchEditMode() * @see #launchEditMode()
* @since 0.1-alpha * @since 0.1-alpha
*/ */
public static void main(String ... args) public static void main(String... args) {
{ System.setProperty("sun.java2d.noddraw", "true");
System.setProperty("sun.java2d.noddraw", "true");
Locale.setDefault(Locale.FRANCE); Locale.setDefault(Locale.FRANCE);
try try {
{ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) {
} new ExceptionInInitializerError("Erreur lors du changement de 'look and feel'").printStackTrace();
catch (Exception e) System.err.print("Caused by ");
{ e.printStackTrace();
new ExceptionInInitializerError("Erreur lors du changement de 'look and feel'").printStackTrace(); }
System.err.print("Caused by ");
e.printStackTrace();
}
try try {
{ new File(Main.class.getResource("/assets").toURI());
new File(Main.class.getResource("/assets").toURI()); DEV = true;
DEV = true; } catch (Throwable t) {
} DEV = false;
catch (Throwable t) }
{
DEV = false;
}
Logger LOGGER = (Logger) LogManager.getRootLogger(); Logger LOGGER = (Logger) LogManager.getRootLogger();
ConsoleAppender console = ConsoleAppender.newBuilder().setLayout(PatternLayout.newBuilder().withPattern("[%d{dd/MM/yyyy}] [%d{HH:mm:ss}] [%t] [%c] [%p] %m%n").build()).setName("Console").build(); ConsoleAppender console = ConsoleAppender.newBuilder().setLayout(PatternLayout.newBuilder().withPattern("[%d{dd/MM/yyyy}] [%d{HH:mm:ss}] [%t] [%c] [%p] %m%n").build()).setName("Console").build();
console.start(); console.start();
LOGGER.addAppender(console); LOGGER.addAppender(console);
LOGGER.setLevel(Level.INFO); LOGGER.setLevel(Level.INFO);
checkJava(); checkJava();
OptionParser parser = new OptionParser(); OptionParser parser = new OptionParser();
OptionSpec<String> edit = parser.accepts("edit", "Lancer l'\u00e9diteur de monde").withOptionalArg(); OptionSpec<String> edit = parser.accepts("edit", "Lancer l'\u00e9diteur de monde").withOptionalArg();
OptionSpec<Boolean> debug = parser.accepts("debug").withOptionalArg().ofType(Boolean.class).defaultsTo(true); OptionSpec<Boolean> debug = parser.accepts("debug").withOptionalArg().ofType(Boolean.class).defaultsTo(true);
OptionSpec<String> help = parser.accepts("help", "Affiche ce menu d'aide").withOptionalArg().forHelp(); OptionSpec<String> help = parser.accepts("help", "Affiche ce menu d'aide").withOptionalArg().forHelp();
OptionSet set = parser.parse(args); OptionSet set = parser.parse(args);
if (set.has(help)) if (set.has(help)) {
{ try {
try parser.printHelpOn(System.out);
{ } catch (IOException e) {
parser.printHelpOn(System.out); e.printStackTrace();
} } finally {
catch (IOException e) System.exit(0);
{ }
e.printStackTrace(); }
}
finally
{
System.exit(0);
}
}
if (set.has(debug)) if (set.has(debug)) {
{ DEBUG = set.valueOf(debug);
DEBUG = set.valueOf(debug);
if (DEBUG) if (DEBUG) {
{ LOGGER.setLevel(Level.ALL);
LOGGER.setLevel(Level.ALL); }
} }
}
try try {
{ SpriteRegister.unpack();
SpriteRegister.unpack(); } catch (IOException | URISyntaxException e) {
} e.printStackTrace();
catch (IOException | URISyntaxException e) }
{
e.printStackTrace();
}
SpriteRegister.refreshAllSprites(); SpriteRegister.refreshAllSprites();
if (set.has(edit)) if (set.has(edit)) {
{ launchEditMode();
launchEditMode(); return;
return; }
}
launchFrame(); launchFrame();
} }
private static void checkJava() private static void checkJava() {
{ if (GraphicsEnvironment.isHeadless()) {
if (GraphicsEnvironment.isHeadless()) HeadlessException ex = new HeadlessException("Impossible de lancer un jeu sans \u00e9cran !");
{ LogManager.getLogger("JAVAX-SWING").fatal("Cette application est un jeu, sans écran, elle aura du mal \u00e0 tourner ...");
HeadlessException ex = new HeadlessException("Impossible de lancer un jeu sans \u00e9cran !"); LogManager.getLogger("JAVAX-SWING").catching(Level.FATAL, ex);
LogManager.getLogger("JAVAX-SWING").fatal("Cette application est un jeu, sans écran, elle aura du mal \u00e0 tourner ..."); System.exit(1);
LogManager.getLogger("JAVAX-SWING").catching(Level.FATAL, ex); }
System.exit(1);
}
try try {
{ Map.class.getDeclaredMethod("getOrDefault", Object.class, Object.class);
Map.class.getDeclaredMethod("getOrDefault", Object.class, Object.class); } catch (NoSuchMethodException ex) {
} ex.printStackTrace();
catch (NoSuchMethodException ex) JOptionPane.showMessageDialog(null, "<html>Cette application requiert <strong>Java 8</strong>.<br />La page de t\u00e9l\u00e9chargement va maintenant s'ouvrir.</html>");
{ JOptionPane.showMessageDialog(null, "<html>Si vous êtes certain que Java 8 est installé sur votre machine, assurez-vous qu'il n'y a pas de versions obsolètes de Java,<br />ou si vous êtes plus expérimentés si le path vers Java est bien défini vers la bonne version.</html>");
ex.printStackTrace(); try {
JOptionPane.showMessageDialog(null, "<html>Cette application requiert <strong>Java 8</strong>.<br />La page de t\u00e9l\u00e9chargement va maintenant s'ouvrir.</html>"); if (Desktop.isDesktopSupported())
JOptionPane.showMessageDialog(null, "<html>Si vous êtes certain que Java 8 est installé sur votre machine, assurez-vous qu'il n'y a pas de versions obsolètes de Java,<br />ou si vous êtes plus expérimentés si le path vers Java est bien défini vers la bonne version.</html>"); Desktop.getDesktop().browse(new URL("http://java.com/download").toURI());
try else
{ JOptionPane.showMessageDialog(null, "<html>Votre machine ne supporte pas la classe Desktop, impossible d'ouvrir la page.<br />Rendez-vous y manuellement sur <a href=\"http://java.com/download\">http://java.com/download</a> pour installer Java.</html>");
if (Desktop.isDesktopSupported()) } catch (IOException | URISyntaxException e) {
Desktop.getDesktop().browse(new URL("http://java.com/download").toURI()); e.printStackTrace();
else }
JOptionPane.showMessageDialog(null, "<html>Votre machine ne supporte pas la classe Desktop, impossible d'ouvrir la page.<br />Rendez-vous y manuellement sur <a href=\"http://java.com/download\">http://java.com/download</a> pour installer Java.</html>"); System.exit(1);
} }
catch (IOException | URISyntaxException e) }
{
e.printStackTrace();
}
System.exit(1);
}
}
/** /**
* Lance la fen&ecirc;tre principale * Lance la fen&ecirc;tre principale
* @see #main(String...) *
* @see #launchEditMode() * @see #main(String...)
*/ * @see #launchEditMode()
private static void launchFrame() */
{ private static void launchFrame() {
MainFrame.getInstance().setVisible(true); MainFrame.getInstance().setVisible(true);
} }
/** /**
* Permet de lancer l'&eacute;diteur de carte * Permet de lancer l'&eacute;diteur de carte
* @return *
* @see #main(String...) * @return
* @see #launchFrame() * @see #main(String...)
* @since 0.1-aplha * @see #launchFrame()
*/ * @since 0.1-aplha
public static boolean launchEditMode() */
{ public static boolean launchEditMode() {
System.out.println("Lancement de l'\u00e9diteur de monde ..."); System.out.println("Lancement de l'\u00e9diteur de monde ...");
int baseWidth; int baseWidth;
int baseHeight; int baseHeight;
int width; int width;
int height; int height;
while (true) while (true) {
{ try {
try String baseWidthStr = JOptionPane.showInputDialog(null, "Veuillez entrez le nombre de cases longueur de votre carte (0 pour annuler) :");
{ if (baseWidthStr == null)
String baseWidthStr = JOptionPane.showInputDialog(null, "Veuillez entrez le nombre de cases longueur de votre carte (0 pour annuler) :"); return false;
if (baseWidthStr == null) baseWidth = Integer.parseInt(baseWidthStr) * 16;
return false; if (baseWidth < 0)
baseWidth = Integer.parseInt(baseWidthStr) * 16; throw new NumberFormatException();
if (baseWidth < 0) if (baseWidth == 0)
throw new NumberFormatException(); return false;
if (baseWidth == 0) break;
return false; } catch (NumberFormatException ex) {
break; continue;
} }
catch (NumberFormatException ex) }
{
continue;
}
}
while (true) while (true) {
{ try {
try String baseHeightStr = JOptionPane.showInputDialog("Veuillez entrez le nombre de cases hauteur de votre carte (0 pour annuler) :");
{ if (baseHeightStr == null)
String baseHeightStr = JOptionPane.showInputDialog("Veuillez entrez le nombre de cases hauteur de votre carte (0 pour annuler) :"); return false;
if (baseHeightStr == null) baseHeight = Integer.parseInt(baseHeightStr) * 16;
return false; if (baseHeight < 0)
baseHeight = Integer.parseInt(baseHeightStr) * 16; throw new NumberFormatException();
if (baseHeight < 0) if (baseHeight == 0)
throw new NumberFormatException(); return false;
if (baseHeight == 0) break;
return false; } catch (NumberFormatException ex) {
break; continue;
} }
catch (NumberFormatException ex) }
{
continue;
}
}
width = baseWidth + ((int) baseWidth / 16) + 1; width = baseWidth + (baseWidth / 16) + 1;
height = baseHeight + ((int) baseHeight / 16) + 1; height = baseHeight + (baseHeight / 16) + 1;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = image.createGraphics(); Graphics2D g = image.createGraphics();
g.setColor(Color.white); g.setColor(Color.white);
g.fillRect(0, 0, width, height); g.fillRect(0, 0, width, height);
g.setColor(Color.black); g.setColor(Color.black);
g.drawLine(0, 0, width, 0); g.drawLine(0, 0, width, 0);
g.drawLine(0, 0, 0, height); g.drawLine(0, 0, 0, height);
for (int x = 17; x <= width; x += 17) for (int x = 17; x <= width; x += 17) {
{ g.drawLine(x, 0, x, height);
g.drawLine(x, 0, x, height); }
}
for (int y = 17; y <= height; y += 17) for (int y = 17; y <= height; y += 17) {
{ g.drawLine(0, y, width, y);
g.drawLine(0, y, width, y); }
}
RawMap rm = EditorAPI.toRawMap(baseWidth, baseHeight); RawMap rm = EditorAPI.toRawMap(baseWidth, baseHeight);
rm.setFont(image); rm.setFont(image);
EditorAPI.open(rm); EditorAPI.open(rm);
return true; return true;
} }
/** /**
* Accesseur disant si le jeu est en d&eacute;bogage ou non. S'active en ins&eacute;rant l'argument --debug dans le lancement. * Accesseur disant si le jeu est en d&eacute;bogage ou non. S'active en ins&eacute;rant l'argument --debug dans le lancement.
* @see #DEBUG *
* @since 0.1-aplha * @see #DEBUG
*/ * @since 0.1-aplha
public static boolean isInDebugMode() */
{ public static boolean isInDebugMode() {
return DEBUG; return DEBUG;
} }
/** /**
* Accesseur disant si le jeu est lanc&eacute; en d&eacute;veloppement ou non. * Accesseur disant si le jeu est lanc&eacute; en d&eacute;veloppement ou non.
* @see #DEV *
* @since 0.1-alpha * @see #DEV
*/ * @since 0.1-alpha
public static boolean isInDevelopmentMode() */
{ public static boolean isInDevelopmentMode() {
return DEV; return DEV;
} }
} }

View File

@ -1,5 +1,7 @@
/** /**
* Ce package comprend uniquement la classe Main, qui lance l'application. * Ce package comprend uniquement la classe Main, qui lance l'application.
*
* @author ÿnérant
*/ */
/** /**
* @author ÿnérant * @author ÿnérant

View File

@ -3,102 +3,85 @@ package fr.ynerant.leveleditor.editor;
import fr.ynerant.leveleditor.api.editor.Case; import fr.ynerant.leveleditor.api.editor.Case;
import fr.ynerant.leveleditor.api.editor.Collision; import fr.ynerant.leveleditor.api.editor.Collision;
import java.awt.Color; import javax.swing.*;
import java.awt.Graphics; import java.awt.*;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import javax.swing.JPanel; public class CollidPanel extends JPanel {
private static final long serialVersionUID = -138754019431984881L;
public class CollidPanel extends JPanel private final EditorFrame frame;
{
private static final long serialVersionUID = -138754019431984881L;
private final EditorFrame frame; public CollidPanel(EditorFrame frame) {
super();
this.frame = frame;
}
public CollidPanel(EditorFrame frame) public EditorFrame getFrame() {
{ return frame;
super (); }
this.frame = frame;
}
public EditorFrame getFrame() public Map getMap() {
{ return frame.getMap();
return frame; }
}
public Map getMap() @Override
{ public void paintComponent(Graphics g) {
return frame.getMap(); 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);
@Override for (Case c : getMap().getAllCases()) {
public void paintComponent(Graphics g) if (isEmpty(c.getCoucheOne().getImage()))
{ continue;
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()) g.drawImage(c.getCoucheOne().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
{
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;
if (isEmpty(c.getCoucheTwo().getImage())) g.drawImage(c.getCoucheTwo().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
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;
if (isEmpty(c.getCoucheThree().getImage())) g.drawImage(c.getCoucheThree().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
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);
for (Case c : getMap().getAllCases()) if (c.getCollision() == Collision.FULL) {
{ Graphics2D grap = alpha.createGraphics();
if (c.getCollision() != Collision.ANY) grap.setColor(new Color(0, 0, 0, 100));
{ grap.fillRect(0, 0, 16, 16);
BufferedImage alpha = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB); 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();
}
if (c.getCollision() == Collision.FULL) g.drawImage(alpha, x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
{ }
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;
}
}
private boolean isEmpty(BufferedImage image) for (int x = 0; x < image.getWidth(); ++x) {
{ for (int y = 0; y < image.getHeight(); ++y) {
int allrgba = 0; allrgba += image.getRGB(x, y) + 1;
}
}
for (int x = 0; x < image.getWidth(); ++x) return allrgba == 0;
{ }
for (int y = 0; y < image.getHeight(); ++y)
{
allrgba += image.getRGB(x, y) + 1;
}
}
return allrgba == 0;
}
} }

View File

@ -5,378 +5,319 @@ import fr.ynerant.leveleditor.api.editor.RawMap;
import fr.ynerant.leveleditor.api.editor.sprites.Category; import fr.ynerant.leveleditor.api.editor.sprites.Category;
import fr.ynerant.leveleditor.api.editor.sprites.Sprite; import fr.ynerant.leveleditor.api.editor.sprites.Sprite;
import fr.ynerant.leveleditor.api.editor.sprites.SpriteRegister; import fr.ynerant.leveleditor.api.editor.sprites.SpriteRegister;
import fr.ynerant.leveleditor.frame.listeners.CollidMapMouseListener; import fr.ynerant.leveleditor.frame.listeners.*;
import fr.ynerant.leveleditor.frame.listeners.CreateMapListener;
import fr.ynerant.leveleditor.frame.listeners.MapMouseListener;
import fr.ynerant.leveleditor.frame.listeners.OpenMapListener;
import fr.ynerant.leveleditor.frame.listeners.SpriteMouseListener;
import java.awt.BorderLayout; import javax.swing.*;
import java.awt.Color; import javax.swing.event.ChangeEvent;
import java.awt.Dimension; import javax.swing.event.ChangeListener;
import java.awt.event.ActionEvent; import java.awt.*;
import java.awt.event.ActionListener; import java.awt.event.*;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import javax.swing.ButtonGroup; public class EditorFrame extends JFrame implements ChangeListener, ActionListener, WindowListener {
import javax.swing.ImageIcon; private static final long serialVersionUID = -2705122356101556462L;
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.JRadioButtonMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.KeyStroke;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class EditorFrame extends JFrame implements ChangeListener, ActionListener, WindowListener private final Map map;
{
private static final long serialVersionUID = -2705122356101556462L;
private final Map map; private final JPanel content = new JPanel();
private final JPanel content = new JPanel(); private final JMenuBar menuBar = new JMenuBar();
private final JMenu fichier = new JMenu("Fichier");
private final JMenu tools = new JMenu("Outils");
private final JMenuItem nouveau = new JMenuItem("Nouveau");
private final JMenuItem open = new JMenuItem("Ouvrir");
private final JMenuItem save = new JMenuItem("Sauvegarder");
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");
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;
private final MapPanel mapPanel;
private final JTabbedPane resources = new JTabbedPane();
private final JPanel couche1 = new JPanel();
private final JPanel couche2 = new JPanel();
private final JPanel couche3 = new JPanel();
ButtonGroup group = new ButtonGroup();
private SpriteComp selectedSprite;
private final JMenuBar menuBar = new JMenuBar(); public EditorFrame(Map map) {
private final JMenu fichier = new JMenu("Fichier"); super("Alice Game Engine");
private final JMenu tools = new JMenu("Outils"); this.map = map;
private final JMenuItem nouveau = new JMenuItem("Nouveau"); this.setSize(600, 600);
private final JMenuItem open = new JMenuItem("Ouvrir"); this.setPreferredSize(getSize());
private final JMenuItem save = new JMenuItem("Sauvegarder"); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
private final JMenuItem saveAs = new JMenuItem("Sauvegarder sous ..."); this.setExtendedState(JFrame.MAXIMIZED_BOTH);
private final JMenuItem exit = new JMenuItem("Quitter"); this.setLocationRelativeTo(null);
private final JMenu selectionMode = new JMenu("Mode de s\u00e9lection"); this.addWindowListener(this);
ButtonGroup group = new ButtonGroup(); content.setLayout(new BorderLayout());
private final JRadioButtonMenuItem pen = new JRadioButtonMenuItem("Pinceau"); this.setContentPane(content);
private final JRadioButtonMenuItem pot = new JRadioButtonMenuItem("Pot de peinture"); this.setVisible(true);
private final JTabbedPane tabs = new JTabbedPane(); this.setVisible(false);
private final JPanel tabEvents = new JPanel();
private final CollidPanel tabColl;
private final MapPanel mapPanel;
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) fichier.setMnemonic(KeyEvent.VK_F + KeyEvent.ALT_DOWN_MASK);
{
super ("Alice Game Engine");
this.map = map;
this.setSize(600, 600);
this.setPreferredSize(getSize());
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.setLocationRelativeTo(null);
this.addWindowListener(this);
content.setLayout(new BorderLayout());
this.setContentPane(content);
this.setVisible(true);
this.setVisible(false);
fichier.setMnemonic(KeyEvent.VK_F + KeyEvent.ALT_DOWN_MASK); nouveau.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_DOWN_MASK, true));
nouveau.addActionListener(new CreateMapListener());
fichier.add(nouveau);
nouveau.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_DOWN_MASK, true)); open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_DOWN_MASK, true));
nouveau.addActionListener(new CreateMapListener()); open.addActionListener(new OpenMapListener());
fichier.add(nouveau); fichier.add(open);
open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_DOWN_MASK, true)); fichier.addSeparator();
open.addActionListener(new OpenMapListener());
fichier.add(open);
fichier.addSeparator(); save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK, true));
save.addActionListener(this);
fichier.add(save);
save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK, true)); saveAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK + KeyEvent.SHIFT_DOWN_MASK, true));
save.addActionListener(this); saveAs.addActionListener(this);
fichier.add(save); fichier.add(saveAs);
saveAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK + KeyEvent.SHIFT_DOWN_MASK, true)); fichier.addSeparator();
saveAs.addActionListener(this);
fichier.add(saveAs);
fichier.addSeparator(); exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, KeyEvent.CTRL_DOWN_MASK, true));
exit.addActionListener(this);
fichier.add(exit);
exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, KeyEvent.CTRL_DOWN_MASK, true)); menuBar.add(fichier);
exit.addActionListener(this);
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);
pen.setSelected(true); tools.setMnemonic(KeyEvent.VK_O + KeyEvent.ALT_DOWN_MASK);
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);
tools.add(selectionMode); menuBar.add(tools);
menuBar.add(tools); this.setJMenuBar(menuBar);
this.setJMenuBar(menuBar); mapPanel = new MapPanel(this);
mapPanel.addMouseListener(new MapMouseListener(mapPanel, this));
mapPanel.addMouseMotionListener(new MapMouseListener(mapPanel, this));
mapPanel = new MapPanel(this); tabColl = new CollidPanel(this);
mapPanel.addMouseListener(new MapMouseListener(mapPanel, this)); tabColl.addMouseListener(new CollidMapMouseListener(tabColl, this));
mapPanel.addMouseMotionListener(new MapMouseListener(mapPanel, this)); tabColl.addMouseMotionListener(new CollidMapMouseListener(tabColl, this));
tabColl = new CollidPanel(this); JScrollPane scrollMap = new JScrollPane(mapPanel);
tabColl.addMouseListener(new CollidMapMouseListener(tabColl, this)); scrollMap.getHorizontalScrollBar().setUnitIncrement(34);
tabColl.addMouseMotionListener(new CollidMapMouseListener(tabColl, this)); scrollMap.getVerticalScrollBar().setUnitIncrement(34);
JScrollPane scrollCollidMap = new JScrollPane(tabColl);
scrollCollidMap.getHorizontalScrollBar().setUnitIncrement(34);
scrollCollidMap.getVerticalScrollBar().setUnitIncrement(34);
JScrollPane scrollMap = new JScrollPane(mapPanel); tabs.addTab("Carte", scrollMap);
scrollMap.getHorizontalScrollBar().setUnitIncrement(34); tabs.addTab("\u00c9vennments", new JScrollPane(tabEvents));
scrollMap.getVerticalScrollBar().setUnitIncrement(34); tabs.addTab("Collisions", scrollCollidMap);
JScrollPane scrollCollidMap = new JScrollPane(tabColl); tabs.addChangeListener(this);
scrollCollidMap.getHorizontalScrollBar().setUnitIncrement(34);
scrollCollidMap.getVerticalScrollBar().setUnitIncrement(34);
tabs.addTab("Carte", scrollMap); content.add(tabs, BorderLayout.CENTER);
tabs.addTab("\u00c9vennments", new JScrollPane(tabEvents));
tabs.addTab("Collisions", scrollCollidMap);
tabs.addChangeListener(this);
content.add(tabs, BorderLayout.CENTER); couche1.setLayout(new WrapLayout(WrapLayout.LEFT));
couche2.setLayout(new WrapLayout(WrapLayout.LEFT));
couche3.setLayout(new WrapLayout(WrapLayout.LEFT));
couche1.setLayout(new WrapLayout(WrapLayout.LEFT)); JScrollPane scroll1 = new JScrollPane(couche1, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
couche2.setLayout(new WrapLayout(WrapLayout.LEFT)); JScrollPane scroll2 = new JScrollPane(couche2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
couche3.setLayout(new WrapLayout(WrapLayout.LEFT)); JScrollPane scroll3 = new JScrollPane(couche3, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
JScrollPane scroll1 = new JScrollPane(couche1, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scroll1.getHorizontalScrollBar().setMaximum(0);
JScrollPane scroll2 = new JScrollPane(couche2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scroll2.getHorizontalScrollBar().setMaximum(0);
JScrollPane scroll3 = new JScrollPane(couche3, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scroll3.getHorizontalScrollBar().setMaximum(0);
scroll1.getHorizontalScrollBar().setMaximum(0); resources.addTab("", new ImageIcon(new File("assets/leveleditor/textures/layer 1.png").getAbsolutePath()), scroll1);
scroll2.getHorizontalScrollBar().setMaximum(0); resources.addTab("", new ImageIcon(new File("assets/leveleditor/textures/layer 2.png").getAbsolutePath()), scroll2);
scroll3.getHorizontalScrollBar().setMaximum(0); resources.addTab("", new ImageIcon(new File("assets/leveleditor/textures/layer 3.png").getAbsolutePath()), scroll3);
resources.addChangeListener(this);
resources.setBackgroundAt(0, Color.white);
resources.setBackgroundAt(1, Color.white);
resources.setBackgroundAt(2, Color.white);
resources.addTab("", new ImageIcon(new File("assets/leveleditor/textures/layer 1.png").getAbsolutePath()), scroll1); content.add(resources, BorderLayout.EAST);
resources.addTab("", new ImageIcon(new File("assets/leveleditor/textures/layer 2.png").getAbsolutePath()), scroll2);
resources.addTab("", new ImageIcon(new File("assets/leveleditor/textures/layer 3.png").getAbsolutePath()), scroll3);
resources.addChangeListener(this);
resources.setBackgroundAt(0, Color.white);
resources.setBackgroundAt(1, Color.white);
resources.setBackgroundAt(2, Color.white);
content.add(resources, BorderLayout.EAST); resize();
resize(); drawResources();
drawResources(); revalidate();
repaint();
}
revalidate(); private void drawResources() {
repaint(); couche1.removeAll();
} couche2.removeAll();
couche3.removeAll();
private void drawResources() if (couche1.getComponents().length > 0) {
{ return;
couche1.removeAll(); }
couche2.removeAll();
couche3.removeAll();
if (couche1.getComponents().length > 0) if (couche1.getWidth() == 0 || couche2.getWidth() == 0 || couche3.getWidth() == 0) {
{ couche1.repaint();
return; couche2.repaint();
} couche3.repaint();
}
if (couche1.getWidth() == 0 || couche2.getWidth() == 0 || couche3.getWidth() == 0) for (Category cat : SpriteRegister.getAllCategories()) {
{ for (Sprite spr : cat.getSprites()) {
couche1.repaint(); SpriteComp sprc1 = new SpriteComp(spr, 0);
couche2.repaint(); SpriteComp sprc2 = new SpriteComp(spr, 1);
couche3.repaint(); 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);
}
}
for (Category cat : SpriteRegister.getAllCategories()) couche1.revalidate();
{ couche2.revalidate();
for (Sprite spr : cat.getSprites()) couche3.revalidate();
{ couche1.repaint();
SpriteComp sprc1 = new SpriteComp(spr, 0); couche2.repaint();
SpriteComp sprc2 = new SpriteComp(spr, 1); couche3.repaint();
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);
}
}
couche1.revalidate(); public void resize() {
couche2.revalidate();
couche3.revalidate();
couche1.repaint();
couche2.repaint();
couche3.repaint();
}
public void resize() int cursorPos = ((JScrollPane) resources.getSelectedComponent()).getVerticalScrollBar().getValue();
{ tabs.setPreferredSize(new Dimension(getWidth(), getHeight() / 5));
tabs.setLocation(0, 0);
BufferedImage img = getMap().getFont();
int width = img.getWidth() * 2;
int height = img.getHeight() * 2;
mapPanel.setPreferredSize(new Dimension(width, height));
mapPanel.setLocation(0, getHeight() / 5);
tabColl.setPreferredSize(new Dimension(width, height));
tabColl.setLocation(0, getHeight() / 5);
resources.setPreferredSize(new Dimension(getWidth() / 4 - 15, getHeight() / 5 * 4 - 40));
resources.setLocation(getWidth() / 4 * 3, getHeight() / 5);
int cursorPos = ((JScrollPane) resources.getSelectedComponent()).getVerticalScrollBar().getValue(); JScrollPane scroll1 = (JScrollPane) resources.getComponent(0);
tabs.setPreferredSize(new Dimension(getWidth(), getHeight() / 5)); JScrollPane scroll2 = (JScrollPane) resources.getComponent(1);
tabs.setLocation(0, 0); JScrollPane scroll3 = (JScrollPane) resources.getComponent(2);
BufferedImage img = getMap().getFont();
int width = img.getWidth() * 2;
int height = img.getHeight() * 2;
mapPanel.setPreferredSize(new Dimension(width, height));
mapPanel.setLocation(0, getHeight() / 5);
tabColl.setPreferredSize(new Dimension(width, height));
tabColl.setLocation(0, getHeight() / 5);
resources.setPreferredSize(new Dimension(getWidth() / 4 - 15, getHeight() / 5 * 4 - 40));
resources.setLocation(getWidth() / 4 * 3, getHeight() / 5);
JScrollPane scroll1 = (JScrollPane) resources.getComponent(0); scroll1.getHorizontalScrollBar().setMaximum(0);
JScrollPane scroll2 = (JScrollPane) resources.getComponent(1); scroll2.getHorizontalScrollBar().setMaximum(0);
JScrollPane scroll3 = (JScrollPane) resources.getComponent(2); scroll3.getHorizontalScrollBar().setMaximum(0);
scroll1.getHorizontalScrollBar().setMaximum(0); drawResources();
scroll2.getHorizontalScrollBar().setMaximum(0);
scroll3.getHorizontalScrollBar().setMaximum(0);
drawResources(); ((JScrollPane) resources.getSelectedComponent()).getVerticalScrollBar().setValue(cursorPos);
}
((JScrollPane) resources.getSelectedComponent()).getVerticalScrollBar().setValue(cursorPos); public Map getMap() {
} return map;
}
public Map getMap() public SpriteComp getSelectedSprite() {
{ return selectedSprite;
return map; }
}
public SpriteComp getSelectedSprite() public void setSelectedSprite(SpriteComp sprite) {
{ this.selectedSprite = sprite;
return selectedSprite; }
}
public void setSelectedSprite(SpriteComp sprite) @Override
{ public void stateChanged(ChangeEvent event) {
this.selectedSprite = sprite; 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);
}
@Override repaint();
public void stateChanged(ChangeEvent event) } else if (event.getSource() == tabs) {
{ resources.setEnabled(tabs.getSelectedIndex() == 0);
if (event.getSource() == resources) couche1.setEnabled(resources.isEnabled());
{ couche2.setEnabled(resources.isEnabled());
if (getSelectedLayerIndex() == 0) couche3.setEnabled(resources.isEnabled());
{
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(); repaint();
} }
else if (event.getSource() == tabs) }
{
resources.setEnabled(tabs.getSelectedIndex() == 0);
couche1.setEnabled(resources.isEnabled());
couche2.setEnabled(resources.isEnabled());
couche3.setEnabled(resources.isEnabled());
repaint(); public int getSelectedLayerIndex() {
} return resources.getSelectedIndex();
} }
public int getSelectedLayerIndex() @Override
{ public void actionPerformed(ActionEvent event) {
return resources.getSelectedIndex(); 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);
@Override if (result == 0)
public void actionPerformed(ActionEvent event) save.doClick();
{
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) if (result != 2)
save.doClick(); dispose();
}
}
if (result != 2) public int getSelectedPaintingMode() {
dispose(); return pen.isSelected() ? 0 : pot.isSelected() ? 1 : -1;
} }
}
public int getSelectedPaintingMode() @Override
{ public void windowActivated(WindowEvent event) {
return pen.isSelected() ? 0 : pot.isSelected() ? 1 : -1; }
}
@Override @Override
public void windowActivated(WindowEvent event) public void windowClosed(WindowEvent event) {
{ }
}
@Override @Override
public void windowClosed(WindowEvent event) public void windowClosing(WindowEvent event) {
{ int result = JOptionPane.showConfirmDialog(null, "Voulez-vous sauvegarder avant de quitter ?", "Confirmation", JOptionPane.YES_NO_CANCEL_OPTION);
}
@Override if (result == 0) {
public void windowClosing(WindowEvent event) EditorAPI.save(RawMap.create(map));
{ }
int result = JOptionPane.showConfirmDialog(null, "Voulez-vous sauvegarder avant de quitter ?", "Confirmation", JOptionPane.YES_NO_CANCEL_OPTION);
if (result == 0) if (result != 2) {
{ dispose();
EditorAPI.save(RawMap.create(map)); }
} }
if (result != 2) @Override
{ public void windowDeactivated(WindowEvent event) {
dispose(); }
}
}
@Override @Override
public void windowDeactivated(WindowEvent event) public void windowDeiconified(WindowEvent event) {
{ }
}
@Override @Override
public void windowDeiconified(WindowEvent event) public void windowIconified(WindowEvent event) {
{ }
}
@Override @Override
public void windowIconified(WindowEvent event) public void windowOpened(WindowEvent event) {
{ }
}
@Override
public void windowOpened(WindowEvent event)
{
}
} }

View File

@ -10,92 +10,77 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
public class Map public class Map {
{ @Deprecated
@Deprecated private static List<Case> cases;
private static List<Case> cases; private final EditorFrame frame;
private final EditorFrame frame; private int width;
private int width; private int height;
private int height; private java.util.Map<Integer, java.util.Map<Integer, Case>> casesMap = new HashMap<Integer, java.util.Map<Integer, Case>>();
private java.util.Map<Integer, java.util.Map<Integer, Case>> casesMap = new HashMap<Integer, java.util.Map<Integer, Case>>(); private transient BufferedImage font;
private transient BufferedImage font;
public Map(RawMap raw) public Map(RawMap raw) {
{ cases = new ArrayList<Case>();
cases = new ArrayList<Case>(); this.width = raw.getWidth();
this.width = raw.getWidth(); this.height = raw.getHeight();
this.height = raw.getHeight(); this.font = raw.getFont();
this.font = raw.getFont();
for (RawCase rc : raw.getCases()) for (RawCase rc : raw.getCases()) {
{ 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()));
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(); reorganizeMap();
frame = new EditorFrame(this); frame = new EditorFrame(this);
getFrame().setVisible(true); getFrame().setVisible(true);
} }
public EditorFrame getFrame() public EditorFrame getFrame() {
{ return frame;
return frame; }
}
public int getWidth() public int getWidth() {
{ return width;
return width; }
}
public int getHeight() public int getHeight() {
{ return height;
return height; }
}
public Case getCase(int x, int y) public Case getCase(int x, int y) {
{ return casesMap.getOrDefault(x, new HashMap<Integer, Case>()).get(y);
return casesMap.getOrDefault(x, new HashMap<Integer, Case>()).get(y); }
}
public void setCase(int x, int y, Case c) public void setCase(int x, int y, Case c) {
{ casesMap.get(x).put(y, c);
casesMap.get(x).put(y, c); }
}
public BufferedImage getFont() public BufferedImage getFont() {
{ return font;
return font; }
}
public void setFont(BufferedImage font) public void setFont(BufferedImage font) {
{ this.font = font;
this.font = font; }
}
private void reorganizeMap() private void reorganizeMap() {
{ for (int i = 0; i < width; ++i) {
for (int i = 0; i < width; ++i) casesMap.put(i, new HashMap<Integer, Case>());
{ }
casesMap.put(i, new HashMap<Integer, Case>());
}
for (Case c : cases) for (Case c : cases) {
{ setCase(c.getPosX(), c.getPosY(), c);
setCase(c.getPosX(), c.getPosY(), c); }
} }
}
public List<Case> getAllCases() public List<Case> getAllCases() {
{ List<Case> list = new ArrayList<Case>();
List<Case> list = new ArrayList<Case>();
for (java.util.Map<Integer, Case> l : casesMap.values()) for (java.util.Map<Integer, Case> l : casesMap.values()) {
{ list.addAll(l.values());
list.addAll(l.values()); }
}
return list; return list;
} }
} }

View File

@ -2,92 +2,79 @@ package fr.ynerant.leveleditor.editor;
import fr.ynerant.leveleditor.api.editor.Case; import fr.ynerant.leveleditor.api.editor.Case;
import java.awt.Graphics; import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import javax.swing.JPanel; public class MapPanel extends JPanel {
private static final long serialVersionUID = 2629019576253690557L;
public class MapPanel extends JPanel private final EditorFrame frame;
{
private static final long serialVersionUID = 2629019576253690557L;
private final EditorFrame frame; public MapPanel(EditorFrame frame) {
super();
this.frame = frame;
}
public MapPanel(EditorFrame frame) public EditorFrame getFrame() {
{ return frame;
super (); }
this.frame = frame;
}
public EditorFrame getFrame() public Map getMap() {
{ return frame.getMap();
return frame; }
}
public Map getMap() @Override
{ public void paintComponent(Graphics g) {
return frame.getMap(); 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);
@Override for (Case c : getMap().getAllCases()) {
public void paintComponent(Graphics g) // BufferedImage image;
{
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())) {
{ g.drawImage(c.getCoucheOne().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
// BufferedImage image; }
if (!isEmpty(c.getCoucheOne().getImage()))
{
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);
}*/ }*/
if (!isEmpty(c.getCoucheTwo().getImage()) && frame.getSelectedLayerIndex() >= 1) if (!isEmpty(c.getCoucheTwo().getImage()) && frame.getSelectedLayerIndex() >= 1) {
{ g.drawImage(c.getCoucheTwo().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
g.drawImage(c.getCoucheTwo().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null); }
}
/* if (frame.getSelectedLayerIndex() != 1) /* if (frame.getSelectedLayerIndex() != 1)
{ {
image = recalculateAplha(c.getCoucheTwo().getImage(), 1); image = recalculateAplha(c.getCoucheTwo().getImage(), 1);
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);
}*/ }*/
if (!isEmpty(c.getCoucheThree().getImage()) && frame.getSelectedLayerIndex() == 2) if (!isEmpty(c.getCoucheThree().getImage()) && frame.getSelectedLayerIndex() == 2) {
{ g.drawImage(c.getCoucheThree().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
g.drawImage(c.getCoucheThree().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null); }
}
/* if (frame.getSelectedLayerIndex() != 2) /* if (frame.getSelectedLayerIndex() != 2)
{ {
image = recalculateAplha(c.getCoucheThree().getImage(), 2); image = recalculateAplha(c.getCoucheThree().getImage(), 2);
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);
}*/ }*/
} }
} }
private boolean isEmpty(BufferedImage image) private boolean isEmpty(BufferedImage image) {
{ int allrgba = 0;
int allrgba = 0;
for (int x = 0; x < image.getWidth(); ++x) for (int x = 0; x < image.getWidth(); ++x) {
{ for (int y = 0; y < image.getHeight(); ++y) {
for (int y = 0; y < image.getHeight(); ++y) allrgba += image.getRGB(x, y) + 1;
{ }
allrgba += image.getRGB(x, y) + 1; }
}
}
return allrgba == 0; return allrgba == 0;
} }
} }

View File

@ -2,79 +2,66 @@ package fr.ynerant.leveleditor.editor;
import fr.ynerant.leveleditor.api.editor.sprites.Sprite; import fr.ynerant.leveleditor.api.editor.sprites.Sprite;
import java.awt.Color; import javax.swing.*;
import java.awt.Dimension; import java.awt.*;
import java.awt.Graphics;
import javax.swing.JComponent; public class SpriteComp extends JComponent {
private static final long serialVersionUID = -6512257366877053285L;
public class SpriteComp extends JComponent private Sprite sprite;
{ private int couche;
private static final long serialVersionUID = -6512257366877053285L; private boolean selected;
private Sprite sprite; public SpriteComp(Sprite sprite, int couche) {
private int couche; super();
private boolean selected; this.sprite = sprite;
this.couche = couche;
this.setMinimumSize(new Dimension(32, 32));
this.setMaximumSize(new Dimension(32, 32));
this.setPreferredSize(new Dimension(32, 32));
this.setSize(new Dimension(32, 32));
public SpriteComp(Sprite sprite, int couche) repaint();
{ }
super ();
this.sprite = sprite;
this.couche = couche;
this.setMinimumSize(new Dimension(32, 32));
this.setMaximumSize(new Dimension(32, 32));
this.setPreferredSize(new Dimension(32, 32));
this.setSize(new Dimension(32, 32));
repaint(); public Sprite getSprite() {
} return sprite;
}
public Sprite getSprite() public void setSprite(Sprite s) {
{ this.sprite = s;
return sprite; }
}
public void setSprite(Sprite s) public int getCouche() {
{ return couche;
this.sprite = s; }
}
public int getCouche() public void setCouche(int couche) {
{ this.couche = couche;
return couche; }
}
public void setCouche(int couche) public boolean isSelected() {
{ return selected;
this.couche = couche; }
}
public boolean isSelected() public void setSelected(boolean selected) {
{ this.selected = selected;
return selected; }
}
public void setSelected(boolean selected) @Override
{ public void paintComponent(Graphics g) {
this.selected = selected; super.paintComponent(g);
}
@Override g.setColor(Color.white);
public void paintComponent(Graphics g) g.fillRect(0, 0, getWidth(), getHeight());
{ g.drawImage(sprite.getImage(), 0, 0, 32, 32, Color.white, null);
super.paintComponent(g);
g.setColor(Color.white); if (isSelected()) {
g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(Color.black);
g.drawImage(sprite.getImage(), 0, 0, 32, 32, Color.white, null); g.drawLine(0, 0, getWidth() - 1, 0);
g.drawLine(0, 0, 0, getHeight() - 1);
if (isSelected()) g.drawLine(0, getHeight() - 1, getWidth() - 1, getHeight() - 1);
{ g.drawLine(getWidth() - 1, 0, getWidth() - 1, getHeight() - 1);
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);
}
}
} }

View File

@ -1,112 +1,96 @@
package fr.ynerant.leveleditor.editor; package fr.ynerant.leveleditor.editor;
import javax.swing.*;
import java.awt.*; import java.awt.*;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
public class WrapLayout extends FlowLayout public class WrapLayout extends FlowLayout {
{ private static final long serialVersionUID = 8777237960365591646L;
private static final long serialVersionUID = 8777237960365591646L;
public WrapLayout() public WrapLayout() {
{ super();
super(); }
}
public WrapLayout(int align) public WrapLayout(int align) {
{ super(align);
super(align); }
}
public WrapLayout(int align, int hgap, int vgap) public WrapLayout(int align, int hgap, int vgap) {
{ super(align, hgap, vgap);
super(align, hgap, vgap); }
}
@Override @Override
public Dimension preferredLayoutSize(Container target) public Dimension preferredLayoutSize(Container target) {
{ return layoutSize(target, true);
return layoutSize(target, true); }
}
@Override @Override
public Dimension minimumLayoutSize(Container target) public Dimension minimumLayoutSize(Container target) {
{ Dimension minimum = layoutSize(target, false);
Dimension minimum = layoutSize(target, false); minimum.width -= (getHgap() + 1);
minimum.width -= (getHgap() + 1); return minimum;
return minimum; }
}
private Dimension layoutSize(Container target, boolean preferred) private Dimension layoutSize(Container target, boolean preferred) {
{ synchronized (target.getTreeLock()) {
synchronized (target.getTreeLock()) int targetWidth = target.getSize().width;
{
int targetWidth = target.getSize().width;
if (targetWidth == 0) if (targetWidth == 0)
targetWidth = Integer.MAX_VALUE; targetWidth = Integer.MAX_VALUE;
int hgap = getHgap(); int hgap = getHgap();
int vgap = getVgap(); int vgap = getVgap();
Insets insets = target.getInsets(); Insets insets = target.getInsets();
int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2); int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2);
int maxWidth = targetWidth - horizontalInsetsAndGap; int maxWidth = targetWidth - horizontalInsetsAndGap;
Dimension dim = new Dimension(0, 0); Dimension dim = new Dimension(0, 0);
int rowWidth = 0; int rowWidth = 0;
int rowHeight = 0; int rowHeight = 0;
int nmembers = target.getComponentCount(); int nmembers = target.getComponentCount();
for (int i = 0; i < nmembers; i++) for (int i = 0; i < nmembers; i++) {
{ Component m = target.getComponent(i);
Component m = target.getComponent(i);
if (m.isVisible()) if (m.isVisible()) {
{ Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize();
Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize();
if (rowWidth + d.width > maxWidth) if (rowWidth + d.width > maxWidth) {
{ addRow(dim, rowWidth, rowHeight);
addRow(dim, rowWidth, rowHeight); rowWidth = 0;
rowWidth = 0; rowHeight = 0;
rowHeight = 0; }
}
if (rowWidth != 0) if (rowWidth != 0) {
{ rowWidth += hgap;
rowWidth += hgap; }
}
rowWidth += d.width; rowWidth += d.width;
rowHeight = Math.max(rowHeight, d.height); rowHeight = Math.max(rowHeight, d.height);
} }
} }
addRow(dim, rowWidth, rowHeight); addRow(dim, rowWidth, rowHeight);
dim.width += horizontalInsetsAndGap; dim.width += horizontalInsetsAndGap;
dim.height += insets.top + insets.bottom + vgap * 2; dim.height += insets.top + insets.bottom + vgap * 2;
Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target); Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target);
if (scrollPane != null) if (scrollPane != null) {
{ dim.width -= (hgap + 1);
dim.width -= (hgap + 1); }
}
return dim; return dim;
} }
} }
private void addRow(Dimension dim, int rowWidth, int rowHeight) private void addRow(Dimension dim, int rowWidth, int rowHeight) {
{ dim.width = Math.max(dim.width, rowWidth);
dim.width = Math.max(dim.width, rowWidth);
if (dim.height > 0) if (dim.height > 0) {
{ dim.height += getVgap();
dim.height += getVgap(); }
}
dim.height += rowHeight; dim.height += rowHeight;
} }
} }

View File

@ -7,106 +7,104 @@ import fr.ynerant.leveleditor.client.main.Main;
import fr.ynerant.leveleditor.frame.listeners.ChangeLAFListener; import fr.ynerant.leveleditor.frame.listeners.ChangeLAFListener;
import fr.ynerant.leveleditor.frame.listeners.CreateMapListener; import fr.ynerant.leveleditor.frame.listeners.CreateMapListener;
import fr.ynerant.leveleditor.frame.listeners.OpenMapListener; import fr.ynerant.leveleditor.frame.listeners.OpenMapListener;
import java.awt.Dimension;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Logger; import org.apache.logging.log4j.core.Logger;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
/** /**
* Fen&ecirc;tre principale du jeu * Fen&ecirc;tre principale du jeu
*
* @author ÿnérant * @author ÿnérant
*/ */
public class MainFrame extends JFrame public class MainFrame extends JFrame {
{ /**
/** * ID de s&eacute;rie
* ID de s&eacute;rie *
* @see {@link JFrame} * @see {@link JFrame}
*/ */
private static final long serialVersionUID = -3168760121879418534L; private static final long serialVersionUID = -3168760121879418534L;
/** /**
* Instance unique principale * Instance unique principale
* @see #MainFrame() *
* @see #getInstance() * @see #MainFrame()
*/ * @see #getInstance()
private static MainFrame INSTANCE; */
private static MainFrame INSTANCE;
/** /**
* Logger de la classe * Logger de la classe
* @see LogManager#getLogger(String) *
*/ * @see LogManager#getLogger(String)
private static Logger LOGGER = (Logger) LogManager.getLogger("MainFrame"); */
private static Logger LOGGER = (Logger) LogManager.getLogger("MainFrame");
private JMenuBar menuBar = new JMenuBar(); private JMenuBar menuBar = new JMenuBar();
private JMenu fichier = new JMenu("Fichier"); private JMenu fichier = new JMenu("Fichier");
private JMenu display = new JMenu("Affichage"); private JMenu display = new JMenu("Affichage");
private JMenu editMaps = new JMenu("Cartes"); private JMenu editMaps = new JMenu("Cartes");
private JMenu changeLAF = new JMenu("Modfier l'apparence"); private JMenu changeLAF = new JMenu("Modfier l'apparence");
private JMenuItem createMap = new JMenuItem("Cr\u00e9er"); private JMenuItem createMap = new JMenuItem("Cr\u00e9er");
private JMenuItem openMap = new JMenuItem("Ouvrir"); private JMenuItem openMap = new JMenuItem("Ouvrir");
private JMenuItem systemLAF = new JMenuItem("Apparence syst\u00e8me"); private JMenuItem systemLAF = new JMenuItem("Apparence syst\u00e8me");
private JMenuItem javaLAF = new JMenuItem("Apparence Java"); private JMenuItem javaLAF = new JMenuItem("Apparence Java");
private JMenuItem darkLAF = new JMenuItem("Apparence sombre"); private JMenuItem darkLAF = new JMenuItem("Apparence sombre");
/** /**
* Constructeur * Constructeur
* @see Main#launchFrame() *
*/ * @see Main#launchFrame()
@SuppressWarnings("JavadocReference") */
private MainFrame() @SuppressWarnings("JavadocReference")
{ private MainFrame() {
super (); super();
LOGGER.info("Initialisation de la fen\u00eatre"); LOGGER.info("Initialisation de la fen\u00eatre");
this.setTitle("Alice Game Engine"); this.setTitle("Alice Game Engine");
this.setPreferredSize(new Dimension(1000, 800)); this.setPreferredSize(new Dimension(1000, 800));
this.setSize(800, 700); this.setSize(800, 700);
this.setLocationRelativeTo(null); this.setLocationRelativeTo(null);
this.setExtendedState(JFrame.MAXIMIZED_BOTH); this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fichier.setMnemonic(KeyEvent.VK_F + KeyEvent.ALT_DOWN_MASK); fichier.setMnemonic(KeyEvent.VK_F + KeyEvent.ALT_DOWN_MASK);
display.setMnemonic(KeyEvent.VK_A + KeyEvent.ALT_DOWN_MASK); display.setMnemonic(KeyEvent.VK_A + KeyEvent.ALT_DOWN_MASK);
createMap.addActionListener(new CreateMapListener()); createMap.addActionListener(new CreateMapListener());
editMaps.add(createMap); editMaps.add(createMap);
openMap.addActionListener(new OpenMapListener()); openMap.addActionListener(new OpenMapListener());
editMaps.add(openMap); editMaps.add(openMap);
fichier.add(editMaps); fichier.add(editMaps);
systemLAF.addActionListener(new ChangeLAFListener(systemLAF, this)); systemLAF.addActionListener(new ChangeLAFListener(systemLAF, this));
changeLAF.add(systemLAF); changeLAF.add(systemLAF);
javaLAF.addActionListener(new ChangeLAFListener(javaLAF, this)); javaLAF.addActionListener(new ChangeLAFListener(javaLAF, this));
changeLAF.add(javaLAF); changeLAF.add(javaLAF);
darkLAF.addActionListener(new ChangeLAFListener(darkLAF, this)); darkLAF.addActionListener(new ChangeLAFListener(darkLAF, this));
changeLAF.add(darkLAF); changeLAF.add(darkLAF);
display.add(changeLAF); display.add(changeLAF);
menuBar.add(fichier); menuBar.add(fichier);
menuBar.add(display); menuBar.add(display);
this.setJMenuBar(menuBar); this.setJMenuBar(menuBar);
} }
/** /**
* Cet accesseur renvoie l'accesseur unique de la classe * Cet accesseur renvoie l'accesseur unique de la classe
* @see #INSTANCE *
* @see #MainFrame() * @return l'instance unique de la classe
* @return l'instance unique de la classe * @see #INSTANCE
*/ * @see #MainFrame()
public static MainFrame getInstance() */
{ public static MainFrame getInstance() {
if (INSTANCE == null) if (INSTANCE == null)
return INSTANCE = new MainFrame(); return INSTANCE = new MainFrame();
return INSTANCE; return INSTANCE;
} }
} }

View File

@ -2,69 +2,48 @@ package fr.ynerant.leveleditor.frame.listeners;
import fr.ynerant.leveleditor.frame.MainFrame; import fr.ynerant.leveleditor.frame.MainFrame;
import javax.swing.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import javax.swing.JFrame; public class ChangeLAFListener implements ActionListener {
import javax.swing.JMenuItem; private final JMenuItem item;
import javax.swing.SwingUtilities; private final JFrame frame;
import javax.swing.UIManager;
public class ChangeLAFListener implements ActionListener public ChangeLAFListener(JMenuItem LAF, MainFrame f) {
{ this.item = LAF;
private final JMenuItem item; this.frame = f;
private final JFrame frame; }
public ChangeLAFListener(JMenuItem LAF, MainFrame f) @Override
{ public void actionPerformed(ActionEvent event) {
this.item = LAF; if (item.getText().toLowerCase().contains("sys")) {
this.frame = f; try {
} UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
@Override new ExceptionInInitializerError("Erreur lors du changement de 'look and feel'").printStackTrace();
public void actionPerformed(ActionEvent event) System.err.print("Caused by ");
{ e.printStackTrace();
if (item.getText().toLowerCase().contains("sys")) }
{ SwingUtilities.updateComponentTreeUI(frame);
try } else if (item.getText().toLowerCase().contains("java")) {
{ try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
} } catch (Exception e) {
catch (Exception e) new ExceptionInInitializerError("Erreur lors du changement de 'look and feel'").printStackTrace();
{ System.err.print("Caused by ");
new ExceptionInInitializerError("Erreur lors du changement de 'look and feel'").printStackTrace(); e.printStackTrace();
System.err.print("Caused by "); }
e.printStackTrace(); SwingUtilities.updateComponentTreeUI(frame);
} } else if (item.getText().toLowerCase().contains("sombre")) {
SwingUtilities.updateComponentTreeUI(frame); try {
} UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
else if (item.getText().toLowerCase().contains("java")) } catch (Exception e) {
{ new ExceptionInInitializerError("Erreur lors du changement de 'look and feel'").printStackTrace();
try System.err.print("Caused by ");
{ e.printStackTrace();
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); }
} SwingUtilities.updateComponentTreeUI(frame);
catch (Exception e) }
{ }
new ExceptionInInitializerError("Erreur lors du changement de 'look and feel'").printStackTrace();
System.err.print("Caused by ");
e.printStackTrace();
}
SwingUtilities.updateComponentTreeUI(frame);
}
else if (item.getText().toLowerCase().contains("sombre"))
{
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
}
catch (Exception e)
{
new ExceptionInInitializerError("Erreur lors du changement de 'look and feel'").printStackTrace();
System.err.print("Caused by ");
e.printStackTrace();
}
SwingUtilities.updateComponentTreeUI(frame);
}
}
} }

View File

@ -9,42 +9,37 @@ import fr.ynerant.leveleditor.editor.Map;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
public class CollidMapMouseListener extends MouseAdapter public class CollidMapMouseListener extends MouseAdapter {
{ private final EditorFrame frame;
private final EditorFrame frame; private final CollidPanel panel;
private final CollidPanel panel;
public CollidMapMouseListener(CollidPanel panel, EditorFrame frame) public CollidMapMouseListener(CollidPanel panel, EditorFrame frame) {
{ this.frame = frame;
this.frame = frame; this.panel = panel;
this.panel = panel; }
}
public EditorFrame getFrame() public EditorFrame getFrame() {
{ return frame;
return frame; }
}
@Override @Override
public void mouseReleased(MouseEvent event) public void mouseReleased(MouseEvent event) {
{ Map map = getFrame().getMap();
Map map = getFrame().getMap();
int x = panel.getWidth() / 2 - map.getFont().getWidth(); int x = panel.getWidth() / 2 - map.getFont().getWidth();
int y = panel.getHeight() / 2 - map.getFont().getHeight(); int y = panel.getHeight() / 2 - map.getFont().getHeight();
Case c = null; 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 ((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 colIndex = c.getCollision().ordinal(); int newColIndex = colIndex + 1;
int newColIndex = colIndex + 1; if (newColIndex >= Collision.values().length)
if (newColIndex >= Collision.values().length) newColIndex = 0;
newColIndex = 0; Collision col = Collision.values()[newColIndex];
Collision col = Collision.values()[newColIndex]; Case n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), c.getCoucheThree(), col);
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); map.setCase((event.getX() - x + 2) / 34, (event.getY() - y + 2) / 34, n);
panel.repaint(); panel.repaint();
} }
} }
} }

View File

@ -12,15 +12,13 @@ import java.awt.event.ActionListener;
/** /**
* @author ÿnérant * @author ÿnérant
*/ */
public class CreateMapListener implements ActionListener public class CreateMapListener implements ActionListener {
{ /* !CodeTemplates.overridecomment.nonjd!
/* !CodeTemplates.overridecomment.nonjd! * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */
*/ @Override
@Override public void actionPerformed(ActionEvent event) {
public void actionPerformed(ActionEvent event) if (Main.launchEditMode())
{ MainFrame.getInstance().dispose();
if (Main.launchEditMode()) }
MainFrame.getInstance().dispose();
}
} }

View File

@ -8,87 +8,88 @@ import fr.ynerant.leveleditor.editor.MapPanel;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
public class MapMouseListener extends MouseAdapter public class MapMouseListener extends MouseAdapter {
{ private final EditorFrame frame;
private final EditorFrame frame; private final MapPanel panel;
private final MapPanel panel;
public MapMouseListener(MapPanel panel, EditorFrame frame) public MapMouseListener(MapPanel panel, EditorFrame frame) {
{ this.frame = frame;
this.frame = frame; this.panel = panel;
this.panel = panel; }
}
public EditorFrame getFrame() public EditorFrame getFrame() {
{ return frame;
return frame; }
}
@Override @Override
public void mouseClicked(MouseEvent event) public void mouseClicked(MouseEvent event) {
{ if (frame.getSelectedPaintingMode() == 0) {
if (frame.getSelectedPaintingMode() == 0) Map map = getFrame().getMap();
{
Map map = getFrame().getMap();
int x = panel.getWidth() / 2 - map.getFont().getWidth(); int x = panel.getWidth() / 2 - map.getFont().getWidth();
int y = panel.getHeight() / 2 - map.getFont().getHeight(); int y = panel.getHeight() / 2 - map.getFont().getHeight();
Case c = null; 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 ((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() != null) Case n;
{
Case n;
switch (getFrame().getSelectedSprite().getCouche()) switch (getFrame().getSelectedSprite().getCouche()) {
{ case 0:
case 0 : n = Case.create(c.getPosX(), c.getPosY(), getFrame().getSelectedSprite().getSprite(), c.getCoucheTwo(), c.getCoucheThree(), c.getCollision()); break; n = Case.create(c.getPosX(), c.getPosY(), getFrame().getSelectedSprite().getSprite(), c.getCoucheTwo(), c.getCoucheThree(), c.getCollision());
case 1 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), getFrame().getSelectedSprite().getSprite(), c.getCoucheThree(), c.getCollision()); break; break;
case 2 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), getFrame().getSelectedSprite().getSprite(), c.getCollision()); break; case 1:
default : n = c; break; 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); map.setCase(n.getPosX(), n.getPosY(), n);
panel.repaint(); panel.repaint();
} }
} }
} } else if (frame.getSelectedPaintingMode() == 1) {
else if (frame.getSelectedPaintingMode() == 1) for (Case c : getFrame().getMap().getAllCases()) {
{ Map map = getFrame().getMap();
for (Case c : getFrame().getMap().getAllCases())
{
Map map = getFrame().getMap();
if (getFrame().getSelectedSprite() != null) if (getFrame().getSelectedSprite() != null) {
{ if (getFrame().getSelectedSprite().getCouche() - 1 > getFrame().getSelectedLayerIndex())
if (getFrame().getSelectedSprite().getCouche() - 1 > getFrame().getSelectedLayerIndex()) return;
return;
Case n; Case n;
switch (getFrame().getSelectedSprite().getCouche()) switch (getFrame().getSelectedSprite().getCouche()) {
{ case 0:
case 0 : n = Case.create(c.getPosX(), c.getPosY(), getFrame().getSelectedSprite().getSprite(), c.getCoucheTwo(), c.getCoucheThree(), c.getCollision()); break; n = Case.create(c.getPosX(), c.getPosY(), getFrame().getSelectedSprite().getSprite(), c.getCoucheTwo(), c.getCoucheThree(), c.getCollision());
case 1 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), getFrame().getSelectedSprite().getSprite(), c.getCoucheThree(), c.getCollision()); break; break;
case 2 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), getFrame().getSelectedSprite().getSprite(), c.getCollision()); break; case 1:
default : n = c; break; 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); map.setCase(n.getPosX(), n.getPosY(), n);
} }
} }
panel.repaint(); panel.repaint();
} }
} }
@Override @Override
public void mouseDragged(MouseEvent event) public void mouseDragged(MouseEvent event) {
{ if (frame.getSelectedPaintingMode() == 0) {
if (frame.getSelectedPaintingMode() == 0) mouseClicked(event);
{ }
mouseClicked(event); }
}
}
} }

View File

@ -6,15 +6,13 @@ import fr.ynerant.leveleditor.frame.MainFrame;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
public class OpenMapListener implements ActionListener public class OpenMapListener implements ActionListener {
{ /* !CodeTemplates.overridecomment.nonjd!
/* !CodeTemplates.overridecomment.nonjd! * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */
*/ @Override
@Override public void actionPerformed(ActionEvent event) {
public void actionPerformed(ActionEvent event) if (EditorAPI.open() != null)
{ MainFrame.getInstance().dispose();
if (EditorAPI.open() != null) }
MainFrame.getInstance().dispose();
}
} }

View File

@ -6,27 +6,23 @@ import fr.ynerant.leveleditor.editor.SpriteComp;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
public class SpriteMouseListener extends MouseAdapter public class SpriteMouseListener extends MouseAdapter {
{ private final SpriteComp sprite;
private final SpriteComp sprite; private final EditorFrame frame;
private final EditorFrame frame;
public SpriteMouseListener(SpriteComp sprc, EditorFrame frame) public SpriteMouseListener(SpriteComp sprc, EditorFrame frame) {
{ this.sprite = sprc;
this.sprite = sprc; this.frame = frame;
this.frame = frame; }
}
@Override @Override
public void mouseReleased(MouseEvent event) public void mouseReleased(MouseEvent event) {
{ if (frame.getSelectedSprite() != null) {
if (frame.getSelectedSprite() != null) frame.getSelectedSprite().setSelected(false);
{ frame.getSelectedSprite().repaint();
frame.getSelectedSprite().setSelected(false); }
frame.getSelectedSprite().repaint(); frame.setSelectedSprite(sprite);
} sprite.setSelected(true);
frame.setSelectedSprite(sprite); sprite.repaint();
sprite.setSelected(true); }
sprite.repaint();
}
} }

View File

@ -1,85 +1,322 @@
{ {
"blank": [ "blank": [
[0,0] [
], 0,
"gazon": [ 0
[0,0], ]
[0,16], ],
[0,32], "gazon": [
[0,48], [
[0,64], 0,
[0,144], 0
[0,160], ],
[0,176], [
[16,144], 0,
[32,144], 16
[16,160], ],
[32,160], [
[32,224], 0,
[48,224], 32
[64,224], ],
[80,224], [
[96,224], 0,
[112,224], 48
[112,208], ],
[159,48], [
[160,166], 0,
[176,166], 64
[128,144], ],
[128,160], [
[144,80], 0,
[48,36], 144
[64,36], ],
[54,53], [
[70,53], 0,
[48,70], 160
[16,28], ],
[16,16], [
[16,32], 0,
[16,48], 176
[16,64], ],
[16,80], [
[32,16], 16,
[32,32], 144
[32,48], ],
[32,64], [
[32,80], 32,
[48,64], 144
[48,80], ],
[64,64], [
[64,80], 16,
[80,64], 160
[80,80], ],
[96,64], [
[96,80], 32,
[112,64], 160
[112,80], ],
[128,80], [
[128,64], 32,
[112,48], 224
[128,48], ],
[112,32], [
[128,32], 48,
[112,16], 224
[128,16], ],
[64,128], [
[80,128], 64,
[96,128], 224
[48,144], ],
[64,144], [
[80,144], 80,
[96,144], 224
[48,160], ],
[96,160], [
[48,176], 96,
[96,176], 224
[32,176], ],
[112,176], [
[64,160], 112,
[80,160], 224
[64,176], ],
[80,176], [
[64,192], 112,
[80,192] 208
] ],
[
159,
48
],
[
160,
166
],
[
176,
166
],
[
128,
144
],
[
128,
160
],
[
144,
80
],
[
48,
36
],
[
64,
36
],
[
54,
53
],
[
70,
53
],
[
48,
70
],
[
16,
28
],
[
16,
16
],
[
16,
32
],
[
16,
48
],
[
16,
64
],
[
16,
80
],
[
32,
16
],
[
32,
32
],
[
32,
48
],
[
32,
64
],
[
32,
80
],
[
48,
64
],
[
48,
80
],
[
64,
64
],
[
64,
80
],
[
80,
64
],
[
80,
80
],
[
96,
64
],
[
96,
80
],
[
112,
64
],
[
112,
80
],
[
128,
80
],
[
128,
64
],
[
112,
48
],
[
128,
48
],
[
112,
32
],
[
128,
32
],
[
112,
16
],
[
128,
16
],
[
64,
128
],
[
80,
128
],
[
96,
128
],
[
48,
144
],
[
64,
144
],
[
80,
144
],
[
96,
144
],
[
48,
160
],
[
96,
160
],
[
48,
176
],
[
96,
176
],
[
32,
176
],
[
112,
176
],
[
64,
160
],
[
80,
160
],
[
64,
176
],
[
80,
176
],
[
64,
192
],
[
80,
192
]
]
} }

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Configuration package="log4j.test" status="info"> <Configuration package="log4j.test" status="info">
<Loggers> <Loggers>
<Root level="info"> <Root level="info">
</Root> </Root>
</Loggers> </Loggers>
</Configuration> </Configuration>

View File

@ -7,31 +7,27 @@ import junit.framework.TestSuite;
/** /**
* Unit test for simple App. * Unit test for simple App.
*/ */
public class AppTest extends TestCase public class AppTest extends TestCase {
{
/** /**
* Create the test case * Create the test case
* *
* @param testName name of the test case * @param testName name of the test case
*/ */
public AppTest(String testName) public AppTest(String testName) {
{ super(testName);
super (testName);
} }
/** /**
* @return the suite of tests being tested * @return the suite of tests being tested
*/ */
public static Test suite() public static Test suite() {
{
return new TestSuite(AppTest.class); return new TestSuite(AppTest.class);
} }
/** /**
* Rigourous Test :-) * Rigourous Test :-)
*/ */
public void testApp() public void testApp() {
{
assertTrue(true); assertTrue(true);
} }
} }