[tiled] r733 - in trunk: . src/tiled/core src/tiled/io src/tiled/io/xml src/tiled/mapeditor src/tiled/mapeditor/dialogs src/tiled/mapeditor/resources src/tiled/view

tiled-svn at biggeruniverse.com tiled-svn at biggeruniverse.com
Sun Mar 23 12:44:39 PDT 2008


Author: aturk
Date: 2008-03-23 13:44:39 -0600 (Sun, 23 Mar 2008)
New Revision: 733

Modified:
   trunk/TODO
   trunk/src/tiled/core/MapLayer.java
   trunk/src/tiled/core/ObjectGroup.java
   trunk/src/tiled/core/TileLayer.java
   trunk/src/tiled/core/TileSet.java
   trunk/src/tiled/io/MapHelper.java
   trunk/src/tiled/io/xml/XMLWriter.java
   trunk/src/tiled/mapeditor/MapEditor.java
   trunk/src/tiled/mapeditor/dialogs/ConfigurationDialog.java
   trunk/src/tiled/mapeditor/resources/gui.properties
   trunk/src/tiled/view/MapView.java
   trunk/src/tiled/view/OrthoMapView.java
Log:
+ Added deep copy (copies all layers to single clipboard layer)-
  required maskedMergeOnto for MapLayer.
+ The "P" thing for properties wasn't doing it for me, replaced with some prototype code.
+ Though I don't know that I ever saw it happen, XMLWriter 
  wasn't always flushing the last thing written, meaning the document
  could end up incomplete on close.
+ Updated TODO per convo with Bj?\195?\184rn

Modified: trunk/TODO
===================================================================
--- trunk/TODO	2007-12-06 17:11:54 UTC (rev 732)
+++ trunk/TODO	2008-03-23 19:44:39 UTC (rev 733)
@@ -7,13 +7,17 @@
 * Make continuous layout and tiles per row behaviour configurable
 * Fix default tabbed tilesets panel height
 * Fix redraw issue on empty area in tile palette panel
+* Fix Object editing to be less confusing
+* Fix remembering docking
 * Replace tile button with a brush preview beneath the layer table
 * Do not reset brush when switching tools (but do show a small tile highlight
   while other tools than stamp brush are selected)
 * Add support for tile instance properties (see Christian's patch) (WIP)
-  - Implement an effective way of displaying the presence of these properties
+- Implement an effective way of displaying the presence of these properties
 * Add support for arbitrary objects and zones placement (ElvenProgrammer)
 * Add separate buttons for adding and removing objects, and enable/disable them depending on the selected layer
++ Add Shift-Ctrl-C deep copy (Copies all layers into a new one)
+* Add custom brush from selection (via Ctrl-B)
 * Update map view when showing/hiding an object group
 
 0.8.0

Modified: trunk/src/tiled/core/MapLayer.java
===================================================================
--- trunk/src/tiled/core/MapLayer.java	2007-12-06 17:11:54 UTC (rev 732)
+++ trunk/src/tiled/core/MapLayer.java	2008-03-23 19:44:39 UTC (rev 733)
@@ -238,8 +238,18 @@
         return isVisible;
     }
 
+    /**
+     * Merges the tile data of this layer with the specified layer. The calling
+     * layer is considered the significant layer, and will overwrite the data
+     * of the argument layer. At cells where the calling layer has no data, the
+     * argument layer data is preserved.
+     *
+     * @param other the insignificant layer to merge with
+     */
     public abstract void mergeOnto(MapLayer other);
 
+    public abstract void maskedMergeOnto(MapLayer other, Area mask);
+    
     public abstract void copyFrom(MapLayer other);
 
     public abstract void maskedCopyFrom(MapLayer other, Area mask);

Modified: trunk/src/tiled/core/ObjectGroup.java
===================================================================
--- trunk/src/tiled/core/ObjectGroup.java	2007-12-06 17:11:54 UTC (rev 732)
+++ trunk/src/tiled/core/ObjectGroup.java	2008-03-23 19:44:39 UTC (rev 733)
@@ -71,6 +71,9 @@
     public void mergeOnto(MapLayer other) {
     }
 
+    public void maskedMergeOnto(MapLayer other, Area mask) {
+    }
+    
     public void copyFrom(MapLayer other) {
     }
 

Modified: trunk/src/tiled/core/TileLayer.java
===================================================================
--- trunk/src/tiled/core/TileLayer.java	2007-12-06 17:11:54 UTC (rev 732)
+++ trunk/src/tiled/core/TileLayer.java	2008-03-23 19:44:39 UTC (rev 733)
@@ -337,12 +337,7 @@
     }
 
     /**
-     * Merges the tile data of this layer with the specified layer. The calling
-     * layer is considered the significant layer, and will overwrite the data
-     * of the argument layer. At cells where the calling layer has no data, the
-     * argument layer data is preserved.
-     *
-     * @param other the insignificant layer to merge with
+     * @inheritDoc MapLayer#mergeOnto(MapLayer)
      */
     public void mergeOnto(MapLayer other) {
         if (!other.canEdit())
@@ -359,6 +354,29 @@
     }
 
     /**
+     * Like mergeOnto, but will only copy the area specified.
+     *
+     * @see TileLayer#mergeOnto(MapLayer)
+     * @param other
+     * @param mask
+     */
+    public void maskedMergeOnto(MapLayer other, Area mask) {
+        if (!canEdit())
+            return;
+
+        Rectangle boundBox = mask.getBounds();
+
+        for (int y = boundBox.y; y < boundBox.y + boundBox.height; y++) {
+            for (int x = boundBox.x; x < boundBox.x + boundBox.width; x++) {
+            	Tile tile = ((TileLayer) other).getTileAt(x, y);
+                if (mask.contains(x,y) && tile != null) {
+                    setTileAt(x, y, tile);
+                }
+            }
+        }
+    }
+    
+    /**
      * Copy data from another layer onto this layer. Unlike mergeOnto,
      * copyFrom() copies the empty cells as well.
      *

Modified: trunk/src/tiled/core/TileSet.java
===================================================================
--- trunk/src/tiled/core/TileSet.java	2007-12-06 17:11:54 UTC (rev 732)
+++ trunk/src/tiled/core/TileSet.java	2008-03-23 19:44:39 UTC (rev 733)
@@ -121,8 +121,8 @@
      */
     private void importTileBitmap(BufferedImage tilebmp, TileCutter cutter)
     {
-        assert tilebmp != null;
-        assert cutter != null;
+        assert(tilebmp != null);
+        assert(cutter != null);
 
         tileCutter = cutter;
         tileSetImage = tilebmp;

Modified: trunk/src/tiled/io/MapHelper.java
===================================================================
--- trunk/src/tiled/io/MapHelper.java	2007-12-06 17:11:54 UTC (rev 732)
+++ trunk/src/tiled/io/MapHelper.java	2008-03-23 19:44:39 UTC (rev 733)
@@ -18,10 +18,10 @@
 
 import tiled.core.Map;
 import tiled.core.TileSet;
-import tiled.io.xml.XMLMapTransformer;
+import tiled.io.xml.XMLMapTransformer;
 import tiled.io.xml.XMLMapWriter;
 import tiled.mapeditor.Resources;
-import tiled.mapeditor.dialogs.PluginLogDialog;
+import tiled.mapeditor.dialogs.PluginLogDialog;
 import tiled.mapeditor.plugin.PluginClassLoader;
 import tiled.util.TiledConfiguration;
 
@@ -161,20 +161,20 @@
                 reportPluginMessages(logger);
             } else {
                 throw new Exception("Unsupported map format");
-            }
+            }
         } catch (IOException e) {
             JOptionPane.showMessageDialog(null,
                     e.getMessage() + (e.getCause() != null ? "\nCause: " +
                         e.getCause().getMessage() : ""),
                         ERROR_LOAD_MAP,
                     JOptionPane.ERROR_MESSAGE);
-            e.printStackTrace();
+            e.printStackTrace();
         } catch (Exception e) {
-            JOptionPane.showMessageDialog(null,
+            JOptionPane.showMessageDialog(null,
                     "Error while loading " + file + ": " +
                     e.getMessage() + (e.getCause() != null ? "\nCause: " +
                         e.getCause().getMessage() : ""),
-                        ERROR_LOAD_MAP,
+                        ERROR_LOAD_MAP,
                     JOptionPane.ERROR_MESSAGE);
             e.printStackTrace();
         }
@@ -211,14 +211,14 @@
                 reportPluginMessages(logger);
             } else {
                 throw new Exception("Unsupported tileset format");
-            }
+            }
         } catch (IOException e) {
             JOptionPane.showMessageDialog(null,
                     e.getMessage() + (e.getCause() != null ? "\nCause: " +
                         e.getCause().getMessage() : ""),
                         ERROR_LOAD_TILESET,
                     JOptionPane.ERROR_MESSAGE);
-            e.printStackTrace();
+            e.printStackTrace();
         } catch (Exception e) {
             JOptionPane.showMessageDialog(null,
                     "Error while loading " + file + ": " +

Modified: trunk/src/tiled/io/xml/XMLWriter.java
===================================================================
--- trunk/src/tiled/io/xml/XMLWriter.java	2007-12-06 17:11:54 UTC (rev 732)
+++ trunk/src/tiled/io/xml/XMLWriter.java	2008-03-23 19:44:39 UTC (rev 733)
@@ -84,6 +84,8 @@
         while (!openElements.isEmpty()) {
             endElement();
         }
+        
+        w.flush(); //writers do not always flush automatically...
     }
 
     public void endElement() throws IOException {

Modified: trunk/src/tiled/mapeditor/MapEditor.java
===================================================================
--- trunk/src/tiled/mapeditor/MapEditor.java	2007-12-06 17:11:54 UTC (rev 732)
+++ trunk/src/tiled/mapeditor/MapEditor.java	2008-03-23 19:44:39 UTC (rev 733)
@@ -19,6 +19,7 @@
 import java.io.File;
 import java.io.IOException;
 import java.util.Iterator;
+import java.util.ListIterator;
 import java.util.Stack;
 import java.util.Vector;
 import java.util.prefs.PreferenceChangeEvent;
@@ -351,9 +352,11 @@
         fileMenu.add(new TMenuItem(exitAction));
 
         JMenuItem copyMenuItem = new TMenuItem(new CopyAction());
+        JMenuItem copyAllMenuItem = new TMenuItem(new CopyAllAction());
         JMenuItem cutMenuItem = new TMenuItem(new CutAction());
         JMenuItem pasteMenuItem = new TMenuItem(new PasteAction());
         copyMenuItem.setEnabled(false);
+        copyAllMenuItem.setEnabled(false);
         cutMenuItem.setEnabled(false);
         pasteMenuItem.setEnabled(false);
 
@@ -371,6 +374,7 @@
         editMenu.add(new TMenuItem(undoHandler.getRedoAction()));
         editMenu.addSeparator();
         editMenu.add(copyMenuItem);
+        editMenu.add(copyAllMenuItem);
         editMenu.add(cutMenuItem);
         editMenu.add(pasteMenuItem);
         editMenu.addSeparator();
@@ -383,6 +387,7 @@
                 "control B"));
 
         mapEventAdapter.addListener(copyMenuItem);
+        mapEventAdapter.addListener(copyAllMenuItem);
         mapEventAdapter.addListener(cutMenuItem);
         mapEventAdapter.addListener(pasteMenuItem);
 
@@ -1731,6 +1736,32 @@
         }
     }
 
+    private class CopyAllAction extends AbstractAction {
+        public CopyAllAction() {
+            super(Resources.getString("action.copyall.name"));
+            putValue(ACCELERATOR_KEY,
+                    KeyStroke.getKeyStroke("shift control C"));
+            putValue(SHORT_DESCRIPTION,
+                     Resources.getString("action.copyall.tooltip"));
+        }
+        public void actionPerformed(ActionEvent evt) {
+        	//FIXME: only works for TileLayers
+            if (currentMap != null && marqueeSelection != null) {
+            	clipboardLayer = new TileLayer(
+                        marqueeSelection.getSelectedAreaBounds());
+            	ListIterator itr = currentMap.getLayers();
+            	while(itr.hasNext()) {
+            		MapLayer layer = (MapLayer) itr.next();
+	                if (layer instanceof TileLayer) {
+	                	clipboardLayer.maskedMergeOnto(
+	                            layer,
+	                            marqueeSelection.getSelectedArea());
+	                }
+            	}
+            }
+        }
+    }
+    
     private class CutAction extends AbstractAction {
         public CutAction() {
             super(Resources.getString("action.cut.name"));
@@ -2003,20 +2034,20 @@
                             JOptionPane.ERROR_MESSAGE);
                 }
             } catch (OutOfMemoryError memoryError) {
-                JOptionPane.showMessageDialog(appFrame,
+                JOptionPane.showMessageDialog(appFrame,
                         "Out of memory while creating image. Try increasing\n" +
                                 "your maximum heap size or zooming out a bit.",
-                        "Out of memory",
+                        "Out of memory",
                         JOptionPane.ERROR_MESSAGE);
             }
         }
     }
 
     private static MapLayer createLayerCopy(MapLayer layer) {
-        try {
+        try {
             return (MapLayer) layer.clone();
         }
-        catch (CloneNotSupportedException e) {
+        catch (CloneNotSupportedException e) {
             e.printStackTrace();
             return null;
         }
@@ -2045,16 +2076,17 @@
         }
         marqueeSelection = null;
 
+    	if(currentMap == newMap) return;
         currentMap = newMap;
         boolean mapLoaded = currentMap != null;
-
+
         // Create a default brush (protect against a bug with custom brushes)
         ShapeBrush sb = new ShapeBrush();
         sb.makeQuadBrush(new Rectangle(0, 0, 1, 1));
         setBrush(sb);
 
         tabbedTilesetsPane.setMap(currentMap);
-
+
         if (!mapLoaded) {
             mapEventAdapter.fireEvent(MapEventAdapter.ME_MAPINACTIVE);
             mapView = null;
@@ -2094,8 +2126,9 @@
                     + ", " + (currentMap.getHeight() - 1));
             tileCoordsLabel.setPreferredSize(null);
             Dimension size = tileCoordsLabel.getPreferredSize();
+            //Dimension size = new Dimension(20,50);
             tileCoordsLabel.setText(" ");
-            tileCoordsLabel.setMinimumSize(size);
+            tileCoordsLabel.setMinimumSize(new Dimension(20,50));
             tileCoordsLabel.setPreferredSize(size);
             zoomLabel.setText(
                     String.valueOf((int) (mapView.getZoom() * 100)) + "%");

Modified: trunk/src/tiled/mapeditor/dialogs/ConfigurationDialog.java
===================================================================
--- trunk/src/tiled/mapeditor/dialogs/ConfigurationDialog.java	2007-12-06 17:11:54 UTC (rev 732)
+++ trunk/src/tiled/mapeditor/dialogs/ConfigurationDialog.java	2008-03-23 19:44:39 UTC (rev 733)
@@ -108,9 +108,9 @@
         ButtonGroup bg = new ButtonGroup();
         bg.add(rbEmbedInTiles);
         bg.add(rbEmbedInSet);
-        undoDepth = new IntegerSpinner();
+        undoDepth = new IntegerSpinner();
         cbGridAA = new JCheckBox(ANTIALIASING_CHECKBOX);
-        gridOpacitySlider = new JSlider(0, 255, 255);
+        gridOpacitySlider = new JSlider(0, 255, 255);
         //gridColor = new JColorChooser();
 
         // Set up the layout
@@ -168,10 +168,10 @@
         JPanel gridOps = new VerticalStaticJPanel();
         gridOps.setLayout(new GridBagLayout());
         gridOps.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
-        c = new GridBagConstraints();
+        c = new GridBagConstraints();
         c.insets = new Insets(0, 0, 0, 5);
         gridOps.add(new JLabel(OPACITY_LABEL), c);
-        c.insets = new Insets(0, 0, 0, 0);
+        c.insets = new Insets(0, 0, 0, 0);
         c.weightx = 1; c.gridx = 1;
         c.fill = GridBagConstraints.HORIZONTAL;
         gridOps.add(gridOpacitySlider, c);
@@ -333,8 +333,8 @@
     }
 
     private void updateFromConfiguration() {
-        undoDepth.setValue(prefs.getInt("undoDepth", 30));
-        gridOpacitySlider.setValue(displayPrefs.getInt("gridOpacity", 255));
+        undoDepth.setValue(prefs.getInt("undoDepth", 30));
+        gridOpacitySlider.setValue(displayPrefs.getInt("gridOpacity", 255));
 
         boolean embedImages = savingPrefs.getBoolean("embedImages", true);
         if (embedImages) {

Modified: trunk/src/tiled/mapeditor/resources/gui.properties
===================================================================
--- trunk/src/tiled/mapeditor/resources/gui.properties	2007-12-06 17:11:54 UTC (rev 732)
+++ trunk/src/tiled/mapeditor/resources/gui.properties	2008-03-23 19:44:39 UTC (rev 733)
@@ -1,5 +1,7 @@
 action.copy.name=Copy
 action.copy.tooltip=Copy to clipboard
+action.copyall.name=Copy All
+action.copyall.tooltip=Copy all layers to clipboard
 action.cut.name=Cut
 action.cut.tooltip=Cut to clipboard
 action.layer.add.name=Add Layer
@@ -143,6 +145,8 @@
 dialog.resizemap.width.label=Width:
 dialog.resizemap.x.label=X:
 dialog.resizemap.y.label=Y:
+dialog.loading.error.title=Error while loading map
+dialog.loading.error.message=Error while loading map
 dialog.saveas.confirm.mismatch=The file extension does not match the file type. Do you wish to continue?
 dialog.saveas.confirm.mismatch.title=Force save?
 dialog.saveas.error.message=Error while attempting to save

Modified: trunk/src/tiled/view/MapView.java
===================================================================
--- trunk/src/tiled/view/MapView.java	2007-12-06 17:11:54 UTC (rev 732)
+++ trunk/src/tiled/view/MapView.java	2008-03-23 19:44:39 UTC (rev 733)
@@ -43,6 +43,8 @@
     protected double zoom = 1.0;
     protected int zoomLevel = ZOOM_NORMALSIZE;
 
+    protected Polygon propPoly;
+    
     // Grid properties
     protected boolean showGrid;
     protected boolean antialiasGrid;
@@ -293,13 +295,13 @@
         g2d.setColor(gridColor);
 
         if (showGrid) {
-            // Grid opacity
-            if (gridOpacity < 255) {
-                g2d.setComposite(AlphaComposite.getInstance(
+            // Grid opacity
+            if (gridOpacity < 255) {
+                g2d.setComposite(AlphaComposite.getInstance(
                         AlphaComposite.SRC_ATOP,
                         (float) gridOpacity / 255.0f));
             }
-            else {
+            else {
                 g2d.setComposite(AlphaComposite.SrcOver);
             }
 

Modified: trunk/src/tiled/view/OrthoMapView.java
===================================================================
--- trunk/src/tiled/view/OrthoMapView.java	2007-12-06 17:11:54 UTC (rev 732)
+++ trunk/src/tiled/view/OrthoMapView.java	2008-03-23 19:44:39 UTC (rev 733)
@@ -35,6 +35,11 @@
      */
     public OrthoMapView(Map map, MapEditor editor) {
         super(map, editor);
+        
+        propPoly = new Polygon();
+        propPoly.addPoint(0, 0);
+        propPoly.addPoint(12, 0);
+        propPoly.addPoint(12, 12);
     }
 
     public int getScrollableBlockIncrement(Rectangle visibleRect,
@@ -125,7 +130,7 @@
             }
             if (zoom > 0.0625) {
                 g.setColor(Color.white);
-                g.drawString(mo.getName(), (int) (ox - 12), (int) (oy - 5));
+                g.drawString(mo.getName() != null ? mo.getName() : "(null)", (int) (ox - 12), (int) (oy - 5));
             }
         }
     }
@@ -201,10 +206,15 @@
         g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                              RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
 
+        g2d.setRenderingHint(RenderingHints.KEY_RENDERING, 
+				RenderingHints.VALUE_RENDER_QUALITY);
+
+        g2d.setComposite(AlphaComposite.SrcAtop);
+        
+        //g2d.setColor(new Color(0.1f, 0.1f, 0.5f, 0.5f));
+    	g2d.setXORMode(new Color(0.9f, 0.9f, 0.9f, 0.5f));
+        
         // Determine tile size and offset
-        Font font = new Font("SansSerif", Font.PLAIN, tsize.height / 4);
-        g2d.setFont(font);
-        FontRenderContext fontRenderContext = g2d.getFontRenderContext();
 
         // Determine area to draw from clipping rectangle
         Rectangle clipRect = g2d.getClipBounds();
@@ -225,7 +235,10 @@
                     }
                     else {
                         //g2d.drawString( "PROP", x, y );
-                        g2d.drawImage(MapView.propertyFlagImage, x, y, null);
+                        //g2d.drawImage(MapView.propertyFlagImage, x + (tsize.width - 12), y, null);
+                    	g2d.translate(x + (tsize.width - 13), y+1);
+                    	g2d.drawPolygon(propPoly);
+                    	g2d.translate(-(x + (tsize.width - 13)), -(y+1));
                     }
                 }
                 catch (Exception e) {




More information about the tiled-commit mailing list