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;
public class Case
{
private int x;
private int y;
private Sprite couche1;
private Sprite couche2;
private Sprite couche3;
private Collision collision;
public int getPosX()
{
return x;
}
public int getPosY()
{
return y;
}
public Sprite getCoucheOne()
{
return couche1;
}
public Sprite getCoucheTwo()
{
return couche2;
}
public Sprite getCoucheThree()
{
return couche3;
}
public Collision getCollision()
{
return collision;
}
public static Case create(int posX, int posY, Sprite couche1, Sprite couche2, Sprite couche3, Collision 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
public String toString()
{
return "{Case x=" + x + " y=" + y + " couche1=" + couche1 + " couche2=" + couche2 + " couche3=" + couche3 + " collision=" + collision.name().toUpperCase() + "}\n";
}
public class Case {
private int x;
private int y;
private Sprite couche1;
private Sprite couche2;
private Sprite couche3;
private Collision collision;
public static Case create(int posX, int posY, Sprite couche1, Sprite couche2, Sprite couche3, Collision 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;
}
public int getPosX() {
return x;
}
public int getPosY() {
return y;
}
public Sprite getCoucheOne() {
return couche1;
}
public Sprite getCoucheTwo() {
return couche2;
}
public Sprite getCoucheThree() {
return couche3;
}
public Collision getCollision() {
return collision;
}
@Override
public String toString() {
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;
public enum Collision
{
FULL, PARTIAL, ANY;
public enum Collision {
FULL, PARTIAL, ANY
}

View File

@ -1,191 +1,161 @@
package fr.ynerant.leveleditor.api.editor;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import fr.ynerant.leveleditor.editor.Map;
import java.awt.Color;
import java.awt.Graphics2D;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
public class EditorAPI {
private static File LAST_FILE;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public static RawMap toRawMap(int width, int height) {
List<RawCase> cases = new ArrayList<RawCase>();
public class EditorAPI
{
private static File LAST_FILE;
for (int y = 1; y < height; y += 16) {
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);
}
}
public static RawMap toRawMap(int width, int height)
{
List<RawCase> cases = new ArrayList<RawCase>();
for (int y = 1; y < height; y += 16)
{
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);
}
public static Gson createGson()
{
GsonBuilder builder = new GsonBuilder();
builder.enableComplexMapKeySerialization();
builder.serializeNulls();
builder.setPrettyPrinting();
return builder.create();
}
return RawMap.create(cases, width, height);
}
public static JFileChooser createJFC()
{
JFileChooser jfc = new JFileChooser();
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);
return jfc;
}
public static Gson createGson() {
GsonBuilder builder = new GsonBuilder();
public static void saveAs(RawMap map)
{
JFileChooser jfc = createJFC();
File file = null;
jfc.showSaveDialog(null);
file = jfc.getSelectedFile();
if (file == null)
return;
if (!file.getName().toLowerCase().endsWith(".gmap") && !file.getName().toLowerCase().endsWith(".dat"))
{
file = new File(file.getParentFile(), file.getName() + ".gmap");
}
LAST_FILE = file;
save(file, map);
}
public static void save(RawMap map)
{
if (LAST_FILE != null)
save(LAST_FILE, map);
else
saveAs(map);
}
public static void save(File file, RawMap map)
{
String json = createGson().toJson(map);
try
{
file.createNewFile();
BufferedOutputStream bos = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(file)));
bos.write(json.getBytes("UTF-8"));
bos.close();
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
public static Map open()
{
JFileChooser jfc = createJFC();
File file = null;
jfc.showOpenDialog(null);
file = jfc.getSelectedFile();
if (file == null)
return null;
LAST_FILE = file;
return open(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, "UTF-8");
}
gis.close();
bytes = null;
json = text;
}
catch (IOException e)
{
e.printStackTrace();
}
RawMap rm = createGson().fromJson(json, RawMap.class);
return open(rm);
}
builder.enableComplexMapKeySerialization();
builder.serializeNulls();
builder.setPrettyPrinting();
public static Map open(RawMap map)
{
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)
{
g.drawLine(0, y, width, y);
}
map.setFont(image);
}
return new Map(map);
}
return builder.create();
}
public static JFileChooser createJFC() {
JFileChooser jfc = new JFileChooser();
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);
return jfc;
}
public static void saveAs(RawMap map) {
JFileChooser jfc = createJFC();
File file = null;
jfc.showSaveDialog(null);
file = jfc.getSelectedFile();
if (file == null)
return;
if (!file.getName().toLowerCase().endsWith(".gmap") && !file.getName().toLowerCase().endsWith(".dat")) {
file = new File(file.getParentFile(), file.getName() + ".gmap");
}
LAST_FILE = file;
save(file, map);
}
public static void save(RawMap map) {
if (LAST_FILE != null)
save(LAST_FILE, map);
else
saveAs(map);
}
public static void save(File file, RawMap map) {
String json = createGson().toJson(map);
try {
file.createNewFile();
BufferedOutputStream bos = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(file)));
bos.write(json.getBytes(StandardCharsets.UTF_8));
bos.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
public static Map open() {
JFileChooser jfc = createJFC();
File file = null;
jfc.showOpenDialog(null);
file = jfc.getSelectedFile();
if (file == null)
return null;
LAST_FILE = file;
return open(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;
json = text;
} catch (IOException e) {
e.printStackTrace();
}
RawMap rm = createGson().fromJson(json, RawMap.class);
return open(rm);
}
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);
}
for (int y = 17; y <= height; y += 17) {
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;
public class RawCase
{
private int x;
private int y;
private RawSprite couche1;
private RawSprite couche2;
private RawSprite couche3;
private Collision collision;
public int getPosX()
{
return x;
}
public int getPosY()
{
return y;
}
public RawSprite getCoucheOne()
{
return couche1;
}
public RawSprite getCoucheTwo()
{
return couche2;
}
public RawSprite getCoucheThree()
{
return couche3;
}
public Collision getCollision()
{
return collision;
}
public static RawCase create(int posX, int posY, RawSprite couche1, RawSprite couche2, RawSprite couche3, Collision collision)
{
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)
{
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;
}
public class RawCase {
private int x;
private int y;
private RawSprite couche1;
private RawSprite couche2;
private RawSprite couche3;
private Collision collision;
public static RawCase create(int posX, int posY, RawSprite couche1, RawSprite couche2, RawSprite couche3, Collision collision) {
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) {
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;
}
public int getPosX() {
return x;
}
public int getPosY() {
return y;
}
public RawSprite getCoucheOne() {
return couche1;
}
public RawSprite getCoucheTwo() {
return couche2;
}
public RawSprite getCoucheThree() {
return couche3;
}
public Collision getCollision() {
return collision;
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -1,175 +1,135 @@
package fr.ynerant.leveleditor.api.editor.sprites;
import com.google.gson.Gson;
import fr.ynerant.leveleditor.client.main.Main;
import org.apache.logging.log4j.LogManager;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.*;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.jar.JarEntry;
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 Map<String, List<List<Double>>> nameToCoords;
private static Map<String, Category> sprites = new HashMap<String, Category>();
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, path.length());
File jarFile = new File(path);
private static void unpackDir(File dir) throws IOException {
for (File f : dir.listFiles()) {
if (f.isDirectory()) {
unpackDir(f);
continue;
}
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();
}
}
}
private static void unpackDir(File dir) throws IOException
{
for (File f : dir.listFiles())
{
if (f.isDirectory())
{
unpackDir(f);
continue;
}
String path = f.getAbsolutePath().substring(f.getAbsolutePath().indexOf(File.separatorChar + "assets") + 1);
File local = new File(path);
local.getParentFile().mkdirs();
if (local.exists())
local.delete();
Files.copy(Paths.get(f.toURI()), Paths.get(local.toURI()));
}
}
String path = f.getAbsolutePath().substring(f.getAbsolutePath().indexOf(File.separatorChar + "assets") + 1);
File local = new File(path);
local.getParentFile().mkdirs();
if (local.exists())
local.delete();
Files.copy(Paths.get(f.toURI()), Paths.get(local.toURI()));
}
}
@SuppressWarnings("unchecked")
public static void refreshAllSprites()
{
if (nameToCoords != null && !nameToCoords.isEmpty() && !sprites.isEmpty())
{
return;
}
File assetsDir = new File("assets");
List<String> assets = new ArrayList<String>();
for (File dir : assetsDir.listFiles())
{
assets.add(dir.getName());
}
for (String asset : assets)
{
try
{
File f = new File(assetsDir.getAbsolutePath() + "/" + asset + "/textures/sprites");
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())
{
try
{
BufferedInputStream is = new BufferedInputStream(new FileInputStream(new File(f, key + ".png")));
BufferedImage img = ImageIO.read(is);
Category cat = Category.create(key, new ArrayList<String>(nameToCoords.keySet()).indexOf(key), new ArrayList<Sprite>());
for (List<Double> list : nameToCoords.get(key))
{
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);
}
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)
{
return sprites.get(name);
}
public static Category getCategory(int index)
{
return getCategory(new ArrayList<String>(sprites.keySet()).get(index));
}
public static List<Category> getAllCategories()
{
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;
}
@SuppressWarnings("unchecked")
public static void refreshAllSprites() {
if (nameToCoords != null && !nameToCoords.isEmpty() && !sprites.isEmpty()) {
return;
}
File assetsDir = new File("assets");
List<String> assets = new ArrayList<String>();
for (File dir : assetsDir.listFiles()) {
assets.add(dir.getName());
}
for (String asset : assets) {
try {
File f = new File(assetsDir.getAbsolutePath() + "/" + asset + "/textures/sprites");
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()) {
try {
BufferedInputStream is = new BufferedInputStream(new FileInputStream(new File(f, key + ".png")));
BufferedImage img = ImageIO.read(is);
Category cat = Category.create(key, new ArrayList<String>(nameToCoords.keySet()).indexOf(key), new ArrayList<Sprite>());
for (List<Double> list : nameToCoords.get(key)) {
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);
} 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) {
return sprites.get(name);
}
public static Category getCategory(int index) {
return getCategory(new ArrayList<String>(sprites.keySet()).get(index));
}
public static List<Category> getAllCategories() {
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;
import fr.ynerant.leveleditor.frame.MainFrame;
import fr.ynerant.leveleditor.api.editor.EditorAPI;
import fr.ynerant.leveleditor.api.editor.RawMap;
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 java.awt.Desktop;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
@ -21,280 +26,232 @@ import java.net.URL;
import java.util.Locale;
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
*
* @author ÿnérant
* @see #main(String...)
*/
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.
* @see #isInDebugMode()
* @see #main(String...)
* @since 0.1-aplha
*/
private static boolean DEBUG;
/**
* Variable disant si le jeu est lanc&eacute; en d&eacute;veloppement ou non.
* @see #isInDevelopmentMode()
* @see #main(String...)
* @since 0.1-aplha
*/
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
* @see #launchEditMode()
* @since 0.1-alpha
*/
public static void main(String ... args)
{
System.setProperty("sun.java2d.noddraw", "true");
Locale.setDefault(Locale.FRANCE);
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e)
{
new ExceptionInInitializerError("Erreur lors du changement de 'look and feel'").printStackTrace();
System.err.print("Caused by ");
e.printStackTrace();
}
try
{
new File(Main.class.getResource("/assets").toURI());
DEV = true;
}
catch (Throwable t)
{
DEV = false;
}
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();
console.start();
LOGGER.addAppender(console);
LOGGER.setLevel(Level.INFO);
checkJava();
OptionParser parser = new OptionParser();
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<String> help = parser.accepts("help", "Affiche ce menu d'aide").withOptionalArg().forHelp();
OptionSet set = parser.parse(args);
if (set.has(help))
{
try
{
parser.printHelpOn(System.out);
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
System.exit(0);
}
}
if (set.has(debug))
{
DEBUG = set.valueOf(debug);
if (DEBUG)
{
LOGGER.setLevel(Level.ALL);
}
}
try
{
SpriteRegister.unpack();
}
catch (IOException | URISyntaxException e)
{
e.printStackTrace();
}
SpriteRegister.refreshAllSprites();
if (set.has(edit))
{
launchEditMode();
return;
}
launchFrame();
}
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.
*
* @see #isInDebugMode()
* @see #main(String...)
* @since 0.1-aplha
*/
private static boolean DEBUG;
private static void checkJava()
{
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 ...");
LogManager.getLogger("JAVAX-SWING").catching(Level.FATAL, ex);
System.exit(1);
}
try
{
Map.class.getDeclaredMethod("getOrDefault", Object.class, Object.class);
}
catch (NoSuchMethodException ex)
{
ex.printStackTrace();
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>");
try
{
if (Desktop.isDesktopSupported())
Desktop.getDesktop().browse(new URL("http://java.com/download").toURI());
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>");
}
catch (IOException | URISyntaxException e)
{
e.printStackTrace();
}
System.exit(1);
}
}
/**
* Variable disant si le jeu est lanc&eacute; en d&eacute;veloppement ou non.
*
* @see #isInDevelopmentMode()
* @see #main(String...)
* @since 0.1-aplha
*/
private static boolean DEV;
/**
* Lance la fen&ecirc;tre principale
* @see #main(String...)
* @see #launchEditMode()
*/
private static void launchFrame()
{
MainFrame.getInstance().setVisible(true);
}
/**
* @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()
* @since 0.1-alpha
*/
public static void main(String... args) {
System.setProperty("sun.java2d.noddraw", "true");
/**
* Permet de lancer l'&eacute;diteur de carte
* @return
* @see #main(String...)
* @see #launchFrame()
* @since 0.1-aplha
*/
public static boolean launchEditMode()
{
System.out.println("Lancement de l'\u00e9diteur de monde ...");
int baseWidth;
int baseHeight;
int width;
int height;
while (true)
{
try
{
String baseWidthStr = JOptionPane.showInputDialog(null, "Veuillez entrez le nombre de cases longueur de votre carte (0 pour annuler) :");
if (baseWidthStr == null)
return false;
baseWidth = Integer.parseInt(baseWidthStr) * 16;
if (baseWidth < 0)
throw new NumberFormatException();
if (baseWidth == 0)
return false;
break;
}
catch (NumberFormatException ex)
{
continue;
}
}
while (true)
{
try
{
String baseHeightStr = JOptionPane.showInputDialog("Veuillez entrez le nombre de cases hauteur de votre carte (0 pour annuler) :");
if (baseHeightStr == null)
return false;
baseHeight = Integer.parseInt(baseHeightStr) * 16;
if (baseHeight < 0)
throw new NumberFormatException();
if (baseHeight == 0)
return false;
break;
}
catch (NumberFormatException ex)
{
continue;
}
}
width = baseWidth + ((int) baseWidth / 16) + 1;
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)
{
g.drawLine(0, y, width, y);
}
RawMap rm = EditorAPI.toRawMap(baseWidth, baseHeight);
rm.setFont(image);
EditorAPI.open(rm);
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.
* @see #DEBUG
* @since 0.1-aplha
*/
public static boolean isInDebugMode()
{
return DEBUG;
}
Locale.setDefault(Locale.FRANCE);
/**
* Accesseur disant si le jeu est lanc&eacute; en d&eacute;veloppement ou non.
* @see #DEV
* @since 0.1-alpha
*/
public static boolean isInDevelopmentMode()
{
return DEV;
}
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
new ExceptionInInitializerError("Erreur lors du changement de 'look and feel'").printStackTrace();
System.err.print("Caused by ");
e.printStackTrace();
}
try {
new File(Main.class.getResource("/assets").toURI());
DEV = true;
} catch (Throwable t) {
DEV = false;
}
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();
console.start();
LOGGER.addAppender(console);
LOGGER.setLevel(Level.INFO);
checkJava();
OptionParser parser = new OptionParser();
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<String> help = parser.accepts("help", "Affiche ce menu d'aide").withOptionalArg().forHelp();
OptionSet set = parser.parse(args);
if (set.has(help)) {
try {
parser.printHelpOn(System.out);
} catch (IOException e) {
e.printStackTrace();
} finally {
System.exit(0);
}
}
if (set.has(debug)) {
DEBUG = set.valueOf(debug);
if (DEBUG) {
LOGGER.setLevel(Level.ALL);
}
}
try {
SpriteRegister.unpack();
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
SpriteRegister.refreshAllSprites();
if (set.has(edit)) {
launchEditMode();
return;
}
launchFrame();
}
private static void checkJava() {
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 ...");
LogManager.getLogger("JAVAX-SWING").catching(Level.FATAL, ex);
System.exit(1);
}
try {
Map.class.getDeclaredMethod("getOrDefault", Object.class, Object.class);
} catch (NoSuchMethodException ex) {
ex.printStackTrace();
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>");
try {
if (Desktop.isDesktopSupported())
Desktop.getDesktop().browse(new URL("http://java.com/download").toURI());
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>");
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
System.exit(1);
}
}
/**
* Lance la fen&ecirc;tre principale
*
* @see #main(String...)
* @see #launchEditMode()
*/
private static void launchFrame() {
MainFrame.getInstance().setVisible(true);
}
/**
* Permet de lancer l'&eacute;diteur de carte
*
* @return
* @see #main(String...)
* @see #launchFrame()
* @since 0.1-aplha
*/
public static boolean launchEditMode() {
System.out.println("Lancement de l'\u00e9diteur de monde ...");
int baseWidth;
int baseHeight;
int width;
int height;
while (true) {
try {
String baseWidthStr = JOptionPane.showInputDialog(null, "Veuillez entrez le nombre de cases longueur de votre carte (0 pour annuler) :");
if (baseWidthStr == null)
return false;
baseWidth = Integer.parseInt(baseWidthStr) * 16;
if (baseWidth < 0)
throw new NumberFormatException();
if (baseWidth == 0)
return false;
break;
} catch (NumberFormatException ex) {
continue;
}
}
while (true) {
try {
String baseHeightStr = JOptionPane.showInputDialog("Veuillez entrez le nombre de cases hauteur de votre carte (0 pour annuler) :");
if (baseHeightStr == null)
return false;
baseHeight = Integer.parseInt(baseHeightStr) * 16;
if (baseHeight < 0)
throw new NumberFormatException();
if (baseHeight == 0)
return false;
break;
} catch (NumberFormatException ex) {
continue;
}
}
width = baseWidth + (baseWidth / 16) + 1;
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);
}
for (int y = 17; y <= height; y += 17) {
g.drawLine(0, y, width, y);
}
RawMap rm = EditorAPI.toRawMap(baseWidth, baseHeight);
rm.setFont(image);
EditorAPI.open(rm);
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.
*
* @see #DEBUG
* @since 0.1-aplha
*/
public static boolean isInDebugMode() {
return DEBUG;
}
/**
* Accesseur disant si le jeu est lanc&eacute; en d&eacute;veloppement ou non.
*
* @see #DEV
* @since 0.1-alpha
*/
public static boolean isInDevelopmentMode() {
return DEV;
}
}

View File

@ -1,5 +1,7 @@
/**
* Ce package comprend uniquement la classe Main, qui lance l'application.
*
* @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.Collision;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.*;
import java.awt.*;
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 static final long serialVersionUID = -138754019431984881L;
private final EditorFrame frame;
public CollidPanel(EditorFrame frame)
{
super ();
this.frame = frame;
}
public EditorFrame getFrame()
{
return frame;
}
public Map getMap()
{
return frame.getMap();
}
@Override
public void paintComponent(Graphics g)
{
g.fillRect(0, 0, getWidth(), getHeight());
BufferedImage img = getMap().getFont();
int x = getWidth() / 2 - img.getWidth();
int y = getHeight() / 2 - img.getHeight();
int width = img.getWidth() * 2;
int height = img.getHeight() * 2;
g.drawImage(getMap().getFont(), x, y, width, height, null);
for (Case c : getMap().getAllCases())
{
if (isEmpty(c.getCoucheOne().getImage()))
continue;
g.drawImage(c.getCoucheOne().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
if (isEmpty(c.getCoucheTwo().getImage()))
continue;
g.drawImage(c.getCoucheTwo().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
if (isEmpty(c.getCoucheThree().getImage()))
continue;
g.drawImage(c.getCoucheThree().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
}
for (Case c : getMap().getAllCases())
{
if (c.getCollision() != Collision.ANY)
{
BufferedImage alpha = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
if (c.getCollision() == Collision.FULL)
{
Graphics2D grap = alpha.createGraphics();
grap.setColor(new Color(0, 0, 0, 100));
grap.fillRect(0, 0, 16, 16);
grap.dispose();
}
else if (c.getCollision() == Collision.PARTIAL)
{
Graphics2D grap = alpha.createGraphics();
grap.setColor(new Color(255, 0, 255, 70));
grap.fillRect(0, 0, 16, 16);
grap.dispose();
}
g.drawImage(alpha, x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
}
}
}
private final EditorFrame frame;
private boolean isEmpty(BufferedImage image)
{
int allrgba = 0;
for (int x = 0; x < image.getWidth(); ++x)
{
for (int y = 0; y < image.getHeight(); ++y)
{
allrgba += image.getRGB(x, y) + 1;
}
}
return allrgba == 0;
}
public CollidPanel(EditorFrame frame) {
super();
this.frame = frame;
}
public EditorFrame getFrame() {
return frame;
}
public Map getMap() {
return frame.getMap();
}
@Override
public void paintComponent(Graphics g) {
g.fillRect(0, 0, getWidth(), getHeight());
BufferedImage img = getMap().getFont();
int x = getWidth() / 2 - img.getWidth();
int y = getHeight() / 2 - img.getHeight();
int width = img.getWidth() * 2;
int height = img.getHeight() * 2;
g.drawImage(getMap().getFont(), x, y, width, height, null);
for (Case c : getMap().getAllCases()) {
if (isEmpty(c.getCoucheOne().getImage()))
continue;
g.drawImage(c.getCoucheOne().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
if (isEmpty(c.getCoucheTwo().getImage()))
continue;
g.drawImage(c.getCoucheTwo().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
if (isEmpty(c.getCoucheThree().getImage()))
continue;
g.drawImage(c.getCoucheThree().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
}
for (Case c : getMap().getAllCases()) {
if (c.getCollision() != Collision.ANY) {
BufferedImage alpha = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
if (c.getCollision() == Collision.FULL) {
Graphics2D grap = alpha.createGraphics();
grap.setColor(new Color(0, 0, 0, 100));
grap.fillRect(0, 0, 16, 16);
grap.dispose();
} else if (c.getCollision() == Collision.PARTIAL) {
Graphics2D grap = alpha.createGraphics();
grap.setColor(new Color(255, 0, 255, 70));
grap.fillRect(0, 0, 16, 16);
grap.dispose();
}
g.drawImage(alpha, x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null);
}
}
}
private boolean isEmpty(BufferedImage image) {
int allrgba = 0;
for (int x = 0; x < image.getWidth(); ++x) {
for (int y = 0; y < image.getHeight(); ++y) {
allrgba += image.getRGB(x, y) + 1;
}
}
return allrgba == 0;
}
}

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.Sprite;
import fr.ynerant.leveleditor.api.editor.sprites.SpriteRegister;
import fr.ynerant.leveleditor.frame.listeners.CollidMapMouseListener;
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 fr.ynerant.leveleditor.frame.listeners.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.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 static final long serialVersionUID = -2705122356101556462L;
public class EditorFrame extends JFrame implements ChangeListener, ActionListener, WindowListener
{
private static final long serialVersionUID = -2705122356101556462L;
private final Map map;
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");
ButtonGroup group = new ButtonGroup();
private final JRadioButtonMenuItem pen = new JRadioButtonMenuItem("Pinceau");
private final JRadioButtonMenuItem pot = new JRadioButtonMenuItem("Pot de peinture");
private final JTabbedPane tabs = new JTabbedPane();
private final JPanel tabEvents = new JPanel();
private final CollidPanel tabColl;
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;
private final Map map;
public EditorFrame(Map map)
{
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);
open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_DOWN_MASK, true));
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);
saveAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK + KeyEvent.SHIFT_DOWN_MASK, true));
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);
menuBar.add(fichier);
pen.setSelected(true);
pen.addActionListener(this);
pot.addActionListener(this);
group.add(pen);
group.add(pot);
selectionMode.add(pen);
selectionMode.add(pot);
private final JPanel content = new JPanel();
tools.setMnemonic(KeyEvent.VK_O + KeyEvent.ALT_DOWN_MASK);
tools.add(selectionMode);
menuBar.add(tools);
this.setJMenuBar(menuBar);
mapPanel = new MapPanel(this);
mapPanel.addMouseListener(new MapMouseListener(mapPanel, this));
mapPanel.addMouseMotionListener(new MapMouseListener(mapPanel, this));
tabColl = new CollidPanel(this);
tabColl.addMouseListener(new CollidMapMouseListener(tabColl, this));
tabColl.addMouseMotionListener(new CollidMapMouseListener(tabColl, this));
JScrollPane scrollMap = new JScrollPane(mapPanel);
scrollMap.getHorizontalScrollBar().setUnitIncrement(34);
scrollMap.getVerticalScrollBar().setUnitIncrement(34);
JScrollPane scrollCollidMap = new JScrollPane(tabColl);
scrollCollidMap.getHorizontalScrollBar().setUnitIncrement(34);
scrollCollidMap.getVerticalScrollBar().setUnitIncrement(34);
tabs.addTab("Carte", scrollMap);
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));
JScrollPane scroll1 = new JScrollPane(couche1, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
JScrollPane scroll2 = new JScrollPane(couche2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
JScrollPane scroll3 = new JScrollPane(couche3, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scroll1.getHorizontalScrollBar().setMaximum(0);
scroll2.getHorizontalScrollBar().setMaximum(0);
scroll3.getHorizontalScrollBar().setMaximum(0);
resources.addTab("", new ImageIcon(new File("assets/leveleditor/textures/layer 1.png").getAbsolutePath()), scroll1);
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();
drawResources();
revalidate();
repaint();
}
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 void drawResources()
{
couche1.removeAll();
couche2.removeAll();
couche3.removeAll();
if (couche1.getComponents().length > 0)
{
return;
}
if (couche1.getWidth() == 0 || couche2.getWidth() == 0 || couche3.getWidth() == 0)
{
couche1.repaint();
couche2.repaint();
couche3.repaint();
}
for (Category cat : SpriteRegister.getAllCategories())
{
for (Sprite spr : cat.getSprites())
{
SpriteComp sprc1 = new SpriteComp(spr, 0);
SpriteComp sprc2 = new SpriteComp(spr, 1);
SpriteComp sprc3 = new SpriteComp(spr, 2);
sprc1.addMouseListener(new SpriteMouseListener(sprc1, this));
sprc2.addMouseListener(new SpriteMouseListener(sprc2, this));
sprc3.addMouseListener(new SpriteMouseListener(sprc3, this));
couche1.add(sprc1);
couche2.add(sprc2);
couche3.add(sprc3);
}
}
couche1.revalidate();
couche2.revalidate();
couche3.revalidate();
couche1.repaint();
couche2.repaint();
couche3.repaint();
}
public void resize()
{
public EditorFrame(Map map) {
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);
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);
JScrollPane scroll1 = (JScrollPane) resources.getComponent(0);
JScrollPane scroll2 = (JScrollPane) resources.getComponent(1);
JScrollPane scroll3 = (JScrollPane) resources.getComponent(2);
scroll1.getHorizontalScrollBar().setMaximum(0);
scroll2.getHorizontalScrollBar().setMaximum(0);
scroll3.getHorizontalScrollBar().setMaximum(0);
drawResources();
((JScrollPane) resources.getSelectedComponent()).getVerticalScrollBar().setValue(cursorPos);
}
fichier.setMnemonic(KeyEvent.VK_F + KeyEvent.ALT_DOWN_MASK);
public Map getMap()
{
return map;
}
nouveau.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_DOWN_MASK, true));
nouveau.addActionListener(new CreateMapListener());
fichier.add(nouveau);
public SpriteComp getSelectedSprite()
{
return selectedSprite;
}
open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_DOWN_MASK, true));
open.addActionListener(new OpenMapListener());
fichier.add(open);
public void setSelectedSprite(SpriteComp sprite)
{
this.selectedSprite = sprite;
}
fichier.addSeparator();
@Override
public void stateChanged(ChangeEvent event)
{
if (event.getSource() == resources)
{
if (getSelectedLayerIndex() == 0)
{
resources.setBackgroundAt(0, Color.white);
resources.setBackgroundAt(1, Color.white);
resources.setBackgroundAt(2, Color.white);
}
else if (getSelectedLayerIndex() == 1)
{
resources.setBackgroundAt(0, Color.black);
resources.setBackgroundAt(1, Color.white);
resources.setBackgroundAt(2, Color.white);
}
else if (getSelectedLayerIndex() == 2)
{
resources.setBackgroundAt(0, Color.black);
resources.setBackgroundAt(1, Color.black);
resources.setBackgroundAt(2, Color.white);
}
repaint();
}
else if (event.getSource() == tabs)
{
resources.setEnabled(tabs.getSelectedIndex() == 0);
couche1.setEnabled(resources.isEnabled());
couche2.setEnabled(resources.isEnabled());
couche3.setEnabled(resources.isEnabled());
repaint();
}
}
save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK, true));
save.addActionListener(this);
fichier.add(save);
public int getSelectedLayerIndex()
{
return resources.getSelectedIndex();
}
saveAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK + KeyEvent.SHIFT_DOWN_MASK, true));
saveAs.addActionListener(this);
fichier.add(saveAs);
@Override
public void actionPerformed(ActionEvent event)
{
if (event.getSource() == save)
{
EditorAPI.save(RawMap.create(map));
}
else if (event.getSource() == saveAs)
{
EditorAPI.saveAs(RawMap.create(map));
}
else if (event.getSource() == exit)
{
int result = JOptionPane.showConfirmDialog(null, "Voulez-vous sauvegarder votre carte avant de quitter ? Toute modification sera perdue", "Confirmation", JOptionPane.YES_NO_CANCEL_OPTION);
if (result == 0)
save.doClick();
if (result != 2)
dispose();
}
}
public int getSelectedPaintingMode()
{
return pen.isSelected() ? 0 : pot.isSelected() ? 1 : -1;
}
fichier.addSeparator();
@Override
public void windowActivated(WindowEvent event)
{
}
exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, KeyEvent.CTRL_DOWN_MASK, true));
exit.addActionListener(this);
fichier.add(exit);
@Override
public void windowClosed(WindowEvent event)
{
}
menuBar.add(fichier);
@Override
public void windowClosing(WindowEvent event)
{
int result = JOptionPane.showConfirmDialog(null, "Voulez-vous sauvegarder avant de quitter ?", "Confirmation", JOptionPane.YES_NO_CANCEL_OPTION);
if (result == 0)
{
EditorAPI.save(RawMap.create(map));
}
if (result != 2)
{
dispose();
}
}
pen.setSelected(true);
pen.addActionListener(this);
pot.addActionListener(this);
group.add(pen);
group.add(pot);
selectionMode.add(pen);
selectionMode.add(pot);
@Override
public void windowDeactivated(WindowEvent event)
{
}
tools.setMnemonic(KeyEvent.VK_O + KeyEvent.ALT_DOWN_MASK);
@Override
public void windowDeiconified(WindowEvent event)
{
}
tools.add(selectionMode);
@Override
public void windowIconified(WindowEvent event)
{
}
menuBar.add(tools);
@Override
public void windowOpened(WindowEvent event)
{
}
this.setJMenuBar(menuBar);
mapPanel = new MapPanel(this);
mapPanel.addMouseListener(new MapMouseListener(mapPanel, this));
mapPanel.addMouseMotionListener(new MapMouseListener(mapPanel, this));
tabColl = new CollidPanel(this);
tabColl.addMouseListener(new CollidMapMouseListener(tabColl, this));
tabColl.addMouseMotionListener(new CollidMapMouseListener(tabColl, this));
JScrollPane scrollMap = new JScrollPane(mapPanel);
scrollMap.getHorizontalScrollBar().setUnitIncrement(34);
scrollMap.getVerticalScrollBar().setUnitIncrement(34);
JScrollPane scrollCollidMap = new JScrollPane(tabColl);
scrollCollidMap.getHorizontalScrollBar().setUnitIncrement(34);
scrollCollidMap.getVerticalScrollBar().setUnitIncrement(34);
tabs.addTab("Carte", scrollMap);
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));
JScrollPane scroll1 = new JScrollPane(couche1, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
JScrollPane scroll2 = new JScrollPane(couche2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
JScrollPane scroll3 = new JScrollPane(couche3, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scroll1.getHorizontalScrollBar().setMaximum(0);
scroll2.getHorizontalScrollBar().setMaximum(0);
scroll3.getHorizontalScrollBar().setMaximum(0);
resources.addTab("", new ImageIcon(new File("assets/leveleditor/textures/layer 1.png").getAbsolutePath()), scroll1);
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();
drawResources();
revalidate();
repaint();
}
private void drawResources() {
couche1.removeAll();
couche2.removeAll();
couche3.removeAll();
if (couche1.getComponents().length > 0) {
return;
}
if (couche1.getWidth() == 0 || couche2.getWidth() == 0 || couche3.getWidth() == 0) {
couche1.repaint();
couche2.repaint();
couche3.repaint();
}
for (Category cat : SpriteRegister.getAllCategories()) {
for (Sprite spr : cat.getSprites()) {
SpriteComp sprc1 = new SpriteComp(spr, 0);
SpriteComp sprc2 = new SpriteComp(spr, 1);
SpriteComp sprc3 = new SpriteComp(spr, 2);
sprc1.addMouseListener(new SpriteMouseListener(sprc1, this));
sprc2.addMouseListener(new SpriteMouseListener(sprc2, this));
sprc3.addMouseListener(new SpriteMouseListener(sprc3, this));
couche1.add(sprc1);
couche2.add(sprc2);
couche3.add(sprc3);
}
}
couche1.revalidate();
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);
JScrollPane scroll1 = (JScrollPane) resources.getComponent(0);
JScrollPane scroll2 = (JScrollPane) resources.getComponent(1);
JScrollPane scroll3 = (JScrollPane) resources.getComponent(2);
scroll1.getHorizontalScrollBar().setMaximum(0);
scroll2.getHorizontalScrollBar().setMaximum(0);
scroll3.getHorizontalScrollBar().setMaximum(0);
drawResources();
((JScrollPane) resources.getSelectedComponent()).getVerticalScrollBar().setValue(cursorPos);
}
public Map getMap() {
return map;
}
public SpriteComp getSelectedSprite() {
return selectedSprite;
}
public void setSelectedSprite(SpriteComp sprite) {
this.selectedSprite = sprite;
}
@Override
public void stateChanged(ChangeEvent event) {
if (event.getSource() == resources) {
if (getSelectedLayerIndex() == 0) {
resources.setBackgroundAt(0, Color.white);
resources.setBackgroundAt(1, Color.white);
resources.setBackgroundAt(2, Color.white);
} else if (getSelectedLayerIndex() == 1) {
resources.setBackgroundAt(0, Color.black);
resources.setBackgroundAt(1, Color.white);
resources.setBackgroundAt(2, Color.white);
} else if (getSelectedLayerIndex() == 2) {
resources.setBackgroundAt(0, Color.black);
resources.setBackgroundAt(1, Color.black);
resources.setBackgroundAt(2, Color.white);
}
repaint();
} 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();
}
@Override
public void actionPerformed(ActionEvent event) {
if (event.getSource() == save) {
EditorAPI.save(RawMap.create(map));
} else if (event.getSource() == saveAs) {
EditorAPI.saveAs(RawMap.create(map));
} else if (event.getSource() == exit) {
int result = JOptionPane.showConfirmDialog(null, "Voulez-vous sauvegarder votre carte avant de quitter ? Toute modification sera perdue", "Confirmation", JOptionPane.YES_NO_CANCEL_OPTION);
if (result == 0)
save.doClick();
if (result != 2)
dispose();
}
}
public int getSelectedPaintingMode() {
return pen.isSelected() ? 0 : pot.isSelected() ? 1 : -1;
}
@Override
public void windowActivated(WindowEvent event) {
}
@Override
public void windowClosed(WindowEvent event) {
}
@Override
public void windowClosing(WindowEvent event) {
int result = JOptionPane.showConfirmDialog(null, "Voulez-vous sauvegarder avant de quitter ?", "Confirmation", JOptionPane.YES_NO_CANCEL_OPTION);
if (result == 0) {
EditorAPI.save(RawMap.create(map));
}
if (result != 2) {
dispose();
}
}
@Override
public void windowDeactivated(WindowEvent event) {
}
@Override
public void windowDeiconified(WindowEvent event) {
}
@Override
public void windowIconified(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.List;
public class Map
{
@Deprecated
private static List<Case> cases;
private final EditorFrame frame;
private int width;
private int height;
private java.util.Map<Integer, java.util.Map<Integer, Case>> casesMap = new HashMap<Integer, java.util.Map<Integer, Case>>();
private transient BufferedImage font;
public Map(RawMap raw)
{
cases = new ArrayList<Case>();
this.width = raw.getWidth();
this.height = raw.getHeight();
this.font = raw.getFont();
for (RawCase rc : raw.getCases())
{
cases.add(Case.create(rc.getPosX(), rc.getPosY(), SpriteRegister.getCategory(rc.getCoucheOne().getCategory()).getSprites().get(rc.getCoucheOne().getIndex()), SpriteRegister.getCategory(rc.getCoucheTwo().getCategory()).getSprites().get(rc.getCoucheTwo().getIndex()), SpriteRegister.getCategory(rc.getCoucheThree().getCategory()).getSprites().get(rc.getCoucheThree().getIndex()), rc.getCollision()));
}
reorganizeMap();
frame = new EditorFrame(this);
getFrame().setVisible(true);
}
public EditorFrame getFrame()
{
return frame;
}
public int getWidth()
{
return width;
}
public int getHeight()
{
return height;
}
public Case getCase(int x, int y)
{
return casesMap.getOrDefault(x, new HashMap<Integer, Case>()).get(y);
}
public void setCase(int x, int y, Case c)
{
casesMap.get(x).put(y, c);
}
public class Map {
@Deprecated
private static List<Case> cases;
private final EditorFrame frame;
private int width;
private int height;
private java.util.Map<Integer, java.util.Map<Integer, Case>> casesMap = new HashMap<Integer, java.util.Map<Integer, Case>>();
private transient BufferedImage font;
public BufferedImage getFont()
{
return font;
}
public Map(RawMap raw) {
cases = new ArrayList<Case>();
this.width = raw.getWidth();
this.height = raw.getHeight();
this.font = raw.getFont();
public void setFont(BufferedImage font)
{
this.font = font;
}
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()));
}
private void reorganizeMap()
{
for (int i = 0; i < width; ++i)
{
casesMap.put(i, new HashMap<Integer, Case>());
}
for (Case c : cases)
{
setCase(c.getPosX(), c.getPosY(), c);
}
}
reorganizeMap();
public List<Case> getAllCases()
{
List<Case> list = new ArrayList<Case>();
for (java.util.Map<Integer, Case> l : casesMap.values())
{
list.addAll(l.values());
}
return list;
}
frame = new EditorFrame(this);
getFrame().setVisible(true);
}
public EditorFrame getFrame() {
return frame;
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public Case getCase(int x, int y) {
return casesMap.getOrDefault(x, new HashMap<Integer, Case>()).get(y);
}
public void setCase(int x, int y, Case c) {
casesMap.get(x).put(y, c);
}
public BufferedImage getFont() {
return font;
}
public void setFont(BufferedImage font) {
this.font = font;
}
private void reorganizeMap() {
for (int i = 0; i < width; ++i) {
casesMap.put(i, new HashMap<Integer, Case>());
}
for (Case c : cases) {
setCase(c.getPosX(), c.getPosY(), c);
}
}
public List<Case> getAllCases() {
List<Case> list = new ArrayList<Case>();
for (java.util.Map<Integer, Case> l : casesMap.values()) {
list.addAll(l.values());
}
return list;
}
}

View File

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

View File

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

View File

@ -1,112 +1,96 @@
package fr.ynerant.leveleditor.editor;
import javax.swing.*;
import java.awt.*;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
public class WrapLayout extends FlowLayout
{
private static final long serialVersionUID = 8777237960365591646L;
public WrapLayout()
{
super();
}
public WrapLayout(int align)
{
super(align);
}
public WrapLayout(int align, int hgap, int vgap)
{
super(align, hgap, vgap);
}
@Override
public Dimension preferredLayoutSize(Container target)
{
return layoutSize(target, true);
}
@Override
public Dimension minimumLayoutSize(Container target)
{
Dimension minimum = layoutSize(target, false);
minimum.width -= (getHgap() + 1);
return minimum;
}
private Dimension layoutSize(Container target, boolean preferred)
{
synchronized (target.getTreeLock())
{
int targetWidth = target.getSize().width;
if (targetWidth == 0)
targetWidth = Integer.MAX_VALUE;
int hgap = getHgap();
int vgap = getVgap();
Insets insets = target.getInsets();
int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2);
int maxWidth = targetWidth - horizontalInsetsAndGap;
Dimension dim = new Dimension(0, 0);
int rowWidth = 0;
int rowHeight = 0;
int nmembers = target.getComponentCount();
for (int i = 0; i < nmembers; i++)
{
Component m = target.getComponent(i);
if (m.isVisible())
{
Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize();
if (rowWidth + d.width > maxWidth)
{
addRow(dim, rowWidth, rowHeight);
rowWidth = 0;
rowHeight = 0;
}
if (rowWidth != 0)
{
rowWidth += hgap;
}
rowWidth += d.width;
rowHeight = Math.max(rowHeight, d.height);
}
}
addRow(dim, rowWidth, rowHeight);
dim.width += horizontalInsetsAndGap;
dim.height += insets.top + insets.bottom + vgap * 2;
Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target);
if (scrollPane != null)
{
dim.width -= (hgap + 1);
}
return dim;
}
}
private void addRow(Dimension dim, int rowWidth, int rowHeight)
{
dim.width = Math.max(dim.width, rowWidth);
if (dim.height > 0)
{
dim.height += getVgap();
}
dim.height += rowHeight;
}
public class WrapLayout extends FlowLayout {
private static final long serialVersionUID = 8777237960365591646L;
public WrapLayout() {
super();
}
public WrapLayout(int align) {
super(align);
}
public WrapLayout(int align, int hgap, int vgap) {
super(align, hgap, vgap);
}
@Override
public Dimension preferredLayoutSize(Container target) {
return layoutSize(target, true);
}
@Override
public Dimension minimumLayoutSize(Container target) {
Dimension minimum = layoutSize(target, false);
minimum.width -= (getHgap() + 1);
return minimum;
}
private Dimension layoutSize(Container target, boolean preferred) {
synchronized (target.getTreeLock()) {
int targetWidth = target.getSize().width;
if (targetWidth == 0)
targetWidth = Integer.MAX_VALUE;
int hgap = getHgap();
int vgap = getVgap();
Insets insets = target.getInsets();
int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2);
int maxWidth = targetWidth - horizontalInsetsAndGap;
Dimension dim = new Dimension(0, 0);
int rowWidth = 0;
int rowHeight = 0;
int nmembers = target.getComponentCount();
for (int i = 0; i < nmembers; i++) {
Component m = target.getComponent(i);
if (m.isVisible()) {
Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize();
if (rowWidth + d.width > maxWidth) {
addRow(dim, rowWidth, rowHeight);
rowWidth = 0;
rowHeight = 0;
}
if (rowWidth != 0) {
rowWidth += hgap;
}
rowWidth += d.width;
rowHeight = Math.max(rowHeight, d.height);
}
}
addRow(dim, rowWidth, rowHeight);
dim.width += horizontalInsetsAndGap;
dim.height += insets.top + insets.bottom + vgap * 2;
Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target);
if (scrollPane != null) {
dim.width -= (hgap + 1);
}
return dim;
}
}
private void addRow(Dimension dim, int rowWidth, int rowHeight) {
dim.width = Math.max(dim.width, rowWidth);
if (dim.height > 0) {
dim.height += getVgap();
}
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.CreateMapListener;
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.core.Logger;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
/**
* Fen&ecirc;tre principale du jeu
*
* @author ÿnérant
*/
public class MainFrame extends JFrame
{
/**
* ID de s&eacute;rie
* @see {@link JFrame}
*/
private static final long serialVersionUID = -3168760121879418534L;
/**
* Instance unique principale
* @see #MainFrame()
* @see #getInstance()
*/
private static MainFrame INSTANCE;
/**
* Logger de la classe
* @see LogManager#getLogger(String)
*/
private static Logger LOGGER = (Logger) LogManager.getLogger("MainFrame");
public class MainFrame extends JFrame {
/**
* ID de s&eacute;rie
*
* @see {@link JFrame}
*/
private static final long serialVersionUID = -3168760121879418534L;
private JMenuBar menuBar = new JMenuBar();
private JMenu fichier = new JMenu("Fichier");
private JMenu display = new JMenu("Affichage");
private JMenu editMaps = new JMenu("Cartes");
private JMenu changeLAF = new JMenu("Modfier l'apparence");
private JMenuItem createMap = new JMenuItem("Cr\u00e9er");
private JMenuItem openMap = new JMenuItem("Ouvrir");
private JMenuItem systemLAF = new JMenuItem("Apparence syst\u00e8me");
private JMenuItem javaLAF = new JMenuItem("Apparence Java");
private JMenuItem darkLAF = new JMenuItem("Apparence sombre");
/**
* Instance unique principale
*
* @see #MainFrame()
* @see #getInstance()
*/
private static MainFrame INSTANCE;
/**
* Constructeur
* @see Main#launchFrame()
*/
@SuppressWarnings("JavadocReference")
private MainFrame()
{
super ();
LOGGER.info("Initialisation de la fen\u00eatre");
this.setTitle("Alice Game Engine");
this.setPreferredSize(new Dimension(1000, 800));
this.setSize(800, 700);
this.setLocationRelativeTo(null);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fichier.setMnemonic(KeyEvent.VK_F + KeyEvent.ALT_DOWN_MASK);
display.setMnemonic(KeyEvent.VK_A + KeyEvent.ALT_DOWN_MASK);
createMap.addActionListener(new CreateMapListener());
editMaps.add(createMap);
openMap.addActionListener(new OpenMapListener());
editMaps.add(openMap);
fichier.add(editMaps);
systemLAF.addActionListener(new ChangeLAFListener(systemLAF, this));
changeLAF.add(systemLAF);
javaLAF.addActionListener(new ChangeLAFListener(javaLAF, this));
changeLAF.add(javaLAF);
darkLAF.addActionListener(new ChangeLAFListener(darkLAF, this));
changeLAF.add(darkLAF);
display.add(changeLAF);
/**
* Logger de la classe
*
* @see LogManager#getLogger(String)
*/
private static Logger LOGGER = (Logger) LogManager.getLogger("MainFrame");
menuBar.add(fichier);
menuBar.add(display);
this.setJMenuBar(menuBar);
}
/**
* Cet accesseur renvoie l'accesseur unique de la classe
* @see #INSTANCE
* @see #MainFrame()
* @return l'instance unique de la classe
*/
public static MainFrame getInstance()
{
if (INSTANCE == null)
return INSTANCE = new MainFrame();
return INSTANCE;
}
private JMenuBar menuBar = new JMenuBar();
private JMenu fichier = new JMenu("Fichier");
private JMenu display = new JMenu("Affichage");
private JMenu editMaps = new JMenu("Cartes");
private JMenu changeLAF = new JMenu("Modfier l'apparence");
private JMenuItem createMap = new JMenuItem("Cr\u00e9er");
private JMenuItem openMap = new JMenuItem("Ouvrir");
private JMenuItem systemLAF = new JMenuItem("Apparence syst\u00e8me");
private JMenuItem javaLAF = new JMenuItem("Apparence Java");
private JMenuItem darkLAF = new JMenuItem("Apparence sombre");
/**
* Constructeur
*
* @see Main#launchFrame()
*/
@SuppressWarnings("JavadocReference")
private MainFrame() {
super();
LOGGER.info("Initialisation de la fen\u00eatre");
this.setTitle("Alice Game Engine");
this.setPreferredSize(new Dimension(1000, 800));
this.setSize(800, 700);
this.setLocationRelativeTo(null);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fichier.setMnemonic(KeyEvent.VK_F + KeyEvent.ALT_DOWN_MASK);
display.setMnemonic(KeyEvent.VK_A + KeyEvent.ALT_DOWN_MASK);
createMap.addActionListener(new CreateMapListener());
editMaps.add(createMap);
openMap.addActionListener(new OpenMapListener());
editMaps.add(openMap);
fichier.add(editMaps);
systemLAF.addActionListener(new ChangeLAFListener(systemLAF, this));
changeLAF.add(systemLAF);
javaLAF.addActionListener(new ChangeLAFListener(javaLAF, this));
changeLAF.add(javaLAF);
darkLAF.addActionListener(new ChangeLAFListener(darkLAF, this));
changeLAF.add(darkLAF);
display.add(changeLAF);
menuBar.add(fichier);
menuBar.add(display);
this.setJMenuBar(menuBar);
}
/**
* Cet accesseur renvoie l'accesseur unique de la classe
*
* @return l'instance unique de la classe
* @see #INSTANCE
* @see #MainFrame()
*/
public static MainFrame getInstance() {
if (INSTANCE == null)
return INSTANCE = new MainFrame();
return INSTANCE;
}
}

View File

@ -2,69 +2,48 @@ package fr.ynerant.leveleditor.frame.listeners;
import fr.ynerant.leveleditor.frame.MainFrame;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
public class ChangeLAFListener implements ActionListener {
private final JMenuItem item;
private final JFrame frame;
public class ChangeLAFListener implements ActionListener
{
private final JMenuItem item;
private final JFrame frame;
public ChangeLAFListener(JMenuItem LAF, MainFrame f)
{
this.item = LAF;
this.frame = f;
}
@Override
public void actionPerformed(ActionEvent event)
{
if (item.getText().toLowerCase().contains("sys"))
{
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
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("java"))
{
try
{
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}
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);
}
}
public ChangeLAFListener(JMenuItem LAF, MainFrame f) {
this.item = LAF;
this.frame = f;
}
@Override
public void actionPerformed(ActionEvent event) {
if (item.getText().toLowerCase().contains("sys")) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} 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("java")) {
try {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
} 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.MouseEvent;
public class CollidMapMouseListener extends MouseAdapter
{
private final EditorFrame frame;
private final CollidPanel panel;
public CollidMapMouseListener(CollidPanel panel, EditorFrame frame)
{
this.frame = frame;
this.panel = panel;
}
public class CollidMapMouseListener extends MouseAdapter {
private final EditorFrame frame;
private final CollidPanel panel;
public EditorFrame getFrame()
{
return frame;
}
@Override
public void mouseReleased(MouseEvent event)
{
Map map = getFrame().getMap();
public CollidMapMouseListener(CollidPanel panel, EditorFrame frame) {
this.frame = frame;
this.panel = panel;
}
int x = panel.getWidth() / 2 - map.getFont().getWidth();
int y = panel.getHeight() / 2 - map.getFont().getHeight();
Case c = null;
if ((c = map.getCase((event.getX() - x + 2) / 34, (event.getY() - y + 2) / 34)) != null && event.getX() - x >= 2 && event.getY() - y >= 2)
{
int colIndex = c.getCollision().ordinal();
int newColIndex = colIndex + 1;
if (newColIndex >= Collision.values().length)
newColIndex = 0;
Collision col = Collision.values()[newColIndex];
Case n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), c.getCoucheThree(), col);
map.setCase((event.getX() - x + 2) / 34, (event.getY() - y + 2) / 34, n);
panel.repaint();
}
}
public EditorFrame getFrame() {
return frame;
}
@Override
public void mouseReleased(MouseEvent event) {
Map map = getFrame().getMap();
int x = panel.getWidth() / 2 - map.getFont().getWidth();
int y = panel.getHeight() / 2 - map.getFont().getHeight();
Case c = null;
if ((c = map.getCase((event.getX() - x + 2) / 34, (event.getY() - y + 2) / 34)) != null && event.getX() - x >= 2 && event.getY() - y >= 2) {
int colIndex = c.getCollision().ordinal();
int newColIndex = colIndex + 1;
if (newColIndex >= Collision.values().length)
newColIndex = 0;
Collision col = Collision.values()[newColIndex];
Case n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), c.getCoucheThree(), col);
map.setCase((event.getX() - x + 2) / 34, (event.getY() - y + 2) / 34, n);
panel.repaint();
}
}
}

View File

@ -12,15 +12,13 @@ import java.awt.event.ActionListener;
/**
* @author ÿnérant
*/
public class CreateMapListener implements ActionListener
{
/* !CodeTemplates.overridecomment.nonjd!
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
@Override
public void actionPerformed(ActionEvent event)
{
if (Main.launchEditMode())
MainFrame.getInstance().dispose();
}
public class CreateMapListener implements ActionListener {
/* !CodeTemplates.overridecomment.nonjd!
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
@Override
public void actionPerformed(ActionEvent event) {
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.MouseEvent;
public class MapMouseListener extends MouseAdapter
{
private final EditorFrame frame;
private final MapPanel panel;
public MapMouseListener(MapPanel panel, EditorFrame frame)
{
this.frame = frame;
this.panel = panel;
}
public class MapMouseListener extends MouseAdapter {
private final EditorFrame frame;
private final MapPanel panel;
public EditorFrame getFrame()
{
return frame;
}
@Override
public void mouseClicked(MouseEvent event)
{
if (frame.getSelectedPaintingMode() == 0)
{
Map map = getFrame().getMap();
public MapMouseListener(MapPanel panel, EditorFrame frame) {
this.frame = frame;
this.panel = panel;
}
int x = panel.getWidth() / 2 - map.getFont().getWidth();
int y = panel.getHeight() / 2 - map.getFont().getHeight();
Case c = null;
if ((c = map.getCase((event.getX() - x + 2) / 34, (event.getY() - y + 2) / 34)) != null && event.getX() - x >= 2 && event.getY() - y >= 2)
{
if (getFrame().getSelectedSprite() != null)
{
Case n;
switch (getFrame().getSelectedSprite().getCouche())
{
case 0 : n = Case.create(c.getPosX(), c.getPosY(), getFrame().getSelectedSprite().getSprite(), c.getCoucheTwo(), c.getCoucheThree(), c.getCollision()); break;
case 1 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), getFrame().getSelectedSprite().getSprite(), c.getCoucheThree(), c.getCollision()); break;
case 2 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), getFrame().getSelectedSprite().getSprite(), c.getCollision()); break;
default : n = c; break;
}
map.setCase(n.getPosX(), n.getPosY(), n);
panel.repaint();
}
}
}
else if (frame.getSelectedPaintingMode() == 1)
{
for (Case c : getFrame().getMap().getAllCases())
{
Map map = getFrame().getMap();
if (getFrame().getSelectedSprite() != null)
{
if (getFrame().getSelectedSprite().getCouche() - 1 > getFrame().getSelectedLayerIndex())
return;
Case n;
switch (getFrame().getSelectedSprite().getCouche())
{
case 0 : n = Case.create(c.getPosX(), c.getPosY(), getFrame().getSelectedSprite().getSprite(), c.getCoucheTwo(), c.getCoucheThree(), c.getCollision()); break;
case 1 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), getFrame().getSelectedSprite().getSprite(), c.getCoucheThree(), c.getCollision()); break;
case 2 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), getFrame().getSelectedSprite().getSprite(), c.getCollision()); break;
default : n = c; break;
}
map.setCase(n.getPosX(), n.getPosY(), n);
}
}
panel.repaint();
}
}
@Override
public void mouseDragged(MouseEvent event)
{
if (frame.getSelectedPaintingMode() == 0)
{
mouseClicked(event);
}
}
public EditorFrame getFrame() {
return frame;
}
@Override
public void mouseClicked(MouseEvent event) {
if (frame.getSelectedPaintingMode() == 0) {
Map map = getFrame().getMap();
int x = panel.getWidth() / 2 - map.getFont().getWidth();
int y = panel.getHeight() / 2 - map.getFont().getHeight();
Case c = null;
if ((c = map.getCase((event.getX() - x + 2) / 34, (event.getY() - y + 2) / 34)) != null && event.getX() - x >= 2 && event.getY() - y >= 2) {
if (getFrame().getSelectedSprite() != null) {
Case n;
switch (getFrame().getSelectedSprite().getCouche()) {
case 0:
n = Case.create(c.getPosX(), c.getPosY(), getFrame().getSelectedSprite().getSprite(), c.getCoucheTwo(), c.getCoucheThree(), c.getCollision());
break;
case 1:
n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), getFrame().getSelectedSprite().getSprite(), c.getCoucheThree(), c.getCollision());
break;
case 2:
n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), getFrame().getSelectedSprite().getSprite(), c.getCollision());
break;
default:
n = c;
break;
}
map.setCase(n.getPosX(), n.getPosY(), n);
panel.repaint();
}
}
} else if (frame.getSelectedPaintingMode() == 1) {
for (Case c : getFrame().getMap().getAllCases()) {
Map map = getFrame().getMap();
if (getFrame().getSelectedSprite() != null) {
if (getFrame().getSelectedSprite().getCouche() - 1 > getFrame().getSelectedLayerIndex())
return;
Case n;
switch (getFrame().getSelectedSprite().getCouche()) {
case 0:
n = Case.create(c.getPosX(), c.getPosY(), getFrame().getSelectedSprite().getSprite(), c.getCoucheTwo(), c.getCoucheThree(), c.getCollision());
break;
case 1:
n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), getFrame().getSelectedSprite().getSprite(), c.getCoucheThree(), c.getCollision());
break;
case 2:
n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), getFrame().getSelectedSprite().getSprite(), c.getCollision());
break;
default:
n = c;
break;
}
map.setCase(n.getPosX(), n.getPosY(), n);
}
}
panel.repaint();
}
}
@Override
public void mouseDragged(MouseEvent event) {
if (frame.getSelectedPaintingMode() == 0) {
mouseClicked(event);
}
}
}

View File

@ -6,15 +6,13 @@ import fr.ynerant.leveleditor.frame.MainFrame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class OpenMapListener implements ActionListener
{
/* !CodeTemplates.overridecomment.nonjd!
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
@Override
public void actionPerformed(ActionEvent event)
{
if (EditorAPI.open() != null)
MainFrame.getInstance().dispose();
}
public class OpenMapListener implements ActionListener {
/* !CodeTemplates.overridecomment.nonjd!
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
@Override
public void actionPerformed(ActionEvent event) {
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.MouseEvent;
public class SpriteMouseListener extends MouseAdapter
{
private final SpriteComp sprite;
private final EditorFrame frame;
public SpriteMouseListener(SpriteComp sprc, EditorFrame frame)
{
this.sprite = sprc;
this.frame = frame;
}
@Override
public void mouseReleased(MouseEvent event)
{
if (frame.getSelectedSprite() != null)
{
frame.getSelectedSprite().setSelected(false);
frame.getSelectedSprite().repaint();
}
frame.setSelectedSprite(sprite);
sprite.setSelected(true);
sprite.repaint();
}
public class SpriteMouseListener extends MouseAdapter {
private final SpriteComp sprite;
private final EditorFrame frame;
public SpriteMouseListener(SpriteComp sprc, EditorFrame frame) {
this.sprite = sprc;
this.frame = frame;
}
@Override
public void mouseReleased(MouseEvent event) {
if (frame.getSelectedSprite() != null) {
frame.getSelectedSprite().setSelected(false);
frame.getSelectedSprite().repaint();
}
frame.setSelectedSprite(sprite);
sprite.setSelected(true);
sprite.repaint();
}
}

View File

@ -1,85 +1,322 @@
{
"blank": [
[0,0]
],
"gazon": [
[0,0],
[0,16],
[0,32],
[0,48],
[0,64],
[0,144],
[0,160],
[0,176],
[16,144],
[32,144],
[16,160],
[32,160],
[32,224],
[48,224],
[64,224],
[80,224],
[96,224],
[112,224],
[112,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]
]
"blank": [
[
0,
0
]
],
"gazon": [
[
0,
0
],
[
0,
16
],
[
0,
32
],
[
0,
48
],
[
0,
64
],
[
0,
144
],
[
0,
160
],
[
0,
176
],
[
16,
144
],
[
32,
144
],
[
16,
160
],
[
32,
160
],
[
32,
224
],
[
48,
224
],
[
64,
224
],
[
80,
224
],
[
96,
224
],
[
112,
224
],
[
112,
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"?>
<Configuration package="log4j.test" status="info">
<Loggers>
<Root level="info">
</Root>
</Loggers>
<Loggers>
<Root level="info">
</Root>
</Loggers>
</Configuration>

View File

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