Search in sources :

Example 1 with FreeTypeFontData

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

the class RootTable method refreshPreview.

public void refreshPreview() {
    if (previewTable != null) {
        previewTable.clear();
        previewTable.setBackground("white");
        previewTable.setColor((Color) previewProperties.get("bgcolor"));
        for (BitmapFont font : previewFonts) {
            font.dispose();
        }
        if (classSelectBox.getSelectedIndex() >= 0 && classSelectBox.getSelectedIndex() < Main.BASIC_CLASSES.length) {
            StyleData styleData = getSelectedStyle();
            Class clazz = Main.BASIC_CLASSES[classSelectBox.getSelectedIndex()];
            if (!styleData.hasMandatoryFields()) {
                Label label;
                if (clazz.equals(SelectBox.class)) {
                    label = new Label("Please fill all mandatory fields\n(Highlighted on the left)\n\nscrollStyle and listStyle\nmust already be defined", getSkin());
                } else if (clazz.equals(TextTooltip.class)) {
                    label = new Label("Please fill all mandatory fields\n(Highlighted on the left)\n\nlabel must already be defined", getSkin());
                } else {
                    label = new Label("Please fill all mandatory fields\n(Highlighted on the left)", getSkin());
                }
                label.setAlignment(Align.center);
                previewTable.add(label);
            } else if (styleData.hasAllNullFields()) {
                Label label;
                label = new Label("All fields are empty!\nEmpty classes are not exported\nAdd style properties in the menu to the left", getSkin());
                label.setAlignment(Align.center);
                previewTable.add(label);
            } else {
                Actor widget = null;
                if (clazz.equals(Button.class)) {
                    Button.ButtonStyle style = createPreviewStyle(Button.ButtonStyle.class, styleData);
                    widget = new Button(style);
                    ((Button) widget).setDisabled((boolean) previewProperties.get("disabled"));
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(CheckBox.class)) {
                    CheckBox.CheckBoxStyle style = createPreviewStyle(CheckBox.CheckBoxStyle.class, styleData);
                    widget = new CheckBox("", style);
                    ((CheckBox) widget).setDisabled((boolean) previewProperties.get("disabled"));
                    ((CheckBox) widget).setText((String) previewProperties.get("text"));
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(ImageButton.class)) {
                    ImageButtonStyle style = createPreviewStyle(ImageButtonStyle.class, styleData);
                    widget = new ImageButton(style);
                    ((ImageButton) widget).setDisabled((boolean) previewProperties.get("disabled"));
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(ImageTextButton.class)) {
                    ImageTextButton.ImageTextButtonStyle style = createPreviewStyle(ImageTextButton.ImageTextButtonStyle.class, styleData);
                    widget = new ImageTextButton("", style);
                    ((ImageTextButton) widget).setDisabled((boolean) previewProperties.get("disabled"));
                    ((ImageTextButton) widget).setText((String) previewProperties.get("text"));
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(Label.class)) {
                    LabelStyle style = createPreviewStyle(LabelStyle.class, styleData);
                    widget = new Label("", style);
                    ((Label) widget).setText((String) previewProperties.get("text"));
                } else if (clazz.equals(List.class)) {
                    ListStyle style = createPreviewStyle(ListStyle.class, styleData);
                    widget = new List(style);
                    Array<String> items = new Array<>(((String) previewProperties.get("text")).split("\\n"));
                    ((List) widget).setItems(items);
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(ProgressBar.class)) {
                    ProgressBar.ProgressBarStyle style = createPreviewStyle(ProgressBar.ProgressBarStyle.class, styleData);
                    widget = new ProgressBar((float) (double) previewProperties.get("minimum"), (float) (double) previewProperties.get("maximum"), (float) (double) previewProperties.get("increment"), (boolean) previewProperties.get("orientation"), style);
                    ((ProgressBar) widget).setValue((float) (double) previewProperties.get("value"));
                    ((ProgressBar) widget).setDisabled((boolean) previewProperties.get("disabled"));
                } else if (clazz.equals(ScrollPane.class)) {
                    ScrollPaneStyle style = createPreviewStyle(ScrollPaneStyle.class, styleData);
                    Label label = new Label("", getSkin());
                    widget = new ScrollPane(label, style);
                    ((ScrollPane) widget).setScrollbarsOnTop((boolean) previewProperties.get("scrollbarsOnTop"));
                    ((ScrollPane) widget).setScrollBarPositions((boolean) previewProperties.get("hScrollBarPosition"), (boolean) previewProperties.get("vScrollBarPosition"));
                    ((ScrollPane) widget).setScrollingDisabled((boolean) previewProperties.get("hScrollDisabled"), (boolean) previewProperties.get("vScrollDisabled"));
                    ((ScrollPane) widget).setForceScroll((boolean) previewProperties.get("forceHscroll"), (boolean) previewProperties.get("forceVscroll"));
                    ((ScrollPane) widget).setVariableSizeKnobs((boolean) previewProperties.get("variableSizeKnobs"));
                    ((ScrollPane) widget).setOverscroll((boolean) previewProperties.get("hOverscroll"), (boolean) previewProperties.get("vOverscroll"));
                    ((ScrollPane) widget).setFadeScrollBars((boolean) previewProperties.get("fadeScroll"));
                    ((ScrollPane) widget).setSmoothScrolling((boolean) previewProperties.get("smoothScroll"));
                    ((ScrollPane) widget).setFlickScroll((boolean) previewProperties.get("flickScroll"));
                    ((ScrollPane) widget).setClamp((boolean) previewProperties.get("clamp"));
                    label.setText((String) previewProperties.get("text"));
                } else if (clazz.equals(SelectBox.class)) {
                    SelectBox.SelectBoxStyle style = createPreviewStyle(SelectBox.SelectBoxStyle.class, styleData);
                    widget = new SelectBox(style);
                    ((SelectBox) widget).setDisabled((boolean) previewProperties.get("disabled"));
                    Array<String> items = new Array<>(((String) previewProperties.get("text")).split("\\n"));
                    ((SelectBox) widget).setItems(items);
                    widget.addListener(main.getHandListener());
                    ((SelectBox) widget).getList().addListener(main.getHandListener());
                } else if (clazz.equals(Slider.class)) {
                    Slider.SliderStyle style = createPreviewStyle(Slider.SliderStyle.class, styleData);
                    widget = new Slider((float) (double) previewProperties.get("minimum"), (float) (double) previewProperties.get("maximum"), (float) (double) previewProperties.get("increment"), (boolean) previewProperties.get("orientation"), style);
                    ((Slider) widget).setDisabled((boolean) previewProperties.get("disabled"));
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(SplitPane.class)) {
                    SplitPane.SplitPaneStyle style = createPreviewStyle(SplitPane.SplitPaneStyle.class, styleData);
                    Label label1 = new Label("", getSkin());
                    Label label2 = new Label("", getSkin());
                    widget = new SplitPane(label1, label2, (boolean) previewProperties.get("orientation"), style);
                    label1.setText((String) previewProperties.get("text"));
                    label2.setText((String) previewProperties.get("text"));
                    if ((boolean) previewProperties.get("orientation")) {
                        widget.addListener(vSplitPaneDragListener);
                        widget.addListener(vSplitPaneInputListener);
                    } else {
                        widget.addListener(hSplitPaneDragListener);
                        widget.addListener(hSplitPaneInputListener);
                    }
                } else if (clazz.equals(TextButton.class)) {
                    TextButtonStyle style = createPreviewStyle(TextButtonStyle.class, styleData);
                    widget = new TextButton("", style);
                    ((TextButton) widget).setDisabled((boolean) previewProperties.get("disabled"));
                    ((TextButton) widget).setText((String) previewProperties.get("text"));
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(TextField.class)) {
                    TextFieldStyle style = createPreviewStyle(TextFieldStyle.class, styleData);
                    widget = new TextField("", style);
                    ((TextField) widget).setFocusTraversal(false);
                    ((TextField) widget).setDisabled((boolean) previewProperties.get("disabled"));
                    ((TextField) widget).setPasswordMode((boolean) previewProperties.get("passwordMode"));
                    ((TextField) widget).setAlignment((int) previewProperties.get("alignment"));
                    ((TextField) widget).setText((String) previewProperties.get("text"));
                    ((TextField) widget).setMessageText((String) previewProperties.get("message"));
                    String string = (String) previewProperties.get("password");
                    if (string.length() > 0) {
                        ((TextField) widget).setPasswordCharacter(string.charAt(0));
                    }
                    widget.addListener(main.getIbeamListener());
                } else if (clazz.equals(TextTooltip.class)) {
                    TextTooltip.TextTooltipStyle style = createPreviewStyle(TextTooltip.TextTooltipStyle.class, styleData);
                    TooltipManager manager = new TooltipManager();
                    manager.animations = false;
                    manager.initialTime = 0.0f;
                    manager.resetTime = 0.0f;
                    manager.subsequentTime = 0.0f;
                    manager.hideAll();
                    manager.instant();
                    TextTooltip toolTip = new TextTooltip((String) previewProperties.get("text"), manager, style);
                    widget = new Label("Hover over me", getSkin());
                    widget.addListener(toolTip);
                } else if (clazz.equals(Touchpad.class)) {
                    Touchpad.TouchpadStyle style = createPreviewStyle(Touchpad.TouchpadStyle.class, styleData);
                    widget = new Touchpad(0, style);
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(Tree.class)) {
                    Tree.TreeStyle style = createPreviewStyle(Tree.TreeStyle.class, styleData);
                    widget = new Tree(style);
                    String[] lines = { "this", "is", "a", "test" };
                    Tree.Node parentNode = null;
                    for (String line : lines) {
                        Label label = new Label(line, getSkin());
                        Tree.Node node = new Tree.Node(label);
                        if (parentNode == null) {
                            ((Tree) widget).add(node);
                        } else {
                            parentNode.add(node);
                        }
                        parentNode = node;
                    }
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(Window.class)) {
                    Window.WindowStyle style = createPreviewStyle(Window.WindowStyle.class, styleData);
                    if (style.stageBackground != null) {
                        previewTable.setBackground(style.stageBackground);
                        previewTable.setColor(Color.WHITE);
                        style.stageBackground = null;
                    }
                    Label sampleText = new Label("", getSkin());
                    sampleText.setText((String) previewProperties.get("text"));
                    widget = new Window((String) previewProperties.get("title"), style);
                    ((Window) widget).add(sampleText);
                }
                if (widget != null) {
                    switch((int) previewProperties.get("size")) {
                        case (0):
                            previewTable.add(widget).size(10.0f);
                            previewSizeSelectBox.setItems(DEFAULT_SIZES);
                            break;
                        case (1):
                            previewTable.add(widget);
                            previewSizeSelectBox.setItems(DEFAULT_SIZES);
                            break;
                        case (2):
                            previewTable.add(widget).size(200.0f);
                            previewSizeSelectBox.setItems(DEFAULT_SIZES);
                            break;
                        case (3):
                            previewTable.add(widget).growX();
                            previewSizeSelectBox.setItems(DEFAULT_SIZES);
                            break;
                        case (4):
                            previewTable.add(widget).growY();
                            previewSizeSelectBox.setItems(DEFAULT_SIZES);
                            break;
                        case (5):
                            previewTable.add(widget).grow();
                            previewSizeSelectBox.setItems(DEFAULT_SIZES);
                            break;
                        case (6):
                            Actor addWidget = widget;
                            TraversalTextField widthField = new TraversalTextField("", getSkin());
                            TraversalTextField heightField = new TraversalTextField("", getSkin());
                            widthField.setNextFocus(heightField);
                            heightField.setNextFocus(widthField);
                            Dialog dialog = new Dialog("Enter dimensions...", getSkin()) {

                                @Override
                                protected void result(Object object) {
                                    if ((boolean) object) {
                                        previewTable.add(addWidget).size(Integer.parseInt(widthField.getText()), Integer.parseInt(heightField.getText()));
                                        Array<String> items = new Array<>(DEFAULT_SIZES);
                                        items.add(widthField.getText() + "x" + heightField.getText());
                                        previewProperties.put("sizeX", Integer.parseInt(widthField.getText()));
                                        previewProperties.put("sizeY", Integer.parseInt(heightField.getText()));
                                        previewSizeSelectBox.setItems(items);
                                        previewSizeSelectBox.setSelectedIndex(7);
                                    } else {
                                        previewSizeSelectBox.setSelectedIndex(1);
                                    }
                                }
                            };
                            dialog.getTitleTable().getCells().first().padLeft(5.0f);
                            dialog.text("Enter the preview dimensions: ");
                            dialog.getContentTable().getCells().first().pad(10.0f);
                            dialog.getContentTable().row();
                            Table sizeTable = new Table();
                            sizeTable.add(widthField).padLeft(10.0f);
                            sizeTable.add(new Label(" x ", getSkin()));
                            sizeTable.add(heightField).padRight(10.0f);
                            dialog.getContentTable().add(sizeTable);
                            dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
                            dialog.button("OK", true);
                            dialog.button("Cancel", false);
                            TextButton okButton = (TextButton) dialog.getButtonTable().getCells().first().getActor();
                            okButton.setDisabled(true);
                            okButton.addListener(main.getHandListener());
                            widthField.addListener(new ChangeListener() {

                                @Override
                                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                                    okButton.setDisabled(!widthField.getText().matches("^\\d+$") || !heightField.getText().matches("^\\d+$"));
                                }
                            });
                            heightField.addListener(new ChangeListener() {

                                @Override
                                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                                    okButton.setDisabled(!widthField.getText().matches("^\\d+$") || !heightField.getText().matches("^\\d+$"));
                                }
                            });
                            dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
                            dialog.key(Input.Keys.ESCAPE, false);
                            dialog.show(stage);
                            stage.setKeyboardFocus(widthField);
                            break;
                        case (7):
                            previewTable.add(widget).size((int) previewProperties.get("sizeX"), (int) previewProperties.get("sizeY"));
                            break;
                    }
                }
            }
        } else {
            CustomStyle customStyle = (CustomStyle) styleSelectBox.getSelected();
            boolean showMessage = true;
            if (customStyle.getProperties().size == 0) {
                Label label = new Label("No style properties!\nEmpty classes are not exported\nAdd style properties in the menu to the left", getSkin());
                label.setAlignment(0);
                previewTable.add(label);
            } else {
                for (CustomProperty customProperty : customStyle.getProperties()) {
                    if (customProperty.getValue() != null && !(customProperty.getValue() instanceof String) || customProperty.getValue() != null && !((String) customProperty.getValue()).equals("")) {
                        showMessage = false;
                        break;
                    }
                }
                if (showMessage) {
                    Label label = new Label("All properties are empty!\nEmpty classes are not exported\nAdd style properties in the menu to the left", getSkin());
                    label.setAlignment(0);
                    previewTable.add(label);
                }
            }
            if (!showMessage) {
                HorizontalGroup horizontalGroup = new HorizontalGroup();
                horizontalGroup.wrap();
                // the following causes a crash. LibGDX bug.
                // horizontalGroup.space(10.0f);
                horizontalGroup.wrapSpace(10.0f);
                horizontalGroup.setTouchable(Touchable.disabled);
                previewTable.add(horizontalGroup).grow().pad(10.0f);
                for (CustomProperty customProperty : customStyle.getProperties()) {
                    if (customProperty.getValue() != null) {
                        Container container = new Container();
                        container.pad(5.0f);
                        horizontalGroup.addActor(container);
                        switch(customProperty.getType()) {
                            case TEXT:
                            case RAW_TEXT:
                                Label labelText = new Label((String) customProperty.getValue(), getSkin());
                                container.setActor(labelText);
                                break;
                            case NUMBER:
                                Label labelNumber = new Label(Double.toString((double) customProperty.getValue()), getSkin());
                                container.setActor(labelNumber);
                                break;
                            case BOOL:
                                Label labelBoolean = new Label(Boolean.toString((boolean) customProperty.getValue()), getSkin());
                                container.setActor(labelBoolean);
                                break;
                            case COLOR:
                                ColorData colorData = null;
                                String colorName = (String) customProperty.getValue();
                                for (ColorData cd : main.getJsonData().getColors()) {
                                    if (cd.getName().equals(colorName)) {
                                        colorData = cd;
                                        break;
                                    }
                                }
                                if (colorData != null) {
                                    Table colorTable = new Table(getSkin());
                                    colorTable.setBackground("white");
                                    colorTable.setColor(colorData.color);
                                    colorTable.add().size(25.0f);
                                    container.setActor(colorTable);
                                }
                                break;
                            case FONT:
                                BitmapFont font = null;
                                FontData fontData = null;
                                String fontName = (String) customProperty.getValue();
                                for (FontData fd : main.getJsonData().getFonts()) {
                                    if (fd.getName().equals(fontName)) {
                                        fontData = fd;
                                        font = new BitmapFont(fd.file);
                                        previewFonts.add(font);
                                        break;
                                    }
                                }
                                if (font != null) {
                                    Label labelFont = new Label(fontData.getName(), new LabelStyle(font, Color.WHITE));
                                    container.setActor(labelFont);
                                }
                                FreeTypeFontData freeTypeFontData = null;
                                for (FreeTypeFontData fd : main.getJsonData().getFreeTypeFonts()) {
                                    if (fd.name.equals(fontName)) {
                                        freeTypeFontData = fd;
                                        break;
                                    }
                                }
                                if (freeTypeFontData.bitmapFont != null) {
                                    Label labelFont = new Label(freeTypeFontData.name, new LabelStyle(freeTypeFontData.bitmapFont, Color.WHITE));
                                    container.setActor(labelFont);
                                }
                                break;
                            case DRAWABLE:
                                DrawableData drawable = null;
                                String drawableName = (String) customProperty.getValue();
                                for (DrawableData dd : main.getAtlasData().getDrawables()) {
                                    if (dd.name.equals(drawableName)) {
                                        drawable = dd;
                                        break;
                                    }
                                }
                                if (drawable != null) {
                                    Image image = new Image(drawablePairs.get(drawable.name));
                                    container.setActor(image);
                                }
                                break;
                        }
                    }
                }
            }
        }
    }
}
Also used : Label(com.badlogic.gdx.scenes.scene2d.ui.Label) SplitPane(com.badlogic.gdx.scenes.scene2d.ui.SplitPane) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) Container(com.badlogic.gdx.scenes.scene2d.ui.Container) DrawableData(com.ray3k.skincomposer.data.DrawableData) TextTooltip(com.badlogic.gdx.scenes.scene2d.ui.TextTooltip) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Touchpad(com.badlogic.gdx.scenes.scene2d.ui.Touchpad) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Tree(com.badlogic.gdx.scenes.scene2d.ui.Tree) List(com.badlogic.gdx.scenes.scene2d.ui.List) HorizontalGroup(com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup) ImageButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.ImageButton.ImageButtonStyle) TextButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle) SelectBox(com.badlogic.gdx.scenes.scene2d.ui.SelectBox) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) FontData(com.ray3k.skincomposer.data.FontData) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) TooltipManager(com.badlogic.gdx.scenes.scene2d.ui.TooltipManager) ScrollPaneStyle(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.ScrollPaneStyle) ListStyle(com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle) ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) Slider(com.badlogic.gdx.scenes.scene2d.ui.Slider) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) TextButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle) ImageButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.ImageButton.ImageButtonStyle) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) ProgressBar(com.badlogic.gdx.scenes.scene2d.ui.ProgressBar) StyleData(com.ray3k.skincomposer.data.StyleData) ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Window(com.badlogic.gdx.scenes.scene2d.ui.Window) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) LabelStyle(com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle) TextFieldStyle(com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldStyle) CustomStyle(com.ray3k.skincomposer.data.CustomStyle) Array(com.badlogic.gdx.utils.Array) ColorData(com.ray3k.skincomposer.data.ColorData) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) CustomProperty(com.ray3k.skincomposer.data.CustomProperty)

Example 2 with FreeTypeFontData

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

the class RootTable method createPreviewStyle.

private <T> T createPreviewStyle(Class<T> clazz, StyleData styleData) {
    T returnValue = null;
    try {
        returnValue = ClassReflection.newInstance(clazz);
        Field[] fields = ClassReflection.getFields(clazz);
        for (Field field : fields) {
            Object value = styleData.properties.get(field.getName()).value;
            if (value != null) {
                if (field.getType().equals(Drawable.class)) {
                    field.set(returnValue, drawablePairs.get((String) value));
                } else if (field.getType().equals(Color.class)) {
                    for (ColorData data : main.getProjectData().getJsonData().getColors()) {
                        if (value.equals(data.getName())) {
                            field.set(returnValue, data.color);
                            break;
                        }
                    }
                } else if (field.getType().equals(BitmapFont.class)) {
                    for (FontData data : main.getProjectData().getJsonData().getFonts()) {
                        if (value.equals(data.getName())) {
                            BitmapFont font = new BitmapFont(data.file);
                            previewFonts.add(font);
                            field.set(returnValue, font);
                        }
                    }
                    for (FreeTypeFontData data : main.getJsonData().getFreeTypeFonts()) {
                        if (value.equals(data.name)) {
                            field.set(returnValue, data.bitmapFont);
                        }
                    }
                } else if (field.getType().equals(Float.TYPE)) {
                    field.set(returnValue, (float) value);
                } else if (field.getType().equals(ListStyle.class)) {
                    Array<StyleData> datas = main.getProjectData().getJsonData().getClassStyleMap().get(List.class);
                    for (StyleData data : datas) {
                        if (value.equals(data.name)) {
                            ListStyle style = createPreviewStyle(ListStyle.class, data);
                            field.set(returnValue, style);
                            break;
                        }
                    }
                } else if (field.getType().equals(ScrollPaneStyle.class)) {
                    Array<StyleData> datas = main.getProjectData().getJsonData().getClassStyleMap().get(ScrollPane.class);
                    for (StyleData data : datas) {
                        if (value.equals(data.name)) {
                            ScrollPaneStyle style = createPreviewStyle(ScrollPaneStyle.class, data);
                            field.set(returnValue, style);
                            break;
                        }
                    }
                } else if (field.getType().equals(LabelStyle.class)) {
                    Array<StyleData> datas = main.getProjectData().getJsonData().getClassStyleMap().get(Label.class);
                    for (StyleData data : datas) {
                        if (value.equals(data.name)) {
                            LabelStyle style = createPreviewStyle(LabelStyle.class, data);
                            field.set(returnValue, style);
                            break;
                        }
                    }
                }
            }
        }
    } finally {
        return returnValue;
    }
}
Also used : ListStyle(com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle) Color(com.badlogic.gdx.graphics.Color) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) FontData(com.ray3k.skincomposer.data.FontData) LabelStyle(com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle) ColorData(com.ray3k.skincomposer.data.ColorData) Array(com.badlogic.gdx.utils.Array) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Field(com.badlogic.gdx.utils.reflect.Field) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) StyleData(com.ray3k.skincomposer.data.StyleData) ScrollPaneStyle(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.ScrollPaneStyle)

Example 3 with FreeTypeFontData

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

the class RootTable method addStyleProperties.

private void addStyleProperties(final Table left) {
    Label label = new Label("Style Properties", getSkin(), "title");
    left.add(label);
    left.row();
    Table table = new Table();
    table.defaults().padLeft(10.0f).padRight(10.0f).growX();
    stylePropertiesScrollPane = new ScrollPane(table, getSkin());
    stylePropertiesScrollPane.setFadeScrollBars(false);
    stylePropertiesScrollPane.setFlickScroll(false);
    stylePropertiesScrollPane.addListener(scrollPaneListener);
    stage.setScrollFocus(stylePropertiesScrollPane);
    left.add(stylePropertiesScrollPane).grow().padTop(10.0f).padBottom(10.0f);
    // gather all scrollPaneStyles
    Array<StyleData> scrollPaneStyles = main.getProjectData().getJsonData().getClassStyleMap().get(ScrollPane.class);
    // gather all listStyles
    Array<StyleData> listStyles = main.getProjectData().getJsonData().getClassStyleMap().get(List.class);
    // gather all labelStyles
    Array<StyleData> labelStyles = main.getProjectData().getJsonData().getClassStyleMap().get(Label.class);
    if (styleProperties != null) {
        for (StyleProperty styleProperty : styleProperties) {
            table.row();
            if (styleProperty.type == Color.class) {
                BrowseField browseField;
                if (styleProperty.optional) {
                    browseField = new BrowseField((String) styleProperty.value, styleProperty.name, getSkin(), "color");
                } else {
                    browseField = new BrowseField((String) styleProperty.value, styleProperty.name, getSkin(), "color-required");
                }
                browseField.addListener(main.getHandListener());
                table.add(browseField).padTop(20.0f);
                browseField.addListener(new StylePropertyChangeListener(styleProperty, browseField));
            } else if (styleProperty.type == BitmapFont.class) {
                BrowseField browseField;
                if (styleProperty.optional) {
                    browseField = new BrowseField((String) styleProperty.value, styleProperty.name, getSkin(), "font");
                } else {
                    browseField = new BrowseField((String) styleProperty.value, styleProperty.name, getSkin(), "font-required");
                }
                browseField.addListener(main.getHandListener());
                table.add(browseField).padTop(20.0f);
                browseField.addListener(new StylePropertyChangeListener(styleProperty, browseField));
            } else if (styleProperty.type == Drawable.class) {
                BrowseField browseField;
                if (styleProperty.optional) {
                    browseField = new BrowseField((String) styleProperty.value, styleProperty.name, getSkin(), "drawable");
                } else {
                    browseField = new BrowseField((String) styleProperty.value, styleProperty.name, getSkin(), "drawable-required");
                }
                browseField.addListener(main.getHandListener());
                table.add(browseField).padTop(20.0f);
                browseField.addListener(new StylePropertyChangeListener(styleProperty, browseField));
            } else if (styleProperty.type == Float.TYPE) {
                if (styleProperty.optional) {
                    label = new Label(styleProperty.name, getSkin());
                } else {
                    label = new Label(styleProperty.name, getSkin(), "required");
                }
                table.add(label).padTop(20.0f).fill(false).expand(false, false);
                table.row();
                Spinner spinner = new Spinner((Double) styleProperty.value, 1.0, false, Spinner.Orientation.HORIZONTAL, getSkin());
                spinner.getTextField().addListener(main.getIbeamListener());
                spinner.getButtonMinus().addListener(main.getHandListener());
                spinner.getButtonPlus().addListener(main.getHandListener());
                table.add(spinner);
                spinner.addListener(new StylePropertyChangeListener(styleProperty, spinner));
            } else if (styleProperty.type == ScrollPaneStyle.class) {
                if (styleProperty.optional) {
                    label = new Label(styleProperty.name, getSkin());
                } else {
                    label = new Label(styleProperty.name, getSkin(), "required");
                }
                table.add(label).padTop(20.0f).fill(false).expand(false, false);
                table.row();
                SelectBox<StyleData> selectBox = new SelectBox<>(getSkin());
                selectBox.setItems(scrollPaneStyles);
                selectBox.addListener(main.getHandListener());
                selectBox.getList().addListener(main.getHandListener());
                if (styleProperty.value != null) {
                    String name = ((String) styleProperty.value);
                    int index = 0;
                    for (StyleData styleData : scrollPaneStyles) {
                        if (styleData.name.equals(name)) {
                            break;
                        } else {
                            index++;
                        }
                    }
                    if (index < scrollPaneStyles.size) {
                        selectBox.setSelectedIndex(index);
                    }
                }
                table.add(selectBox);
                selectBox.addListener(new StylePropertyChangeListener(styleProperty, selectBox));
            } else if (styleProperty.type == ListStyle.class) {
                if (styleProperty.optional) {
                    label = new Label(styleProperty.name, getSkin());
                } else {
                    label = new Label(styleProperty.name, getSkin(), "required");
                }
                table.add(label).padTop(20.0f).fill(false).expand(false, false);
                table.row();
                SelectBox<StyleData> selectBox = new SelectBox<>(getSkin());
                selectBox.setItems(listStyles);
                selectBox.addListener(main.getHandListener());
                selectBox.getList().addListener(main.getHandListener());
                if (styleProperty.value != null) {
                    String name = ((String) styleProperty.value);
                    int index = 0;
                    for (StyleData styleData : listStyles) {
                        if (styleData.name.equals(name)) {
                            break;
                        } else {
                            index++;
                        }
                    }
                    if (index < listStyles.size) {
                        selectBox.setSelectedIndex(index);
                    }
                }
                table.add(selectBox);
                selectBox.addListener(new StylePropertyChangeListener(styleProperty, selectBox));
            } else if (styleProperty.type == LabelStyle.class) {
                if (styleProperty.optional) {
                    label = new Label(styleProperty.name, getSkin());
                } else {
                    label = new Label(styleProperty.name, getSkin(), "required");
                }
                table.add(label).padTop(20.0f).fill(false).expand(false, false);
                table.row();
                SelectBox<StyleData> selectBox = new SelectBox<>(getSkin());
                selectBox.setItems(labelStyles);
                selectBox.addListener(main.getHandListener());
                selectBox.getList().addListener(main.getHandListener());
                if (styleProperty.value != null) {
                    String name = ((String) styleProperty.value);
                    int index = 0;
                    for (StyleData styleData : labelStyles) {
                        if (styleData.name.equals(name)) {
                            break;
                        } else {
                            index++;
                        }
                    }
                    if (index < labelStyles.size) {
                        selectBox.setSelectedIndex(index);
                    }
                }
                table.add(selectBox);
                selectBox.addListener(new StylePropertyChangeListener(styleProperty, selectBox));
            }
            table.row();
        }
    } else if (customProperties != null) {
        for (CustomProperty styleProperty : customProperties) {
            if (styleProperty.getType() == PropertyType.COLOR) {
                String value = "";
                if (styleProperty.getValue() instanceof String) {
                    for (ColorData color : main.getJsonData().getColors()) {
                        if (color.getName().equals(styleProperty.getValue())) {
                            value = (String) styleProperty.getValue();
                            break;
                        }
                    }
                }
                BrowseField browseField = new BrowseField(value, styleProperty.getName(), getSkin(), "color");
                browseField.addListener(main.getHandListener());
                table.add(browseField).padTop(20.0f);
                browseField.addListener(new CustomPropertyChangeListener(styleProperty, browseField));
            } else if (styleProperty.getType() == PropertyType.FONT) {
                String value = "";
                if (styleProperty.getValue() instanceof String) {
                    for (FontData font : main.getJsonData().getFonts()) {
                        if (font.getName().equals(styleProperty.getValue())) {
                            value = (String) styleProperty.getValue();
                            break;
                        }
                    }
                    for (FreeTypeFontData font : main.getJsonData().getFreeTypeFonts()) {
                        System.out.println("hit");
                        if (font.name.equals(styleProperty.getValue())) {
                            value = (String) styleProperty.getValue();
                        }
                    }
                }
                BrowseField browseField = new BrowseField(value, styleProperty.getName(), getSkin(), "font");
                browseField.addListener(main.getHandListener());
                table.add(browseField).padTop(20.0f);
                browseField.addListener(new CustomPropertyChangeListener(styleProperty, browseField));
            } else if (styleProperty.getType() == PropertyType.DRAWABLE) {
                String value = "";
                if (styleProperty.getValue() instanceof String) {
                    for (DrawableData drawable : main.getAtlasData().getDrawables()) {
                        if (drawable.name.equals(styleProperty.getValue())) {
                            value = (String) styleProperty.getValue();
                            break;
                        }
                    }
                }
                BrowseField browseField = new BrowseField(value, styleProperty.getName(), getSkin(), "drawable");
                browseField.addListener(main.getHandListener());
                table.add(browseField).padTop(20.0f);
                browseField.addListener(new CustomPropertyChangeListener(styleProperty, browseField));
            } else if (styleProperty.getType() == PropertyType.NUMBER) {
                label = new Label(styleProperty.getName(), getSkin());
                table.add(label).padTop(20.0f).fill(false).expand(false, false);
                table.row();
                if (styleProperty.getValue() instanceof Float) {
                    styleProperty.setValue((double) (float) styleProperty.getValue());
                }
                Double value = 0.0;
                if (styleProperty.getValue() instanceof Double) {
                    value = (Double) styleProperty.getValue();
                }
                Spinner spinner = new Spinner(value, 1.0, false, Spinner.Orientation.HORIZONTAL, getSkin());
                spinner.setRound(false);
                spinner.getTextField().addListener(main.getIbeamListener());
                spinner.getButtonMinus().addListener(main.getHandListener());
                spinner.getButtonPlus().addListener(main.getHandListener());
                table.add(spinner);
                spinner.addListener(new CustomPropertyChangeListener(styleProperty, spinner));
            } else if (styleProperty.getType() == PropertyType.TEXT || styleProperty.getType() == PropertyType.RAW_TEXT) {
                label = new Label(styleProperty.getName(), getSkin());
                table.add(label).padTop(20.0f).fill(false).expand(false, false);
                table.row();
                String value = "";
                if (styleProperty.getValue() instanceof String) {
                    value = (String) styleProperty.getValue();
                }
                TextField textField = new TextField(value, getSkin());
                textField.setAlignment(Align.center);
                textField.addListener(main.getIbeamListener());
                table.add(textField);
                textField.addListener(new CustomPropertyChangeListener(styleProperty, textField));
            } else if (styleProperty.getType() == PropertyType.BOOL) {
                label = new Label(styleProperty.getName(), getSkin());
                table.add(label).padTop(20.0f).fill(false).expand(false, false);
                table.row();
                Button button = new Button(getSkin(), "switch");
                boolean value = false;
                if (styleProperty.getValue() instanceof Boolean) {
                    value = (boolean) styleProperty.getValue();
                }
                button.setChecked(value);
                table.add(button).fill(false);
                button.addListener(new CustomPropertyChangeListener(styleProperty, button));
            }
            Button duplicateButton = new Button(getSkin(), "duplicate");
            table.add(duplicateButton).fill(false).expand(false, false).pad(0).bottom();
            duplicateButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    fire(new CustomPropertyEvent(styleProperty, duplicateButton, CustomPropertyEnum.DUPLICATE));
                }
            });
            TextTooltip toolTip = new TextTooltip("Duplicate Style Property", main.getTooltipManager(), getSkin());
            duplicateButton.addListener(toolTip);
            Button deleteButton = new Button(getSkin(), "delete");
            table.add(deleteButton).fill(false).expand(false, false).pad(0).bottom();
            deleteButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    fire(new CustomPropertyEvent(styleProperty, duplicateButton, CustomPropertyEnum.DELETE));
                }
            });
            toolTip = new TextTooltip("Delete Style Property", main.getTooltipManager(), getSkin());
            deleteButton.addListener(toolTip);
            Button renameButton = new Button(getSkin(), "settings");
            table.add(renameButton).fill(false).expand(false, false).pad(0).bottom();
            renameButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    fire(new CustomPropertyEvent(styleProperty, duplicateButton, CustomPropertyEnum.RENAME));
                }
            });
            toolTip = new TextTooltip("Rename Style Property", main.getTooltipManager(), getSkin());
            renameButton.addListener(toolTip);
            table.row();
        }
        left.row();
        table = new Table();
        left.add(table).right().padBottom(10.0f);
        Button button = new Button(getSkin(), "new");
        button.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                fire(new CustomPropertyEvent(null, null, CustomPropertyEnum.NEW));
            }
        });
        table.add(button);
        TextTooltip toolTip = new TextTooltip("New Style Property", main.getTooltipManager(), getSkin());
        button.addListener(toolTip);
    }
}
Also used : ListStyle(com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) DrawableData(com.ray3k.skincomposer.data.DrawableData) TextTooltip(com.badlogic.gdx.scenes.scene2d.ui.TextTooltip) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) StyleData(com.ray3k.skincomposer.data.StyleData) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) SelectBox(com.badlogic.gdx.scenes.scene2d.ui.SelectBox) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) FontData(com.ray3k.skincomposer.data.FontData) StyleProperty(com.ray3k.skincomposer.data.StyleProperty) ColorData(com.ray3k.skincomposer.data.ColorData) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) CustomProperty(com.ray3k.skincomposer.data.CustomProperty)

Example 4 with FreeTypeFontData

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

the class DialogFonts method result.

@Override
protected void result(Object object) {
    if (styleProperty != null) {
        if (object instanceof FontData) {
            main.getProjectData().setChangesSaved(false);
            FontData font = (FontData) object;
            FontUndoable undoable = new FontUndoable(main.getRootTable(), main.getJsonData(), styleProperty, styleProperty.value, font.getName());
            main.getUndoableManager().addUndoable(undoable, true);
        } else if (object instanceof FreeTypeFontData) {
            main.getProjectData().setChangesSaved(false);
            FreeTypeFontData font = (FreeTypeFontData) object;
            FontUndoable undoable = new FontUndoable(main.getRootTable(), main.getJsonData(), styleProperty, styleProperty.value, font.name);
            main.getUndoableManager().addUndoable(undoable, true);
        } else if (object instanceof Boolean) {
            if ((boolean) object) {
                FontUndoable undoable = new FontUndoable(main.getRootTable(), main.getJsonData(), styleProperty, styleProperty.value, null);
                main.getUndoableManager().addUndoable(undoable, true);
                main.getProjectData().setChangesSaved(false);
                main.getRootTable().setStatusBarMessage("Drawable emptied for \"" + styleProperty.name + "\"");
                main.getRootTable().refreshStyleProperties(true);
            } else {
                boolean hasFont = false;
                for (FontData font : main.getJsonData().getFonts()) {
                    if (font.getName().equals(styleProperty.value)) {
                        hasFont = true;
                        break;
                    }
                }
                for (FreeTypeFontData font : main.getJsonData().getFreeTypeFonts()) {
                    if (font.name.equals(styleProperty.value)) {
                        hasFont = true;
                        break;
                    }
                }
                if (!hasFont) {
                    styleProperty.value = null;
                    main.getProjectData().setChangesSaved(false);
                    main.getRootTable().setStatusBarMessage("Drawable deleted for \"" + styleProperty.name + "\"");
                    main.getRootTable().refreshStyleProperties(true);
                }
            }
        }
    } else if (customProperty != null) {
        if (object instanceof FontData) {
            main.getProjectData().setChangesSaved(false);
            FontData font = (FontData) object;
            CustomFontUndoable undoable = new CustomFontUndoable(main, customProperty, font.getName());
            main.getUndoableManager().addUndoable(undoable, true);
        } else if (object instanceof FreeTypeFontData) {
            main.getProjectData().setChangesSaved(false);
            FreeTypeFontData font = (FreeTypeFontData) object;
            CustomFontUndoable undoable = new CustomFontUndoable(main, customProperty, font.name);
            main.getUndoableManager().addUndoable(undoable, true);
        } else if (object instanceof Boolean) {
            if ((boolean) object) {
                CustomFontUndoable undoable = new CustomFontUndoable(main, customProperty, null);
                main.getUndoableManager().addUndoable(undoable, true);
                main.getProjectData().setChangesSaved(false);
                main.getRootTable().setStatusBarMessage("Drawable emptied for \"" + customProperty.getName() + "\"");
                main.getRootTable().refreshStyleProperties(true);
            } else {
                boolean hasFont = false;
                for (FontData font : main.getJsonData().getFonts()) {
                    if (font.getName().equals(customProperty.getValue())) {
                        hasFont = true;
                        break;
                    }
                }
                if (!hasFont) {
                    customProperty.setValue(null);
                    main.getProjectData().setChangesSaved(false);
                    main.getRootTable().setStatusBarMessage("Drawable deleted for \"" + customProperty.getName() + "\"");
                    main.getRootTable().refreshStyleProperties(true);
                }
            }
        }
    }
    if (listener != null) {
        listener.handle(null);
    }
    main.getRootTable().refreshPreview();
}
Also used : CustomFontUndoable(com.ray3k.skincomposer.UndoableManager.CustomFontUndoable) FontUndoable(com.ray3k.skincomposer.UndoableManager.FontUndoable) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) FontData(com.ray3k.skincomposer.data.FontData) BitmapFontData(com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData) CustomFontUndoable(com.ray3k.skincomposer.UndoableManager.CustomFontUndoable)

Example 5 with FreeTypeFontData

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

the class DialogFonts method refreshTable.

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

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

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

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

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

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

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

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

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

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

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

Aggregations

FontData (com.ray3k.skincomposer.data.FontData)7 FreeTypeFontData (com.ray3k.skincomposer.data.FreeTypeFontData)7 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)4 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)4 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)4 Array (com.badlogic.gdx.utils.Array)4 StyleData (com.ray3k.skincomposer.data.StyleData)4 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)3 Actor (com.badlogic.gdx.scenes.scene2d.Actor)3 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)3 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)3 LabelStyle (com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle)3 ListStyle (com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle)3 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)3 SelectBox (com.badlogic.gdx.scenes.scene2d.ui.SelectBox)3 TextTooltip (com.badlogic.gdx.scenes.scene2d.ui.TextTooltip)3 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)3 ColorData (com.ray3k.skincomposer.data.ColorData)3 DrawableData (com.ray3k.skincomposer.data.DrawableData)3 FileHandle (com.badlogic.gdx.files.FileHandle)2