Search in sources :

Example 1 with MenuTree

use of org.terasology.engine.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.engine.rendering.nui.contextMenu.MenuTree)

Example 2 with MenuTree

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

Example 3 with MenuTree

use of org.terasology.engine.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.engine.rendering.nui.contextMenu.MenuTree) JsonTreeValue(org.terasology.nui.widgets.treeView.JsonTreeValue)

Example 4 with MenuTree

use of org.terasology.engine.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.engine.rendering.nui.contextMenu.MenuTree) JsonTreeValue(org.terasology.nui.widgets.treeView.JsonTreeValue) JsonTree(org.terasology.nui.widgets.treeView.JsonTree)

Example 5 with MenuTree

use of org.terasology.engine.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.engine.rendering.nui.contextMenu.MenuTree) JsonTreeValue(org.terasology.nui.widgets.treeView.JsonTreeValue)

Aggregations

MenuTree (org.terasology.engine.rendering.nui.contextMenu.MenuTree)5 JsonTreeValue (org.terasology.nui.widgets.treeView.JsonTreeValue)4 JsonTree (org.terasology.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 NUIManager (org.terasology.engine.rendering.nui.NUIManager)1 AbstractWidget (org.terasology.nui.AbstractWidget)1 Border (org.terasology.nui.Border)1