use of org.terasology.rendering.nui.widgets.treeView.JsonTreeValue 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;
}
use of org.terasology.rendering.nui.widgets.treeView.JsonTreeValue 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);
}
use of org.terasology.rendering.nui.widgets.treeView.JsonTreeValue 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);
}
use of org.terasology.rendering.nui.widgets.treeView.JsonTreeValue in project Terasology by MovingBlocks.
the class NUIEditorItemRenderer method getTexture.
@Override
public Texture getTexture(JsonTreeValue value) {
String textureName = null;
if (value.getType() == JsonTreeValue.Type.KEY_VALUE_PAIR) {
textureName = ATTRIBUTE_TEXTURE_NAME;
} else if (value.getType() == JsonTreeValue.Type.OBJECT) {
JsonTree node = (JsonTree) editorTreeViewModel.getNodeByValue(value);
// If the node has a "type": "..." child, retrieve the texture by the type name.
if (node != null) {
// If the node has no type and is a root node, do not draw an icon.
if (node.isRoot()) {
return null;
} else if (!node.isRoot() && "elements".equals(node.getParent().getValue().getKey())) {
textureName = node.getValue().getKey();
} else {
for (Tree<JsonTreeValue> child : node.getChildren()) {
JsonTreeValue childValue = child.getValue();
if (childValue.getType() == JsonTreeValue.Type.KEY_VALUE_PAIR && "type".equals(childValue.getKey())) {
textureName = (String) childValue.getValue();
}
}
}
}
// Otherwise use the default texture.
if (textureName == null) {
textureName = OBJECT_TEXTURE_NAME;
}
} else if (value.getType() == JsonTreeValue.Type.ARRAY) {
textureName = ARRAY_TEXTURE_NAME;
} else if (value.getKey() != null) {
textureName = value.getKey();
} else {
return null;
}
Optional<Texture> texture = Assets.getTexture(textureName != null ? String.format("engine:editor_%s", textureName) : ICON_BLANK);
return texture.isPresent() ? texture.get() : null;
}
use of org.terasology.rendering.nui.widgets.treeView.JsonTreeValue 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);
}
Aggregations