Search in sources :

Example 1 with StyleProperty

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

the class RootTable method addStyleProperties.

private void addStyleProperties(final Table left) {
    Label label = new Label("Style Properties", getSkin(), "title");
    left.add(label);
    left.row();
    Table table = new Table();
    table.defaults().padLeft(10.0f).padRight(10.0f).growX();
    stylePropertiesScrollPane = new ScrollPane(table, getSkin());
    stylePropertiesScrollPane.setFadeScrollBars(false);
    stylePropertiesScrollPane.setFlickScroll(false);
    stylePropertiesScrollPane.addListener(scrollPaneListener);
    stage.setScrollFocus(stylePropertiesScrollPane);
    left.add(stylePropertiesScrollPane).grow().padTop(10.0f).padBottom(10.0f);
    // gather all scrollPaneStyles
    Array<StyleData> scrollPaneStyles = main.getProjectData().getJsonData().getClassStyleMap().get(ScrollPane.class);
    // gather all listStyles
    Array<StyleData> listStyles = main.getProjectData().getJsonData().getClassStyleMap().get(List.class);
    // gather all labelStyles
    Array<StyleData> labelStyles = main.getProjectData().getJsonData().getClassStyleMap().get(Label.class);
    if (styleProperties != null) {
        for (StyleProperty styleProperty : styleProperties) {
            table.row();
            if (styleProperty.type == Color.class) {
                BrowseField browseField;
                if (styleProperty.optional) {
                    browseField = new BrowseField((String) styleProperty.value, styleProperty.name, getSkin(), "color");
                } else {
                    browseField = new BrowseField((String) styleProperty.value, styleProperty.name, getSkin(), "color-required");
                }
                browseField.addListener(main.getHandListener());
                table.add(browseField).padTop(20.0f);
                browseField.addListener(new StylePropertyChangeListener(styleProperty, browseField));
            } else if (styleProperty.type == BitmapFont.class) {
                BrowseField browseField;
                if (styleProperty.optional) {
                    browseField = new BrowseField((String) styleProperty.value, styleProperty.name, getSkin(), "font");
                } else {
                    browseField = new BrowseField((String) styleProperty.value, styleProperty.name, getSkin(), "font-required");
                }
                browseField.addListener(main.getHandListener());
                table.add(browseField).padTop(20.0f);
                browseField.addListener(new StylePropertyChangeListener(styleProperty, browseField));
            } else if (styleProperty.type == Drawable.class) {
                BrowseField browseField;
                if (styleProperty.optional) {
                    browseField = new BrowseField((String) styleProperty.value, styleProperty.name, getSkin(), "drawable");
                } else {
                    browseField = new BrowseField((String) styleProperty.value, styleProperty.name, getSkin(), "drawable-required");
                }
                browseField.addListener(main.getHandListener());
                table.add(browseField).padTop(20.0f);
                browseField.addListener(new StylePropertyChangeListener(styleProperty, browseField));
            } else if (styleProperty.type == Float.TYPE) {
                if (styleProperty.optional) {
                    label = new Label(styleProperty.name, getSkin());
                } else {
                    label = new Label(styleProperty.name, getSkin(), "required");
                }
                table.add(label).padTop(20.0f).fill(false).expand(false, false);
                table.row();
                Spinner spinner = new Spinner((Double) styleProperty.value, 1.0, false, Spinner.Orientation.HORIZONTAL, getSkin());
                spinner.getTextField().addListener(main.getIbeamListener());
                spinner.getButtonMinus().addListener(main.getHandListener());
                spinner.getButtonPlus().addListener(main.getHandListener());
                table.add(spinner);
                spinner.addListener(new StylePropertyChangeListener(styleProperty, spinner));
            } else if (styleProperty.type == ScrollPaneStyle.class) {
                if (styleProperty.optional) {
                    label = new Label(styleProperty.name, getSkin());
                } else {
                    label = new Label(styleProperty.name, getSkin(), "required");
                }
                table.add(label).padTop(20.0f).fill(false).expand(false, false);
                table.row();
                SelectBox<StyleData> selectBox = new SelectBox<>(getSkin());
                selectBox.setItems(scrollPaneStyles);
                selectBox.addListener(main.getHandListener());
                selectBox.getList().addListener(main.getHandListener());
                if (styleProperty.value != null) {
                    String name = ((String) styleProperty.value);
                    int index = 0;
                    for (StyleData styleData : scrollPaneStyles) {
                        if (styleData.name.equals(name)) {
                            break;
                        } else {
                            index++;
                        }
                    }
                    if (index < scrollPaneStyles.size) {
                        selectBox.setSelectedIndex(index);
                    }
                }
                table.add(selectBox);
                selectBox.addListener(new StylePropertyChangeListener(styleProperty, selectBox));
            } else if (styleProperty.type == ListStyle.class) {
                if (styleProperty.optional) {
                    label = new Label(styleProperty.name, getSkin());
                } else {
                    label = new Label(styleProperty.name, getSkin(), "required");
                }
                table.add(label).padTop(20.0f).fill(false).expand(false, false);
                table.row();
                SelectBox<StyleData> selectBox = new SelectBox<>(getSkin());
                selectBox.setItems(listStyles);
                selectBox.addListener(main.getHandListener());
                selectBox.getList().addListener(main.getHandListener());
                if (styleProperty.value != null) {
                    String name = ((String) styleProperty.value);
                    int index = 0;
                    for (StyleData styleData : listStyles) {
                        if (styleData.name.equals(name)) {
                            break;
                        } else {
                            index++;
                        }
                    }
                    if (index < listStyles.size) {
                        selectBox.setSelectedIndex(index);
                    }
                }
                table.add(selectBox);
                selectBox.addListener(new StylePropertyChangeListener(styleProperty, selectBox));
            } else if (styleProperty.type == LabelStyle.class) {
                if (styleProperty.optional) {
                    label = new Label(styleProperty.name, getSkin());
                } else {
                    label = new Label(styleProperty.name, getSkin(), "required");
                }
                table.add(label).padTop(20.0f).fill(false).expand(false, false);
                table.row();
                SelectBox<StyleData> selectBox = new SelectBox<>(getSkin());
                selectBox.setItems(labelStyles);
                selectBox.addListener(main.getHandListener());
                selectBox.getList().addListener(main.getHandListener());
                if (styleProperty.value != null) {
                    String name = ((String) styleProperty.value);
                    int index = 0;
                    for (StyleData styleData : labelStyles) {
                        if (styleData.name.equals(name)) {
                            break;
                        } else {
                            index++;
                        }
                    }
                    if (index < labelStyles.size) {
                        selectBox.setSelectedIndex(index);
                    }
                }
                table.add(selectBox);
                selectBox.addListener(new StylePropertyChangeListener(styleProperty, selectBox));
            }
            table.row();
        }
    } else if (customProperties != null) {
        for (CustomProperty styleProperty : customProperties) {
            if (styleProperty.getType() == PropertyType.COLOR) {
                String value = "";
                if (styleProperty.getValue() instanceof String) {
                    for (ColorData color : main.getJsonData().getColors()) {
                        if (color.getName().equals(styleProperty.getValue())) {
                            value = (String) styleProperty.getValue();
                            break;
                        }
                    }
                }
                BrowseField browseField = new BrowseField(value, styleProperty.getName(), getSkin(), "color");
                browseField.addListener(main.getHandListener());
                table.add(browseField).padTop(20.0f);
                browseField.addListener(new CustomPropertyChangeListener(styleProperty, browseField));
            } else if (styleProperty.getType() == PropertyType.FONT) {
                String value = "";
                if (styleProperty.getValue() instanceof String) {
                    for (FontData font : main.getJsonData().getFonts()) {
                        if (font.getName().equals(styleProperty.getValue())) {
                            value = (String) styleProperty.getValue();
                            break;
                        }
                    }
                    for (FreeTypeFontData font : main.getJsonData().getFreeTypeFonts()) {
                        System.out.println("hit");
                        if (font.name.equals(styleProperty.getValue())) {
                            value = (String) styleProperty.getValue();
                        }
                    }
                }
                BrowseField browseField = new BrowseField(value, styleProperty.getName(), getSkin(), "font");
                browseField.addListener(main.getHandListener());
                table.add(browseField).padTop(20.0f);
                browseField.addListener(new CustomPropertyChangeListener(styleProperty, browseField));
            } else if (styleProperty.getType() == PropertyType.DRAWABLE) {
                String value = "";
                if (styleProperty.getValue() instanceof String) {
                    for (DrawableData drawable : main.getAtlasData().getDrawables()) {
                        if (drawable.name.equals(styleProperty.getValue())) {
                            value = (String) styleProperty.getValue();
                            break;
                        }
                    }
                }
                BrowseField browseField = new BrowseField(value, styleProperty.getName(), getSkin(), "drawable");
                browseField.addListener(main.getHandListener());
                table.add(browseField).padTop(20.0f);
                browseField.addListener(new CustomPropertyChangeListener(styleProperty, browseField));
            } else if (styleProperty.getType() == PropertyType.NUMBER) {
                label = new Label(styleProperty.getName(), getSkin());
                table.add(label).padTop(20.0f).fill(false).expand(false, false);
                table.row();
                if (styleProperty.getValue() instanceof Float) {
                    styleProperty.setValue((double) (float) styleProperty.getValue());
                }
                Double value = 0.0;
                if (styleProperty.getValue() instanceof Double) {
                    value = (Double) styleProperty.getValue();
                }
                Spinner spinner = new Spinner(value, 1.0, false, Spinner.Orientation.HORIZONTAL, getSkin());
                spinner.setRound(false);
                spinner.getTextField().addListener(main.getIbeamListener());
                spinner.getButtonMinus().addListener(main.getHandListener());
                spinner.getButtonPlus().addListener(main.getHandListener());
                table.add(spinner);
                spinner.addListener(new CustomPropertyChangeListener(styleProperty, spinner));
            } else if (styleProperty.getType() == PropertyType.TEXT || styleProperty.getType() == PropertyType.RAW_TEXT) {
                label = new Label(styleProperty.getName(), getSkin());
                table.add(label).padTop(20.0f).fill(false).expand(false, false);
                table.row();
                String value = "";
                if (styleProperty.getValue() instanceof String) {
                    value = (String) styleProperty.getValue();
                }
                TextField textField = new TextField(value, getSkin());
                textField.setAlignment(Align.center);
                textField.addListener(main.getIbeamListener());
                table.add(textField);
                textField.addListener(new CustomPropertyChangeListener(styleProperty, textField));
            } else if (styleProperty.getType() == PropertyType.BOOL) {
                label = new Label(styleProperty.getName(), getSkin());
                table.add(label).padTop(20.0f).fill(false).expand(false, false);
                table.row();
                Button button = new Button(getSkin(), "switch");
                boolean value = false;
                if (styleProperty.getValue() instanceof Boolean) {
                    value = (boolean) styleProperty.getValue();
                }
                button.setChecked(value);
                table.add(button).fill(false);
                button.addListener(new CustomPropertyChangeListener(styleProperty, button));
            }
            Button duplicateButton = new Button(getSkin(), "duplicate");
            table.add(duplicateButton).fill(false).expand(false, false).pad(0).bottom();
            duplicateButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    fire(new CustomPropertyEvent(styleProperty, duplicateButton, CustomPropertyEnum.DUPLICATE));
                }
            });
            TextTooltip toolTip = new TextTooltip("Duplicate Style Property", main.getTooltipManager(), getSkin());
            duplicateButton.addListener(toolTip);
            Button deleteButton = new Button(getSkin(), "delete");
            table.add(deleteButton).fill(false).expand(false, false).pad(0).bottom();
            deleteButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    fire(new CustomPropertyEvent(styleProperty, duplicateButton, CustomPropertyEnum.DELETE));
                }
            });
            toolTip = new TextTooltip("Delete Style Property", main.getTooltipManager(), getSkin());
            deleteButton.addListener(toolTip);
            Button renameButton = new Button(getSkin(), "settings");
            table.add(renameButton).fill(false).expand(false, false).pad(0).bottom();
            renameButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    fire(new CustomPropertyEvent(styleProperty, duplicateButton, CustomPropertyEnum.RENAME));
                }
            });
            toolTip = new TextTooltip("Rename Style Property", main.getTooltipManager(), getSkin());
            renameButton.addListener(toolTip);
            table.row();
        }
        left.row();
        table = new Table();
        left.add(table).right().padBottom(10.0f);
        Button button = new Button(getSkin(), "new");
        button.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                fire(new CustomPropertyEvent(null, null, CustomPropertyEnum.NEW));
            }
        });
        table.add(button);
        TextTooltip toolTip = new TextTooltip("New Style Property", main.getTooltipManager(), getSkin());
        button.addListener(toolTip);
    }
}
Also used : ListStyle(com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) DrawableData(com.ray3k.skincomposer.data.DrawableData) TextTooltip(com.badlogic.gdx.scenes.scene2d.ui.TextTooltip) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) StyleData(com.ray3k.skincomposer.data.StyleData) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) SelectBox(com.badlogic.gdx.scenes.scene2d.ui.SelectBox) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) FontData(com.ray3k.skincomposer.data.FontData) StyleProperty(com.ray3k.skincomposer.data.StyleProperty) ColorData(com.ray3k.skincomposer.data.ColorData) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) CustomProperty(com.ray3k.skincomposer.data.CustomProperty)

Example 2 with StyleProperty

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

the class DialogFonts method renameFont.

private void renameFont(FontData font, String newName) {
    for (Array<StyleData> datas : main.getJsonData().getClassStyleMap().values()) {
        for (StyleData data : datas) {
            for (StyleProperty property : data.properties.values()) {
                if (property != null && property.type.equals(BitmapFont.class) && property.value != null && property.value.equals(font.getName())) {
                    property.value = newName;
                }
            }
        }
    }
    try {
        font.setName(newName);
    } catch (FontData.NameFormatException ex) {
        Gdx.app.error(getClass().getName(), "Error trying to rename a font.", ex);
        main.getDialogFactory().showDialogError("Rename Font Error...", "Error trying to rename a font.\n\nOpen log?");
    }
    main.getUndoableManager().clearUndoables();
    main.getRootTable().refreshStyleProperties(true);
    main.getRootTable().refreshPreview();
    main.getProjectData().setChangesSaved(false);
    refreshTable();
}
Also used : StyleProperty(com.ray3k.skincomposer.data.StyleProperty) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) FontData(com.ray3k.skincomposer.data.FontData) BitmapFontData(com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) StyleData(com.ray3k.skincomposer.data.StyleData)

Example 3 with StyleProperty

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

the class DialogFreeTypeFont method result.

@Override
protected void result(Object object) {
    if ((Boolean) object) {
        if (mode == Mode.EDIT) {
            if (!originalData.name.equals(data.name)) {
                for (Array<StyleData> styleDatas : main.getJsonData().getClassStyleMap().values()) {
                    for (StyleData styleData : styleDatas) {
                        for (StyleProperty property : styleData.properties.values()) {
                            if (property != null && property.type.equals(BitmapFont.class) && property.value != null && property.value.equals(originalData.name)) {
                                property.value = data.name;
                            }
                        }
                    }
                }
            }
            originalData.bitmapFont.dispose();
            main.getJsonData().getFreeTypeFonts().removeValue(originalData, false);
            main.getUndoableManager().clearUndoables();
            main.getRootTable().refreshStyleProperties(true);
            main.getProjectData().setChangesSaved(false);
        }
        data.createBitmapFont(main);
        main.getJsonData().getFreeTypeFonts().add(data);
        for (DialogFreeTypeFontListener listener : listeners) {
            listener.fontAdded(data);
        }
    }
}
Also used : StyleProperty(com.ray3k.skincomposer.data.StyleProperty) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) StyleData(com.ray3k.skincomposer.data.StyleData)

Example 4 with StyleProperty

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

the class DialogFreeTypeFont method populate.

private void populate() {
    root.pad(15.0f);
    Label label = new Label(mode == Mode.NEW ? "Create a new FreeType Font placeholder." : "Edit FreeType Font placeholder.", skin, "required");
    root.add(label);
    root.row();
    Table table = new Table();
    root.add(table).growX();
    table.defaults().space(5.0f);
    label = new Label("Font Name:", skin);
    table.add(label);
    TextField textField = new TextField(data.name, skin);
    textField.setName("fontName");
    table.add(textField);
    TextTooltip toolTip = new TextTooltip("The name used in skin JSON", main.getTooltipManager(), getSkin());
    textField.addListener(toolTip);
    textField.addListener(main.getIbeamListener());
    textField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            TextField textField = (TextField) actor;
            data.name = textField.getText();
            updateDisabledFields();
        }
    });
    label = new Label("Preview TTF:", skin);
    table.add(label).spaceLeft(15.0f);
    SelectBox<String> selectBox = new SelectBox(skin);
    selectBox.setName("previewSelectBox");
    Array<String> previewFontNames = new Array<>();
    FileHandle previewFontsPath = Gdx.files.local("preview fonts");
    if (previewFontsPath.exists()) {
        Array<FileHandle> files = new Array<>(previewFontsPath.list("ttf"));
        for (FileHandle file : files) {
            previewFontNames.add(file.nameWithoutExtension());
        }
    }
    selectBox.setItems(previewFontNames);
    selectBox.setSelected(data.previewTTF);
    table.add(selectBox);
    toolTip = new TextTooltip("The TTF font for preview use in Skin Composer only", main.getTooltipManager(), getSkin());
    selectBox.addListener(toolTip);
    selectBox.addListener(main.getHandListener());
    selectBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            SelectBox<String> selectBox = (SelectBox) actor;
            data.previewTTF = selectBox.getSelected();
            updateDisabledFields();
        }
    });
    TextButton textButton = new TextButton("Open Preview Folder", skin);
    table.add(textButton);
    toolTip = new TextTooltip("Add new preview fonts here", main.getTooltipManager(), getSkin());
    textButton.addListener(toolTip);
    textButton.addListener(main.getHandListener());
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            try {
                Utils.openFileExplorer(Gdx.files.local("preview fonts/"));
            } catch (Exception e) {
            }
        }
    });
    root.row();
    Image image = new Image(skin, "welcome-separator");
    image.setScaling(Scaling.stretch);
    root.add(image).growX().space(15.0f);
    root.row();
    textField = new TextField(previewText, previewStyle);
    textField.setName("previewField");
    textField.setAlignment(Align.center);
    root.add(textField).growX();
    textField.addListener(main.getIbeamListener());
    textField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            previewText = ((TextField) actor).getText();
        }
    });
    root.row();
    image = new Image(skin, "welcome-separator");
    image.setScaling(Scaling.stretch);
    root.add(image).growX().space(15.0f);
    root.row();
    table = new Table();
    root.add(table);
    table.defaults().space(5.0f);
    CheckBox checkBox = new CheckBox("Use custom serializer and integrate TTF in Skin JSON", skin);
    checkBox.setName("serializerCheckBox");
    checkBox.setChecked(data.useCustomSerializer);
    table.add(checkBox);
    checkBox.addListener(main.getHandListener());
    checkBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            CheckBox checkBox = (CheckBox) actor;
            ScrollPane scrollPane = findActor("scrollPane");
            SelectBox selectBox = findActor("previewSelectBox");
            if (checkBox.isChecked()) {
                scrollPane.addAction(Actions.sequence(Actions.fadeIn(.25f), Actions.touchable(Touchable.enabled)));
                selectBox.addAction(Actions.sequence(Actions.alpha(.25f, .25f), Actions.touchable(Touchable.disabled)));
            } else {
                scrollPane.addAction(Actions.sequence(Actions.alpha(.25f, .25f), Actions.touchable(Touchable.disabled)));
                selectBox.addAction(Actions.sequence(Actions.fadeIn(.25f), Actions.touchable(Touchable.enabled)));
            }
            data.useCustomSerializer = checkBox.isChecked();
            updateDisabledFields();
        }
    });
    textButton = new TextButton("More Info...", skin);
    table.add(textButton);
    textButton.addListener(main.getHandListener());
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            showMoreInfoDialog();
        }
    });
    root.row();
    Table bottom = new Table();
    ScrollPane scrollPane = new ScrollPane(bottom, skin);
    scrollPane.setName("scrollPane");
    scrollPane.setFadeScrollBars(false);
    scrollPane.setFlickScroll(false);
    root.add(scrollPane).padTop(10.0f);
    if (!data.useCustomSerializer) {
        scrollPane.setColor(1, 1, 1, .25f);
        scrollPane.setTouchable(Touchable.disabled);
    } else {
        selectBox.setColor(1, 1, 1, .25f);
        selectBox.setTouchable(Touchable.disabled);
    }
    bottom.defaults().space(5.0f);
    table = new Table();
    bottom.add(table).growX().colspan(4).spaceBottom(15.0f);
    table.defaults().space(5.0f);
    label = new Label("TTF Path:", skin);
    table.add(label);
    textField = new TextField(data.file == null ? "" : data.file.path(), skin);
    textField.setName("fileField");
    textField.setDisabled(true);
    table.add(textField).growX();
    toolTip = new TextTooltip("Path to TTF font to be distributed with skin", main.getTooltipManager(), getSkin());
    textField.addListener(toolTip);
    textButton = new TextButton("Browse...", skin);
    table.add(textButton);
    textButton.addListener(main.getHandListener());
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Runnable runnable = () -> {
                String defaultPath = main.getProjectData().getLastFontPath();
                String[] filterPatterns = null;
                if (!Utils.isMac()) {
                    filterPatterns = new String[] { "*.ttf" };
                }
                File file = main.getDesktopWorker().openDialog("Select TTF file...", defaultPath, filterPatterns, "True Type Font files");
                if (file != null) {
                    FileHandle fileHandle = new FileHandle(file);
                    data.file = fileHandle;
                    updateDisabledFields();
                    ((TextField) DialogFreeTypeFont.this.findActor("fileField")).setText(fileHandle.path());
                    main.getProjectData().setLastFontPath(fileHandle.parent().path() + "/");
                }
            };
            main.getDialogFactory().showDialogLoading(runnable);
        }
    });
    bottom.row();
    label = new Label("Size:", skin);
    bottom.add(label).right();
    Spinner spinner = new Spinner(data.size, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("The size in pixels", main.getTooltipManager(), getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(main.getHandListener());
    spinner.getButtonPlus().addListener(main.getHandListener());
    spinner.getTextField().addListener(main.getIbeamListener());
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.size = (int) spinner.getValue();
            updateDisabledFields();
        }
    });
    label = new Label("Mono:", skin);
    bottom.add(label).right();
    Button button = new Button(skin, "switch");
    button.setChecked(data.mono);
    bottom.add(button).left();
    toolTip = new TextTooltip("If on, font smoothing is disabled", main.getTooltipManager(), getSkin());
    button.addListener(toolTip);
    button.addListener(main.getHandListener());
    button.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.mono = button.isChecked();
            updateDisabledFields();
        }
    });
    bottom.row();
    label = new Label("Hinting:", skin);
    bottom.add(label).right();
    selectBox = new SelectBox(skin);
    selectBox.setItems("None", "Slight", "Medium", "Full", "AutoSlight", "AutoMedium", "AutoFull");
    selectBox.setSelected(data.hinting);
    bottom.add(selectBox).fillX().left();
    toolTip = new TextTooltip("Strength of hinting", main.getTooltipManager(), getSkin());
    selectBox.addListener(toolTip);
    selectBox.addListener(main.getHandListener());
    selectBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            SelectBox<String> selectBox = (SelectBox) actor;
            data.hinting = selectBox.getSelected();
            updateDisabledFields();
        }
    });
    label = new Label("Color:", skin);
    bottom.add(label).right();
    textButton = new TextButton(data.color, skin);
    textButton.setName("colorTextButton");
    image = new Image(skin, "icon-colorwheel-over");
    textButton.add(image).space(10.0f);
    bottom.add(textButton).left();
    toolTip = new TextTooltip("Foreground color (Required)", main.getTooltipManager(), getSkin());
    textButton.addListener(toolTip);
    textButton.addListener(main.getHandListener());
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            TextButton textButton = (TextButton) actor;
            main.getDialogFactory().showDialogColors(new StyleProperty(), (ColorData colorData) -> {
                if (colorData != null) {
                    textButton.setText(colorData.getName());
                    textButton.setUserObject(colorData);
                    data.color = colorData.getName();
                } else {
                    textButton.setText("");
                    textButton.setUserObject(null);
                    data.color = null;
                }
                updateColors();
                updateDisabledFields();
            });
        }
    });
    bottom.row();
    label = new Label("Gamma:", skin);
    bottom.add(label).right();
    spinner = new Spinner(Double.parseDouble(df.format(data.gamma)), 1.0, false, Spinner.Orientation.HORIZONTAL, skin);
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Glyph gamma. Values > 1 reduce antialiasing.", main.getTooltipManager(), getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(main.getHandListener());
    spinner.getButtonPlus().addListener(main.getHandListener());
    spinner.getTextField().addListener(main.getIbeamListener());
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.gamma = (float) spinner.getValue();
            updateDisabledFields();
        }
    });
    label = new Label("Render Count:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.renderCount, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Number of times to render the glyph. Useful with a shadow or border, so it doesn't show through the glyph.", main.getTooltipManager(), getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(main.getHandListener());
    spinner.getButtonPlus().addListener(main.getHandListener());
    spinner.getTextField().addListener(main.getIbeamListener());
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.renderCount = (int) spinner.getValue();
            updateDisabledFields();
        }
    });
    bottom.row();
    label = new Label("Border Width:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.borderWidth, 1.0, false, Spinner.Orientation.HORIZONTAL, skin);
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Border width in pixels, 0 to disable", main.getTooltipManager(), getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(main.getHandListener());
    spinner.getButtonPlus().addListener(main.getHandListener());
    spinner.getTextField().addListener(main.getIbeamListener());
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.borderWidth = (float) spinner.getValue();
            updateDisabledFields();
        }
    });
    label = new Label("Border Color:", skin);
    bottom.add(label).right();
    textButton = new TextButton(data.borderColor, skin);
    textButton.setName("borderColorTextButton");
    image = new Image(skin, "icon-colorwheel-over");
    textButton.add(image).space(10.0f);
    bottom.add(textButton).left();
    toolTip = new TextTooltip("Border color; Required if borderWidth > 0", main.getTooltipManager(), getSkin());
    textButton.addListener(toolTip);
    textButton.addListener(main.getHandListener());
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            TextButton textButton = (TextButton) actor;
            main.getDialogFactory().showDialogColors(new StyleProperty(), (ColorData colorData) -> {
                if (colorData != null) {
                    textButton.setText(colorData.getName());
                    textButton.setUserObject(colorData);
                    data.borderColor = colorData.getName();
                } else {
                    textButton.setText("");
                    textButton.setUserObject(null);
                    data.borderColor = null;
                }
                updateColors();
                updateDisabledFields();
            });
        }
    });
    bottom.row();
    label = new Label("Border Straight:", skin);
    bottom.add(label).right();
    button = new Button(skin, "switch");
    button.setChecked(data.borderStraight);
    bottom.add(button).left();
    toolTip = new TextTooltip("On for straight (mitered), off for rounded borders", main.getTooltipManager(), getSkin());
    button.addListener(toolTip);
    button.addListener(main.getHandListener());
    button.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.borderStraight = button.isChecked();
            updateDisabledFields();
        }
    });
    label = new Label("Border Gamma:", skin);
    bottom.add(label).right();
    spinner = new Spinner(Double.parseDouble(df.format(data.borderGamma)), 1.0, false, Spinner.Orientation.HORIZONTAL, skin);
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Values < 1 increase the border size.", main.getTooltipManager(), getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(main.getHandListener());
    spinner.getButtonPlus().addListener(main.getHandListener());
    spinner.getTextField().addListener(main.getIbeamListener());
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.borderGamma = (float) spinner.getValue();
            updateDisabledFields();
        }
    });
    bottom.row();
    label = new Label("Shadow Offset X:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.shadowOffsetX, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Offset of text shadow on X axis in pixels, 0 to disable", main.getTooltipManager(), getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(main.getHandListener());
    spinner.getButtonPlus().addListener(main.getHandListener());
    spinner.getTextField().addListener(main.getIbeamListener());
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.shadowOffsetX = (int) spinner.getValue();
            updateDisabledFields();
        }
    });
    label = new Label("Shadow Offset Y:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.shadowOffsetY, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Offset of text shadow on Y axis in pixels, 0 to disable", main.getTooltipManager(), getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(main.getHandListener());
    spinner.getButtonPlus().addListener(main.getHandListener());
    spinner.getTextField().addListener(main.getIbeamListener());
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.shadowOffsetY = (int) spinner.getValue();
            updateDisabledFields();
        }
    });
    bottom.row();
    label = new Label("Shadow Color:", skin);
    bottom.add(label).right();
    textButton = new TextButton(data.shadowColor, skin);
    textButton.setName("shadowColorTextButton");
    image = new Image(skin, "icon-colorwheel-over");
    textButton.add(image).space(10.0f);
    bottom.add(textButton).left();
    toolTip = new TextTooltip("Shadow color; required if shadowOffset > 0.", main.getTooltipManager(), getSkin());
    textButton.addListener(toolTip);
    textButton.addListener(main.getHandListener());
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            TextButton textButton = (TextButton) actor;
            main.getDialogFactory().showDialogColors(new StyleProperty(), (ColorData colorData) -> {
                if (colorData != null) {
                    textButton.setText(colorData.getName());
                    textButton.setUserObject(colorData);
                    data.shadowColor = colorData.getName();
                } else {
                    textButton.setText("");
                    textButton.setUserObject(null);
                    data.shadowColor = null;
                }
                updateColors();
                updateDisabledFields();
            });
        }
    });
    label = new Label("Incremental:", skin);
    bottom.add(label).right();
    button = new Button(skin, "switch");
    button.setChecked(data.incremental);
    bottom.add(button).left();
    toolTip = new TextTooltip("When true, glyphs are rendered on the fly to the \n" + "font's glyph page textures as they are needed.", main.getTooltipManager(), getSkin());
    button.addListener(toolTip);
    button.addListener(main.getHandListener());
    button.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.incremental = button.isChecked();
            updateDisabledFields();
        }
    });
    bottom.row();
    label = new Label("Space X:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.spaceX, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Pixels to add to glyph spacing. Can be negative.", main.getTooltipManager(), getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(main.getHandListener());
    spinner.getButtonPlus().addListener(main.getHandListener());
    spinner.getTextField().addListener(main.getIbeamListener());
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.spaceX = (int) spinner.getValue();
            updateDisabledFields();
        }
    });
    label = new Label("Space Y:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.spaceY, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Pixels to add to glyph spacing. Can be negative.", main.getTooltipManager(), getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(main.getHandListener());
    spinner.getButtonPlus().addListener(main.getHandListener());
    spinner.getTextField().addListener(main.getIbeamListener());
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.spaceY = (int) spinner.getValue();
            updateDisabledFields();
        }
    });
    bottom.row();
    label = new Label("Characters:", skin);
    bottom.add(label).right();
    textField = new TextField(data.characters, skin);
    bottom.add(textField).left().growX();
    toolTip = new TextTooltip("The characters the font should contain. Leave blank for defaults.", main.getTooltipManager(), getSkin());
    textField.addListener(toolTip);
    textField.addListener(main.getIbeamListener());
    textField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            TextField textField = (TextField) actor;
            data.characters = textField.getText();
            updateDisabledFields();
        }
    });
    label = new Label("Kerning:", skin);
    bottom.add(label).right();
    button = new Button(skin, "switch");
    button.setChecked(data.kerning);
    bottom.add(button).left();
    toolTip = new TextTooltip("Whether the font should include kerning", main.getTooltipManager(), getSkin());
    button.addListener(toolTip);
    button.addListener(main.getHandListener());
    button.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.kerning = button.isChecked();
            updateDisabledFields();
        }
    });
    bottom.row();
    label = new Label("Flip:", skin);
    bottom.add(label).right();
    button = new Button(skin, "switch");
    button.setChecked(data.flip);
    bottom.add(button).left();
    toolTip = new TextTooltip("Whether to flip the font vertically", main.getTooltipManager(), getSkin());
    button.addListener(toolTip);
    button.addListener(main.getHandListener());
    button.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.flip = button.isChecked();
            updateDisabledFields();
        }
    });
    label = new Label("GenMipMaps:", skin);
    bottom.add(label).right();
    button = new Button(skin, "switch");
    button.setChecked(data.genMipMaps);
    bottom.add(button).left();
    toolTip = new TextTooltip("Whether to generate mip maps for the resulting texture", main.getTooltipManager(), getSkin());
    button.addListener(toolTip);
    button.addListener(main.getHandListener());
    button.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.genMipMaps = button.isChecked();
            updateDisabledFields();
        }
    });
    bottom.row();
    label = new Label("Min Filter:", skin);
    bottom.add(label).right();
    selectBox = new SelectBox(skin);
    selectBox.setItems("Nearest", "Linear", "MipMap", "MipMapNearestNearest", "MipMapLinearNearest", "MipMapNearestLinear", "MipMapLinearLinear");
    selectBox.setSelected(data.minFilter);
    bottom.add(selectBox).left();
    toolTip = new TextTooltip("Minification filter", main.getTooltipManager(), getSkin());
    selectBox.addListener(toolTip);
    selectBox.addListener(main.getHandListener());
    selectBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            SelectBox<String> selectBox = (SelectBox) actor;
            data.minFilter = selectBox.getSelected();
            updateDisabledFields();
        }
    });
    label = new Label("Mag Filter:", skin);
    bottom.add(label).right();
    selectBox = new SelectBox(skin);
    selectBox.setItems("Nearest", "Linear", "MipMap", "MipMapNearestNearest", "MipMapLinearNearest", "MipMapNearestLinear", "MipMapLinearLinear");
    selectBox.setSelected(data.magFilter);
    bottom.add(selectBox).left();
    toolTip = new TextTooltip("Magnification filter", main.getTooltipManager(), getSkin());
    selectBox.addListener(toolTip);
    selectBox.addListener(main.getHandListener());
    selectBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            SelectBox<String> selectBox = (SelectBox) actor;
            data.magFilter = selectBox.getSelected();
            updateDisabledFields();
        }
    });
    buttons.pad(10.0f);
    buttons.defaults().minWidth(75.0f).space(25.0f);
    textButton = new TextButton("OK", skin);
    textButton.setName("okButton");
    textButton.addListener(main.getHandListener());
    button(textButton, true);
    textButton = new TextButton("Cancel", skin);
    textButton.setName("cancelButton");
    textButton.addListener(main.getHandListener());
    button(textButton, false);
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) Spinner(com.ray3k.skincomposer.Spinner) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) TextTooltip(com.badlogic.gdx.scenes.scene2d.ui.TextTooltip) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) SelectBox(com.badlogic.gdx.scenes.scene2d.ui.SelectBox) Array(com.badlogic.gdx.utils.Array) StyleProperty(com.ray3k.skincomposer.data.StyleProperty) ColorData(com.ray3k.skincomposer.data.ColorData) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) File(java.io.File)

Example 5 with StyleProperty

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

the class DialogColors method renameColor.

private void renameColor(ColorData color, String newName) {
    // style properties
    for (Array<StyleData> datas : main.getJsonData().getClassStyleMap().values()) {
        for (StyleData data : datas) {
            for (StyleProperty property : data.properties.values()) {
                if (property != null && property.type.equals(Color.class) && property.value != null && property.value.equals(color.getName())) {
                    property.value = newName;
                }
            }
        }
    }
    // tinted drawables
    for (DrawableData drawableData : main.getAtlasData().getDrawables()) {
        if (drawableData.tintName != null && drawableData.tintName.equals(color.getName())) {
            drawableData.tintName = newName;
        }
    }
    try {
        color.setName(newName);
    } catch (ColorData.NameFormatException ex) {
        Gdx.app.error(getClass().getName(), "Error trying to rename a color.", ex);
        main.getDialogFactory().showDialogError("Name Error...", "Error while naming a color.\\nPlease ensure name is formatted appropriately:\\nNo spaces, don't start with a number, - and _ acceptable.\n\nOpen log?");
    }
    main.getUndoableManager().clearUndoables();
    main.getRootTable().refreshStyleProperties(true);
    main.getRootTable().refreshPreview();
    main.getProjectData().setChangesSaved(false);
    refreshTable();
}
Also used : StyleProperty(com.ray3k.skincomposer.data.StyleProperty) ColorData(com.ray3k.skincomposer.data.ColorData) DrawableData(com.ray3k.skincomposer.data.DrawableData) Color(com.badlogic.gdx.graphics.Color) StyleData(com.ray3k.skincomposer.data.StyleData)

Aggregations

StyleProperty (com.ray3k.skincomposer.data.StyleProperty)9 StyleData (com.ray3k.skincomposer.data.StyleData)8 DrawableData (com.ray3k.skincomposer.data.DrawableData)5 Actor (com.badlogic.gdx.scenes.scene2d.Actor)4 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)4 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)4 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)4 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)4 TextTooltip (com.badlogic.gdx.scenes.scene2d.ui.TextTooltip)4 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)4 ColorData (com.ray3k.skincomposer.data.ColorData)4 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)3 Array (com.badlogic.gdx.utils.Array)3 FontData (com.ray3k.skincomposer.data.FontData)3 FreeTypeFontData (com.ray3k.skincomposer.data.FreeTypeFontData)3 FileHandle (com.badlogic.gdx.files.FileHandle)2 Color (com.badlogic.gdx.graphics.Color)2 BitmapFontData (com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData)2 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)2 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)2