Search in sources :

Example 11 with FontData

use of com.ray3k.skincomposer.data.FontData in project skin-composer by raeleus.

the class DialogFreeTypeFont method updateDisabledFields.

private void updateDisabledFields() {
    CheckBox checkBox = findActor("serializerCheckBox");
    SelectBox selectBox = findActor("previewSelectBox");
    selectBox.setDisabled(checkBox.isChecked());
    boolean notValid = false;
    if (checkBox.isChecked()) {
        if (data.color == null)
            notValid = true;
        else if (data.file == null || !data.file.exists())
            notValid = true;
        else if (!MathUtils.isZero(data.borderWidth) && data.borderColor == null)
            notValid = true;
        else if ((data.shadowOffsetX != 0 || data.shadowOffsetY != 0) && data.shadowColor == null)
            notValid = true;
    }
    if (notValid) {
        TextField textField = findActor("previewField");
        Cell cell = ((Table) textField.getParent()).getCell(textField);
        previewStyle.font = skin.get("free-type-preview", TextFieldStyle.class).font;
        textField = new TextField(previewText, previewStyle);
        textField.setName("previewField");
        textField.setAlignment(Align.center);
        cell.setActor(textField);
    } else {
        data.createBitmapFont(main);
        if (data.bitmapFont != null) {
            TextField textField = findActor("previewField");
            Cell cell = ((Table) textField.getParent()).getCell(textField);
            previewStyle.font = data.bitmapFont;
            textField = new TextField(previewText, previewStyle);
            textField.setName("previewField");
            textField.setAlignment(Align.center);
            cell.setActor(textField);
        }
    }
    if (!StyleData.validate(((TextField) findActor("fontName")).getText()))
        notValid = true;
    for (FontData font : main.getJsonData().getFonts()) {
        if (font.getName().equals(data.name)) {
            notValid = true;
            break;
        }
    }
    for (FreeTypeFontData font : main.getJsonData().getFreeTypeFonts()) {
        if (font.name.equals(data.name) && (mode == Mode.NEW || !font.name.equals(originalData.name))) {
            notValid = true;
            break;
        }
    }
    TextButton textButton = findActor("okButton");
    textButton.setDisabled(notValid);
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) SelectBox(com.badlogic.gdx.scenes.scene2d.ui.SelectBox) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) FontData(com.ray3k.skincomposer.data.FontData) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Cell(com.badlogic.gdx.scenes.scene2d.ui.Cell)

Example 12 with FontData

use of com.ray3k.skincomposer.data.FontData in project skin-composer by raeleus.

the class DialogPathErrors method resolveAssetsFromFolder.

private void resolveAssetsFromFolder(FileHandle folder, Array<DrawableData> drawables, Array<FontData> fonts) {
    if (folder.isDirectory()) {
        for (DrawableData drawable : drawables) {
            if (!foundDrawables.contains(drawable, true)) {
                FileHandle file = folder.child(drawable.file.name());
                if (file.exists()) {
                    drawable.file = file;
                    foundDrawables.add(drawable);
                }
            }
        }
        for (FontData font : fonts) {
            if (!foundFonts.contains(font, true)) {
                FileHandle file = folder.child(font.file.name());
                if (file.exists()) {
                    font.file = file;
                    foundFonts.add(font);
                }
            }
        }
    }
    applyButton.setDisabled(foundDrawables.size != drawables.size || foundFonts.size != fonts.size);
}
Also used : DrawableData(com.ray3k.skincomposer.data.DrawableData) FileHandle(com.badlogic.gdx.files.FileHandle) FontData(com.ray3k.skincomposer.data.FontData)

Example 13 with FontData

use of com.ray3k.skincomposer.data.FontData in project skin-composer by raeleus.

the class DialogPathErrors method resetDrawableTable.

private void resetDrawableTable(Main main, Skin skin, Array<DrawableData> drawables, Array<FontData> fonts) {
    dataTable.clear();
    if (drawables.size > 0) {
        Label label = new Label("Drawable Name", skin, "black");
        dataTable.add(label);
        label = new Label("Path", skin, "black");
        dataTable.add(label);
        dataTable.add();
        label = new Label("Found?", skin, "black");
        dataTable.add(label);
        dataTable.row();
        Image image = new Image(skin, "welcome-separator");
        dataTable.add(image).colspan(4).pad(5.0f).padLeft(0.0f).padRight(0.0f).growX();
        for (DrawableData drawable : drawables) {
            dataTable.row();
            label = new Label(drawable.name, skin);
            dataTable.add(label);
            label = new Label(drawable.file.path(), skin);
            label.setWrap(true);
            label.setAlignment(Align.left);
            dataTable.add(label).growX();
            TextButton textButton = new TextButton("browse...", skin);
            textButton.addListener(main.getHandListener());
            dataTable.add(textButton).padLeft(10.0f);
            textButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    DesktopWorker desktopWorker = main.getDesktopWorker();
                    String[] filterPatterns = null;
                    if (!Utils.isMac()) {
                        filterPatterns = new String[] { "*.png", "*.jpg", "*.jpeg", "*.bmp", "*.gif" };
                    }
                    File file = desktopWorker.openDialog("Locate " + drawable.file.name() + "...", drawable.file.path(), filterPatterns, "Image files");
                    if (file != null) {
                        FileHandle fileHandle = new FileHandle(file);
                        drawable.file = fileHandle;
                        if (!foundDrawables.contains(drawable, true)) {
                            foundDrawables.add(drawable);
                        }
                        resolveAssetsFromFolder(fileHandle.parent(), drawables, fonts);
                        resetDrawableTable(main, skin, drawables, fonts);
                    }
                }
            });
            if (foundDrawables.contains(drawable, true)) {
                label = new Label("YES", skin, "white");
                label.setColor(Color.GREEN);
                dataTable.add(label);
            } else {
                label = new Label("NO", skin, "white");
                label.setColor(Color.RED);
                dataTable.add(label);
            }
            dataTable.row();
            image = new Image(skin, "welcome-separator");
            dataTable.add(image).colspan(4).pad(5.0f).padLeft(0.0f).padRight(0.0f).growX();
        }
    }
    if (fonts.size > 0) {
        dataTable.row();
        dataTable.defaults().padTop(20.0f);
        Label label = new Label("Font Name", skin, "black");
        dataTable.add(label);
        label = new Label("Path", skin, "black");
        dataTable.add(label);
        dataTable.add();
        label = new Label("Found?", skin, "black");
        dataTable.add(label);
        dataTable.defaults().reset();
        dataTable.row();
        Image image = new Image(skin, "welcome-separator");
        dataTable.add(image).colspan(4).pad(5.0f).padLeft(0.0f).padRight(0.0f).growX();
        for (FontData font : fonts) {
            dataTable.row();
            label = new Label(font.getName(), skin);
            dataTable.add(label);
            label = new Label(font.file.path(), skin);
            label.setWrap(true);
            label.setAlignment(Align.left);
            dataTable.add(label).growX();
            TextButton textButton = new TextButton("browse...", skin);
            textButton.addListener(main.getHandListener());
            dataTable.add(textButton);
            textButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    DesktopWorker desktopWorker = main.getDesktopWorker();
                    String[] filterPatterns = null;
                    if (!Utils.isMac()) {
                        filterPatterns = new String[] { "*.fnt" };
                    }
                    File file = desktopWorker.openDialog("Locate " + font.file.name() + "...", font.file.path(), filterPatterns, "Font files");
                    if (file != null) {
                        FileHandle fileHandle = new FileHandle(file);
                        font.file = fileHandle;
                        if (!foundFonts.contains(font, true)) {
                            foundFonts.add(font);
                        }
                        resolveAssetsFromFolder(fileHandle.parent(), drawables, fonts);
                        resetDrawableTable(main, skin, drawables, fonts);
                    }
                }
            });
            if (foundFonts.contains(font, true)) {
                label = new Label("YES", skin, "white");
                label.setColor(Color.GREEN);
                dataTable.add(label);
            } else {
                label = new Label("NO", skin, "white");
                label.setColor(Color.RED);
                dataTable.add(label);
            }
            dataTable.row();
            image = new Image(skin, "welcome-separator");
            dataTable.add(image).colspan(4).pad(5.0f).padLeft(0.0f).padRight(0.0f).growX();
        }
    }
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) DesktopWorker(com.ray3k.skincomposer.DesktopWorker) FileHandle(com.badlogic.gdx.files.FileHandle) FontData(com.ray3k.skincomposer.data.FontData) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) DrawableData(com.ray3k.skincomposer.data.DrawableData) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) File(java.io.File)

Example 14 with FontData

use of com.ray3k.skincomposer.data.FontData in project skin-composer by raeleus.

the class MainListener method exportFile.

public void exportFile() {
    dialogFactory.showDialogLoading(() -> {
        Array<String> warnings = new Array<>();
        String defaultPath = projectData.getLastImportExportPath();
        String[] filterPatterns = { "*.json" };
        File file = desktopWorker.saveDialog("Export skin...", defaultPath, filterPatterns, "Json files");
        if (file != null) {
            FileHandle fileHandle = new FileHandle(file);
            if (fileHandle.extension() == null || !fileHandle.extension().equals(".json")) {
                fileHandle = fileHandle.sibling(fileHandle.nameWithoutExtension() + ".json");
            }
            projectData.setLastImportExportPath(fileHandle.parent().path() + "/");
            Array<String> newWarnings = main.getProjectData().getJsonData().writeFile(fileHandle);
            warnings.addAll(newWarnings);
            try {
                newWarnings = main.getProjectData().getAtlasData().writeAtlas(fileHandle.parent().child(fileHandle.nameWithoutExtension() + ".atlas"));
                warnings.addAll(newWarnings);
            } catch (Exception ex) {
                Gdx.app.error(getClass().getName(), "Error while writing texture atlas", ex);
                dialogFactory.showDialogError("Atlas Error...", "Error while writing texture atlas.\n\nOpen log?");
            }
            for (FontData font : main.getProjectData().getJsonData().getFonts()) {
                if (!font.file.parent().equals(fileHandle.parent())) {
                    font.file.copyTo(fileHandle.parent());
                }
            }
            for (FreeTypeFontData font : main.getProjectData().getJsonData().getFreeTypeFonts()) {
                if (font.useCustomSerializer && !font.file.parent().equals(fileHandle.parent())) {
                    font.file.copyTo(fileHandle.parent());
                }
            }
        }
        if (warnings.size > 0) {
            main.getDialogFactory().showWarningDialog(warnings);
        }
    });
}
Also used : Array(com.badlogic.gdx.utils.Array) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) FileHandle(com.badlogic.gdx.files.FileHandle) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) FontData(com.ray3k.skincomposer.data.FontData) File(java.io.File)

Aggregations

FontData (com.ray3k.skincomposer.data.FontData)14 FreeTypeFontData (com.ray3k.skincomposer.data.FreeTypeFontData)12 FileHandle (com.badlogic.gdx.files.FileHandle)8 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)7 DrawableData (com.ray3k.skincomposer.data.DrawableData)7 BitmapFontData (com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData)6 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)6 Array (com.badlogic.gdx.utils.Array)6 Actor (com.badlogic.gdx.scenes.scene2d.Actor)5 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)5 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)5 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)5 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)5 StyleData (com.ray3k.skincomposer.data.StyleData)5 LabelStyle (com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle)4 SelectBox (com.badlogic.gdx.scenes.scene2d.ui.SelectBox)4 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)3 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)3 ListStyle (com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle)3 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)3