use of org.terasology.rendering.nui.widgets.treeView.JsonTreeValue in project Terasology by MovingBlocks.
the class WidgetSelectionScreen method initialise.
@Override
public void initialise() {
availableWidgets = find("availableWidgets", UIDropdownScrollable.class);
// Populate the widget list.
ClassLibrary<UIWidget> metadataLibrary = getManager().getWidgetMetadataLibrary();
for (ClassMetadata metadata : metadataLibrary) {
if (!CoreScreenLayer.class.isAssignableFrom(metadata.getType())) {
widgets.put(metadata.toString(), metadata);
}
}
List<String> options = Lists.newArrayList(widgets.keySet());
Collections.sort(options);
availableWidgets.setOptions(options);
// Add the widget as a child of the node.
WidgetUtil.trySubscribe(this, "ok", button -> {
String selection = availableWidgets.getSelection();
JsonTree childNode;
if (node.getValue().getType() == JsonTreeValue.Type.ARRAY) {
ClassMetadata metadata = widgets.get(selection);
// Get the widget tree from a utility method.
childNode = NUIEditorNodeUtils.createNewWidget(selection, "newWidget", false);
// If the widget is an UILayout override, also add a "contents" array node to the tree.
if (UILayout.class.isAssignableFrom(metadata.getType())) {
childNode.addChild(new JsonTreeValue("contents", null, JsonTreeValue.Type.ARRAY));
}
} else {
childNode = new JsonTree(new JsonTreeValue(selection, null, JsonTreeValue.Type.OBJECT));
childNode.setExpanded(true);
}
node.addChild(childNode);
closeListeners.forEach(UpdateListener::onAction);
getManager().closeScreen(ASSET_URI);
});
find("ok", UIButton.class).bindEnabled(new ReadOnlyBinding<Boolean>() {
@Override
public Boolean get() {
return availableWidgets.getSelection() != null;
}
});
WidgetUtil.trySubscribe(this, "cancel", button -> getManager().closeScreen(ASSET_URI));
}
use of org.terasology.rendering.nui.widgets.treeView.JsonTreeValue 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;
}
use of org.terasology.rendering.nui.widgets.treeView.JsonTreeValue 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;
}
use of org.terasology.rendering.nui.widgets.treeView.JsonTreeValue 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;
}
use of org.terasology.rendering.nui.widgets.treeView.JsonTreeValue 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;
}
Aggregations