Search in sources :

Example 51 with ChangeListener

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

the class DialogFactory method showNewStyleDialog.

public void showNewStyleDialog(Skin skin, Stage stage) {
    Class selectedClass = main.getRootTable().getSelectedClass();
    final TextField textField = new TextField("", skin);
    Dialog dialog = new Dialog("New Style", skin, "bg") {

        @Override
        protected void result(Object object) {
            if ((Boolean) object) {
                main.getUndoableManager().addUndoable(new NewStyleUndoable(selectedClass, textField.getText(), main), true);
            }
        }
    };
    dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
    dialog.button("OK", true).button("Cancel", false);
    dialog.getButtonTable().getCells().first().getActor().addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
    final TextButton okButton = (TextButton) dialog.getButtonTable().getCells().get(0).getActor();
    textField.setTextFieldListener((TextField textField1, char c) -> {
        if (c == '\n') {
            if (!okButton.isDisabled()) {
                main.getUndoableManager().addUndoable(new NewStyleUndoable(selectedClass, textField1.getText(), main), true);
                dialog.hide();
            }
            main.getStage().setKeyboardFocus(textField1);
        }
    });
    textField.addListener(main.getIbeamListener());
    dialog.getTitleLabel().setAlignment(Align.center);
    dialog.getContentTable().defaults().padLeft(10.0f).padRight(10.0f);
    dialog.text("What is the name of the new style?");
    dialog.getContentTable().getCells().first().pad(10.0f);
    dialog.getContentTable().row();
    dialog.getContentTable().add(textField).growX();
    okButton.setDisabled(true);
    Array<StyleData> currentStyles = main.getProjectData().getJsonData().getClassStyleMap().get(selectedClass);
    textField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            boolean disable = !StyleData.validate(textField.getText());
            if (!disable) {
                for (StyleData data : currentStyles) {
                    if (data.name.equals(textField.getText())) {
                        disable = true;
                        break;
                    }
                }
            }
            okButton.setDisabled(disable);
        }
    });
    dialog.key(Input.Keys.ESCAPE, false);
    dialog.show(stage);
    stage.setKeyboardFocus(textField);
    textField.setFocusTraversal(false);
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) NewStyleUndoable(com.ray3k.skincomposer.UndoableManager.NewStyleUndoable) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) CustomClass(com.ray3k.skincomposer.data.CustomClass) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) StyleData(com.ray3k.skincomposer.data.StyleData)

Example 52 with ChangeListener

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

the class DialogFactory method showCustomDrawableDialog.

public void showCustomDrawableDialog(Skin skin, Stage stage, DrawableData modifyDrawable, CustomDrawableListener customDrawableListener) {
    final TextField textField = new TextField("", skin);
    Dialog dialog = new Dialog("New Custom Drawable", skin, "bg") {

        @Override
        protected void result(Object object) {
            if ((Boolean) object) {
                customDrawableListener.run(textField.getText());
            }
        }
    };
    dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
    dialog.button("OK", true).button("Cancel", false);
    dialog.getButtonTable().getCells().first().getActor().addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
    final TextButton okButton = (TextButton) dialog.getButtonTable().getCells().get(0).getActor();
    textField.setTextFieldListener((TextField textField1, char c) -> {
        if (c == '\n') {
            if (!okButton.isDisabled()) {
                customDrawableListener.run(textField.getText());
                dialog.hide();
            }
            main.getStage().setKeyboardFocus(textField1);
        }
    });
    textField.addListener(main.getIbeamListener());
    if (modifyDrawable != null) {
        textField.setText(modifyDrawable.name);
    }
    dialog.getTitleLabel().setAlignment(Align.center);
    dialog.getContentTable().defaults().padLeft(10.0f).padRight(10.0f);
    if (modifyDrawable == null) {
        dialog.text("Enter the name for the custom drawable.\nUse to reference custom classes that inherit from Drawable.");
    } else {
        dialog.text("Enter the new name for the custom drawable.\nUse to reference custom classes that inherit from Drawable.");
    }
    ((Label) dialog.getContentTable().getCells().first().getActor()).setAlignment(Align.center);
    dialog.getContentTable().getCells().first().pad(10.0f);
    dialog.getContentTable().row();
    dialog.getContentTable().add(textField).growX();
    okButton.setDisabled(true);
    textField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            boolean disable = !StyleData.validate(textField.getText());
            if (main.getAtlasData().getDrawable(textField.getText()) != null) {
                disable = true;
            }
            okButton.setDisabled(disable);
        }
    });
    dialog.key(Input.Keys.ESCAPE, false);
    dialog.show(stage);
    stage.setKeyboardFocus(textField);
    textField.selectAll();
    textField.setFocusTraversal(false);
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Example 53 with ChangeListener

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

the class DialogFonts method fontNameDialog.

private void fontNameDialog(Array<FileHandle> files, int index) {
    if (index < files.size) {
        try {
            final FileHandle fileHandle = files.get(index);
            final TextField textField = new TextField(FontData.filter(fileHandle.nameWithoutExtension()), getSkin());
            final Dialog nameDialog = new Dialog("Enter a name...", getSkin(), "bg") {

                @Override
                protected void result(Object object) {
                    if ((Boolean) object) {
                        String name = textField.getText();
                        addFont(name, fileHandle);
                    }
                }

                @Override
                public boolean remove() {
                    fontNameDialog(files, index + 1);
                    return super.remove();
                }
            };
            nameDialog.getTitleTable().padLeft(5.0f);
            nameDialog.button("OK", true);
            nameDialog.button("Cancel", false);
            nameDialog.getButtonTable().getCells().first().getActor().addListener(main.getHandListener());
            nameDialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
            final TextButton button = (TextButton) nameDialog.getButtonTable().getCells().first().getActor();
            nameDialog.getButtonTable().padBottom(15.0f);
            textField.setTextFieldListener((TextField textField1, char c) -> {
                if (c == '\n') {
                    if (!button.isDisabled()) {
                        String name1 = textField1.getText();
                        if (addFont(name1, fileHandle)) {
                            nameDialog.hide();
                        }
                    }
                    main.getStage().setKeyboardFocus(textField1);
                }
            });
            textField.addListener(main.getIbeamListener());
            nameDialog.getContentTable().defaults().padLeft(10.0f).padRight(10.0f).padTop(5.0f);
            nameDialog.text("Please enter a name for the new font: ");
            nameDialog.getContentTable().row();
            nameDialog.getContentTable().add(textField).growX();
            nameDialog.getContentTable().row();
            nameDialog.text("Preview:");
            nameDialog.getContentTable().row();
            LabelStyle previewStyle = new LabelStyle();
            previewStyle.font = new BitmapFont(fileHandle);
            Table table = new Table(getSkin());
            table.setBackground("white");
            BitmapFontData bitmapFontData = new BitmapFontData(fileHandle, false);
            if (Utils.brightness(Utils.averageEdgeColor(new FileHandle(bitmapFontData.imagePaths[0]))) > .5f) {
                table.setColor(Color.BLACK);
            } else {
                table.setColor(Color.WHITE);
            }
            table.add(new Label("Lorem Ipsum", previewStyle)).pad(5.0f);
            nameDialog.getContentTable().add(table);
            nameDialog.key(Keys.ESCAPE, false);
            button.setDisabled(!FontData.validate(textField.getText()));
            textField.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    boolean disable = !FontData.validate(textField.getText());
                    if (!disable) {
                        for (FontData data : main.getJsonData().getFonts()) {
                            if (data.getName().equals(textField.getText())) {
                                disable = true;
                                break;
                            }
                        }
                    }
                    button.setDisabled(disable);
                }
            });
            nameDialog.setColor(1.0f, 1.0f, 1.0f, 0.0f);
            textField.setFocusTraversal(false);
            if (!Utils.doesImageFitBox(new FileHandle(bitmapFontData.imagePaths[0]), maxTextureWidth, maxTextureHeight)) {
                showAddFontSizeError(fileHandle.nameWithoutExtension());
            } else {
                nameDialog.show(getStage());
                getStage().setKeyboardFocus(textField);
                textField.selectAll();
            }
        } catch (Exception e) {
            Gdx.app.error(getClass().getName(), "Error creating preview font from file", e);
            main.getDialogFactory().showDialogError("Preview Error...", "Error creating preview font from file. Check file paths.\n\nOpen log?");
        }
    } else {
        // after all fonts are processed
        if (main.getProjectData().areResourcesRelative()) {
            main.getProjectData().makeResourcesRelative();
        }
    }
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) BitmapFontData(com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData) FileHandle(com.badlogic.gdx.files.FileHandle) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) FontData(com.ray3k.skincomposer.data.FontData) BitmapFontData(com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) LabelStyle(com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle) 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) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 54 with ChangeListener

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

the class DialogFonts method refreshTable.

public void refreshTable() {
    fontsTable.clear();
    fontsTable.defaults().growX().pad(5.0f);
    if (fonts.size == 0 && freeTypeFonts.size == 0) {
        fontsTable.add(new Label("No fonts have been set!", getSkin()));
    } else {
        if (fonts.size > 0) {
            Label label = new Label("Bitmap Fonts", getSkin(), "required");
            label.setAlignment(Align.center);
            fontsTable.add(label);
            fontsTable.row();
        }
        for (FontData font : fonts) {
            Button button = new Button(getSkin(), "color-base");
            Label label = new Label(font.getName(), getSkin());
            label.setTouchable(Touchable.disabled);
            button.add(label).left();
            button.addListener(main.getHandListener());
            Button renameButton = new Button(getSkin(), "settings-small");
            renameButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    renameDialog(font);
                    event.setBubbles(false);
                }
            });
            renameButton.addListener(new InputListener() {

                @Override
                public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                    event.setBubbles(false);
                    return true;
                }
            });
            button.add(renameButton).padLeft(15.0f);
            TextTooltip toolTip = new TextTooltip("Rename Font", main.getTooltipManager(), getSkin());
            renameButton.addListener(toolTip);
            LabelStyle style = new LabelStyle();
            style.font = fontMap.get(font);
            style.fontColor = Color.WHITE;
            label = new Label("Lorem Ipsum", style);
            label.setAlignment(Align.center);
            label.setTouchable(Touchable.disabled);
            Table bg = new Table(getSkin());
            bg.setBackground("white");
            BitmapFontData bf = new BitmapFontData(font.file, false);
            if (bf.imagePaths.length > 0) {
                FileHandle file = new FileHandle(bf.imagePaths[0]);
                if (!file.exists()) {
                    file = bf.fontFile.sibling(bf.fontFile.nameWithoutExtension() + ".png");
                }
                if (Utils.brightness(Utils.averageEdgeColor(file)) < .5f) {
                    bg.setColor(Color.WHITE);
                } else {
                    bg.setColor(Color.BLACK);
                }
            }
            bg.add(label).pad(5.0f).grow();
            button.add(bg).padLeft(15).growX();
            Button closeButton = new Button(getSkin(), "delete-small");
            final FontData deleteFont = font;
            closeButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    fonts.removeValue(deleteFont, true);
                    main.getProjectData().setChangesSaved(false);
                    BitmapFontData bitmapFontData = new BitmapFontData(deleteFont.file, false);
                    for (String path : bitmapFontData.imagePaths) {
                        FileHandle imagefile = new FileHandle(path);
                        drawables.removeValue(new DrawableData(imagefile), false);
                    }
                    for (Array<StyleData> datas : main.getJsonData().getClassStyleMap().values()) {
                        for (StyleData data : datas) {
                            for (StyleProperty property : data.properties.values()) {
                                if (property != null && property.type.equals(BitmapFont.class) && property.value != null && property.value.equals(deleteFont.getName())) {
                                    property.value = null;
                                }
                            }
                        }
                    }
                    main.getUndoableManager().clearUndoables();
                    main.getRootTable().refreshStyleProperties(true);
                    main.getRootTable().refreshPreview();
                    event.setBubbles(false);
                    refreshTable();
                }
            });
            closeButton.addListener(new InputListener() {

                @Override
                public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                    event.setBubbles(false);
                    return true;
                }
            });
            button.add(closeButton).padLeft(5.0f).right();
            toolTip = new TextTooltip("Delete Font", main.getTooltipManager(), getSkin());
            closeButton.addListener(toolTip);
            if (styleProperty == null && customProperty == null) {
                button.setTouchable(Touchable.childrenOnly);
            } else {
                final FontData fontResult = font;
                button.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                        result(fontResult);
                        hide();
                    }
                });
            }
            fontsTable.add(button);
            fontsTable.row();
        }
        if (freeTypeFonts.size > 0) {
            Label label = new Label("FreeType Fonts", getSkin(), "required");
            label.setAlignment(Align.center);
            fontsTable.add(label).spaceTop(20.0f);
            fontsTable.row();
        }
        for (FreeTypeFontData font : freeTypeFonts) {
            Button button = new Button(getSkin(), "color-base");
            Label label = new Label(font.name, getSkin());
            label.setTouchable(Touchable.disabled);
            button.add(label).left();
            button.addListener(main.getHandListener());
            Button renameButton = new Button(getSkin(), "settings-small");
            renameButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    freeTypeSettingsDialog(font);
                    event.setBubbles(false);
                }
            });
            renameButton.addListener(new InputListener() {

                @Override
                public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                    event.setBubbles(false);
                    return true;
                }
            });
            button.add(renameButton).padLeft(15.0f);
            TextTooltip toolTip = new TextTooltip("Rename Font", main.getTooltipManager(), getSkin());
            renameButton.addListener(toolTip);
            LabelStyle style = new LabelStyle();
            style.font = font.bitmapFont;
            style.fontColor = Color.WHITE;
            label = new Label("Lorem Ipsum", style);
            label.setAlignment(Align.center);
            label.setTouchable(Touchable.disabled);
            Table bg = new Table(getSkin());
            bg.setBackground("white");
            bg.add(label).pad(5.0f).grow();
            button.add(bg).padLeft(15).growX();
            Button closeButton = new Button(getSkin(), "delete-small");
            final FreeTypeFontData deleteFont = font;
            closeButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    freeTypeFonts.removeValue(deleteFont, true);
                    main.getProjectData().setChangesSaved(false);
                    for (Array<StyleData> datas : main.getJsonData().getClassStyleMap().values()) {
                        for (StyleData data : datas) {
                            for (StyleProperty property : data.properties.values()) {
                                if (property != null && property.type.equals(BitmapFont.class) && property.value != null && property.value.equals(deleteFont.name)) {
                                    property.value = null;
                                }
                            }
                        }
                    }
                    main.getUndoableManager().clearUndoables();
                    main.getRootTable().refreshStyleProperties(true);
                    main.getRootTable().refreshPreview();
                    event.setBubbles(false);
                    refreshTable();
                }
            });
            closeButton.addListener(new InputListener() {

                @Override
                public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                    event.setBubbles(false);
                    return true;
                }
            });
            button.add(closeButton).padLeft(5.0f).right();
            toolTip = new TextTooltip("Delete Font", main.getTooltipManager(), getSkin());
            closeButton.addListener(toolTip);
            if (styleProperty == null && customProperty == null) {
                button.setTouchable(Touchable.childrenOnly);
            } else {
                final FreeTypeFontData fontResult = font;
                button.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                        result(fontResult);
                        hide();
                    }
                });
            }
            fontsTable.add(button);
            fontsTable.row();
        }
    }
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) BitmapFontData(com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData) FileHandle(com.badlogic.gdx.files.FileHandle) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) FontData(com.ray3k.skincomposer.data.FontData) BitmapFontData(com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) LabelStyle(com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle) Array(com.badlogic.gdx.utils.Array) StyleProperty(com.ray3k.skincomposer.data.StyleProperty) DrawableData(com.ray3k.skincomposer.data.DrawableData) TextTooltip(com.badlogic.gdx.scenes.scene2d.ui.TextTooltip) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) StyleData(com.ray3k.skincomposer.data.StyleData)

Example 55 with ChangeListener

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

the class DialogFreeTypeFont method showMoreInfoDialog.

private void showMoreInfoDialog() {
    Dialog dialog = new Dialog("Custom serializer for FreeType Fonts", skin, "bg");
    dialog.setFillParent(true);
    dialog.getTitleLabel().setAlignment(Align.center);
    dialog.getContentTable().pad(15.0f);
    dialog.getButtonTable().pad(15.0f);
    Label label = new Label("Integrating TTF files and specifying FreeType within a Skin JSON requires a custom serializer. This is done by overriding getJsonLoader(). See the example below:", skin);
    label.setWrap(true);
    dialog.getContentTable().add(label).growX();
    dialog.getContentTable().row();
    Image image = new Image(skin, "code-sample");
    image.setScaling(Scaling.fit);
    dialog.getContentTable().add(image);
    dialog.getContentTable().row();
    TextButton textButton = new TextButton("Copy sample code to clipboard", skin);
    dialog.getContentTable().add(textButton);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Gdx.app.getClipboard().setContents(SERIALIZER_TEXT);
        }
    });
    dialog.key(Keys.ENTER, true).key(Keys.ESCAPE, false);
    dialog.getButtonTable().defaults().minWidth(100.0f);
    dialog.button("OK", true);
    dialog.show(main.getStage());
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) Image(com.badlogic.gdx.scenes.scene2d.ui.Image)

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