Search in sources :

Example 16 with DrawableData

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

the class DialogDrawables method renameDrawableDialog.

private void renameDrawableDialog(DrawableData drawable) {
    TextField textField = new TextField("", getSkin());
    Dialog dialog = new Dialog("Rename drawable?", getSkin(), "bg") {

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

        @Override
        public Dialog show(Stage stage) {
            Dialog dialog = super.show(stage);
            stage.setKeyboardFocus(textField);
            return dialog;
        }
    };
    dialog.getTitleTable().padLeft(5.0f);
    dialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f);
    dialog.getButtonTable().padBottom(15.0f);
    dialog.getContentTable().add(new Label("Please enter a new name for the drawable: ", getSkin()));
    dialog.button("OK", true);
    dialog.button("Cancel", false).key(Keys.ESCAPE, false);
    TextButton okButton = (TextButton) dialog.getButtonTable().getCells().first().getActor();
    okButton.setDisabled(true);
    okButton.addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
    dialog.getContentTable().row();
    textField.setText(drawable.name);
    textField.selectAll();
    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()) {
                    renameDrawable(drawable, textField.getText());
                    dialog.hide();
                }
            }
        }
    });
    textField.addListener(main.getIbeamListener());
    dialog.getContentTable().add(textField);
    textField.setFocusTraversal(false);
    dialog.show(getStage());
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) DrawableData(com.ray3k.skincomposer.data.DrawableData) 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 17 with DrawableData

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

the class DialogDrawables method customDrawableDialog.

private void customDrawableDialog() {
    Array<DrawableData> backup = new Array<>();
    main.getDialogFactory().showCustomDrawableDialog(getSkin(), getStage(), new DialogFactory.CustomDrawableListener() {

        @Override
        public void run(String name) {
            DrawableData drawable = new DrawableData(name);
            main.getAtlasData().getDrawables().add(drawable);
            gatherDrawables();
            main.getDialogFactory().showDialogLoading(() -> {
                if (!produceAtlas()) {
                    showDrawableError();
                    Gdx.app.log(getClass().getName(), "Attempting to reload drawables backup...");
                    main.getAtlasData().getDrawables().clear();
                    main.getAtlasData().getDrawables().addAll(backup);
                    gatherDrawables();
                    if (produceAtlas()) {
                        Gdx.app.log(getClass().getName(), "Successfully rolled back changes to drawables");
                    } else {
                        Gdx.app.error(getClass().getName(), "Critical failure, could not roll back changes to drawables");
                    }
                } else {
                    if (main.getProjectData().areResourcesRelative()) {
                        main.getProjectData().makeResourcesRelative();
                    }
                    main.getProjectData().setChangesSaved(false);
                }
                sortBySelectedMode();
            });
        }
    });
}
Also used : Array(com.badlogic.gdx.utils.Array) DrawableData(com.ray3k.skincomposer.data.DrawableData)

Example 18 with DrawableData

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

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

the class DialogDrawables method newTintedDrawable.

/**
 * Creates a TintedDrawable based on the provided DrawableData. Prompts
 * user for a Color and name.
 * @param drawableData
 */
private void newTintedDrawable(DrawableData drawableData) {
    Color previousColor = Color.WHITE;
    if (drawableData.tint != null) {
        previousColor = drawableData.tint;
    }
    main.getDialogFactory().showDialogColorPicker(previousColor, new DialogColorPicker.ColorListener() {

        @Override
        public void selected(Color color) {
            if (color != null) {
                final DrawableData tintedDrawable = new DrawableData(drawableData.file);
                tintedDrawable.tint = color;
                // Fix background color for new, tinted drawable
                Color temp = Utils.averageEdgeColor(tintedDrawable.file, tintedDrawable.tint);
                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()));
                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 dialog = 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();
                    }
                };
                dialog.getTitleTable().getCells().first().padLeft(5.0f);
                dialog.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);
                                dialog.hide();
                            }
                        }
                        return false;
                    }
                });
                dialog.text("What is the name of the new tinted drawable?");
                dialog.getContentTable().getCells().first().pad(10.0f);
                Drawable drawable = drawablePairs.get(drawableData);
                Drawable preview = null;
                if (drawable instanceof SpriteDrawable) {
                    preview = ((SpriteDrawable) drawable).tint(color);
                } else if (drawable instanceof NinePatchDrawable) {
                    preview = ((NinePatchDrawable) drawable).tint(color);
                }
                if (preview != null) {
                    dialog.getContentTable().row();
                    Table table = new Table();
                    table.setBackground(preview);
                    dialog.getContentTable().add(table);
                }
                dialog.getContentTable().row();
                dialog.getContentTable().add(textField).growX().pad(10.0f);
                dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
                dialog.button(button, true);
                button.addListener(main.getHandListener());
                dialog.button("Cancel", false);
                dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
                dialog.key(Input.Keys.ESCAPE, false);
                dialog.show(getStage());
                getStage().setKeyboardFocus(textField);
                textField.selectAll();
                textField.setFocusTraversal(false);
            }
        }
    });
}
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) 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 20 with DrawableData

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

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