Search in sources :

Example 1 with MenuTree

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;
}
Also used : MenuTree(org.terasology.rendering.nui.contextMenu.MenuTree) JsonTreeValue(org.terasology.rendering.nui.widgets.treeView.JsonTreeValue) JsonTree(org.terasology.rendering.nui.widgets.treeView.JsonTree)

Example 2 with MenuTree

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;
}
Also used : MenuTree(org.terasology.rendering.nui.contextMenu.MenuTree) JsonTreeValue(org.terasology.rendering.nui.widgets.treeView.JsonTreeValue) UISkin(org.terasology.rendering.nui.skin.UISkin) LoggerFactory(org.slf4j.LoggerFactory) JsonTree(org.terasology.rendering.nui.widgets.treeView.JsonTree) Lists(com.google.common.collect.Lists) Map(java.util.Map) NUIManager(org.terasology.rendering.nui.NUIManager) Logger(org.slf4j.Logger) LayoutConfig(org.terasology.rendering.nui.LayoutConfig) UIWidget(org.terasology.rendering.nui.UIWidget) SerializedName(com.google.gson.annotations.SerializedName) Field(java.lang.reflect.Field) Maps(com.google.common.collect.Maps) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) Border(org.terasology.math.Border) Binding(org.terasology.rendering.nui.databinding.Binding) ParameterizedType(java.lang.reflect.ParameterizedType) AbstractWidget(org.terasology.rendering.nui.AbstractWidget) Font(org.terasology.rendering.assets.font.Font) Color(org.terasology.rendering.nui.Color) Modifier(java.lang.reflect.Modifier) Optional(java.util.Optional) ReflectionUtils(org.reflections.ReflectionUtils) UILayout(org.terasology.rendering.nui.UILayout) TextureRegion(org.terasology.rendering.assets.texture.TextureRegion) MenuTree(org.terasology.rendering.nui.contextMenu.MenuTree) JsonTreeValue(org.terasology.rendering.nui.widgets.treeView.JsonTreeValue) Consumer(java.util.function.Consumer) JsonTree(org.terasology.rendering.nui.widgets.treeView.JsonTree)

Example 3 with MenuTree

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;
}
Also used : MenuTree(org.terasology.rendering.nui.contextMenu.MenuTree) JsonTreeValue(org.terasology.rendering.nui.widgets.treeView.JsonTreeValue)

Example 4 with MenuTree

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;
}
Also used : MenuTree(org.terasology.rendering.nui.contextMenu.MenuTree) JsonTreeValue(org.terasology.rendering.nui.widgets.treeView.JsonTreeValue)

Example 5 with MenuTree

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));
            }
        }
    });
}
Also used : MenuTree(org.terasology.rendering.nui.contextMenu.MenuTree)

Aggregations

MenuTree (org.terasology.rendering.nui.contextMenu.MenuTree)5 JsonTreeValue (org.terasology.rendering.nui.widgets.treeView.JsonTreeValue)4 JsonTree (org.terasology.rendering.nui.widgets.treeView.JsonTree)2 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 SerializedName (com.google.gson.annotations.SerializedName)1 Field (java.lang.reflect.Field)1 Modifier (java.lang.reflect.Modifier)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Consumer (java.util.function.Consumer)1 ReflectionUtils (org.reflections.ReflectionUtils)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Border (org.terasology.math.Border)1 Font (org.terasology.rendering.assets.font.Font)1 TextureRegion (org.terasology.rendering.assets.texture.TextureRegion)1