Search in sources :

Example 46 with ChangeListener

use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener in project skin-composer by raeleus.

the class DialogDrawables method populate.

public void populate() {
    getContentTable().clear();
    getButtonTable().padBottom(15.0f);
    if (property == null && customProperty == null) {
        getContentTable().add(new Label("Drawables", getSkin(), "title"));
    } else {
        getContentTable().add(new Label("Select a Drawable", getSkin(), "title"));
    }
    getContentTable().row();
    Table table = new Table(getSkin());
    table.defaults().pad(10.0f);
    getContentTable().add(table).growX();
    table.add("Sort by:");
    sortSelectBox = new SelectBox(getSkin());
    sortSelectBox.setItems("A-Z", "Z-A", "Oldest", "Newest");
    sortSelectBox.setSelectedIndex(sortSelection);
    sortSelectBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            sortSelection = sortSelectBox.getSelectedIndex();
            sortBySelectedMode();
        }
    });
    sortSelectBox.addListener(main.getHandListener());
    sortSelectBox.getList().addListener(main.getHandListener());
    table.add(sortSelectBox);
    TextButton textButton = new TextButton("Add Drawable", getSkin(), "new");
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Gdx.graphics.setSystemCursor(Cursor.SystemCursor.Arrow);
            newDrawableDialog();
        }
    });
    textButton.addListener(main.getHandListener());
    table.add(textButton);
    textButton = new TextButton("Custom Drawable", getSkin(), "new");
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Gdx.graphics.setSystemCursor(Cursor.SystemCursor.Arrow);
            customDrawableDialog();
        }
    });
    textButton.addListener(main.getHandListener());
    table.add(textButton);
    table.add(new Label("Zoom:", getSkin())).right().expandX();
    zoomSlider = new Slider(0, 3, 1, false, getSkin());
    zoomSlider.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            refreshDrawableDisplay();
        }
    });
    zoomSlider.addListener(main.getHandListener());
    table.add(zoomSlider);
    getContentTable().row();
    contentGroup = new HorizontalGroup();
    contentGroup.center().wrap(true).space(5.0f).wrapSpace(5.0f).rowAlign(Align.left);
    scrollPane = new ScrollPane(contentGroup, getSkin());
    scrollPane.setFadeScrollBars(false);
    scrollPane.setFlickScroll(false);
    getContentTable().add(scrollPane).grow();
    sortBySelectedMode();
    getContentTable().row();
    if (property != null || customProperty != null) {
        button("Clear Drawable", true);
        button("Cancel", false);
        getButtonTable().getCells().first().getActor().addListener(main.getHandListener());
        getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
    } else {
        button("Close", false);
        getButtonTable().getCells().first().getActor().addListener(main.getHandListener());
    }
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Slider(com.badlogic.gdx.scenes.scene2d.ui.Slider) SelectBox(com.badlogic.gdx.scenes.scene2d.ui.SelectBox) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) HorizontalGroup(com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup)

Example 47 with ChangeListener

use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener 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 48 with ChangeListener

use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener 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 49 with ChangeListener

use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener 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 50 with ChangeListener

use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener 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

Actor (com.badlogic.gdx.scenes.scene2d.Actor)71 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)71 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)51 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)43 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)38 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)25 Stage (com.badlogic.gdx.scenes.scene2d.Stage)22 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)21 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)15 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)14 SelectBox (com.badlogic.gdx.scenes.scene2d.ui.SelectBox)12 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)12 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)11 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)11 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)11 DrawableData (com.ray3k.skincomposer.data.DrawableData)11 ColorData (com.ray3k.skincomposer.data.ColorData)10 Color (com.badlogic.gdx.graphics.Color)9 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)9 Slider (com.badlogic.gdx.scenes.scene2d.ui.Slider)9