Search in sources :

Example 6 with EmitterData

use of de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData in project litiengine by gurkenlabs.

the class MapComponent method createNewMapObject.

private IMapObject createNewMapObject(MapObjectType type) {
    final Rectangle2D newObjectArea = this.getMouseSelectArea(true);
    IMapObject mo = new MapObject();
    mo.setType(type.toString());
    mo.setX((float) newObjectArea.getX());
    mo.setY((float) newObjectArea.getY());
    // ensure a minimum size for the new object
    float width = (float) newObjectArea.getWidth();
    float height = (float) newObjectArea.getHeight();
    mo.setWidth(width == 0 ? 16 : width);
    mo.setHeight(height == 0 ? 16 : height);
    mo.setId(Game.world().environment().getNextMapId());
    mo.setName("");
    switch(type) {
        case EMITTER:
            EmitterData defaultData = new EmitterData();
            defaultData.initDefaults();
            defaultData.setWidth(mo.getWidth());
            defaultData.setHeight(mo.getHeight());
            defaultData.setName(mo.getName());
            EmitterMapObjectLoader.updateMapObject(defaultData, mo);
            break;
        case PROP:
            mo.setValue(MapObjectProperty.COLLISIONBOX_WIDTH, (newObjectArea.getWidth() * 0.4));
            mo.setValue(MapObjectProperty.COLLISIONBOX_HEIGHT, (newObjectArea.getHeight() * 0.4));
            mo.setValue(MapObjectProperty.COLLISION, true);
            mo.setValue(MapObjectProperty.COMBAT_INDESTRUCTIBLE, false);
            mo.setValue(MapObjectProperty.PROP_ADDSHADOW, true);
            break;
        case LIGHTSOURCE:
            mo.setValue(MapObjectProperty.LIGHT_COLOR, Color.WHITE);
            mo.setValue(MapObjectProperty.LIGHT_SHAPE, "ellipse");
            mo.setValue(MapObjectProperty.LIGHT_ACTIVE, true);
            break;
        case COLLISIONBOX:
            mo.setValue(MapObjectProperty.COLLISION_TYPE, Collision.STATIC);
            break;
        case SOUNDSOURCE:
            mo.setValue(MapObjectProperty.SOUND_VOLUME, 1);
            mo.setValue(MapObjectProperty.SOUND_LOOP, true);
            break;
        case SPAWNPOINT:
            break;
        default:
            break;
    }
    this.add(mo);
    return mo;
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) MapObject(de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) EmitterData(de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData)

Example 7 with EmitterData

use of de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData in project litiengine by gurkenlabs.

the class AssetPanelItem method addEntity.

private boolean addEntity() {
    if (Game.world().environment() == null || Game.world().camera() == null) {
        return false;
    }
    if (this.getOrigin() instanceof SpritesheetResource) {
        SpritesheetResource info = (SpritesheetResource) this.getOrigin();
        MapObject mo = new MapObject();
        String propName = PropPanel.getIdentifierBySpriteName(info.getName());
        String creatureName = CreaturePanel.getCreatureSpriteName(info.getName());
        if (propName != null) {
            mo.setType(MapObjectType.PROP.name());
            mo.setValue(MapObjectProperty.SPRITESHEETNAME, propName);
        } else if (creatureName != null) {
            mo.setType(MapObjectType.CREATURE.name());
            mo.setValue(MapObjectProperty.SPRITESHEETNAME, creatureName);
        } else {
            return false;
        }
        mo.setX((int) Game.world().camera().getFocus().getX() - info.getWidth() / 2f);
        mo.setY((int) Game.world().camera().getFocus().getY() - info.getHeight() / 2f);
        mo.setWidth(info.getWidth());
        mo.setHeight(info.getHeight());
        mo.setId(Game.world().environment().getNextMapId());
        mo.setName("");
        mo.setValue(MapObjectProperty.COLLISIONBOX_WIDTH, info.getWidth() * 0.4);
        mo.setValue(MapObjectProperty.COLLISIONBOX_HEIGHT, info.getHeight() * 0.4);
        mo.setValue(MapObjectProperty.COLLISION, true);
        mo.setValue(MapObjectProperty.COMBAT_INDESTRUCTIBLE, false);
        mo.setValue(MapObjectProperty.PROP_ADDSHADOW, true);
        Editor.instance().getMapComponent().add(mo);
        return true;
    } else if (this.getOrigin() instanceof EmitterData) {
        MapObject newEmitter = (MapObject) EmitterMapObjectLoader.createMapObject((EmitterData) this.getOrigin());
        newEmitter.setX((int) (Game.world().camera().getFocus().getX() - newEmitter.getWidth()));
        newEmitter.setY((int) (Game.world().camera().getFocus().getY() - newEmitter.getHeight()));
        newEmitter.setId(Game.world().environment().getNextMapId());
        Editor.instance().getMapComponent().add(newEmitter);
    } else if (this.getOrigin() instanceof Blueprint) {
        Blueprint blueprint = (Blueprint) this.getOrigin();
        UndoManager.instance().beginOperation();
        try {
            List<IMapObject> newObjects = blueprint.build((int) Game.world().camera().getFocus().getX() - blueprint.getWidth() / 2, (int) Game.world().camera().getFocus().getY() - blueprint.getHeight() / 2);
            for (IMapObject newMapObject : newObjects) {
                Editor.instance().getMapComponent().add(newMapObject);
            }
            // gets added
            for (IMapObject newMapObject : newObjects) {
                Editor.instance().getMapComponent().setSelection(newMapObject, false);
            }
        } finally {
            UndoManager.instance().endOperation();
        }
    }
    return false;
}
Also used : SpritesheetResource(de.gurkenlabs.litiengine.resources.SpritesheetResource) Blueprint(de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) MapObject(de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) EmitterData(de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData)

Example 8 with EmitterData

use of de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData in project litiengine by gurkenlabs.

the class AssetPanelItem method deleteAsset.

private void deleteAsset() {
    if (getOrigin() instanceof SpritesheetResource) {
        SpritesheetResource info = (SpritesheetResource) getOrigin();
        int n = getDeleteDialog("spritesheet", info.getName());
        if (n == JOptionPane.OK_OPTION) {
            Editor.instance().getGameFile().getSpriteSheets().remove(getOrigin());
            Resources.images().clear();
            Resources.spritesheets().remove(info.getName());
            Editor.instance().getMapComponent().reloadEnvironment();
            UI.getAssetController().refresh();
        }
    } else if (getOrigin() instanceof EmitterData) {
        EmitterData emitter = (EmitterData) getOrigin();
        int n = getDeleteDialog("emitter", emitter.getName());
        if (n == JOptionPane.OK_OPTION) {
            Editor.instance().getGameFile().getEmitters().remove(getOrigin());
            Editor.instance().getMapComponent().reloadEnvironment();
            UI.getAssetController().refresh();
        }
    } else if (getOrigin() instanceof Blueprint) {
        Blueprint blueprint = (Blueprint) getOrigin();
        int n = getDeleteDialog("blueprint", blueprint.getName());
        if (n == JOptionPane.OK_OPTION) {
            Editor.instance().getGameFile().getBluePrints().remove(getOrigin());
            UI.getAssetController().refresh();
        }
    } else if (getOrigin() instanceof SoundResource) {
        SoundResource sound = (SoundResource) getOrigin();
        int n = getDeleteDialog("sound", sound.getName());
        if (n == JOptionPane.OK_OPTION) {
            Editor.instance().getGameFile().getSounds().remove(getOrigin());
            UI.getAssetController().refresh();
        }
    }
}
Also used : SpritesheetResource(de.gurkenlabs.litiengine.resources.SpritesheetResource) Blueprint(de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint) SoundResource(de.gurkenlabs.litiengine.resources.SoundResource) Blueprint(de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint) EmitterData(de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData)

Example 9 with EmitterData

use of de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData in project litiengine by gurkenlabs.

the class AssetPanelItem method canAdd.

private boolean canAdd() {
    if (this.getOrigin() instanceof SpritesheetResource) {
        SpritesheetResource info = (SpritesheetResource) this.getOrigin();
        String propName = PropPanel.getIdentifierBySpriteName(info.getName());
        return propName != null && !propName.isEmpty() || CreaturePanel.getCreatureSpriteName(info.getName()) != null;
    }
    return this.getOrigin() instanceof MapObject || this.getOrigin() instanceof EmitterData;
}
Also used : SpritesheetResource(de.gurkenlabs.litiengine.resources.SpritesheetResource) MapObject(de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) EmitterData(de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData)

Example 10 with EmitterData

use of de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData in project litiengine by gurkenlabs.

the class AssetPanelItem method exportEmitter.

private void exportEmitter() {
    if (!(this.getOrigin() instanceof EmitterData)) {
        return;
    }
    EmitterData emitter = (EmitterData) this.getOrigin();
    XmlExportDialog.export(emitter, "Emitter", emitter.getName());
}
Also used : EmitterData(de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData)

Aggregations

EmitterData (de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData)12 IMapObject (de.gurkenlabs.litiengine.environment.tilemap.IMapObject)4 Blueprint (de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint)4 MapObject (de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject)4 SpritesheetResource (de.gurkenlabs.litiengine.resources.SpritesheetResource)3 Emitter (de.gurkenlabs.litiengine.graphics.emitters.Emitter)2 Align (de.gurkenlabs.litiengine.Align)1 Valign (de.gurkenlabs.litiengine.Valign)1 Quality (de.gurkenlabs.litiengine.configuration.Quality)1 IEntity (de.gurkenlabs.litiengine.entities.IEntity)1 Tileset (de.gurkenlabs.litiengine.environment.tilemap.xml.Tileset)1 Spritesheet (de.gurkenlabs.litiengine.graphics.Spritesheet)1 ParticleType (de.gurkenlabs.litiengine.graphics.emitters.particles.ParticleType)1 ParticleParameter (de.gurkenlabs.litiengine.graphics.emitters.xml.ParticleParameter)1 Collision (de.gurkenlabs.litiengine.physics.Collision)1 SoundResource (de.gurkenlabs.litiengine.resources.SoundResource)1 Sound (de.gurkenlabs.litiengine.sound.Sound)1 JAXBException (jakarta.xml.bind.JAXBException)1 Rectangle2D (java.awt.geom.Rectangle2D)1 BufferedImage (java.awt.image.BufferedImage)1