Search in sources :

Example 6 with StyleProperty

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

the class DialogDrawables method deleteDrawable.

private void deleteDrawable(DrawableData drawable) {
    if (!drawable.customized && drawable.tint == null && drawable.tintName == null && checkDuplicateDrawables(drawable.file, 1)) {
        showConfirmDeleteDialog(drawable);
    } else {
        main.getAtlasData().getDrawables().removeValue(drawable, true);
        for (Array<StyleData> datas : main.getJsonData().getClassStyleMap().values()) {
            for (StyleData data : datas) {
                for (StyleProperty styleProperty : data.properties.values()) {
                    if (styleProperty != null && styleProperty.type.equals(Drawable.class) && styleProperty.value != null && styleProperty.value.equals(drawable.toString())) {
                        styleProperty.value = null;
                    }
                }
            }
        }
        main.getRootTable().refreshStyleProperties(true);
        main.getRootTable().refreshPreview();
        main.getUndoableManager().clearUndoables();
        main.getProjectData().setChangesSaved(false);
        gatherDrawables();
        sortBySelectedMode();
    }
}
Also used : StyleProperty(com.ray3k.skincomposer.data.StyleProperty) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable) TiledDrawable(com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable) StyleData(com.ray3k.skincomposer.data.StyleData)

Example 7 with StyleProperty

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

the class DialogDrawables method removeDuplicateDrawables.

/**
 * Removes any duplicate drawables that share the same file name. This
 * ignores the file extension and also deletes TintedDrawables from the
 * same file.
 * @param handle
 */
private void removeDuplicateDrawables(FileHandle handle) {
    boolean refreshDrawables = false;
    String name = DrawableData.proper(handle.name());
    for (int i = 0; i < main.getAtlasData().getDrawables().size; i++) {
        DrawableData data = main.getAtlasData().getDrawables().get(i);
        if (name.equals(DrawableData.proper(data.file.name()))) {
            main.getAtlasData().getDrawables().removeValue(data, true);
            for (Array<StyleData> datas : main.getJsonData().getClassStyleMap().values()) {
                for (StyleData tempData : datas) {
                    for (StyleProperty prop : tempData.properties.values()) {
                        if (prop != null && prop.type.equals(Drawable.class) && prop.value != null && prop.value.equals(data.toString())) {
                            prop.value = null;
                        }
                    }
                }
            }
            refreshDrawables = true;
            i--;
        }
    }
    main.getRootTable().refreshStyleProperties(true);
    main.getRootTable().refreshPreview();
    if (refreshDrawables) {
        gatherDrawables();
    }
}
Also used : StyleProperty(com.ray3k.skincomposer.data.StyleProperty) DrawableData(com.ray3k.skincomposer.data.DrawableData) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable) TiledDrawable(com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable) StyleData(com.ray3k.skincomposer.data.StyleData)

Example 8 with StyleProperty

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

the class DialogColors method refreshTable.

public void refreshTable() {
    colorTable.clear();
    if (colors.size > 0) {
        colorTable.defaults().padTop(5.0f);
        for (ColorData color : colors) {
            Button button = new Button(getSkin(), "color-base");
            button.addListener(main.getHandListener());
            Label label = new Label(color.toString(), getSkin(), "white");
            label.setTouchable(Touchable.disabled);
            float brightness = Utils.brightness(color.color);
            Color borderColor;
            if (brightness > .35f) {
                borderColor = Color.BLACK;
                label.setColor(borderColor);
            } else {
                borderColor = Color.WHITE;
                label.setColor(borderColor);
            }
            Color bgColor = new Color(color.color.r, color.color.g, color.color.b, 1.0f);
            Table table = new Table(getSkin());
            table.setBackground("white");
            table.setColor(bgColor);
            table.add(label).pad(3.0f);
            if (styleProperty == null && customProperty == null && !selectingForTintedDrawable) {
                table.addCaptureListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                        event.setBubbles(false);
                        refreshTable();
                    }
                });
                table.addCaptureListener(new InputListener() {

                    @Override
                    public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                        event.setBubbles(false);
                        return true;
                    }
                });
            }
            Table borderTable = new Table(getSkin());
            borderTable.setBackground("white");
            borderTable.setColor(borderColor);
            borderTable.add(table).growX().pad(1.0f);
            button.add(borderTable).growX();
            // rename button
            Button renameButton = new Button(getSkin(), "settings-small");
            renameButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    renameDialog(color);
                    event.setBubbles(false);
                }
            });
            renameButton.addListener(new InputListener() {

                @Override
                public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                    event.setBubbles(false);
                    return true;
                }
            });
            button.add(renameButton).padLeft(10.0f);
            TextTooltip toolTip = new TextTooltip("Rename Color", main.getTooltipManager(), getSkin());
            renameButton.addListener(toolTip);
            // recolor button
            Button recolorButton = new Button(getSkin(), "colorwheel");
            recolorButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    recolorDialog(color);
                    event.setBubbles(false);
                }
            });
            recolorButton.addListener(new InputListener() {

                @Override
                public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                    event.setBubbles(false);
                    return true;
                }
            });
            button.add(recolorButton);
            toolTip = new TextTooltip("Change Color", main.getTooltipManager(), getSkin());
            recolorButton.addListener(toolTip);
            label = new Label("(" + ((int) (color.color.r * 255)) + ", " + ((int) (color.color.g * 255)) + ", " + ((int) (color.color.b * 255)) + ", " + ((int) (color.color.a * 255)) + ")", getSkin());
            label.setTouchable(Touchable.disabled);
            label.setAlignment(Align.center);
            if (styleProperty == null && customProperty == null && !selectingForTintedDrawable) {
                label.addCaptureListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                        event.setBubbles(false);
                        refreshTable();
                    }
                });
                label.addCaptureListener(new InputListener() {

                    @Override
                    public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                        event.setBubbles(false);
                        return true;
                    }
                });
            }
            button.add(label).padLeft(5.0f).minWidth(160.0f);
            // delete color button
            Button closeButton = new Button(getSkin(), "delete-small");
            final ColorData deleteColor = color;
            closeButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    colors.removeValue(deleteColor, true);
                    main.getProjectData().setChangesSaved(false);
                    // clear style properties that use this color.
                    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(deleteColor.getName())) {
                                    property.value = null;
                                }
                            }
                        }
                    }
                    // delete tinted drawables based on this color.
                    for (DrawableData drawableData : new Array<>(main.getProjectData().getAtlasData().getDrawables())) {
                        if (drawableData.tintName != null && drawableData.tintName.equals(deleteColor.getName())) {
                            main.getProjectData().getAtlasData().getDrawables().removeValue(drawableData, true);
                            // clear any style properties based on this tinted drawable.
                            for (Array<StyleData> styleDatas : main.getJsonData().getClassStyleMap().values()) {
                                for (StyleData styleData : styleDatas) {
                                    for (StyleProperty styleProperty : styleData.properties.values()) {
                                        if (styleProperty != null && styleProperty.type.equals(Drawable.class) && styleProperty.value != null && styleProperty.value.equals(drawableData.toString())) {
                                            styleProperty.value = null;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    main.getUndoableManager().clearUndoables();
                    main.getRootTable().refreshStyleProperties(true);
                    main.getRootTable().refreshPreview();
                    event.setBubbles(false);
                    refreshTable();
                }
            });
            closeButton.addListener(new InputListener() {

                @Override
                public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                    event.setBubbles(false);
                    return true;
                }
            });
            toolTip = new TextTooltip("Delete Color", main.getTooltipManager(), getSkin());
            closeButton.addListener(toolTip);
            button.add(closeButton).padLeft(5.0f);
            if (styleProperty == null && customProperty == null && !selectingForTintedDrawable) {
                button.setTouchable(Touchable.childrenOnly);
            } else {
                setObject(button, color);
                final ColorData result = color;
                button.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                        result(result);
                        hide();
                    }
                });
            }
            colorTable.add(button).growX();
            colorTable.row();
        }
    } else {
        colorTable.add(new Label("No colors have been set!", getSkin(), "required"));
    }
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Color(com.badlogic.gdx.graphics.Color) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) ColorData(com.ray3k.skincomposer.data.ColorData) Array(com.badlogic.gdx.utils.Array) StyleProperty(com.ray3k.skincomposer.data.StyleProperty) DrawableData(com.ray3k.skincomposer.data.DrawableData) TextTooltip(com.badlogic.gdx.scenes.scene2d.ui.TextTooltip) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) StyleData(com.ray3k.skincomposer.data.StyleData)

Example 9 with StyleProperty

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

the class DialogFonts method refreshTable.

public void refreshTable() {
    fontsTable.clear();
    fontsTable.defaults().growX().pad(5.0f);
    if (fonts.size == 0 && freeTypeFonts.size == 0) {
        fontsTable.add(new Label("No fonts have been set!", getSkin()));
    } else {
        if (fonts.size > 0) {
            Label label = new Label("Bitmap Fonts", getSkin(), "required");
            label.setAlignment(Align.center);
            fontsTable.add(label);
            fontsTable.row();
        }
        for (FontData font : fonts) {
            Button button = new Button(getSkin(), "color-base");
            Label label = new Label(font.getName(), getSkin());
            label.setTouchable(Touchable.disabled);
            button.add(label).left();
            button.addListener(main.getHandListener());
            Button renameButton = new Button(getSkin(), "settings-small");
            renameButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    renameDialog(font);
                    event.setBubbles(false);
                }
            });
            renameButton.addListener(new InputListener() {

                @Override
                public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                    event.setBubbles(false);
                    return true;
                }
            });
            button.add(renameButton).padLeft(15.0f);
            TextTooltip toolTip = new TextTooltip("Rename Font", main.getTooltipManager(), getSkin());
            renameButton.addListener(toolTip);
            LabelStyle style = new LabelStyle();
            style.font = fontMap.get(font);
            style.fontColor = Color.WHITE;
            label = new Label("Lorem Ipsum", style);
            label.setAlignment(Align.center);
            label.setTouchable(Touchable.disabled);
            Table bg = new Table(getSkin());
            bg.setBackground("white");
            BitmapFontData bf = new BitmapFontData(font.file, false);
            if (bf.imagePaths.length > 0) {
                FileHandle file = new FileHandle(bf.imagePaths[0]);
                if (!file.exists()) {
                    file = bf.fontFile.sibling(bf.fontFile.nameWithoutExtension() + ".png");
                }
                if (Utils.brightness(Utils.averageEdgeColor(file)) < .5f) {
                    bg.setColor(Color.WHITE);
                } else {
                    bg.setColor(Color.BLACK);
                }
            }
            bg.add(label).pad(5.0f).grow();
            button.add(bg).padLeft(15).growX();
            Button closeButton = new Button(getSkin(), "delete-small");
            final FontData deleteFont = font;
            closeButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    fonts.removeValue(deleteFont, true);
                    main.getProjectData().setChangesSaved(false);
                    BitmapFontData bitmapFontData = new BitmapFontData(deleteFont.file, false);
                    for (String path : bitmapFontData.imagePaths) {
                        FileHandle imagefile = new FileHandle(path);
                        drawables.removeValue(new DrawableData(imagefile), false);
                    }
                    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(deleteFont.getName())) {
                                    property.value = null;
                                }
                            }
                        }
                    }
                    main.getUndoableManager().clearUndoables();
                    main.getRootTable().refreshStyleProperties(true);
                    main.getRootTable().refreshPreview();
                    event.setBubbles(false);
                    refreshTable();
                }
            });
            closeButton.addListener(new InputListener() {

                @Override
                public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                    event.setBubbles(false);
                    return true;
                }
            });
            button.add(closeButton).padLeft(5.0f).right();
            toolTip = new TextTooltip("Delete Font", main.getTooltipManager(), getSkin());
            closeButton.addListener(toolTip);
            if (styleProperty == null && customProperty == null) {
                button.setTouchable(Touchable.childrenOnly);
            } else {
                final FontData fontResult = font;
                button.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                        result(fontResult);
                        hide();
                    }
                });
            }
            fontsTable.add(button);
            fontsTable.row();
        }
        if (freeTypeFonts.size > 0) {
            Label label = new Label("FreeType Fonts", getSkin(), "required");
            label.setAlignment(Align.center);
            fontsTable.add(label).spaceTop(20.0f);
            fontsTable.row();
        }
        for (FreeTypeFontData font : freeTypeFonts) {
            Button button = new Button(getSkin(), "color-base");
            Label label = new Label(font.name, getSkin());
            label.setTouchable(Touchable.disabled);
            button.add(label).left();
            button.addListener(main.getHandListener());
            Button renameButton = new Button(getSkin(), "settings-small");
            renameButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    freeTypeSettingsDialog(font);
                    event.setBubbles(false);
                }
            });
            renameButton.addListener(new InputListener() {

                @Override
                public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                    event.setBubbles(false);
                    return true;
                }
            });
            button.add(renameButton).padLeft(15.0f);
            TextTooltip toolTip = new TextTooltip("Rename Font", main.getTooltipManager(), getSkin());
            renameButton.addListener(toolTip);
            LabelStyle style = new LabelStyle();
            style.font = font.bitmapFont;
            style.fontColor = Color.WHITE;
            label = new Label("Lorem Ipsum", style);
            label.setAlignment(Align.center);
            label.setTouchable(Touchable.disabled);
            Table bg = new Table(getSkin());
            bg.setBackground("white");
            bg.add(label).pad(5.0f).grow();
            button.add(bg).padLeft(15).growX();
            Button closeButton = new Button(getSkin(), "delete-small");
            final FreeTypeFontData deleteFont = font;
            closeButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    freeTypeFonts.removeValue(deleteFont, true);
                    main.getProjectData().setChangesSaved(false);
                    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(deleteFont.name)) {
                                    property.value = null;
                                }
                            }
                        }
                    }
                    main.getUndoableManager().clearUndoables();
                    main.getRootTable().refreshStyleProperties(true);
                    main.getRootTable().refreshPreview();
                    event.setBubbles(false);
                    refreshTable();
                }
            });
            closeButton.addListener(new InputListener() {

                @Override
                public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                    event.setBubbles(false);
                    return true;
                }
            });
            button.add(closeButton).padLeft(5.0f).right();
            toolTip = new TextTooltip("Delete Font", main.getTooltipManager(), getSkin());
            closeButton.addListener(toolTip);
            if (styleProperty == null && customProperty == null) {
                button.setTouchable(Touchable.childrenOnly);
            } else {
                final FreeTypeFontData fontResult = font;
                button.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                        result(fontResult);
                        hide();
                    }
                });
            }
            fontsTable.add(button);
            fontsTable.row();
        }
    }
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) BitmapFontData(com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData) FileHandle(com.badlogic.gdx.files.FileHandle) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) FontData(com.ray3k.skincomposer.data.FontData) BitmapFontData(com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) LabelStyle(com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle) Array(com.badlogic.gdx.utils.Array) StyleProperty(com.ray3k.skincomposer.data.StyleProperty) DrawableData(com.ray3k.skincomposer.data.DrawableData) TextTooltip(com.badlogic.gdx.scenes.scene2d.ui.TextTooltip) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) 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