Package tiled.core

Examples of tiled.core.TileLayer


        myTs.setName("Merged Set");
    }

    public TileLayer merge(int start, int len, boolean all) {
        Rectangle r = myMap.getBounds();
        TileLayer mergedLayer = new TileLayer(r);

        for (int i = 0; i < r.height; i++) {
            for (int j = 0; j < r.width; j++) {
                mergedLayer.setTileAt(j, i, createCell(j, i, start, len, all));
            }
        }

        return mergedLayer;
    }
View Full Code Here


        public Cell(Map map, int posx, int posy, int start, int len, boolean all) {
            sandwich = new Vector<Tile>();
            for (int i = 0; i < len; i++) {
                MapLayer ml = map.getLayer(start+i);
                if (ml instanceof TileLayer) {
                    TileLayer l = (TileLayer) ml;
                    if (l.isVisible() || all) {
                        sandwich.add(l.getTileAt(posx, posy));
                    } else {
                        sandwich.add(null);
                    }
                }
            }
View Full Code Here

        super.doPaint(x, y);

        // FIXME: This loop does not take all edges into account

        for (int layer = 0; layer < numLayers; layer++) {
            TileLayer tl = (TileLayer) affectedMp.getLayer(initLayer + layer);
            if (tl != null) {
                for (int i = 0; i <= shapeBounds.height + 1; i++) {
                    for (int j = 0; j <= shapeBounds.width + 1; j++) {
                        if (shape.contains(j, i)) {
                            tl.setTileAt(j + centerx, i + centery, paintTile);
                        }
                    }
                }
            }
        }
View Full Code Here

        Rectangle shapeBounds = Converter.AWTRectToSWT(shape.getBounds());
        int centerx = x - shapeBounds.width / 2;
        int centery = y - shapeBounds.height / 2;

        for (int i = 0; i < numLayers; i++) {
            TileLayer tl = (TileLayer) affectedMp.getLayer(initLayer - i);
            if (tl != null) {
                for (int cy = 0; cy <= shapeBounds.height; cy++) {
                    for (int cx = 0; cx < shapeBounds.width; cx++) {
                        if (shape.contains(cx, cy) &&
                                mt.genrand() % 101 <= 100 * ratio)
                        {
                            tl.setTileAt(
                                    cx + centerx, cy + centery, paintTile);
                        }
                    }
                }
            }
View Full Code Here

          tile.x) - minx) + 1, (Math.max(limp.y, tile.y) - miny) + 1);

      // STAMP
      if (mouseButton == 3 && layer instanceof TileLayer) {
        // Right mouse button dragged: create and set custom brush
        TileLayer brushLayer = new TileLayer(bounds);
        brushLayer.copyFrom(getCurrentLayer());
        brushLayer.setOffset(tile.x - (int) bounds.width / 2, tile.y
            - (int) bounds.height / 2);

        // Do a quick check to make sure the selection is not empty
        if (brushLayer.isEmpty()) {
          MessageDialog.openInformation(getSite().getShell(),
          Resources.getString("dialog.selection.empty"),
          Resources.getString("dialog.selection.empty"));
        } else {
          setBrush(new CustomBrush(brushLayer));
View Full Code Here

        }
        break;
      case PS_POUR:
         paintEdit = null;
        if (layer instanceof TileLayer) {
          TileLayer tileLayer = (TileLayer) layer;
          Tile oldTile = tileLayer.getTileAt(tile.x, tile.y);
          pour(tileLayer, tile.x, tile.y, currentTile, oldTile);
          mapView.redraw();
        }
        break;
      case PS_EYED:
        if (layer instanceof TileLayer) {
          TileLayer tileLayer = (TileLayer) layer;
          Tile newTile = tileLayer.getTileAt(tile.x, tile.y);
          setCurrentTile(newTile);
        }
        break;
      case PS_MOVE: {
        Point translation = new Point(tile.x - mousePressLocation.x,
View Full Code Here

  private void pour(TileLayer layer, int x, int y, Tile newTile, Tile oldTile) {
    if (newTile == oldTile || !layer.canEdit())
      return;

    Rectangle area;
    TileLayer before = (TileLayer) createLayerCopy(layer);
    TileLayer after;

    // Check that the copy was succesfully created
    if (before == null) {
      return;
    }

    if (marqueeSelection == null) {
      area = new Rectangle(x, y, 0, 0);
      Stack<Point> stack = new Stack<Point>();

      stack.push(new Point(x, y));
      while (!stack.empty()) {
        // Remove the next tile from the stack
        Point p = stack.pop();

        // If the tile it meets the requirements, set it and push its
        // neighbouring tiles on the stack.
        if (layer.contains(p.x, p.y)
            && layer.getTileAt(p.x, p.y) == oldTile) {
          layer.setTileAt(p.x, p.y, newTile);
          Converter.add(area, p.x, p.y);

          stack.push(new Point(p.x, p.y - 1));
          stack.push(new Point(p.x, p.y + 1));
          stack.push(new Point(p.x + 1, p.y));
          stack.push(new Point(p.x - 1, p.y));
        }
      }
    } else {
      if (marqueeSelection.getSelectedArea().contains(x, y)) {
        area = marqueeSelection.getSelectedAreaBounds();
        for (int i = area.y; i < area.height + area.y; i++) {
          for (int j = area.x; j < area.width + area.x; j++) {
            if (marqueeSelection.getSelectedArea().contains(j, i)) {
              layer.setTileAt(j, i, newTile);
            }
          }
        }
      } else {
        return;
      }
    }

    Rectangle bounds = new Rectangle(area.x, area.y, area.width + 1,
        area.height + 1);
    after = new TileLayer(bounds);
    after.copyFrom(layer);

     MapLayerEdit mle = new MapLayerEdit(layer, before, after);
     mle.setPresentationName(TOOL_FILL);
     addEdit(mle);
  }
View Full Code Here

  public void copySelection() {
    if (currentMap != null) {
      if (marqueeSelection != null && getCurrentLayer() instanceof TileLayer) {
              if (getCurrentLayer() instanceof TileLayer) {
                  clipboardLayer = new TileLayer(
                          marqueeSelection.getSelectedAreaBounds());
              }
//              else if (getCurrentLayer() instanceof ObjectGroup) {
//                  clipboardLayer = new ObjectGroup(
//                          marqueeSelection.getSelectedAreaBounds());
View Full Code Here

  }
 
  public void copyAll() {
    //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) {
View Full Code Here

        if (result) {
            TileMergeHelper tmh = new TileMergeHelper(map);
            int len = map.getTotalLayers();
            //TODO: Add a dialog option: "Yes, visible only"
            TileLayer newLayer = tmh.merge(0, len, true);
            map.removeAllLayers();
            map.addLayer(newLayer);
            newLayer.setName("Merged Layer");
            map.addTileset(tmh.getSet());
            editor.setCurrentLayer(0);
        }
        else /*if (ret == JOptionPane.NO_OPTION)*/ {
            while (map.getTotalLayers() > 1) {
View Full Code Here

TOP

Related Classes of tiled.core.TileLayer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.