Exemple #1
0
        private void UpdateGenericEvents(ConstellationEditorEvents.RequestRepaint requestRepaint, ConstellationEditorEvents.EditorEvents editorEvents, Event e)
        {
            if (e.type == EventType.Repaint)
            {
                mousePosition = e.mousePosition;
            }

            if (Event.current.keyCode == KeyCode.Delete)
            {
                for (var i = 0; i < SelectedNodes.Count; i++)
                {
                    RemoveNode(SelectedNodes[SelectedNodes.Count - 1].NodeData, editorEvents);
                }
            }

            for (var i = 0; i < Nodes.Count; i++)
            {
                var nodeRect     = Nodes[i].GetNodeRect(out float positionOffsetX, out float positionOffsetY);
                var deleteRect   = Nodes[i].GetDeleteRect(EditorData.GetConstellationEditorConfig());
                var questionRect = Nodes[i].GetQuestionRect(EditorData.GetConstellationEditorConfig());
                var resizeRect   = Nodes[i].GetResizeRect(EditorData.GetConstellationEditorConfig());

                if (nodeRect.Contains(mousePosition))
                {
                    if (mousePressed)
                    {
                        requestRepaint();
                        if (e.control || SelectedNodes.Count == 0)
                        {
                            SelectedNodes.Add(Nodes[i]);
                            Nodes[i].SelectedNode();
                        }
                        else if (SelectedNodes.Count <= 1)
                        {
                            foreach (var selectedNodes in SelectedNodes)
                            {
                                selectedNodes.UnselectNode();
                            }
                            SelectedNodes.Clear();
                            SelectedNodes.Add(Nodes[i]);
                            Nodes[i].SelectedNode();
                        }

                        for (var j = 0; j < Nodes[i].GetInputs().Length; j++)
                        {
                            var inputRect = Nodes[i].GetInputRect(j, EditorData.GetConstellationEditorConfig());
                            if (inputRect.Contains(mousePosition))
                            {
                                Links.AddLinkFromInput(Nodes[i].GetInputs()[j],
                                                       (ConstellationEditorEvents.EditorEventType editorEventType, string message) =>
                                {
                                    editorEvents(editorEventType, message);
                                    if (editorEventType == ConstellationEditorEvents.EditorEventType.LinkAdded)
                                    {
                                        UpdateGenericNodeByLinkGUID(message);
                                    }
                                });
                            }
                        }

                        for (var j = 0; j < Nodes[i].GetOutputs().Length; j++)
                        {
                            var outputRect = Nodes[i].GetOuptputRect(j, EditorData.GetConstellationEditorConfig());
                            if (outputRect.Contains(mousePosition))
                            {
                                Links.AddLinkFromOutput(Nodes[i].GetOutputs()[j],
                                                        (ConstellationEditorEvents.EditorEventType editorEventType, string message) =>
                                {
                                    editorEvents(editorEventType, message);
                                    if (editorEventType == ConstellationEditorEvents.EditorEventType.LinkAdded)
                                    {
                                        UpdateGenericNodeByLinkGUID(message);
                                    }
                                });
                            }
                        }

                        if (deleteRect.Contains(mousePosition) && mouseButtonDown)
                        {
                            RemoveNode(Nodes[i].NodeData, editorEvents);
                            return;
                        }

                        if (questionRect.Contains(mousePosition) && mouseButtonDown)
                        {
                            editorEvents(ConstellationEditorEvents.EditorEventType.HelpClicked, Nodes[i].GetName());
                            return;
                        }

                        for (var j = 0; j < Nodes[i].GetAttributeDatas().Length; j++)
                        {
                            var attributeRect = Nodes[i].GetParameterRect(j, EditorData.GetConstellationEditorConfig());
                            if (attributeRect.Contains(mousePosition))
                            {
                                editorEvents(ConstellationEditorEvents.EditorEventType.AddToUndo, "Attribute edited");
                                currentEventScope = EventsScope.EditingAttributes;
                                return;
                            }
                        }

                        if (mouseButtonDown)
                        {
                            if (resizeRect.Contains(mousePosition))
                            {
                                currentEventScope = EventsScope.Resizing;
                                return;
                            }
                            editorEvents(ConstellationEditorEvents.EditorEventType.AddToUndo, "Node moved");
                            SetNodeToFirst(Nodes[i]);
                            currentEventScope = EventsScope.Dragging;
                            return;
                        }
                    }
                }
                else if (mousePressed && e.mousePosition.x != mouseClickStartPosition.x && e.mousePosition.y != mouseClickStartPosition.y)
                {
                    currentEventScope = EventsScope.Selecting;
                }
            }

            if (e.MouseUp() && e.button != 2)
            {
                foreach (var node in SelectedNodes)
                {
                    node.UnselectNode();
                }
                SelectedNodes.Clear();
            }
        }
Exemple #2
0
        private void UpdateGenericEvents(ConstellationEditorEvents.RequestRepaint requestRepaint, ConstellationEditorEvents.EditorEvents editorEvents, Event e)
        {
            for (var i = 0; i < Nodes.Count; i++)
            {
                var nodeRect     = Nodes[i].GetNodeRect(out float positionOffsetX, out float positionOffsetY);
                var deleteRect   = Nodes[i].GetDeleteRect();
                var questionRect = Nodes[i].GetQuestionRect();
                var resizeRect   = Nodes[i].GetResizeRect();

                if (nodeRect.Contains(e.mousePosition))
                {
                    if (mousePressed)
                    {
                        requestRepaint();
                        if (e.control)
                        {
                            SelectedNodes.Add(Nodes[i]);
                            SetNodeToFirst(Nodes[i]);
                        }
                        else
                        {
                            SelectedNodes.Clear();
                            SelectedNodes.Add(Nodes[i]);
                        }

                        for (var j = 0; j < Nodes[i].GetInputs().Length; j++)
                        {
                            var inputRect = Nodes[i].GetInputRect(j);
                            if (inputRect.Contains(e.mousePosition))
                            {
                                Links.AddLinkFromInput(Nodes[i].GetInputs()[j], editorEvents);
                            }
                        }

                        for (var j = 0; j < Nodes[i].GetOutputs().Length; j++)
                        {
                            var outputRect = Nodes[i].GetOuptputRect(j);
                            if (outputRect.Contains(e.mousePosition))
                            {
                                Links.AddLinkFromOutput(Nodes[i].GetOutputs()[j], editorEvents);
                            }
                        }

                        if (deleteRect.Contains(e.mousePosition) && mouseButtonDown)
                        {
                            RemoveNode(Nodes[i].NodeData, editorEvents);
                            return;
                        }

                        if (questionRect.Contains(e.mousePosition) && mouseButtonDown)
                        {
                            editorEvents(ConstellationEditorEvents.EditorEventType.HelpClicked, Nodes[i].GetName());
                            return;
                        }

                        for (var j = 0; j < Nodes[i].GetAttributeDatas().Length; j++)
                        {
                            var attributeRect = Nodes[i].GetAttributeRect(j);
                            if (attributeRect.Contains(e.mousePosition))
                            {
                                currentEventScope = EventsScope.EditingAttributes;
                                return;
                            }
                        }

                        if (mouseButtonDown)
                        {
                            if (resizeRect.Contains(e.mousePosition))
                            {
                                currentEventScope = EventsScope.Resizing;
                                return;
                            }
                            SetNodeToFirst(Nodes[i]);
                            currentEventScope = EventsScope.Dragging;
                            return;
                        }
                    }
                }
            }
            if (mousePressed)
            {
                SelectedNodes.Clear();
            }
        }