Search in sources :

Example 1 with PropertyBox

use of com.gempukku.libgdx.graph.ui.graph.property.PropertyBox in project gdx-graph by MarcinSc.

the class GraphDesignTab method createPropertyPopupMenu.

private PopupMenu createPropertyPopupMenu(float x, float y) {
    PopupMenu menu = new PopupMenu();
    for (UIGraphConfiguration uiGraphConfiguration : uiGraphConfigurations) {
        for (Map.Entry<String, PropertyBoxProducer> propertyEntry : uiGraphConfiguration.getPropertyBoxProducers().entrySet()) {
            final String name = propertyEntry.getKey();
            final PropertyBoxProducer value = propertyEntry.getValue();
            MenuItem valueMenuItem = new MenuItem(name);
            valueMenuItem.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    PropertyBox defaultPropertyBox = value.createDefaultPropertyBox(skin, type.getPropertyLocations());
                    addPropertyBox(name, defaultPropertyBox);
                }
            });
            menu.addItem(valueMenuItem);
        }
    }
    return menu;
}
Also used : UIGraphConfiguration(com.gempukku.libgdx.graph.ui.UIGraphConfiguration) PropertyBox(com.gempukku.libgdx.graph.ui.graph.property.PropertyBox) Actor(com.badlogic.gdx.scenes.scene2d.Actor) PropertyBoxProducer(com.gempukku.libgdx.graph.ui.graph.property.PropertyBoxProducer) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Example 2 with PropertyBox

use of com.gempukku.libgdx.graph.ui.graph.property.PropertyBox in project gdx-graph by MarcinSc.

the class GraphDesignTab method serializeGraph.

public JsonValue serializeGraph() {
    JsonValue graph = new JsonValue(JsonValue.ValueType.object);
    graph.addChild("version", new JsonValue(GraphLoader.VERSION));
    graph.addChild("type", new JsonValue(type.getType()));
    JsonValue objects = new JsonValue(JsonValue.ValueType.array);
    for (JsonValue jsonValue : getSortedNodesAsJson()) {
        objects.addChild(jsonValue);
    }
    graph.addChild("nodes", objects);
    List<JsonValue> connectionJsonValues = getSortedConnectionsAsJson();
    JsonValue connections = new JsonValue(JsonValue.ValueType.array);
    for (JsonValue connection : connectionJsonValues) {
        connections.addChild(connection);
    }
    graph.addChild("connections", connections);
    JsonValue properties = new JsonValue(JsonValue.ValueType.array);
    for (PropertyBox propertyBox : propertyBoxes) {
        JsonValue property = new JsonValue(JsonValue.ValueType.object);
        property.addChild("name", new JsonValue(propertyBox.getName()));
        property.addChild("type", new JsonValue(propertyBox.getType()));
        PropertyLocation location = propertyBox.getLocation();
        if (location != null)
            property.addChild("location", new JsonValue(location.name()));
        JsonValue data = propertyBox.getData();
        if (data != null)
            property.addChild("data", data);
        properties.addChild(property);
    }
    graph.addChild("properties", properties);
    JsonValue groups = new JsonValue(JsonValue.ValueType.array);
    for (NodeGroup nodeGroup : graphContainer.getNodeGroups()) {
        JsonValue group = new JsonValue(JsonValue.ValueType.object);
        group.addChild("name", new JsonValue(nodeGroup.getName()));
        JsonValue nodes = new JsonValue(JsonValue.ValueType.array);
        for (String nodeId : nodeGroup.getNodeIds()) {
            nodes.addChild(new JsonValue(nodeId));
        }
        group.addChild("nodes", nodes);
        groups.addChild(group);
    }
    graph.addChild("groups", groups);
    return graph;
}
Also used : PropertyBox(com.gempukku.libgdx.graph.ui.graph.property.PropertyBox) PropertyLocation(com.gempukku.libgdx.graph.shader.property.PropertyLocation) JsonValue(com.badlogic.gdx.utils.JsonValue) NodeGroup(com.gempukku.libgdx.graph.data.NodeGroup)

Example 3 with PropertyBox

use of com.gempukku.libgdx.graph.ui.graph.property.PropertyBox in project gdx-graph by MarcinSc.

the class GraphDesignTab method createGraphPopupMenu.

private PopupMenu createGraphPopupMenu(final float popupX, final float popupY) {
    PopupMenu popupMenu = new PopupMenu();
    for (UIGraphConfiguration uiGraphConfiguration : uiGraphConfigurations) {
        boolean hasChild = false;
        for (final GraphBoxProducer producer : uiGraphConfiguration.getGraphBoxProducers()) {
            String menuLocation = producer.getMenuLocation();
            if (menuLocation != null) {
                String[] menuSplit = menuLocation.split("/");
                PopupMenu targetMenu = findOrCreatePopupMenu(popupMenu, menuSplit, 0);
                final String title = producer.getName();
                MenuItem valueMenuItem = new MenuItem(title);
                valueMenuItem.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeEvent event, Actor actor) {
                        String id = UUID.randomUUID().toString().replace("-", "");
                        GraphBox graphBox = producer.createDefault(skin, id);
                        graphContainer.addGraphBox(graphBox, title, true, popupX, popupY);
                    }
                });
                targetMenu.addItem(valueMenuItem);
                hasChild = true;
            }
        }
        if (hasChild)
            popupMenu.addSeparator();
    }
    MenuItem propertyMenuItem = new MenuItem("Property");
    propertyMenuItem.setDisabled(true);
    popupMenu.addItem(propertyMenuItem);
    if (!propertyBoxes.isEmpty()) {
        PopupMenu propertyMenu = new PopupMenu();
        for (final PropertyBox propertyProducer : propertyBoxes) {
            final String name = propertyProducer.getName();
            MenuItem valueMenuItem = new MenuItem(name);
            valueMenuItem.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    String id = UUID.randomUUID().toString().replace("-", "");
                    GraphBox graphBox = propertyProducer.createPropertyBox(skin, id, popupX, popupY);
                    graphContainer.addGraphBox(graphBox, "Property", true, popupX, popupY);
                }
            });
            propertyMenu.addItem(valueMenuItem);
        }
        propertyMenuItem.setSubMenu(propertyMenu);
        propertyMenuItem.setDisabled(false);
    }
    return popupMenu;
}
Also used : UIGraphConfiguration(com.gempukku.libgdx.graph.ui.UIGraphConfiguration) PropertyBox(com.gempukku.libgdx.graph.ui.graph.property.PropertyBox) GraphBoxProducer(com.gempukku.libgdx.graph.ui.producer.GraphBoxProducer) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Example 4 with PropertyBox

use of com.gempukku.libgdx.graph.ui.graph.property.PropertyBox in project gdx-graph by MarcinSc.

the class UIGraphLoaderCallback method addPipelineProperty.

@Override
public void addPipelineProperty(String type, String name, PropertyLocation location, JsonValue data) {
    PropertyBoxProducer producer = findPropertyProducerByType(type);
    if (producer == null)
        throw new IllegalArgumentException("Unable to find property producer for type: " + type);
    PropertyBox propertyBox = producer.createPropertyBox(skin, name, location, data, propertyLocations);
    graphDesignTab.addPropertyBox(type, propertyBox);
}
Also used : PropertyBox(com.gempukku.libgdx.graph.ui.graph.property.PropertyBox) PropertyBoxProducer(com.gempukku.libgdx.graph.ui.graph.property.PropertyBoxProducer)

Aggregations

PropertyBox (com.gempukku.libgdx.graph.ui.graph.property.PropertyBox)4 Actor (com.badlogic.gdx.scenes.scene2d.Actor)2 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)2 UIGraphConfiguration (com.gempukku.libgdx.graph.ui.UIGraphConfiguration)2 PropertyBoxProducer (com.gempukku.libgdx.graph.ui.graph.property.PropertyBoxProducer)2 JsonValue (com.badlogic.gdx.utils.JsonValue)1 NodeGroup (com.gempukku.libgdx.graph.data.NodeGroup)1 PropertyLocation (com.gempukku.libgdx.graph.shader.property.PropertyLocation)1 GraphBoxProducer (com.gempukku.libgdx.graph.ui.producer.GraphBoxProducer)1