Search in sources :

Example 6 with FreeTypeFontData

use of com.ray3k.skincomposer.data.FreeTypeFontData 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 7 with FreeTypeFontData

use of com.ray3k.skincomposer.data.FreeTypeFontData 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)7 FreeTypeFontData (com.ray3k.skincomposer.data.FreeTypeFontData)7 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)4 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)4 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)4 Array (com.badlogic.gdx.utils.Array)4 StyleData (com.ray3k.skincomposer.data.StyleData)4 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)3 Actor (com.badlogic.gdx.scenes.scene2d.Actor)3 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)3 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)3 LabelStyle (com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle)3 ListStyle (com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle)3 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)3 SelectBox (com.badlogic.gdx.scenes.scene2d.ui.SelectBox)3 TextTooltip (com.badlogic.gdx.scenes.scene2d.ui.TextTooltip)3 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)3 ColorData (com.ray3k.skincomposer.data.ColorData)3 DrawableData (com.ray3k.skincomposer.data.DrawableData)3 FileHandle (com.badlogic.gdx.files.FileHandle)2