Search in sources :

Example 11 with ColorData

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

the class DialogColors method renameDialog.

private void renameDialog(ColorData color) {
    TextField textField = new TextField("", getSkin());
    TextButton okButton;
    Dialog dialog = new Dialog("Rename Color?", getSkin(), "bg") {

        @Override
        protected void result(Object object) {
            if ((boolean) object) {
                renameColor(color, textField.getText());
            }
        }

        @Override
        public Dialog show(Stage stage) {
            Dialog dialog = super.show(stage);
            main.getStage().setKeyboardFocus(textField);
            return dialog;
        }
    };
    dialog.getTitleTable().padLeft(5.0f);
    float brightness = Utils.brightness(color.color);
    Color borderColor;
    if (brightness > .35f) {
        borderColor = Color.BLACK;
    } else {
        borderColor = Color.WHITE;
    }
    Table bg = new Table(getSkin());
    bg.setBackground("white");
    bg.setColor(borderColor);
    dialog.getContentTable().add(bg);
    Label label = new Label(color.getName(), getSkin(), "white");
    label.setColor(color.color);
    bg.add(label).pad(10);
    dialog.getContentTable().row();
    label = new Label("What do you want to rename the color to?", getSkin());
    dialog.getContentTable().add(label);
    dialog.getContentTable().row();
    textField.setText(color.getName());
    textField.selectAll();
    textField.addListener(main.getIbeamListener());
    dialog.getContentTable().add(textField);
    dialog.getCell(dialog.getContentTable()).pad(15.0f);
    dialog.button("OK", true);
    dialog.button("Cancel", false).key(Keys.ESCAPE, false);
    okButton = (TextButton) dialog.getButtonTable().getCells().first().getActor();
    okButton.setDisabled(true);
    okButton.addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
    dialog.getButtonTable().padBottom(15.0f);
    textField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            boolean disable = !ColorData.validate(textField.getText());
            if (!disable) {
                for (ColorData data : main.getJsonData().getColors()) {
                    if (data.getName().equals(textField.getText())) {
                        disable = true;
                        break;
                    }
                }
            }
            okButton.setDisabled(disable);
        }
    });
    textField.setTextFieldListener(new TextField.TextFieldListener() {

        @Override
        public void keyTyped(TextField textField, char c) {
            if (c == '\n') {
                if (!okButton.isDisabled()) {
                    renameColor(color, textField.getText());
                    dialog.hide();
                }
            }
        }
    });
    textField.setFocusTraversal(false);
    dialog.show(getStage());
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) 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) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Stage(com.badlogic.gdx.scenes.scene2d.Stage) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Example 12 with ColorData

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

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

the class DialogColors method newColor.

private boolean newColor(String name, Color color) {
    if (ColorData.validate(name)) {
        try {
            main.getProjectData().setChangesSaved(false);
            colors.add(new ColorData(name, color));
            sortBySelectedMode();
            refreshTable();
            return true;
        } catch (Exception e) {
            Gdx.app.log(getClass().getName(), "Error trying to add color.", e);
            main.getDialogFactory().showDialogError("Error creating color...", "Error while attempting to create color.\n\nOpen log?");
            return false;
        }
    } else {
        return false;
    }
}
Also used : ColorData(com.ray3k.skincomposer.data.ColorData)

Example 14 with ColorData

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

the class DialogDrawables method colorSwatchesDialog.

private void colorSwatchesDialog(DrawableData drawableData) {
    DialogColors dialog = new DialogColors(main, (StyleProperty) null, true, (ColorData colorData) -> {
        if (colorData != null) {
            final DrawableData tintedDrawable = new DrawableData(drawableData.file);
            tintedDrawable.tintName = colorData.getName();
            // Fix background color for new, tinted drawable
            Color temp = Utils.averageEdgeColor(tintedDrawable.file, colorData.color);
            if (Utils.brightness(temp) > .5f) {
                tintedDrawable.bgColor = Color.BLACK;
            } else {
                tintedDrawable.bgColor = Color.WHITE;
            }
            final TextField textField = new TextField(drawableData.name, getSkin());
            final TextButton button = new TextButton("OK", getSkin());
            button.setDisabled(!DrawableData.validate(textField.getText()) || checkIfNameExists(textField.getText()));
            button.addListener(main.getHandListener());
            textField.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    button.setDisabled(!DrawableData.validate(textField.getText()) || checkIfNameExists(textField.getText()));
                }
            });
            textField.addListener(main.getIbeamListener());
            Dialog approveDialog = new Dialog("TintedDrawable...", getSkin(), "bg") {

                @Override
                protected void result(Object object) {
                    if (object instanceof Boolean && (boolean) object) {
                        tintedDrawable.name = textField.getText();
                        main.getAtlasData().getDrawables().add(tintedDrawable);
                        main.getProjectData().setChangesSaved(false);
                    }
                }

                @Override
                public boolean remove() {
                    gatherDrawables();
                    produceAtlas();
                    sortBySelectedMode();
                    getStage().setScrollFocus(scrollPane);
                    return super.remove();
                }
            };
            approveDialog.addCaptureListener(new InputListener() {

                @Override
                public boolean keyDown(InputEvent event, int keycode2) {
                    if (keycode2 == Input.Keys.ENTER) {
                        if (!button.isDisabled()) {
                            tintedDrawable.name = textField.getText();
                            main.getAtlasData().getDrawables().add(tintedDrawable);
                            main.getProjectData().setChangesSaved(false);
                            approveDialog.hide();
                        }
                    }
                    return false;
                }
            });
            approveDialog.getTitleTable().padLeft(5.0f);
            approveDialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f);
            approveDialog.getButtonTable().padBottom(15.0f);
            approveDialog.text("What is the name of the new tinted drawable?");
            Drawable drawable = drawablePairs.get(drawableData);
            Drawable preview = null;
            if (drawable instanceof SpriteDrawable) {
                preview = ((SpriteDrawable) drawable).tint(colorData.color);
            } else if (drawable instanceof NinePatchDrawable) {
                preview = ((NinePatchDrawable) drawable).tint(colorData.color);
            }
            if (preview != null) {
                approveDialog.getContentTable().row();
                Table table = new Table();
                table.setBackground(preview);
                approveDialog.getContentTable().add(table);
            }
            approveDialog.getContentTable().row();
            approveDialog.getContentTable().add(textField).growX();
            approveDialog.button(button, true);
            approveDialog.button("Cancel", false);
            approveDialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
            approveDialog.key(Input.Keys.ESCAPE, false);
            approveDialog.show(getStage());
            getStage().setKeyboardFocus(textField);
            textField.selectAll();
            textField.setFocusTraversal(false);
        }
    });
    dialog.setFillParent(true);
    dialog.show(getStage());
    dialog.refreshTable();
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Color(com.badlogic.gdx.graphics.Color) 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) ColorData(com.ray3k.skincomposer.data.ColorData) DrawableData(com.ray3k.skincomposer.data.DrawableData) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)

Example 15 with ColorData

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

the class DialogDrawables method tiledDrawableDialog.

private void tiledDrawableDialog(DrawableData drawable) {
    DialogColors dialog = new DialogColors(main, (StyleProperty) null, true, (ColorData colorData) -> {
        if (colorData != null) {
            final Spinner minWidthSpinner = new Spinner(0.0f, 1.0f, true, Spinner.Orientation.HORIZONTAL, getSkin());
            final Spinner minHeightSpinner = new Spinner(0.0f, 1.0f, true, Spinner.Orientation.HORIZONTAL, getSkin());
            TextField textField = new TextField("", getSkin()) {

                @Override
                public void next(boolean up) {
                    if (up) {
                        getStage().setKeyboardFocus(minHeightSpinner.getTextField());
                        minHeightSpinner.getTextField().selectAll();
                    } else {
                        getStage().setKeyboardFocus(minWidthSpinner.getTextField());
                        minWidthSpinner.getTextField().selectAll();
                    }
                }
            };
            Dialog tileDialog = new Dialog("New Tiled Drawable", getSkin(), "bg") {

                @Override
                protected void result(Object object) {
                    super.result(object);
                    if (object instanceof Boolean && (boolean) object == true) {
                        tiledDrawable(drawable, colorData, (float) minWidthSpinner.getValue(), (float) minHeightSpinner.getValue(), textField.getText());
                    }
                    getStage().setScrollFocus(scrollPane);
                }

                @Override
                public Dialog show(Stage stage) {
                    Dialog dialog = super.show(stage);
                    stage.setKeyboardFocus(textField);
                    return dialog;
                }
            };
            tileDialog.getTitleTable().padLeft(5.0f);
            tileDialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f);
            tileDialog.getButtonTable().padBottom(15.0f);
            tileDialog.getContentTable().add(new Label("Please enter a name for the TiledDrawable: ", getSkin()));
            tileDialog.button("OK", true);
            tileDialog.button("Cancel", false).key(Keys.ESCAPE, false);
            TextButton okButton = (TextButton) tileDialog.getButtonTable().getCells().first().getActor();
            okButton.setDisabled(true);
            okButton.addListener(main.getHandListener());
            tileDialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
            tileDialog.getContentTable().row();
            textField.setText(drawable.name);
            textField.selectAll();
            tileDialog.getContentTable().add(textField);
            Vector2 dimensions = Utils.imageDimensions(drawable.file);
            tileDialog.getContentTable().row();
            Table table = new Table();
            table.defaults().space(10.0f);
            tileDialog.getContentTable().add(table);
            Label label = new Label("MinWidth:", getSkin());
            table.add(label);
            minWidthSpinner.setValue(dimensions.x);
            minWidthSpinner.setMinimum(0.0f);
            table.add(minWidthSpinner).minWidth(150.0f);
            minWidthSpinner.setTransversalPrevious(textField);
            minWidthSpinner.setTransversalNext(minHeightSpinner.getTextField());
            table.row();
            label = new Label("MinHeight:", getSkin());
            table.add(label);
            minHeightSpinner.setValue(dimensions.y);
            minHeightSpinner.setMinimum(0.0f);
            table.add(minHeightSpinner).minWidth(150.0f);
            minHeightSpinner.setTransversalPrevious(minWidthSpinner.getTextField());
            minHeightSpinner.setTransversalNext(textField);
            textField.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    boolean disable = !DrawableData.validate(textField.getText());
                    if (!disable) {
                        for (DrawableData data : main.getAtlasData().getDrawables()) {
                            if (data.name.equals(textField.getText())) {
                                disable = true;
                                break;
                            }
                        }
                    }
                    okButton.setDisabled(disable);
                }
            });
            textField.setTextFieldListener(new TextField.TextFieldListener() {

                @Override
                public void keyTyped(TextField textField, char c) {
                    if (c == '\n') {
                        if (!okButton.isDisabled()) {
                            tiledDrawable(drawable, colorData, (float) minWidthSpinner.getValue(), (float) minHeightSpinner.getValue(), textField.getText());
                            tileDialog.hide();
                        }
                    }
                }
            });
            textField.addListener(main.getIbeamListener());
            tileDialog.show(getStage());
        }
    });
    dialog.setFillParent(true);
    dialog.show(getStage());
    dialog.refreshTable();
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Spinner(com.ray3k.skincomposer.Spinner) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) ColorData(com.ray3k.skincomposer.data.ColorData) DrawableData(com.ray3k.skincomposer.data.DrawableData) Vector2(com.badlogic.gdx.math.Vector2) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Stage(com.badlogic.gdx.scenes.scene2d.Stage) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Aggregations

ColorData (com.ray3k.skincomposer.data.ColorData)15 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)11 Actor (com.badlogic.gdx.scenes.scene2d.Actor)10 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)10 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)10 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)10 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)8 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)7 DrawableData (com.ray3k.skincomposer.data.DrawableData)7 Color (com.badlogic.gdx.graphics.Color)6 StyleData (com.ray3k.skincomposer.data.StyleData)5 Stage (com.badlogic.gdx.scenes.scene2d.Stage)4 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)4 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)4 TextTooltip (com.badlogic.gdx.scenes.scene2d.ui.TextTooltip)4 Array (com.badlogic.gdx.utils.Array)4 StyleProperty (com.ray3k.skincomposer.data.StyleProperty)4 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)3 ListStyle (com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle)3 SelectBox (com.badlogic.gdx.scenes.scene2d.ui.SelectBox)3