use of org.terasology.rendering.nui.contextMenu.MenuTree 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.contextMenu.MenuTree 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.contextMenu.MenuTree in project Terasology by MovingBlocks.
the class NUIEditorMenuTreeBuilder method createPrimaryContextMenu.
public MenuTree createPrimaryContextMenu(JsonTree node) {
MenuTree primaryTree = new MenuTree(null);
JsonTreeValue.Type type = node.getValue().getType();
// Create the ADD_EXTENDED level.
if ((type == JsonTreeValue.Type.ARRAY && !"contents".equals(node.getValue().getKey())) || type == JsonTreeValue.Type.OBJECT) {
MenuTree addTree = createAddContextMenu(node);
primaryTree.addSubmenu(addTree);
}
// If the node is a "contents" array, add the widget addition option (redirects to WidgetSelectionScreen).
if (type == JsonTreeValue.Type.ARRAY && "contents".equals(node.getValue().getKey())) {
primaryTree.addOption(OPTION_ADD_WIDGET, externalConsumers.get(OPTION_ADD_WIDGET), node);
}
// Always add the copy&paste options.
primaryTree.addOption(OPTION_COPY, externalConsumers.get(OPTION_COPY), node);
primaryTree.addOption(OPTION_PASTE, externalConsumers.get(OPTION_PASTE), node);
// Unless the node is an OBJECT child of an ARRAY (should always have an empty key), add the edit option.
if (type != JsonTreeValue.Type.NULL && !(type == JsonTreeValue.Type.OBJECT && !node.isRoot() && node.getParent().getValue().getType() == JsonTreeValue.Type.ARRAY)) {
primaryTree.addOption(OPTION_EDIT, externalConsumers.get(OPTION_EDIT), node);
}
if (!node.isRoot()) {
primaryTree.addOption(OPTION_DELETE, externalConsumers.get(OPTION_DELETE), node);
}
return primaryTree;
}
use of org.terasology.rendering.nui.contextMenu.MenuTree in project Terasology by MovingBlocks.
the class NUIEditorMenuTreeBuilder method createPrimarySkinContextMenu.
public MenuTree createPrimarySkinContextMenu(JsonTree node) {
MenuTree primaryTree = new MenuTree(null);
JsonTreeValue.Type type = node.getValue().getType();
// Create the ADD_EXTENDED level.
if (type == JsonTreeValue.Type.ARRAY || (type == JsonTreeValue.Type.OBJECT && !"elements".equals(node.getValue().getKey()))) {
MenuTree addTree = createAddSkinContextMenu(node);
primaryTree.addSubmenu(addTree);
}
// If the node is an "elements" object, add the widget addition option (redirects to WidgetSelectionScreen).
if (type == JsonTreeValue.Type.OBJECT && "elements".equals(node.getValue().getKey())) {
primaryTree.addOption(OPTION_ADD_WIDGET, externalConsumers.get(OPTION_ADD_WIDGET), node);
}
// Always add the copy&paste and edit options.
primaryTree.addOption(OPTION_COPY, externalConsumers.get(OPTION_COPY), node);
primaryTree.addOption(OPTION_PASTE, externalConsumers.get(OPTION_PASTE), node);
primaryTree.addOption(OPTION_EDIT, externalConsumers.get(OPTION_EDIT), node);
return primaryTree;
}
use of org.terasology.rendering.nui.contextMenu.MenuTree in project Terasology by MovingBlocks.
the class JsonEditorTreeView method setEditor.
public void setEditor(Consumer<JsonTree> editorFunction, NUIManager manager) {
// Create and display a context menu on RMB.
subscribeNodeClick((event, node) -> {
if (event.getMouseButton() == MouseInput.MOUSE_RIGHT) {
setSelectedIndex(getModel().indexOf(node));
setAlternativeWidget(null);
MenuTree menuTree = contextMenuTreeProducer.apply((JsonTree) node);
ContextMenuUtils.showContextMenu(manager, event.getMouse().getPosition(), menuTree);
}
});
// Edit a node on double click.
subscribeNodeDoubleClick((event, node) -> {
if (event.getMouseButton() == MouseInput.MOUSE_LEFT) {
editorFunction.accept((JsonTree) node);
}
});
// Edit the currently selected node on F2.
subscribeKeyEvent(event -> {
if (event.isDown() && event.getKey() == Keyboard.Key.F2) {
Integer selectedIndex = getSelectedIndex();
if (selectedIndex != null) {
editorFunction.accept((JsonTree) getModel().getNode(selectedIndex));
}
}
});
}
Aggregations