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

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


    // (endY +2 for high tiles, could be done more properly)

    // Draw this map layer
    for (int y = startY, gy = (startY + 1) * tsize.height; y < endY; y++, gy += tsize.height) {
      for (int x = startX, gx = startX * tsize.width; x < endX; x++, gx += tsize.width) {
        Tile tile = layer.getTileAt(x, y);

        if (tile != null) {
          if (layer instanceof SelectionLayer) {
            gridPoly.translate(gx, gy);
            g2d.fillPolygon(gridPoly);
            gridPoly.translate(-gx, -gy);
            // paintEdge(g, layer, gx, gy);
          } else {
            tile.draw(g2d, gx, gy, zoom);
          }
        }
      }
    }
  }
View Full Code Here


      highlightColor = Color.decode(prefs.get("selectionColor", "#0000FF"));
    } catch (NumberFormatException e) {
      highlightColor = Color.blue;
    }

    selTile = new Tile();
    selection = new Area();
  }
View Full Code Here

      out.write(height & FIRST_BYTE);
      out.write(height >> 8 & FIRST_BYTE);

      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
          Tile tile = ((TileLayer) layer).getTileAt(x, y);
          if (tile != null && tile.getId() > 0) {
            out.write(1);
          } else {
            out.write(0);
          }
        }
View Full Code Here

    BufferedImage b = ct.getTilesetGraphic(p);

    // add tileset
    // add tiles
    for (int i = 0, l = b.getWidth() / 32 * (b.getHeight() / 32); i < l; i++) {
      Tile t = new Tile();
      t.setId(i);
      t.setImage(b.getSubimage(i % (b.getWidth() / 32) * 32, i / (b.getWidth() / 32) * 32, 32, 32));
      t.setTileSet(tileset);
      tileset.addTile(t);
    }

    tileset.setName(ct.getTitle());

View Full Code Here

    // create data
    for (int z = 0, n = map.getLayerVector().size(); z < n; z++) {
      TileLayer layer = (TileLayer) map.getLayer(z);
      for (int x = 0, l = layer.getWidth(); x < l; x++) {
        for (int y = 0, m = layer.getHeight(); y < m; y++) {
          Tile t = layer.getTileAt(x, y);

          // is empty?
          if (t == null) {
            cm.set(x, y, z, -1);
            continue;
          }

          // set
          cm.set(x, y, z, t.getId());
        }

      }
    }
View Full Code Here

  }

  public Tile createCell(int tx, int ty, int start, int len, boolean all) {
    Cell c = new Cell(myMap, tx, ty, start, len, all);
    Iterator<Cell> itr = cells.iterator();
    Tile tile;

    while (itr.hasNext()) {
      Cell check = itr.next();
      if (check.equals(c)) {
        return check.getTile();
      }
    }

    cells.add(c);

    tile = new Tile();
    c.setTile(tile);

    // GENERATE MERGED TILE IMAGE
    // FIXME: although faster, the following doesn't seem to handle alpha on
    // some platforms...
    GraphicsConfiguration config = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
    Image tileImg = config.createCompatibleImage(c.getWidth(), c.getHeight());
    c.render(tileImg.getGraphics());
    tile.setImage(tileImg);

    myTs.addTile(tile);

    return tile;
  }
View Full Code Here

      // Write tile properties when necessary.
      Iterator<?> tileIterator = set.iterator();

      while (tileIterator.hasNext()) {
        Tile tile = (Tile) tileIterator.next();
        // todo: move the null check back into the iterator?
        if (tile != null && !tile.getProperties().isEmpty()) {
          w.startElement("tile");
          w.writeAttribute("id", tile.getId());
          writeProperties(tile.getProperties(), w);
          w.endElement();
        }
      }
    } else {
      // Embedded tileset
      Preferences prefs = TiledConfiguration.node("saving");

      boolean embedImages = prefs.getBoolean("embedImages", true);
      boolean tileSetImages = prefs.getBoolean("tileSetImages", false);

      if (tileSetImages) {
        Enumeration<String> ids = set.getImageIds();
        while (ids.hasMoreElements()) {
          String id = ids.nextElement();
          w.startElement("image");
          w.writeAttribute("format", "png");
          w.writeAttribute("id", id);
          w.startElement("data");
          w.writeAttribute("encoding", "base64");
          w.writeCDATA(new String(Base64.encode(ImageHelper.imageToPNG(set.getImageById(Integer.parseInt(id))))));
          w.endElement();
          w.endElement();
        }
      } else if (!embedImages) {
        String imgSource = prefs.get("tileImagePrefix", "tile") + "set.png";

        w.startElement("image");
        w.writeAttribute("source", imgSource);

        String tilesetFilename = wp.substring(0, wp.lastIndexOf(File.separatorChar) + 1) + imgSource;
        FileOutputStream fw = new FileOutputStream(new File(tilesetFilename));
        // byte[] data = ImageHelper.imageToPNG(setImage);
        // fw.write(data, 0, data.length);
        w.endElement();

        fw.close();
      }

      // Check to see if there is a need to write tile elements
      Iterator<?> tileIterator = set.iterator();
      boolean needWrite = !set.isOneForOne();

      if (embedImages) {
        needWrite = true;
      } else {
        // As long as one has properties, they all need to be written.
        // TODO: This shouldn't be necessary
        while (tileIterator.hasNext()) {
          Tile tile = (Tile) tileIterator.next();
          if (!tile.getProperties().isEmpty()) {
            needWrite = true;
            break;
          }
        }
      }

      if (needWrite) {
        tileIterator = set.iterator();
        while (tileIterator.hasNext()) {
          Tile tile = (Tile) tileIterator.next();
          // todo: move this check back into the iterator?
          if (tile != null) {
            writeTile(tile, w);
          }
        }
View Full Code Here

          out = baos;
        }

        for (int y = 0; y < l.getHeight(); y++) {
          for (int x = 0; x < l.getWidth(); x++) {
            Tile tile = tl.getTileAt(x + bounds.x, y + bounds.y);
            int gid = 0;

            if (tile != null) {
              gid = tile.getGid();
            }

            out.write(gid & LAST_BYTE);
            out.write(gid >> 8 & LAST_BYTE);
            out.write(gid >> 16 & LAST_BYTE);
            out.write(gid >> 24 & LAST_BYTE);
          }
        }

        if (compressLayerData) {
          ((GZIPOutputStream) out).finish();
        }

        w.writeCDATA(new String(Base64.encode(baos.toByteArray())));
      } else {
        for (int y = 0; y < l.getHeight(); y++) {
          for (int x = 0; x < l.getWidth(); x++) {
            Tile tile = tl.getTileAt(x + bounds.x, y + bounds.y);
            int gid = 0;

            if (tile != null) {
              gid = tile.getGid();
            }

            w.startElement("tile");
            w.writeAttribute("gid", gid);
            w.endElement();
View Full Code Here

    for (int k = 0; k < s.getTotalKeys(); k++) {
      Sprite.KeyFrame key = s.getKey(k);
      w.startElement("keyframe");
      w.writeAttribute("name", key.getName());
      for (int it = 0; it < key.getTotalFrames(); it++) {
        Tile stile = key.getFrame(it);
        w.startElement("tile");
        w.writeAttribute("gid", stile.getGid());
        w.endElement();
      }
      w.endElement();
    }
    w.endElement();
View Full Code Here

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

TOP

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

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.