Search in sources :

Example 11 with DrawableData

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

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

the class DialogDrawables method tiledDrawable.

private void tiledDrawable(DrawableData drawable, ColorData colorData, float minWidth, float minHeight, String name) {
    DrawableData tiledDrawable = new DrawableData();
    tiledDrawable.name = name;
    tiledDrawable.tintName = colorData.getName();
    tiledDrawable.file = drawable.file;
    tiledDrawable.tiled = true;
    tiledDrawable.visible = true;
    tiledDrawable.minWidth = minWidth;
    tiledDrawable.minHeight = minHeight;
    // Fix background color for new, tinted drawable
    Color temp = Utils.averageEdgeColor(tiledDrawable.file, colorData.color);
    if (Utils.brightness(temp) > .5f) {
        tiledDrawable.bgColor = Color.BLACK;
    } else {
        tiledDrawable.bgColor = Color.WHITE;
    }
    main.getAtlasData().getDrawables().add(tiledDrawable);
    main.getProjectData().setChangesSaved(false);
    gatherDrawables();
    produceAtlas();
    sortBySelectedMode();
    getStage().setScrollFocus(scrollPane);
}
Also used : DrawableData(com.ray3k.skincomposer.data.DrawableData) Color(com.badlogic.gdx.graphics.Color)

Example 13 with DrawableData

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

the class DialogDrawables method result.

@Override
protected void result(Object object) {
    instance = null;
    if (object != null) {
        if (object instanceof DrawableData) {
            main.getProjectData().setChangesSaved(false);
            DrawableData drawable = (DrawableData) object;
            Undoable undoable;
            if (property != null) {
                undoable = new DrawableUndoable(main.getRootTable(), main.getAtlasData(), property, property.value, drawable.name);
            } else {
                undoable = new UndoableManager.CustomDrawableUndoable(main, customProperty, drawable.name);
            }
            main.getUndoableManager().addUndoable(undoable, true);
        } else if (object instanceof Boolean) {
            if (property != null) {
                if ((boolean) object) {
                    main.getProjectData().setChangesSaved(false);
                    DrawableUndoable undoable = new DrawableUndoable(main.getRootTable(), main.getAtlasData(), property, property.value, null);
                    main.getUndoableManager().addUndoable(undoable, true);
                    main.getRootTable().setStatusBarMessage("Drawable emptied for \"" + property.name + "\"");
                } else {
                    boolean hasDrawable = false;
                    for (DrawableData drawable : main.getAtlasData().getDrawables()) {
                        if (drawable.name.equals(property.value)) {
                            hasDrawable = true;
                            break;
                        }
                    }
                    if (!hasDrawable) {
                        main.getProjectData().setChangesSaved(false);
                        main.getUndoableManager().clearUndoables();
                        property.value = null;
                        main.getRootTable().setStatusBarMessage("Drawable deleted for \"" + property.name + "\"");
                        main.getRootTable().refreshStyleProperties(true);
                    }
                }
            } else if (customProperty != null) {
                if ((boolean) object) {
                    main.getProjectData().setChangesSaved(false);
                    CustomDrawableUndoable undoable = new CustomDrawableUndoable(main, customProperty, null);
                    main.getUndoableManager().addUndoable(undoable, true);
                    main.getRootTable().setStatusBarMessage("Drawable emptied for \"" + customProperty.getName() + "\"");
                } else {
                    boolean hasDrawable = false;
                    for (DrawableData drawable : main.getAtlasData().getDrawables()) {
                        if (drawable.name.equals(customProperty.getValue())) {
                            hasDrawable = true;
                            break;
                        }
                    }
                    if (!hasDrawable) {
                        main.getProjectData().setChangesSaved(false);
                        main.getUndoableManager().clearUndoables();
                        customProperty.setValue(null);
                        main.getRootTable().setStatusBarMessage("Drawable deleted for \"" + customProperty.getName() + "\"");
                        main.getRootTable().refreshStyleProperties(true);
                    }
                }
            }
        }
    }
    // todo: do proper implementation of event handling with fire(), etc.
    if (listener != null) {
        listener.handle(null);
        listener = null;
    }
}
Also used : CustomDrawableUndoable(com.ray3k.skincomposer.UndoableManager.CustomDrawableUndoable) DrawableUndoable(com.ray3k.skincomposer.UndoableManager.DrawableUndoable) Undoable(com.ray3k.skincomposer.Undoable) CustomDrawableUndoable(com.ray3k.skincomposer.UndoableManager.CustomDrawableUndoable) DrawableUndoable(com.ray3k.skincomposer.UndoableManager.DrawableUndoable) DrawableData(com.ray3k.skincomposer.data.DrawableData) UndoableManager(com.ray3k.skincomposer.UndoableManager) CustomDrawableUndoable(com.ray3k.skincomposer.UndoableManager.CustomDrawableUndoable) CustomDrawableUndoable(com.ray3k.skincomposer.UndoableManager.CustomDrawableUndoable)

Example 14 with DrawableData

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

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

the class DialogDrawables method checkDuplicateDrawables.

/**
 * Checks if there are any drawables that have the same file name as the specified file.
 * This ignores the file extension.
 * @param handle
 * @param minimum The minimum allowed matches before it's considered a duplicate
 * @return
 */
private boolean checkDuplicateDrawables(FileHandle handle, int minimum) {
    int count = 0;
    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()))) {
            count++;
        }
    }
    return count > minimum;
}
Also used : DrawableData(com.ray3k.skincomposer.data.DrawableData)

Aggregations

DrawableData (com.ray3k.skincomposer.data.DrawableData)25 Actor (com.badlogic.gdx.scenes.scene2d.Actor)11 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)11 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)11 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)9 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)9 FileHandle (com.badlogic.gdx.files.FileHandle)7 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)7 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)7 ColorData (com.ray3k.skincomposer.data.ColorData)7 FontData (com.ray3k.skincomposer.data.FontData)7 Array (com.badlogic.gdx.utils.Array)6 StyleData (com.ray3k.skincomposer.data.StyleData)6 Color (com.badlogic.gdx.graphics.Color)5 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)5 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)5 TextTooltip (com.badlogic.gdx.scenes.scene2d.ui.TextTooltip)5 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)5 NinePatchDrawable (com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)5 SpriteDrawable (com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable)5