Fix layoutInfo conditions
import org.terasology.rendering.nui.Color;
import org.terasology.rendering.nui.LayoutConfig;
import org.terasology.rendering.nui.NUIManager;
+import org.terasology.rendering.nui.UILayout;
import org.terasology.rendering.nui.UIWidget;
import org.terasology.rendering.nui.contextMenu.MenuTree;
import org.terasology.rendering.nui.databinding.Binding;
@@ -250,9 +251,18 @@ private void populateContextMenu(JsonTree node, MenuTree addTree, boolean isSkin
}
}
// If the node is part of a layout, add an option to add the layoutInfo node.
- if (nodeInfo.getLayoutClass() != null) {
+ if (!node.isRoot() && !node.getParent().isRoot()) {
String layoutInfo = "layoutInfo";
- if (!Objects.equals(node.getValue().getKey(), layoutInfo) && !node.hasChildWithKey(layoutInfo)) {
+ String contents = "contents";
+ Class parentParentClass = NUIEditorNodeUtils
+ .getNodeInfo((JsonTree) node.getParent().getParent(), nuiManager)
+ .getNodeClass();
+ if (!node.hasChildWithKey(layoutInfo)
+ && UIWidget.class.isAssignableFrom(clazz)
+ && node.getParent().getValue() != null
+ && node.getParent().getValue().getKey() != null
+ && node.getParent().getValue().getKey().equals(contents)
+ && UILayout.class.isAssignableFrom(parentParentClass)) {
addTree.addOption(layoutInfo, n -> {
JsonTree child = new JsonTree(new JsonTreeValue(layoutInfo, null, JsonTreeValue.Type.OBJECT));
child.setExpanded(true);
