Esempio n. 1
0
 private void Clear()
 {
     m_bgImg       = null;
     m_describeLab = string.Empty;
     m_livePoints.Clear();
     m_currentMouseMode = MouseModes.IDLE;
     m_nodes.Clear();
 }
Esempio n. 2
0
        private void HandleMouseUp(object sender, MouseButtonEventArgs e)
        {
            switch (MouseMode)
            {
            case MouseModes.Nothing:

                var mouseUpOnNode = false;

                foreach (var node in NodeCollection)
                {
                    if (VisualTreeHelper.HitTest(node.Border, e.GetPosition(node)) != null)
                    {
                        mouseUpOnNode = true;
                    }
                }


                // if mouse up in empty space unselect all nodes
                if (!mouseUpOnNode && e.ChangedButton != MouseButton.Right)
                {
                    foreach (var node in SelectedNodes)
                    {
                        node.IsSelected = false;
                    }

                    SelectedNodes.Clear();
                }


                break;

            case MouseModes.Panning:

                foreach (var node in NodeCollection)
                {
                    MouseMove -= node.HostCanvas_MouseMove;
                }


                Console.WriteLine(NodeCollection.Count);

                MouseMode = MouseModes.Nothing;
                break;

            case MouseModes.Selection:
                Children.Remove(selectionRectangle);
                selectionRectangle = null;

                MouseMode = MouseModes.Nothing;
                break;
            }
        }
Esempio n. 3
0
        public PointerModule()
        {
            // Add the mouse modes
            MouseModes.Add(new PointerMode("Left", MouseFlags.LEFTDOWN | MouseFlags.LEFTUP));          // index 0
            MouseModes.Add(new PointerMode("Right", MouseFlags.RIGHTDOWN | MouseFlags.RIGHTUP, 3, 0)); // index 1
            MouseModes.Add(new PointerMode("Double", MouseFlags.LEFTDOWN | MouseFlags.LEFTUP, 1, 0));  // 2
            MouseModes.Add(new PointerMode("Drag", MouseFlags.LEFTDOWN, 2, 0));                        // 3
            MouseModes.Add(new PointerMode("Scroll Up", MouseFlags.WHEEL, 4, 10));                     // 4
            MouseModes.Add(new PointerMode("Scroll Down", MouseFlags.WHEEL, 4, -10));                  //5

            // Set to left click by default
            SelectedMode = MouseModes[0];
        }
Esempio n. 4
0
        void OnLetUp(object sender, LetTypes type)
        {
            if (sender != m_currentSelectedLet)
            {
                Let senderLet = (Let)sender;
                if (senderLet.Owner != m_currentSelectedLet.Owner)
                {
                    if ((m_currentSelectedLet.Type == LetTypes.INLET && type == LetTypes.OUTLET) ||
                        (m_currentSelectedLet.Type == LetTypes.OUTLET && type == LetTypes.INLET))
                    {
                        Let inlet  = null;
                        Let outlet = null;

                        if (m_currentSelectedLet.Type == LetTypes.INLET)
                        {
                            inlet  = m_currentSelectedLet;
                            outlet = (Let)sender;
                        }
                        else
                        {
                            outlet = m_currentSelectedLet;
                            inlet  = (Let)sender;
                        }

                        Connection connection = new Connection((Inlet)inlet, (Outlet)outlet, m_livePoints);
                        inlet.Connections.Add(connection);
                        outlet.Connections.Add(connection);

                        if (Application.isPlaying)
                        {
                            ((Outlet)outlet).MakeConnections();
                            //   ((Outlet)outlet).Emit += ((Inlet)inlet).Slot;
                        }
                        //if ( !inlet.Contains(outlet) &&
                        //    !outlet.Contains(inlet) )
                        //{

                        //}
                        //else
                        //{
                        //    Debug.LogError("has let ====");
                        //}

                        m_livePoints.Clear();
                        m_currentMouseMode = MouseModes.IDLE;
                    }
                }
            }
        }
Esempio n. 5
0
 public GridBasedViewer( )
     : base()
 {
     GridWidth         = 64;
     GridHeight        = 64;
     gridLinePen       = new Pen(Color.DarkGray, 1.0f);
     gridAxisPen       = new Pen(Color.Gray, 3.0f);
     selectionBrush    = new SolidBrush(Color.FromArgb(128, Color.Magenta));
     items             = new List <GridBasedViewerItem>();
     mouseMode         = MouseModes.FreeToMove;
     offset            = new Point(0, 0);
     moving            = false;
     cursorEnter       = false;
     showGrids         = true;
     selectedItemIndex = -1;
 }
Esempio n. 6
0
        /// <summary>
        /// Sets the mouse mode, what the user needs to do in order to change the tab
        /// </summary>
        /// <param name="mode">The new mouse mode</param>
        public virtual void SetMouseMode(MouseModes mode)
        {
            if (mode == currentMouseMode)
            {
                return;
            }

            switch (currentMouseMode)
            {
            case MouseModes.mouseClick:
                parentControl.MouseClick -= OnClick;
                break;

            case MouseModes.mouseDoubleClick:
                parentControl.MouseDoubleClick -= OnClick;
                break;

            case MouseModes.mouseDown:
                parentControl.MouseDown -= OnClick;
                break;

            case MouseModes.mouseUp:
                parentControl.MouseUp -= OnClick;
                break;
            }

            currentMouseMode = mode;

            switch (currentMouseMode)
            {
            case MouseModes.mouseClick:
                parentControl.MouseClick += OnClick;
                break;

            case MouseModes.mouseDoubleClick:
                parentControl.MouseDoubleClick += OnClick;
                break;

            case MouseModes.mouseDown:
                parentControl.MouseDown += OnClick;
                break;

            case MouseModes.mouseUp:
                parentControl.MouseUp += OnClick;
                break;
            }
        }
 public void ChangeMouseMode(MouseModes newMode)
 {
     CurrentMode = newMode;
 }
Esempio n. 8
0
        private async void HandleMouseDown(object sender, MouseButtonEventArgs e)
        {
            switch (MouseMode)
            {
            case MouseModes.Nothing:

                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    if (e.ClickCount == 2)
                    {
                        // double click in empty space of canvas
                        var node = new SelectionNode(this)
                        {
                            Left = Mouse.GetPosition(this).X - 15,
                            Top  = Mouse.GetPosition(this).Y - 20
                        };
                    }
                    else
                    {
                        var mouseUpOnNode = false;

                        foreach (var node in NodeCollection)
                        {
                            if (VisualTreeHelper.HitTest(node.Border, e.GetPosition(node)) != null)
                            {
                                mouseUpOnNode = true;
                            }
                        }

                        // if mouse up in empty space
                        if (!mouseUpOnNode)
                        {
                            startSelectionPoint = Mouse.GetPosition(this);
                            MouseMode           = MouseModes.Selection;
                            SplineMode          = SplineModes.Nothing;

                            if (radialMenu != null)
                            {
                                radialMenu.IsOpen = false;
                                radialMenu.Dispose();
                                radialMenu = null;
                            }
                        }
                    }
                }
                else if (e.MiddleButton == MouseButtonState.Pressed)
                {
                    // panning
                    foreach (var node in NodeCollection)
                    {
                        node.OldMousePosition = e.GetPosition(this);

                        if (MouseMode != MouseModes.Panning)
                        {
                            MouseMove += node.HostCanvas_MouseMove;
                        }
                    }

                    MouseMode = MouseModes.Panning;
                }
                else if (e.RightButton == MouseButtonState.Pressed)
                {
                    if (radialMenu == null)
                    {
                        radialMenu = new RadialContentMenu(this);
                        Children.Add(radialMenu);
                    }

                    if (radialMenu.IsOpen)
                    {
                        radialMenu.IsOpen = false;
                        await Task.Delay(400);
                    }
                    radialMenu.SetValue(LeftProperty, Mouse.GetPosition(this).X - 150);
                    radialMenu.SetValue(TopProperty, Mouse.GetPosition(this).Y - 150);

                    radialMenu.IsOpen = true;
                }

                break;
            }
        }
        private void HandleMouseUp(object sender, MouseButtonEventArgs e)
        {
            switch (MouseMode)
            {
                case MouseModes.Nothing:

                    var mouseUpOnNode = false;

                    foreach (var node in NodeCollection)
                    {
                        if (VisualTreeHelper.HitTest(node.Border, e.GetPosition(node)) != null)
                            mouseUpOnNode = true;
                    }


                    // if mouse up in empty space unselect all nodes
                    if (!mouseUpOnNode && e.ChangedButton != MouseButton.Right)
                    {
                        foreach (var node in SelectedNodes)
                            node.IsSelected = false;

                        SelectedNodes.Clear();
                    }


                    break;

                case MouseModes.Panning:

                    foreach (var node in NodeCollection)
                        MouseMove -= node.HostCanvas_MouseMove;


                    Console.WriteLine(NodeCollection.Count);

                    MouseMode = MouseModes.Nothing;
                    break;

                case MouseModes.Selection:
                    Children.Remove(selectionRectangle);
                    selectionRectangle = null;

                    MouseMode = MouseModes.Nothing;
                    break;
            }
        }
        private async void HandleMouseDown(object sender, MouseButtonEventArgs e)
        {
            switch (MouseMode)
            {
                case MouseModes.Nothing:

                    if (e.LeftButton == MouseButtonState.Pressed)
                    {
                        if (e.ClickCount == 2)
                        {
                            // double click in empty space of canvas
                            var node = new SelectionNode(this)
                            {
                                Left = Mouse.GetPosition(this).X - 15,
                                Top = Mouse.GetPosition(this).Y - 20
                            };
                        }
                        else
                        {
                            var mouseUpOnNode = false;

                            foreach (var node in NodeCollection)
                            {
                                if (VisualTreeHelper.HitTest(node.Border, e.GetPosition(node)) != null)
                                    mouseUpOnNode = true;
                            }

                            // if mouse up in empty space
                            if (!mouseUpOnNode)
                            {
                                startSelectionPoint = Mouse.GetPosition(this);
                                MouseMode = MouseModes.Selection;
                                SplineMode = SplineModes.Nothing;

                                if (radialMenu != null)
                                {
                                    radialMenu.IsOpen = false;
                                    radialMenu.Dispose();
                                    radialMenu = null;
                                }
                            }
                        }
                    }
                    else if (e.MiddleButton == MouseButtonState.Pressed)
                    {
                        // panning
                        foreach (var node in NodeCollection)
                        {
                            node.OldMousePosition = e.GetPosition(this);

                            if (MouseMode != MouseModes.Panning)
                                MouseMove += node.HostCanvas_MouseMove;
                        }

                        MouseMode = MouseModes.Panning;
                    }
                    else if (e.RightButton == MouseButtonState.Pressed)
                    {
                        if (radialMenu == null)
                        {
                            radialMenu = new RadialContentMenu(this);
                            Children.Add(radialMenu);
                        }

                        if (radialMenu.IsOpen)
                        {
                            radialMenu.IsOpen = false;
                            await Task.Delay(400);
                        }
                        radialMenu.SetValue(LeftProperty, Mouse.GetPosition(this).X - 150);
                        radialMenu.SetValue(TopProperty, Mouse.GetPosition(this).Y - 150);

                        radialMenu.IsOpen = true;
                    }

                    break;
            }
        }
Esempio n. 11
0
 void OnLetPressed(object sender, LetTypes type)
 {
     m_currentSelectedLet = (Let)sender;
     m_startMousePos      = Event.current.mousePosition;
     m_currentMouseMode   = MouseModes.CONNECTING;
 }
Esempio n. 12
0
        void OnGUI()
        {
            if (GUI.Button(new Rect(10, 10, 80, 30), "New"))
            {
                OnDestroy();
                Clear();
                chatID = 1000 + PersuadeSystem.Instacne.persuadeGroup.persuadeGroup.Count;
                Repaint();
            }
            if (GUI.Button(new Rect(10, 50, 80, 30), "Open"))
            {
                ChatJsonWindow.Open(JsonWindow.Persuade);
            }
            if (GUI.Button(new Rect(10, 90, 80, 30), "Save"))
            {
                EditorPersuadeData editorPersuade = new EditorPersuadeData();
                SetPersuadeData(editorPersuade);
                editorPersuade.m_describe = m_describeLab;
                PersuadeSystem.Instacne.SaveEditorData(m_nodes, chatID, editorPersuade);
            }

            if (GUI.Button(new Rect(10, 130, 80, 30), "Ouput"))
            {
                EditorPersuadeData editorPersuade = new EditorPersuadeData();
                SetPersuadeData(editorPersuade);
                editorPersuade.m_describe = m_describeLab;
                PersuadeData persuadeData = new PersuadeData();
                SetPersuadeData(persuadeData);
                PersuadeSystem.Instacne.SaveData(m_nodes, chatID, editorPersuade, persuadeData);
            }
            GUI.BeginGroup(new Rect(100, 5, 500, 400));
            EditorGUILayout.BeginVertical();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("ID:", GUILayout.MaxWidth(150));
            chatID = EditorGUILayout.IntField(chatID);
            EditorGUILayout.EndHorizontal();
            //m_bgImg = EditorGUILayout.ObjectField(m_bgImg, typeof(Texture), GUILayout.MaxWidth(180)) as Texture;

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("描述(策划看):", GUILayout.MaxWidth(150));
            m_describeLab = EditorGUILayout.TextArea(m_describeLab);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("名称:", GUILayout.MaxWidth(150));
            persuadeName = EditorGUILayout.TextArea(persuadeName);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("开头介绍:", GUILayout.MaxWidth(150));
            introduce = EditorGUILayout.TextArea(introduce);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("关键证人ID:", GUILayout.MaxWidth(150));
            npcId = EditorGUILayout.LongField(npcId);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("证据ID数组0,1,2:", GUILayout.MaxWidth(150));
            evidenceIds = EditorGUILayout.TextField(evidenceIds);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();
            GUI.EndGroup();
            //GUI.BeginGroup(new Rect(100, 15, 200, 50));
            //GUI.EndGroup();
            var nodesToRemove = new List <int>();

            for (int i = 0; i < m_nodes.Count; i++)
            {
                if (m_nodes[i] == null)
                {
                    nodesToRemove.Add(i);
                }
            }

            for (int i = 0; i < nodesToRemove.Count; i++)
            {
                m_nodes.RemoveAt(nodesToRemove[i] - i);
            }

            BeginWindows();

            for (int i = 0; i < m_nodes.Count; i++)
            {
                m_nodes[i].Draw();
            }

            EndWindows();

            bool       isConnectionSelected = false;
            Connection connectionSelected   = null;
            float      minDistance          = float.MaxValue;

            // Collect connections
            List <Connection> connections = new List <Connection>();
            int selectedConnection        = -1;

            for (int i = 0; i < m_nodes.Count; i++)
            {
                for (int j = 0; j < m_nodes[i].Lets.Count; j++)
                {
                    Let outlet = m_nodes[i].Lets[j];
                    if (outlet.Type == LetTypes.OUTLET)
                    {
                        for (int k = 0; k < outlet.Connections.Count; k++)
                        {
                            Connection connection = outlet.Connections[k];
                            connections.Add(connection);

                            List <Vector2> points = new List <Vector2>();
                            points.Add(new Vector2(connection.Inlet.Position.center.x, connection.Inlet.Position.center.y));
                            for (int l = 0; l < connection.Points.Length; l++)
                            {
                                points.Add(connection.Points[l]);
                            }
                            points.Add(new Vector2(connection.Outlet.Position.center.x, connection.Outlet.Position.center.y));

                            for (int l = 0; l < points.Count - 1; l++)
                            {
                                float distance = MouseDistanceToLine(points[l], points[l + 1]);

                                if (distance < 20.0f)
                                {
                                    if (distance < minDistance)
                                    {
                                        minDistance          = distance;
                                        isConnectionSelected = true;
                                        connectionSelected   = connection;
                                        selectedConnection   = connections.Count - 1;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Draw connections
            for (int i = 0; i < connections.Count; i++)
            {
                Connection connection = connections[i];

                List <Vector2> points = new List <Vector2>();
                points.Add(connection.Inlet.Position.center);
                for (int j = 0; j < connection.Points.Length; j++)
                {
                    points.Add(connection.Points[j]);
                }
                points.Add(connection.Outlet.Position.center);

                for (int j = 0; j < points.Count - 1; j++)
                {
                    if (i != selectedConnection)
                    {
                        DrawLine(points[j], points[j + 1], ConnectionColor);
                    }
                    else
                    {
                        DrawLine(points[j], points[j + 1], Color.blue);
                    }
                }
            }

            // Process events
            if (Event.current.type == EventType.MouseMove)
            {
                bool handled = false;
                for (int i = 0; i < m_nodes.Count; i++)
                {
                    if (m_nodes[i].MouseOver(Event.current.mousePosition))
                    {
                        handled = true;

                        break;
                    }
                }

                if (!handled)
                {
                    // Do something
                }

                Repaint();
            }
            else if (Event.current.type == EventType.MouseDown && m_currentMouseMode != MouseModes.CONNECTING)
            {
                bool handled = false;
                for (int i = 0; i < m_nodes.Count; i++)
                {
                    if (m_nodes[i].MouseDown(Event.current.mousePosition, Event.current.button))
                    {
                        handled = true;
                    }
                }

                if (!handled && Event.current.button == 1)
                {
                    if (!isConnectionSelected)
                    {
                        CreateNodeMenu();
                    }
                    else
                    {
                        BreakConnectionMenu(connectionSelected.Inlet, connectionSelected.Outlet);
                    }
                }
                else if (!handled && Event.current.button == 0)
                {
                    m_startMousePos = Event.current.mousePosition;
                }
            }
            else if (Event.current.type == EventType.MouseDown && m_currentMouseMode == MouseModes.CONNECTING)
            {
                if (Event.current.button == 0)
                {
                    m_livePoints.Add(Event.current.mousePosition);
                    Repaint();
                }
                else if (Event.current.button == 1)
                {
                    m_currentMouseMode = MouseModes.IDLE;
                    m_livePoints.Clear();
                }
            }
            else if (Event.current.type == EventType.MouseDrag)
            {
                bool handled = false;
                for (int i = 0; i < m_nodes.Count; i++)
                {
                    if (m_nodes[i].MouseDrag(Event.current.mousePosition))
                    {
                        handled = true;
                        break;
                    }
                }

                if (!handled)
                {
                    if (Event.current.shift)
                    {
                        Vector2 offset = Event.current.mousePosition - m_startMousePos;
                        for (int i = 0; i < m_nodes.Count; i++)
                        {
                            m_nodes[i].Position += offset;
                        }

                        Repaint();

                        m_startMousePos = Event.current.mousePosition;
                        handled         = true;
                    }
                }
            }
            else if (Event.current.type == EventType.MouseUp)
            {
                for (int i = 0; i < m_nodes.Count; i++)
                {
                    m_nodes[i].MouseUp(Event.current.mousePosition);
                }
            }

            if (m_currentMouseMode == MouseModes.CONNECTING)
            {
                List <Vector2> points = new List <Vector2>();
                points.Add(m_startMousePos);
                for (int i = 0; i < m_livePoints.Count; i++)
                {
                    points.Add(m_livePoints[i]);
                }
                points.Add(Event.current.mousePosition);

                for (int i = 0; i < points.Count - 1; i++)
                {
                    DrawConnectingCurve(points[i], points[i + 1]);
                }

                Repaint();
            }

            List <BaseNode> nodesToDelete = new List <BaseNode>();

            foreach (BaseNode node in m_nodes)
            {
                if (!node.Valid)
                {
                    nodesToDelete.Add(node);
                }
            }

            foreach (BaseNode node in nodesToDelete)
            {
                m_nodes.Remove(node);

                node.BreakAllLets();

                // DestroyImmediate(node.gameObject);
            }

            if (nodesToDelete.Count > 0)
            {
                Repaint();
            }
        }
Esempio n. 13
0
        void OnGUI()
        {
            if (m_nodegraphStack.Count > 0)
            {
                if (GUI.Button(new Rect(10, 10, 200, 50), "Back"))
                {
                    // Pop nodegraph stack
                    GoBack();

                    return;
                }
            }

            var nodesToRemove = new List <int>();

            for (int i = 0; i < m_nodes.Count; i++)
            {
                if (m_nodes[i] == null)
                {
                    nodesToRemove.Add(i);
                }
            }

            for (int i = 0; i < nodesToRemove.Count; i++)
            {
                m_nodes.RemoveAt(nodesToRemove[i] - i);
            }

            BeginWindows();

            for (int i = 0; i < m_nodes.Count; i++)
            {
                m_nodes[i].Draw();
            }

            EndWindows();

            bool       isConnectionSelected = false;
            Connection connectionSelected   = null;
            float      minDistance          = float.MaxValue;

            // Collect connections
            List <Connection> connections = new List <Connection>();
            int selectedConnection        = -1;

            for (int i = 0; i < m_nodes.Count; i++)
            {
                for (int j = 0; j < m_nodes[i].Lets.Count; j++)
                {
                    Let outlet = m_nodes[i].Lets[j];
                    if (outlet.Type == LetTypes.OUTLET)
                    {
                        for (int k = 0; k < outlet.Connections.Count; k++)
                        {
                            Connection connection = outlet.Connections[k];
                            connections.Add(connection);

                            List <Vector2> points = new List <Vector2>();
                            points.Add(new Vector2(connection.Inlet.Position.center.x, connection.Inlet.Position.center.y));
                            for (int l = 0; l < connection.Points.Length; l++)
                            {
                                points.Add(connection.Points[l]);
                            }
                            points.Add(new Vector2(connection.Outlet.Position.center.x, connection.Outlet.Position.center.y));

                            for (int l = 0; l < points.Count - 1; l++)
                            {
                                float distance = MouseDistanceToLine(points[l], points[l + 1]);

                                if (distance < 20.0f)
                                {
                                    if (distance < minDistance)
                                    {
                                        minDistance          = distance;
                                        isConnectionSelected = true;
                                        connectionSelected   = connection;
                                        selectedConnection   = connections.Count - 1;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Draw connections
            for (int i = 0; i < connections.Count; i++)
            {
                Connection connection = connections[i];

                List <Vector2> points = new List <Vector2>();
                points.Add(connection.Inlet.Position.center);
                for (int j = 0; j < connection.Points.Length; j++)
                {
                    points.Add(connection.Points[j]);
                }
                points.Add(connection.Outlet.Position.center);

                for (int j = 0; j < points.Count - 1; j++)
                {
                    if (i != selectedConnection)
                    {
                        DrawLine(points[j], points[j + 1], ConnectionColor);
                    }
                    else
                    {
                        DrawLine(points[j], points[j + 1], Color.blue);
                    }
                }
            }

            // Process events
            if (Event.current.type == EventType.MouseMove)
            {
                bool handled = false;
                for (int i = 0; i < m_nodes.Count; i++)
                {
                    if (m_nodes[i].MouseOver(Event.current.mousePosition))
                    {
                        handled = true;

                        break;
                    }
                }

                if (!handled)
                {
                    // Do something
                }

                Repaint();
            }
            else if (Event.current.type == EventType.MouseDown && m_currentMouseMode != MouseModes.CONNECTING)
            {
                bool handled = false;
                for (int i = 0; i < m_nodes.Count; i++)
                {
                    if (m_nodes[i].MouseDown(Event.current.mousePosition, Event.current.button))
                    {
                        handled = true;
                    }
                }

                if (!handled && Event.current.button == 1)
                {
                    if (!isConnectionSelected)
                    {
                        CreateNodeMenu();
                    }
                    else
                    {
                        BreakConnectionMenu(connectionSelected.Inlet, connectionSelected.Outlet);
                    }
                }
                else if (!handled && Event.current.button == 0)
                {
                    m_startMousePos = Event.current.mousePosition;
                }
            }
            else if (Event.current.type == EventType.MouseDown && m_currentMouseMode == MouseModes.CONNECTING)
            {
                if (Event.current.button == 0)
                {
                    m_livePoints.Add(Event.current.mousePosition);
                    Repaint();
                }
                else if (Event.current.button == 1)
                {
                    m_currentMouseMode = MouseModes.IDLE;
                    m_livePoints.Clear();
                }
            }
            else if (Event.current.type == EventType.MouseDrag)
            {
                bool handled = false;
                for (int i = 0; i < m_nodes.Count; i++)
                {
                    if (m_nodes[i].MouseDrag(Event.current.mousePosition))
                    {
                        handled = true;
                        break;
                    }
                }

                if (!handled)
                {
                    if (Event.current.shift)
                    {
                        Vector2 offset = Event.current.mousePosition - m_startMousePos;
                        for (int i = 0; i < m_nodes.Count; i++)
                        {
                            m_nodes[i].Position += offset;
                        }

                        Repaint();

                        m_startMousePos = Event.current.mousePosition;
                        handled         = true;
                    }
                }
            }
            else if (Event.current.type == EventType.MouseUp)
            {
                for (int i = 0; i < m_nodes.Count; i++)
                {
                    m_nodes[i].MouseUp(Event.current.mousePosition);
                }
            }

            if (m_currentMouseMode == MouseModes.CONNECTING)
            {
                List <Vector2> points = new List <Vector2>();
                points.Add(m_startMousePos);
                for (int i = 0; i < m_livePoints.Count; i++)
                {
                    points.Add(m_livePoints[i]);
                }
                points.Add(Event.current.mousePosition);

                for (int i = 0; i < points.Count - 1; i++)
                {
                    DrawConnectingCurve(points[i], points[i + 1]);
                }

                Repaint();
            }

            List <BaseNode> nodesToDelete = new List <BaseNode>();

            foreach (BaseNode node in m_nodes)
            {
                if (!node.Valid)
                {
                    nodesToDelete.Add(node);
                }
            }

            foreach (BaseNode node in nodesToDelete)
            {
                m_nodes.Remove(node);

                node.BreakAllLets();

                DestroyImmediate(node.gameObject);
            }

            if (nodesToDelete.Count > 0)
            {
                Repaint();
            }
        }
Esempio n. 14
0
        public override void Update()
        {
            MakeMapEditorBetter();
            Vector2 vector = default(Vector2);

            vector.X = (lastMouseScreenPosition.X - MInput.Mouse.Position.X) / Camera.Zoom;
            vector.Y = (lastMouseScreenPosition.Y - MInput.Mouse.Position.Y) / Camera.Zoom;
            if (MInput.Keyboard.Pressed(Keys.Space) && MInput.Keyboard.Check(Keys.LeftControl))
            {
                Camera.Zoom     = 6f;
                Camera.Position = Vector2.Zero;
            }
            int zoomDir = Math.Sign(MInput.Mouse.WheelDelta);

            if ((zoomDir > 0 && Camera.Zoom >= 1f) || Camera.Zoom > 1f)
            {
                Camera.Zoom += zoomDir;
            }
            else
            {
                Camera.Zoom += zoomDir * 0.25f;
            }
            Camera.Zoom      = Math.Max(0.25f, Math.Min(24f, Camera.Zoom));
            Camera.Position += new Vector2(Input.MoveX.Value, Input.MoveY.Value) * 300f * Engine.DeltaTime;
            UpdateMouse();
            hovered.Clear();
            if (mouseMode == MouseModes.Hover)
            {
                mouseDragStart = mousePosition;
                if (MInput.Mouse.PressedLeftButton)
                {
                    bool flag = LevelCheck(mousePosition);
                    if (MInput.Keyboard.Check(Keys.Space))
                    {
                        mouseMode = MouseModes.Pan;
                    }
                    else if (MInput.Keyboard.Check(Keys.P))
                    {
                        BoardSpaceTemplate pathDest = TestCheck(mousePosition);
                        BoardSpaceTemplate pathSrc;
                        if (pathDest != null && selection.Count == 1 && (pathSrc = selection.First()) != pathDest)
                        {
                            if (!connections.ContainsKey(pathSrc))
                            {
                                connections[pathSrc] = new HashSet <BoardSpaceTemplate>();
                            }
                            if (connections[pathSrc].Contains(pathDest))
                            {
                                connections[pathSrc].Remove(pathDest);
                            }
                            else
                            {
                                connections[pathSrc].Add(pathDest);
                            }
                            selection.Clear();
                            selection.Add(pathDest);
                        }
                    }
                    else if (MInput.Keyboard.Check(Keys.LeftControl))
                    {
                        if (flag)
                        {
                            ToggleSelection(mousePosition);
                        }
                        else
                        {
                            mouseMode = MouseModes.Select;
                        }
                    }
                    else if (MInput.Keyboard.Check(Keys.N))
                    {
                        spaces.Add(new BoardSpaceTemplate(new BoardSpace {
                            x = (int)mousePosition.X / 2, y = (int)mousePosition.Y / 2, type = 'b'
                        }));
                    }
                    else if (flag)
                    {
                        if (!SelectionCheck(mousePosition))
                        {
                            SetSelection(mousePosition);
                        }

                        StoreUndo();
                        foreach (BoardSpaceTemplate item3 in selection)
                        {
                            item3.StartMoving();
                        }
                        mouseMode = MouseModes.Move;
                    }
                    else
                    {
                        mouseMode = MouseModes.Select;
                    }
                }
                else if (MInput.Mouse.PressedRightButton)
                {
                    BoardSpaceTemplate space = TestCheck(mousePosition);
                    if (space != null)
                    {
                        if (MInput.Keyboard.Check(Keys.N))
                        {
                            spaces.Remove(space);
                        }
                        return;
                    }
                }
                else if (MInput.Mouse.PressedMiddleButton)
                {
                    mouseMode = MouseModes.Pan;
                }
                else if (!MInput.Keyboard.Check(Keys.Space))
                {
                    foreach (BoardSpaceTemplate space in spaces)
                    {
                        if (space.Check(mousePosition))
                        {
                            hovered.Add(space);
                        }
                    }
                    if (MInput.Keyboard.Check(Keys.LeftControl))
                    {
                        if (MInput.Keyboard.Pressed(Keys.Z))
                        {
                            Undo();
                        }
                        else if (MInput.Keyboard.Pressed(Keys.Y) || (MInput.Keyboard.Check(Keys.LeftShift) && MInput.Keyboard.Pressed(Keys.Z)))
                        {
                            Redo();
                        }
                        else if (MInput.Keyboard.Pressed(Keys.A))
                        {
                            SelectAll();
                        }
                    }

                    if (MInput.Keyboard.Check(Keys.Delete))
                    {
                        DeleteSelected();
                    }
                }
            }
            else if (mouseMode == MouseModes.Pan)
            {
                Camera.Position += vector;
                if (!MInput.Mouse.CheckLeftButton && !MInput.Mouse.CheckMiddleButton)
                {
                    mouseMode = MouseModes.Hover;
                }
            }
            else if (mouseMode == MouseModes.Select)
            {
                Rectangle mouseRect = GetMouseRect(mouseDragStart, mousePosition);
                foreach (BoardSpaceTemplate space in spaces)
                {
                    if (space.Check(mouseRect))
                    {
                        hovered.Add(space);
                    }
                }
                if (!MInput.Mouse.CheckLeftButton)
                {
                    if (MInput.Keyboard.Check(Keys.LeftControl))
                    {
                        ToggleSelection(mouseRect);
                    }
                    else
                    {
                        SetSelection(mouseRect);
                    }
                    mouseMode = MouseModes.Hover;
                }
            }
            else if (mouseMode == MouseModes.Move)
            {
                Vector2 relativeMove = coordScale * ((mousePosition - mouseDragStart) / coordScale).Round();
                bool    snap         = selection.Count == 1 && !MInput.Keyboard.Check(Keys.LeftAlt);
                foreach (BoardSpaceTemplate space in selection)
                {
                    space.Move(relativeMove);
                }
                if (!MInput.Mouse.CheckLeftButton)
                {
                    mouseMode = MouseModes.Hover;
                }
            }
            if (MInput.Keyboard.Pressed(Keys.D1))
            {
                SetType('b');
            }
            else if (MInput.Keyboard.Pressed(Keys.D2))
            {
                SetType('r');
            }
            else if (MInput.Keyboard.Pressed(Keys.D3))
            {
                SetType('i');
            }
            else if (MInput.Keyboard.Pressed(Keys.D4))
            {
                SetType('s');
            }
            else if (MInput.Keyboard.Pressed(Keys.D5))
            {
                SetType('g');
                SetGreenSpaceEvent(DebugCommands.greenSpaceEvent);
            }
            if (MInput.Keyboard.Pressed(Keys.H))
            {
                ToggleHeartSpace();
            }
            if (MInput.Keyboard.Pressed(Keys.F1) || (MInput.Keyboard.Check(Keys.LeftControl) && MInput.Keyboard.Pressed(Keys.S)))
            {
                SaveAndReload();
                return;
            }
            if (saveFlash > 0f)
            {
                saveFlash -= Engine.DeltaTime * 4f;
            }
            lastMouseScreenPosition = MInput.Mouse.Position;
            base.Update();
        }
Esempio n. 15
0
        void OnGUI()
        {
            if (GUI.Button(new Rect(10, 10, 80, 30), "New"))
            {
                OnDestroy();
                Clear();
                chatID = 1000 + ChatSystemManager.Instacne.chatGroup.m_chats.Count;
                Repaint();
            }
            if (GUI.Button(new Rect(10, 50, 80, 30), "Open"))
            {
                ChatJsonWindow.Open();
            }
            if (GUI.Button(new Rect(10, 90, 80, 30), "Save"))
            {
                string bgName = string.Empty;
                if (m_bgImg != null)
                {
                    bgName = UnityEditor.AssetDatabase.GetAssetPath(m_bgImg);
                }
                ChatSystemManager.Instacne.SaveEditorChatData(m_nodes, bgName, chatID, m_describeLab);
            }

            if (GUI.Button(new Rect(10, 130, 80, 30), "Ouput"))
            {
                //string bgName = string.Empty;
                //if (m_bgImg != null)
                //{
                //    bgName = m_bgImg.name + ".png";
                //}
                ChatSystemManager.Instacne.SaveChatData(m_nodes, m_bgImg, chatID, m_describeLab);
            }
            GUI.BeginGroup(new Rect(100, 5, 200, 200));
            EditorGUILayout.BeginVertical();
            chatID        = EditorGUILayout.IntField(chatID);
            m_bgImg       = EditorGUILayout.ObjectField(m_bgImg, typeof(Texture), GUILayout.MaxWidth(180)) as Texture;
            m_describeLab = EditorGUILayout.TextArea(m_describeLab);
            EditorGUILayout.EndVertical();
            GUI.EndGroup();
            //GUI.BeginGroup(new Rect(100, 15, 200, 50));
            //GUI.EndGroup();
            var nodesToRemove = new List <int>();

            for (int i = 0; i < m_nodes.Count; i++)
            {
                if (m_nodes[i] == null)
                {
                    nodesToRemove.Add(i);
                }
            }

            for (int i = 0; i < nodesToRemove.Count; i++)
            {
                m_nodes.RemoveAt(nodesToRemove[i] - i);
            }

            BeginWindows();

            for (int i = 0; i < m_nodes.Count; i++)
            {
                m_nodes[i].Draw();
            }

            EndWindows();

            bool       isConnectionSelected = false;
            Connection connectionSelected   = null;
            float      minDistance          = float.MaxValue;

            // Collect connections
            List <Connection> connections = new List <Connection>();
            int selectedConnection        = -1;

            for (int i = 0; i < m_nodes.Count; i++)
            {
                for (int j = 0; j < m_nodes[i].Lets.Count; j++)
                {
                    Let outlet = m_nodes[i].Lets[j];
                    if (outlet.Type == LetTypes.OUTLET)
                    {
                        for (int k = 0; k < outlet.Connections.Count; k++)
                        {
                            Connection connection = outlet.Connections[k];
                            connections.Add(connection);

                            List <Vector2> points = new List <Vector2>();
                            points.Add(new Vector2(connection.Inlet.Position.center.x, connection.Inlet.Position.center.y));
                            for (int l = 0; l < connection.Points.Length; l++)
                            {
                                points.Add(connection.Points[l]);
                            }
                            points.Add(new Vector2(connection.Outlet.Position.center.x, connection.Outlet.Position.center.y));

                            for (int l = 0; l < points.Count - 1; l++)
                            {
                                float distance = MouseDistanceToLine(points[l], points[l + 1]);

                                if (distance < 20.0f)
                                {
                                    if (distance < minDistance)
                                    {
                                        minDistance          = distance;
                                        isConnectionSelected = true;
                                        connectionSelected   = connection;
                                        selectedConnection   = connections.Count - 1;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Draw connections
            for (int i = 0; i < connections.Count; i++)
            {
                Connection connection = connections[i];

                List <Vector2> points = new List <Vector2>();
                points.Add(connection.Inlet.Position.center);
                for (int j = 0; j < connection.Points.Length; j++)
                {
                    points.Add(connection.Points[j]);
                }
                points.Add(connection.Outlet.Position.center);

                for (int j = 0; j < points.Count - 1; j++)
                {
                    if (i != selectedConnection)
                    {
                        DrawLine(points[j], points[j + 1], ConnectionColor);
                    }
                    else
                    {
                        DrawLine(points[j], points[j + 1], Color.blue);
                    }
                }
            }

            // Process events
            if (Event.current.type == EventType.MouseMove)
            {
                bool handled = false;
                for (int i = 0; i < m_nodes.Count; i++)
                {
                    if (m_nodes[i].MouseOver(Event.current.mousePosition))
                    {
                        handled = true;

                        break;
                    }
                }

                if (!handled)
                {
                    // Do something
                }

                Repaint();
            }
            else if (Event.current.type == EventType.MouseDown && m_currentMouseMode != MouseModes.CONNECTING)
            {
                bool handled = false;
                for (int i = 0; i < m_nodes.Count; i++)
                {
                    if (m_nodes[i].MouseDown(Event.current.mousePosition, Event.current.button))
                    {
                        handled = true;
                    }
                }

                if (!handled && Event.current.button == 1)
                {
                    if (!isConnectionSelected)
                    {
                        CreateNodeMenu();
                    }
                    else
                    {
                        BreakConnectionMenu(connectionSelected.Inlet, connectionSelected.Outlet);
                    }
                }
                else if (!handled && Event.current.button == 0)
                {
                    m_startMousePos = Event.current.mousePosition;
                }
            }
            else if (Event.current.type == EventType.MouseDown && m_currentMouseMode == MouseModes.CONNECTING)
            {
                if (Event.current.button == 0)
                {
                    m_livePoints.Add(Event.current.mousePosition);
                    Repaint();
                }
                else if (Event.current.button == 1)
                {
                    m_currentMouseMode = MouseModes.IDLE;
                    m_livePoints.Clear();
                }
            }
            else if (Event.current.type == EventType.MouseDrag)
            {
                bool handled = false;
                for (int i = 0; i < m_nodes.Count; i++)
                {
                    if (m_nodes[i].MouseDrag(Event.current.mousePosition))
                    {
                        handled = true;
                        break;
                    }
                }

                if (!handled)
                {
                    if (Event.current.shift)
                    {
                        Vector2 offset = Event.current.mousePosition - m_startMousePos;
                        for (int i = 0; i < m_nodes.Count; i++)
                        {
                            m_nodes[i].Position += offset;
                        }

                        Repaint();

                        m_startMousePos = Event.current.mousePosition;
                        handled         = true;
                    }
                }
            }
            else if (Event.current.type == EventType.MouseUp)
            {
                for (int i = 0; i < m_nodes.Count; i++)
                {
                    m_nodes[i].MouseUp(Event.current.mousePosition);
                }
            }

            if (m_currentMouseMode == MouseModes.CONNECTING)
            {
                List <Vector2> points = new List <Vector2>();
                points.Add(m_startMousePos);
                for (int i = 0; i < m_livePoints.Count; i++)
                {
                    points.Add(m_livePoints[i]);
                }
                points.Add(Event.current.mousePosition);

                for (int i = 0; i < points.Count - 1; i++)
                {
                    DrawConnectingCurve(points[i], points[i + 1]);
                }

                Repaint();
            }

            List <BaseNode> nodesToDelete = new List <BaseNode>();

            foreach (BaseNode node in m_nodes)
            {
                if (!node.Valid)
                {
                    nodesToDelete.Add(node);
                }
            }

            foreach (BaseNode node in nodesToDelete)
            {
                m_nodes.Remove(node);

                node.BreakAllLets();

                // DestroyImmediate(node.gameObject);
            }

            if (nodesToDelete.Count > 0)
            {
                Repaint();
            }
        }