Search in sources :

Example 1 with SpritesheetImportPanel

use of de.gurkenlabs.utiliti.swing.dialogs.SpritesheetImportPanel 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)

Aggregations

SpriteSheetInfo (de.gurkenlabs.litiengine.SpriteSheetInfo)1 Blueprint (de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint)1 SpritesheetImportPanel (de.gurkenlabs.utiliti.swing.dialogs.SpritesheetImportPanel)1 Point (java.awt.Point)1 File (java.io.File)1 IOException (java.io.IOException)1 JFileChooser (javax.swing.JFileChooser)1 FileFilter (javax.swing.filechooser.FileFilter)1 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)1