Search in sources :

Example 1 with SpriteSheetInfo

use of de.gurkenlabs.litiengine.SpriteSheetInfo in project litiengine by gurkenlabs.

the class EditorScreen method loadSpriteSheets.

private void loadSpriteSheets(Map map) {
    List<SpriteSheetInfo> infos = new ArrayList<>();
    int cnt = 0;
    for (ITileset tileSet : map.getTilesets()) {
        if (tileSet.getImage() == null || Spritesheet.find(tileSet.getName()) != null) {
            continue;
        }
        Spritesheet sprite = Spritesheet.find(tileSet.getImage().getSource());
        if (sprite == null) {
            sprite = Spritesheet.load(tileSet);
            if (sprite == null) {
                continue;
            }
        }
        infos.add(new SpriteSheetInfo(sprite));
        cnt++;
    }
    for (IImageLayer imageLayer : map.getImageLayers()) {
        Spritesheet sprite = Spritesheet.find(imageLayer.getImage().getSource());
        if (sprite == null) {
            BufferedImage img = Resources.getImage(imageLayer.getImage().getAbsoluteSourcePath(), true);
            sprite = Spritesheet.load(img, imageLayer.getImage().getSource(), img.getWidth(), img.getHeight());
            if (sprite == null) {
                continue;
            }
        }
        SpriteSheetInfo info = new SpriteSheetInfo(sprite);
        infos.add(info);
        this.getGameFile().getSpriteSheets().removeIf(x -> x.getName().equals(info.getName()));
        this.getGameFile().getSpriteSheets().add(info);
        cnt++;
    }
    this.loadSpriteSheets(infos, false);
    for (SpriteSheetInfo info : infos) {
        if (!this.getGameFile().getSpriteSheets().stream().anyMatch(x -> x.getName().equals(info.getName()))) {
            this.getGameFile().getSpriteSheets().add(info);
        }
    }
    if (cnt > 0) {
        log.log(Level.INFO, "{0} tilesets loaded from {1}", new Object[] { cnt, map.getFileName() });
    }
}
Also used : Color(java.awt.Color) ITileset(de.gurkenlabs.litiengine.environment.tilemap.ITileset) EditorComponent(de.gurkenlabs.utiliti.components.EditorComponent) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) Spritesheet(de.gurkenlabs.litiengine.graphics.Spritesheet) Point(java.awt.Point) ComponentType(de.gurkenlabs.utiliti.components.EditorComponent.ComponentType) MathUtilities(de.gurkenlabs.litiengine.util.MathUtilities) SpriteSheetInfo(de.gurkenlabs.litiengine.SpriteSheetInfo) Map(de.gurkenlabs.litiengine.environment.tilemap.xml.Map) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Blueprint(de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint) MapComponent(de.gurkenlabs.utiliti.components.MapComponent) Graphics2D(java.awt.Graphics2D) ImageCache(de.gurkenlabs.litiengine.graphics.ImageCache) FileUtilities(de.gurkenlabs.litiengine.util.io.FileUtilities) Tileset(de.gurkenlabs.litiengine.environment.tilemap.xml.Tileset) JFileChooser(javax.swing.JFileChooser) Resources(de.gurkenlabs.litiengine.Resources) IImageLayer(de.gurkenlabs.litiengine.environment.tilemap.IImageLayer) BufferedImage(java.awt.image.BufferedImage) Font(java.awt.Font) EmitterData(de.gurkenlabs.litiengine.graphics.particles.xml.EmitterData) Collection(java.util.Collection) IOException(java.io.IOException) Logger(java.util.logging.Logger) JOptionPane(javax.swing.JOptionPane) FileFilter(javax.swing.filechooser.FileFilter) Collectors(java.util.stream.Collectors) MapObjectPanel(de.gurkenlabs.utiliti.swing.panels.MapObjectPanel) File(java.io.File) GameData(de.gurkenlabs.litiengine.GameData) Input(de.gurkenlabs.litiengine.input.Input) ImageFormat(de.gurkenlabs.litiengine.graphics.ImageFormat) List(java.util.List) CustomEmitter(de.gurkenlabs.litiengine.graphics.particles.xml.CustomEmitter) XmlUtilities(de.gurkenlabs.litiengine.util.io.XmlUtilities) Paths(java.nio.file.Paths) Screen(de.gurkenlabs.litiengine.gui.screens.Screen) RenderEngine(de.gurkenlabs.litiengine.graphics.RenderEngine) SpritesheetImportPanel(de.gurkenlabs.utiliti.swing.dialogs.SpritesheetImportPanel) Game(de.gurkenlabs.litiengine.Game) ScreenInfo(de.gurkenlabs.litiengine.annotation.ScreenInfo) XmlImportDialog(de.gurkenlabs.utiliti.swing.XmlImportDialog) SpriteSheetInfo(de.gurkenlabs.litiengine.SpriteSheetInfo) ITileset(de.gurkenlabs.litiengine.environment.tilemap.ITileset) Spritesheet(de.gurkenlabs.litiengine.graphics.Spritesheet) ArrayList(java.util.ArrayList) IImageLayer(de.gurkenlabs.litiengine.environment.tilemap.IImageLayer) Point(java.awt.Point) Blueprint(de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint) BufferedImage(java.awt.image.BufferedImage)

Example 2 with SpriteSheetInfo

use of de.gurkenlabs.litiengine.SpriteSheetInfo in project litiengine by gurkenlabs.

the class EditorScreen method importSpritesheets.

public void importSpritesheets() {
    JFileChooser chooser;
    try {
        chooser = new JFileChooser(new File(this.getProjectPath()).getCanonicalPath());
        FileFilter filter = new FileNameExtensionFilter(SPRITESHEET_FILE_NAME, ImageFormat.getAllExtensions());
        chooser.setFileFilter(filter);
        chooser.addChoosableFileFilter(filter);
        chooser.setMultiSelectionEnabled(true);
        if (chooser.showOpenDialog(Game.getScreenManager().getRenderComponent()) == JFileChooser.APPROVE_OPTION) {
            SpritesheetImportPanel spritePanel = new SpritesheetImportPanel(chooser.getSelectedFiles());
            int option = JOptionPane.showConfirmDialog(Game.getScreenManager().getRenderComponent(), spritePanel, Resources.get("menu_assets_editSprite"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
            if (option != JOptionPane.OK_OPTION) {
                return;
            }
            // TODO: somehow improve this to allow keeping the animation frames and only update the image
            Collection<SpriteSheetInfo> sprites = spritePanel.getSpriteSheets();
            for (SpriteSheetInfo info : sprites) {
                this.getGameFile().getSpriteSheets().removeIf(x -> x.getName().equals(info.getName()));
                this.getGameFile().getSpriteSheets().add(info);
                log.log(Level.INFO, "imported spritesheet {0}", new Object[] { info.getName() });
            }
            this.loadSpriteSheets(sprites, true);
        }
    } catch (IOException e) {
        log.log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
}
Also used : SpriteSheetInfo(de.gurkenlabs.litiengine.SpriteSheetInfo) JFileChooser(javax.swing.JFileChooser) SpritesheetImportPanel(de.gurkenlabs.utiliti.swing.dialogs.SpritesheetImportPanel) IOException(java.io.IOException) FileFilter(javax.swing.filechooser.FileFilter) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File) Point(java.awt.Point) Blueprint(de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint)

Example 3 with SpriteSheetInfo

use of de.gurkenlabs.litiengine.SpriteSheetInfo in project litiengine by gurkenlabs.

the class MapComponent method loadTileset.

public void loadTileset(ITileset tileset, boolean embedded) {
    Spritesheet sprite = Spritesheet.find(tileset.getImage().getSource());
    if (sprite != null) {
        Spritesheet.remove(sprite.getName());
        this.screen.getGameFile().getSpriteSheets().removeIf(x -> x.getName().equals(sprite.getName()));
    }
    Spritesheet newSprite = Spritesheet.load(tileset);
    SpriteSheetInfo info = new SpriteSheetInfo(newSprite);
    EditorScreen.instance().getGameFile().getSpriteSheets().removeIf(x -> x.getName().equals(info.getName()));
    EditorScreen.instance().getGameFile().getSpriteSheets().add(info);
    EditorScreen.instance().loadSpriteSheets(Arrays.asList(info), true);
    if (!embedded) {
        this.screen.getGameFile().getTilesets().removeIf(x -> x.getName().equals(tileset.getName()));
        this.screen.getGameFile().getTilesets().add((Tileset) tileset);
    }
}
Also used : SpriteSheetInfo(de.gurkenlabs.litiengine.SpriteSheetInfo) Spritesheet(de.gurkenlabs.litiengine.graphics.Spritesheet)

Example 4 with SpriteSheetInfo

use of de.gurkenlabs.litiengine.SpriteSheetInfo in project litiengine by gurkenlabs.

the class AssetPanel method loadSprites.

public void loadSprites(List<SpriteSheetInfo> infos) {
    this.load(infos, () -> {
        Collections.sort(infos);
        for (SpriteSheetInfo info : infos) {
            Icon icon;
            Spritesheet sprite = Spritesheet.find(info.getName());
            if (sprite == null || sprite.getSprite(0) == null) {
                icon = null;
            } else {
                icon = new ImageIcon(ImageProcessing.scaleImage(sprite.getSprite(0), 64, 64, true));
            }
            AssetPanelItem panelItem = new AssetPanelItem(icon, info.getName(), info);
            this.add(panelItem);
            panelItem.validate();
        }
    });
}
Also used : ImageIcon(javax.swing.ImageIcon) SpriteSheetInfo(de.gurkenlabs.litiengine.SpriteSheetInfo) Spritesheet(de.gurkenlabs.litiengine.graphics.Spritesheet) Icon(javax.swing.Icon) ImageIcon(javax.swing.ImageIcon)

Example 5 with SpriteSheetInfo

use of de.gurkenlabs.litiengine.SpriteSheetInfo in project litiengine by gurkenlabs.

the class EditorScreen method importSpriteFile.

public void importSpriteFile() {
    JFileChooser chooser;
    try {
        chooser = new JFileChooser(new File(this.getProjectPath()).getCanonicalPath());
        FileFilter filter = new FileNameExtensionFilter(SPRITE_FILE_NAME, SpriteSheetInfo.PLAIN_TEXT_FILE_EXTENSION);
        chooser.setFileFilter(filter);
        chooser.addChoosableFileFilter(filter);
        if (chooser.showOpenDialog(Game.getScreenManager().getRenderComponent()) == JFileChooser.APPROVE_OPTION) {
            File spriteFile = chooser.getSelectedFile();
            if (spriteFile == null) {
                return;
            }
            List<Spritesheet> loaded = Spritesheet.load(spriteFile.toString());
            List<SpriteSheetInfo> infos = new ArrayList<>();
            for (Spritesheet sprite : loaded) {
                SpriteSheetInfo info = new SpriteSheetInfo(sprite);
                infos.add(info);
                this.getGameFile().getSpriteSheets().removeIf(x -> x.getName().equals(info.getName()));
                this.getGameFile().getSpriteSheets().add(info);
            }
            this.loadSpriteSheets(infos, true);
        }
    } catch (IOException e) {
        log.log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
}
Also used : SpriteSheetInfo(de.gurkenlabs.litiengine.SpriteSheetInfo) JFileChooser(javax.swing.JFileChooser) Spritesheet(de.gurkenlabs.litiengine.graphics.Spritesheet) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FileFilter(javax.swing.filechooser.FileFilter) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File)

Aggregations

SpriteSheetInfo (de.gurkenlabs.litiengine.SpriteSheetInfo)5 Spritesheet (de.gurkenlabs.litiengine.graphics.Spritesheet)4 File (java.io.File)3 IOException (java.io.IOException)3 JFileChooser (javax.swing.JFileChooser)3 FileFilter (javax.swing.filechooser.FileFilter)3 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)3 Blueprint (de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint)2 SpritesheetImportPanel (de.gurkenlabs.utiliti.swing.dialogs.SpritesheetImportPanel)2 Point (java.awt.Point)2 ArrayList (java.util.ArrayList)2 Game (de.gurkenlabs.litiengine.Game)1 GameData (de.gurkenlabs.litiengine.GameData)1 Resources (de.gurkenlabs.litiengine.Resources)1 ScreenInfo (de.gurkenlabs.litiengine.annotation.ScreenInfo)1 IImageLayer (de.gurkenlabs.litiengine.environment.tilemap.IImageLayer)1 ITileset (de.gurkenlabs.litiengine.environment.tilemap.ITileset)1 Map (de.gurkenlabs.litiengine.environment.tilemap.xml.Map)1 Tileset (de.gurkenlabs.litiengine.environment.tilemap.xml.Tileset)1 ImageCache (de.gurkenlabs.litiengine.graphics.ImageCache)1