Search in sources :

Example 1 with DialogDrawables

use of com.ray3k.skincomposer.dialog.DialogDrawables in project skin-composer by raeleus.

the class GeneralListeners method selectDrawableListener.

public static EventListener selectDrawableListener(DrawableData originalDrawable, String toolTipText, DrawableSelected drawableSelected) {
    var popTableClickListener = new PopTableClickListener(skin) {

        {
            getPopTable().key(Keys.ESCAPE, popTable::hide);
        }

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            update();
        }

        public void update() {
            var popTable = getPopTable();
            popTable.clearChildren();
            var label = new Label("Drawable:", skin, "scene-label-colored");
            popTable.add(label);
            popTable.row();
            var stack = new Stack();
            popTable.add(stack).minSize(100).maxSize(300).grow();
            var background = new Image(skin, "scene-tile-ten");
            stack.add(background);
            Image image;
            if (originalDrawable != null) {
                image = new Image(atlasData.drawablePairs.get(originalDrawable));
            } else {
                image = new Image((Drawable) null);
            }
            stack.add(image);
            popTable.row();
            var textButton = new TextButton("Select Drawable", skin, "scene-small");
            popTable.add(textButton).minWidth(100);
            textButton.addListener(handListener);
            textButton.addListener(new TextTooltip(toolTipText, tooltipManager, skin, "scene"));
            textButton.addListener(new ChangeListener() {

                boolean confirmed;

                DrawableData drawableData;

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    popTable.hide();
                    dialogFactory.showDialogDrawables(true, new DialogDrawables.DialogDrawablesListener() {

                        @Override
                        public void confirmed(DrawableData drawable, DialogDrawables dialog) {
                            confirmed = true;
                            drawableData = drawable;
                        }

                        @Override
                        public void emptied(DialogDrawables dialog) {
                            confirmed = false;
                        }

                        @Override
                        public void cancelled(DialogDrawables dialog) {
                        }
                    }, new DialogListener() {

                        @Override
                        public void opened() {
                        }

                        @Override
                        public void closed() {
                            if (confirmed) {
                                drawableSelected.selected(drawableData);
                                image.setDrawable(atlasData.drawablePairs.get(drawableData));
                            } else {
                                drawableSelected.selected(null);
                                image.setDrawable(null);
                            }
                        }
                    });
                }
            });
        }
    };
    popTableClickListener.update();
    return popTableClickListener;
}
Also used : Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) GraphDrawerDrawable(space.earlygrey.shapedrawer.scene2d.GraphDrawerDrawable) DrawableData(com.ray3k.skincomposer.data.DrawableData) PopTableClickListener(com.ray3k.stripe.PopTableClickListener) DialogListener(com.ray3k.skincomposer.dialog.DialogListener) SimActor(com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerModel.SimActor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) DialogDrawables(com.ray3k.skincomposer.dialog.DialogDrawables)

Aggregations

ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)1 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)1 DrawableData (com.ray3k.skincomposer.data.DrawableData)1 DialogDrawables (com.ray3k.skincomposer.dialog.DialogDrawables)1 DialogListener (com.ray3k.skincomposer.dialog.DialogListener)1 SimActor (com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerModel.SimActor)1 PopTableClickListener (com.ray3k.stripe.PopTableClickListener)1 GraphDrawerDrawable (space.earlygrey.shapedrawer.scene2d.GraphDrawerDrawable)1