Search in sources :

Example 6 with JsonTree

use of org.terasology.nui.widgets.treeView.JsonTree in project Terasology by MovingBlocks.

the class NUIEditorNodeUtils method createNewSkin.

/**
 * @return The {@link JsonTree} to be used as an initial skin template within {@link NUISkinEditorScreen}.
 */
public static JsonTree createNewSkin() {
    JsonTree tree = new JsonTree(new JsonTreeValue(null, null, JsonTreeValue.Type.OBJECT));
    tree.addChild(new JsonTreeValue("inherit", "default", JsonTreeValue.Type.KEY_VALUE_PAIR));
    tree.addChild(new JsonTreeValue("elements", null, JsonTreeValue.Type.OBJECT));
    tree.addChild(new JsonTreeValue("families", null, JsonTreeValue.Type.OBJECT));
    return tree;
}
Also used : JsonTreeValue(org.terasology.nui.widgets.treeView.JsonTreeValue) JsonTree(org.terasology.nui.widgets.treeView.JsonTree)

Example 7 with JsonTree

use of org.terasology.nui.widgets.treeView.JsonTree in project Terasology by MovingBlocks.

the class NUIEditorMenuTreeBuilder method createAddContextMenu.

public MenuTree createAddContextMenu(JsonTree node) {
    MenuTree addTree = new MenuTree(OPTION_ADD_EXTENDED);
    JsonTreeValue.Type type = node.getValue().getType();
    if (type == JsonTreeValue.Type.ARRAY) {
        // Add generic item addition options.
        addTree.addOption("Boolean value", n -> {
            JsonTree child = new JsonTree(new JsonTreeValue(null, false, JsonTreeValue.Type.VALUE));
            n.addChild(child);
            for (Consumer<JsonTree> listener : addContextMenuListeners) {
                listener.accept(child);
            }
        }, node);
        addTree.addOption("Number value", n -> {
            JsonTree child = new JsonTree((new JsonTreeValue(null, 0.0f, JsonTreeValue.Type.VALUE)));
            n.addChild(child);
            for (Consumer<JsonTree> listener : addContextMenuListeners) {
                listener.accept(n);
            }
        }, node);
        addTree.addOption("String value", n -> {
            JsonTree child = new JsonTree((new JsonTreeValue(null, "", JsonTreeValue.Type.VALUE)));
            n.addChild(child);
            for (Consumer<JsonTree> listener : addContextMenuListeners) {
                listener.accept(child);
            }
        }, node);
    } else if (type == JsonTreeValue.Type.OBJECT) {
        // Add a generic key/value pair addition option.
        addTree.addOption("Key/value pair", n -> {
            JsonTree child = new JsonTree((new JsonTreeValue("", "", JsonTreeValue.Type.KEY_VALUE_PAIR)));
            n.addChild(child);
            for (Consumer<JsonTree> listener : addContextMenuListeners) {
                listener.accept(child);
            }
        }, node);
        populateContextMenu(node, addTree, false);
    }
    return addTree;
}
Also used : MenuTree(org.terasology.engine.rendering.nui.contextMenu.MenuTree) JsonTreeValue(org.terasology.nui.widgets.treeView.JsonTreeValue) Color(org.terasology.nui.Color) UILayout(org.terasology.nui.UILayout) LoggerFactory(org.slf4j.LoggerFactory) Lists(com.google.common.collect.Lists) LayoutConfig(org.terasology.nui.LayoutConfig) UITextureRegion(org.terasology.nui.UITextureRegion) AbstractWidget(org.terasology.nui.AbstractWidget) Map(java.util.Map) MenuTree(org.terasology.engine.rendering.nui.contextMenu.MenuTree) Font(org.terasology.nui.asset.font.Font) JsonTree(org.terasology.nui.widgets.treeView.JsonTree) Binding(org.terasology.nui.databinding.Binding) Logger(org.slf4j.Logger) UISkin(org.terasology.nui.skin.UISkin) SerializedName(com.google.gson.annotations.SerializedName) Field(java.lang.reflect.Field) Maps(com.google.common.collect.Maps) UIWidget(org.terasology.nui.UIWidget) NUIManager(org.terasology.engine.rendering.nui.NUIManager) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) Border(org.terasology.nui.Border) ParameterizedType(java.lang.reflect.ParameterizedType) Modifier(java.lang.reflect.Modifier) Optional(java.util.Optional) ReflectionUtils(org.reflections.ReflectionUtils) JsonTreeValue(org.terasology.nui.widgets.treeView.JsonTreeValue) Consumer(java.util.function.Consumer) JsonTree(org.terasology.nui.widgets.treeView.JsonTree)

Example 8 with JsonTree

use of org.terasology.nui.widgets.treeView.JsonTree in project Terasology by MovingBlocks.

the class NUIEditorMenuTreeBuilder method createWidgetChild.

private void createWidgetChild(String name, JsonTree node) {
    JsonTree widgetTree = new JsonTree(new JsonTreeValue(name, null, JsonTreeValue.Type.OBJECT));
    NUIEditorNodeUtils.createNewWidget("UILabel", "newWidget", false).getChildren().forEach(widgetTree::addChild);
    widgetTree.addChild(new JsonTreeValue("text", "", JsonTreeValue.Type.KEY_VALUE_PAIR));
    node.addChild(widgetTree);
}
Also used : JsonTreeValue(org.terasology.nui.widgets.treeView.JsonTreeValue) JsonTree(org.terasology.nui.widgets.treeView.JsonTree)

Example 9 with JsonTree

use of org.terasology.nui.widgets.treeView.JsonTree in project Terasology by MovingBlocks.

the class NUIEditorMenuTreeBuilder method createAddSkinContextMenu.

public MenuTree createAddSkinContextMenu(JsonTree node) {
    MenuTree addTree = new MenuTree(OPTION_ADD_EXTENDED);
    JsonTreeValue.Type type = node.getValue().getType();
    if (type == JsonTreeValue.Type.OBJECT) {
        if ("families".equals(node.getValue().getKey())) {
            // Add an option to add a family for a "families" node.
            addTree.addOption("New family", n -> {
                JsonTree child = new JsonTree(new JsonTreeValue("", null, JsonTreeValue.Type.OBJECT));
                child.setExpanded(true);
                n.addChild(child);
                for (Consumer<JsonTree> listener : addContextMenuListeners) {
                    listener.accept(child);
                }
            }, node);
        } else {
            addTree.addOption("Key/value pair", n -> {
                JsonTree child = new JsonTree((new JsonTreeValue("", "", JsonTreeValue.Type.KEY_VALUE_PAIR)));
                n.addChild(child);
                for (Consumer<JsonTree> listener : addContextMenuListeners) {
                    listener.accept(child);
                }
            }, node);
            populateContextMenu(node, addTree, true);
        }
    }
    return addTree;
}
Also used : MenuTree(org.terasology.engine.rendering.nui.contextMenu.MenuTree) JsonTreeValue(org.terasology.nui.widgets.treeView.JsonTreeValue) JsonTree(org.terasology.nui.widgets.treeView.JsonTree)

Example 10 with JsonTree

use of org.terasology.nui.widgets.treeView.JsonTree in project Terasology by MovingBlocks.

the class NUIEditorMenuTreeBuilder method createChild.

private JsonTree createChild(String name, JsonTree node, Field field, Class clazz) throws IllegalAccessException, InstantiationException {
    JsonTreeValue childValue = new JsonTreeValue();
    childValue.setKey(name);
    if (UISkin.class.isAssignableFrom(field.getType())) {
        // Skin fields should always be KEY_VALUE_PAIR nodes with string values.
        childValue.setValue("engine:default");
        childValue.setType(JsonTreeValue.Type.KEY_VALUE_PAIR);
    } else {
        if (isWidget(field)) {
            createWidgetChild(name, node);
            return null;
        } else {
            childValue.setValue(getFieldValue(field, clazz));
            childValue.setType(getNodeType(field, getFieldValue(field, clazz)));
        }
    }
    JsonTree child = new JsonTree(childValue);
    child.setExpanded(true);
    node.addChild(child);
    return child;
}
Also used : JsonTreeValue(org.terasology.nui.widgets.treeView.JsonTreeValue) JsonTree(org.terasology.nui.widgets.treeView.JsonTree)

Aggregations

JsonTree (org.terasology.nui.widgets.treeView.JsonTree)27 JsonTreeValue (org.terasology.nui.widgets.treeView.JsonTreeValue)14 JsonParser (com.google.gson.JsonParser)9 JsonElement (com.google.gson.JsonElement)6 JsonObject (com.google.gson.JsonObject)5 JsonSyntaxException (com.google.gson.JsonSyntaxException)5 Map (java.util.Map)5 UIWidget (org.terasology.nui.UIWidget)5 Gson (com.google.gson.Gson)4 JsonPrimitive (com.google.gson.JsonPrimitive)4 JsonReader (com.google.gson.stream.JsonReader)4 IOException (java.io.IOException)4 InputStreamReader (java.io.InputStreamReader)4 UITextEntry (org.terasology.nui.widgets.UITextEntry)4 Optional (java.util.Optional)3 AssetDataFile (org.terasology.gestalt.assets.format.AssetDataFile)3 UILayout (org.terasology.nui.UILayout)3 Field (java.lang.reflect.Field)2 Set (java.util.Set)2 MenuTree (org.terasology.engine.rendering.nui.contextMenu.MenuTree)2