Search in sources :

Example 1 with IMapObjectLayer

use of de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer in project litiengine by gurkenlabs.

the class MapSelectionPanel method initLayerControl.

private void initLayerControl() {
    if (mapList.getSelectedIndex() == -1 && this.model.size() > 0) {
        this.mapList.setSelectedIndex(0);
    }
    if (EditorScreen.instance().getMapComponent().getMaps().isEmpty()) {
        layerModel.clear();
        return;
    }
    Map map = EditorScreen.instance().getMapComponent().getMaps().get(mapList.getSelectedIndex());
    this.lastSelection = listObjectLayers.getSelectedIndex();
    layerModel.clear();
    for (IMapObjectLayer layer : map.getMapObjectLayers()) {
        String layerName = layer.getName();
        int layerSize = layer.getMapObjects().size();
        JCheckBox newBox = new JCheckBox(layerName + " (" + layerSize + ")");
        if (layer.getColor() != null) {
            final String cacheKey = map.getFileName() + layer.getName();
            if (!ImageCache.IMAGES.containsKey(cacheKey)) {
                BufferedImage img = ImageProcessing.getCompatibleImage(10, 10);
                Graphics2D g = (Graphics2D) img.getGraphics();
                g.setColor(layer.getColor());
                g.fillRect(0, 0, 9, 9);
                g.setColor(Color.BLACK);
                g.drawRect(0, 0, 9, 9);
                g.dispose();
                ImageCache.IMAGES.put(cacheKey, img);
            }
            newBox.setIcon(new ImageIcon(ImageCache.IMAGES.get(cacheKey)));
        }
        newBox.setSelected(true);
        layerModel.addElement(newBox);
    }
    int start = 0;
    int end = mapList.getModel().getSize() - 1;
    if (end >= 0) {
        listObjectLayers.setSelectionInterval(start, end);
        this.selectLayer(this.lastSelection);
    }
}
Also used : JCheckBox(javax.swing.JCheckBox) ImageIcon(javax.swing.ImageIcon) IMapObjectLayer(de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer) Map(de.gurkenlabs.litiengine.environment.tilemap.xml.Map) Spawnpoint(de.gurkenlabs.litiengine.environment.tilemap.Spawnpoint) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 2 with IMapObjectLayer

use of de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer in project litiengine by gurkenlabs.

the class MapComponent method handleMouseReleased.

private void handleMouseReleased(ComponentMouseEvent e) {
    if (!this.hasFocus()) {
        return;
    }
    this.dragPoint = null;
    this.dragLocationMapObjects.clear();
    this.dragSizeMapObject = null;
    switch(this.currentEditMode) {
        case EDITMODE_CREATE:
            if (this.newObjectArea == null) {
                break;
            }
            IMapObject mo = this.createNewMapObject(EditorScreen.instance().getMapObjectPanel().getObjectType());
            this.newObjectArea = null;
            this.setFocus(mo, !Input.keyboard().isPressed(KeyEvent.VK_SHIFT));
            EditorScreen.instance().getMapObjectPanel().bind(mo);
            this.setEditMode(EDITMODE_EDIT);
            break;
        case EDITMODE_MOVE:
            if (this.isMoving) {
                this.isMoving = false;
                for (IMapObject selected : this.getSelectedMapObjects()) {
                    UndoManager.instance().mapObjectChanged(selected);
                }
                UndoManager.instance().endOperation();
            }
            break;
        case EDITMODE_EDIT:
            if (this.isMoving || this.isTransforming) {
                this.isMoving = false;
                this.isTransforming = false;
                UndoManager.instance().mapObjectChanged(this.getFocusedMapObject());
            }
            if (this.startPoint == null) {
                return;
            }
            Rectangle2D rect = this.getCurrentMouseSelectionArea(false);
            boolean somethingIsFocused = false;
            boolean currentObjectFocused = false;
            for (IMapObjectLayer layer : Game.getEnvironment().getMap().getMapObjectLayers()) {
                if (layer == null || !EditorScreen.instance().getMapSelectionPanel().isVisibleMapObjectLayer(layer.getName())) {
                    continue;
                }
                for (IMapObject mapObject : layer.getMapObjects()) {
                    if (mapObject == null) {
                        continue;
                    }
                    MapObjectType type = MapObjectType.get(mapObject.getType());
                    if (type == MapObjectType.PATH) {
                        continue;
                    }
                    if (!GeometricUtilities.intersects(rect, mapObject.getBoundingBox())) {
                        continue;
                    }
                    if (this.getFocusedMapObject() != null && mapObject.getId() == this.getFocusedMapObject().getId()) {
                        currentObjectFocused = true;
                        continue;
                    }
                    if (somethingIsFocused) {
                        if (rect.getWidth() == 0 && rect.getHeight() == 0) {
                            break;
                        }
                        this.setSelection(mapObject, false);
                        continue;
                    }
                    this.setFocus(mapObject, !Input.keyboard().isPressed(KeyEvent.VK_SHIFT));
                    EditorScreen.instance().getMapObjectPanel().bind(mapObject);
                    somethingIsFocused = true;
                }
            }
            if (!somethingIsFocused && !currentObjectFocused) {
                this.setFocus(null, true);
                EditorScreen.instance().getMapObjectPanel().bind(null);
            }
            break;
        default:
            break;
    }
    this.startPoint = null;
}
Also used : IMapObjectLayer(de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer) Rectangle2D(java.awt.geom.Rectangle2D) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) MapObjectType(de.gurkenlabs.litiengine.environment.tilemap.MapObjectType)

Example 3 with IMapObjectLayer

use of de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer in project litiengine by gurkenlabs.

the class MapPropertyPanel method bind.

public void bind(IMap map) {
    this.dataSource = map;
    if (map == null) {
        return;
    }
    this.setControlValues(map);
    for (IMapObjectLayer layer : map.getMapObjectLayers()) {
        this.model.addRow(new Object[] { layer.getName(), layer.getColor() != null ? "#" + Integer.toHexString(layer.getColor().getRGB()).substring(2) : null });
    }
}
Also used : IMapObjectLayer(de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer)

Example 4 with IMapObjectLayer

use of de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer in project litiengine by gurkenlabs.

the class MapComponent method renderMapObjectBounds.

private void renderMapObjectBounds(Graphics2D g) {
    // render all entities
    for (final IMapObjectLayer layer : Game.getEnvironment().getMap().getMapObjectLayers()) {
        if (layer == null) {
            continue;
        }
        if (!EditorScreen.instance().getMapSelectionPanel().isVisibleMapObjectLayer(layer.getName())) {
            continue;
        }
        Color colorBoundingBoxFill;
        if (layer.getColor() != null) {
            colorBoundingBoxFill = new Color(layer.getColor().getRed(), layer.getColor().getGreen(), layer.getColor().getBlue(), 15);
        } else {
            colorBoundingBoxFill = DEFAULT_COLOR_BOUNDING_BOX_FILL;
        }
        for (final IMapObject mapObject : layer.getMapObjects()) {
            if (mapObject == null) {
                continue;
            }
            MapObjectType type = MapObjectType.get(mapObject.getType());
            final BasicStroke shapeStroke = new BasicStroke(1f / Game.getCamera().getRenderScale());
            // render spawn points
            if (type == MapObjectType.SPAWNPOINT) {
                g.setColor(COLOR_SPAWNPOINT);
                Game.getRenderEngine().renderShape(g, new Rectangle2D.Double(mapObject.getBoundingBox().getCenterX() - 1, mapObject.getBoundingBox().getCenterY() - 1, 2, 2));
            } else if (type == MapObjectType.PATH) {
                if (mapObject.getPolyline() == null || mapObject.getPolyline().getPoints().isEmpty()) {
                    continue;
                }
                // found the path for the rat
                final Path2D path = MapUtilities.convertPolylineToPath(mapObject);
                if (path == null) {
                    continue;
                }
                g.setColor(COLOR_LANE);
                Game.getRenderEngine().renderOutline(g, path, shapeStroke);
                Point2D start = new Point2D.Double(mapObject.getLocation().getX(), mapObject.getLocation().getY());
                Game.getRenderEngine().renderShape(g, new Ellipse2D.Double(start.getX() - 1, start.getY() - 1, 3, 3));
                Game.getRenderEngine().renderText(g, "#" + mapObject.getId() + "(" + mapObject.getName() + ")", start.getX(), start.getY() - 5);
            }
            if (type != MapObjectType.COLLISIONBOX) {
                this.renderBoundingBox(g, mapObject, colorBoundingBoxFill, shapeStroke);
            }
            this.renderCollisionBox(g, mapObject, shapeStroke);
        }
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Point2D(java.awt.geom.Point2D) IMapObjectLayer(de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer) Color(java.awt.Color) Path2D(java.awt.geom.Path2D) Rectangle2D(java.awt.geom.Rectangle2D) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) MapObjectType(de.gurkenlabs.litiengine.environment.tilemap.MapObjectType)

Example 5 with IMapObjectLayer

use of de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer in project litiengine by gurkenlabs.

the class Environment method loadFromMap.

@Override
public void loadFromMap(final int mapId) {
    for (final IMapObjectLayer layer : this.getMap().getMapObjectLayers()) {
        Optional<IMapObject> opt = layer.getMapObjects().stream().filter(mapObject -> mapObject.getType() != null && !mapObject.getType().isEmpty() && mapObject.getId() == mapId).findFirst();
        if (opt.isPresent()) {
            IMapObject mapObject = opt.get();
            this.addMapObject(mapObject);
            break;
        }
    }
}
Also used : Color(java.awt.Color) AmbientLight(de.gurkenlabs.litiengine.graphics.AmbientLight) Rectangle2D(java.awt.geom.Rectangle2D) Emitter(de.gurkenlabs.litiengine.graphics.particles.Emitter) IMovementController(de.gurkenlabs.litiengine.physics.IMovementController) IMapLoader(de.gurkenlabs.litiengine.environment.tilemap.IMapLoader) Map(java.util.Map) FileUtilities(de.gurkenlabs.litiengine.util.io.FileUtilities) Trigger(de.gurkenlabs.litiengine.entities.Trigger) Creature(de.gurkenlabs.litiengine.entities.Creature) Shape(java.awt.Shape) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RenderType(de.gurkenlabs.litiengine.graphics.RenderType) Logger(java.util.logging.Logger) IEntity(de.gurkenlabs.litiengine.entities.IEntity) Collectors(java.util.stream.Collectors) List(java.util.List) IMapObjectLayer(de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer) Optional(java.util.Optional) Spawnpoint(de.gurkenlabs.litiengine.environment.tilemap.Spawnpoint) IEntityController(de.gurkenlabs.litiengine.entities.ai.IEntityController) Game(de.gurkenlabs.litiengine.Game) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Rectangle(java.awt.Rectangle) GeometricUtilities(de.gurkenlabs.litiengine.util.geom.GeometricUtilities) CollisionBox(de.gurkenlabs.litiengine.entities.CollisionBox) IMap(de.gurkenlabs.litiengine.environment.tilemap.IMap) MapUtilities(de.gurkenlabs.litiengine.environment.tilemap.MapUtilities) Quality(de.gurkenlabs.litiengine.configuration.Quality) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Graphics2D(java.awt.Graphics2D) StaticShadowLayer(de.gurkenlabs.litiengine.graphics.StaticShadowLayer) Prop(de.gurkenlabs.litiengine.entities.Prop) LightSource(de.gurkenlabs.litiengine.graphics.LightSource) ICollisionEntity(de.gurkenlabs.litiengine.entities.ICollisionEntity) MapProperty(de.gurkenlabs.litiengine.environment.tilemap.MapProperty) IRenderable(de.gurkenlabs.litiengine.graphics.IRenderable) ICombatEntity(de.gurkenlabs.litiengine.entities.ICombatEntity) MapArea(de.gurkenlabs.litiengine.environment.tilemap.MapArea) TmxMapLoader(de.gurkenlabs.litiengine.environment.tilemap.TmxMapLoader) StaticShadow(de.gurkenlabs.litiengine.graphics.StaticShadow) Consumer(java.util.function.Consumer) MapObjectType(de.gurkenlabs.litiengine.environment.tilemap.MapObjectType) TimeUtilities(de.gurkenlabs.litiengine.util.TimeUtilities) IMobileEntity(de.gurkenlabs.litiengine.entities.IMobileEntity) StaticShadowType(de.gurkenlabs.litiengine.graphics.StaticShadowType) IAnimationController(de.gurkenlabs.litiengine.graphics.animation.IAnimationController) Collections(java.util.Collections) IUpdateable(de.gurkenlabs.litiengine.IUpdateable) IMapObjectLayer(de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject)

Aggregations

IMapObjectLayer (de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer)5 IMapObject (de.gurkenlabs.litiengine.environment.tilemap.IMapObject)3 MapObjectType (de.gurkenlabs.litiengine.environment.tilemap.MapObjectType)3 Rectangle2D (java.awt.geom.Rectangle2D)3 Spawnpoint (de.gurkenlabs.litiengine.environment.tilemap.Spawnpoint)2 Color (java.awt.Color)2 Graphics2D (java.awt.Graphics2D)2 Game (de.gurkenlabs.litiengine.Game)1 IUpdateable (de.gurkenlabs.litiengine.IUpdateable)1 Quality (de.gurkenlabs.litiengine.configuration.Quality)1 CollisionBox (de.gurkenlabs.litiengine.entities.CollisionBox)1 Creature (de.gurkenlabs.litiengine.entities.Creature)1 ICollisionEntity (de.gurkenlabs.litiengine.entities.ICollisionEntity)1 ICombatEntity (de.gurkenlabs.litiengine.entities.ICombatEntity)1 IEntity (de.gurkenlabs.litiengine.entities.IEntity)1 IMobileEntity (de.gurkenlabs.litiengine.entities.IMobileEntity)1 Prop (de.gurkenlabs.litiengine.entities.Prop)1 Trigger (de.gurkenlabs.litiengine.entities.Trigger)1 IEntityController (de.gurkenlabs.litiengine.entities.ai.IEntityController)1 IMap (de.gurkenlabs.litiengine.environment.tilemap.IMap)1