Search in sources :

Example 1 with EmitterData

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

the class EditorScreen method importEmitters.

public void importEmitters() {
    XmlImportDialog.importXml("Emitter", files -> {
        for (File file : files) {
            EmitterData emitter = XmlUtilities.readFromFile(EmitterData.class, file.toString());
            if (emitter == null) {
                continue;
            }
            if (this.gameFile.getEmitters().stream().anyMatch(x -> x.getName().equals(emitter.getName()))) {
                int result = JOptionPane.showConfirmDialog(Game.getScreenManager().getRenderComponent(), Resources.get("import_emitter_question", emitter.getName()), Resources.get("import_emitter_title"), JOptionPane.YES_NO_OPTION);
                if (result == JOptionPane.NO_OPTION) {
                    continue;
                }
                this.gameFile.getEmitters().removeIf(x -> x.getName().equals(emitter.getName()));
            }
            this.gameFile.getEmitters().add(emitter);
            log.log(Level.INFO, "imported emitter {0} from {1}", new Object[] { emitter.getName(), file });
        }
    });
}
Also used : File(java.io.File) EmitterData(de.gurkenlabs.litiengine.graphics.particles.xml.EmitterData) Point(java.awt.Point) Blueprint(de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint)

Example 2 with EmitterData

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

the class AssetPanel method loadEmitters.

public void loadEmitters(List<EmitterData> emitters) {
    this.load(emitters, () -> {
        Collections.sort(emitters);
        for (EmitterData emitter : emitters) {
            AssetPanelItem panelItem = new AssetPanelItem(Icons.DOC_EMITTER, emitter.getName(), emitter);
            this.add(panelItem);
            panelItem.validate();
        }
    });
}
Also used : EmitterData(de.gurkenlabs.litiengine.graphics.particles.xml.EmitterData)

Example 3 with EmitterData

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

the class AssetPanelItem method addEntity.

private boolean addEntity() {
    // TODO: experimental code... this needs to be refactored with issue #66
    if (this.getOrigin() instanceof SpriteSheetInfo) {
        SpriteSheetInfo info = (SpriteSheetInfo) this.getOrigin();
        String propName = PropPanel.getNameBySpriteName(info.getName());
        if (propName == null) {
            return false;
        }
        MapObject mo = new MapObject();
        mo.setType(MapObjectType.PROP.name());
        mo.setX((int) Game.getCamera().getFocus().getX() - info.getWidth() / 2);
        mo.setY((int) Game.getCamera().getFocus().getY() - info.getHeight() / 2);
        mo.setWidth((int) info.getWidth());
        mo.setHeight((int) info.getHeight());
        mo.setId(Game.getEnvironment().getNextMapId());
        mo.setName("");
        mo.setCustomProperty(MapObjectProperty.COLLISIONBOX_WIDTH, (info.getWidth() * 0.4) + "");
        mo.setCustomProperty(MapObjectProperty.COLLISIONBOX_HEIGHT, (info.getHeight() * 0.4) + "");
        mo.setCustomProperty(MapObjectProperty.COLLISION, "true");
        mo.setCustomProperty(MapObjectProperty.PROP_INDESTRUCTIBLE, "false");
        mo.setCustomProperty(MapObjectProperty.PROP_ADDSHADOW, "true");
        mo.setCustomProperty(MapObjectProperty.SPRITESHEETNAME, propName);
        EditorScreen.instance().getMapComponent().add(mo);
        return true;
    } else if (this.getOrigin() instanceof EmitterData) {
        MapObject newEmitter = (MapObject) EmitterMapObjectLoader.createMapObject((EmitterData) this.getOrigin());
        newEmitter.setX((int) (Game.getCamera().getFocus().getX() - newEmitter.getWidth()));
        newEmitter.setY((int) (Game.getCamera().getFocus().getY() - newEmitter.getHeight()));
        newEmitter.setId(Game.getEnvironment().getNextMapId());
        EditorScreen.instance().getMapComponent().add(newEmitter);
    } else if (this.getOrigin() instanceof Blueprint) {
        Blueprint blueprint = (Blueprint) this.getOrigin();
        UndoManager.instance().beginOperation();
        try {
            List<MapObject> newObjects = blueprint.build((int) Game.getCamera().getFocus().getX() - blueprint.getWidth() / 2, (int) Game.getCamera().getFocus().getY() - blueprint.getHeight() / 2);
            for (MapObject newMapObject : newObjects) {
                EditorScreen.instance().getMapComponent().add(newMapObject);
            }
            // gets added
            for (MapObject newMapObject : newObjects) {
                EditorScreen.instance().getMapComponent().setSelection(newMapObject, false);
            }
        } finally {
            UndoManager.instance().endOperation();
        }
    }
    return false;
}
Also used : SpriteSheetInfo(de.gurkenlabs.litiengine.SpriteSheetInfo) Blueprint(de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint) MapObject(de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject) EmitterData(de.gurkenlabs.litiengine.graphics.particles.xml.EmitterData)

Example 4 with EmitterData

use of de.gurkenlabs.litiengine.graphics.particles.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.particles.xml.EmitterData)

Example 5 with EmitterData

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

the class AssetPanelItem method deleteAsset.

private void deleteAsset() {
    if (getOrigin() instanceof SpriteSheetInfo) {
        SpriteSheetInfo info = (SpriteSheetInfo) getOrigin();
        int n = JOptionPane.showConfirmDialog(Game.getScreenManager().getRenderComponent(), "Do you really want to delete the spritesheet [" + info.getName() + "]?\n Entities that use the sprite won't be rendered anymore!", "Delete Spritesheet?", JOptionPane.YES_NO_OPTION);
        if (n == JOptionPane.OK_OPTION) {
            EditorScreen.instance().getGameFile().getSpriteSheets().remove(getOrigin());
            ImageCache.clearAll();
            Spritesheet.remove(info.getName());
            EditorScreen.instance().getMapComponent().reloadEnvironment();
            Program.getAssetTree().forceUpdate();
        }
    } else if (getOrigin() instanceof EmitterData) {
        EmitterData emitter = (EmitterData) getOrigin();
        int n = JOptionPane.showConfirmDialog(Game.getScreenManager().getRenderComponent(), "Do you really want to delete the emitter [" + emitter.getName() + "]", "Delete Emitter?", JOptionPane.YES_NO_OPTION);
        if (n == JOptionPane.OK_OPTION) {
            EditorScreen.instance().getGameFile().getEmitters().remove(getOrigin());
            EditorScreen.instance().getMapComponent().reloadEnvironment();
            Program.getAssetTree().forceUpdate();
        }
    } else if (getOrigin() instanceof Blueprint) {
        Blueprint blueprint = (Blueprint) getOrigin();
        int n = JOptionPane.showConfirmDialog(Game.getScreenManager().getRenderComponent(), "Do you really want to delete the blueprint [" + blueprint.getName() + "]?", "Delete Blueprint?", JOptionPane.YES_NO_OPTION);
        if (n == JOptionPane.OK_OPTION) {
            EditorScreen.instance().getGameFile().getBluePrints().remove(getOrigin());
            Program.getAssetTree().forceUpdate();
        }
    }
}
Also used : SpriteSheetInfo(de.gurkenlabs.litiengine.SpriteSheetInfo) Blueprint(de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint) Blueprint(de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint) EmitterData(de.gurkenlabs.litiengine.graphics.particles.xml.EmitterData)

Aggregations

EmitterData (de.gurkenlabs.litiengine.graphics.particles.xml.EmitterData)8 SpriteSheetInfo (de.gurkenlabs.litiengine.SpriteSheetInfo)3 Blueprint (de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint)3 MapObject (de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject)2 Align (de.gurkenlabs.litiengine.Align)1 Valign (de.gurkenlabs.litiengine.Valign)1 IEntity (de.gurkenlabs.litiengine.entities.IEntity)1 CustomEmitter (de.gurkenlabs.litiengine.graphics.particles.xml.CustomEmitter)1 ParticleParameter (de.gurkenlabs.litiengine.graphics.particles.xml.ParticleParameter)1 ParticleType (de.gurkenlabs.litiengine.graphics.particles.xml.ParticleType)1 CollisionType (de.gurkenlabs.litiengine.physics.CollisionType)1 Point (java.awt.Point)1 File (java.io.File)1