Skip to content
Browse files

Merge branch '0.7'

Conflicts:
	.hgignore
	src/tiled/mapeditor/MapEditor.java
	src/tiled/view/IsoMapView.java
  • Loading branch information...
2 parents 6535b2e + 38dc196 commit 3e77ba2f64f7a08287a3cad6365d01a44c09b954 @bjorn committed Nov 24, 2011
View
14 .hgignore
@@ -1,11 +1,13 @@
-syntax: glob
-*.class
-*.jar
-build/*
-intellij/*
+syntax: glob
+*.class
+*.jar
+build/*
+docs/*
+intellij/*
+docs/api/*
+releases/*.zip
\.orig\..*$
\.orig$
\.chg\..*$
\.rej$
\.conflict\~$
-docs/api/*
View
7 CHANGES
@@ -1,5 +1,12 @@
+0.7.2 - November 30th, 2008
+
* Added support for associating an image with a map object
* Fixed not being able to move an object group
+* Fixed unable to select small map objects
+* Fixed references to external tilesets that are not in the same directory
+* Fixed some files missing from tiled-core.jar
+* Updated The Mana World plugin to detect the collision layer correctly
+* Updated minimum Java version to 1.5
0.7.1 - September 2nd, 2008
View
2 TODO
@@ -1,6 +1,6 @@
ROADMAP TO FUTURE RELEASES
-0.7.2
+0.7.3
* Check that tile palette panel doesn't keep listening after being replaced
* Update translations for dialog.saveas.confirm.mismatch
* Make continuous layout and tiles per row behaviour configurable
View
2 plugins/json/build.xml
@@ -10,7 +10,7 @@
<target name="dist" description="Generate the JSON writer plugin">
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
- <javac source="1.4" target="1.4" srcdir="${src}" destdir="${build}" classpath="${dist}/tiled.jar"/>
+ <javac source="1.5" target="1.5" srcdir="${src}" destdir="${build}" classpath="${dist}/tiled.jar"/>
<jar
jarfile="${dist}/plugins/json.jar"
manifest="MANIFEST.MF"
View
2 plugins/json/src/org/json/CookieList.java
@@ -51,7 +51,7 @@ public static JSONObject toJSONObject(String string)
*/
public static String toString(JSONObject o) {
boolean b = false;
- Iterator keys = o.keys();
+ Iterator<String> keys = o.keys();
String s;
StringBuffer sb = new StringBuffer();
while (keys.hasNext()) {
View
2 plugins/json/src/org/json/HTTP.java
@@ -107,7 +107,7 @@ public static JSONObject toJSONObject(String string) throws ParseException {
* information.
*/
public static String toString(JSONObject o) throws NoSuchElementException {
- Iterator keys = o.keys();
+ Iterator<String> keys = o.keys();
String s;
StringBuffer sb = new StringBuffer();
if (o.has("Status-Code") && o.has("Reason-Phrase")) {
View
10 plugins/json/src/org/json/JSONArray.java
@@ -47,14 +47,14 @@
/**
* The getArrayList where the JSONArray's properties are kept.
*/
- private ArrayList myArrayList;
+ private ArrayList<Object> myArrayList;
/**
* Construct an empty JSONArray.
*/
public JSONArray() {
- myArrayList = new ArrayList();
+ myArrayList = new ArrayList<Object>();
}
@@ -113,8 +113,8 @@ public JSONArray(String string) throws ParseException {
* Construct a JSONArray from a Collection.
* @param collection A Collection.
*/
- public JSONArray(Collection collection) {
- myArrayList = new ArrayList(collection);
+ public JSONArray(Collection<Object> collection) {
+ myArrayList = new ArrayList<Object>(collection);
}
@@ -139,7 +139,7 @@ public Object get(int index) throws NoSuchElementException {
* Get the ArrayList which is holding the elements of the JSONArray.
* @return The ArrayList.
*/
- ArrayList getArrayList() {
+ ArrayList<Object> getArrayList() {
return myArrayList;
}
View
18 plugins/json/src/org/json/JSONObject.java
@@ -92,7 +92,7 @@ public String toString() {
/**
* The hash map where the JSONObject's properties are kept.
*/
- private HashMap myHashMap;
+ private HashMap<String, Object> myHashMap;
/**
* It is sometimes more convenient and less ambiguous to have a NULL
@@ -106,7 +106,7 @@ public String toString() {
* Construct an empty JSONObject.
*/
public JSONObject() {
- myHashMap = new HashMap();
+ myHashMap = new HashMap<String, Object>();
}
@@ -175,8 +175,8 @@ public JSONObject(String string) throws ParseException {
* @param map A map object that can be used to initialize the contents of
* the JSONObject.
*/
- public JSONObject(Map map) {
- myHashMap = new HashMap(map);
+ public JSONObject(Map<String, Object> map) {
+ myHashMap = new HashMap<String, Object>(map);
}
@@ -278,7 +278,7 @@ public double getDouble(String key)
* Get the HashMap the holds that contents of the JSONObject.
* @return The getHashMap.
*/
- HashMap getHashMap() {
+ HashMap<String, Object> getHashMap() {
return myHashMap;
}
@@ -373,7 +373,7 @@ public boolean isNull(String key) {
*
* @return An iterator of the keys.
*/
- public Iterator keys() {
+ public Iterator<String> keys() {
return myHashMap.keySet().iterator();
}
@@ -396,7 +396,7 @@ public int length() {
*/
public JSONArray names() {
JSONArray ja = new JSONArray();
- Iterator keys = keys();
+ Iterator<String> keys = keys();
while (keys.hasNext()) {
ja.put(keys.next());
}
@@ -805,7 +805,7 @@ public JSONArray toJSONArray(JSONArray names) {
* with <code>}</code>&nbsp;<small>(right brace)</small>.
*/
public String toString() {
- Iterator keys = keys();
+ Iterator<String> keys = keys();
Object o = null;
String s;
StringBuffer sb = new StringBuffer();
@@ -864,7 +864,7 @@ public String toString(int indentFactor) {
*/
String toString(int indentFactor, int indent) {
int i;
- Iterator keys = keys();
+ Iterator<String> keys = keys();
String pad = "";
StringBuffer sb = new StringBuffer();
indent += indentFactor;
View
2 plugins/json/src/org/json/XML.java
@@ -266,7 +266,7 @@ public static String toString(Object o, String tagName) {
JSONArray ja;
JSONObject jo;
String k;
- Iterator keys;
+ Iterator<String> keys;
int len;
String s;
Object v;
View
4 plugins/json/src/org/json/XMLTokener.java
@@ -16,10 +16,10 @@
/** The table of entity values. It initially contains Character values for
* amp, apos, gt, lt, quot.
*/
- private static final HashMap entity;
+ private static final HashMap<String, Character> entity;
static {
- entity = new HashMap(8);
+ entity = new HashMap<String, Character>(8);
entity.put("amp", XML.AMP);
entity.put("apos", XML.APOS);
entity.put("gt", XML.GT);
View
2 src/tiled/io/xml/XMLMapTransformer.java
@@ -817,7 +817,7 @@ private Map unmarshal(InputStream in) throws Exception {
builder.setEntityResolver(entityResolver);
InputSource insrc = new InputSource(in);
insrc.setSystemId(xmlPath);
- insrc.setEncoding("UTF8");
+ insrc.setEncoding("UTF-8");
doc = builder.parse(insrc);
} catch (SAXException e) {
e.printStackTrace();
View
18 src/tiled/io/xml/XMLMapWriter.java
@@ -16,6 +16,7 @@
import java.awt.Image;
import java.awt.Rectangle;
import java.io.*;
+import java.nio.charset.Charset;
import java.util.*;
import java.util.prefs.Preferences;
import java.util.zip.GZIPOutputStream;
@@ -58,7 +59,7 @@ public void writeMap(Map map, String filename) throws Exception {
os = new GZIPOutputStream(os);
}
- Writer writer = new OutputStreamWriter(os);
+ Writer writer = new OutputStreamWriter(os, Charset.forName("UTF-8"));
XMLWriter xmlWriter = new XMLWriter(writer);
xmlWriter.startDocument();
@@ -81,7 +82,7 @@ public void writeMap(Map map, String filename) throws Exception {
*/
public void writeTileset(TileSet set, String filename) throws Exception {
OutputStream os = new FileOutputStream(filename);
- Writer writer = new OutputStreamWriter(os);
+ Writer writer = new OutputStreamWriter(os, Charset.forName("UTF-8"));
XMLWriter xmlWriter = new XMLWriter(writer);
xmlWriter.startDocument();
@@ -93,7 +94,7 @@ public void writeTileset(TileSet set, String filename) throws Exception {
public void writeMap(Map map, OutputStream out) throws Exception {
- Writer writer = new OutputStreamWriter(out);
+ Writer writer = new OutputStreamWriter(out,Charset.forName("UTF-8"));
XMLWriter xmlWriter = new XMLWriter(writer);
xmlWriter.startDocument();
@@ -104,7 +105,7 @@ public void writeMap(Map map, OutputStream out) throws Exception {
}
public void writeTileset(TileSet set, OutputStream out) throws Exception {
- Writer writer = new OutputStreamWriter(out);
+ Writer writer = new OutputStreamWriter(out, Charset.forName("UTF-8"));
XMLWriter xmlWriter = new XMLWriter(writer);
xmlWriter.startDocument();
@@ -164,7 +165,7 @@ private static void writeProperties(Properties props, XMLWriter w) throws
IOException
{
if (!props.isEmpty()) {
- final SortedSet propertyKeys = new TreeSet();
+ final SortedSet<Object> propertyKeys = new TreeSet<Object>();
propertyKeys.addAll(props.keySet());
w.startElement("properties");
for (Object propertyKey : propertyKeys) {
@@ -259,13 +260,12 @@ private void writeTileset(TileSet set, XMLWriter w, String wp)
String name = set.getName();
w.startElement("tileset");
+ w.writeAttribute("firstgid", set.getFirstGid());
if (name != null) {
w.writeAttribute("name", name);
}
- w.writeAttribute("firstgid", set.getFirstGid());
-
if (tilebmpFile != null) {
w.writeAttribute("tilewidth", set.getTileWidth());
w.writeAttribute("tileheight", set.getTileHeight());
@@ -296,7 +296,7 @@ private void writeTileset(TileSet set, XMLWriter w, String wp)
w.endElement();
// Write tile properties when necessary.
- Iterator tileIterator = set.iterator();
+ Iterator<Object> tileIterator = set.iterator();
while (tileIterator.hasNext()) {
Tile tile = (Tile) tileIterator.next();
@@ -345,7 +345,7 @@ private void writeTileset(TileSet set, XMLWriter w, String wp)
}
// Check to see if there is a need to write tile elements
- Iterator tileIterator = set.iterator();
+ Iterator<Object> tileIterator = set.iterator();
boolean needWrite = !set.isOneForOne();
if (!tileSetImages) {
View
5,016 src/tiled/mapeditor/MapEditor.java
2,508 additions, 2,508 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
148 src/tiled/view/IsoMapView.java
@@ -8,6 +8,9 @@
*
* Adam Turk <aturk@biggeruniverse.com>
* Bjorn Lindeijer <bjorn@lindeijer.nl>
+ *
+ * screenToPixelCoords and paintObjectGroup
+ * implemented by: Alturos <alturos@gmail.com>
*/
package tiled.view;
@@ -16,16 +19,14 @@
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
import javax.swing.SwingConstants;
+import java.util.Iterator;
+import java.util.Properties;
-import tiled.core.Map;
-import tiled.core.MapLayer;
-import tiled.core.ObjectGroup;
-import tiled.core.Tile;
-import tiled.core.TileLayer;
+import tiled.core.*;
import tiled.mapeditor.selection.SelectionLayer;
/**
- * @version $Id$
+ * Isometric map view implementation.
*/
public class IsoMapView extends MapView
{
@@ -119,8 +120,65 @@ protected void paintLayer(Graphics2D g2d, TileLayer layer) {
}
}
- protected void paintObjectGroup(Graphics2D g2d, ObjectGroup og) {
- // TODO: Implement objectgroup painting for IsoMapView
+ protected void paintObjectGroup(Graphics2D g2d, ObjectGroup og)
+ {
+ final Dimension tsize = getTileSize();
+ final Rectangle bounds = og.getBounds();
+
+ Iterator<MapObject> itr = og.getObjects();
+ g2d.translate(bounds.x * tsize.width, bounds.y * tsize.height);
+
+ while (itr.hasNext()) {
+ MapObject mo = itr.next();
+ final double oxi = mo.getX() * zoom;
+ final double oyi = mo.getY() * zoom;
+
+ Point objTileCoords = pixelToTileCoords((int) oxi, (int) oyi);
+ Point objScreenCoords = tileToScreenCoords(og,
+ objTileCoords.x,
+ objTileCoords.y);
+ int ox = objScreenCoords.x;
+ int oy = objScreenCoords.y;
+
+ Image objectImage = mo.getImage(zoom);
+ if (objectImage != null) {
+ g2d.drawImage(objectImage, (int) ox, (int) oy, null);
+ }
+ if (mo.getWidth() == 0 || mo.getHeight() == 0) {
+ g2d.setRenderingHint(
+ RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+ g2d.setColor(Color.black);
+ g2d.fillOval(
+ (int) ox + 1, (int) oy + 1,
+ (int) (10 * zoom), (int) (10 * zoom));
+ g2d.setColor(Color.orange);
+ g2d.fillOval(
+ (int) ox, (int) oy,
+ (int) (10 * zoom), (int) (10 * zoom));
+ g2d.setRenderingHint(
+ RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_OFF);
+ }
+ else {
+ g2d.setColor(Color.black);
+ objScreenCoords.x += 1;
+ objScreenCoords.y += 1;
+ g2d.drawPolygon(getObjectPolygon(mo,objScreenCoords));
+ objScreenCoords.x -= 1;
+ objScreenCoords.y -= 1;
+ g2d.setColor(Color.orange);
+ g2d.drawPolygon(getObjectPolygon(mo,objScreenCoords));
+ }
+ if (zoom > 0.0625) {
+ final String s = mo.getName() != null ? mo.getName() : "(null)";
+ int XOffset = (s.length() / 2) * 6;
+ g2d.setColor(Color.black);
+ g2d.drawString(s, (int) (ox - XOffset) + 1, (int) (oy - 5) + 1);
+ g2d.setColor(Color.white);
+ g2d.drawString(s, (int) (ox - XOffset), (int) (oy - 5));
+ }
+ }
}
protected void paintGrid(Graphics2D g2d) {
@@ -271,6 +329,33 @@ public Point screenToTileCoords(MapLayer layer,int x, int y) {
(my < 0 ? my - tileSize.height : my) / tileSize.height);
}
+ /**
+ * Returns the coordinates the mouse arrow in MapPixel Coords.
+ */
+ public Point screenToPixelCoords(int x, int y)
+ {
+ Dimension tileSize = getTileSize();
+ double r = getTileRatio();
+
+ // Translate origin to top-center
+ x -= map.getHeight() * (tileSize.width / 2);
+ int mx = y + (int) (x / r);
+ int my = y - (int) (x / r);
+
+ my /= zoom;
+ mx /= zoom;
+
+ // Calculate map coords and divide by tile size (tiles assumed to
+ // be square in normal projection)
+ return new Point(
+ (mx < 0 ? mx - tileSize.height : (int) (mx * r)),
+ (my < 0 ? my - tileSize.height : my));
+ //Point pos = screenToTileCoords(x, y);
+ //pos.x = ((pos.x * map.getTileWidth()));
+ //pos.y = ((pos.y * map.getTileHeight()));
+ //return pos;
+ }
+
protected Polygon createGridPolygon(Dimension tileSize, int tx, int ty, int border) {
tileSize.width -= border * 2;
tileSize.height -= border * 2;
@@ -294,6 +379,53 @@ protected double getTileRatio() {
return (double)map.getTileWidth() / (double)map.getTileHeight();
}
+ protected Point pixelToTileCoords(int x, int y)
+ {
+ Point TilePos = new Point();
+ Dimension tileSize = getTileSize();
+ // First, make sure we are at the top left corner
+
+ x = x - (x % tileSize.width);
+ y = y - (y % tileSize.height);
+
+ TilePos.x = (int) ((x / tileSize.width));
+ TilePos.y = (int) ((y / tileSize.height));
+ return TilePos;
+ }
+
+ protected Polygon getObjectPolygon(MapObject mo, Point topLeftScr)
+ {
+ // The number of pixels short of a full tile.
+ // This promotes drawing only a full tile worth of outline
+ final int xTOffset = (mo.getWidth() % map.getTileWidth());
+ final int yTOffset = (mo.getHeight() % map.getTileHeight());
+
+ // The number of tilews wide and deep the object is
+ final int xTiles = ((mo.getWidth() + xTOffset) / map.getTileWidth());
+ final int yTiles = ((mo.getHeight() + yTOffset) / map.getTileHeight());
+
+ final int halfWidth = (int) (map.getTileWidth() * zoom) / 2;
+ final int halfHeight = (int) (map.getTileHeight() * zoom) / 2;
+
+ Polygon poly = new Polygon();
+ // Top left
+ poly.addPoint(topLeftScr.x, topLeftScr.y);
+ // Top Right
+ poly.addPoint(
+ (topLeftScr.x + (halfWidth * xTiles)),
+ (topLeftScr.y + (halfHeight * xTiles)));
+ // Bottom Right
+ poly.addPoint(
+ (topLeftScr.x + ((xTiles - yTiles) * halfWidth)),
+ (topLeftScr.y + ((xTiles + yTiles) * halfHeight)));
+ // Bottom Left
+ poly.addPoint(
+ (topLeftScr.x - (yTiles * halfWidth)),
+ (topLeftScr.y + (yTiles * halfHeight)));
+
+ return poly;
+ }
+
/**
* Returns the location on the screen of the top corner of a tile.
*/

0 comments on commit 3e77ba2

Please sign in to comment.
Something went wrong with that request. Please try again.