Search in sources :

Example 1 with FileChooserListener

use of com.kotcrab.vis.ui.widget.file.FileChooserListener in project bladecoder-adventure-engine by bladecoder.

the class AssetsList method create.

private void create() {
    final String type = assetTypes.getSelected();
    if (type.equals("atlases")) {
        new CreateAtlasDialog(skin).show(getStage());
    // addAssets();
    } else if (type.equals("particles")) {
        // Open the particle editor
        List<String> cp = new ArrayList<String>();
        cp.add(System.getProperty("java.class.path"));
        try {
            RunProccess.runJavaProccess("com.badlogic.gdx.tools.particleeditor.ParticleEditor", cp, null);
        } catch (IOException e) {
            Message.showMsgDialog(getStage(), "Error", "Error launching Particle Editor.");
            EditorLogger.printStackTrace(e);
        }
    } else {
        FileChooser fileChooser = new FileChooser(Mode.OPEN);
        fileChooser.setSelectionMode(SelectionMode.FILES);
        fileChooser.setMultiSelectionEnabled(true);
        fileChooser.setSize(Gdx.graphics.getWidth() * 0.7f, Gdx.graphics.getHeight() * 0.7f);
        fileChooser.setViewMode(ViewMode.LIST);
        getStage().addActor(fileChooser);
        if (lastDir != null)
            fileChooser.setDirectory(lastDir);
        // chooser.setTitle("Select the '" + type + "' asset files");
        // allow "All Types" mode where all files are shown
        FileTypeFilter typeFilter = new FileTypeFilter(true);
        switch(type) {
            case "images":
                typeFilter.addRule("Images (*.png, *.jpg, *.etc1)", "jpg", "png", "etc1");
                break;
            case "music":
            case "sounds":
            case "voices":
                typeFilter.addRule("Sound (*.mp3, *.wav, *.ogg)", "wav", "mp3", "ogg");
                break;
            case "spine":
                typeFilter.addRule("Spine (*.skel, *.json)", "skel", "json");
                break;
            default:
                typeFilter.addRule("All", "");
                break;
        }
        fileChooser.setFileTypeFilter(typeFilter);
        fileChooser.setListener(new FileChooserListener() {

            @Override
            public void selected(Array<FileHandle> files) {
                try {
                    String dirName = getAssetDir(type);
                    lastDir = files.get(0).parent().file();
                    // Si no existe la carpeta la creamos
                    File dir = new File(dirName);
                    if (!dir.exists())
                        dir.mkdir();
                    for (FileHandle f : files) {
                        if (type.equals("images")) {
                            List<String> res = Ctx.project.getResolutions();
                            for (String r : res) {
                                File destFile = new File(dirName + "/" + r + "/" + f.file().getName());
                                float scale = Float.parseFloat(r);
                                if (scale != 1.0f) {
                                    ImageUtils.scaleImageFile(f.file(), destFile, scale);
                                } else {
                                    Files.copy(f.file().toPath(), destFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
                                }
                            }
                        } else {
                            File destFile = new File(dir, f.file().getName());
                            Files.copy(f.file().toPath(), destFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
                        }
                    }
                    addAssets();
                } catch (Exception ex) {
                    String msg = "Something went wrong while getting the assets.\n\n" + ex.getClass().getSimpleName() + " - " + ex.getMessage();
                    Message.showMsgDialog(getStage(), "Error", msg);
                    EditorLogger.printStackTrace(ex);
                }
            }

            @Override
            public void canceled() {
            }
        });
    }
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) FileTypeFilter(com.kotcrab.vis.ui.widget.file.FileTypeFilter) IOException(java.io.IOException) IOException(java.io.IOException) Array(com.badlogic.gdx.utils.Array) FileChooserListener(com.kotcrab.vis.ui.widget.file.FileChooserListener) FileChooser(com.kotcrab.vis.ui.widget.file.FileChooser) ArrayList(java.util.ArrayList) CustomList(com.bladecoder.engineeditor.ui.panels.CustomList) List(java.util.List) File(java.io.File)

Example 2 with FileChooserListener

use of com.kotcrab.vis.ui.widget.file.FileChooserListener in project bladecoder-adventure-engine by bladecoder.

the class ToolsWindow method exportTSV.

private void exportTSV() {
    FileChooser fileChooser = new FileChooser(Mode.SAVE);
    fileChooser.setSize(Gdx.graphics.getWidth() * 0.7f, Gdx.graphics.getHeight() * 0.7f);
    fileChooser.setViewMode(ViewMode.LIST);
    fileChooser.setSelectionMode(SelectionMode.FILES);
    getStage().addActor(fileChooser);
    fileChooser.setListener(new FileChooserListener() {

        @Override
        public void selected(Array<FileHandle> files) {
            try {
                // fileChooser.setTitle("Select the file to export the
                // project texts");
                I18NUtils.exportTSV(Ctx.project.getAssetPath() + Project.MODEL_PATH, files.get(0).file().getAbsolutePath(), Ctx.project.getChapter().getId(), "default");
                Message.showMsg(getStage(), files.get(0).file().getName() + " exported sucessfully.", 4);
            } catch (IOException e) {
                Message.showMsg(getStage(), "There was a problem generating the .tsv file.", 4);
                EditorLogger.printStackTrace(e);
            }
        }

        @Override
        public void canceled() {
        }
    });
}
Also used : FileChooserListener(com.kotcrab.vis.ui.widget.file.FileChooserListener) FileHandle(com.badlogic.gdx.files.FileHandle) FileChooser(com.kotcrab.vis.ui.widget.file.FileChooser) IOException(java.io.IOException)

Example 3 with FileChooserListener

use of com.kotcrab.vis.ui.widget.file.FileChooserListener in project bladecoder-adventure-engine by bladecoder.

the class ToolsWindow method createUIAtlas.

protected void createUIAtlas() {
    FileChooser fileChooser = new FileChooser(Mode.OPEN);
    fileChooser.setSize(Gdx.graphics.getWidth() * 0.7f, Gdx.graphics.getHeight() * 0.7f);
    fileChooser.setViewMode(ViewMode.LIST);
    fileChooser.setSelectionMode(SelectionMode.DIRECTORIES);
    getStage().addActor(fileChooser);
    fileChooser.setListener(new FileChooserListener() {

        @Override
        public void selected(Array<FileHandle> files) {
            List<String> res = Ctx.project.getResolutions();
            for (String r : res) {
                float scale = Float.parseFloat(r);
                try {
                    int maxWH = (int) (ImageUtils.getRecommendedAtlasSize() * scale);
                    ImageUtils.createAtlas(files.get(0).file().getAbsolutePath(), Ctx.project.getAssetPath() + Project.UI_PATH + "/" + r, "ui" + ".atlas", scale, maxWH, maxWH, TextureFilter.Linear, TextureFilter.Nearest, "png", false);
                } catch (IOException e) {
                    EditorLogger.error(e.getMessage());
                    Message.showMsgDialog(getStage(), "Error creating atlas", e.getMessage());
                    return;
                }
            }
            Message.showMsg(getStage(), "UI Atlas created sucessfully.", 4);
        }

        @Override
        public void canceled() {
        }
    });
}
Also used : FileChooserListener(com.kotcrab.vis.ui.widget.file.FileChooserListener) FileHandle(com.badlogic.gdx.files.FileHandle) FileChooser(com.kotcrab.vis.ui.widget.file.FileChooser) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException)

Example 4 with FileChooserListener

use of com.kotcrab.vis.ui.widget.file.FileChooserListener in project bladecoder-adventure-engine by bladecoder.

the class ToolsWindow method exportUIImages.

protected void exportUIImages() {
    FileChooser fileChooser = new FileChooser(Mode.OPEN);
    fileChooser.setSize(Gdx.graphics.getWidth() * 0.7f, Gdx.graphics.getHeight() * 0.7f);
    fileChooser.setViewMode(ViewMode.LIST);
    fileChooser.setSelectionMode(SelectionMode.DIRECTORIES);
    getStage().addActor(fileChooser);
    fileChooser.setListener(new FileChooserListener() {

        @Override
        public void selected(Array<FileHandle> files) {
            try {
                // fileChooser.setTitle("Select the file to export the
                // project texts");
                ImageUtils.unpackAtlas(new File(Ctx.project.getAssetPath() + Project.UI_PATH + "/1/ui.atlas"), files.get(0).file());
                Message.showMsg(getStage(), "UI Atlas images exported sucessfully.", 4);
            } catch (Exception e) {
                Message.showMsg(getStage(), "There was a problem exporting images from UI Atlas.", 4);
                EditorLogger.printStackTrace(e);
            }
        }

        @Override
        public void canceled() {
        }
    });
}
Also used : FileChooserListener(com.kotcrab.vis.ui.widget.file.FileChooserListener) FileHandle(com.badlogic.gdx.files.FileHandle) FileChooser(com.kotcrab.vis.ui.widget.file.FileChooser) File(java.io.File) IOException(java.io.IOException)

Example 5 with FileChooserListener

use of com.kotcrab.vis.ui.widget.file.FileChooserListener in project bladecoder-adventure-engine by bladecoder.

the class ToolsWindow method importTSV.

private void importTSV() {
    FileChooser fileChooser = new FileChooser(Mode.OPEN);
    fileChooser.setSize(Gdx.graphics.getWidth() * 0.7f, Gdx.graphics.getHeight() * 0.7f);
    fileChooser.setViewMode(ViewMode.LIST);
    fileChooser.setSelectionMode(SelectionMode.FILES);
    getStage().addActor(fileChooser);
    fileChooser.setListener(new FileChooserListener() {

        @Override
        public void selected(Array<FileHandle> files) {
            try {
                // chooser.setTitle("Select the .tsv file to import");
                I18NUtils.importTSV(Ctx.project.getAssetPath() + Project.MODEL_PATH, files.get(0).file().getAbsolutePath(), Ctx.project.getChapter().getId(), "default");
                // Reload texts
                Ctx.project.getI18N().load(Ctx.project.getChapter().getId());
                Message.showMsg(getStage(), files.get(0).file().getName() + " imported sucessfully.", 4);
            } catch (IOException e) {
                Message.showMsg(getStage(), "There was a problem importing the .tsv file.", 4);
                EditorLogger.printStackTrace(e);
            }
        }

        @Override
        public void canceled() {
        }
    });
}
Also used : FileChooserListener(com.kotcrab.vis.ui.widget.file.FileChooserListener) FileHandle(com.badlogic.gdx.files.FileHandle) FileChooser(com.kotcrab.vis.ui.widget.file.FileChooser) IOException(java.io.IOException)

Aggregations

FileHandle (com.badlogic.gdx.files.FileHandle)6 FileChooserListener (com.kotcrab.vis.ui.widget.file.FileChooserListener)6 IOException (java.io.IOException)6 FileChooser (com.kotcrab.vis.ui.widget.file.FileChooser)5 File (java.io.File)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Array (com.badlogic.gdx.utils.Array)1 CustomList (com.bladecoder.engineeditor.ui.panels.CustomList)1 FileTypeFilter (com.kotcrab.vis.ui.widget.file.FileTypeFilter)1