Ejemplo n.º 1
0
        public static void ProcessNodeEvent(Event e, TerraNode node)
        {
            foreach (NodeSocket socket in node.Sockets)
            {
                ProcessSocketEvent(e, socket);
            }

            switch (e.type)
            {
            case EventType.MouseDown:

                if (e.button == 0)
                {
                    if (node.Rect.Contains(e.mousePosition))
                    {
                        if (!TerraGraphEditor.NodeSelection.Contains(node))
                        {
                            if (!e.shift)
                            {
                                TerraGraphEditor.NodeSelection.Clear();
                                TerraGraphEditor.CommentSelection.Clear();
                            }

                            TerraGraphEditor.NodeSelection.Add(node);
                        }
                        else
                        {
                            if (e.shift)
                            {
                                TerraGraphEditor.NodeSelection.Remove(node);
                            }
                        }

                        GUI.FocusControl(null);
                        e.Use();
                    }
                }

                if (e.button == 1)
                {
                    if (node.Rect.Contains(e.mousePosition))
                    {
                        TerraGraphEditor.NodeSelection.Clear();
                        TerraGraphEditor.CommentSelection.Clear();
                        GUI.FocusControl(null);

                        GenericMenu contextMenu = TerraUtility.CreateNodeContextMenu((t) => TerraGraphEditor.Window.CreateNode(t, e.mousePosition));
                        contextMenu.AddSeparator("");
                        contextMenu.AddItem(new GUIContent("Remove Node"), false, () => TerraGraphEditor.Window.RemoveNode(node));
                        contextMenu.ShowAsContext();

                        e.Use();
                    }
                }

                break;
            }

            TerraUtility.BuildNodeCursorRects(node);
        }
Ejemplo n.º 2
0
        public static void ProcessGraphEditorEvents(Event e, TerraGraphEditor window)
        {
            switch (e.type)
            {
            case EventType.KeyDown:

                if (e.keyCode == KeyCode.Delete)
                {
                    foreach (TerraNode node in TerraGraphEditor.NodeSelection)
                    {
                        window.RemoveNode(node);
                    }

                    foreach (GraphComment comment in TerraGraphEditor.CommentSelection)
                    {
                        TerraGraphEditor.Graph.RemoveComment(comment);
                    }

                    TerraGraphEditor.NodeSelection.Clear();
                    TerraGraphEditor.CommentSelection.Clear();
                    TerraGraphEditor.Selecting = false;

                    e.Use();
                }

                if (e.keyCode == KeyCode.F)
                {
                    if (TerraGraphEditor.NodeSelection.Count != 0 || TerraGraphEditor.CommentSelection.Count != 0)
                    {
                        Vector2 currentCenter = TerraGraphEditor.Window.position.size * 0.5f;
                        Vector2 targetCenter  = TerraGraphEditor.NodeSelection[0].Rect.center;
                        Vector2 offset        = currentCenter - targetCenter;

                        foreach (TerraNode node in TerraGraphEditor.Graph.Nodes)
                        {
                            node.SetPosition(node.Rect.position + offset);
                        }
                        foreach (GraphComment comment in TerraGraphEditor.Graph.Comments)
                        {
                            comment.SetPosition(comment.Rect.position + offset);
                        }
                        TerraGUI.ApplyGridOffset(offset);

                        e.Use();
                    }
                }

                break;

            case EventType.MouseDown:

                if (e.button == 0)
                {
                    TerraGraphEditor.NodeSelection.Clear();
                    TerraGraphEditor.CommentSelection.Clear();
                    TerraGraphEditor.SelectionStart = e.mousePosition;
                    TerraGraphEditor.Selecting      = true;
                    GUI.FocusControl(null);
                    e.Use();
                }

                if (e.button == 1)
                {
                    TerraGraphEditor.NodeSelection.Clear();
                    TerraGraphEditor.CommentSelection.Clear();
                    GUI.FocusControl(null);
                    GenericMenu contextMenu = TerraUtility.CreateNodeContextMenu((t) => window.CreateNode(t, e.mousePosition));
                    contextMenu.AddSeparator("");
                    contextMenu.AddItem(new GUIContent("Add Comment"), false, () => TerraGraphEditor.Window.CreateComment(e.mousePosition));
                    contextMenu.ShowAsContext();
                    e.Use();
                }

                break;

            case EventType.MouseUp:

                if (e.button == 0)
                {
                    TerraGraphEditor.HeldSocket      = null;
                    TerraGraphEditor.ResizingComment = null;
                    TerraGraphEditor.Selecting       = false;
                    e.Use();
                }

                break;

            case EventType.MouseDrag:

                if (e.button == 0)
                {
                    if (!new Rect(new Vector2(0, 0), window.position.size).Contains(e.mousePosition))
                    {
                        TerraGraphEditor.NodeSelection.Clear();
                        TerraGraphEditor.CommentSelection.Clear();
                        TerraGraphEditor.Selecting       = false;
                        TerraGraphEditor.ResizingComment = null;
                        TerraGraphEditor.HeldSocket      = null;
                        GUI.FocusControl(null);
                        e.Use();
                    }

                    if (TerraGraphEditor.ResizingComment != null)
                    {
                        TerraGraphEditor.ResizingComment.SetSize(TerraGraphEditor.ResizingComment.Rect.size + e.delta);
                        e.Use();
                    }

                    else if (!TerraGraphEditor.Selecting)
                    {
                        foreach (TerraNode node in TerraGraphEditor.NodeSelection)
                        {
                            node.SetPosition(node.Rect.position + e.delta);
                        }

                        foreach (GraphComment comment in TerraGraphEditor.CommentSelection)
                        {
                            comment.SetPosition(comment.Rect.position + e.delta);
                        }

                        e.Use();
                    }
                }

                if (e.button == 2)
                {
                    TerraGUI.ApplyGridOffset(e.delta);

                    foreach (TerraNode node in TerraGraphEditor.Graph.Nodes)
                    {
                        node.SetPosition(node.Rect.position + e.delta);
                    }

                    foreach (GraphComment comment in TerraGraphEditor.Graph.Comments)
                    {
                        comment.SetPosition(comment.Rect.position + e.delta);
                    }

                    e.Use();
                }

                break;
            }
        }
Ejemplo n.º 3
0
        public static void ProcessCommentEvent(Event e, GraphComment comment)
        {
            switch (e.type)
            {
            case EventType.MouseDown:

                if (e.button == 0)
                {
                    if (TerraUtility.GetCommentResizeRect(comment).Contains(e.mousePosition))
                    {
                        TerraGraphEditor.CommentSelection.Clear();
                        TerraGraphEditor.NodeSelection.Clear();
                        TerraGraphEditor.ResizingComment = comment;
                        GUI.FocusControl(null);
                        e.Use();
                    }

                    else if (comment.Rect.Contains(e.mousePosition))
                    {
                        if (!TerraGraphEditor.CommentSelection.Contains(comment))
                        {
                            if (!e.shift)
                            {
                                TerraGraphEditor.CommentSelection.Clear();
                                TerraGraphEditor.NodeSelection.Clear();
                            }

                            TerraGraphEditor.CommentSelection.Add(comment);
                        }
                        else
                        {
                            if (e.shift)
                            {
                                TerraGraphEditor.CommentSelection.Remove(comment);
                            }
                        }

                        GUI.FocusControl(null);
                        e.Use();
                    }
                }

                if (e.button == 1)
                {
                    if (comment.Rect.Contains(e.mousePosition))
                    {
                        TerraGraphEditor.NodeSelection.Clear();
                        TerraGraphEditor.CommentSelection.Clear();

                        GenericMenu contextMenu = TerraUtility.CreateNodeContextMenu((t) => TerraGraphEditor.Window.CreateNode(t, e.mousePosition));
                        contextMenu.AddSeparator("");
                        contextMenu.AddItem(new GUIContent("Remove Comment"), false, () => TerraGraphEditor.Graph.RemoveComment(comment));
                        contextMenu.ShowAsContext();

                        e.Use();
                    }
                }

                break;
            }

            TerraUtility.BuildCommentCursorRects(comment);
        }