diff --git a/.project b/.project index 8a695f0..b5d0d6c 100644 --- a/.project +++ b/.project @@ -1,23 +1,23 @@ - - - unknown - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.jdt.core.javanature - org.eclipse.m2e.core.maven2Nature - - + + + Alice Game Engine + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/src/main/java/galaxyoyo/unknown/api/editor/Case.java b/src/main/java/galaxyoyo/alice/gameengine/api/editor/Case.java similarity index 86% rename from src/main/java/galaxyoyo/unknown/api/editor/Case.java rename to src/main/java/galaxyoyo/alice/gameengine/api/editor/Case.java index 6e662cf..98b06ca 100644 --- a/src/main/java/galaxyoyo/unknown/api/editor/Case.java +++ b/src/main/java/galaxyoyo/alice/gameengine/api/editor/Case.java @@ -1,61 +1,61 @@ -package galaxyoyo.unknown.api.editor; - -import galaxyoyo.unknown.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"; - } -} +package galaxyoyo.alice.gameengine.api.editor; + +import galaxyoyo.alice.gameengine.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"; + } +} diff --git a/src/main/java/galaxyoyo/unknown/api/editor/Collision.java b/src/main/java/galaxyoyo/alice/gameengine/api/editor/Collision.java similarity index 50% rename from src/main/java/galaxyoyo/unknown/api/editor/Collision.java rename to src/main/java/galaxyoyo/alice/gameengine/api/editor/Collision.java index 8cb9f1d..668ed09 100644 --- a/src/main/java/galaxyoyo/unknown/api/editor/Collision.java +++ b/src/main/java/galaxyoyo/alice/gameengine/api/editor/Collision.java @@ -1,6 +1,6 @@ -package galaxyoyo.unknown.api.editor; - -public enum Collision -{ - FULL, PARTIAL, ANY; -} +package galaxyoyo.alice.gameengine.api.editor; + +public enum Collision +{ + FULL, PARTIAL, ANY; +} diff --git a/src/main/java/galaxyoyo/unknown/api/editor/EditorAPI.java b/src/main/java/galaxyoyo/alice/gameengine/api/editor/EditorAPI.java similarity index 93% rename from src/main/java/galaxyoyo/unknown/api/editor/EditorAPI.java rename to src/main/java/galaxyoyo/alice/gameengine/api/editor/EditorAPI.java index 97676f3..f8050fc 100644 --- a/src/main/java/galaxyoyo/unknown/api/editor/EditorAPI.java +++ b/src/main/java/galaxyoyo/alice/gameengine/api/editor/EditorAPI.java @@ -1,191 +1,191 @@ -package galaxyoyo.unknown.api.editor; - -import galaxyoyo.unknown.editor.Map; - -import java.awt.Color; -import java.awt.Graphics2D; -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.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; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - -public class EditorAPI -{ - private static File LAST_FILE; - - public static RawMap toRawMap(int width, int height) - { - List cases = new ArrayList(); - - 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(); - } - - 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("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); - } - - 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); - } -} +package galaxyoyo.alice.gameengine.api.editor; + +import galaxyoyo.alice.gameengine.editor.Map; + +import java.awt.Color; +import java.awt.Graphics2D; +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.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; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +public class EditorAPI +{ + private static File LAST_FILE; + + public static RawMap toRawMap(int width, int height) + { + List cases = new ArrayList(); + + 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(); + } + + 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("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); + } + + 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); + } +} diff --git a/src/main/java/galaxyoyo/unknown/api/editor/RawCase.java b/src/main/java/galaxyoyo/alice/gameengine/api/editor/RawCase.java similarity index 91% rename from src/main/java/galaxyoyo/unknown/api/editor/RawCase.java rename to src/main/java/galaxyoyo/alice/gameengine/api/editor/RawCase.java index a1b4ea6..3360ad4 100644 --- a/src/main/java/galaxyoyo/unknown/api/editor/RawCase.java +++ b/src/main/java/galaxyoyo/alice/gameengine/api/editor/RawCase.java @@ -1,65 +1,65 @@ -package galaxyoyo.unknown.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; - } -} +package galaxyoyo.alice.gameengine.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; + } +} diff --git a/src/main/java/galaxyoyo/unknown/api/editor/RawMap.java b/src/main/java/galaxyoyo/alice/gameengine/api/editor/RawMap.java similarity index 87% rename from src/main/java/galaxyoyo/unknown/api/editor/RawMap.java rename to src/main/java/galaxyoyo/alice/gameengine/api/editor/RawMap.java index 777a3a9..5340ca7 100644 --- a/src/main/java/galaxyoyo/unknown/api/editor/RawMap.java +++ b/src/main/java/galaxyoyo/alice/gameengine/api/editor/RawMap.java @@ -1,63 +1,63 @@ -package galaxyoyo.unknown.api.editor; - -import galaxyoyo.unknown.editor.Map; - -import java.awt.image.BufferedImage; -import java.util.ArrayList; -import java.util.List; - -public class RawMap -{ - private List cases; - private int width; - private int height; - private transient BufferedImage font; - - public List getCases() - { - return cases; - } - - public int getWidth() - { - return width; - } - - public int getHeight() - { - return height; - } - - public static RawMap create(List cases, int width, int height) - { - RawMap rm = new RawMap(); - rm.cases = cases; - rm.width = width; - rm.height = height; - return rm; - } - - public BufferedImage getFont() - { - return font; - } - - 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(); - for (Case c : map.getAllCases()) - { - RawCase rc = RawCase.create(c); - raw.cases.add(rc); - } - return raw; - } -} +package galaxyoyo.alice.gameengine.api.editor; + +import galaxyoyo.alice.gameengine.editor.Map; + +import java.awt.image.BufferedImage; +import java.util.ArrayList; +import java.util.List; + +public class RawMap +{ + private List cases; + private int width; + private int height; + private transient BufferedImage font; + + public List getCases() + { + return cases; + } + + public int getWidth() + { + return width; + } + + public int getHeight() + { + return height; + } + + public static RawMap create(List cases, int width, int height) + { + RawMap rm = new RawMap(); + rm.cases = cases; + rm.width = width; + rm.height = height; + return rm; + } + + public BufferedImage getFont() + { + return font; + } + + 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(); + for (Case c : map.getAllCases()) + { + RawCase rc = RawCase.create(c); + raw.cases.add(rc); + } + return raw; + } +} diff --git a/src/main/java/galaxyoyo/unknown/api/editor/RawSprite.java b/src/main/java/galaxyoyo/alice/gameengine/api/editor/RawSprite.java similarity index 78% rename from src/main/java/galaxyoyo/unknown/api/editor/RawSprite.java rename to src/main/java/galaxyoyo/alice/gameengine/api/editor/RawSprite.java index f2b2c7e..050615a 100644 --- a/src/main/java/galaxyoyo/unknown/api/editor/RawSprite.java +++ b/src/main/java/galaxyoyo/alice/gameengine/api/editor/RawSprite.java @@ -1,29 +1,29 @@ -package galaxyoyo.unknown.api.editor; - -import galaxyoyo.unknown.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; - } -} +package galaxyoyo.alice.gameengine.api.editor; + +import galaxyoyo.alice.gameengine.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; + } +} diff --git a/src/main/java/galaxyoyo/alice/gameengine/api/editor/package-info.java b/src/main/java/galaxyoyo/alice/gameengine/api/editor/package-info.java new file mode 100644 index 0000000..73336eb --- /dev/null +++ b/src/main/java/galaxyoyo/alice/gameengine/api/editor/package-info.java @@ -0,0 +1,4 @@ +/** + * @author galaxyoyo + */ +package galaxyoyo.alice.gameengine.api.editor; \ No newline at end of file diff --git a/src/main/java/galaxyoyo/unknown/api/editor/sprites/Category.java b/src/main/java/galaxyoyo/alice/gameengine/api/editor/sprites/Category.java similarity index 85% rename from src/main/java/galaxyoyo/unknown/api/editor/sprites/Category.java rename to src/main/java/galaxyoyo/alice/gameengine/api/editor/sprites/Category.java index eacc1ba..9c0168a 100644 --- a/src/main/java/galaxyoyo/unknown/api/editor/sprites/Category.java +++ b/src/main/java/galaxyoyo/alice/gameengine/api/editor/sprites/Category.java @@ -1,40 +1,40 @@ -package galaxyoyo.unknown.api.editor.sprites; - -import java.util.List; - -public class Category -{ - private List sprites; - private String name; - private int index; - - private Category() - { - } - - public String getName() - { - return name; - } - - public List getSprites() - { - return sprites; - } - - public int getIndex() - { - return index; - } - - public static Category create(String name, int index, List sprites) - { - Category c = new Category(); - - c.name = name; - c.index = index; - c.sprites = sprites; - - return c; - } -} +package galaxyoyo.alice.gameengine.api.editor.sprites; + +import java.util.List; + +public class Category +{ + private List sprites; + private String name; + private int index; + + private Category() + { + } + + public String getName() + { + return name; + } + + public List getSprites() + { + return sprites; + } + + public int getIndex() + { + return index; + } + + public static Category create(String name, int index, List sprites) + { + Category c = new Category(); + + c.name = name; + c.index = index; + c.sprites = sprites; + + return c; + } +} diff --git a/src/main/java/galaxyoyo/unknown/api/editor/sprites/Sprite.java b/src/main/java/galaxyoyo/alice/gameengine/api/editor/sprites/Sprite.java similarity index 91% rename from src/main/java/galaxyoyo/unknown/api/editor/sprites/Sprite.java rename to src/main/java/galaxyoyo/alice/gameengine/api/editor/sprites/Sprite.java index 88cf708..4da268a 100644 --- a/src/main/java/galaxyoyo/unknown/api/editor/sprites/Sprite.java +++ b/src/main/java/galaxyoyo/alice/gameengine/api/editor/sprites/Sprite.java @@ -1,72 +1,72 @@ -package galaxyoyo.unknown.api.editor.sprites; - -import java.awt.AlphaComposite; -import java.awt.Color; -import java.awt.Graphics2D; -import java.awt.image.BufferedImage; -import java.util.ArrayList; - -public class Sprite -{ - public static final Sprite BLANK = new Sprite(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB), Category.create("blank", 0, new ArrayList()), 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() + "}"; - } -} +package galaxyoyo.alice.gameengine.api.editor.sprites; + +import java.awt.AlphaComposite; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; +import java.util.ArrayList; + +public class Sprite +{ + public static final Sprite BLANK = new Sprite(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB), Category.create("blank", 0, new ArrayList()), 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() + "}"; + } +} diff --git a/src/main/java/galaxyoyo/unknown/api/editor/sprites/SpriteRegister.java b/src/main/java/galaxyoyo/alice/gameengine/api/editor/sprites/SpriteRegister.java similarity index 94% rename from src/main/java/galaxyoyo/unknown/api/editor/sprites/SpriteRegister.java rename to src/main/java/galaxyoyo/alice/gameengine/api/editor/sprites/SpriteRegister.java index 206e5f9..01a6e6c 100644 --- a/src/main/java/galaxyoyo/unknown/api/editor/sprites/SpriteRegister.java +++ b/src/main/java/galaxyoyo/alice/gameengine/api/editor/sprites/SpriteRegister.java @@ -1,175 +1,175 @@ -package galaxyoyo.unknown.api.editor.sprites; - -import galaxyoyo.unknown.client.main.Main; - -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.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.jar.JarEntry; -import java.util.jar.JarFile; - -import javax.imageio.ImageIO; - -import org.apache.logging.log4j.LogManager; - -import com.google.gson.Gson; - -public class SpriteRegister -{ - private static Map>> nameToCoords; - private static Map sprites = new HashMap(); - - 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); - - if(jarFile.isFile()) - { - JarFile jar = new JarFile(jarFile); - Enumeration 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())); - } - } - - @SuppressWarnings("unchecked") - public static void refreshAllSprites() - { - if (nameToCoords != null && !nameToCoords.isEmpty() && !sprites.isEmpty()) - { - return; - } - - File assetsDir = new File("assets"); - List assets = new ArrayList(); - - 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(nameToCoords.keySet()).indexOf(key), new ArrayList()); - - for (List 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(sprites.keySet()).get(index)); - } - - public static List getAllCategories() - { - return new ArrayList(sprites.values()); - } - - public static List getAllSprites() - { - List list = new ArrayList(); - - for (Category c : sprites.values()) - { - list.addAll(c.getSprites()); - } - - return list; - } -} +package galaxyoyo.alice.gameengine.api.editor.sprites; + +import galaxyoyo.alice.gameengine.client.main.Main; + +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.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.jar.JarEntry; +import java.util.jar.JarFile; + +import javax.imageio.ImageIO; + +import org.apache.logging.log4j.LogManager; + +import com.google.gson.Gson; + +public class SpriteRegister +{ + private static Map>> nameToCoords; + private static Map sprites = new HashMap(); + + 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); + + if(jarFile.isFile()) + { + JarFile jar = new JarFile(jarFile); + Enumeration 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())); + } + } + + @SuppressWarnings("unchecked") + public static void refreshAllSprites() + { + if (nameToCoords != null && !nameToCoords.isEmpty() && !sprites.isEmpty()) + { + return; + } + + File assetsDir = new File("assets"); + List assets = new ArrayList(); + + 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(nameToCoords.keySet()).indexOf(key), new ArrayList()); + + for (List 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(sprites.keySet()).get(index)); + } + + public static List getAllCategories() + { + return new ArrayList(sprites.values()); + } + + public static List getAllSprites() + { + List list = new ArrayList(); + + for (Category c : sprites.values()) + { + list.addAll(c.getSprites()); + } + + return list; + } +} diff --git a/src/main/java/galaxyoyo/unknown/client/main/Main.java b/src/main/java/galaxyoyo/alice/gameengine/client/main/Main.java similarity index 93% rename from src/main/java/galaxyoyo/unknown/client/main/Main.java rename to src/main/java/galaxyoyo/alice/gameengine/client/main/Main.java index 69232c3..f6fcc6b 100644 --- a/src/main/java/galaxyoyo/unknown/client/main/Main.java +++ b/src/main/java/galaxyoyo/alice/gameengine/client/main/Main.java @@ -1,289 +1,289 @@ -/** - * @author galaxyoyo - */ -package galaxyoyo.unknown.client.main; - -import galaxyoyo.unknown.api.editor.EditorAPI; -import galaxyoyo.unknown.api.editor.RawMap; -import galaxyoyo.unknown.api.editor.sprites.SpriteRegister; -import galaxyoyo.unknown.frame.MainFrame; - -import java.awt.Color; -import java.awt.Desktop; -import java.awt.Graphics2D; -import java.awt.GraphicsEnvironment; -import java.awt.HeadlessException; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.Locale; -import java.util.Map; - -import javax.swing.JOptionPane; - -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 galaxyoyo - * @see #main(String...) - */ -public class Main -{ - /** - * Variable disant si le jeu est en débogage ou non. S'active en insé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é en développement ou non. - * @see #isInDevelopmentMode() - * @see #main(String...) - * @since 0.1-aplha - */ - private static boolean DEV; - - /** - * @param args arguments du jeu. Possibilités :
    --edit lancera un éditeur
    --help 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 - { - 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 edit = parser.accepts("edit", "Lancer l'\u00e9diteur de monde").withOptionalArg(); - OptionSpec debug = parser.accepts("debug").withOptionalArg().ofType(Boolean.class).defaultsTo(true); - OptionSpec 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, "Cette application requiert Java 8.
La page de t\u00e9l\u00e9chargement va maintenant s'ouvrir."); - JOptionPane.showMessageDialog(null, "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,
ou si vous êtes plus expérimentés si le path vers Java est bien défini vers la bonne version."); - try - { - if (Desktop.isDesktopSupported()) - Desktop.getDesktop().browse(new URL("http://java.com/download").toURI()); - else - JOptionPane.showMessageDialog(null, "Votre machine ne supporte pas la classe Desktop, impossible d'ouvrir la page.
Rendez-vous y manuellement sur http://java.com/download pour installer Java."); - } - catch (IOException | URISyntaxException e) - { - e.printStackTrace(); - } - System.exit(1); - } - } - - /** - * Lance la fenêtre principale - * @see #main(String...) - * @see #launchEditMode() - */ - private static void launchFrame() - { - MainFrame.getInstance().setVisible(true); - } - - /** - * Permet de lancer l'é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; - JOptionPane.showMessageDialog(null, "NOMBRE : " + baseWidth); - 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ébogage ou non. S'active en insé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é en développement ou non. - * @see #DEV - * @since 0.1-alpha - */ - public static boolean isInDevelopmentMode() - { - return DEV; - } -} +/** + * @author galaxyoyo + */ +package galaxyoyo.alice.gameengine.client.main; + +import galaxyoyo.alice.gameengine.api.editor.EditorAPI; +import galaxyoyo.alice.gameengine.api.editor.RawMap; +import galaxyoyo.alice.gameengine.api.editor.sprites.SpriteRegister; +import galaxyoyo.gameengine.frame.MainFrame; + +import java.awt.Color; +import java.awt.Desktop; +import java.awt.Graphics2D; +import java.awt.GraphicsEnvironment; +import java.awt.HeadlessException; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.Locale; +import java.util.Map; + +import javax.swing.JOptionPane; + +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 galaxyoyo + * @see #main(String...) + */ +public class Main +{ + /** + * Variable disant si le jeu est en débogage ou non. S'active en insé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é en développement ou non. + * @see #isInDevelopmentMode() + * @see #main(String...) + * @since 0.1-aplha + */ + private static boolean DEV; + + /** + * @param args arguments du jeu. Possibilités :
    --edit lancera un éditeur
    --help 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 + { + 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 edit = parser.accepts("edit", "Lancer l'\u00e9diteur de monde").withOptionalArg(); + OptionSpec debug = parser.accepts("debug").withOptionalArg().ofType(Boolean.class).defaultsTo(true); + OptionSpec 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, "Cette application requiert Java 8.
La page de t\u00e9l\u00e9chargement va maintenant s'ouvrir."); + JOptionPane.showMessageDialog(null, "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,
ou si vous êtes plus expérimentés si le path vers Java est bien défini vers la bonne version."); + try + { + if (Desktop.isDesktopSupported()) + Desktop.getDesktop().browse(new URL("http://java.com/download").toURI()); + else + JOptionPane.showMessageDialog(null, "Votre machine ne supporte pas la classe Desktop, impossible d'ouvrir la page.
Rendez-vous y manuellement sur http://java.com/download pour installer Java."); + } + catch (IOException | URISyntaxException e) + { + e.printStackTrace(); + } + System.exit(1); + } + } + + /** + * Lance la fenêtre principale + * @see #main(String...) + * @see #launchEditMode() + */ + private static void launchFrame() + { + MainFrame.getInstance().setVisible(true); + } + + /** + * Permet de lancer l'é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; + JOptionPane.showMessageDialog(null, "NOMBRE : " + baseWidth); + 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ébogage ou non. S'active en insé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é en développement ou non. + * @see #DEV + * @since 0.1-alpha + */ + public static boolean isInDevelopmentMode() + { + return DEV; + } +} diff --git a/src/main/java/galaxyoyo/unknown/client/main/package-info.java b/src/main/java/galaxyoyo/alice/gameengine/client/main/package-info.java similarity index 70% rename from src/main/java/galaxyoyo/unknown/client/main/package-info.java rename to src/main/java/galaxyoyo/alice/gameengine/client/main/package-info.java index 4de6196..aecadf8 100644 --- a/src/main/java/galaxyoyo/unknown/client/main/package-info.java +++ b/src/main/java/galaxyoyo/alice/gameengine/client/main/package-info.java @@ -1,7 +1,7 @@ -/** - * Ce package comprend uniquement la classe Main, qui lance l'application. - */ -/** - * @author galaxyoyo - */ -package galaxyoyo.unknown.client.main; \ No newline at end of file +/** + * Ce package comprend uniquement la classe Main, qui lance l'application. + */ +/** + * @author galaxyoyo + */ +package galaxyoyo.alice.gameengine.client.main; \ No newline at end of file diff --git a/src/main/java/galaxyoyo/unknown/editor/CollidPanel.java b/src/main/java/galaxyoyo/alice/gameengine/editor/CollidPanel.java similarity index 91% rename from src/main/java/galaxyoyo/unknown/editor/CollidPanel.java rename to src/main/java/galaxyoyo/alice/gameengine/editor/CollidPanel.java index 658a8d7..fce708b 100644 --- a/src/main/java/galaxyoyo/unknown/editor/CollidPanel.java +++ b/src/main/java/galaxyoyo/alice/gameengine/editor/CollidPanel.java @@ -1,104 +1,104 @@ -package galaxyoyo.unknown.editor; - -import galaxyoyo.unknown.api.editor.Case; -import galaxyoyo.unknown.api.editor.Collision; - -import java.awt.Color; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.image.BufferedImage; - -import javax.swing.JPanel; - -public class CollidPanel extends JPanel -{ - private static final long serialVersionUID = -138754019431984881L; - - private final EditorFrame frame; - - public CollidPanel(EditorFrame frame) - { - super (); - this.frame = frame; - } - - public EditorFrame getFrame() - { - return frame; - } - - public Map getMap() - { - return frame.getMap(); - } - - @Override - public void paintComponent(Graphics g) - { - g.fillRect(0, 0, getWidth(), getHeight()); - BufferedImage img = getMap().getFont(); - int x = getWidth() / 2 - img.getWidth(); - int y = getHeight() / 2 - img.getHeight(); - int width = img.getWidth() * 2; - int height = img.getHeight() * 2; - g.drawImage(getMap().getFont(), x, y, width, height, null); - - for (Case c : getMap().getAllCases()) - { - if (isEmpty(c.getCoucheOne().getImage())) - continue; - - g.drawImage(c.getCoucheOne().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null); - - if (isEmpty(c.getCoucheTwo().getImage())) - continue; - - g.drawImage(c.getCoucheTwo().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null); - - if (isEmpty(c.getCoucheThree().getImage())) - continue; - - g.drawImage(c.getCoucheThree().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null); - } - - for (Case c : getMap().getAllCases()) - { - if (c.getCollision() != Collision.ANY) - { - BufferedImage alpha = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB); - - if (c.getCollision() == Collision.FULL) - { - Graphics2D grap = alpha.createGraphics(); - grap.setColor(new Color(0, 0, 0, 100)); - grap.fillRect(0, 0, 16, 16); - grap.dispose(); - } - else if (c.getCollision() == Collision.PARTIAL) - { - Graphics2D grap = alpha.createGraphics(); - grap.setColor(new Color(255, 0, 255, 70)); - grap.fillRect(0, 0, 16, 16); - grap.dispose(); - } - - g.drawImage(alpha, x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null); - } - } - } - - private boolean isEmpty(BufferedImage image) - { - int allrgba = 0; - - for (int x = 0; x < image.getWidth(); ++x) - { - for (int y = 0; y < image.getHeight(); ++y) - { - allrgba += image.getRGB(x, y) + 1; - } - } - - return allrgba == 0; - } -} +package galaxyoyo.alice.gameengine.editor; + +import galaxyoyo.alice.gameengine.api.editor.Case; +import galaxyoyo.alice.gameengine.api.editor.Collision; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; + +import javax.swing.JPanel; + +public class CollidPanel extends JPanel +{ + private static final long serialVersionUID = -138754019431984881L; + + private final EditorFrame frame; + + public CollidPanel(EditorFrame frame) + { + super (); + this.frame = frame; + } + + public EditorFrame getFrame() + { + return frame; + } + + public Map getMap() + { + return frame.getMap(); + } + + @Override + public void paintComponent(Graphics g) + { + g.fillRect(0, 0, getWidth(), getHeight()); + BufferedImage img = getMap().getFont(); + int x = getWidth() / 2 - img.getWidth(); + int y = getHeight() / 2 - img.getHeight(); + int width = img.getWidth() * 2; + int height = img.getHeight() * 2; + g.drawImage(getMap().getFont(), x, y, width, height, null); + + for (Case c : getMap().getAllCases()) + { + if (isEmpty(c.getCoucheOne().getImage())) + continue; + + g.drawImage(c.getCoucheOne().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null); + + if (isEmpty(c.getCoucheTwo().getImage())) + continue; + + g.drawImage(c.getCoucheTwo().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null); + + if (isEmpty(c.getCoucheThree().getImage())) + continue; + + g.drawImage(c.getCoucheThree().getImage(), x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null); + } + + for (Case c : getMap().getAllCases()) + { + if (c.getCollision() != Collision.ANY) + { + BufferedImage alpha = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB); + + if (c.getCollision() == Collision.FULL) + { + Graphics2D grap = alpha.createGraphics(); + grap.setColor(new Color(0, 0, 0, 100)); + grap.fillRect(0, 0, 16, 16); + grap.dispose(); + } + else if (c.getCollision() == Collision.PARTIAL) + { + Graphics2D grap = alpha.createGraphics(); + grap.setColor(new Color(255, 0, 255, 70)); + grap.fillRect(0, 0, 16, 16); + grap.dispose(); + } + + g.drawImage(alpha, x + c.getPosX() * 34 + 2, y + c.getPosY() * 34 + 2, 32, 32, null); + } + } + } + + private boolean isEmpty(BufferedImage image) + { + int allrgba = 0; + + for (int x = 0; x < image.getWidth(); ++x) + { + for (int y = 0; y < image.getHeight(); ++y) + { + allrgba += image.getRGB(x, y) + 1; + } + } + + return allrgba == 0; + } +} diff --git a/src/main/java/galaxyoyo/unknown/editor/EditorFrame.java b/src/main/java/galaxyoyo/alice/gameengine/editor/EditorFrame.java similarity index 91% rename from src/main/java/galaxyoyo/unknown/editor/EditorFrame.java rename to src/main/java/galaxyoyo/alice/gameengine/editor/EditorFrame.java index 374bacd..4f908ff 100644 --- a/src/main/java/galaxyoyo/unknown/editor/EditorFrame.java +++ b/src/main/java/galaxyoyo/alice/gameengine/editor/EditorFrame.java @@ -1,381 +1,382 @@ -package galaxyoyo.unknown.editor; - -import galaxyoyo.unknown.api.editor.EditorAPI; -import galaxyoyo.unknown.api.editor.RawMap; -import galaxyoyo.unknown.api.editor.sprites.Category; -import galaxyoyo.unknown.api.editor.sprites.Sprite; -import galaxyoyo.unknown.api.editor.sprites.SpriteRegister; -import galaxyoyo.unknown.frame.listeners.CollidMapMouseListener; -import galaxyoyo.unknown.frame.listeners.CreateMapListener; -import galaxyoyo.unknown.frame.listeners.MapMouseListener; -import galaxyoyo.unknown.frame.listeners.OpenMapListener; -import galaxyoyo.unknown.frame.listeners.SpriteMouseListener; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyEvent; -import java.awt.event.WindowEvent; -import java.awt.event.WindowListener; -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; - - 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; - - public EditorFrame(Map map) - { - 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); - - 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/unknown/textures/layer 1.png").getAbsolutePath()), scroll1); - resources.addTab("", new ImageIcon(new File("assets/unknown/textures/layer 2.png").getAbsolutePath()), scroll2); - resources.addTab("", new ImageIcon(new File("assets/unknown/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) - { - } -} +package galaxyoyo.alice.gameengine.editor; + +import galaxyoyo.alice.gameengine.api.editor.EditorAPI; +import galaxyoyo.alice.gameengine.api.editor.RawMap; +import galaxyoyo.alice.gameengine.api.editor.sprites.Category; +import galaxyoyo.alice.gameengine.api.editor.sprites.Sprite; +import galaxyoyo.alice.gameengine.api.editor.sprites.SpriteRegister; +import galaxyoyo.gameengine.frame.listeners.CollidMapMouseListener; +import galaxyoyo.gameengine.frame.listeners.CreateMapListener; +import galaxyoyo.gameengine.frame.listeners.MapMouseListener; +import galaxyoyo.gameengine.frame.listeners.OpenMapListener; +import galaxyoyo.gameengine.frame.listeners.SpriteMouseListener; + +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 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; + + 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; + + 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); + + 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/unknown/textures/layer 1.png").getAbsolutePath()), scroll1); + resources.addTab("", new ImageIcon(new File("assets/unknown/textures/layer 2.png").getAbsolutePath()), scroll2); + resources.addTab("", new ImageIcon(new File("assets/unknown/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) + { + } +} diff --git a/src/main/java/galaxyoyo/unknown/editor/Map.java b/src/main/java/galaxyoyo/alice/gameengine/editor/Map.java similarity index 85% rename from src/main/java/galaxyoyo/unknown/editor/Map.java rename to src/main/java/galaxyoyo/alice/gameengine/editor/Map.java index 81e0990..d8e4827 100644 --- a/src/main/java/galaxyoyo/unknown/editor/Map.java +++ b/src/main/java/galaxyoyo/alice/gameengine/editor/Map.java @@ -1,101 +1,101 @@ -package galaxyoyo.unknown.editor; - -import galaxyoyo.unknown.api.editor.Case; -import galaxyoyo.unknown.api.editor.RawCase; -import galaxyoyo.unknown.api.editor.RawMap; -import galaxyoyo.unknown.api.editor.sprites.SpriteRegister; - -import java.awt.image.BufferedImage; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -public class Map -{ - @Deprecated - private static List cases; - private final EditorFrame frame; - private int width; - private int height; - private java.util.Map> casesMap = new HashMap>(); - private transient BufferedImage font; - - public Map(RawMap raw) - { - cases = new ArrayList(); - 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()).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()); - } - - for (Case c : cases) - { - setCase(c.getPosX(), c.getPosY(), c); - } - } - - public List getAllCases() - { - List list = new ArrayList(); - - for (java.util.Map l : casesMap.values()) - { - list.addAll(l.values()); - } - - return list; - } -} +package galaxyoyo.alice.gameengine.editor; + +import galaxyoyo.alice.gameengine.api.editor.Case; +import galaxyoyo.alice.gameengine.api.editor.RawCase; +import galaxyoyo.alice.gameengine.api.editor.RawMap; +import galaxyoyo.alice.gameengine.api.editor.sprites.SpriteRegister; + +import java.awt.image.BufferedImage; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class Map +{ + @Deprecated + private static List cases; + private final EditorFrame frame; + private int width; + private int height; + private java.util.Map> casesMap = new HashMap>(); + private transient BufferedImage font; + + public Map(RawMap raw) + { + cases = new ArrayList(); + 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()).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()); + } + + for (Case c : cases) + { + setCase(c.getPosX(), c.getPosY(), c); + } + } + + public List getAllCases() + { + List list = new ArrayList(); + + for (java.util.Map l : casesMap.values()) + { + list.addAll(l.values()); + } + + return list; + } +} diff --git a/src/main/java/galaxyoyo/unknown/editor/MapPanel.java b/src/main/java/galaxyoyo/alice/gameengine/editor/MapPanel.java similarity index 93% rename from src/main/java/galaxyoyo/unknown/editor/MapPanel.java rename to src/main/java/galaxyoyo/alice/gameengine/editor/MapPanel.java index 8999d03..fd673f0 100644 --- a/src/main/java/galaxyoyo/unknown/editor/MapPanel.java +++ b/src/main/java/galaxyoyo/alice/gameengine/editor/MapPanel.java @@ -1,93 +1,93 @@ -package galaxyoyo.unknown.editor; - -import galaxyoyo.unknown.api.editor.Case; - -import java.awt.Graphics; -import java.awt.image.BufferedImage; - -import javax.swing.JPanel; - -public class MapPanel extends JPanel -{ - private static final long serialVersionUID = 2629019576253690557L; - - private final EditorFrame frame; - - public MapPanel(EditorFrame frame) - { - super (); - this.frame = frame; - } - - public EditorFrame getFrame() - { - return frame; - } - - public Map getMap() - { - return frame.getMap(); - } - - @Override - public void paintComponent(Graphics g) - { - g.fillRect(0, 0, getWidth(), getHeight()); - BufferedImage img = getMap().getFont(); - int x = getWidth() / 2 - img.getWidth(); - int y = getHeight() / 2 - img.getHeight(); - int width = img.getWidth() * 2; - int height = img.getHeight() * 2; - g.drawImage(getMap().getFont(), x, y, width, height, null); - - for (Case c : getMap().getAllCases()) - { - // 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 (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 (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; - } -} +package galaxyoyo.alice.gameengine.editor; + +import galaxyoyo.alice.gameengine.api.editor.Case; + +import java.awt.Graphics; +import java.awt.image.BufferedImage; + +import javax.swing.JPanel; + +public class MapPanel extends JPanel +{ + private static final long serialVersionUID = 2629019576253690557L; + + private final EditorFrame frame; + + public MapPanel(EditorFrame frame) + { + super (); + this.frame = frame; + } + + public EditorFrame getFrame() + { + return frame; + } + + public Map getMap() + { + return frame.getMap(); + } + + @Override + public void paintComponent(Graphics g) + { + g.fillRect(0, 0, getWidth(), getHeight()); + BufferedImage img = getMap().getFont(); + int x = getWidth() / 2 - img.getWidth(); + int y = getHeight() / 2 - img.getHeight(); + int width = img.getWidth() * 2; + int height = img.getHeight() * 2; + g.drawImage(getMap().getFont(), x, y, width, height, null); + + for (Case c : getMap().getAllCases()) + { + // 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 (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 (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; + } +} diff --git a/src/main/java/galaxyoyo/unknown/editor/SpriteComp.java b/src/main/java/galaxyoyo/alice/gameengine/editor/SpriteComp.java similarity index 89% rename from src/main/java/galaxyoyo/unknown/editor/SpriteComp.java rename to src/main/java/galaxyoyo/alice/gameengine/editor/SpriteComp.java index de861eb..23858f5 100644 --- a/src/main/java/galaxyoyo/unknown/editor/SpriteComp.java +++ b/src/main/java/galaxyoyo/alice/gameengine/editor/SpriteComp.java @@ -1,80 +1,80 @@ -package galaxyoyo.unknown.editor; - -import galaxyoyo.unknown.api.editor.sprites.Sprite; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Graphics; - -import javax.swing.JComponent; - -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(); - } - - 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); - } - } -} +package galaxyoyo.alice.gameengine.editor; + +import galaxyoyo.alice.gameengine.api.editor.sprites.Sprite; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; + +import javax.swing.JComponent; + +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(); + } + + 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); + } + } +} diff --git a/src/main/java/galaxyoyo/unknown/editor/WrapLayout.java b/src/main/java/galaxyoyo/alice/gameengine/editor/WrapLayout.java similarity index 93% rename from src/main/java/galaxyoyo/unknown/editor/WrapLayout.java rename to src/main/java/galaxyoyo/alice/gameengine/editor/WrapLayout.java index 86719d7..4e546be 100644 --- a/src/main/java/galaxyoyo/unknown/editor/WrapLayout.java +++ b/src/main/java/galaxyoyo/alice/gameengine/editor/WrapLayout.java @@ -1,112 +1,112 @@ -package galaxyoyo.unknown.editor; - -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; - } +package galaxyoyo.alice.gameengine.editor; + +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; + } } \ No newline at end of file diff --git a/src/main/java/galaxyoyo/unknown/frame/MainFrame.java b/src/main/java/galaxyoyo/gameengine/frame/MainFrame.java similarity index 85% rename from src/main/java/galaxyoyo/unknown/frame/MainFrame.java rename to src/main/java/galaxyoyo/gameengine/frame/MainFrame.java index 7b6ded8..7159156 100644 --- a/src/main/java/galaxyoyo/unknown/frame/MainFrame.java +++ b/src/main/java/galaxyoyo/gameengine/frame/MainFrame.java @@ -1,93 +1,93 @@ -/** - * @author galaxyoyo - */ -package galaxyoyo.unknown.frame; - -import galaxyoyo.unknown.frame.listeners.CreateMapListener; -import galaxyoyo.unknown.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; - -/** - * Fenêtre principale du jeu - * @author galaxyoyo - */ -public class MainFrame extends JFrame -{ - /** - * ID de sé - * @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"); - - private JMenuBar menuBar = new JMenuBar(); - private JMenu fichier = new JMenu("Fichier"); - private JMenu editMaps = new JMenu("Cartes"); - private JMenuItem createMap = new JMenuItem("Cr\u00e9er"); - private JMenuItem openMap = new JMenuItem("Ouvrir"); - - /** - * Constructeur - * @see galaxyoyo.unknown.client.main.Main#launchFrame() - */ - private MainFrame() - { - super (); - LOGGER.info("Initialisation de la fen\u00eatre"); - this.setTitle("WHAT IS THE NAME PLEASE"); - 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); - - createMap.addActionListener(new CreateMapListener()); - editMaps.add(createMap); - openMap.addActionListener(new OpenMapListener()); - editMaps.add(openMap); - - fichier.add(editMaps); - - menuBar.add(fichier); - - 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; - } -} +/** + * @author galaxyoyo + */ +package galaxyoyo.gameengine.frame; + +import galaxyoyo.gameengine.frame.listeners.CreateMapListener; +import galaxyoyo.gameengine.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; + +/** + * Fenêtre principale du jeu + * @author galaxyoyo + */ +public class MainFrame extends JFrame +{ + /** + * ID de sé + * @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"); + + private JMenuBar menuBar = new JMenuBar(); + private JMenu fichier = new JMenu("Fichier"); + private JMenu editMaps = new JMenu("Cartes"); + private JMenuItem createMap = new JMenuItem("Cr\u00e9er"); + private JMenuItem openMap = new JMenuItem("Ouvrir"); + + /** + * Constructeur + * @see galaxyoyo.alice.gameengine.client.main.Main#launchFrame() + */ + 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); + + createMap.addActionListener(new CreateMapListener()); + editMaps.add(createMap); + openMap.addActionListener(new OpenMapListener()); + editMaps.add(openMap); + + fichier.add(editMaps); + + menuBar.add(fichier); + + 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; + } +} diff --git a/src/main/java/galaxyoyo/unknown/frame/listeners/CollidMapMouseListener.java b/src/main/java/galaxyoyo/gameengine/frame/listeners/CollidMapMouseListener.java similarity index 79% rename from src/main/java/galaxyoyo/unknown/frame/listeners/CollidMapMouseListener.java rename to src/main/java/galaxyoyo/gameengine/frame/listeners/CollidMapMouseListener.java index e70c7f1..bddd777 100644 --- a/src/main/java/galaxyoyo/unknown/frame/listeners/CollidMapMouseListener.java +++ b/src/main/java/galaxyoyo/gameengine/frame/listeners/CollidMapMouseListener.java @@ -1,50 +1,50 @@ -package galaxyoyo.unknown.frame.listeners; - -import galaxyoyo.unknown.api.editor.Case; -import galaxyoyo.unknown.api.editor.Collision; -import galaxyoyo.unknown.editor.CollidPanel; -import galaxyoyo.unknown.editor.EditorFrame; -import galaxyoyo.unknown.editor.Map; - -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; - -public class CollidMapMouseListener extends MouseAdapter -{ - private final EditorFrame frame; - private final CollidPanel panel; - - public CollidMapMouseListener(CollidPanel panel, EditorFrame frame) - { - this.frame = frame; - this.panel = panel; - } - - public EditorFrame getFrame() - { - return frame; - } - - @Override - public void 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(); - } - } -} +package galaxyoyo.gameengine.frame.listeners; + +import galaxyoyo.alice.gameengine.api.editor.Case; +import galaxyoyo.alice.gameengine.api.editor.Collision; +import galaxyoyo.alice.gameengine.editor.CollidPanel; +import galaxyoyo.alice.gameengine.editor.EditorFrame; +import galaxyoyo.alice.gameengine.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 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(); + } + } +} diff --git a/src/main/java/galaxyoyo/unknown/frame/listeners/CreateMapListener.java b/src/main/java/galaxyoyo/gameengine/frame/listeners/CreateMapListener.java similarity index 74% rename from src/main/java/galaxyoyo/unknown/frame/listeners/CreateMapListener.java rename to src/main/java/galaxyoyo/gameengine/frame/listeners/CreateMapListener.java index 96254e7..6c2436d 100644 --- a/src/main/java/galaxyoyo/unknown/frame/listeners/CreateMapListener.java +++ b/src/main/java/galaxyoyo/gameengine/frame/listeners/CreateMapListener.java @@ -1,26 +1,26 @@ -/** - * @author galaxyoyo - */ -package galaxyoyo.unknown.frame.listeners; - -import galaxyoyo.unknown.client.main.Main; -import galaxyoyo.unknown.frame.MainFrame; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -/** - * @author galaxyoyo - */ -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(); - } -} +/** + * @author galaxyoyo + */ +package galaxyoyo.gameengine.frame.listeners; + +import galaxyoyo.alice.gameengine.client.main.Main; +import galaxyoyo.gameengine.frame.MainFrame; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * @author galaxyoyo + */ +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(); + } +} diff --git a/src/main/java/galaxyoyo/unknown/frame/listeners/MapMouseListener.java b/src/main/java/galaxyoyo/gameengine/frame/listeners/MapMouseListener.java similarity index 89% rename from src/main/java/galaxyoyo/unknown/frame/listeners/MapMouseListener.java rename to src/main/java/galaxyoyo/gameengine/frame/listeners/MapMouseListener.java index 783fd25..1614e2c 100644 --- a/src/main/java/galaxyoyo/unknown/frame/listeners/MapMouseListener.java +++ b/src/main/java/galaxyoyo/gameengine/frame/listeners/MapMouseListener.java @@ -1,94 +1,94 @@ -package galaxyoyo.unknown.frame.listeners; - -import galaxyoyo.unknown.api.editor.Case; -import galaxyoyo.unknown.editor.EditorFrame; -import galaxyoyo.unknown.editor.Map; -import galaxyoyo.unknown.editor.MapPanel; - -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; - -public class MapMouseListener extends MouseAdapter -{ - private final EditorFrame frame; - private final MapPanel panel; - - public MapMouseListener(MapPanel panel, EditorFrame frame) - { - this.frame = frame; - this.panel = panel; - } - - public EditorFrame getFrame() - { - return frame; - } - - @Override - public void 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); - } - } -} +package galaxyoyo.gameengine.frame.listeners; + +import galaxyoyo.alice.gameengine.api.editor.Case; +import galaxyoyo.alice.gameengine.editor.EditorFrame; +import galaxyoyo.alice.gameengine.editor.Map; +import galaxyoyo.alice.gameengine.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 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); + } + } +} diff --git a/src/main/java/galaxyoyo/unknown/frame/listeners/OpenMapListener.java b/src/main/java/galaxyoyo/gameengine/frame/listeners/OpenMapListener.java similarity index 72% rename from src/main/java/galaxyoyo/unknown/frame/listeners/OpenMapListener.java rename to src/main/java/galaxyoyo/gameengine/frame/listeners/OpenMapListener.java index 13959bd..f8c1ac1 100644 --- a/src/main/java/galaxyoyo/unknown/frame/listeners/OpenMapListener.java +++ b/src/main/java/galaxyoyo/gameengine/frame/listeners/OpenMapListener.java @@ -1,20 +1,20 @@ -package galaxyoyo.unknown.frame.listeners; - -import galaxyoyo.unknown.api.editor.EditorAPI; -import galaxyoyo.unknown.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(); - } -} +package galaxyoyo.gameengine.frame.listeners; + +import galaxyoyo.alice.gameengine.api.editor.EditorAPI; +import galaxyoyo.gameengine.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(); + } +} diff --git a/src/main/java/galaxyoyo/unknown/frame/listeners/SpriteMouseListener.java b/src/main/java/galaxyoyo/gameengine/frame/listeners/SpriteMouseListener.java similarity index 78% rename from src/main/java/galaxyoyo/unknown/frame/listeners/SpriteMouseListener.java rename to src/main/java/galaxyoyo/gameengine/frame/listeners/SpriteMouseListener.java index 3fcd892..25f04ce 100644 --- a/src/main/java/galaxyoyo/unknown/frame/listeners/SpriteMouseListener.java +++ b/src/main/java/galaxyoyo/gameengine/frame/listeners/SpriteMouseListener.java @@ -1,32 +1,32 @@ -package galaxyoyo.unknown.frame.listeners; - -import galaxyoyo.unknown.editor.EditorFrame; -import galaxyoyo.unknown.editor.SpriteComp; - -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; - -public class SpriteMouseListener extends MouseAdapter -{ - private final SpriteComp sprite; - private final EditorFrame frame; - - public SpriteMouseListener(SpriteComp sprc, EditorFrame frame) - { - this.sprite = sprc; - this.frame = frame; - } - - @Override - public void mouseReleased(MouseEvent event) - { - if (frame.getSelectedSprite() != null) - { - frame.getSelectedSprite().setSelected(false); - frame.getSelectedSprite().repaint(); - } - frame.setSelectedSprite(sprite); - sprite.setSelected(true); - sprite.repaint(); - } -} +package galaxyoyo.gameengine.frame.listeners; + +import galaxyoyo.alice.gameengine.editor.EditorFrame; +import galaxyoyo.alice.gameengine.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(); + } +} diff --git a/src/main/java/galaxyoyo/unknown/api/editor/package-info.java b/src/main/java/galaxyoyo/unknown/api/editor/package-info.java deleted file mode 100644 index 4e404f7..0000000 --- a/src/main/java/galaxyoyo/unknown/api/editor/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * @author galaxyoyo - */ -package galaxyoyo.unknown.api.editor; \ No newline at end of file