Search in sources :

Example 86 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project skin-composer by raeleus.

the class Dialog9Patch method showLoadPatchesDialog.

private void showLoadPatchesDialog() {
    Runnable runnable = () -> {
        String defaultPath = projectData.getLastDrawablePath();
        String[] filterPatterns = null;
        if (!Utils.isMac()) {
            filterPatterns = new String[] { "*.9.png;" };
        }
        File file = desktopWorker.openDialog("Load Patches from File...", defaultPath, filterPatterns, "Nine Patch files");
        if (file != null) {
            Gdx.app.postRunnable(() -> {
                var fileHandle = new FileHandle(file);
                loadPatches(fileHandle);
            });
        }
    };
    dialogFactory.showDialogLoading(runnable);
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) File(java.io.File)

Example 87 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project skin-composer by raeleus.

the class DialogDrawables method finalizeDrawables.

/**
 * Adds the drawables to the project.
 * @param backup If there is a failure, the drawable list will be rolled
 * back to the provided backup.
 * @param filesToProcess
 */
private void finalizeDrawables(Array<DrawableData> backup, Array<FileHandle> filesToProcess) {
    for (FileHandle file : filesToProcess) {
        DrawableData data = new DrawableData(file);
        if (Utils.isNinePatch(file.name())) {
            data.type = DrawableType.NINE_PATCH;
        } else {
            data.type = DrawableType.TEXTURE;
        }
        if (!checkIfNameExists(data.name)) {
            atlasData.getDrawables().add(data);
        }
    }
    gatherDrawables();
    dialogFactory.showDialogLoading(() -> {
        Gdx.app.postRunnable(() -> {
            if (!atlasData.produceAtlas()) {
                showDrawableError();
                Gdx.app.log(getClass().getName(), "Attempting to reload drawables backup...");
                atlasData.getDrawables().clear();
                atlasData.getDrawables().addAll(backup);
                gatherDrawables();
                if (atlasData.produceAtlas()) {
                    Gdx.app.log(getClass().getName(), "Successfully rolled back changes to drawables");
                } else {
                    Gdx.app.error(getClass().getName(), "Critical failure, could not roll back changes to drawables");
                }
            } else {
                if (projectData.areResourcesRelative()) {
                    projectData.makeResourcesRelative();
                }
                projectData.setChangesSaved(false);
            }
            sortBySelectedMode();
        });
    });
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle)

Example 88 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project skin-composer by raeleus.

the class DialogDrawables method drawablesSelected.

private void drawablesSelected(Array<FileHandle> files) {
    atlasData.atlasCurrent = false;
    Array<DrawableData> backup = new Array<>(atlasData.getDrawables());
    Array<FileHandle> unhandledFiles = new Array<>();
    Array<FileHandle> filesToProcess = new Array<>();
    projectData.setLastDrawablePath(files.get(0).parent().path() + "/");
    for (FileHandle fileHandle : files) {
        var duplicateDrawable = checkDuplicateDrawables(DrawableData.proper(fileHandle.name()), 0);
        var duplicateFontDrawable = checkDuplicateFontDrawables(DrawableData.proper(fileHandle.name()), 0);
        if (duplicateDrawable || duplicateFontDrawable) {
            unhandledFiles.add(fileHandle);
        } else {
            filesToProcess.add(fileHandle);
        }
    }
    if (unhandledFiles.size > 0) {
        showRemoveDuplicatesDialog(unhandledFiles, backup, filesToProcess);
    } else {
        finalizeDrawables(backup, filesToProcess);
    }
}
Also used : Array(com.badlogic.gdx.utils.Array) FileHandle(com.badlogic.gdx.files.FileHandle)

Example 89 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project skin-composer by raeleus.

the class DialogDrawables method initialize.

public void initialize(Main main, DialogDrawablesListener listener) {
    Table table = new Table();
    table.setFillParent(true);
    table.setTouchable(Touchable.disabled);
    addActor(table);
    Label label = new Label("", getSkin(), "filter");
    label.setName("filter-label");
    label.setColor(1, 1, 1, 0);
    table.add(label).bottom().right().expand().pad(50).padBottom(20);
    filterInputListener = new FilterInputListener(this);
    addListener(filterInputListener);
    showing9patchButton = true;
    showingOptions = true;
    this.main = main;
    instance = this;
    this.listener = listener;
    filesDroppedListener = (Array<FileHandle> files) -> {
        Iterator<FileHandle> iter = files.iterator();
        while (iter.hasNext()) {
            FileHandle file = iter.next();
            if (file.isDirectory()) {
                files.addAll(file.list());
                iter.remove();
            } else if (!(file.name().toLowerCase().endsWith(".png") || file.name().toLowerCase().endsWith(".jpg") || file.name().toLowerCase().endsWith(".jpeg") || file.name().toLowerCase().endsWith(".bmp") || file.name().toLowerCase().endsWith(".gif"))) {
                iter.remove();
            }
        }
        var filesLimited = new Array<FileHandle>(files);
        iter = filesLimited.iterator();
        while (iter.hasNext()) {
            var file = iter.next();
            if (!file.name().toLowerCase(Locale.ROOT).endsWith(".9.png")) {
                if (files.contains(file.sibling(file.nameWithoutExtension() + ".9.png"), false)) {
                    iter.remove();
                }
            }
        }
        if (filesLimited.size > 0) {
            drawablesSelected(filesLimited);
        }
    };
    desktopWorker.addFilesDroppedListener(filesDroppedListener);
    gatherDrawables();
    atlasData.produceAtlas();
    populate();
}
Also used : Array(com.badlogic.gdx.utils.Array) FileHandle(com.badlogic.gdx.files.FileHandle)

Example 90 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project skin-composer by raeleus.

the class DialogDrawables method drawablesSelected.

/**
 * Called when a selection of drawables has been chosen from the
 * newDrawablesDialog(). Adds the new drawables to the project.
 * @param files
 */
private void drawablesSelected(List<File> files) {
    Array<FileHandle> fileHandles = new Array<>();
    files.forEach((file) -> {
        fileHandles.add(new FileHandle(file));
    });
    drawablesSelected(fileHandles);
}
Also used : Array(com.badlogic.gdx.utils.Array) FileHandle(com.badlogic.gdx.files.FileHandle)

Aggregations

FileHandle (com.badlogic.gdx.files.FileHandle)207 File (java.io.File)62 IOException (java.io.IOException)38 Array (com.badlogic.gdx.utils.Array)36 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)28 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)16 TextureAtlasData (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData)16 Texture (com.badlogic.gdx.graphics.Texture)15 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)13 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)12 ArrayList (java.util.ArrayList)12 Region (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region)11 Color (com.badlogic.gdx.graphics.Color)10 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)10 IntArray (com.badlogic.gdx.utils.IntArray)10 Pixmap (com.badlogic.gdx.graphics.Pixmap)9 BitmapFontData (com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData)9 Element (com.badlogic.gdx.utils.XmlReader.Element)9 Locale (java.util.Locale)9 FreeTypeFontGenerator (com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator)8