Search in sources :

Example 1 with DialogListener

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

the class MainListener method openFile.

public void openFile() {
    Runnable runnable = () -> {
        String defaultPath = projectData.getLastOpenSavePath();
        String[] filterPatterns = null;
        if (!Utils.isMac()) {
            filterPatterns = new String[] { "*.scmp" };
        }
        File file = desktopWorker.openDialog("Open Skin Composer file...", defaultPath, filterPatterns, "Skin Composer files");
        if (file != null) {
            Gdx.app.postRunnable(() -> {
                FileHandle fileHandle = new FileHandle(file);
                projectData.load(fileHandle);
                Array<DrawableData> drawableErrors = projectData.verifyDrawablePaths();
                Array<FontData> fontErrors = projectData.verifyFontPaths();
                var freeTypeFontErrors = projectData.verifyFreeTypeFontPaths();
                if (drawableErrors.size > 0 || fontErrors.size > 0 || freeTypeFontErrors.size > 0) {
                    dialogFactory.showDialogPathErrors(drawableErrors, fontErrors, freeTypeFontErrors);
                }
                if (projectData.checkForInvalidMinWidthHeight()) {
                    projectData.setLoadedVersion(Main.VERSION);
                    dialogFactory.yesNoDialog("Fix minWidth and minHeight errors?", "Old project (< v.30) detected.\nResolve minWidth and minHeight errors?", new DialogFactory.ConfirmationListener() {

                        @Override
                        public void selected(int selection) {
                            if (selection == 0) {
                                projectData.fixInvalidMinWidthHeight();
                                refreshTextureAtlas();
                            }
                        }
                    }, null);
                }
                projectData.setLastOpenSavePath(fileHandle.parent().path() + "/");
                rootTable.populate();
                rootTable.updateRecentFiles();
            });
        }
    };
    if (!projectData.areChangesSaved() && !projectData.isNewProject()) {
        var dialog = dialogFactory.yesNoCancelDialog("Save Changes?", "Do you want to save changes to the existing project?" + "\nAll unsaved changes will be lost.", (int selection) -> {
            if (selection == 0) {
                saveFile(runnable);
            } else if (selection == 1) {
                dialogFactory.showDialogLoading(runnable);
            }
        }, dialogListener);
        dialog.addListener(new DialogListener() {

            @Override
            public void opened() {
                desktopWorker.removeFilesDroppedListener(rootTable.getFilesDroppedListener());
            }

            @Override
            public void closed() {
                desktopWorker.addFilesDroppedListener(rootTable.getFilesDroppedListener());
            }
        });
    } else {
        dialogFactory.showDialogLoading(runnable);
    }
}
Also used : Array(com.badlogic.gdx.utils.Array) FileHandle(com.badlogic.gdx.files.FileHandle) DialogListener(com.ray3k.skincomposer.dialog.DialogListener) File(java.io.File)

Example 2 with DialogListener

use of com.ray3k.skincomposer.dialog.DialogListener 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)

Example 3 with DialogListener

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

the class ImageButtonListeners method imageButtonColorListener.

public static EventListener imageButtonColorListener(final DialogSceneComposerEvents events, SimActor simActor) {
    var simImageButton = (DialogSceneComposerModel.SimImageButton) simActor;
    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("Color:", skin, "scene-label-colored");
            popTable.add(label);
            popTable.row();
            var imageButton = new ImageButton(skin, "scene-color");
            imageButton.getImage().setColor(simImageButton.color == null ? Color.WHITE : simImageButton.color.color);
            popTable.add(imageButton).minWidth(100);
            imageButton.addListener(handListener);
            imageButton.addListener(new TextTooltip("Select the color of the button.", tooltipManager, skin, "scene"));
            imageButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    popTable.hide();
                    dialogFactory.showDialogColors(new StyleProperty(), (colorData, pressedCancel) -> {
                        if (!pressedCancel) {
                            events.imageButtonColor(colorData);
                        }
                    }, new DialogListener() {

                        @Override
                        public void opened() {
                        }

                        @Override
                        public void closed() {
                        }
                    });
                }
            });
            popTable.row();
            label = new Label(simImageButton.color == null ? "white" : simImageButton.color.getName(), skin, "scene-label-colored");
            popTable.add(label);
        }
    };
    popTableClickListener.update();
    return popTableClickListener;
}
Also used : InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) PopTableClickListener(com.ray3k.stripe.PopTableClickListener) com.badlogic.gdx.scenes.scene2d.ui(com.badlogic.gdx.scenes.scene2d.ui) DialogSceneComposer(com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposer) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) DialogListener(com.ray3k.skincomposer.dialog.DialogListener) TEXT_FIELD_WIDTH(com.ray3k.skincomposer.dialog.scenecomposer.menulisteners.ListenersUtils.TEXT_FIELD_WIDTH) Spinner(com.ray3k.stripe.Spinner) Color(com.badlogic.gdx.graphics.Color) Actor(com.badlogic.gdx.scenes.scene2d.Actor) DialogSceneComposerEvents(com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerEvents) DialogSceneComposerModel(com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerModel) SimActor(com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerModel.SimActor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) Keys(com.badlogic.gdx.Input.Keys) Main(com.ray3k.skincomposer.Main) Input(com.badlogic.gdx.Input) StyleData(com.ray3k.skincomposer.data.StyleData) StyleSelectorPopTable(com.ray3k.skincomposer.dialog.scenecomposer.StyleSelectorPopTable) EventListener(com.badlogic.gdx.scenes.scene2d.EventListener) StyleProperty(com.ray3k.skincomposer.data.StyleProperty) StyleProperty(com.ray3k.skincomposer.data.StyleProperty) PopTableClickListener(com.ray3k.stripe.PopTableClickListener) DialogListener(com.ray3k.skincomposer.dialog.DialogListener) Actor(com.badlogic.gdx.scenes.scene2d.Actor) SimActor(com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerModel.SimActor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent)

Example 4 with DialogListener

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

the class DialogSceneComposer method rootBackgroundColorListener.

private EventListener rootBackgroundColorListener() {
    var popTableClickListener = new PopTableClickListener(skin) {

        @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("Color:", skin, "scene-label-colored");
            popTable.add(label);
            popTable.row();
            var imageButton = new ImageButton(skin, "scene-color");
            imageButton.getImage().setColor(rootActor.backgroundColor == null ? Color.WHITE : rootActor.backgroundColor.color);
            popTable.add(imageButton).minWidth(100);
            imageButton.addListener(handListener);
            imageButton.addListener(new TextTooltip("Select the color of the background.", tooltipManager, skin, "scene"));
            imageButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    popTable.hide();
                    dialogFactory.showDialogColors(new StyleProperty(), (colorData, pressedCancel) -> {
                        if (!pressedCancel) {
                            events.rootBackgroundColor(colorData);
                        }
                    }, new DialogListener() {

                        @Override
                        public void opened() {
                        }

                        @Override
                        public void closed() {
                        }
                    });
                }
            });
            popTable.row();
            label = new Label(rootActor.backgroundColor == null ? "white" : rootActor.backgroundColor.getName(), skin, "scene-label-colored");
            popTable.add(label);
        }
    };
    popTableClickListener.update();
    return popTableClickListener;
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) PopTableClickListener(com.ray3k.stripe.PopTableClickListener) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) com.badlogic.gdx.scenes.scene2d.ui(com.badlogic.gdx.scenes.scene2d.ui) com.ray3k.skincomposer.dialog.scenecomposer.menulisteners(com.ray3k.skincomposer.dialog.scenecomposer.menulisteners) Array(com.badlogic.gdx.utils.Array) Cursor(com.badlogic.gdx.graphics.Cursor) DialogListener(com.ray3k.skincomposer.dialog.DialogListener) Gdx(com.badlogic.gdx.Gdx) Align(com.badlogic.gdx.utils.Align) Color(com.badlogic.gdx.graphics.Color) DialogSceneComposerModel(com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerModel) PopTable(com.ray3k.stripe.PopTable) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) StripeMenuBar(com.ray3k.stripe.StripeMenuBar) KeyboardShortcut(com.ray3k.stripe.StripeMenuBar.KeyboardShortcut) Keys(com.badlogic.gdx.Input.Keys) Main(com.ray3k.skincomposer.Main) IntPair(com.ray3k.skincomposer.utils.IntPair) Input(com.badlogic.gdx.Input) com.badlogic.gdx.scenes.scene2d(com.badlogic.gdx.scenes.scene2d) StyleProperty(com.ray3k.skincomposer.data.StyleProperty) StyleProperty(com.ray3k.skincomposer.data.StyleProperty) PopTableClickListener(com.ray3k.stripe.PopTableClickListener) DialogListener(com.ray3k.skincomposer.dialog.DialogListener) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Example 5 with DialogListener

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

the class LabelListeners method labelColorListener.

public static EventListener labelColorListener(final DialogSceneComposerEvents events, SimActor simActor) {
    var simLabel = (DialogSceneComposerModel.SimLabel) simActor;
    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("Color:", skin, "scene-label-colored");
            popTable.add(label);
            popTable.row();
            var imageButton = new ImageButton(skin, "scene-color");
            imageButton.getImage().setColor(simLabel.color == null ? Color.WHITE : simLabel.color.color);
            popTable.add(imageButton).minWidth(100);
            imageButton.addListener(handListener);
            imageButton.addListener(new TextTooltip("Select the color of the Label.", tooltipManager, skin, "scene"));
            imageButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    popTable.hide();
                    dialogFactory.showDialogColors(new StyleProperty(), (colorData, pressedCancel) -> {
                        if (!pressedCancel) {
                            events.labelColor(colorData);
                        }
                    }, new DialogListener() {

                        @Override
                        public void opened() {
                        }

                        @Override
                        public void closed() {
                        }
                    });
                }
            });
            popTable.row();
            label = new Label(simLabel.color == null ? "white" : simLabel.color.getName(), skin, "scene-label-colored");
            popTable.add(label);
        }
    };
    popTableClickListener.update();
    return popTableClickListener;
}
Also used : InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) PopTableClickListener(com.ray3k.stripe.PopTableClickListener) com.badlogic.gdx.scenes.scene2d.ui(com.badlogic.gdx.scenes.scene2d.ui) DialogSceneComposer(com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposer) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) DialogListener(com.ray3k.skincomposer.dialog.DialogListener) TEXT_FIELD_WIDTH(com.ray3k.skincomposer.dialog.scenecomposer.menulisteners.ListenersUtils.TEXT_FIELD_WIDTH) Align(com.badlogic.gdx.utils.Align) Color(com.badlogic.gdx.graphics.Color) Actor(com.badlogic.gdx.scenes.scene2d.Actor) DialogSceneComposerEvents(com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerEvents) DialogSceneComposerModel(com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerModel) SimActor(com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerModel.SimActor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) Keys(com.badlogic.gdx.Input.Keys) Main(com.ray3k.skincomposer.Main) Input(com.badlogic.gdx.Input) StyleData(com.ray3k.skincomposer.data.StyleData) StyleSelectorPopTable(com.ray3k.skincomposer.dialog.scenecomposer.StyleSelectorPopTable) EventListener(com.badlogic.gdx.scenes.scene2d.EventListener) StyleProperty(com.ray3k.skincomposer.data.StyleProperty) StyleProperty(com.ray3k.skincomposer.data.StyleProperty) PopTableClickListener(com.ray3k.stripe.PopTableClickListener) DialogListener(com.ray3k.skincomposer.dialog.DialogListener) Actor(com.badlogic.gdx.scenes.scene2d.Actor) SimActor(com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerModel.SimActor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent)

Aggregations

DialogListener (com.ray3k.skincomposer.dialog.DialogListener)14 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)10 PopTableClickListener (com.ray3k.stripe.PopTableClickListener)10 Input (com.badlogic.gdx.Input)9 Keys (com.badlogic.gdx.Input.Keys)9 Color (com.badlogic.gdx.graphics.Color)9 com.badlogic.gdx.scenes.scene2d.ui (com.badlogic.gdx.scenes.scene2d.ui)9 Main (com.ray3k.skincomposer.Main)9 StyleProperty (com.ray3k.skincomposer.data.StyleProperty)9 DialogSceneComposerModel (com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerModel)9 SimActor (com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerModel.SimActor)8 DialogSceneComposer (com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposer)7 DialogSceneComposerEvents (com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerEvents)7 TEXT_FIELD_WIDTH (com.ray3k.skincomposer.dialog.scenecomposer.menulisteners.ListenersUtils.TEXT_FIELD_WIDTH)7 Actor (com.badlogic.gdx.scenes.scene2d.Actor)6 EventListener (com.badlogic.gdx.scenes.scene2d.EventListener)6 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)6 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)6 StyleData (com.ray3k.skincomposer.data.StyleData)6 StyleSelectorPopTable (com.ray3k.skincomposer.dialog.scenecomposer.StyleSelectorPopTable)6