[tiled] r678 - in trunk: . src/tiled/core src/tiled/io/xml src/tiled/mapeditor src/tiled/mapeditor/dialogs
svn@biggeruniverse.com
svn at biggeruniverse.com
Fri Jun 23 12:21:18 PDT 2006
Author: bjorn
Date: 2006-06-23 14:21:18 -0500 (Fri, 23 Jun 2006)
New Revision: 678
Added:
trunk/src/tiled/mapeditor/dialogs/TileInstancePropertiesDialog.java
Modified:
trunk/CHANGES
trunk/src/tiled/core/MapLayer.java
trunk/src/tiled/core/TileLayer.java
trunk/src/tiled/io/xml/XMLMapTransformer.java
trunk/src/tiled/io/xml/XMLMapWriter.java
trunk/src/tiled/mapeditor/MapEditor.java
Log:
Applied patch by Christian Henz and fixed a bug with the marquee selected reset.
Modified: trunk/CHANGES
===================================================================
--- trunk/CHANGES 2006-06-23 16:10:39 UTC (rev 677)
+++ trunk/CHANGES 2006-06-23 19:21:18 UTC (rev 678)
@@ -1,5 +1,6 @@
trunk
+* Added support for tile instance properties (by Christian Henz)
* Fixed selection of TMX as default map format also when plugins are loaded
* Fixed active marquee not being reset on loading a map
* Fixed layer duplicates to not share layer properties with the original
@@ -7,7 +8,7 @@
0.6.0 - June 23rd, 2006
* Added internationalization, with translations to Dutch, German, Italian,
- French and Spanish.
+ French and Spanish
* Added stamp function for pencil: right-click, drag now creates a stamp
for easy copying
* Added more error-checking to XMLMapTransformer, the default map reader
Modified: trunk/src/tiled/core/MapLayer.java
===================================================================
--- trunk/src/tiled/core/MapLayer.java 2006-06-23 16:10:39 UTC (rev 677)
+++ trunk/src/tiled/core/MapLayer.java 2006-06-23 19:21:18 UTC (rev 678)
@@ -101,7 +101,7 @@
*
* @param bounds
*/
- public void setBounds(Rectangle bounds) {
+ protected void setBounds(Rectangle bounds) {
this.bounds = new Rectangle(bounds);
}
Modified: trunk/src/tiled/core/TileLayer.java
===================================================================
--- trunk/src/tiled/core/TileLayer.java 2006-06-23 16:10:39 UTC (rev 677)
+++ trunk/src/tiled/core/TileLayer.java 2006-06-23 19:21:18 UTC (rev 678)
@@ -15,6 +15,7 @@
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.Area;
+import java.util.Properties;
/**
* A TileLayer is a specialized MapLayer, used for tracking two dimensional
@@ -25,7 +26,23 @@
public class TileLayer extends MapLayer
{
protected Tile[][] map;
+ protected Properties[][] tileInstanceProperties;
+ public Properties getTileInstancePropertiesAt(int x, int y) {
+ try {
+ return tileInstanceProperties[y - bounds.y][x - bounds.x];
+ } catch (ArrayIndexOutOfBoundsException e) {
+ return null;
+ }
+ }
+
+ public void setTileInstancePropertiesAt(int x, int y, Properties tip) {
+ try {
+ tileInstanceProperties[y - bounds.y][x - bounds.x] = tip;
+ } catch (ArrayIndexOutOfBoundsException e) {
+ }
+ }
+
/**
* Default contructor
*/
@@ -180,9 +197,10 @@
* @param bounds
* @see MapLayer#setBounds
*/
- public void setBounds(Rectangle bounds) {
+ protected void setBounds(Rectangle bounds) {
super.setBounds(bounds);
map = new Tile[bounds.height][bounds.width];
+ tileInstanceProperties = new Properties[bounds.height][bounds.width];
}
/**
@@ -258,6 +276,12 @@
try {
if (canEdit()) {
map[ty - bounds.y][tx - bounds.x] = ti;
+
+ if (ti != null) {
+ tileInstanceProperties[ty - bounds.y][tx - bounds.x] = new Properties();
+ } else {
+ tileInstanceProperties[ty - bounds.y][tx - bounds.x] = null;
+ }
}
} catch (ArrayIndexOutOfBoundsException e) {
// Silently ignore out of bounds exception
@@ -411,9 +435,20 @@
// Clone the layer data
clone.map = new Tile[map.length][];
+ clone.tileInstanceProperties = new Properties[map.length][];
+
for (int i = 0; i < map.length; i++) {
clone.map[i] = new Tile[map[i].length];
System.arraycopy(map[i], 0, clone.map[i], 0, map[i].length);
+
+ clone.tileInstanceProperties[i] = new Properties[map[i].length];
+ for (int j = 0; j < map[i].length; j++) {
+ if (map[i][j] != null) {
+ clone.tileInstanceProperties[i][j] = new Properties();
+ } else {
+ clone.tileInstanceProperties[i][j] = null;
+ }
+ }
}
return clone;
@@ -432,6 +467,7 @@
return;
Tile[][] newMap = new Tile[height][width];
+ Properties[][] newTileInstanceProperties = new Properties[height][width];
int maxX = Math.min(width, bounds.width + dx);
int maxY = Math.min(height, bounds.height + dy);
@@ -439,6 +475,7 @@
for (int x = Math.max(0, dx); x < maxX; x++) {
for (int y = Math.max(0, dy); y < maxY; y++) {
newMap[y][x] = getTileAt(x - dx, y - dy);
+ newTileInstanceProperties[y][x] = getTileInstancePropertiesAt( x - dx, y - dy );
}
}
Modified: trunk/src/tiled/io/xml/XMLMapTransformer.java
===================================================================
--- trunk/src/tiled/io/xml/XMLMapTransformer.java 2006-06-23 16:10:39 UTC (rev 677)
+++ trunk/src/tiled/io/xml/XMLMapTransformer.java 2006-06-23 19:21:18 UTC (rev 678)
@@ -87,7 +87,7 @@
} else if ("boolean".equalsIgnoreCase(parameterTypes[i].getName())) {
conformingArguments[i] = Boolean.valueOf(args[i]);
} else {
- logger.debug("Unsupported argument type " +
+ logger.debug("Unsupported argument type " +
parameterTypes[i].getName() +
", defaulting to java.lang.String");
conformingArguments[i] = args[i];
@@ -109,7 +109,7 @@
} else if ("shifted".equalsIgnoreCase(o)) {
map.setOrientation(Map.MDO_SHIFTED);
} else {
- logger.warn("Unknown orientation '" + o + "'");
+ logger.warn("Unknown orientation '" + o + "'");
}
}
@@ -163,7 +163,7 @@
reflectInvokeMethod(o,methods[j],
new String [] {n.getNodeValue()});
} else {
- logger.warn("Unsupported attribute '" +
+ logger.warn("Unsupported attribute '" +
n.getNodeName() +
"' on <" + node.getNodeName() + "> tag");
}
@@ -199,7 +199,7 @@
if ("data".equals(n.getNodeName())) {
Node cdata = n.getFirstChild();
if (cdata == null) {
- logger.warn("image <data> tag enclosed no " +
+ logger.warn("image <data> tag enclosed no " +
"data. (empty data tag)");
} else {
String sdata = cdata.getNodeValue();
@@ -257,7 +257,7 @@
for (int itr = 0; (tsNode = tsNodeList.item(itr)) != null; itr++) {
set = unmarshalTileset(tsNode);
if (set.getSource() != null) {
- logger.warn("Recursive external Tilesets are not supported.");
+ logger.warn("Recursive external Tilesets are not supported.");
}
set.setSource(filename);
// NOTE: This is a deliberate break. multiple tilesets per TSX are
@@ -267,7 +267,7 @@
xmlPath = xmlPathSave;
} catch (SAXException e) {
- logger.error("Failed while loading "+filename+": "+e.getMessage());
+ logger.error("Failed while loading "+filename+": "+e.getMessage());
//e.printStackTrace();
}
@@ -297,18 +297,18 @@
//just a little check for tricky people...
String extention = source.substring(source.lastIndexOf('.') + 1);
if (!"tsx".equals(extention.toLowerCase())) {
- logger.warn("tileset files should end in .tsx! ("+source+")");
+ logger.warn("tileset files should end in .tsx! ("+source+")");
}
InputStream in = new URL(makeUrl(filename)).openStream();
ext = unmarshalTilesetFile(in, filename);
} catch (FileNotFoundException fnf) {
- logger.error("Could not find external tileset file " +
+ logger.error("Could not find external tileset file " +
filename);
}
if (ext == null) {
- logger.error("tileset "+source+" was not loaded correctly!");
+ logger.error("tileset "+source+" was not loaded correctly!");
ext = new TileSet();
}
@@ -520,13 +520,14 @@
for (Node child = t.getFirstChild(); child != null;
child = child.getNextSibling())
{
- if ("data".equalsIgnoreCase(child.getNodeName())) {
+ String nodeName = child.getNodeName();
+ if ("data".equalsIgnoreCase(nodeName)) {
String encoding = getAttributeValue(child, "encoding");
if (encoding != null && "base64".equalsIgnoreCase(encoding)) {
Node cdata = child.getFirstChild();
if (cdata == null) {
- logger.warn("layer <data> tag enclosed no data. (empty data tag)");
+ logger.warn("layer <data> tag enclosed no data. (empty data tag)");
} else {
char[] enc = cdata.getNodeValue().trim().toCharArray();
byte[] dec = Base64.decode(enc);
@@ -562,8 +563,8 @@
} else {
int x = 0, y = 0;
for (Node dataChild = child.getFirstChild();
- dataChild != null;
- dataChild = dataChild.getNextSibling())
+ dataChild != null;
+ dataChild = dataChild.getNextSibling())
{
if ("tile".equalsIgnoreCase(dataChild.getNodeName())) {
int tileId = getAttribute(dataChild, "gid", -1);
@@ -583,6 +584,21 @@
}
}
}
+ } else if ("tileproperties".equalsIgnoreCase(nodeName)) {
+ for (Node tpn = child.getFirstChild();
+ tpn != null;
+ tpn = tpn.getNextSibling())
+ {
+ if ("tile".equalsIgnoreCase(tpn.getNodeName())) {
+ int x = getAttribute(tpn, "x", -1);
+ int y = getAttribute(tpn, "y", -1);
+
+ Properties tip = new Properties();
+
+ readProperties(tpn.getChildNodes(), tip);
+ ml.setTileInstancePropertiesAt(x, y, tip);
+ }
+ }
}
}
Modified: trunk/src/tiled/io/xml/XMLMapWriter.java
===================================================================
--- trunk/src/tiled/io/xml/XMLMapWriter.java 2006-06-23 16:10:39 UTC (rev 677)
+++ trunk/src/tiled/io/xml/XMLMapWriter.java 2006-06-23 19:21:18 UTC (rev 678)
@@ -420,6 +420,27 @@
}
}
w.endElement();
+
+ w.startElement("tileproperties");
+
+ for (int y = 0; y < l.getHeight(); y++) {
+ for (int x = 0; x < l.getWidth(); x++) {
+ Properties tip = ((TileLayer) l).getTileInstancePropertiesAt(x, y);
+
+ if (tip != null && !tip.isEmpty()) {
+ w.startElement("tile");
+
+ w.writeAttribute("x", x);
+ w.writeAttribute("y", y);
+
+ writeProperties(tip, w);
+
+ w.endElement();
+ }
+ }
+ }
+
+ w.endElement();
}
w.endElement();
}
Modified: trunk/src/tiled/mapeditor/MapEditor.java
===================================================================
--- trunk/src/tiled/mapeditor/MapEditor.java 2006-06-23 16:10:39 UTC (rev 677)
+++ trunk/src/tiled/mapeditor/MapEditor.java 2006-06-23 19:21:18 UTC (rev 678)
@@ -123,6 +123,9 @@
private AboutDialog aboutDialog;
private MapLayerEdit paintEdit;
+ private TileInstancePropertiesDialog tileInstancePropertiesDialog;
+ private JButton tileInstancePropertiesButton;
+
/** Available brushes */
private Vector brushes = new Vector();
private Brush eraserBrush;
@@ -223,6 +226,8 @@
appFrame.setVisible(true);
+ tileInstancePropertiesDialog = new TileInstancePropertiesDialog(this);
+
// Restore the state of the main frame. This needs to happen after
// making the frame visible, otherwise it has no effect (in Linux).
Preferences mainDialogPrefs = prefs.node("dialog/main");
@@ -298,7 +303,7 @@
JMenuItem save = new TMenuItem(saveAction);
JMenuItem saveAs = new TMenuItem(saveAsAction);
JMenuItem saveAsImage = createMenuItem(Resources.getString("menu.file.image"), null,
- Resources.getString("menu.file.image.tooltip"), "control shift I");
+ Resources.getString("menu.file.image.tooltip"), "control shift I");
JMenuItem close = new TMenuItem(new CloseMapAction(this, saveAction));
recentMenu = new JMenu(Resources.getString("menu.file.recent"));
@@ -346,10 +351,10 @@
editMenu.add(transformSub);
editMenu.addSeparator();
editMenu.add(createMenuItem(Resources.getString("menu.edit.preferences"),
- null, Resources.getString("menu.edit.preferences.tooltip"), null));
+ null, Resources.getString("menu.edit.preferences.tooltip"), null));
editMenu.add(createMenuItem(Resources.getString("menu.edit.brush"), null,
- Resources.getString("menu.edit.brush.tooltip"),
- "control B"));
+ Resources.getString("menu.edit.brush.tooltip"),
+ "control B"));
mapEventAdapter.addListener(copyMenuItem);
mapEventAdapter.addListener(cutMenuItem);
@@ -358,12 +363,12 @@
JMenu mapMenu = new JMenu(Resources.getString("menu.map"));
mapMenu.add(createMenuItem(Resources.getString("menu.map.resize"), null,
- Resources.getString("menu.map.resize.tooltip")));
+ Resources.getString("menu.map.resize.tooltip")));
mapMenu.add(createMenuItem(Resources.getString("menu.map.search"), null,
- Resources.getString("menu.map.search.tooltip")));
+ Resources.getString("menu.map.search.tooltip")));
mapMenu.addSeparator();
mapMenu.add(createMenuItem(Resources.getString("menu.map.properties"), null,
- Resources.getString("menu.map.properties.tooltip")));
+ Resources.getString("menu.map.properties.tooltip")));
mapEventAdapter.addListener(mapMenu);
@@ -382,16 +387,16 @@
layerMenu.add(new TMenuItem(mergeAllLayersAction));
layerMenu.addSeparator();
layerMenu.add(createMenuItem(Resources.getString("menu.layer.properties"), null,
- Resources.getString("menu.layer.properties.tooltip")));
+ Resources.getString("menu.layer.properties.tooltip")));
JMenu tilesetMenu = new JMenu(Resources.getString("menu.tilesets"));
tilesetMenu.add(createMenuItem(Resources.getString("menu.tilesets.new"), null,
- Resources.getString("menu.tilesets.new.tooltip")));
+ Resources.getString("menu.tilesets.new.tooltip")));
tilesetMenu.add(createMenuItem(Resources.getString("menu.tilesets.import"), null,
- Resources.getString("menu.tilesets.import.tooltip")));
+ Resources.getString("menu.tilesets.import.tooltip")));
tilesetMenu.addSeparator();
tilesetMenu.add(createMenuItem(Resources.getString("menu.tilesets.manager"), null,
- Resources.getString("menu.tilesets.manager.tooltip")));
+ Resources.getString("menu.tilesets.manager.tooltip")));
/*
@@ -421,7 +426,7 @@
cursorMenuItem.setSelected(prefs.getBoolean("cursorhighlight", true));
cursorMenuItem.addActionListener(this);
cursorMenuItem.setToolTipText(
- Resources.getString("menu.view.cursor.tooltip"));
+ Resources.getString("menu.view.cursor.tooltip"));
boundaryMenuItem = new JCheckBoxMenuItem(Resources.getString("menu.view.boundaries"));
boundaryMenuItem.addActionListener(this);
@@ -450,7 +455,7 @@
JMenu helpMenu = new JMenu(Resources.getString("menu.help"));
helpMenu.add(createMenuItem(Resources.getString("menu.help.plugins"), null,
- Resources.getString("menu.help.plugins.tooltip")));
+ Resources.getString("menu.help.plugins.tooltip")));
helpMenu.add(createMenuItem(Resources.getString("menu.help.about"), null, Resources.getString("menu.help.about.tooltip")));
menuBar = new JMenuBar();
@@ -569,6 +574,11 @@
layerButtons.setMaximumSize(new Dimension(Integer.MAX_VALUE,
layerButtons.getPreferredSize().height));
+ tileInstancePropertiesButton = new JButton("Properties");
+ tileInstancePropertiesButton.setActionCommand("tileInstanceProperties");
+ mapEventAdapter.addListener(tileInstancePropertiesButton);
+ tileInstancePropertiesButton.addActionListener(this);
+
// Edit history
/*
JScrollPane editSp = new JScrollPane();
@@ -592,6 +602,8 @@
layerPanel.add(new JScrollPane(layerTable), c);
c.weighty = 0; c.insets = new Insets(0, 0, 0, 0); c.gridy += 1;
layerPanel.add(layerButtons, c);
+ c.gridy += 1;
+ layerPanel.add(tileInstancePropertiesButton, c);
/*
c.weighty = 0.25; c.insets = new Insets(3, 0, 0, 0); c.gridy += 1;
layerPanel.add(editSp, c);
@@ -943,7 +955,9 @@
MapLayer layer = getCurrentLayer();
Point limp = mouseInitialPressLocation;
- if (currentPointerState == PS_MARQUEE) {
+ if (currentPointerState == PS_MARQUEE) {
+ // Uncommented to allow single tile selections
+ /*
Point tile = mapView.screenToTileCoords(event.getX(), event.getY());
if (tile.y - limp.y == 0 && tile.x - limp.x == 0) {
if (marqueeSelection != null) {
@@ -951,6 +965,10 @@
marqueeSelection = null;
}
}
+ */
+
+ // There should be a proper notification mechanism for this...
+ tileInstancePropertiesDialog.setSelection(marqueeSelection);
} else if (currentPointerState == PS_MOVE) {
if (layer != null && moveDist.x != 0 || moveDist.x != 0) {
undoSupport.postEdit(new MoveLayerEdit(layer, moveDist));
@@ -960,43 +978,43 @@
}
- //STAMP
- if (bMouseIsDragging && mouseButton == MouseEvent.BUTTON3 &&
- getCurrentLayer() instanceof TileLayer &&
- currentPointerState == PS_PAINT)
- {
- Point tile = mapView.screenToTileCoords(event.getX(), event.getY());
- int minx = Math.min(limp.x, tile.x);
- int miny = Math.min(limp.y, tile.y);
+ // STAMP
+ if (bMouseIsDragging && mouseButton == MouseEvent.BUTTON3 &&
+ getCurrentLayer() instanceof TileLayer &&
+ currentPointerState == PS_PAINT)
+ {
+ Point tile = mapView.screenToTileCoords(event.getX(), event.getY());
+ int minx = Math.min(limp.x, tile.x);
+ int miny = Math.min(limp.y, tile.y);
- Rectangle bounds = new Rectangle(
- minx, miny,
- (Math.max(limp.x, tile.x) - minx)+1,
- (Math.max(limp.y, tile.y) - miny)+1);
+ Rectangle bounds = new Rectangle(
+ minx, miny,
+ (Math.max(limp.x, tile.x) - minx) + 1,
+ (Math.max(limp.y, tile.y) - miny) + 1);
- // Right mouse button dragged: create and set custom brush
- MultilayerPlane mlp =
- new MultilayerPlane(bounds.width, bounds.height);
- TileLayer brushLayer = new TileLayer(bounds);
- brushLayer.copyFrom(getCurrentLayer());
+ // Right mouse button dragged: create and set custom brush
+ MultilayerPlane mlp =
+ new MultilayerPlane(bounds.width, bounds.height);
+ TileLayer brushLayer = new TileLayer(bounds);
+ brushLayer.copyFrom(getCurrentLayer());
- //do a quick check to make sure the selection is not empty
- if(brushLayer.isEmpty()) {
- JOptionPane.showMessageDialog(appFrame,
- Resources.getString("dialog.selection.empty"),
- Resources.getString("dialog.selection.empty"),
- JOptionPane.WARNING_MESSAGE);
- } else {
- mlp.addLayer(brushLayer);
- setBrush(new CustomBrush(mlp));
- }
+ // Do a quick check to make sure the selection is not empty
+ if (brushLayer.isEmpty()) {
+ JOptionPane.showMessageDialog(appFrame,
+ Resources.getString("dialog.selection.empty"),
+ Resources.getString("dialog.selection.empty"),
+ JOptionPane.WARNING_MESSAGE);
+ } else {
+ mlp.addLayer(brushLayer);
+ setBrush(new CustomBrush(mlp));
+ }
- //get rid of any visible marquee
- if (marqueeSelection != null) {
- currentMap.removeLayerSpecial(marqueeSelection);
- marqueeSelection = null;
- }
- }
+ //get rid of any visible marquee
+ if (marqueeSelection != null) {
+ currentMap.removeLayerSpecial(marqueeSelection);
+ marqueeSelection = null;
+ }
+ }
if (paintEdit != null) {
if (layer != null) {
@@ -1057,13 +1075,13 @@
brushRedraw.y = tile.y - brushRedraw.height / 2;
if (!redraw.equals(brushRedraw)) {
- mapView.repaintRegion(redraw);
- cursorHighlight.setOffset(brushRedraw.x, brushRedraw.y);
+ mapView.repaintRegion(redraw);
+ cursorHighlight.setOffset(brushRedraw.x, brushRedraw.y);
//cursorHighlight.selectRegion(currentBrush.getShape());
- mapView.repaintRegion(brushRedraw);
- /*if(currentBrush instanceof CustomBrush) {
- mapView.paintSubMap(currentBrush, null, 0.5f);
- }*/
+ mapView.repaintRegion(brushRedraw);
+ /*if(currentBrush instanceof CustomBrush) {
+ mapView.paintSubMap(currentBrush, null, 0.5f);
+ }*/
}
}
}
@@ -1103,6 +1121,10 @@
}
tilePaletteDialog.setVisible(true);
}
+ } else if (command.equals("tileInstanceProperties")) {
+ if (currentMap != null) {
+ tileInstancePropertiesDialog.setVisible(true);
+ }
} else {
handleEvent(event);
}
@@ -1688,16 +1710,16 @@
Rectangle brushRedraw = currentBrush.getBounds();
- //make sure it's clean
- cursorHighlight.setOffset(0,0);
+ // Make sure it's clean
+ cursorHighlight.setOffset(0, 0);
- //resize and select the region
- cursorHighlight.resize(brushRedraw.width, brushRedraw.height,0,0);
+ // Resize and select the region
+ cursorHighlight.resize(brushRedraw.width, brushRedraw.height, 0, 0);
cursorHighlight.selectRegion(currentBrush.getShape());
- /*if(currentBrush instanceof CustomBrush) {
- cursorHighlight.setVisible(false);
+ /*if (currentBrush instanceof CustomBrush) {
+ cursorHighlight.setVisible(false);
} else {
- cursorHighlight.setVisible(true);
+ cursorHighlight.setVisible(true);
}*/
}
@@ -1751,7 +1773,7 @@
return true;
} else {
JOptionPane.showMessageDialog(appFrame,
- Resources.getString("general.file.failed"),
+ Resources.getString("general.file.failed"),
Resources.getString("dialog.openmap.error.title"),
JOptionPane.ERROR_MESSAGE);
}
@@ -1837,6 +1859,12 @@
}
public void setCurrentMap(Map newMap) {
+ // Cancel any active selection
+ if (marqueeSelection != null) {
+ currentMap.removeLayerSpecial(marqueeSelection);
+ }
+ marqueeSelection = null;
+
currentMap = newMap;
boolean mapLoaded = currentMap != null;
@@ -1845,12 +1873,6 @@
sb.makeQuadBrush(new Rectangle(0, 0, 1, 1));
setBrush(sb);
- // Cancel any active selection
- if (marqueeSelection != null) {
- currentMap.removeLayerSpecial(marqueeSelection);
- }
- marqueeSelection = null;
-
if (!mapLoaded) {
mapEventAdapter.fireEvent(MapEventAdapter.ME_MAPINACTIVE);
mapView = null;
@@ -1904,11 +1926,12 @@
Tile firstTile = null;
if (!tilesets.isEmpty()) {
Iterator it = tilesets.iterator();
- while(it.hasNext() && firstTile == null) {
- TileSet set = (TileSet)it.next();
- int i=0;
- while(firstTile == null && i < set.getMaxTileId()) {
- firstTile = set.getTile(i++);
+ while (it.hasNext() && firstTile == null) {
+ TileSet set = (TileSet) it.next();
+ int i = 0;
+ while (firstTile == null && i < set.getMaxTileId()) {
+ firstTile = set.getTile(i);
+ i++;
}
}
}
Added: trunk/src/tiled/mapeditor/dialogs/TileInstancePropertiesDialog.java
===================================================================
--- trunk/src/tiled/mapeditor/dialogs/TileInstancePropertiesDialog.java 2006-06-23 16:10:39 UTC (rev 677)
+++ trunk/src/tiled/mapeditor/dialogs/TileInstancePropertiesDialog.java 2006-06-23 19:21:18 UTC (rev 678)
@@ -0,0 +1,234 @@
+/*
+ * Tiled Map Editor, (c) 2004-2006
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Adam Turk <aturk at biggeruniverse.com>
+ * Bjorn Lindeijer <b.lindeijer at xs4all.nl>
+ */
+
+package tiled.mapeditor.dialogs;
+
+import java.awt.Dimension;
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Enumeration;
+import java.util.LinkedList;
+import java.util.Properties;
+import javax.swing.*;
+
+import tiled.core.MapLayer;
+import tiled.core.Tile;
+import tiled.core.TileLayer;
+import tiled.mapeditor.MapEditor;
+import tiled.mapeditor.Resources;
+import tiled.mapeditor.selection.SelectionLayer;
+import tiled.mapeditor.util.PropertiesTableModel;
+import tiled.mapeditor.widget.VerticalStaticJPanel;
+
+/**
+ * @version $Id$
+ */
+public class TileInstancePropertiesDialog extends JDialog
+{
+ private JTable tProperties;
+ private Properties properties = new Properties();
+ private PropertiesTableModel tableModel = new PropertiesTableModel();
+
+ private static final String DIALOG_TITLE = "Tile Properties"; // Resource this
+ private static final String APPLY_BUTTON = "Apply"; // Resource this
+ private static final String APPLY_TOOLTIP = "Apply properties to selected tiles"; // Resource this
+ private static final String DELETE_BUTTON = Resources.getString("general.button.delete");
+
+ private final MapEditor editor;
+ private LinkedList propertiesList = new LinkedList(); // Holds all currently selected Properties
+
+ public TileInstancePropertiesDialog(MapEditor editor) {
+ super(editor.getAppFrame(), DIALOG_TITLE, false);
+ this.editor = editor;
+ init();
+ pack();
+ setLocationRelativeTo(getOwner());
+ }
+
+ private void init() {
+ tProperties = new JTable(tableModel);
+ JScrollPane propScrollPane = new JScrollPane(tProperties);
+ propScrollPane.setPreferredSize(new Dimension(200, 150));
+
+ JButton applyButton = new JButton(APPLY_BUTTON);
+ applyButton.setToolTipText(APPLY_TOOLTIP);
+ JButton deleteButton = new JButton(Resources.getIcon("gnome-delete.png"));
+ deleteButton.setToolTipText(DELETE_BUTTON);
+
+ JPanel user = new VerticalStaticJPanel();
+ user.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
+ user.setLayout(new BoxLayout(user, BoxLayout.X_AXIS));
+ user.add(Box.createGlue());
+ user.add(Box.createRigidArea(new Dimension(5, 0)));
+ user.add(deleteButton);
+
+ JPanel buttons = new VerticalStaticJPanel();
+ buttons.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
+ buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
+ buttons.add(Box.createGlue());
+ buttons.add(applyButton);
+
+ JPanel mainPanel = new JPanel();
+ mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
+ mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
+ mainPanel.add(propScrollPane);
+ mainPanel.add(user);
+ mainPanel.add(buttons);
+
+ getContentPane().add(mainPanel);
+ getRootPane().setDefaultButton(applyButton);
+
+ //create actionlisteners
+ applyButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent actionEvent) {
+ buildPropertiesAndApply();
+ }
+ });
+
+ deleteButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent actionEvent) {
+ deleteSelected();
+ }
+ });
+ }
+
+ public void setSelection(SelectionLayer selection) {
+ // Start off fresh...
+ properties.clear();
+ propertiesList.clear();
+
+ // Get all properties of all selected tiles...
+ MapLayer ml = editor.getCurrentLayer();
+ if (ml instanceof TileLayer) {
+ TileLayer tl = (TileLayer) ml;
+ Rectangle r = selection.getSelectedAreaBounds();
+ int maxJ = (int) (r.getY() + r.getHeight());
+ int maxI = (int) (r.getX() + r.getWidth());
+
+ for (int j = (int) r.getY(); j < maxJ; j++) {
+ for (int i = (int) r.getX(); i < maxI; i++) {
+ Tile t = selection.getTileAt(i, j);
+ if (t != null) {
+ Properties p = tl.getTileInstancePropertiesAt(i, j);
+ if (p != null) propertiesList.add(p);
+ }
+ }
+ }
+ }
+
+ if (!propertiesList.isEmpty()) {
+ // Start with properties of first tile instance
+ Properties p = (Properties) propertiesList.get(0);
+
+ for (Enumeration e = p.keys(); e.hasMoreElements();) {
+ String key = (String) e.nextElement();
+ properties.put(key, p.getProperty(key));
+ }
+
+ for (int i = 1; i < propertiesList.size(); i++) {
+ // Merge the other properties...
+ p = (Properties) propertiesList.get(i);
+
+ for (Enumeration e = properties.keys(); e.hasMoreElements();) {
+ // We only care for properties that are already "known"...
+
+ String key = (String) e.nextElement();
+ String val = properties.getProperty(key);
+ String mval = p.getProperty(key);
+
+ if (mval == null) {
+ properties.remove(key); // Drop non-common properties
+ } else if (!mval.equals(val)) {
+ properties.setProperty(key, "?"); // Hide non-common values
+ }
+ }
+ }
+ }
+
+ updateInfo(); // Refresh display
+ }
+
+ private void updateInfo() {
+ // Make a copy of the properties that will be changed by the
+ // properties table model.
+ Properties props = new Properties();
+ Enumeration keys = properties.keys();
+ while (keys.hasMoreElements()) {
+ String key = (String) keys.nextElement();
+ props.put(key, properties.getProperty(key));
+ }
+ tableModel.update(props);
+ }
+
+ public void getProps() {
+ updateInfo();
+ setVisible(true);
+ }
+
+ private void buildPropertiesAndApply() {
+ // Copy over the new set of properties from the properties table
+ // model.
+
+ properties.clear();
+
+ Properties newProps = tableModel.getProperties();
+ Enumeration keys = newProps.keys();
+ while (keys.hasMoreElements()) {
+ String key = (String) keys.nextElement();
+ properties.put(key, newProps.getProperty(key));
+ }
+
+ applyPropertiesToTiles();
+ }
+
+
+ private void deleteFromSelectedTiles(String key) {
+ for (int i = 0; i < propertiesList.size(); i++) {
+ Properties p = (Properties) propertiesList.get(i);
+ p.remove(key);
+ }
+ }
+
+ private void deleteSelected() {
+ int total = tProperties.getSelectedRowCount();
+ Object[] keys = new Object[total];
+ int[] selRows = tProperties.getSelectedRows();
+
+ for (int i = 0; i < total; i++) {
+ keys[i] = tProperties.getValueAt(selRows[i], 0);
+ }
+
+ for (int i = 0; i < total; i++) {
+ if (keys[i] != null) {
+ tableModel.remove(keys[i]);
+ deleteFromSelectedTiles((String) keys[i]);
+ }
+ }
+ }
+
+ private void applyPropertiesToTiles() {
+ for (int i = 0; i < propertiesList.size(); i++) {
+ Properties tp = (Properties) propertiesList.get(i);
+
+ for (Enumeration e = properties.keys();
+ e.hasMoreElements();) {
+
+ String key = (String) e.nextElement();
+ String val = properties.getProperty(key);
+ if (!val.equals("?")) {
+ tp.setProperty(key, val);
+ }
+ }
+ }
+ }
+}
Property changes on: trunk/src/tiled/mapeditor/dialogs/TileInstancePropertiesDialog.java
___________________________________________________________________
Name: svn:keywords
+ Id
More information about the tiled-commit
mailing list