Пример #1
0
 // Return a boolean when it's name never be used in alphabet.
 public static bool IsConnectionNameUsed(GraphGrammarConnection currentConnection)
 {
     return((from connection in Alphabet.Connections
             where connection.Name == currentConnection.Name && connection != Alphabet.SelectedConnection
             select connection)
            .Any());
 }
Пример #2
0
        // Update symbol appearance.
        public void UpdateSymbol(GraphGrammarSymbol before, GraphGrammarSymbol after)
        {
            int symbolIndex                   = -1;
            GraphGrammarNode       node       = null;
            GraphGrammarConnection connection = null;

            if (before is GraphGrammarNode)
            {
                node        = (GraphGrammarNode)after;
                symbolIndex = _nodes.FindIndex(x => x.Equals(before));
                _nodes[symbolIndex].AlphabetID   = node.AlphabetID;
                _nodes[symbolIndex].Terminal     = node.Terminal;
                _nodes[symbolIndex].Name         = node.Name;
                _nodes[symbolIndex].Abbreviation = node.Abbreviation;
                _nodes[symbolIndex].Description  = node.Description;
                _nodes[symbolIndex].OutlineColor = node.OutlineColor;
                _nodes[symbolIndex].FilledColor  = node.FilledColor;
                _nodes[symbolIndex].TextColor    = node.TextColor;
            }
            else if (before is GraphGrammarConnection)
            {
                connection  = (GraphGrammarConnection)after;
                symbolIndex = _connections.FindIndex(x => x.Equals(before));
                _connections[symbolIndex].AlphabetID   = connection.AlphabetID;
                _connections[symbolIndex].Name         = connection.Name;
                _connections[symbolIndex].Description  = connection.Description;
                _connections[symbolIndex].OutlineColor = connection.OutlineColor;
                _connections[symbolIndex].Requirement  = connection.Requirement;
                _connections[symbolIndex].Arrow        = connection.Arrow;
            }
            return;
        }
Пример #3
0
 public static void Initialize()
 {
     // Initial whole fields in window.
     _symbolName         = string.Empty;
     _symbolAbbreviation = string.Empty;
     _symbolDescription  = string.Empty;
     _symbolOutlineColor = Color.black;
     _symbolFilledColor  = Color.white;
     _symbolTextColor    = Color.black;
     _symbolTerminal     = NodeTerminalType.Terminal;
     // Set the first values.
     _currentTab               = AlphabetWindowTab.Nodes;
     _isInitTabButton          = true;
     _editingMode              = EditingMode.None;
     _scrollPosition           = Vector2.zero;
     _messageHint              = string.Empty;
     _messageType              = MessageType.Info;
     _node                     = new GraphGrammarNode(NodeTerminalType.Terminal);
     _connection               = new GraphGrammarConnection();
     _symbolListCanvas         = new Rect(0, 0, Screen.width, Screen.height);
     _symbolListCanvasInWindow = _symbolListCanvas;
     _symbolListArea           = new Rect(0, 0, Screen.width, Screen.height);
     _centerPosition           = new Vector2(Screen.width / 2, 75);
     _connectionType           = ConnectionType.WeakRequirement;
     _connectionArrowType      = ConnectionArrowType.Normal;
     // Revoke all.
     Alphabet.RevokeAllSelected();
 }
Пример #4
0
            // Unserialize connections
            private static List <Mission.GraphGrammarConnection> UnserializeConnections(XElement element)
            {
                List <Mission.GraphGrammarConnection> connections = new List <Mission.GraphGrammarConnection>();
                XElement elementConnections = element.Element("Connections");

                foreach (var elementConnection in elementConnections.Elements("Connection"))
                {
                    Mission.GraphGrammarConnection connection = new Mission.GraphGrammarConnection();

                    connection.ID            = new Guid(elementConnection.Attribute("id").Value);
                    connection.AlphabetID    = new Guid(elementConnection.Element("AlphabetID").Value);
                    connection.Name          = elementConnection.Element("Name").Value;
                    connection.Description   = elementConnection.Element("Description").Value;
                    connection.Requirement   = (Mission.ConnectionType)Enum.Parse(typeof(Mission.ConnectionType), elementConnection.Element("Requirement").Value);
                    connection.Arrow         = (Mission.ConnectionArrowType)Enum.Parse(typeof(Mission.ConnectionArrowType), elementConnection.Element("ArrowType").Value);
                    connection.StartSelected = bool.Parse(elementConnection.Element("StartSelected").Value);
                    connection.EndSelected   = bool.Parse(elementConnection.Element("EndSelected").Value);

                    XElement elementScope = elementConnection.Element("Scope");
                    connection.StartpointScope = UnserializeRect(elementScope.Element("Startpoint"));
                    connection.EndpointScope   = UnserializeRect(elementScope.Element("Endpoint"));

                    XElement elementSymbolColor = elementConnection.Element("SymbolColor");
                    connection.OutlineColor = UnserializeColor(elementSymbolColor.Element("Outline"));

                    connections.Add(connection);
                }
                return(connections);
            }
Пример #5
0
 public Node(GraphGrammarConnection connection, int index) : this()
 {
     Debug.Log(connection);
     this.AlphabetID = connection.AlphabetID;
     this.Name       = connection.Name;
     this.IsEdge     = true;
     this.Index      = index;
 }
Пример #6
0
 // Update the information form another connection, mostly reference is in Alphabet.
 public void UpdateSymbolInfo(GraphGrammarConnection referenceConnection)
 {
     _name         = referenceConnection.Name;
     _description  = referenceConnection.Description;
     _outlineColor = referenceConnection.OutlineColor;
     _requirement  = referenceConnection.Requirement;
     _arrow        = referenceConnection.Arrow;
 }
Пример #7
0
 // Add a new pair for stickied connection.
 public void AddStickiedConnection(GraphGrammarConnection connection, string location)
 {
     // If connection is not store here, append this connection.
     if (!_stickiedConnections.Any(e => e.connection == connection))
     {
         _stickiedConnections.Add(new StickiedConnection(connection, location));
     }
 }
Пример #8
0
 void UpdateFields(GraphGrammarConnection connection)
 {
     _symbolName          = connection.Name;
     _symbolDescription   = connection.Description;
     _symbolOutlineColor  = connection.OutlineColor;
     _connectionType      = connection.Requirement;
     _connectionArrowType = connection.Arrow;
     // Repaint the window.
     Repaint();
 }
Пример #9
0
        // Same symbols in mission grammar will be updated in the same time when the alphabet updated.
        public static void OnAlphabetUpdated(GraphGrammarSymbol symbol)
        {
            GraphGrammarNode       referenceNode       = null;
            GraphGrammarConnection referenceConnection = null;

            if (symbol is GraphGrammarNode)
            {
                referenceNode = (GraphGrammarNode)symbol;
                foreach (var group in _groups)
                {
                    foreach (var rule in group.Rules)
                    {
                        foreach (var node in rule.SourceRule.Nodes)
                        {
                            if (node.AlphabetID == referenceNode.AlphabetID)
                            {
                                node.UpdateSymbolInfo(referenceNode);
                            }
                        }
                        foreach (var node in rule.ReplacementRule.Nodes)
                        {
                            if (node.AlphabetID == referenceNode.AlphabetID)
                            {
                                node.UpdateSymbolInfo(referenceNode);
                            }
                        }
                    }
                }
            }
            else if (symbol is GraphGrammarConnection)
            {
                referenceConnection = (GraphGrammarConnection)symbol;
                foreach (var group in _groups)
                {
                    foreach (var rule in group.Rules)
                    {
                        foreach (var connection in rule.SourceRule.Connections)
                        {
                            if (connection.AlphabetID == referenceConnection.AlphabetID)
                            {
                                connection.UpdateSymbolInfo(referenceConnection);
                            }
                        }
                        foreach (var connection in rule.ReplacementRule.Connections)
                        {
                            if (connection.AlphabetID == referenceConnection.AlphabetID)
                            {
                                connection.UpdateSymbolInfo(referenceConnection);
                            }
                        }
                    }
                }
            }
        }
Пример #10
0
        // Add a new connection from another exist connection.
        public GraphGrammarConnection AddConnection(GraphGrammarConnection connectionClone)
        {
            RevokeAllSelected();
            // Deep copy.
            GraphGrammarConnection connection = new GraphGrammarConnection(connectionClone);

            connection.Selected = true;
            _connections.Add(connection);
            // Update the current connection.
            _selectedSymbol = connection;
            return(connection);
        }
Пример #11
0
        // Add a new connection.
        public void AddConnection()
        {
            // Revoke all symbols first.
            RevokeAllSelected();
            // Create a new connection.
            GraphGrammarConnection connection = new GraphGrammarConnection();

            connection.Selected = true;
            _connections.Add(connection);
            // Update the current connection.
            _selectedSymbol = connection;
            return;
        }
Пример #12
0
        // Draw the connection in the connection list.
        public static void DrawConnectionInList(GraphGrammarConnection connection)
        {
            connection.StartPositionX = 10;
            connection.EndPositionX   = 60;
            connection.StartPositionY = connection.EndPositionY = 25 + 50 * _connections.FindIndex(c => c == connection);
            // Background color of selectable area.
            Color rectColor = SampleStyle.ColorBlue;

            rectColor.a = 0.75f;
            EditorCanvas.DrawQuad(new Rect(5, connection.StartPositionY - 23, Screen.width - 8, 46), connection.Selected ? rectColor : Color.clear);
            // Draw this connection.
            connection.Draw();
        }
Пример #13
0
 // Update the connection information from the current field values.
 void UpdateConnection(GraphGrammarConnection connection)
 {
     if (connection == null)
     {
         return;
     }
     connection.Name         = _symbolName;
     connection.Description  = _symbolDescription;
     connection.OutlineColor = _symbolOutlineColor;
     connection.Requirement  = _connectionType;
     connection.Arrow        = _connectionArrowType;
     // Repaint the window.
     Repaint();
 }
Пример #14
0
        // Buttons about adding new symbol, modifying and deleting.
        void LayoutEditingModeButtonGroup()
        {
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button(Languages.GetText("MissionAlphabet-AddNew"), SampleStyle.GetButtonStyle(SampleStyle.ButtonType.Left, SampleStyle.ButtonColor.Blue), SampleStyle.ButtonHeight))
            {
                // Switch the mode.
                _editingMode = EditingMode.Create;
                // Initial the preview node and connection.
                _node       = new GraphGrammarNode();
                _connection = new GraphGrammarConnection();
                // Initial all fields and repaint.
                Alphabet.RevokeAllSelected();
                InitFields();
                Repaint();
            }
            switch (_currentTab)
            {
            case AlphabetWindowTab.Nodes:
                EditorGUI.BeginDisabledGroup(Alphabet.SelectedNode == null || Alphabet.IsAnyNode(Alphabet.SelectedNode.AlphabetID));
                break;

            case AlphabetWindowTab.Connections:
                EditorGUI.BeginDisabledGroup(Alphabet.SelectedConnection == null);
                break;
            }
            if (GUILayout.Button(Languages.GetText("MissionAlphabet-Modify"), SampleStyle.GetButtonStyle(SampleStyle.ButtonType.Mid, SampleStyle.ButtonColor.Blue), SampleStyle.ButtonHeight))
            {
                // Switch the mode.
                _editingMode = EditingMode.Modify;
            }
            if (GUILayout.Button(Languages.GetText("MissionAlphabet-Delete"), SampleStyle.GetButtonStyle(SampleStyle.ButtonType.Right, SampleStyle.ButtonColor.Blue), SampleStyle.ButtonHeight))
            {
                // Switch the mode.
                _editingMode = EditingMode.Delete;
                // Remove the node or connection from alphabet and repaint.
                switch (_currentTab)
                {
                case AlphabetWindowTab.Nodes:
                    Alphabet.RemoveNode(Alphabet.SelectedNode);
                    break;

                case AlphabetWindowTab.Connections:
                    Alphabet.RemoveConnection(Alphabet.SelectedConnection);
                    break;
                }
                Repaint();
            }
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.EndHorizontal();
        }
Пример #15
0
        // Add node and connection to graph grammar by dfs.
        // "layer" is used to calculate x position
        private static void RecursionGraphGrammar(Node node, ref GraphGrammar graphGrammar, int layer)
        {
            if (CountInLayer.Count <= layer)
            {
                CountInLayer.Add(0);
            }
            // Mark this node.
            node.Explored = true;
            // "index" is used to calculate y position.
            int index = 0;

            foreach (Node edgeNode in node.Children)
            {
                // Add connection (Now only use Connections[0], will modify).
                Node childNode  = edgeNode.Children[0];
                var  connection = new GraphGrammarConnection(Alphabet.Connections.Find(c => c.AlphabetID == edgeNode.AlphabetID));
                graphGrammar.Connections.Add(connection);
                // Set starting sticked attribute.
                _nodeMappingTable[node].AddStickiedConnection(connection, "start");
                connection.StartpointStickyOn = _nodeMappingTable[node];
                connection.StartPosition      = _nodeMappingTable[node].Position;
                // If mapping table have not contained this Node then add it.
                if (!_nodeMappingTable.ContainsKey(childNode))
                {
                    // Set position.
                    _nodeMappingTable[childNode] = new GraphGrammarNode(_referenceNodeTable[childNode.AlphabetID])
                    {
                        Position = new Vector2(LEFT_TOP_POSITION.x + layer * PADDING,
                                               LEFT_TOP_POSITION.y + (CountInLayer[layer] + index) * PADDING)
                    };
                    graphGrammar.Nodes.Add(_nodeMappingTable[childNode]);
                }
                // Set ending sticked attribute.
                _nodeMappingTable[childNode].AddStickiedConnection(connection, "end");
                connection.EndpointStickyOn = _nodeMappingTable[childNode];
                connection.EndPosition      = _nodeMappingTable[childNode].Position;
                // Check the mark exist.
                if (!childNode.Explored)
                {
                    // Search deeper, so "layer" must increase.
                    RecursionGraphGrammar(childNode, ref graphGrammar, layer + 1);
                }
                index++;
            }
            CountInLayer[layer] += index;
        }
Пример #16
0
 // Clone construction for basic informations.
 public GraphGrammarConnection(GraphGrammarConnection connection)
 {
     // Generate new symbol ID, but use same alphabet ID.
     this._symbolID   = Guid.NewGuid();
     this._alphabetID = connection.AlphabetID;
     // Basic information to copy.
     this._type               = SymbolType.Connection;
     this._name               = connection.Name;
     this._description        = connection.Description;
     this._requirement        = connection.Requirement;
     this._arrow              = connection.Arrow;
     this._startpointScope    = connection.StartpointScope;
     this._endpointScope      = connection.EndpointScope;
     this._outlineColor       = connection.OutlineColor;
     this._startpointStickyOn = null;
     this._endpointStickyOn   = null;
 }
Пример #17
0
        // Points of connection is sticky to the node.
        public bool StickyNode(GraphGrammarConnection connection, Vector2 pos, string location)
        {
            bool sticked = false;

            foreach (GraphGrammarNode node in _nodes.AsEnumerable().Reverse())
            {
                if (node.IsInScope(pos))
                {
                    if (string.Equals(location, "start"))
                    {
                        connection.StartpointStickyOn = node;
                    }
                    else
                    {
                        connection.EndpointStickyOn = node;
                    }
                    node.AddStickiedConnection(connection, location);
                    sticked = true;
                }
                else
                {
                    node.RemoveStickiedConnection(connection, location);
                }
            }
            // If no stick anything then set null.
            if (!sticked)
            {
                if (string.Equals(location, "start"))
                {
                    connection.StartpointStickyOn = null;
                }
                else
                {
                    connection.EndpointStickyOn = null;
                }
            }
            return(sticked);
        }
Пример #18
0
 // Add a new connection.
 public static void AddConnection(GraphGrammarConnection connection)
 {
     _connections.Add(connection);
 }
Пример #19
0
 // Remove the specific stickied connection.
 public void RemoveStickiedConnection(GraphGrammarConnection connection, string location)
 {
     // If connection is store here, remove this connection.
     _stickiedConnections.Remove(_stickiedConnections.Find(e => e.connection == connection && e.location == location));
 }
Пример #20
0
 // Construction.
 public StickiedConnection(GraphGrammarConnection connection, string location)
 {
     this.connection = connection;
     this.location   = location;
 }
Пример #21
0
 // Remove one connection.
 public static void RemoveConnection(GraphGrammarConnection connection)
 {
     _connections.Remove(connection);
 }