Search in sources :

Example 1 with MapObjectType

use of de.gurkenlabs.litiengine.environment.tilemap.MapObjectType 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 2 with MapObjectType

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

the class MapComponent method renderBoundingBox.

private void renderBoundingBox(Graphics2D g, IMapObject mapObject, Color colorBoundingBoxFill, BasicStroke shapeStroke) {
    MapObjectType type = MapObjectType.get(mapObject.getType());
    Color fillColor = colorBoundingBoxFill;
    if (type == MapObjectType.TRIGGER) {
        fillColor = COLOR_TRIGGER_FILL;
    } else if (type == MapObjectType.STATICSHADOW) {
        fillColor = COLOR_SHADOW_FILL;
    }
    // render bounding boxes
    g.setColor(fillColor);
    // the color
    if (type != MapObjectType.LIGHTSOURCE) {
        Game.getRenderEngine().renderShape(g, mapObject.getBoundingBox());
    }
    Color borderColor = colorBoundingBoxFill;
    if (type == MapObjectType.TRIGGER) {
        borderColor = COLOR_TRIGGER_BORDER;
    } else if (type == MapObjectType.LIGHTSOURCE) {
        final String mapObjectColor = mapObject.getCustomProperty(MapObjectProperty.LIGHT_COLOR);
        if (mapObjectColor != null && !mapObjectColor.isEmpty()) {
            Color lightColor = Color.decode(mapObjectColor);
            borderColor = new Color(lightColor.getRed(), lightColor.getGreen(), lightColor.getBlue(), 180);
        }
    } else if (type == MapObjectType.STATICSHADOW) {
        borderColor = COLOR_SHADOW_BORDER;
    } else if (type == MapObjectType.SPAWNPOINT) {
        borderColor = COLOR_SPAWNPOINT;
    }
    g.setColor(borderColor);
    Game.getRenderEngine().renderOutline(g, mapObject.getBoundingBox(), shapeStroke);
    this.renderName(g, borderColor, mapObject);
}
Also used : Color(java.awt.Color) MapObjectType(de.gurkenlabs.litiengine.environment.tilemap.MapObjectType)

Example 3 with MapObjectType

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

the class MapComponent method delete.

public void delete(final IMapObject mapObject) {
    if (mapObject == null) {
        return;
    }
    MapObjectType type = MapObjectType.get(mapObject.getType());
    Game.getEnvironment().getMap().removeMapObject(mapObject.getId());
    Game.getEnvironment().remove(mapObject.getId());
    if (type == MapObjectType.STATICSHADOW || type == MapObjectType.LIGHTSOURCE) {
        Game.getEnvironment().getAmbientLight().updateSection(mapObject.getBoundingBox());
    }
    if (mapObject.equals(this.getFocusedMapObject())) {
        this.setFocus(null, true);
    }
}
Also used : MapObjectType(de.gurkenlabs.litiengine.environment.tilemap.MapObjectType)

Example 4 with MapObjectType

use of de.gurkenlabs.litiengine.environment.tilemap.MapObjectType 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 MapObjectType

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

the class MapObjectPanel method setControlValues.

@Override
protected void setControlValues(IMapObject mapObject) {
    this.spinnerX.setValue((int) mapObject.getLocation().getX());
    this.spinnerY.setValue((int) mapObject.getLocation().getY());
    this.spinnerWidth.setValue((int) mapObject.getDimension().getWidth());
    this.spinnerHeight.setValue((int) mapObject.getDimension().getHeight());
    MapObjectType type = MapObjectType.get(mapObject.getType());
    this.comboBoxType.setSelectedItem(type);
    this.textFieldName.setText(mapObject.getName());
    this.labelEntityID.setText(Integer.toString(mapObject.getId()));
    this.comboBoxType.setEnabled(false);
    this.tagPanel.bind(mapObject.getCustomProperty(MapObjectProperty.TAGS));
}
Also used : MapObjectType(de.gurkenlabs.litiengine.environment.tilemap.MapObjectType)

Aggregations

MapObjectType (de.gurkenlabs.litiengine.environment.tilemap.MapObjectType)6 IMapObject (de.gurkenlabs.litiengine.environment.tilemap.IMapObject)3 IMapObjectLayer (de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer)2 Color (java.awt.Color)2 Rectangle2D (java.awt.geom.Rectangle2D)2 Resources (de.gurkenlabs.litiengine.Resources)1 MapObjectProperty (de.gurkenlabs.litiengine.environment.tilemap.MapObjectProperty)1 EditorScreen (de.gurkenlabs.utiliti.EditorScreen)1 TagPanel (de.gurkenlabs.utiliti.swing.TagPanel)1 BasicStroke (java.awt.BasicStroke)1 BorderLayout (java.awt.BorderLayout)1 Dimension (java.awt.Dimension)1 Font (java.awt.Font)1 Path2D (java.awt.geom.Path2D)1 Point2D (java.awt.geom.Point2D)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 GroupLayout (javax.swing.GroupLayout)1 Alignment (javax.swing.GroupLayout.Alignment)1