Search in sources :

Example 31 with Spinner

use of com.ray3k.stripe.Spinner in project skin-composer by raeleus.

the class PopSettings method populate.

public void populate() {
    pad(10);
    defaults().space(15);
    var label = new Label("Settings", skin, "title");
    add(label);
    row();
    var table = new Table();
    add(table);
    table.defaults().growX().space(5);
    if (!Utils.isMac()) {
        var textButton = new TextButton("Open temp/log directory", skin);
        textButton.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                try {
                    Utils.openFileExplorer(Main.appFolder.child("temp/"));
                } catch (Exception e) {
                    Gdx.app.error(getClass().getName(), "Error opening temp folder", e);
                    dialogFactory.showDialogError("Folder Error...", "Error opening temp folder.\n\nOpen log?");
                }
            }
        });
        textButton.addListener(handListener);
        table.add(textButton);
        table.row();
        textButton = new TextButton("Open preferences directory", skin);
        textButton.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                try {
                    Utils.openFileExplorer(Gdx.files.external(".prefs/"));
                } catch (Exception e) {
                    Gdx.app.error(getClass().getName(), "Error opening preferences folder", e);
                    dialogFactory.showDialogError("Folder Error...", "Error opening preferences folder.\n\nOpen log?");
                }
            }
        });
        textButton.addListener(handListener);
        table.add(textButton);
        if (projectData.areChangesSaved() && projectData.getSaveFile().exists()) {
            table.row();
            textButton = new TextButton("Open project/import directory", skin);
            textButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    try {
                        Utils.openFileExplorer(projectData.getSaveFile().sibling(projectData.getSaveFile().nameWithoutExtension() + "_data"));
                    } catch (Exception e) {
                        Gdx.app.error(getClass().getName(), "Error opening project folder", e);
                        dialogFactory.showDialogError("Folder Error...", "Error opening project folder\n\nOpen log?");
                    }
                }
            });
            textButton.addListener(handListener);
            table.add(textButton);
        }
        table.row();
        textButton = new TextButton("Open texture packer settings file for export", skin);
        textButton.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                try {
                    Utils.openFileExplorer(Main.appFolder.child("texturepacker/atlas-export-settings.json"));
                } catch (Exception e) {
                    Gdx.app.error(getClass().getName(), "Error opening atlas-export-settings.json", e);
                    dialogFactory.showDialogError("File Error...", "Error opening atlas-export-settings.json\n\nOpen log?");
                }
            }
        });
        textButton.addListener(handListener);
        table.add(textButton);
        table.row();
        textButton = new TextButton("Open texture packer settings file for preview", skin);
        textButton.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                try {
                    Utils.openFileExplorer(Main.appFolder.child("texturepacker/atlas-internal-settings.json"));
                } catch (Exception e) {
                    Gdx.app.error(getClass().getName(), "Error opening atlas-internal-settings.json", e);
                    dialogFactory.showDialogError("File Error...", "Error opening atlas-internal-settings.json\n\nOpen log?");
                }
            }
        });
        textButton.addListener(handListener);
        table.add(textButton);
    }
    row();
    table = new Table();
    add(table);
    table.defaults().space(5);
    label = new Label("UI Scale:", skin);
    table.add(label);
    var slider = new Slider(1, 3, 1, false, skin);
    slider.setValue(uiScale);
    table.add(slider);
    slider.addListener(handListener);
    var scaleLabel = new Label(uiScale + "x", skin);
    table.add(scaleLabel).width(25);
    slider.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            uiScale = (int) slider.getValue();
            scaleLabel.setText(uiScale + "x");
            main.resizeUiScale(uiScale, uiScale > 1);
            changedUIscale = true;
        }
    });
    var textButton = new TextButton("Auto", skin);
    table.add(textButton);
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            var display = Gdx.graphics.getDisplayMode();
            uiScale = display.height >= 1440 ? 2 : 1;
            slider.setValue(uiScale);
            scaleLabel.setText(uiScale + "x");
            main.resizeUiScale(uiScale, uiScale > 1);
            changedUIscale = true;
        }
    });
    row();
    table = new Table();
    add(table);
    table.defaults().space(5);
    label = new Label("Max Number of Undos: ", skin);
    table.add(label);
    var spinner = new Spinner(projectData.getMaxUndos(), 1.0, true, Orientation.HORIZONTAL, getSkin());
    spinner.setMinimum(1.0);
    spinner.setMaximum(100.0);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            maxUndos = (int) spinner.getValue();
        }
    });
    spinner.addListener(new FocusListener() {

        @Override
        public void keyboardFocusChanged(FocusListener.FocusEvent event, Actor actor, boolean focused) {
            maxUndos = (int) spinner.getValue();
        }
    });
    spinner.getTextField().addListener(ibeamListener);
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    table.add(spinner).minWidth(100.0f);
    row();
    table = new Table();
    add(table);
    table.defaults().expandX().left().space(5);
    var relativeCheckBox = new ImageTextButton("Keep resources relative?", getSkin(), "checkbox");
    relativeCheckBox.setChecked(resourcesRelative);
    relativeCheckBox.addListener(handListener);
    relativeCheckBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            resourcesRelative = relativeCheckBox.isChecked();
        }
    });
    table.add(relativeCheckBox);
    table.row();
    var welcomeCheckBox = new ImageTextButton("Show welcome screen?", getSkin(), "checkbox");
    welcomeCheckBox.setChecked(allowingWelcome);
    welcomeCheckBox.addListener(handListener);
    welcomeCheckBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            allowingWelcome = welcomeCheckBox.isChecked();
        }
    });
    table.add(welcomeCheckBox);
    table.row();
    var exportWarningsCheckBox = new ImageTextButton("Show export warnings?", getSkin(), "checkbox");
    exportWarningsCheckBox.setChecked(exportWarnings);
    exportWarningsCheckBox.addListener(handListener);
    exportWarningsCheckBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            exportWarnings = exportWarningsCheckBox.isChecked();
        }
    });
    table.add(exportWarningsCheckBox);
    table.row();
    var fullPathCheckBox = new ImageTextButton("Show full path in recent files", getSkin(), "checkbox");
    fullPathCheckBox.setChecked(recentFullPath);
    fullPathCheckBox.addListener(handListener);
    fullPathCheckBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            recentFullPath = fullPathCheckBox.isChecked();
        }
    });
    table.add(fullPathCheckBox);
    table.row();
    var updatesCheckBox = new ImageTextButton("Check for updates?", getSkin(), "checkbox");
    updatesCheckBox.setChecked(allowingUpdates);
    updatesCheckBox.addListener(handListener);
    updatesCheckBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            allowingUpdates = updatesCheckBox.isChecked();
        }
    });
    table.add(updatesCheckBox);
    row();
    var buttonTable = new Table();
    buttonTable.pad(5);
    add(buttonTable);
    buttonTable.defaults().minWidth(75).space(5);
    textButton = new TextButton("OK", getSkin());
    textButton.addListener(handListener);
    buttonTable.add(textButton);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            approve();
        }
    });
    textButton = new TextButton("CANCEL", getSkin());
    textButton.addListener(handListener);
    buttonTable.add(textButton);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            cancel();
        }
    });
    key(Keys.ESCAPE, () -> {
        cancel();
    });
}
Also used : RootTable(com.ray3k.skincomposer.RootTable) PopTable(com.ray3k.stripe.PopTable) Spinner(com.ray3k.stripe.Spinner) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) FocusListener(com.badlogic.gdx.scenes.scene2d.utils.FocusListener)

Example 32 with Spinner

use of com.ray3k.stripe.Spinner in project skin-composer by raeleus.

the class DialogBitmapFont method loadSettings.

private void loadSettings(FileHandle fileHandle) {
    var fontSettings = json.fromJson(FontSettings.class, fileHandle.readString("utf-8"));
    ((TextField) findActor("characters")).setText(fontSettings.characters);
    data.characters = fontSettings.characters;
    ((Spinner) findActor("size")).setValue(fontSettings.size);
    data.size = fontSettings.size;
    ((Button) findActor("mono")).setChecked(fontSettings.mono);
    data.mono = fontSettings.mono;
    ((SelectBox<String>) findActor("hinting")).setSelected(fontSettings.hinting);
    data.hinting = fontSettings.hinting;
    if (fontSettings.color != null) {
        var color = jsonData.getColorByName(fontSettings.color);
        if (color == null) {
            try {
                color = new ColorData(fontSettings.color, new Color(fontSettings.colorValue));
            } catch (ColorData.NameFormatException ex) {
                Gdx.app.error(getClass().getName(), "Error creating color.", ex);
            }
            jsonData.getColors().add(color);
        }
        ((TextButton) findActor("colorTextButton")).setUserObject(color);
        data.color = fontSettings.color;
    }
    ((Spinner) findActor("gamma")).setValue(new BigDecimal(df.format(fontSettings.gamma)));
    data.gamma = fontSettings.gamma;
    ((Spinner) findActor("renderCount")).setValue(fontSettings.renderCount);
    data.renderCount = fontSettings.renderCount;
    ((Spinner) findActor("borderWidth")).setValue(fontSettings.borderWidth);
    data.borderWidth = fontSettings.borderWidth;
    if (fontSettings.borderColor != null) {
        var color = jsonData.getColorByName(fontSettings.borderColor);
        if (color == null) {
            try {
                color = new ColorData(fontSettings.borderColor, new Color(fontSettings.borderColorValue));
            } catch (ColorData.NameFormatException ex) {
                Gdx.app.error(getClass().getName(), "Error creating color.", ex);
            }
            jsonData.getColors().add(color);
        }
        ((TextButton) findActor("borderColorTextButton")).setUserObject(color);
        data.borderColor = fontSettings.borderColor;
    }
    ((Button) findActor("borderStraight")).setChecked(fontSettings.borderStraight);
    data.borderStraight = fontSettings.borderStraight;
    ((Spinner) findActor("borderGamma")).setValue(new BigDecimal(df.format(fontSettings.gamma)));
    data.borderGamma = fontSettings.borderGamma;
    ((Spinner) findActor("shadowOffsetX")).setValue(fontSettings.shadowOffsetX);
    data.shadowOffsetX = fontSettings.shadowOffsetX;
    ((Spinner) findActor("shadowOffsetY")).setValue(fontSettings.shadowOffsetY);
    data.shadowOffsetY = fontSettings.shadowOffsetY;
    if (fontSettings.shadowColor != null) {
        var color = jsonData.getColorByName(fontSettings.shadowColor);
        if (color == null) {
            try {
                color = new ColorData(fontSettings.shadowColor, new Color(fontSettings.shadowColorValue));
            } catch (ColorData.NameFormatException ex) {
                Gdx.app.error(getClass().getName(), "Error creating color.", ex);
            }
            jsonData.getColors().add(color);
        }
        ((TextButton) findActor("shadowColorTextButton")).setUserObject(color);
        data.shadowColor = fontSettings.shadowColor;
    }
    ((Button) findActor("incremental")).setChecked(fontSettings.incremental);
    data.incremental = fontSettings.incremental;
    ((Spinner) findActor("spaceX")).setValue(fontSettings.spaceX);
    data.spaceX = fontSettings.spaceX;
    ((Spinner) findActor("spaceY")).setValue(fontSettings.spaceY);
    data.spaceY = fontSettings.spaceY;
    ((Button) findActor("kerning")).setChecked(fontSettings.kerning);
    data.kerning = fontSettings.kerning;
    ((Button) findActor("flip")).setChecked(fontSettings.flip);
    data.flip = fontSettings.flip;
    ((Button) findActor("genMipMaps")).setChecked(fontSettings.genMipMaps);
    data.genMipMaps = fontSettings.genMipMaps;
    ((SelectBox<String>) findActor("minFilter")).setSelected(fontSettings.minFilter);
    data.minFilter = fontSettings.minFilter;
    ((SelectBox<String>) findActor("magFilter")).setSelected(fontSettings.magFilter);
    data.magFilter = fontSettings.magFilter;
    updateColors();
    updatePreviewAndOK();
}
Also used : ColorData(com.ray3k.skincomposer.data.ColorData) Spinner(com.ray3k.stripe.Spinner) Color(com.badlogic.gdx.graphics.Color) BigDecimal(java.math.BigDecimal)

Example 33 with Spinner

use of com.ray3k.stripe.Spinner in project skin-composer by raeleus.

the class DialogBitmapFont method populate.

private void populate() {
    root.pad(15.0f);
    Label label = new Label("Create a new Bitmap Font.", skin, "black");
    root.add(label);
    root.row();
    Image image = new Image(skin, "welcome-separator");
    image.setScaling(Scaling.stretch);
    root.add(image).growX().space(15.0f);
    root.row();
    previewTable = new Table();
    previewTable.setBackground(getSkin().getDrawable("white"));
    previewTable.setColor(Color.BLACK);
    root.add(previewTable).growX();
    var textField = new TextField(previewText, previewStyle);
    textField.setName("previewField");
    textField.setAlignment(Align.center);
    previewTable.add(textField).growX();
    textField.addListener(ibeamListener);
    textField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            previewText = ((TextField) actor).getText();
        }
    });
    root.row();
    var imageButton = new ImageButton(getSkin(), "color");
    root.add(imageButton).expandX().right();
    imageButton.addListener(handListener);
    imageButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            dialogFactory.showDialogColorPicker(previewBGcolor, new DialogColorPicker.ColorListener() {

                @Override
                public void selected(Color color) {
                    if (color != null) {
                        automaticBgColor = false;
                        previewBGcolor.set(color);
                        previewTable.setColor(color);
                    }
                }
            });
        }
    });
    var toolTip = new TextTooltip("Background color for preview text.", tooltipManager, getSkin());
    imageButton.addListener(toolTip);
    root.row();
    image = new Image(skin, "welcome-separator");
    image.setScaling(Scaling.stretch);
    root.add(image).growX().space(15.0f);
    root.row();
    Table bottom = new Table();
    ScrollPane scrollPane = new ScrollPane(bottom, skin);
    scrollPane.setName("scrollPane");
    scrollPane.setFadeScrollBars(false);
    scrollPane.setFlickScroll(false);
    root.add(scrollPane).padTop(10.0f).growX();
    bottom.defaults().space(5.0f);
    var table = new Table();
    bottom.add(table).growX().colspan(5).spaceBottom(15.0f);
    table.defaults().space(5.0f);
    label = new Label("Source Font Path:", skin);
    label.setName("source-label");
    table.add(label).right();
    var ltLabel = new LeadingTruncateLabel(data.file == null ? "" : data.file.path(), skin, "field");
    ltLabel.setName("sourceFileField");
    ltLabel.setEllipsis(true);
    table.add(ltLabel).growX().minWidth(0).prefWidth(0);
    ltLabel.addListener(handListener);
    ltLabel.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            event.getListenerActor().fire(new ChangeListener.ChangeEvent());
        }
    });
    var textButton = new TextButton("Browse...", skin);
    table.add(textButton).fillX();
    toolTip = new TextTooltip("Path to source Font file to be read", tooltipManager, getSkin());
    ltLabel.addListener(toolTip);
    textButton.addListener(toolTip);
    textButton.addListener(handListener);
    var sourceChangeListener = new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Runnable runnable = () -> {
                String defaultPath = projectData.getLastFontPath();
                String[] filterPatterns = null;
                if (!Utils.isMac()) {
                    filterPatterns = new String[] { "*.ttf", "*.otf" };
                }
                File file = desktopWorker.openDialog("Select Font file...", defaultPath, filterPatterns, "Font Files (*.TTF;*.OTF)");
                if (file != null) {
                    Gdx.app.postRunnable(() -> {
                        loadTTFsource(new FileHandle(file));
                    });
                }
            };
            dialogFactory.showDialogLoading(runnable);
        }
    };
    ltLabel.addListener(sourceChangeListener);
    textButton.addListener(sourceChangeListener);
    table.row();
    table.defaults().space(5.0f);
    label = new Label("Target FNT Path:", skin);
    label.setName("target-label");
    label.setEllipsis(true);
    table.add(label).right();
    ltLabel = new LeadingTruncateLabel(target == null ? "" : data.file.path(), skin, "field");
    ltLabel.setName("targetFileField");
    ltLabel.setEllipsis(true);
    table.add(ltLabel).growX().minWidth(0).prefWidth(0);
    ltLabel.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            event.getListenerActor().fire(new ChangeListener.ChangeEvent());
        }
    });
    textButton = new TextButton("Browse...", skin);
    table.add(textButton).fillX();
    toolTip = new TextTooltip("Path to target FNT file to be saved", tooltipManager, getSkin());
    ltLabel.addListener(toolTip);
    textButton.addListener(toolTip);
    ltLabel.addListener(handListener);
    textButton.addListener(handListener);
    var targetChangeListener = new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Runnable runnable = () -> {
                String defaultPath = projectData.getLastFontPath();
                String[] filterPatterns = null;
                if (!Utils.isMac()) {
                    filterPatterns = new String[] { "*.fnt" };
                }
                File file = desktopWorker.saveDialog("Select FNT file...", defaultPath, filterPatterns, "Bitmap Font files");
                if (file != null) {
                    Gdx.app.postRunnable(() -> {
                        target = new FileHandle(file);
                        if (!target.extension().equalsIgnoreCase("fnt")) {
                            target = target.sibling(target.name() + ".fnt");
                        }
                        var leadingTruncateLabel = (LeadingTruncateLabel) DialogBitmapFont.this.findActor("targetFileField");
                        leadingTruncateLabel.setText(target.path());
                        projectData.setLastFontPath(target.parent().path() + "/");
                        updatePreviewAndOK();
                    });
                }
            };
            dialogFactory.showDialogLoading(runnable);
        }
    };
    ltLabel.addListener(targetChangeListener);
    textButton.addListener(targetChangeListener);
    table.row();
    table.defaults().space(5.0f);
    label = new Label("Characters:", skin);
    table.add(label).right();
    final var charactersTextField = new TextField(data.characters, skin);
    charactersTextField.setName("characters");
    table.add(charactersTextField).growX();
    charactersTextField.addListener(ibeamListener);
    toolTip = new TextTooltip("The characters the font should contain. Leave blank for defaults.", tooltipManager, getSkin());
    charactersTextField.addListener(toolTip);
    var characterSelectBox = new SelectBox<String>(skin);
    characterSelectBox.setName("characterSelectBox");
    characterSelectBox.setItems("default", "0-9", "a-zA-Z", "a-zA-Z0-9", "custom", "Load from file (UTF-8)...");
    table.add(characterSelectBox).fillX();
    characterSelectBox.addListener(handListener);
    characterSelectBox.getList().addListener(handListener);
    toolTip = new TextTooltip("Character preset list", tooltipManager, getSkin());
    characterSelectBox.addListener(toolTip);
    characterSelectBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            switch(characterSelectBox.getSelected()) {
                case "default":
                    charactersTextField.setText("");
                    charactersTextField.setMessageText("");
                    data.characters = "";
                    break;
                case "0-9":
                    charactersTextField.setText("0123456789");
                    charactersTextField.setMessageText("");
                    data.characters = charactersTextField.getText();
                    break;
                case "a-zA-Z":
                    charactersTextField.setText("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
                    charactersTextField.setMessageText("");
                    data.characters = charactersTextField.getText();
                    break;
                case "a-zA-Z0-9":
                    charactersTextField.setText("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
                    charactersTextField.setMessageText("");
                    data.characters = charactersTextField.getText();
                    break;
                case "Load from file (UTF-8)...":
                    charactersTextField.setText("");
                    charactersTextField.setMessageText("Characters loaded from text file...");
                    data.characters = "";
                    showCharacterDialog();
                    break;
            }
            data.characters = !data.characters.equals("") && !data.characters.contains("\u0000") ? "\u0000" + data.characters : data.characters;
            updatePreviewAndOK();
        }
    });
    charactersTextField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            data.characters = charactersTextField.getText();
            data.characters = !data.characters.equals("") && !data.characters.contains("\u0000") ? "\u0000" + data.characters : data.characters;
            updatePreviewAndOK();
            if ("".equals(charactersTextField.getText())) {
                characterSelectBox.setSelected("default");
            } else {
                characterSelectBox.setSelected("custom");
            }
        }
    });
    bottom.row();
    label = new Label("Size:", skin);
    bottom.add(label).right();
    Spinner spinner = new Spinner(data.size, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("size");
    spinner.setMinimum(5);
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("The size in pixels", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.size = (int) spinner.getValue();
            updatePreviewAndOK();
        }
    });
    label = new Label("Mono:", skin);
    bottom.add(label).right();
    Button button = new Button(skin, "switch");
    button.setName("mono");
    button.setChecked(data.mono);
    bottom.add(button).left();
    toolTip = new TextTooltip("If on, font smoothing is disabled", tooltipManager, getSkin());
    button.addListener(toolTip);
    button.addListener(handListener);
    button.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.mono = button.isChecked();
            updatePreviewAndOK();
        }
    });
    bottom.add().growX();
    bottom.row();
    label = new Label("Hinting:", skin);
    bottom.add(label).right();
    var selectBox = new SelectBox<String>(skin);
    selectBox.setName("hinting");
    selectBox.setItems("None", "Slight", "Medium", "Full", "AutoSlight", "AutoMedium", "AutoFull");
    selectBox.setSelected(data.hinting);
    bottom.add(selectBox).left();
    toolTip = new TextTooltip("Strength of hinting", tooltipManager, getSkin());
    selectBox.addListener(toolTip);
    selectBox.addListener(handListener);
    selectBox.getList().addListener(handListener);
    selectBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            SelectBox<String> selectBox = (SelectBox) actor;
            data.hinting = selectBox.getSelected();
            updatePreviewAndOK();
        }
    });
    label = new Label("Color:", skin);
    label.setName("color-label");
    bottom.add(label).right();
    textButton = new TextButton(data.color, skin);
    textButton.setName("colorTextButton");
    image = new Image(skin, "icon-colorwheel-over");
    textButton.add(image).space(10.0f);
    bottom.add(textButton).left();
    toolTip = new TextTooltip("Foreground color (Required)", tooltipManager, getSkin());
    textButton.addListener(toolTip);
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            TextButton textButton = (TextButton) actor;
            dialogFactory.showDialogColors(new StyleProperty(), (colorData, pressedCancel) -> {
                if (colorData != null) {
                    textButton.setText(colorData.getName());
                    textButton.setUserObject(colorData);
                    data.color = colorData.getName();
                } else {
                    textButton.setText("");
                    textButton.setUserObject(null);
                    data.color = null;
                }
                updateColors();
                updatePreviewAndOK();
            }, null);
        }
    });
    bottom.row();
    label = new Label("Gamma:", skin);
    bottom.add(label).right();
    spinner = new Spinner(Double.parseDouble(df.format(data.gamma)), .1, false, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("gamma");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Glyph gamma. Values > 1 reduce antialiasing.", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.gamma = (float) spinner.getValue();
            updatePreviewAndOK();
        }
    });
    label = new Label("Render Count:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.renderCount, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("renderCount");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Number of times to render the glyph. Useful with a shadow or border, so it doesn't show through the glyph.", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.renderCount = (int) spinner.getValue();
            updatePreviewAndOK();
        }
    });
    bottom.row();
    label = new Label("Border Width:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.borderWidth, 1.0, false, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("borderWidth");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Border width in pixels, 0 to disable", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.borderWidth = (float) spinner.getValue();
            updatePreviewAndOK();
        }
    });
    label = new Label("Border Color:", skin);
    label.setName("border-color-label");
    bottom.add(label).right();
    textButton = new TextButton(data.borderColor, skin);
    textButton.setName("borderColorTextButton");
    image = new Image(skin, "icon-colorwheel-over");
    textButton.add(image).space(10.0f);
    bottom.add(textButton).left();
    toolTip = new TextTooltip("Border color; Required if borderWidth > 0", tooltipManager, getSkin());
    textButton.addListener(toolTip);
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            TextButton textButton = (TextButton) actor;
            dialogFactory.showDialogColors(new StyleProperty(), (colorData, pressedCancel) -> {
                if (colorData != null) {
                    textButton.setText(colorData.getName());
                    textButton.setUserObject(colorData);
                    data.borderColor = colorData.getName();
                } else {
                    textButton.setText("");
                    textButton.setUserObject(null);
                    data.borderColor = null;
                }
                updateColors();
                updatePreviewAndOK();
            }, null);
        }
    });
    bottom.row();
    label = new Label("Border Straight:", skin);
    bottom.add(label).right();
    button = new Button(skin, "switch");
    button.setName("borderStraight");
    button.setChecked(data.borderStraight);
    bottom.add(button).left();
    toolTip = new TextTooltip("On for straight (mitered), off for rounded borders", tooltipManager, getSkin());
    button.addListener(toolTip);
    button.addListener(handListener);
    button.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.borderStraight = button.isChecked();
            updatePreviewAndOK();
        }
    });
    label = new Label("Border Gamma:", skin);
    bottom.add(label).right();
    spinner = new Spinner(Double.parseDouble(df.format(data.borderGamma)), 1.0, false, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("borderGamma");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Values < 1 increase the border size.", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.borderGamma = (float) spinner.getValue();
            updatePreviewAndOK();
        }
    });
    bottom.row();
    label = new Label("Shadow Offset X:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.shadowOffsetX, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("shadowOffsetX");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Offset of text shadow on X axis in pixels, 0 to disable", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.shadowOffsetX = (int) spinner.getValue();
            updatePreviewAndOK();
        }
    });
    label = new Label("Shadow Offset Y:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.shadowOffsetY, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("shadowOffsetY");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Offset of text shadow on Y axis in pixels, 0 to disable", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.shadowOffsetY = (int) spinner.getValue();
            updatePreviewAndOK();
        }
    });
    bottom.row();
    label = new Label("Shadow Color:", skin);
    label.setName("shadow-color-label");
    bottom.add(label).right();
    textButton = new TextButton(data.shadowColor, skin);
    textButton.setName("shadowColorTextButton");
    image = new Image(skin, "icon-colorwheel-over");
    textButton.add(image).space(10.0f);
    bottom.add(textButton).left();
    toolTip = new TextTooltip("Shadow color; required if shadowOffset > 0.", tooltipManager, getSkin());
    textButton.addListener(toolTip);
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            TextButton textButton = (TextButton) actor;
            dialogFactory.showDialogColors(new StyleProperty(), (colorData, pressedCancel) -> {
                if (colorData != null) {
                    textButton.setText(colorData.getName());
                    textButton.setUserObject(colorData);
                    data.shadowColor = colorData.getName();
                } else {
                    textButton.setText("");
                    textButton.setUserObject(null);
                    data.shadowColor = null;
                }
                updateColors();
                updatePreviewAndOK();
            }, null);
        }
    });
    label = new Label("Incremental:", skin);
    bottom.add(label).right();
    button = new Button(skin, "switch");
    button.setName("incremental");
    button.setChecked(data.incremental);
    bottom.add(button).left();
    toolTip = new TextTooltip("When true, glyphs are rendered on the fly to the \n" + "font's glyph page textures as they are needed.", tooltipManager, getSkin());
    button.addListener(toolTip);
    button.addListener(handListener);
    button.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.incremental = button.isChecked();
            updatePreviewAndOK();
        }
    });
    bottom.row();
    label = new Label("Space X:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.spaceX, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("spaceX");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Pixels to add to glyph spacing. Can be negative.", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.spaceX = (int) spinner.getValue();
            updatePreviewAndOK();
        }
    });
    label = new Label("Space Y:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.spaceY, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("spaceY");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Pixels to add to glyph spacing. Can be negative.", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.spaceY = (int) spinner.getValue();
            updatePreviewAndOK();
        }
    });
    bottom.row();
    label = new Label("Kerning:", skin);
    bottom.add(label).right();
    button = new Button(skin, "switch");
    button.setName("kerning");
    button.setChecked(data.kerning);
    bottom.add(button).left();
    toolTip = new TextTooltip("Whether the font should include kerning", tooltipManager, getSkin());
    button.addListener(toolTip);
    button.addListener(handListener);
    button.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.kerning = button.isChecked();
            updatePreviewAndOK();
        }
    });
    bottom.row();
    label = new Label("Flip:", skin);
    bottom.add(label).right();
    button = new Button(skin, "switch");
    button.setName("flip");
    button.setChecked(data.flip);
    bottom.add(button).left();
    toolTip = new TextTooltip("Whether to flip the font vertically", tooltipManager, getSkin());
    button.addListener(toolTip);
    button.addListener(handListener);
    button.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.flip = button.isChecked();
            updatePreviewAndOK();
        }
    });
    label = new Label("GenMipMaps:", skin);
    bottom.add(label).right();
    button = new Button(skin, "switch");
    button.setName("genMipMaps");
    button.setChecked(data.genMipMaps);
    bottom.add(button).left();
    toolTip = new TextTooltip("Whether to generate mip maps for the resulting texture", tooltipManager, getSkin());
    button.addListener(toolTip);
    button.addListener(handListener);
    button.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.genMipMaps = button.isChecked();
            updatePreviewAndOK();
        }
    });
    bottom.row();
    label = new Label("Min Filter:", skin);
    bottom.add(label).right();
    selectBox = new SelectBox<>(skin);
    selectBox.setName("minFilter");
    selectBox.setItems("Nearest", "Linear", "MipMap", "MipMapNearestNearest", "MipMapLinearNearest", "MipMapNearestLinear", "MipMapLinearLinear");
    selectBox.setSelected(data.minFilter);
    bottom.add(selectBox).left();
    toolTip = new TextTooltip("Minification filter", tooltipManager, getSkin());
    selectBox.addListener(toolTip);
    selectBox.addListener(handListener);
    selectBox.getList().addListener(handListener);
    selectBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            SelectBox<String> selectBox = (SelectBox) actor;
            data.minFilter = selectBox.getSelected();
            updatePreviewAndOK();
        }
    });
    label = new Label("Mag Filter:", skin);
    bottom.add(label).right();
    selectBox = new SelectBox<>(skin);
    selectBox.setName("magFilter");
    selectBox.setItems("Nearest", "Linear", "MipMap", "MipMapNearestNearest", "MipMapLinearNearest", "MipMapNearestLinear", "MipMapLinearLinear");
    selectBox.setSelected(data.magFilter);
    bottom.add(selectBox).left();
    toolTip = new TextTooltip("Magnification filter", tooltipManager, getSkin());
    selectBox.addListener(toolTip);
    selectBox.addListener(handListener);
    selectBox.getList().addListener(handListener);
    selectBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            SelectBox<String> selectBox = (SelectBox) actor;
            data.magFilter = selectBox.getSelected();
            updatePreviewAndOK();
        }
    });
    buttons.pad(10.0f);
    buttons.defaults().minWidth(75.0f).space(25.0f);
    textButton = new TextButton("Generate Font", skin);
    textButton.setName("okButton");
    textButton.addListener(handListener);
    button(textButton, ButtonType.GENERATE);
    textButton = new TextButton("Save Settings", skin);
    textButton.setName("saveButton");
    textButton.addListener(handListener);
    getButtonTable().add(textButton);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            result(ButtonType.SAVE_SETTINGS);
        }
    });
    textButton = new TextButton("Load Settings", skin);
    textButton.setName("loadButton");
    textButton.addListener(handListener);
    getButtonTable().add(textButton);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            result(ButtonType.LOAD_SETTINGS);
        }
    });
    textButton = new TextButton("Cancel", skin);
    textButton.setName("cancelButton");
    textButton.addListener(handListener);
    button(textButton, ButtonType.CANCEL);
    updateLabelHighlight(null);
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) MathUtils(com.badlogic.gdx.math.MathUtils) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) DecimalFormatSymbols(java.text.DecimalFormatSymbols) Utils(com.ray3k.skincomposer.utils.Utils) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) Spinner(com.ray3k.stripe.Spinner) Gdx(com.badlogic.gdx.Gdx) BigDecimal(java.math.BigDecimal) com.badlogic.gdx.utils(com.badlogic.gdx.utils) LeadingTruncateLabel(com.ray3k.skincomposer.LeadingTruncateLabel) Locale(java.util.Locale) TextFieldStyle(com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldStyle) com.badlogic.gdx.scenes.scene2d.ui(com.badlogic.gdx.scenes.scene2d.ui) DecimalFormat(java.text.DecimalFormat) ColorData(com.ray3k.skincomposer.data.ColorData) FilesDroppedListener(com.ray3k.skincomposer.FilesDroppedListener) Group(com.badlogic.gdx.scenes.scene2d.Group) Color(com.badlogic.gdx.graphics.Color) Actor(com.badlogic.gdx.scenes.scene2d.Actor) com.badlogic.gdx.scenes.scene2d.utils(com.badlogic.gdx.scenes.scene2d.utils) File(java.io.File) Keys(com.badlogic.gdx.Input.Keys) Main(com.ray3k.skincomposer.Main) LabelStyle(com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle) StyleProperty(com.ray3k.skincomposer.data.StyleProperty) FileHandle(com.badlogic.gdx.files.FileHandle) Spinner(com.ray3k.stripe.Spinner) LeadingTruncateLabel(com.ray3k.skincomposer.LeadingTruncateLabel) LeadingTruncateLabel(com.ray3k.skincomposer.LeadingTruncateLabel) Actor(com.badlogic.gdx.scenes.scene2d.Actor) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) Color(com.badlogic.gdx.graphics.Color) StyleProperty(com.ray3k.skincomposer.data.StyleProperty) File(java.io.File)

Example 34 with Spinner

use of com.ray3k.stripe.Spinner in project skin-composer by raeleus.

the class DialogDrawables method tintedDrawableSettingsDialog.

private void tintedDrawableSettingsDialog(DrawableData drawable) {
    TextField textField = new TextField("", getSkin());
    var dialog = new Dialog("Rename drawable?", getSkin(), "bg") {

        @Override
        protected void result(Object object) {
            super.result(object);
            if (object instanceof Boolean && (boolean) object == true) {
                applyTintedDrawableSettings(drawable, textField.getText());
                drawable.minWidth = ((Spinner) findActor("minWidth")).getValueAsInt();
                drawable.minHeight = ((Spinner) findActor("minHeight")).getValueAsInt();
                atlasData.produceAtlas();
                refreshDrawableDisplay();
            }
            getStage().setScrollFocus(scrollPane);
        }

        public void callResult(Object object) {
            result(object);
        }

        @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.addListener(handListener);
    dialog.getButtonTable().getCells().get(1).getActor().addListener(handListener);
    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()) || (checkIfNameExists(textField.getText()) && !drawable.name.equals(textField.getText()));
            okButton.setDisabled(disable);
        }
    });
    textField.setTextFieldListener((TextField textField1, char c) -> {
        if (c == '\n') {
            if (!okButton.isDisabled()) {
                dialog.callResult(true);
                dialog.hide();
            }
        }
    });
    textField.addListener(ibeamListener);
    dialog.getContentTable().add(textField);
    dialog.getContentTable().row();
    var table = new Table();
    dialog.getContentTable().add(table);
    table.defaults().space(3);
    var label = new Label("Set values to -1 to disable.", getSkin());
    table.add(label).colspan(2).padTop(7);
    table.row();
    label = new Label("minWidth:", getSkin());
    table.add(label);
    var spinner = new Spinner(drawable.minWidth, 1, true, Spinner.Orientation.HORIZONTAL, getSkin());
    spinner.setMinimum(-1);
    spinner.setName("minWidth");
    table.add(spinner).width(100);
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    table.row();
    label = new Label("minHeight:", getSkin());
    table.add(label);
    spinner = new Spinner(drawable.minHeight, 1, true, Spinner.Orientation.HORIZONTAL, getSkin());
    spinner.setMinimum(-1);
    spinner.setName("minHeight");
    table.add(spinner).width(100);
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    textField.setFocusTraversal(false);
    dialog.show(getStage());
}
Also used : Spinner(com.ray3k.stripe.Spinner)

Example 35 with Spinner

use of com.ray3k.stripe.Spinner in project skin-composer by raeleus.

the class DialogFactory method showPixelDrawableDialog.

public void showPixelDrawableDialog(Skin skin, Stage stage, DrawableData modifyDrawable, PixelDrawableListener pixelDrawableListener) {
    final var textField = new TextField("", skin);
    final var imageButtonStyle = new ImageButtonStyle(skin.get("default", ImageButtonStyle.class));
    imageButtonStyle.imageUp = skin.newDrawable("white");
    imageButtonStyle.imageUp.setMinWidth(25);
    imageButtonStyle.imageUp.setMinHeight(25);
    var imageButton = new ImageButton(imageButtonStyle);
    if (modifyDrawable == null) {
        imageButton.getImage().setColor(new Color(1, 1, 1, 0));
    } else {
        var colorData = jsonData.getColorByName(modifyDrawable.tintName);
        imageButton.getImage().setColor(colorData.color);
        imageButton.setUserObject(colorData);
    }
    var widthSpinner = new Spinner(modifyDrawable == null ? -1 : modifyDrawable.minWidth, 1, true, Orientation.HORIZONTAL, skin);
    var heightSpinner = new Spinner(modifyDrawable == null ? -1 : modifyDrawable.minHeight, 1, true, Orientation.HORIZONTAL, skin);
    Dialog dialog = new Dialog("New Pixel Drawable", skin, "bg") {

        @Override
        protected void result(Object object) {
            if ((Boolean) object) {
                pixelDrawableListener.run(textField.getText(), (ColorData) imageButton.getUserObject(), widthSpinner.getValueAsInt(), heightSpinner.getValueAsInt());
            }
        }
    };
    dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
    var okButton = new TextButton("OK", skin);
    dialog.button(okButton, true);
    okButton.addListener(handListener);
    var textButton = new TextButton("Cancel", skin);
    dialog.button(textButton, false);
    textButton.addListener(handListener);
    textField.setTextFieldListener((TextField textField1, char c) -> {
        if (c == '\n') {
            if (!okButton.isDisabled()) {
                pixelDrawableListener.run(textField.getText(), (ColorData) imageButton.getUserObject(), widthSpinner.getValueAsInt(), heightSpinner.getValueAsInt());
                dialog.hide();
            }
            stage.setKeyboardFocus(textField1);
        }
    });
    textField.addListener(ibeamListener);
    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("Create a 1x1 pixel texture region with the selected tint.\nEnter the name for the pixel drawable.");
    } else {
        dialog.text("Enter the new name for the pixel 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();
    dialog.getContentTable().row();
    var label = new Label("Choose a tint color:", skin);
    dialog.text(label);
    dialog.getContentTable().row();
    dialog.getContentTable().add(imageButton);
    imageButton.addListener(handListener);
    imageButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            dialogFactory.showDialogColors(new StyleProperty(), (colorData, cancelled) -> {
                if (!cancelled) {
                    imageButton.setUserObject(colorData);
                    imageButton.getImage().setColor(colorData.color);
                    boolean disable = !StyleData.validate(textField.getText());
                    if (modifyDrawable != null && textField.getText().equals(modifyDrawable.name))
                        disable = false;
                    var foundDrawable = atlasData.getDrawable(textField.getText());
                    if (foundDrawable != null && foundDrawable != modifyDrawable)
                        disable = true;
                    if (imageButton.getUserObject() == null)
                        disable = true;
                    okButton.setDisabled(disable);
                }
            }, new DialogListener() {

                @Override
                public void opened() {
                }

                @Override
                public void closed() {
                }
            });
        }
    });
    dialog.getContentTable().row();
    var subTable = new Table();
    dialog.getContentTable().add(subTable);
    subTable.defaults().space(2);
    label = new Label("Min Width:", skin);
    subTable.add(label);
    widthSpinner.setMinimum(-1);
    subTable.add(widthSpinner).width(100).spaceRight(15);
    widthSpinner.getButtonMinus().addListener(handListener);
    widthSpinner.getTextField().addListener(ibeamListener);
    widthSpinner.getButtonPlus().addListener(handListener);
    label = new Label("Min Height:", skin);
    subTable.add(label);
    heightSpinner.setMinimum(-1);
    subTable.add(heightSpinner).width(100).spaceRight(5);
    heightSpinner.getButtonMinus().addListener(handListener);
    heightSpinner.getTextField().addListener(ibeamListener);
    heightSpinner.getButtonPlus().addListener(handListener);
    okButton.setDisabled(modifyDrawable == null);
    textField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            boolean disable = !StyleData.validate(textField.getText());
            if (modifyDrawable != null && textField.getText().equals(modifyDrawable.name))
                disable = false;
            var foundDrawable = atlasData.getDrawable(textField.getText());
            if (foundDrawable != null && foundDrawable != modifyDrawable)
                disable = true;
            if (imageButton.getUserObject() == 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 : DialogBitmapFontListener(com.ray3k.skincomposer.dialog.DialogBitmapFont.DialogBitmapFontListener) Array(com.badlogic.gdx.utils.Array) Action(com.badlogic.gdx.scenes.scene2d.Action) Scaling(com.badlogic.gdx.utils.Scaling) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) Spinner(com.ray3k.stripe.Spinner) Gdx(com.badlogic.gdx.Gdx) DialogFreeTypeFontListener(com.ray3k.skincomposer.dialog.DialogFreeTypeFont.DialogFreeTypeFontListener) com.ray3k.skincomposer.data(com.ray3k.skincomposer.data) CustomClassListener(com.ray3k.skincomposer.dialog.DialogCustomClass.CustomClassListener) ImageButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.ImageButton.ImageButtonStyle) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) NewStyleUndoable(com.ray3k.skincomposer.UndoableManager.NewStyleUndoable) DialogDrawablesListener(com.ray3k.skincomposer.dialog.DialogDrawables.DialogDrawablesListener) ImageFontListener(com.ray3k.skincomposer.dialog.DialogImageFont.ImageFontListener) Actions(com.badlogic.gdx.scenes.scene2d.actions.Actions) Input(com.badlogic.gdx.Input) Stage(com.badlogic.gdx.scenes.scene2d.Stage) UndoableManager(com.ray3k.skincomposer.UndoableManager) DuplicateStyleUndoable(com.ray3k.skincomposer.UndoableManager.DuplicateStyleUndoable) PropertyType(com.ray3k.skincomposer.data.CustomProperty.PropertyType) com.badlogic.gdx.scenes.scene2d.ui(com.badlogic.gdx.scenes.scene2d.ui) DialogSceneComposer(com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposer) DialogColorsListener(com.ray3k.skincomposer.dialog.DialogColors.DialogColorsListener) Dialog9PatchListener(com.ray3k.skincomposer.dialog.Dialog9Patch.Dialog9PatchListener) DeleteStyleUndoable(com.ray3k.skincomposer.UndoableManager.DeleteStyleUndoable) Align(com.badlogic.gdx.utils.Align) Color(com.badlogic.gdx.graphics.Color) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.Button.ButtonStyle) PopTable(com.ray3k.stripe.PopTable) WelcomeListener(com.ray3k.skincomposer.dialog.PopWelcome.WelcomeListener) CustomStylePropertyListener(com.ray3k.skincomposer.dialog.DialogCustomProperty.CustomStylePropertyListener) Keys(com.badlogic.gdx.Input.Keys) Main(com.ray3k.skincomposer.Main) ObjectMap(com.badlogic.gdx.utils.ObjectMap) DialogTenPatchListener(com.ray3k.skincomposer.dialog.DialogTenPatch.DialogTenPatchListener) Orientation(com.ray3k.stripe.Spinner.Orientation) EventListener(com.badlogic.gdx.scenes.scene2d.EventListener) CustomStyleListener(com.ray3k.skincomposer.dialog.DialogCustomStyle.CustomStyleListener) PopTable(com.ray3k.stripe.PopTable) Spinner(com.ray3k.stripe.Spinner) Color(com.badlogic.gdx.graphics.Color) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ImageButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.ImageButton.ImageButtonStyle) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Aggregations

Spinner (com.ray3k.stripe.Spinner)43 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)34 Actor (com.badlogic.gdx.scenes.scene2d.Actor)29 PopTableClickListener (com.ray3k.stripe.PopTableClickListener)29 SimActor (com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerModel.SimActor)28 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)27 StyleSelectorPopTable (com.ray3k.skincomposer.dialog.scenecomposer.StyleSelectorPopTable)12 Color (com.badlogic.gdx.graphics.Color)11 PopTable (com.ray3k.stripe.PopTable)11 Keys (com.badlogic.gdx.Input.Keys)8 com.badlogic.gdx.scenes.scene2d.ui (com.badlogic.gdx.scenes.scene2d.ui)8 Main (com.ray3k.skincomposer.Main)8 Gdx (com.badlogic.gdx.Gdx)6 File (java.io.File)6 FileHandle (com.badlogic.gdx.files.FileHandle)5 MathUtils (com.badlogic.gdx.math.MathUtils)5 FilesDroppedListener (com.ray3k.skincomposer.FilesDroppedListener)5 Utils (com.ray3k.skincomposer.utils.Utils)5 Input (com.badlogic.gdx.Input)4 Pixmap (com.badlogic.gdx.graphics.Pixmap)4