Search in sources :

Example 6 with IMapObject

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

the class MapComponent method handleTransform.

private void handleTransform() {
    final IMapObject transformObject = this.getFocusedMapObject();
    if (transformObject == null || this.currentEditMode != EDITMODE_EDIT || currentTransform == TransformType.NONE) {
        return;
    }
    if (this.dragPoint == null) {
        this.dragPoint = Input.mouse().getMapLocation();
        this.dragLocationMapObjects.put(this.getFocusedMapObject(), new Point2D.Double(transformObject.getX(), transformObject.getY()));
        this.dragSizeMapObject = new Dimension(transformObject.getDimension());
        return;
    }
    Point2D dragLocationMapObject = this.dragLocationMapObjects.get(this.getFocusedMapObject());
    double deltaX = Input.mouse().getMapLocation().getX() - this.dragPoint.getX();
    double deltaY = Input.mouse().getMapLocation().getY() - this.dragPoint.getY();
    double newWidth = this.dragSizeMapObject.getWidth();
    double newHeight = this.dragSizeMapObject.getHeight();
    double newX = this.snapX(dragLocationMapObject.getX());
    double newY = this.snapY(dragLocationMapObject.getY());
    switch(this.currentTransform) {
        case DOWN:
            newHeight += deltaY;
            break;
        case DOWNRIGHT:
            newHeight += deltaY;
            newWidth += deltaX;
            break;
        case DOWNLEFT:
            newHeight += deltaY;
            newWidth -= deltaX;
            newX += deltaX;
            newX = MathUtilities.clamp(newX, 0, dragLocationMapObject.getX() + this.dragSizeMapObject.getWidth());
            break;
        case LEFT:
            newWidth -= deltaX;
            newX += deltaX;
            newX = MathUtilities.clamp(newX, 0, dragLocationMapObject.getX() + this.dragSizeMapObject.getWidth());
            break;
        case RIGHT:
            newWidth += deltaX;
            break;
        case UP:
            newHeight -= deltaY;
            newY += deltaY;
            newY = MathUtilities.clamp(newY, 0, dragLocationMapObject.getY() + this.dragSizeMapObject.getHeight());
            break;
        case UPLEFT:
            newHeight -= deltaY;
            newY += deltaY;
            newY = MathUtilities.clamp(newY, 0, dragLocationMapObject.getY() + this.dragSizeMapObject.getHeight());
            newWidth -= deltaX;
            newX += deltaX;
            newX = MathUtilities.clamp(newX, 0, dragLocationMapObject.getX() + this.dragSizeMapObject.getWidth());
            break;
        case UPRIGHT:
            newHeight -= deltaY;
            newY += deltaY;
            newY = MathUtilities.clamp(newY, 0, dragLocationMapObject.getY() + this.dragSizeMapObject.getHeight());
            newWidth += deltaX;
            break;
        default:
            return;
    }
    transformObject.setWidth(this.snapX(newWidth));
    transformObject.setHeight(this.snapY(newHeight));
    transformObject.setX(this.snapX(newX));
    transformObject.setY(this.snapY(newY));
    Game.getEnvironment().reloadFromMap(transformObject.getId());
    if (MapObjectType.get(transformObject.getType()) == MapObjectType.LIGHTSOURCE) {
        Game.getEnvironment().getAmbientLight().updateSection(transformObject.getBoundingBox());
    }
    EditorScreen.instance().getMapObjectPanel().bind(transformObject);
    this.updateTransformControls();
}
Also used : Point2D(java.awt.geom.Point2D) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) Dimension(java.awt.Dimension)

Example 7 with IMapObject

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

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

the class EmitterMapObjectLoader method createMapObject.

public static IMapObject createMapObject(EmitterData emitterData) {
    MapObject newMapObject = new MapObject();
    newMapObject.setType(MapObjectType.EMITTER.toString());
    // emitter
    newMapObject.setWidth(emitterData.getWidth());
    newMapObject.setHeight(emitterData.getHeight());
    newMapObject.setCustomProperty(MapObjectProperty.Emitter.SPAWNRATE, Integer.toString(emitterData.getSpawnRate()));
    newMapObject.setCustomProperty(MapObjectProperty.Emitter.SPAWNAMOUNT, Integer.toString(emitterData.getSpawnAmount()));
    newMapObject.setCustomProperty(MapObjectProperty.Emitter.UPDATERATE, Integer.toString(emitterData.getUpdateRate()));
    newMapObject.setCustomProperty(MapObjectProperty.Emitter.TIMETOLIVE, Integer.toString(emitterData.getEmitterTTL()));
    newMapObject.setCustomProperty(MapObjectProperty.Emitter.MAXPARTICLES, Integer.toString(emitterData.getMaxParticles()));
    newMapObject.setCustomProperty(MapObjectProperty.Emitter.PARTICLETYPE, emitterData.getParticleType().name());
    newMapObject.setCustomProperty(MapObjectProperty.Emitter.COLORDEVIATION, Float.toString(emitterData.getColorDeviation()));
    newMapObject.setCustomProperty(MapObjectProperty.Emitter.ALPHADEVIATION, Float.toString(emitterData.getAlphaDeviation()));
    newMapObject.setCustomProperty(MapObjectProperty.Emitter.ORIGIN_ALIGN, emitterData.getOriginAlign().name());
    newMapObject.setCustomProperty(MapObjectProperty.Emitter.ORIGIN_VALIGN, emitterData.getOriginValign().name());
    String commaSeperatedColors = ArrayUtilities.getCommaSeparatedString(emitterData.getColors());
    newMapObject.setCustomProperty(MapObjectProperty.Emitter.COLORS, commaSeperatedColors);
    newMapObject.setCustomProperty(MapObjectProperty.Emitter.PARTICLETYPE, ArrayUtilities.getCommaSeparatedString(emitterData.getColorProbabilities()));
    newMapObject.setCustomProperty(MapObjectProperty.Particle.MINX, Float.toString(emitterData.getParticleX().getMinValue()));
    newMapObject.setCustomProperty(MapObjectProperty.Particle.MINY, Float.toString(emitterData.getParticleY().getMinValue()));
    newMapObject.setCustomProperty(MapObjectProperty.Particle.MINSTARTWIDTH, Float.toString(emitterData.getParticleWidth().getMinValue()));
    newMapObject.setCustomProperty(MapObjectProperty.Particle.MINSTARTHEIGHT, Float.toString(emitterData.getParticleHeight().getMinValue()));
    newMapObject.setCustomProperty(MapObjectProperty.Particle.MINDELTAX, Float.toString(emitterData.getDeltaX().getMinValue()));
    newMapObject.setCustomProperty(MapObjectProperty.Particle.MINDELTAY, Float.toString(emitterData.getDeltaY().getMinValue()));
    newMapObject.setCustomProperty(MapObjectProperty.Particle.MINGRAVITYX, Float.toString(emitterData.getGravityX().getMinValue()));
    newMapObject.setCustomProperty(MapObjectProperty.Particle.MINGRAVITYY, Float.toString(emitterData.getGravityY().getMinValue()));
    newMapObject.setCustomProperty(MapObjectProperty.Particle.MINDELTAWIDTH, Float.toString(emitterData.getDeltaWidth().getMinValue()));
    newMapObject.setCustomProperty(MapObjectProperty.Particle.MINDELTAHEIGHT, Float.toString(emitterData.getDeltaHeight().getMinValue()));
    newMapObject.setCustomProperty(MapObjectProperty.Particle.MAXX, Float.toString(emitterData.getParticleX().getMaxValue()));
    newMapObject.setCustomProperty(MapObjectProperty.Particle.MAXY, Float.toString(emitterData.getParticleY().getMaxValue()));
    newMapObject.setCustomProperty(MapObjectProperty.Particle.MAXSTARTWIDTH, Float.toString(emitterData.getParticleWidth().getMaxValue()));
    newMapObject.setCustomProperty(MapObjectProperty.Particle.MAXSTARTHEIGHT, Float.toString(emitterData.getParticleHeight().getMaxValue()));
    newMapObject.setCustomProperty(MapObjectProperty.Particle.MAXDELTAX, Float.toString(emitterData.getDeltaX().getMaxValue()));
    newMapObject.setCustomProperty(MapObjectProperty.Particle.MAXDELTAY, Float.toString(emitterData.getDeltaY().getMaxValue()));
    newMapObject.setCustomProperty(MapObjectProperty.Particle.MAXGRAVITYX, Float.toString(emitterData.getGravityX().getMaxValue()));
    newMapObject.setCustomProperty(MapObjectProperty.Particle.MAXGRAVITYY, Float.toString(emitterData.getGravityY().getMaxValue()));
    newMapObject.setCustomProperty(MapObjectProperty.Particle.MAXDELTAWIDTH, Float.toString(emitterData.getDeltaWidth().getMaxValue()));
    newMapObject.setCustomProperty(MapObjectProperty.Particle.MAXDELTAHEIGHT, Float.toString(emitterData.getDeltaHeight().getMaxValue()));
    // particle
    newMapObject.setCustomProperty(MapObjectProperty.Particle.MINTTL, Integer.toString(emitterData.getParticleMinTTL()));
    newMapObject.setCustomProperty(MapObjectProperty.Particle.MAXTTL, Integer.toString(emitterData.getParticleMaxTTL()));
    newMapObject.setCustomProperty(MapObjectProperty.Particle.COLLISIONTYPE, emitterData.getCollisionType().toString());
    newMapObject.setCustomProperty(MapObjectProperty.Particle.TEXT, emitterData.getParticleText());
    newMapObject.setCustomProperty(MapObjectProperty.Particle.SPRITE, emitterData.getSpritesheet());
    newMapObject.setCustomProperty(MapObjectProperty.Particle.ANIMATESPRITE, Boolean.toString(emitterData.isAnimateSprite()));
    return newMapObject;
}
Also used : MapObject(de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject)

Example 9 with IMapObject

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

the class UndoManager method restoreState.

private static void restoreState(IMapObject target, IMapObject restore) {
    target.setId(restore.getId());
    target.setName(restore.getName());
    target.setType(restore.getType());
    target.setX(restore.getX());
    target.setY(restore.getY());
    target.setWidth(restore.getWidth());
    target.setHeight(restore.getHeight());
    target.getAllCustomProperties().clear();
    for (Property prop : restore.getAllCustomProperties()) {
        target.setCustomProperty(prop.getName(), prop.getValue());
    }
    Game.getEnvironment().reloadFromMap(target.getId());
    if (MapObjectType.get(target.getType()) == MapObjectType.LIGHTSOURCE) {
        Game.getEnvironment().getAmbientLight().updateSection(MapObject.getBounds2D((MapObject) target, (MapObject) restore));
    }
    if (EditorScreen.instance().getMapComponent().getFocusedMapObject() != null && EditorScreen.instance().getMapComponent().getFocusedMapObject().getId() == target.getId()) {
        EditorScreen.instance().getMapObjectPanel().bind(target);
        EditorScreen.instance().getMapSelectionPanel().focus(target);
    }
}
Also used : Property(de.gurkenlabs.litiengine.environment.tilemap.xml.Property) MapObject(de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject)

Example 10 with IMapObject

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

the class MapComponent method createNewMapObject.

private IMapObject createNewMapObject(MapObjectType type) {
    IMapObject mo = new MapObject();
    mo.setType(type.toString());
    mo.setX((int) this.newObjectArea.getX());
    mo.setY((int) this.newObjectArea.getY());
    mo.setWidth((int) this.newObjectArea.getWidth());
    mo.setHeight((int) this.newObjectArea.getHeight());
    mo.setId(Game.getEnvironment().getNextMapId());
    mo.setName("");
    switch(type) {
        case PROP:
            mo.setCustomProperty(MapObjectProperty.COLLISIONBOX_WIDTH, (this.newObjectArea.getWidth() * 0.4) + "");
            mo.setCustomProperty(MapObjectProperty.COLLISIONBOX_HEIGHT, (this.newObjectArea.getHeight() * 0.4) + "");
            mo.setCustomProperty(MapObjectProperty.COLLISION, "true");
            mo.setCustomProperty(MapObjectProperty.PROP_INDESTRUCTIBLE, "false");
            mo.setCustomProperty(MapObjectProperty.PROP_ADDSHADOW, "true");
            break;
        case LIGHTSOURCE:
            mo.setCustomProperty(MapObjectProperty.LIGHT_ALPHA, "180");
            mo.setCustomProperty(MapObjectProperty.LIGHT_COLOR, "#ffffff");
            mo.setCustomProperty(MapObjectProperty.LIGHT_SHAPE, LightSource.ELLIPSE);
            mo.setCustomProperty(MapObjectProperty.LIGHT_ACTIVE, "true");
            break;
        case SPAWNPOINT:
        default:
            break;
    }
    this.add(mo);
    return mo;
}
Also used : IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) MapObject(de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject)

Aggregations

IMapObject (de.gurkenlabs.litiengine.environment.tilemap.IMapObject)23 IEntity (de.gurkenlabs.litiengine.entities.IEntity)7 Dimension (java.awt.Dimension)6 Point (java.awt.Point)5 Test (org.junit.jupiter.api.Test)5 MapObject (de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject)4 Point2D (java.awt.geom.Point2D)4 Rectangle2D (java.awt.geom.Rectangle2D)4 IMapObjectLayer (de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer)3 MapObjectType (de.gurkenlabs.litiengine.environment.tilemap.MapObjectType)3 BasicStroke (java.awt.BasicStroke)3 CollisionBox (de.gurkenlabs.litiengine.entities.CollisionBox)2 Prop (de.gurkenlabs.litiengine.entities.Prop)2 Trigger (de.gurkenlabs.litiengine.entities.Trigger)2 Blueprint (de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint)2 LightSource (de.gurkenlabs.litiengine.graphics.LightSource)2 Color (java.awt.Color)2 Stroke (java.awt.Stroke)2 ArrayList (java.util.ArrayList)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2