Search in sources :

Example 6 with StyleData

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

the class DialogFactory method showDeleteStyleDialog.

public void showDeleteStyleDialog(Skin skin, Stage stage) {
    StyleData styleData = main.getRootTable().getSelectedStyle();
    Dialog dialog = new Dialog("Delete Style", skin, "bg") {

        @Override
        protected void result(Object object) {
            if ((Boolean) object) {
                main.getUndoableManager().addUndoable(new DeleteStyleUndoable(styleData, main), true);
            }
        }
    };
    dialog.getTitleLabel().setAlignment(Align.center);
    dialog.getContentTable().defaults().padLeft(10.0f).padRight(10.0f);
    dialog.text("Are you sure you want to delete style " + styleData.name + "?");
    dialog.getContentTable().getCells().first().pad(10.0f);
    dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
    dialog.button("Yes, delete the style", true).button("No", false);
    dialog.getButtonTable().getCells().first().getActor().addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
    dialog.key(Input.Keys.ENTER, true).key(Input.Keys.ESCAPE, false);
    dialog.show(stage);
}
Also used : DeleteStyleUndoable(com.ray3k.skincomposer.UndoableManager.DeleteStyleUndoable) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) StyleData(com.ray3k.skincomposer.data.StyleData)

Example 7 with StyleData

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

the class DialogFactory method showDuplicateStyleDialog.

public void showDuplicateStyleDialog(Skin skin, Stage stage) {
    Class selectedClass = main.getRootTable().getSelectedClass();
    StyleData originalStyle = main.getRootTable().getSelectedStyle();
    final TextField textField = new TextField("", skin);
    Dialog dialog = new Dialog("Duplicate Style", skin, "bg") {

        @Override
        protected void result(Object object) {
            if ((Boolean) object) {
                main.getUndoableManager().addUndoable(new DuplicateStyleUndoable(originalStyle, textField.getText(), main), true);
            }
        }
    };
    dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
    dialog.button("OK", true).button("Cancel", false);
    final TextButton okButton = (TextButton) dialog.getButtonTable().getCells().get(0).getActor();
    okButton.addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
    textField.setTextFieldListener((TextField textField1, char c) -> {
        if (c == '\n') {
            if (!okButton.isDisabled()) {
                main.getUndoableManager().addUndoable(new DuplicateStyleUndoable(originalStyle, textField.getText(), main), true);
                dialog.hide();
            }
            main.getStage().setKeyboardFocus(textField1);
        }
    });
    textField.addListener(main.getIbeamListener());
    dialog.getTitleLabel().setAlignment(Align.center);
    dialog.getContentTable().defaults().padLeft(10.0f).padRight(10.0f);
    dialog.text("What is the name of the new, duplicated style?");
    dialog.getContentTable().getCells().first().pad(10.0f);
    dialog.getContentTable().row();
    dialog.getContentTable().add(textField).growX();
    okButton.setDisabled(true);
    Array<StyleData> currentStyles = main.getProjectData().getJsonData().getClassStyleMap().get(selectedClass);
    textField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            boolean disable = !StyleData.validate(textField.getText());
            if (!disable) {
                for (StyleData data : currentStyles) {
                    if (data.name.equals(textField.getText())) {
                        disable = true;
                        break;
                    }
                }
            }
            okButton.setDisabled(disable);
        }
    });
    dialog.key(Input.Keys.ESCAPE, false);
    dialog.show(stage);
    stage.setKeyboardFocus(textField);
    textField.setFocusTraversal(false);
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) DuplicateStyleUndoable(com.ray3k.skincomposer.UndoableManager.DuplicateStyleUndoable) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) CustomClass(com.ray3k.skincomposer.data.CustomClass) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) StyleData(com.ray3k.skincomposer.data.StyleData)

Example 8 with StyleData

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

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

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

StyleData (com.ray3k.skincomposer.data.StyleData)15 StyleProperty (com.ray3k.skincomposer.data.StyleProperty)8 Actor (com.badlogic.gdx.scenes.scene2d.Actor)7 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)7 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)7 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)6 DrawableData (com.ray3k.skincomposer.data.DrawableData)6 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)5 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)5 ColorData (com.ray3k.skincomposer.data.ColorData)5 FontData (com.ray3k.skincomposer.data.FontData)5 FreeTypeFontData (com.ray3k.skincomposer.data.FreeTypeFontData)5 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 TextTooltip (com.badlogic.gdx.scenes.scene2d.ui.TextTooltip)4 Array (com.badlogic.gdx.utils.Array)4 Color (com.badlogic.gdx.graphics.Color)3 LabelStyle (com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle)3 ListStyle (com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle)3