Search in sources :

Example 11 with DialogListener

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

the class MainListener method newFile.

public void newFile() {
    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(() -> {
                    Gdx.app.postRunnable(() -> {
                        projectData.clear();
                    });
                });
            } else if (selection == 1) {
                projectData.clear();
            }
        }, dialogListener);
        dialog.addListener(new DialogListener() {

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

            @Override
            public void closed() {
                desktopWorker.addFilesDroppedListener(rootTable.getFilesDroppedListener());
            }
        });
    } else {
        projectData.clear();
    }
}
Also used : DialogListener(com.ray3k.skincomposer.dialog.DialogListener)

Example 12 with DialogListener

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

the class MainListener method openFile.

public void openFile(FileHandle fileHandle) {
    Runnable runnable = () -> {
        if (fileHandle != null) {
            Gdx.app.postRunnable(() -> {
                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) DialogListener(com.ray3k.skincomposer.dialog.DialogListener)

Example 13 with DialogListener

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

the class TableListeners method tableColorListener.

public static EventListener tableColorListener(final DialogSceneComposerEvents events, SimActor simActor) {
    var simTable = (DialogSceneComposerModel.SimTable) 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(simTable.color == null ? Color.WHITE : simTable.color.color);
            popTable.add(imageButton).minWidth(100);
            imageButton.addListener(handListener);
            imageButton.addListener(new TextTooltip("Select the color of the table background and of the table contents.", tooltipManager, skin, "scene"));
            popTable.row();
            var colorLabel = new Label(simTable.color == null ? "No Color" : simTable.color.getName(), skin, "scene-label-colored");
            popTable.add(colorLabel);
            imageButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    popTable.hide();
                    dialogFactory.showDialogColors(new StyleProperty(), (colorData, pressedCancel) -> {
                        if (!pressedCancel) {
                            events.tableColor(colorData);
                            imageButton.getImage().setColor(colorData == null ? Color.WHITE : colorData.color);
                            colorLabel.setText(colorData == null ? "No Color" : colorData.getName());
                        }
                    }, new DialogListener() {

                        @Override
                        public void opened() {
                        }

                        @Override
                        public void closed() {
                        }
                    });
                }
            });
        }
    };
    popTableClickListener.update();
    return popTableClickListener;
}
Also used : 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) DialogSceneComposer(com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposer) DialogListener(com.ray3k.skincomposer.dialog.DialogListener) TEXT_FIELD_WIDTH(com.ray3k.skincomposer.dialog.scenecomposer.menulisteners.ListenersUtils.TEXT_FIELD_WIDTH) Spinner(com.ray3k.stripe.Spinner) Align(com.badlogic.gdx.utils.Align) Color(com.badlogic.gdx.graphics.Color) DialogSceneComposerEvents(com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerEvents) DialogSceneComposerModel(com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerModel) KeyListener(com.ray3k.stripe.PopTable.KeyListener) PopTable(com.ray3k.stripe.PopTable) 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) WidgetType(com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerEvents.WidgetType) 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) SimActor(com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerModel.SimActor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Example 14 with DialogListener

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

the class TextButtonListeners method textButtonColorListener.

public static EventListener textButtonColorListener(final DialogSceneComposerEvents events, SimActor simActor) {
    var simTextButton = (DialogSceneComposerModel.SimTextButton) 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(simTextButton.color == null ? Color.WHITE : simTextButton.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.textButtonColor(colorData);
                        }
                    }, new DialogListener() {

                        @Override
                        public void opened() {
                        }

                        @Override
                        public void closed() {
                        }
                    });
                }
            });
            popTable.row();
            label = new Label(simTextButton.color == null ? "white" : simTextButton.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)

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