Search in sources :

Example 11 with JsonTree

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

the class NUIEditorNodeUtils method createNewScreen.

/**
 * @return The {@link JsonTree} to be used as an initial screen template within {@link NUIEditorScreen}.
 */
public static JsonTree createNewScreen() {
    JsonTree tree = new JsonTree(new JsonTreeValue(null, null, JsonTreeValue.Type.OBJECT));
    tree.addChild(new JsonTreeValue("type", "PlaceholderScreen", JsonTreeValue.Type.KEY_VALUE_PAIR));
    tree.addChild(new JsonTreeValue("skin", "engine:default", JsonTreeValue.Type.KEY_VALUE_PAIR));
    JsonTree layout = new JsonTree(new JsonTreeValue("contents", null, JsonTreeValue.Type.OBJECT));
    layout.addChild(new JsonTreeValue("type", "RelativeLayout", JsonTreeValue.Type.KEY_VALUE_PAIR));
    JsonTree contents = new JsonTree(new JsonTreeValue("contents", null, JsonTreeValue.Type.ARRAY));
    JsonTree label = createNewWidget("UILabel", "sampleLabel", true);
    label.addChild(new JsonTreeValue("text", SAMPLE_LABEL_TEXT, JsonTreeValue.Type.KEY_VALUE_PAIR));
    contents.addChild(label);
    layout.addChild(contents);
    tree.addChild(layout);
    return tree;
}
Also used : JsonTreeValue(org.terasology.rendering.nui.widgets.treeView.JsonTreeValue) JsonTree(org.terasology.rendering.nui.widgets.treeView.JsonTree)

Example 12 with JsonTree

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

the class NUIEditorTextEntryBuilder method createValueEditor.

/**
 * @return A {@link UITextEntry} to be used to edit a JSON value node.
 */
public static UITextEntry<JsonTree> createValueEditor() {
    UITextEntry.Formatter<JsonTree> formatter = value -> value.getValue().toString();
    UITextEntry.Parser<JsonTree> parser = value -> {
        try {
            Double valueDouble = Double.parseDouble(value);
            return new JsonTree(new JsonTreeValue(null, valueDouble, JsonTreeValue.Type.VALUE));
        } catch (NumberFormatException e) {
            if ("true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value)) {
                return new JsonTree(new JsonTreeValue(null, Boolean.parseBoolean(value), JsonTreeValue.Type.VALUE));
            } else {
                return new JsonTree(new JsonTreeValue(null, value, JsonTreeValue.Type.VALUE));
            }
        }
    };
    return createEditorEntry(formatter, parser);
}
Also used : JsonElement(com.google.gson.JsonElement) UITextEntry(org.terasology.rendering.nui.widgets.UITextEntry) JsonTreeValue(org.terasology.rendering.nui.widgets.treeView.JsonTreeValue) JsonObject(com.google.gson.JsonObject) JsonTree(org.terasology.rendering.nui.widgets.treeView.JsonTree) JsonSyntaxException(com.google.gson.JsonSyntaxException) Gson(com.google.gson.Gson) Map(java.util.Map) JsonPrimitive(com.google.gson.JsonPrimitive) JsonParser(com.google.gson.JsonParser) JsonTreeValue(org.terasology.rendering.nui.widgets.treeView.JsonTreeValue) JsonTree(org.terasology.rendering.nui.widgets.treeView.JsonTree) UITextEntry(org.terasology.rendering.nui.widgets.UITextEntry)

Example 13 with JsonTree

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

the class NUIEditorTextEntryBuilder method createArrayEditor.

/**
 * @return A {@link UITextEntry} to be used to edit a JSON array node.
 */
public static UITextEntry<JsonTree> createArrayEditor() {
    UITextEntry.Formatter<JsonTree> formatter = value -> value.getValue().getKey();
    UITextEntry.Parser<JsonTree> parser = value -> new JsonTree(new JsonTreeValue(value, null, JsonTreeValue.Type.ARRAY));
    return createEditorEntry(formatter, parser);
}
Also used : JsonElement(com.google.gson.JsonElement) UITextEntry(org.terasology.rendering.nui.widgets.UITextEntry) JsonTreeValue(org.terasology.rendering.nui.widgets.treeView.JsonTreeValue) JsonObject(com.google.gson.JsonObject) JsonTree(org.terasology.rendering.nui.widgets.treeView.JsonTree) JsonSyntaxException(com.google.gson.JsonSyntaxException) Gson(com.google.gson.Gson) Map(java.util.Map) JsonPrimitive(com.google.gson.JsonPrimitive) JsonParser(com.google.gson.JsonParser) JsonTreeValue(org.terasology.rendering.nui.widgets.treeView.JsonTreeValue) JsonTree(org.terasology.rendering.nui.widgets.treeView.JsonTree) UITextEntry(org.terasology.rendering.nui.widgets.UITextEntry)

Example 14 with JsonTree

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

the class JsonEditorTreeView method undo.

/**
 * Sets the widget's state to the previous item in the history.
 *
 * @return true if the widget's state was changed, false otherwise.
 */
public boolean undo() {
    if (historyPosition > 0) {
        historyPosition--;
        JsonTree node = (JsonTree) history.get(historyPosition).copy();
        setTreeViewModel(node, false);
        return true;
    }
    return false;
}
Also used : JsonTree(org.terasology.rendering.nui.widgets.treeView.JsonTree)

Example 15 with JsonTree

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

the class JsonEditorTreeView method redo.

/**
 * Sets the widget's state to the next item in the history.
 *
 * @return true if the widget's state was changed, false otherwise.
 */
public boolean redo() {
    if (historyPosition < history.size() - 1) {
        historyPosition++;
        JsonTree node = (JsonTree) history.get(historyPosition).copy();
        setTreeViewModel(node, false);
        return true;
    }
    return false;
}
Also used : JsonTree(org.terasology.rendering.nui.widgets.treeView.JsonTree)

Aggregations

JsonTree (org.terasology.rendering.nui.widgets.treeView.JsonTree)27 JsonTreeValue (org.terasology.rendering.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.rendering.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.rendering.nui.widgets.UITextEntry)4 Optional (java.util.Optional)3 AssetDataFile (org.terasology.assets.format.AssetDataFile)3 UISkin (org.terasology.rendering.nui.skin.UISkin)3 Field (java.lang.reflect.Field)2 Set (java.util.Set)2 UILayout (org.terasology.rendering.nui.UILayout)2