Package de.yaams.extensions.basemap.tiled.core

Examples of de.yaams.extensions.basemap.tiled.core.MapLayer


      }
    }

    @Override
    public void actionPerformed(ActionEvent evt) {
      MapLayer currentLayer = getCurrentLayer();
      MapLayer layer = currentLayer;
      MapLayerEdit transEdit;
      transEdit = new MapLayerEdit(currentLayer, createLayerCopy(currentLayer));

      if (marqueeSelection != null) {
        if (currentLayer instanceof TileLayer) {
          layer = new TileLayer(marqueeSelection.getSelectedAreaBounds());
        } else if (currentLayer instanceof ObjectGroup) {
          layer = new ObjectGroup(marqueeSelection.getSelectedAreaBounds());
        }
        layer.setMap(currentMap);
        layer.maskedCopyFrom(currentLayer, marqueeSelection.getSelectedArea());
      }

      switch (transform) {
      case MapLayer.ROTATE_90:
      case MapLayer.ROTATE_180:
      case MapLayer.ROTATE_270:
        transEdit.setPresentationName("Rotate");
        layer.rotate(transform);
        // if(marqueeSelection != null)
        // marqueeSelection.rotate(transform);
        break;
      case MapLayer.MIRROR_VERTICAL:
        transEdit.setPresentationName("Vertical Flip");
        layer.mirror(MapLayer.MIRROR_VERTICAL);
        // if(marqueeSelection != null)
        // marqueeSelection.mirror(transform);
        break;
      case MapLayer.MIRROR_HORIZONTAL:
        transEdit.setPresentationName("Horizontal Flip");
        layer.mirror(MapLayer.MIRROR_HORIZONTAL);
        // if(marqueeSelection != null)
        // marqueeSelection.mirror(transform);
        break;
      }

      if (marqueeSelection != null) {
        layer.mergeOnto(currentLayer);
      }

      transEdit.end(createLayerCopy(currentLayer));
      undoSupport.postEdit(transEdit);
      mapView.repaint();
View Full Code Here


      // 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());
          }
        }
      }
View Full Code Here

    }

    @Override
    public void actionPerformed(ActionEvent evt) {
      if (currentMap != null && marqueeSelection != null) {
        MapLayer ml = getCurrentLayer();

        if (getCurrentLayer() instanceof TileLayer) {
          clipboardLayer = new TileLayer(marqueeSelection.getSelectedAreaBounds());
        } else if (getCurrentLayer() instanceof ObjectGroup) {
          clipboardLayer = new ObjectGroup(marqueeSelection.getSelectedAreaBounds());
View Full Code Here

    @Override
    public void actionPerformed(ActionEvent evt) {
      if (currentMap != null && clipboardLayer != null) {
        Vector<MapLayer> layersBefore = currentMap.getLayerVector();
        MapLayer ml = createLayerCopy(clipboardLayer);
        ml.setName(Resources.getString("general.layer.layer") + " " + currentMap.getTotalLayers());
        currentMap.addLayer(ml);
        undoSupport.postEdit(new MapLayerStateEdit(currentMap, layersBefore, new Vector<MapLayer>(currentMap.getLayerVector()),
            "Paste Selection"));
      }
    }
View Full Code Here

  private static final int FIRST_BYTE = 0x000000FF;

  public static void writeMap(Map map, OutputStream out) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    MapLayer layer = null;

    // Get the last "collision" layer
    for (MapLayer mapLayer : map) {
      if (mapLayer.getName().equalsIgnoreCase("collision")) {
        layer = mapLayer;
      }
    }

    if (layer != null && layer instanceof TileLayer) {
      int width = layer.getWidth();
      int height = layer.getHeight();

      // Write width and height
      out.write(width & FIRST_BYTE);
      out.write(width >> 8 & FIRST_BYTE);
      out.write(height & FIRST_BYTE);
View Full Code Here

      w.writeComment("Layer data is " + (prefs.getBoolean("layerCompression", true) ? "compressed (GZip)" : "")
          + " binary data, encoded in Base64");
    }
    Iterator<MapLayer> ml = map.getLayers();
    while (ml.hasNext()) {
      MapLayer layer = ml.next();
      writeMapLayer(layer, w, wp);
    }

    w.endElement();
  }
View Full Code Here

    if (currentMap == null || currentLayer < 0) {
      return;
    }

    Point tile = mapView.screenToTileCoords(event.getX(), event.getY());
    MapLayer layer = getCurrentLayer();

    if (layer == null) {
      return;
    } else if (mouseButton == MouseEvent.BUTTON3) {
      if (layer instanceof TileLayer) {
        if (!bMouseIsDragging) {
          // Click event is sent before the drag event
          // so this one always happens
          Tile newTile = ((TileLayer) layer).getTileAt(tile.x, tile.y);
          setCurrentTile(newTile);
        } else if (currentPointerState == PS_PAINT) {
          // In case we are dragging to create a custom brush, let
          // the user know where we are creating it from
          if (marqueeSelection == null) {
            marqueeSelection = new SelectionLayer(currentMap.getWidth(), currentMap.getHeight());
            currentMap.addLayerSpecial(marqueeSelection);
          }

          Point limp = mouseInitialPressLocation;
          Rectangle oldArea = marqueeSelection.getSelectedAreaBounds();
          int minx = Math.min(limp.x, tile.x);
          int miny = Math.min(limp.y, tile.y);

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

          marqueeSelection.selectRegion(selRect);
          if (oldArea != null) {
            oldArea.add(marqueeSelection.getSelectedAreaBounds());
            mapView.repaintRegion(oldArea);
          }
        }
      } else if (layer instanceof ObjectGroup && !bMouseIsDragging) {
        // Get the object on this location and display the relative
        // options dialog
        ObjectGroup group = (ObjectGroup) layer;
        Point pos = mapView.screenToPixelCoords(event.getX(), event.getY());
        MapObject obj = group.getObjectNear(pos.x, pos.y, mapView.getZoom());
        if (obj != null) {
          ObjectDialog od = new ObjectDialog(YaFrame.get(), obj, undoSupport);
          od.getProps();
        }
      }
    } else if (mouseButton == MouseEvent.BUTTON2 || mouseButton == MouseEvent.BUTTON1
        && (event.getModifiersEx() & InputEvent.ALT_DOWN_MASK) != 0) {
      // Scroll with middle mouse button
      int dx = event.getX() - mouseInitialScreenLocation.x;
      int dy = event.getY() - mouseInitialScreenLocation.y;
      JViewport mapViewPort = mapScrollPane.getViewport();
      Point currentPosition = mapViewPort.getViewPosition();
      mouseInitialScreenLocation = new Point(event.getX() - dx, event.getY() - dy);

      Point newPosition = new Point(currentPosition.x - dx, currentPosition.y - dy);

      // Take into account map boundaries in order to prevent
      // scrolling past them
      int maxX = mapView.getWidth() - mapViewPort.getWidth();
      int maxY = mapView.getHeight() - mapViewPort.getHeight();
      newPosition.x = Math.min(maxX, Math.max(0, newPosition.x));
      newPosition.y = Math.min(maxY, Math.max(0, newPosition.y));

      mapViewPort.setViewPosition(newPosition);
    } else if (mouseButton == MouseEvent.BUTTON1) {
      switch (currentPointerState) {
      case PS_PAINT:
        paintEdit.setPresentationName(TOOL_PAINT);
        if (layer instanceof TileLayer) {
          try {
            mapView.repaintRegion(currentBrush.doPaint(tile.x, tile.y));
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
        break;
      case PS_ERASE:
        paintEdit.setPresentationName(TOOL_ERASE);
        if (layer instanceof TileLayer) {
          ((TileLayer) layer).setTileAt(tile.x, tile.y, null);
          mapView.repaintRegion(new Rectangle(tile.x, tile.y, 1, 1));
        }
        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.repaint();
        }
        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, tile.y - mousePressLocation.y);

        layer.translate(translation.x, translation.y);
        moveDist.translate(translation.x, translation.y);
        mapView.repaint();
        break;
      }
      case PS_MARQUEE:
View Full Code Here

    bMouseIsDown = true;
    bMouseIsDragging = false;
    mousePressLocation = mapView.screenToTileCoords(e.getX(), e.getY());
    mouseInitialPressLocation = mousePressLocation;

    MapLayer layer = getCurrentLayer();

    if (mouseButton == MouseEvent.BUTTON2 || mouseButton == MouseEvent.BUTTON1 && (e.getModifiersEx() & InputEvent.ALT_DOWN_MASK) != 0) {
      // Remember screen location for scrolling with middle mouse button
      mouseInitialScreenLocation = new Point(e.getX(), e.getY());
    } else if (mouseButton == MouseEvent.BUTTON1) {
View Full Code Here

    doMouse(e);
  }

  @Override
  public void mouseReleased(MouseEvent event) {
    final MapLayer layer = getCurrentLayer();
    final Point limp = mouseInitialPressLocation;

    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) {
       * currentMap.removeLayerSpecial(marqueeSelection); marqueeSelection
       * = null; } }
       */

      // There should be a proper notification mechanism for this...
      // if (marqueeSelection != null) {
      // tileInstancePropertiesDialog.setSelection(marqueeSelection);
      // }
    } else if (currentPointerState == PS_MOVE) {
      if (layer != null && (moveDist.x != 0 || moveDist.x != 0)) {
        undoSupport.postEdit(new MoveLayerEdit(layer, moveDist));
      }
    } else if (currentPointerState == PS_PAINT) {
      if (layer instanceof TileLayer) {
        currentBrush.endPaint();
      }
    } else if (currentPointerState == PS_MOVEOBJ) {
      if (layer instanceof ObjectGroup && currentObject != null && (moveDist.x != 0 || moveDist.x != 0)) {
        undoSupport.postEdit(new MoveObjectEdit(currentObject, moveDist));
      }
    }

    if (/* bMouseIsDragging && */currentPointerState == PS_PAINT || currentPointerState == PS_ADDOBJ) {
      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);

      // STAMP
      if (mouseButton == MouseEvent.BUTTON3 && 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.getWidth() / 2, tile.y - (int) bounds.getHeight() / 2);

        // 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 {
          setBrush(new CustomBrush(brushLayer));
          cursorHighlight.setOffset(tile.x - (int) bounds.getWidth() / 2, tile.y - (int) bounds.getHeight() / 2);
        }
      } else if (mouseButton == MouseEvent.BUTTON1 && layer instanceof ObjectGroup) {
        // TODO: Fix this to use pixels in the first place
        // (with optional snap to grid)
        int w = currentMap.getTileWidth();
        int h = currentMap.getTileHeight();
        MapObject object = new MapObject(bounds.x * w, bounds.y * h, bounds.width * w, bounds.height * h);
        /*
         * Point pos = mapView.screenToPixelCoords( event.getX(),
         * event.getY());
         */
        ObjectGroup group = (ObjectGroup) layer;
        undoSupport.postEdit(new AddObjectEdit(group, object));
        group.addObject(object);
        mapView.repaint();
      }

      // get rid of any visible marquee
      if (marqueeSelection != null) {
        currentMap.removeLayerSpecial(marqueeSelection);
        marqueeSelection = null;
      }
    }

    if (paintEdit != null) {
      if (layer != null) {
        try {
          MapLayer endLayer = paintEdit.getStart().createDiff(layer);
          paintEdit.end(endLayer);
          undoSupport.postEdit(paintEdit);
        } catch (Exception e) {
          e.printStackTrace();
        }
View Full Code Here

      if (!redraw.equals(brushRedraw)) {
        if (currentBrush instanceof CustomBrush) {
          CustomBrush customBrush = (CustomBrush) currentBrush;
          ListIterator<MapLayer> layers = customBrush.getLayers();
          while (layers.hasNext()) {
            MapLayer layer = layers.next();
            layer.setOffset(brushRedraw.x, brushRedraw.y);
          }
        }
        mapView.repaintRegion(redraw);
        cursorHighlight.setOffset(brushRedraw.x, brushRedraw.y);
        // cursorHighlight.selectRegion(currentBrush.getShape());
View Full Code Here

TOP

Related Classes of de.yaams.extensions.basemap.tiled.core.MapLayer

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.