Search in sources :

Example 6 with Dialog

use of com.badlogic.gdx.scenes.scene2d.ui.Dialog in project gdx-skineditor by cobolfoo.

the class OptionsPane method showFloatInputDialog.

/**
	 * 
	 * Display a input dialog asking for a float value
	 * 
	 */
public void showFloatInputDialog(final Field field) {
    try {
        final TextField textValue = new TextField(String.valueOf((Float) field.get(currentStyle)), game.skin);
        Dialog dlg = new Dialog("Change Value", game.skin) {

            @Override
            protected void result(Object object) {
                if ((Boolean) object == false) {
                    return;
                }
                float value = 0;
                String text = textValue.getText();
                if (text.isEmpty() == false) {
                    value = Float.valueOf(text);
                }
                try {
                    field.set(currentStyle, value);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                game.screenMain.saveToSkin();
                refresh();
                game.screenMain.paneOptions.updateSelectedTableFields();
                game.screenMain.panePreview.refresh();
            }
        };
        dlg.pad(20);
        dlg.getContentTable().add("Float Value:");
        dlg.getContentTable().add(textValue).pad(20);
        dlg.button("OK", true);
        dlg.button("Cancel", false);
        dlg.key(com.badlogic.gdx.Input.Keys.ENTER, true);
        dlg.key(com.badlogic.gdx.Input.Keys.ESCAPE, false);
        dlg.show(getStage());
        getStage().setKeyboardFocus(textValue);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : DrawablePickerDialog(org.shadebob.skineditor.DrawablePickerDialog) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) FontPickerDialog(org.shadebob.skineditor.FontPickerDialog) ColorPickerDialog(org.shadebob.skineditor.ColorPickerDialog) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField)

Example 7 with Dialog

use of com.badlogic.gdx.scenes.scene2d.ui.Dialog in project gdx-skineditor by cobolfoo.

the class ColorPickerDialog method updateTable.

/**
	 * Refresh table content with colors from the skin
	 */
public void updateTable() {
    tableColors.clear();
    tableColors.add(new Label("Color Name", game.skin, "title")).left().width(170);
    tableColors.add(new Label("Value", game.skin, "title")).colspan(2).left().width(60).padRight(50);
    tableColors.row();
    Iterator<String> it = colors.keys().iterator();
    while (it.hasNext()) {
        final String key = it.next();
        final Color color = colors.get(key);
        tableColors.add(key).left();
        // Create drawable on the fly
        Pixmap pixmap = new Pixmap(18, 18, Pixmap.Format.RGBA8888);
        pixmap.setColor(color);
        pixmap.fill();
        pixmap.setColor(Color.BLACK);
        pixmap.drawRectangle(0, 0, 18, 18);
        Texture texture = new Texture(pixmap);
        pixmap.dispose();
        tableColors.add(new Image(texture));
        tableColors.add(color.toString()).left();
        TextButton buttonSelect = new TextButton("Select", game.skin);
        buttonSelect.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeEvent event, Actor actor) {
                try {
                    field.set(game.screenMain.paneOptions.currentStyle, color);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                hide();
                game.screenMain.panePreview.refresh();
                game.screenMain.paneOptions.updateSelectedTableFields();
                game.screenMain.saveToSkin();
            }
        });
        TextButton buttonRemove = new TextButton("Remove", game.skin);
        buttonRemove.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeEvent event, Actor actor) {
                Dialog dlg = new Dialog("Delete Style", game.skin) {

                    @Override
                    protected void result(Object object) {
                        if ((Boolean) object == false) {
                            return;
                        }
                        if (isColorInUse(color) == true) {
                            game.showNotice("Error", "Color already in use!", game.screenMain.stage);
                        } else {
                            colors.remove(key);
                            // update table
                            updateTable();
                            game.screenMain.saveToSkin();
                        }
                    }
                };
                dlg.pad(20);
                dlg.getContentTable().add("You are sure you want to delete this color?");
                dlg.button("OK", true);
                dlg.button("Cancel", false);
                dlg.key(com.badlogic.gdx.Input.Keys.ENTER, true);
                dlg.key(com.badlogic.gdx.Input.Keys.ESCAPE, false);
                dlg.show(game.screenMain.stage);
            }
        });
        if (field != null) {
            tableColors.add(buttonSelect).padRight(5);
        }
        tableColors.add(buttonRemove);
        tableColors.row();
    }
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Color(com.badlogic.gdx.graphics.Color) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) Texture(com.badlogic.gdx.graphics.Texture) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 8 with Dialog

use of com.badlogic.gdx.scenes.scene2d.ui.Dialog in project gdx-skineditor by cobolfoo.

the class OptionsPane method createNewStyle.

/**
	 * 
	 */
protected void createNewStyle() {
    final TextField textStyleName = new TextField("", game.skin);
    Dialog dlgStyle = new Dialog("New Style", game.skin) {

        @Override
        protected void result(Object object) {
            if ((Boolean) object == false) {
                return;
            }
            String styleName = textStyleName.getText();
            if (styleName.length() == 0) {
                game.showNotice("Warning", "No style name entered!", game.screenMain.stage);
                return;
            }
            // Check if the style name is already in use
            if (listItems.contains(styleName, false)) {
                game.showNotice("Warning", "Style name already in use!", game.screenMain.stage);
                return;
            }
            try {
                game.skinProject.add(styleName, currentStyle.getClass().newInstance());
            } catch (Exception e) {
                e.printStackTrace();
            }
            //game.skinProject.add(text, game.skin.get("default", currentStyle.getClass()), currentStyle.getClass());
            game.screenMain.saveToSkin();
            refresh();
            game.screenMain.panePreview.refresh();
        }
    };
    dlgStyle.pad(20);
    dlgStyle.getContentTable().add("Style Name:");
    dlgStyle.getContentTable().add(textStyleName).pad(20);
    dlgStyle.button("OK", true);
    dlgStyle.button("Cancel", false);
    dlgStyle.key(com.badlogic.gdx.Input.Keys.ENTER, true);
    dlgStyle.key(com.badlogic.gdx.Input.Keys.ESCAPE, false);
    dlgStyle.show(getStage());
    getStage().setKeyboardFocus(textStyleName);
}
Also used : DrawablePickerDialog(org.shadebob.skineditor.DrawablePickerDialog) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) FontPickerDialog(org.shadebob.skineditor.FontPickerDialog) ColorPickerDialog(org.shadebob.skineditor.ColorPickerDialog) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField)

Example 9 with Dialog

use of com.badlogic.gdx.scenes.scene2d.ui.Dialog in project gdx-skineditor by cobolfoo.

the class OptionsPane method showDeleteDialog.

/**
	 * 
	 */
protected void showDeleteDialog() {
    // Check if it used by other style prior to delete it
    // FIXME: TODO
    Dialog dlgStyle = new Dialog("Delete Style", game.skin) {

        @Override
        protected void result(Object object) {
            if ((Boolean) object == false) {
                return;
            }
            // Now we really add it!
            game.skinProject.remove((String) listStyles.getSelected(), currentStyle.getClass());
            refresh();
            game.screenMain.saveToSkin();
            game.screenMain.panePreview.refresh();
        }
    };
    dlgStyle.pad(20);
    dlgStyle.getContentTable().add("You are sure you want to delete this style?");
    dlgStyle.button("OK", true);
    dlgStyle.button("Cancel", false);
    dlgStyle.key(com.badlogic.gdx.Input.Keys.ENTER, true);
    dlgStyle.key(com.badlogic.gdx.Input.Keys.ESCAPE, false);
    dlgStyle.show(getStage());
}
Also used : DrawablePickerDialog(org.shadebob.skineditor.DrawablePickerDialog) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) FontPickerDialog(org.shadebob.skineditor.FontPickerDialog) ColorPickerDialog(org.shadebob.skineditor.ColorPickerDialog)

Example 10 with Dialog

use of com.badlogic.gdx.scenes.scene2d.ui.Dialog in project gdx-skineditor by cobolfoo.

the class DrawablePickerDialog method show.

@Override
public Dialog show(Stage stage) {
    refresh();
    Dialog d = super.show(stage);
    getStage().setScrollFocus(scrollPane);
    return d;
}
Also used : Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog)

Aggregations

Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)13 Actor (com.badlogic.gdx.scenes.scene2d.Actor)6 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)6 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)6 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)6 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)5 ColorPickerDialog (org.shadebob.skineditor.ColorPickerDialog)4 DrawablePickerDialog (org.shadebob.skineditor.DrawablePickerDialog)4 FontPickerDialog (org.shadebob.skineditor.FontPickerDialog)4 FileHandle (com.badlogic.gdx.files.FileHandle)3 Texture (com.badlogic.gdx.graphics.Texture)2 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)2 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)2 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)2 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)2 TextFieldListener (com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldListener)2 NinePatchEditorDialog (org.shadebob.skineditor.NinePatchEditorDialog)2 Preferences (com.badlogic.gdx.Preferences)1 Color (com.badlogic.gdx.graphics.Color)1 Pixmap (com.badlogic.gdx.graphics.Pixmap)1