Search in sources :

Example 6 with ScrollPaneStyle

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

the class OptionsPane method updateTableFields.

/**
 */
private void updateTableFields(final String style) {
    ImageButton button = (ImageButton) game.screenMain.barWidgets.group.getChecked();
    String widget = button.getUserObject().toString();
    Gdx.app.log("OptionsPane", "Update fields table for widget: " + widget + ", style: " + style);
    tableFields.clear();
    tableFields.add(new Label("Name", game.skin, "title")).left().width(170);
    tableFields.add(new Label("Value", game.skin, "title")).left().width(60).padRight(50);
    tableFields.row();
    Field[] fields = ClassReflection.getFields(currentStyle.getClass());
    for (final Field field : fields) {
        try {
            // Grey optional
            if (game.opt.isFieldOptional(currentStyle.getClass(), field.getName())) {
                tableFields.add(new Label(field.getName(), game.skin, "optional")).left();
            } else {
                tableFields.add(new Label(field.getName(), game.skin, "default")).left();
            }
            Actor actor;
            // field type
            String name = field.getType().getSimpleName();
            Object obj = field.get(currentStyle);
            if (name.equals("Drawable")) {
                /**
                 * Handle Drawable object
                 */
                Drawable drawable = (Drawable) field.get(currentStyle);
                String resourceName = "";
                ImageTextButton.ImageTextButtonStyle buttonStyle = new ImageTextButton.ImageTextButtonStyle(game.skin.getDrawable("default-round"), game.skin.getDrawable("default-round-down"), game.skin.getDrawable("default-round"), game.skin.getFont("default-font"));
                if (drawable != null) {
                    resourceName = game.skinProject.resolveObjectName(Drawable.class, drawable);
                    buttonStyle.imageUp = drawable;
                } else {
                    buttonStyle.up = game.skinProject.getDrawable("default-rect");
                    buttonStyle.checked = game.skinProject.getDrawable("default-rect");
                }
                actor = new ImageTextButton(resourceName, buttonStyle);
                ((ImageTextButton) actor).setClip(true);
                actor.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeEvent event, Actor actor) {
                        showDrawableDialog(field);
                    }
                });
            } else if (name.equals("Color")) {
                /**
                 * Handle Color object
                 */
                Color color = (Color) field.get(currentStyle);
                ImageTextButton.ImageTextButtonStyle buttonStyle = new ImageTextButton.ImageTextButtonStyle(game.skin.getDrawable("default-round"), game.skin.getDrawable("default-round-down"), game.skin.getDrawable("default-round"), game.skin.getFont("default-font"));
                String resourceName = "";
                if (color != null) {
                    resourceName = game.skinProject.resolveObjectName(Color.class, color);
                    resourceName += " (" + color.toString() + ")";
                    // 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);
                    buttonStyle.imageUp = new SpriteDrawable(new Sprite(texture));
                    pixmap.dispose();
                } else {
                    buttonStyle.up = game.skinProject.getDrawable("default-rect");
                    buttonStyle.checked = game.skinProject.getDrawable("default-rect");
                }
                actor = new ImageTextButton(resourceName, buttonStyle);
                ((ImageTextButton) actor).setClip(true);
                actor.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeEvent event, Actor actor) {
                        showColorPickerDialog(field);
                    }
                });
            } else if (name.equals("BitmapFont")) {
                /**
                 * Handle BitmapFont object
                 */
                BitmapFont font = (BitmapFont) field.get(currentStyle);
                String resourceName = "";
                ImageTextButton.ImageTextButtonStyle buttonStyle = new ImageTextButton.ImageTextButtonStyle(game.skin.getDrawable("default-round"), game.skin.getDrawable("default-round-down"), game.skin.getDrawable("default-round"), game.skin.getFont("default-font"));
                if (font != null) {
                    resourceName = game.skinProject.resolveObjectName(BitmapFont.class, font);
                    buttonStyle.font = font;
                } else {
                    buttonStyle.up = game.skinProject.getDrawable("default-rect");
                    buttonStyle.checked = game.skinProject.getDrawable("default-rect");
                }
                actor = new ImageTextButton(resourceName, buttonStyle);
                ((ImageTextButton) actor).setClip(true);
                actor.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeEvent event, Actor actor) {
                        showFontPickerDialog(field);
                    }
                });
            } else if (name.equals("float")) {
                /**
                 * Handle Float object
                 */
                Float value = (Float) field.get(currentStyle);
                String resourceName = "";
                ImageTextButton.ImageTextButtonStyle buttonStyle = new ImageTextButton.ImageTextButtonStyle(game.skin.getDrawable("default-round"), game.skin.getDrawable("default-round-down"), game.skin.getDrawable("default-round"), game.skin.getFont("default-font"));
                if ((value != null) && (value != 0)) {
                    resourceName = String.valueOf(value);
                } else {
                    buttonStyle.up = game.skinProject.getDrawable("default-rect");
                    buttonStyle.checked = game.skinProject.getDrawable("default-rect");
                }
                actor = new ImageTextButton(resourceName, buttonStyle);
                ((ImageTextButton) actor).setClip(true);
                actor.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeEvent event, Actor actor) {
                        showFloatInputDialog(field);
                    }
                });
            } else if (name.equals("ListStyle")) {
                /**
                 * Handle ListStyle object
                 */
                ListStyle listStyle = (ListStyle) field.get(currentStyle);
                actor = new SelectBox<String>(game.skin, "default");
                Array<String> items = new Array<String>();
                final ObjectMap<String, ListStyle> values = game.skinProject.getAll(ListStyle.class);
                Iterator<String> it = values.keys().iterator();
                String selection = null;
                while (it.hasNext()) {
                    String key = it.next();
                    items.add(key);
                    if (listStyle == values.get(key)) {
                        selection = key;
                    }
                }
                ((SelectBox) actor).setItems(items);
                if (selection != null) {
                    ((SelectBox) actor).setSelected(selection);
                }
                actor.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeEvent event, Actor actor) {
                        String selection = (String) ((SelectBox) actor).getSelected();
                        try {
                            field.set(currentStyle, values.get(selection));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        game.screenMain.saveToSkin();
                        refresh();
                        game.screenMain.paneOptions.updateSelectedTableFields();
                        game.screenMain.panePreview.refresh();
                    }
                });
            } else if (name.equals("ScrollPaneStyle")) {
                /**
                 * Handle ListStyle object
                 */
                ScrollPaneStyle scrollStyle = (ScrollPaneStyle) field.get(currentStyle);
                actor = new SelectBox<String>(game.skin, "default");
                Array<String> items = new Array<String>();
                final ObjectMap<String, ScrollPaneStyle> values = game.skinProject.getAll(ScrollPaneStyle.class);
                Iterator<String> it = values.keys().iterator();
                String selection = null;
                while (it.hasNext()) {
                    String key = it.next();
                    items.add(key);
                    if (scrollStyle == values.get(key)) {
                        selection = key;
                    }
                }
                ((SelectBox) actor).setItems(items);
                if (selection != null) {
                    ((SelectBox) actor).setSelected(selection);
                }
                actor.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeEvent event, Actor actor) {
                        String selection = (String) ((SelectBox) actor).getSelected();
                        try {
                            field.set(currentStyle, values.get(selection));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        game.screenMain.saveToSkin();
                        refresh();
                        game.screenMain.paneOptions.updateSelectedTableFields();
                        game.screenMain.panePreview.refresh();
                    }
                });
            } else {
                Gdx.app.log("OptionsPane", "Unknown type: " + name);
                actor = new Label("Unknown Type", game.skin);
            }
            tableFields.add(actor).left().height(32).padRight(24).expandX().fillX();
            tableFields.row();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : ListStyle(com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle) ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Texture(com.badlogic.gdx.graphics.Texture) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Field(com.badlogic.gdx.utils.reflect.Field) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) ObjectMap(com.badlogic.gdx.utils.ObjectMap) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Iterator(java.util.Iterator) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) SelectBox(com.badlogic.gdx.scenes.scene2d.ui.SelectBox) Color(com.badlogic.gdx.graphics.Color) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) Array(com.badlogic.gdx.utils.Array) Pixmap(com.badlogic.gdx.graphics.Pixmap) ScrollPaneStyle(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.ScrollPaneStyle)

Example 7 with ScrollPaneStyle

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

the class Skin method save.

/**
 * Store all resources in the specified skin JSON file.
 */
public boolean save(FileHandle skinFile) {
    StringWriter jsonText = new StringWriter();
    JsonWriter writer = new JsonWriter(jsonText);
    Json json = new Json();
    json.setWriter(writer);
    json.writeObjectStart();
    // Iterator it = resources.keys().iterator();
    // while(it.hasNext()) {
    // Object item = it.next();
    // if (item instanceof com.badlogic.gdx.scenes.scene2d.utils.Drawable) {
    // Drawable d = (Drawable) item;
    // 
    // }
    // }
    // Sort items
    Array<Class> items = new Array<Class>();
    items.add(com.badlogic.gdx.graphics.Color.class);
    items.add(com.badlogic.gdx.graphics.g2d.BitmapFont.class);
    items.add(Skin.TintedDrawable.class);
    items.add(com.badlogic.gdx.scenes.scene2d.ui.ProgressBar.ProgressBarStyle.class);
    items.add(com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle.class);
    items.add(com.badlogic.gdx.scenes.scene2d.ui.ImageButton.ImageButtonStyle.class);
    items.add(com.badlogic.gdx.scenes.scene2d.ui.SplitPane.SplitPaneStyle.class);
    items.add(com.badlogic.gdx.scenes.scene2d.ui.Touchpad.TouchpadStyle.class);
    items.add(com.badlogic.gdx.scenes.scene2d.ui.Button.ButtonStyle.class);
    items.add(com.badlogic.gdx.scenes.scene2d.ui.Window.WindowStyle.class);
    items.add(com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldStyle.class);
    items.add(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.ScrollPaneStyle.class);
    items.add(com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle.class);
    items.add(com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle.class);
    items.add(com.badlogic.gdx.scenes.scene2d.ui.CheckBox.CheckBoxStyle.class);
    items.add(com.badlogic.gdx.scenes.scene2d.ui.Tree.TreeStyle.class);
    items.add(com.badlogic.gdx.scenes.scene2d.ui.Slider.SliderStyle.class);
    items.add(com.badlogic.gdx.scenes.scene2d.ui.SelectBox.SelectBoxStyle.class);
    for (Class<?> item : items) {
        String name = item.getName();
        json.writeObjectStart(name);
        ObjectMap<String, Object> typeResources = resources.get(item);
        // Build a temporary array for string keys to prevent nested
        // iterators with getObjetName function.
        Array<String> styles = new Array<String>();
        Iterator itStyles = typeResources.keys().iterator();
        while (itStyles.hasNext()) {
            String style = (String) itStyles.next();
            styles.add(style);
        }
        for (String style : styles) {
            json.writeObjectStart(style);
            Field[] fields = ClassReflection.getFields(typeResources.get(style).getClass());
            // Handle functions
            if (typeResources.get(style) instanceof com.badlogic.gdx.graphics.g2d.BitmapFont) {
                BitmapFont font = (BitmapFont) typeResources.get(style);
                json.writeValue("file", font.getData().fontFile.name());
            }
            for (Field field : fields) {
                try {
                    Object object = field.get(typeResources.get(style));
                    if (object != null) {
                        if (object instanceof BitmapFont) {
                            String value = resolveObjectName(BitmapFont.class, object);
                            if (value != null) {
                                json.writeValue(field.getName(), value);
                            }
                        } else if (object instanceof Float) {
                            if ((Float) object != 0.0f) {
                                json.writeValue(field.getName(), object);
                            }
                        } else if (object instanceof Color) {
                            if (typeResources.get(style) instanceof Color) {
                            // Skip sub-color
                            } else {
                                json.writeValue(field.getName(), object);
                            }
                        } else if (object instanceof Drawable) {
                            if (typeResources.get(style) instanceof com.badlogic.gdx.scenes.scene2d.ui.Skin.TintedDrawable) {
                            // Skip drawable if it is from tinted drawable
                            } else {
                                String value = null;
                                value = resolveObjectName(Drawable.class, object);
                                // 
                                if (value != null) {
                                    json.writeValue(field.getName(), value);
                                }
                            }
                        } else if (object instanceof ListStyle) {
                            String value = resolveObjectName(ListStyle.class, object);
                            if (value != null) {
                                json.writeValue(field.getName(), value);
                            }
                        } else if (object instanceof ScrollPaneStyle) {
                            String value = resolveObjectName(ScrollPaneStyle.class, object);
                            if (value != null) {
                                json.writeValue(field.getName(), value);
                            }
                        } else if (object instanceof String) {
                            // only used to get original drawable for tinted drawable
                            json.writeValue(field.getName(), object);
                        } else if (object instanceof char[]) {
                        // Don't store.
                        } else {
                            throw new IllegalArgumentException("resource object type is unknown: " + object.getClass().getCanonicalName());
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            json.writeObjectEnd();
        }
        json.writeObjectEnd();
    }
    json.writeObjectEnd();
    PrettyPrintSettings settings = new PrettyPrintSettings();
    settings.outputType = OutputType.minimal;
    settings.singleLineColumns = 100;
    skinFile.writeString(json.prettyPrint(jsonText.toString(), settings), false);
    return true;
}
Also used : ListStyle(com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle) Field(com.badlogic.gdx.utils.reflect.Field) StringWriter(java.io.StringWriter) Iterator(java.util.Iterator) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) PrettyPrintSettings(com.badlogic.gdx.utils.JsonValue.PrettyPrintSettings) Color(com.badlogic.gdx.graphics.Color) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) 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) Json(com.badlogic.gdx.utils.Json) JsonWriter(com.badlogic.gdx.utils.JsonWriter) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) SerializationException(com.badlogic.gdx.utils.SerializationException) ReflectionException(com.badlogic.gdx.utils.reflect.ReflectionException) Array(com.badlogic.gdx.utils.Array) ScrollPaneStyle(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.ScrollPaneStyle)

Example 8 with ScrollPaneStyle

use of com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.ScrollPaneStyle in project var3dframe by Var3D.

the class VGame method getScrollPane.

/**
 * 创建ScrollPane
 */
public UI<ScrollPane> getScrollPane(Actor actor, Color bg) {
    ScrollPaneStyle style = new ScrollPaneStyle();
    style.background = getRectColorDrawable(2, 2, bg);
    return getScrollPane(actor, style);
}
Also used : ScrollPaneStyle(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.ScrollPaneStyle)

Example 9 with ScrollPaneStyle

use of com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.ScrollPaneStyle in project var3dframe by Var3D.

the class VGame method getScrollPane.

/**
 * 创建ScrollPane
 */
public UI<ScrollPane> getScrollPane(Actor actor, String background) {
    ScrollPaneStyle style = new ScrollPaneStyle();
    style.background = getDrawable(background);
    return getScrollPane(actor, style);
}
Also used : ScrollPaneStyle(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.ScrollPaneStyle)

Aggregations

ScrollPaneStyle (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.ScrollPaneStyle)9 ListStyle (com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle)7 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)6 Color (com.badlogic.gdx.graphics.Color)4 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)4 Array (com.badlogic.gdx.utils.Array)4 Field (com.badlogic.gdx.utils.reflect.Field)3 GlyphLayout (com.badlogic.gdx.graphics.g2d.GlyphLayout)2 LabelStyle (com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle)2 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)2 SpriteDrawable (com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable)2 Iterator (java.util.Iterator)2 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 Texture (com.badlogic.gdx.graphics.Texture)1 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)1 Actor (com.badlogic.gdx.scenes.scene2d.Actor)1 CheckBoxStyle (com.badlogic.gdx.scenes.scene2d.ui.CheckBox.CheckBoxStyle)1 ImageButton (com.badlogic.gdx.scenes.scene2d.ui.ImageButton)1 ImageTextButton (com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton)1 ImageTextButtonStyle (com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton.ImageTextButtonStyle)1