Search in sources :

Example 6 with DrawableData

use of com.ray3k.skincomposer.data.DrawableData in project skin-composer by raeleus.

the class DialogDrawables method tiledDrawableSettingsDialog.

private void tiledDrawableSettingsDialog(DrawableData drawable) {
    DialogColors dialog = new DialogColors(main, (StyleProperty) null, true, (ColorData colorData) -> {
        if (colorData != null) {
            final Spinner minWidthSpinner = new Spinner(0.0f, 1.0f, true, Spinner.Orientation.HORIZONTAL, getSkin());
            final Spinner minHeightSpinner = new Spinner(0.0f, 1.0f, true, Spinner.Orientation.HORIZONTAL, getSkin());
            TextField textField = new TextField("", getSkin()) {

                @Override
                public void next(boolean up) {
                    if (up) {
                        getStage().setKeyboardFocus(minHeightSpinner.getTextField());
                        minHeightSpinner.getTextField().selectAll();
                    } else {
                        getStage().setKeyboardFocus(minWidthSpinner.getTextField());
                        minWidthSpinner.getTextField().selectAll();
                    }
                }
            };
            Dialog tileDialog = new Dialog("Tiled Drawable Settings", getSkin(), "bg") {

                @Override
                protected void result(Object object) {
                    super.result(object);
                    if (object instanceof Boolean && (boolean) object == true) {
                        tiledDrawableSettings(drawable, colorData, (float) minWidthSpinner.getValue(), (float) minHeightSpinner.getValue(), textField.getText());
                    }
                    getStage().setScrollFocus(scrollPane);
                }

                @Override
                public Dialog show(Stage stage) {
                    Dialog dialog = super.show(stage);
                    stage.setKeyboardFocus(textField);
                    return dialog;
                }
            };
            tileDialog.getTitleTable().padLeft(5.0f);
            tileDialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f);
            tileDialog.getButtonTable().padBottom(15.0f);
            tileDialog.getContentTable().add(new Label("Please enter a name for the TiledDrawable: ", getSkin()));
            tileDialog.button("OK", true);
            tileDialog.button("Cancel", false).key(Keys.ESCAPE, false);
            TextButton okButton = (TextButton) tileDialog.getButtonTable().getCells().first().getActor();
            okButton.addListener(main.getHandListener());
            tileDialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
            tileDialog.getContentTable().row();
            textField.setText(drawable.name);
            textField.selectAll();
            tileDialog.getContentTable().add(textField);
            tileDialog.getContentTable().row();
            Table table = new Table();
            table.defaults().space(10.0f);
            tileDialog.getContentTable().add(table);
            Label label = new Label("MinWidth:", getSkin());
            table.add(label);
            minWidthSpinner.setValue(drawable.minWidth);
            minWidthSpinner.setMinimum(0.0f);
            table.add(minWidthSpinner).minWidth(150.0f);
            minWidthSpinner.setTransversalPrevious(textField);
            minWidthSpinner.setTransversalNext(minHeightSpinner.getTextField());
            table.row();
            label = new Label("MinHeight:", getSkin());
            table.add(label);
            minHeightSpinner.setValue(drawable.minHeight);
            minHeightSpinner.setMinimum(0.0f);
            table.add(minHeightSpinner).minWidth(150.0f);
            minHeightSpinner.setTransversalPrevious(minWidthSpinner.getTextField());
            minHeightSpinner.setTransversalNext(textField);
            textField.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    boolean disable = !DrawableData.validate(textField.getText());
                    if (!disable) {
                        if (!drawable.name.equals(textField.getText())) {
                            for (DrawableData data : main.getAtlasData().getDrawables()) {
                                if (data.name.equals(textField.getText())) {
                                    disable = true;
                                    break;
                                }
                            }
                        }
                    }
                    okButton.setDisabled(disable);
                }
            });
            textField.setTextFieldListener(new TextField.TextFieldListener() {

                @Override
                public void keyTyped(TextField textField, char c) {
                    if (c == '\n') {
                        if (!okButton.isDisabled()) {
                            tiledDrawableSettings(drawable, colorData, (float) minWidthSpinner.getValue(), (float) minHeightSpinner.getValue(), textField.getText());
                            tileDialog.hide();
                        }
                    }
                }
            });
            textField.addListener(main.getIbeamListener());
            tileDialog.show(getStage());
        }
    });
    dialog.setFillParent(true);
    dialog.show(getStage());
    dialog.refreshTable();
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Spinner(com.ray3k.skincomposer.Spinner) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) ColorData(com.ray3k.skincomposer.data.ColorData) DrawableData(com.ray3k.skincomposer.data.DrawableData) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Stage(com.badlogic.gdx.scenes.scene2d.Stage) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Example 7 with DrawableData

use of com.ray3k.skincomposer.data.DrawableData in project skin-composer by raeleus.

the class DialogDrawables method produceAtlas.

/**
 * Writes a TextureAtlas based on drawables list. Creates drawables to be
 * displayed on screen
 * @return
 */
private boolean produceAtlas() {
    try {
        if (atlas != null) {
            atlas.dispose();
            atlas = null;
        }
        if (!main.getAtlasData().atlasCurrent) {
            main.getAtlasData().writeAtlas();
            main.getAtlasData().atlasCurrent = true;
        }
        atlas = main.getAtlasData().getAtlas();
        for (DrawableData data : main.getAtlasData().getDrawables()) {
            Drawable drawable;
            if (data.customized) {
                drawable = getSkin().getDrawable("custom-drawable-skincomposer-image");
            } else if (data.tiled) {
                String name = data.file.name();
                name = DrawableData.proper(name);
                drawable = new TiledDrawable(atlas.findRegion(name));
                drawable.setMinWidth(data.minWidth);
                drawable.setMinHeight(data.minHeight);
                ((TiledDrawable) drawable).getColor().set(main.getJsonData().getColorByName(data.tintName).color);
            } else if (data.file.name().matches(".*\\.9\\.[a-zA-Z0-9]*$")) {
                String name = data.file.name();
                name = DrawableData.proper(name);
                drawable = new NinePatchDrawable(atlas.createPatch(name));
                if (data.tint != null) {
                    drawable = ((NinePatchDrawable) drawable).tint(data.tint);
                } else if (data.tintName != null) {
                    drawable = ((NinePatchDrawable) drawable).tint(main.getJsonData().getColorByName(data.tintName).color);
                }
            } else {
                String name = data.file.name();
                name = DrawableData.proper(name);
                drawable = new SpriteDrawable(atlas.createSprite(name));
                if (data.tint != null) {
                    drawable = ((SpriteDrawable) drawable).tint(data.tint);
                } else if (data.tintName != null) {
                    drawable = ((SpriteDrawable) drawable).tint(main.getJsonData().getColorByName(data.tintName).color);
                }
            }
            drawablePairs.put(data, drawable);
        }
        return true;
    } catch (Exception e) {
        Gdx.app.error(getClass().getName(), "Error while attempting to generate drawables.", e);
        main.getDialogFactory().showDialogError("Atlas Error...", "Error while attempting to generate drawables.\n\nOpen log?");
        return false;
    }
}
Also used : SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) DrawableData(com.ray3k.skincomposer.data.DrawableData) TiledDrawable(com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable) TiledDrawable(com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)

Example 8 with DrawableData

use of com.ray3k.skincomposer.data.DrawableData in project skin-composer by raeleus.

the class DialogDrawables method refreshDrawableDisplay.

private void refreshDrawableDisplay() {
    contentGroup.clear();
    if (drawables.size == 0) {
        Label label = new Label("No drawables have been added!", getSkin());
        contentGroup.addActor(label);
    }
    for (DrawableData drawable : drawables) {
        Button drawableButton;
        if (property != null || customProperty != null) {
            drawableButton = new Button(getSkin(), "color-base");
            drawableButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    result(drawable);
                    hide();
                }
            });
            drawableButton.addListener(main.getHandListener());
        } else {
            drawableButton = new Button(getSkin(), "color-base-static");
        }
        contentGroup.addActor(drawableButton);
        Table table = new Table();
        drawableButton.add(table).width(sizes[MathUtils.floor(zoomSlider.getValue())]).height(sizes[MathUtils.floor(zoomSlider.getValue())]);
        ClickListener fixDuplicateTouchListener = new ClickListener() {

            @Override
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                event.setBubbles(false);
                return super.touchDown(event, x, y, pointer, button);
            }
        };
        // color wheel
        if (!drawable.customized && !drawable.tiled) {
            Button button = new Button(getSkin(), "colorwheel");
            button.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    newTintedDrawable(drawable);
                    event.setBubbles(false);
                }
            });
            button.addListener(fixDuplicateTouchListener);
            if (property == null && customProperty == null) {
                button.addListener(main.getHandListener());
            }
            table.add(button);
            TextTooltip toolTip = new TextTooltip("New Tinted Drawable", main.getTooltipManager(), getSkin());
            button.addListener(toolTip);
        } else {
            table.add();
        }
        // swatches
        if (!drawable.customized && !drawable.tiled) {
            Button button = new Button(getSkin(), "swatches");
            button.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    colorSwatchesDialog(drawable);
                    event.setBubbles(false);
                }
            });
            button.addListener(fixDuplicateTouchListener);
            if (property == null && customProperty == null) {
                button.addListener(main.getHandListener());
            }
            table.add(button);
            TextTooltip toolTip = new TextTooltip("Tinted Drawable from Colors", main.getTooltipManager(), getSkin());
            button.addListener(toolTip);
        } else {
            table.add();
        }
        // tiles button (NOT FOR TINTS OR CUSTOM DRAWABLES)
        if (!drawable.customized && drawable.tint == null && drawable.tintName == null) {
            ;
            Button button = new Button(getSkin(), "tiles");
            button.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    tiledDrawableDialog(drawable);
                    event.setBubbles(false);
                }
            });
            button.addListener(fixDuplicateTouchListener);
            if (property == null && customProperty == null) {
                button.addListener(main.getHandListener());
            }
            table.add(button);
            TextTooltip toolTip = new TextTooltip("Tiled Drawable", main.getTooltipManager(), getSkin());
            button.addListener(toolTip);
        } else {
            table.add();
        }
        // tiled settings
        if (drawable.tiled) {
            Button button = new Button(getSkin(), "settings-small");
            button.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    tiledDrawableSettingsDialog(drawable);
                    event.setBubbles(false);
                }
            });
            button.addListener(fixDuplicateTouchListener);
            if (property == null && customProperty == null) {
                button.addListener(main.getHandListener());
            }
            table.add(button);
            TextTooltip toolTip = new TextTooltip("Tiled Drawable Settings", main.getTooltipManager(), getSkin());
            button.addListener(toolTip);
        } else // rename (ONLY FOR TINTS)
        if (drawable.tint != null || drawable.tintName != null) {
            Button button = new Button(getSkin(), "settings-small");
            button.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    renameDrawableDialog(drawable);
                    event.setBubbles(false);
                }
            });
            button.addListener(fixDuplicateTouchListener);
            if (property == null && customProperty == null) {
                button.addListener(main.getHandListener());
            }
            table.add(button);
            TextTooltip toolTip = new TextTooltip("Rename Tinted Drawable", main.getTooltipManager(), getSkin());
            button.addListener(toolTip);
        } else // settings for custom drawables
        if (drawable.customized) {
            Button button = new Button(getSkin(), "settings-small");
            button.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    renameCustomDrawableDialog(drawable);
                    event.setBubbles(false);
                }
            });
            button.addListener(fixDuplicateTouchListener);
            if (property == null && customProperty == null) {
                button.addListener(main.getHandListener());
            }
            table.add(button);
            TextTooltip toolTip = new TextTooltip("Rename Custom Drawable", main.getTooltipManager(), getSkin());
            button.addListener(toolTip);
        } else {
            table.add();
        }
        // delete
        Button button = new Button(getSkin(), "delete-small");
        button.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                deleteDrawable(drawable);
                event.setBubbles(false);
            }
        });
        button.addListener(fixDuplicateTouchListener);
        if (property == null && customProperty == null) {
            button.addListener(main.getHandListener());
        }
        table.add(button).expandX().right();
        TextTooltip toolTip = new TextTooltip("Delete Drawable", main.getTooltipManager(), getSkin());
        button.addListener(toolTip);
        // preview
        table.row();
        Container bg = new Container();
        bg.setClip(true);
        bg.setBackground(getSkin().getDrawable("white"));
        bg.setColor(drawable.bgColor);
        Image image = new Image(drawablePairs.get(drawable));
        if (MathUtils.isZero(zoomSlider.getValue())) {
            image.setScaling(Scaling.fit);
            bg.fill(false);
        } else {
            image.setScaling(Scaling.stretch);
            bg.fill();
        }
        bg.setActor(image);
        table.add(bg).colspan(5).grow();
        // name
        table.row();
        Label label = new Label(drawable.name, getSkin());
        label.setEllipsis("...");
        label.setEllipsis(true);
        label.setAlignment(Align.center);
        table.add(label).colspan(5).growX().width(sizes[MathUtils.floor(zoomSlider.getValue())]);
        // Tooltip
        toolTip = new TextTooltip(drawable.name, main.getTooltipManager(), getSkin());
        label.addListener(toolTip);
    }
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) DrawableData(com.ray3k.skincomposer.data.DrawableData) Container(com.badlogic.gdx.scenes.scene2d.ui.Container) TextTooltip(com.badlogic.gdx.scenes.scene2d.ui.TextTooltip) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 9 with DrawableData

use of com.ray3k.skincomposer.data.DrawableData in project skin-composer by raeleus.

the class DialogDrawables method finalizeDrawables.

/**
 * Adds the drawables to the project.
 * @param backup If there is a failure, the drawable list will be rolled
 * back to the provided backup.
 * @param filesToProcess
 */
private void finalizeDrawables(Array<DrawableData> backup, Array<FileHandle> filesToProcess) {
    for (FileHandle file : filesToProcess) {
        DrawableData data = new DrawableData(file);
        if (!checkIfNameExists(data.name)) {
            main.getAtlasData().getDrawables().add(data);
        }
    }
    gatherDrawables();
    main.getDialogFactory().showDialogLoading(() -> {
        if (!produceAtlas()) {
            showDrawableError();
            Gdx.app.log(getClass().getName(), "Attempting to reload drawables backup...");
            main.getAtlasData().getDrawables().clear();
            main.getAtlasData().getDrawables().addAll(backup);
            gatherDrawables();
            if (produceAtlas()) {
                Gdx.app.log(getClass().getName(), "Successfully rolled back changes to drawables");
            } else {
                Gdx.app.error(getClass().getName(), "Critical failure, could not roll back changes to drawables");
            }
        } else {
            if (main.getProjectData().areResourcesRelative()) {
                main.getProjectData().makeResourcesRelative();
            }
            main.getProjectData().setChangesSaved(false);
        }
        sortBySelectedMode();
    });
}
Also used : DrawableData(com.ray3k.skincomposer.data.DrawableData) FileHandle(com.badlogic.gdx.files.FileHandle)

Example 10 with DrawableData

use of com.ray3k.skincomposer.data.DrawableData in project skin-composer by raeleus.

the class DialogDrawables method drawablesSelected.

private void drawablesSelected(Array<FileHandle> files) {
    main.getAtlasData().atlasCurrent = false;
    Array<DrawableData> backup = new Array<>(main.getAtlasData().getDrawables());
    Array<FileHandle> unhandledFiles = new Array<>();
    Array<FileHandle> filesToProcess = new Array<>();
    main.getProjectData().setLastDrawablePath(files.get(0).parent().path() + "/");
    for (FileHandle fileHandle : files) {
        if (checkDuplicateDrawables(fileHandle, 0)) {
            unhandledFiles.add(fileHandle);
        } else {
            filesToProcess.add(fileHandle);
        }
    }
    if (unhandledFiles.size > 0) {
        showRemoveDuplicatesDialog(unhandledFiles, backup, filesToProcess);
    } else {
        finalizeDrawables(backup, filesToProcess);
    }
}
Also used : Array(com.badlogic.gdx.utils.Array) DrawableData(com.ray3k.skincomposer.data.DrawableData) FileHandle(com.badlogic.gdx.files.FileHandle)

Aggregations

DrawableData (com.ray3k.skincomposer.data.DrawableData)25 Actor (com.badlogic.gdx.scenes.scene2d.Actor)11 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)11 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)11 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)9 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)9 FileHandle (com.badlogic.gdx.files.FileHandle)7 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)7 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)7 ColorData (com.ray3k.skincomposer.data.ColorData)7 FontData (com.ray3k.skincomposer.data.FontData)7 Array (com.badlogic.gdx.utils.Array)6 StyleData (com.ray3k.skincomposer.data.StyleData)6 Color (com.badlogic.gdx.graphics.Color)5 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)5 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)5 TextTooltip (com.badlogic.gdx.scenes.scene2d.ui.TextTooltip)5 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)5 NinePatchDrawable (com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)5 SpriteDrawable (com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable)5