コード例 #1
0
        //Update the Lineconnector with values
        private void UpdateLine(ConnectionPort selectedport)
        {
            TopValue.Text    = selectedport.Top.ToString();
            LeftValue.Text   = selectedport.Left.ToString();
            WidthValue.Text  = selectedport.Width.ToString();
            HeightValue.Text = selectedport.Height.ToString();

            lineexpander.ToolTip = "";

            SolidColorBrush scb = selectedport.PortStyle.Fill as SolidColorBrush;

            fill.Color = scb.Color;
            SolidColorBrush scb1 = selectedport.PortStyle.Stroke as SolidColorBrush;

            stroke.Color = scb1.Color;
        }
コード例 #2
0
 //UpdateAppearance of  the ConnectionPorts
 private void UpdateAppearance(ConnectionPort cp, SolidColorBrush solidColorBrush, bool fill)
 {
     if (fill)
     {
         if (cp.PortStyle.Fill != null)
         {
             cp.PortStyle.Fill = null;
             //Ports can be customized using PortStyle property
             cp.PortStyle.Fill = solidColorBrush;
         }
     }
     else
     {
         cp.PortStyle.Stroke = solidColorBrush;
     }
 }
コード例 #3
0
        protected internal override void OnAddConnection(ConnectionPort port, ConnectionPort connection)
        {
            base.OnAddConnection(port, connection);

            if (!(connection.body is RPGTalkNode))
            {
                port.RemoveConnection(connection);
                return;
            }


            if (port.direction == Direction.In)
            {
                attachedTo = connection.body as RPGTalkNode;
            }
        }
コード例 #4
0
        /// <summary>
        /// Saves the XML document.
        /// </summary>
        public static void SaveXml()
        {
            using (XmlWriter writer = XmlWriter.Create(Paths.CreateOSPath("settings.xml"), XmlWriterSettings)) {
                writer.WriteStartDocument();
                writer.WriteStartElement("Options");

                writer.WriteStartElement("General");

                writer.WriteElementString("AutoSave", AutoSave.ToString());
                writer.WriteElementString("AutoSaveSpeed", AutoSaveSpeed.ToString());
                writer.WriteElementString("AutoScroll", AutoScroll.ToString());
                writer.WriteElementString("Music", Music.ToString());
                writer.WriteElementString("NpcBar", NpcBar.ToString());
                writer.WriteElementString("NpcDamage", NpcDamage.ToString());
                writer.WriteElementString("NpcName", NpcName.ToString());
                writer.WriteElementString("PlayerBar", PlayerBar.ToString());
                writer.WriteElementString("PlayerDamage", PlayerDamage.ToString());
                writer.WriteElementString("PlayerName", PlayerName.ToString());
                writer.WriteElementString("SavedAccount", SavedAccount);
                writer.WriteElementString("SavedPassword", SavedPassword);
                writer.WriteElementString("Sound", Sound.ToString());
                writer.WriteElementString("SpeechBubbles", SpeechBubbles.ToString());
                writer.WriteElementString("Timestamps", Timestamps.ToString());
                writer.WriteElementString("ActiveSkin", ActiveSkin);

                writer.WriteEndElement();
                writer.WriteStartElement("ConnectionInfo");

                writer.WriteElementString("Port", ConnectionPort.ToString());
                writer.WriteElementString("Server", ConnectionIP);
                writer.WriteElementString("UpdateLink", UpdateAddress);
                writer.WriteElementString("SFXLink", SoundAddress);
                writer.WriteElementString("MusicLink", MusicAddress);

                writer.WriteEndElement();
                writer.WriteStartElement("Editor");

                writer.WriteElementString("MapGrid", MapGrid.ToString());
                writer.WriteElementString("DisplayAttributes", DisplayAttributes.ToString());
                writer.WriteElementString("DragAndPlace", DragAndPlace.ToString());

                writer.WriteEndElement();

                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
        }
コード例 #5
0
        //Creating the LineConnector
        private LineConnector connection(Node head, Node tail, ConnectionPort headport, ConnectionPort tailport, string label)
        {
            LineConnector flow = new LineConnector();

            flow.HeadNode           = head;
            flow.TailNode           = tail;
            flow.ConnectionHeadPort = headport;
            flow.ConnectionTailPort = tailport;
            flow.ConnectorType      = ConnectorType.Straight;
            flow.TailDecoratorShape = DecoratorShape.None;
            flow.LineStyle.Stroke   = new SolidColorBrush(Colors.Brown);
            flow.Label = label;
            flow.LabelHorizontalAlignment = HorizontalAlignment.Center;
            flow.LabelVerticalAlignment   = VerticalAlignment.Center;
            diagramModel.Connections.Add(flow);
            return(flow);
        }
コード例 #6
0
ファイル: Window1.xaml.cs プロジェクト: Abbas1546/WPF
        //Defining the nodes.
        public void CreateNodes()
        {
            //Node n = addNode("", 100, 100, 60, 100);
            Node           node1             = addNode("", 200, 200, 100, 60);
            ConnectionPort NewIdeaOut        = addPort(node1, Brushes.Blue, Brushes.Blue, "In", 0, 10);
            ConnectionPort MeetingIn         = addPort(node1, Brushes.Blue, Brushes.Blue, "In", 0, 50);
            ConnectionPort MeetingOut        = addPort(node1, Brushes.Red, Brushes.Red, "Out", 100, 30);
            Node           node2             = addNode("", 400, 300, 100, 60);
            ConnectionPort BoardDecisionIn   = addPort(node2, Brushes.Blue, Brushes.Blue, "In", 0, 10);
            ConnectionPort BoardDecisionOut  = addPort(node2, Brushes.Blue, Brushes.Blue, "In", 0, 50);
            ConnectionPort BoardDecisionOut2 = addPort(node2, Brushes.Red, Brushes.Red, "Out", 100, 30);
            Node           node3             = addNode("", 600, 400, 100, 60);
            ConnectionPort projectIn         = addPort(node3, Brushes.Blue, Brushes.Blue, "In", 0, 10);
            ConnectionPort projectOut        = addPort(node3, Brushes.Blue, Brushes.Blue, "In", 0, 50);
            ConnectionPort projectOut2       = addPort(node3, Brushes.Red, Brushes.Red, "Out", 100, 30);
            Node           node4             = addNode("A.B.C.D", 800, 400, 100, 60);
            Node           node5             = addNode("A ", 100, 195, 30, 30);
            Node           node6             = addNode("B ", 100, 235, 30, 30);
            Node           node7             = addNode("C ", 100, 335, 30, 30);
            Node           node8             = addNode("D ", 100, 435, 30, 30);

            //Creates the connections for the nodes.
            Connect(ConnectorType.Orthogonal, node1, node2, MeetingOut, BoardDecisionIn, "A.B");
            Connect(ConnectorType.Orthogonal, node2, node3, BoardDecisionOut2, projectIn, "A.B.C");
            Connect(ConnectorType.Straight, node3, node4, projectOut2, null, "A.B.C.D");
            Connect(ConnectorType.Straight, node1, node5, NewIdeaOut, null, null);
            Connect(ConnectorType.Straight, node1, node6, MeetingIn, null, null);
            Connect(ConnectorType.Straight, node2, node7, BoardDecisionOut, null, null);
            Connect(ConnectorType.Straight, node3, node8, projectOut, null, null);


            //setting the alignment and connection Port size
            foreach (Node node in diagramModel.Nodes)
            {
                node.LabelHorizontalAlignment   = HorizontalAlignment.Center;
                node.LabelVerticalAlignment     = VerticalAlignment.Center;
                node.HorizontalContentAlignment = HorizontalAlignment.Center;
                node.VerticalContentAlignment   = VerticalAlignment.Center;
                foreach (ConnectionPort port in node.Ports)
                {
                    port.Width  = 10;
                    port.Height = 10;
                }
            }
            newConnDropped = false;
        }
コード例 #7
0
ファイル: Window1.xaml.cs プロジェクト: Abbas1546/WPF
        //Backup the reference, to revert the chages if it is invalid connection
        void diagramView_ConnectorDragStart(object sender, ConnDragRoutedEventArgs evtArgs)
        {
            LineConnector line = evtArgs.Connector;

            if (evtArgs.FixedNodeEnd == line.TailNode)
            {
                oldNode = line.HeadNode as Node;
                oldPort = line.ConnectionHeadPort;
                isHead  = true;
            }
            else
            {
                oldNode = line.TailNode as Node;
                oldPort = line.ConnectionTailPort;
                isHead  = false;
            }
        }
コード例 #8
0
        internal override EdgePoint GetEdgePointForPort(ConnectionPort port)
        {
            if (port == node.onEnterOutput)
            {
                return(new EdgePoint(node.onEnterOutput.rect.center, Vector2.down, colors.primaryColor2, colors.primaryColor1));
            }

            if (port == node.onUpdateOutput)
            {
                return(new EdgePoint(node.onUpdateOutput.rect.center, Vector2.down, colors.primaryColor2, colors.primaryColor1));
            }

            if (port == node.onExitOutput)
            {
                return(new EdgePoint(node.onExitOutput.rect.center, Vector2.down, colors.primaryColor2, colors.primaryColor1));
            }

            return(base.GetEdgePointForPort(port));
        }
コード例 #9
0
        internal override EdgePoint GetEdgePointForPort(ConnectionPort port)
        {
            if (port == node.input)
            {
                return(new EdgePoint(node.input.rect.center, Vector2.up, colors.primaryColor2, colors.primaryColor1));
            }

            if (port == node.outputTrue)
            {
                return(new EdgePoint(node.outputTrue.rect.center, Vector2.down, colors.primaryColor2, colors.primaryColor1));
            }

            if (port == node.outputFalse)
            {
                return(new EdgePoint(node.outputFalse.rect.center, Vector2.down, colors.primaryColor2, colors.primaryColor1));
            }

            return(base.GetEdgePointForPort(port));
        }
コード例 #10
0
 //Fill and Stroke Color changed
 private void fill_ColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     Syncfusion.Windows.Tools.Controls.ColorPickerPalette cpp = d as Syncfusion.Windows.Tools.Controls.ColorPickerPalette;
     if (diagramView.SelectionList.Count > 0)
     {
         if (head.IsChecked == true)
         {
             foreach (object o in diagramView.SelectionList)
             {
                 if (o is LineConnector)
                 {
                     ConnectionPort cp = (o as LineConnector).ConnectionHeadPort;
                     if (cpp.Name == "fill")
                     {
                         UpdateAppearance(cp, new SolidColorBrush(fill.Color), true);
                     }
                     else if (cpp.Name == "stroke")
                     {
                         UpdateAppearance(cp, new SolidColorBrush(stroke.Color), false);
                     }
                 }
             }
         }
         else if (tail.IsChecked == true)
         {
             foreach (object o in diagramView.SelectionList)
             {
                 if (o is LineConnector)
                 {
                     ConnectionPort cp = (o as LineConnector).ConnectionTailPort;
                     if (cpp.Name == "fill")
                     {
                         UpdateAppearance(cp, new SolidColorBrush(fill.Color), true);
                     }
                     else if (cpp.Name == "stroke")
                     {
                         UpdateAppearance(cp, new SolidColorBrush(stroke.Color), false);
                     }
                 }
             }
         }
     }
 }
コード例 #11
0
        /// <summary>
        /// Remove the transition between the two given ports.
        /// </summary>
        public static void DisconnectPorts(ConnectionPort port1, ConnectionPort port2, bool autoSave = true)
        {
            port1.Disconnect(port2);

            #if SERIALIZER_DEBUG
            Debug.Log("Port [" + port1.name + "] disconnected from Port [" + port2.name + "]");
            #endif

            if (autoSave)
            {
                Save();
            }

            if (port1.node && port1.node.controller)
            {
                port1.node.controller.isDirty = true;
            }
            else if (port2.node && port2.node.controller)
            {
                port2.node.controller.isDirty = true;
            }
        }
コード例 #12
0
        public override bool CanApplyConnection(ConnectionPort port)
        {
            if (port is FSMInputNode)
            {
                FSMInputNode valueKnob = port as FSMInputNode;
                if (valueKnob == null || !valueType.IsAssignableFrom(valueKnob.valueType))
                {
                    return(false);
                }

                if (valueKnob == null || body == valueKnob.body || connections.Contains(valueKnob))
                {
                    return(false);
                }

                if (direction == Direction.None && valueKnob.direction == Direction.None)
                {
                    return(true); // None-Directive connections can always connect
                }
                if (direction == Direction.In && valueKnob.direction != Direction.Out)
                {
                    return(false); // Cannot connect inputs with anything other than outputs
                }
                if (direction == Direction.Out && valueKnob.direction != Direction.In)
                {
                    return(false);              // Cannot connect outputs with anything other than inputs
                }
                if (direction == Direction.Out) // Let inputs handle checks for recursion
                {
                    return(base.CanApplyConnection(this));
                }

                return(true);
            }

            return(false);
        }
コード例 #13
0
        void CreateChoiceNode(ref string line, ref Vector2 position, ref RPGTalkNode fatherNode, int choiceNum, ref StringReader sReader, ref int currentLine)
        {
            int initialBracket = line.IndexOf("[choice]");

            //Ok! Let's isolate its string
            line = line.Substring(initialBracket + 8);

            RPGTalkChoiceNode choiceNode = Node.Create("rpgtalkChoiceNode", position) as RPGTalkChoiceNode;


            //Connect the node
            ConnectionPort myPort = null;

            foreach (ConnectionPort port in choiceNode.connectionPorts)
            {
                if (port.direction == Direction.In)
                {
                    myPort = port;
                    break;
                }
            }

            foreach (ConnectionPort port in fatherNode.connectionPorts)
            {
                if (port.direction == Direction.Out)
                {
                    port.ApplyConnection(myPort);
                    break;
                }
            }


            //Let's check if it has a follow up
            GetNewTalkTag(ref line, ref position, ref currentLine, ref sReader, choiceNode, choiceNum - 1);

            choiceNode.DialogLine = line;
        }
コード例 #14
0
 public bool ContinueCalculation(Node node)
 {
     if (node.calculated && !node.AllowRecursion)
     { // Already calulated
         return(true);
     }
     if (node.ancestorsCalculated() && node.Calculate())
     { // Calculation was successful
         node.calculated = true;
         if (node.ContinueCalculation)
         { // Continue with children
             for (int i = 0; i < node.outputPorts.Count; i++)
             {
                 ConnectionPort outPort = node.outputPorts[i];
                 for (int t = 0; t < outPort.connections.Count; t++)
                 {
                     ContinueCalculation(outPort.connections[t].body);
                 }
             }
         }
         return(true);
     }
     return(false);
 }
コード例 #15
0
        public override void OnProcess(Event e)
        {
            if (m_menu != null)
            {
                m_menu.ShowAsContext();
                m_menu = null;
            }

            if (m_port1 != null && m_port2 != null)
            {
                ConnectionPort port1 = m_port1;
                ConnectionPort port2 = m_port2;
                m_port1 = null;
                m_port2 = null;

                m_menu = new GenericMenu();
                m_menu.AddItem(new GUIContent("Delete Transition"), false, () => {
                    string recordTitle = "Connection removed: [" + port1.node.name + " : " + port1.name + "] -> [" + port2.node.name + " : " + port2.name + "]";
                    GraphUndo.RecordAndPerform(recordTitle,
                                               () => { Serializer.DisconnectPorts(port1, port2); },
                                               () => { Serializer.ConnectPorts(port1, port2); });
                });
            }
        }
コード例 #16
0
        void CreateNode(ref string line, ref Vector2 position, ref int currentLine, string cutsceneTitle, ref StringReader sReader, ref RPGTalkNode fatherNode, bool startNode = false)
        {
            RPGTalkNode thisNode     = null;
            int         characterID  = 0;
            int         expressionID = 0;
            string      dialoger;


            //Good. Let's create the node
            thisNode    = Node.Create("rpgtalkNode", position) as RPGTalkNode;
            position.x += 400;

            //If it is a [title] line, we don't want to actually read it, but the line after it
            if (startNode)
            {
                thisNode.CutsceneTitle = cutsceneTitle;
                line = sReader.ReadLine();
                currentLine++;
            }

            //dialoger
            GetDialoger(line, out line, out characterID, out expressionID, out dialoger);
            thisNode.characterID  = characterID;
            thisNode.expressionID = expressionID;

            //questions
            string questionID;

            GetQuestion(line, out line, out questionID);

            thisNode.DialogLine = line;


            //Connect the node
            if (fatherNode != null)
            {
                ConnectionPort myPort = null;
                foreach (ConnectionPort port in thisNode.connectionPorts)
                {
                    if (port.direction == Direction.In)
                    {
                        myPort = port;
                        break;
                    }
                }

                foreach (ConnectionPort port in fatherNode.connectionPorts)
                {
                    if (port.direction == Direction.Out)
                    {
                        port.ApplyConnection(myPort);
                        break;
                    }
                }
            }

            fatherNode = thisNode;


            if (questionID.Length > 0)
            {
                thisNode.questionID = questionID;
                line = sReader.ReadLine();
                currentLine++;
                int   choices   = 0;
                float originalY = position.y;
                while (line != null && line.IndexOf("[choice]") != -1)
                {
                    choices++;
                    if (choices % 2 == 0)
                    {
                        position.y = originalY + 100;
                    }
                    else
                    {
                        position.y = originalY - 40;
                    }

                    CreateChoiceNode(ref line, ref position, ref fatherNode, choices, ref sReader, ref currentLine);

                    line = sReader.ReadLine();
                    currentLine++;

                    if (choices % 2 == 0 || line == null || line.IndexOf("[choice]") == -1)
                    {
                        position.x += 180;
                    }

                    continue;
                }
                position.y = originalY;
            }
            else
            {
                line = sReader.ReadLine();
                currentLine++;
            }


            createdNodes.Add(thisNode);
        }
コード例 #17
0
        // RPGTalk added to load the TXT!
        void LoadTXTFile()
        {
            //Get the actual selected path
            string selectedPath = "Assets";

            foreach (UnityEngine.Object obj in Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Assets))
            {
                selectedPath = AssetDatabase.GetAssetPath(obj);
                if (File.Exists(selectedPath))
                {
                    selectedPath = Path.GetDirectoryName(selectedPath);
                }
                break;
            }
            string path = EditorUtility.OpenFilePanel("Load dialog TXT", selectedPath, "txt");

            //first, clear the canvas.
            canvasCache.NewNodeCanvas(typeof(RPGTalkNodeCanvas));

            // read the TXT file into the elements list
            StreamReader reader  = new StreamReader(path);
            string       txtFile = reader.ReadToEnd();

            reader.Close();
            StringReader sReader = new StringReader(txtFile);

            string line        = sReader.ReadLine();
            int    currentLine = 0;

            if (line == null)
            {
                Debug.LogError("There was an error reading your file! Check your encoding settings.");
                return;
            }

            RPGTalkNode fatherNode = null;
            Vector2     position   = Vector2.zero;

            followUpNodes = new List <FollowUpNode>();
            createdNodes  = new List <RPGTalkNode>();

            while (line != null)
            {
                //If the line is empty, we will just ignore it
                if (string.IsNullOrEmpty(line))
                {
                    line = sReader.ReadLine();
                    currentLine++;
                    continue;
                }



                //Lets check with this is an oppening node
                int titleLine = line.IndexOf("[title=");
                if (titleLine != -1)
                {
                    string title    = "";
                    int    titleEnd = line.IndexOf("]", titleLine);
                    if (titleEnd != -1)
                    {
                        title = line.Substring(titleLine + 7, titleEnd - (titleLine + 7));
                    }
                    else
                    {
                        Debug.LogError("Error reading title");
                    }

                    if (title.Length > 0)
                    {
                        //Good. We got a title. Let's find out if it is an oppening or a closing one
                        if (title.IndexOf("_begin") != -1)
                        {
                            title = title.Substring(0, title.IndexOf("_begin"));

                            CreateNode(ref line, ref position, ref currentLine, title, ref sReader, ref fatherNode, true);

                            continue;
                        }
                        else if (title.IndexOf("_end") != -1)
                        {
                            //end last title node
                            position.y += 250;
                            position.x  = 0;
                            fatherNode  = null;

                            line = sReader.ReadLine();
                            currentLine++;
                            continue;
                        }
                        else
                        {
                            Debug.LogError("Right now, Node Editor only reads TXT made with node editor. You can change your TXT title to have _begin and _end tags");
                        }
                    }
                }// end if title



                //Let's check if this line is a save
                if (line.IndexOf("[save") != -1 && line.IndexOf("]") != -1)
                {
                    //We do have one!
                    int initialBracket = line.IndexOf("[save");
                    int finalBracket   = -1;
                    if (initialBracket != -1)
                    {
                        finalBracket = line.IndexOf("]", initialBracket);
                    }

                    //There still are any '[save' and it is before a ']'?
                    if (initialBracket < finalBracket)
                    {
                        //Everything fine until now. Now let's check the start and break variables
                        int indexOfStart = line.IndexOf("start=", initialBracket + 5);
                        int endOfStart   = line.IndexOf(" ", indexOfStart);
                        if (endOfStart == -1)
                        {
                            endOfStart = line.IndexOf("]", indexOfStart);
                        }
                        int indexOfBreak = line.IndexOf("break=", initialBracket + 5);
                        int endOfBreak   = line.IndexOf(" ", indexOfBreak);
                        if (endOfBreak == -1)
                        {
                            endOfBreak = line.IndexOf("]", indexOfBreak);
                        }
                        int indexOfSavedData = line.IndexOf("data=", initialBracket + 5);
                        int endOfSavedData   = line.IndexOf(" ", indexOfSavedData);
                        if (endOfSavedData == -1)
                        {
                            endOfSavedData = line.IndexOf("]", indexOfSavedData);
                        }
                        int indexOfModifier = line.IndexOf("mod=", initialBracket + 5);
                        int endOfModifier   = line.IndexOf(" ", indexOfModifier);
                        if (endOfModifier == -1)
                        {
                            endOfModifier = line.IndexOf("]", indexOfModifier);
                        }



                        if (indexOfStart != -1 && indexOfBreak != -1 && endOfBreak != -1 && endOfStart != -1 &&
                            indexOfSavedData != -1 && endOfSavedData != -1 && indexOfModifier != -1 && endOfModifier != -1)
                        {
                            string newLineToStart = line.Substring(indexOfStart + 6, endOfStart - (indexOfStart + 6));
                            string newLineToBreak = line.Substring(indexOfBreak + 6, endOfBreak - (indexOfBreak + 6));
                            string newSavedData   = line.Substring(indexOfSavedData + 5, endOfSavedData - (indexOfSavedData + 5));
                            string newModfier     = line.Substring(indexOfModifier + 4, endOfModifier - (indexOfModifier + 4));
                            int    intModifier;

                            if (newLineToStart.Length > 0 && newLineToBreak.Length > 0 && newSavedData.Length > 0 && int.TryParse(newModfier, out intModifier))
                            {
                                //Good, this a valid save. Let's create the node
                                RPGTalkSaveNode thisNode = Node.Create("rpgtalkSaveNode", position) as RPGTalkSaveNode;
                                position.x += 300;

                                thisNode.modifier  = intModifier;
                                thisNode.savedData = newSavedData;

                                //Lets keep this node to move and connect later
                                FollowUpNode followUp = new FollowUpNode();
                                followUp.node          = thisNode;
                                followUp.followUpTitle = newLineToStart;
                                //followUp.identifier = choiceNum;
                                line = sReader.ReadLine();
                                currentLine++;
                                followUpNodes.Add(followUp);


                                //Connect the node
                                if (fatherNode != null)
                                {
                                    ConnectionPort myPort = null;
                                    foreach (ConnectionPort port in thisNode.connectionPorts)
                                    {
                                        if (port.direction == Direction.In)
                                        {
                                            myPort = port;
                                            break;
                                        }
                                    }

                                    foreach (ConnectionPort port in fatherNode.connectionPorts)
                                    {
                                        if (port.direction == Direction.Out)
                                        {
                                            port.ApplyConnection(myPort);
                                            break;
                                        }
                                    }
                                }


                                continue;
                            }
                            else
                            {
                                Debug.LogWarning("There was a problem in your save variables. Check The spelling");
                            }
                        }
                        else
                        {
                            Debug.LogWarning("Found a [save] variable in the text but it didn't had a variable. Check The spelling");
                        }
                    }
                }



                //This is none of the special lines. So it must be a common node.
                CreateNode(ref line, ref position, ref currentLine, "", ref sReader, ref fatherNode);
            }



            //Everything created. Everthing fine. Let's now add connections to the follow up nodes (choices and saves)
            foreach (FollowUpNode follow in followUpNodes)
            {
                //the follow up node is exclusive to the prior node? if it isn't, we don't want to move it. Just add the connection
                if (follow.followUpTitle.IndexOf("FollowUp_") != -1 && follow.followUpTitle.IndexOf("Choice_" + follow.identifier.ToString()) != -1)
                {
                    //TODO: Move the followups
                }


                //Find out what node should if be connected to
                foreach (RPGTalkNode talkNode in createdNodes)
                {
                    string removeBegin = follow.followUpTitle.Substring(0, follow.followUpTitle.LastIndexOf("_begin"));

                    if (talkNode.CutsceneTitle == removeBegin)
                    {
                        //Connect the nodes
                        ConnectionPort myPort = null;
                        foreach (ConnectionPort port in follow.node.connectionPorts)
                        {
                            if (port.direction == Direction.Out)
                            {
                                myPort = port;
                                break;
                            }
                        }

                        foreach (ConnectionPort port in talkNode.connectionPorts)
                        {
                            if (port.direction == Direction.In)
                            {
                                port.ApplyConnection(myPort);
                                break;
                            }
                        }


                        break;
                    }
                }
            }
        }
コード例 #18
0
        public override void ProcessEvent(CoreMouseEventArgs e)
        {
            switch (e.Type)
            {
            case CoreMouseEventProcessor.MouseDown:
            {
                CoreMouseDownEventArgs args            = e as CoreMouseDownEventArgs;
                BaseUMLObject          LastStartTarget = Panel.TopBaseUMLObjectsAt(args.Location);
                break;
            }

            case CoreMouseEventProcessor.MouseDragging:
            {
                CoreMouseDraggingEventArgs args = e as CoreMouseDraggingEventArgs;
                //Console.WriteLine("BaseConnShape_Mode::MouseDragging{(" + args.Start.X + "," + args.Start.Y + ")->(" + args.End.X + "," + args.End.Y + ")," + args.Distance + ",key=" + args.Button + "}");
                BaseUMLObject  StartTarget = Panel.TopBaseUMLObjectsAt(args.Start);
                BaseUMLObject  EndTarget = Panel.TopBaseUMLObjectsAt(args.End);
                ConnectionPort StartPort = null, EndPort = null;
                DrawingGroup   PanelForeground = Panel.getForeground();
                if (StartTarget != null)
                {
                    StartPort = StartTarget.NearConnectionPort(args.Start);
                }
                if (EndTarget != null)
                {
                    EndPort = EndTarget.NearConnectionPort(args.End);
                }
                if (StartTarget != null)          //開始點在BaseUMLObject上
                {
                    if (LastEndTarget != null)    //上次的EndTarget不為空,將他的Ports顏色還原並取消選取
                    {
                        foreach (ConnectionPort port in LastEndTarget.AllConnectionPort())
                        {
                            port.setHighLight(false);
                        }
                        LastEndTarget.setSelected(false);
                        LastEndTarget = null;
                    }
                    if (EndTarget != null)                                               //開始點在BaseUMLObject上,結束點在BaseUMLObject上,把開始BaseUMLObject和結束BaseUMLObject的目標Port來HighLight
                    {
                        foreach (ConnectionPort port in StartTarget.AllConnectionPort()) //將開始BaseUMLObject顏色還原
                        {
                            port.setHighLight(false);
                        }
                        if (StartPort != null)          //設定開始BaseUMLObject目標Port顏色
                        {
                            StartPort.setHighLight(true);
                        }
                        StartTarget.setSelected(true);
                        if (EndTarget != StartTarget)                                      //結束和開始不相同
                        {
                            foreach (ConnectionPort port in EndTarget.AllConnectionPort()) //將結束BaseUMLObject顏色還原
                            {
                                port.setHighLight(false);
                            }
                            if (EndPort != null)          //設定結束BaseUMLObject目標Port顏色
                            {
                                EndPort.setHighLight(true);
                            }
                            EndTarget.setSelected(true);
                            LastEndTarget = EndTarget;          //設定上次的EndTarget為此次的EndTarget
                        }
                    }
                    else          //開始點在BaseUMLObject上,結束點不在BaseUMLObject上
                    {
                        //開始點在BaseUMLObject上,結束點不在BaseUMLObject上
                        //將開始BaseUMLObject顏色還原
                        foreach (ConnectionPort port in StartTarget.AllConnectionPort())
                        {
                            port.setHighLight(false);
                        }
                        //選取開始BaseUMLObject讓其能繪出Port顏色
                        StartTarget.setSelected(true);
                    }
                    using (DrawingContext dc = PanelForeground.Open())          //要求子類別畫出預覽圖形
                    {
                        ProcessPreviewConnShape(dc, args.Start, args.End);
                    }
                }
                else
                {
                    if (LastStartTarget != null)          //開始點不在BaseUMLObject上,將上次StartTarget的Port顏色還原
                    {
                        foreach (ConnectionPort port in LastStartTarget.AllConnectionPort())
                        {
                            port.setHighLight(false);
                        }
                        LastStartTarget = null;
                    }
                }
                break;
            }

            case CoreMouseEventProcessor.MouseDragEnd:
            {
                CoreMouseDragEndEventArgs args = e as CoreMouseDragEndEventArgs;
                //Console.WriteLine("BaseConnShape_Mode::MouseDragEnd{(" + args.Start.X + "," + args.Start.Y + ")->(" + args.End.X + "," + args.End.Y + ")," + args.Distance + ",key=" + args.Button + "}");
                BaseUMLObject  StartTarget = Panel.TopBaseUMLObjectsAt(args.Start);
                BaseUMLObject  EndTarget = Panel.TopBaseUMLObjectsAt(args.End);
                ConnectionPort StartPort = null, EndPort = null;
                DrawingGroup   PanelForeground = Panel.getForeground();
                if (StartTarget != null)
                {
                    foreach (ConnectionPort port in StartTarget.AllConnectionPort())          //將開始BaseUMLObject顏色還原
                    {
                        port.setHighLight(false);
                    }
                    StartTarget.setSelected(false);          //將開始BaseUMLObject取消選取
                    StartPort = StartTarget.NearConnectionPort(args.Start);
                }
                if (EndTarget != null)
                {
                    foreach (ConnectionPort port in EndTarget.AllConnectionPort())          //將開始BaseUMLObject顏色還原
                    {
                        port.setHighLight(false);
                    }
                    EndTarget.setSelected(false);          //將開始BaseUMLObject取消選取
                    EndPort = EndTarget.NearConnectionPort(args.End);
                }
                if (StartPort != null && EndPort != null && StartTarget != EndTarget)
                {
                    ProcessAddConnShape(StartPort, EndPort);
                }
                break;
            }

            case CoreMouseEventProcessor.MouseUp:
            {
                Panel.getForeground().Children.Clear();
                break;
            }
            }
        }
コード例 #19
0
 protected abstract void ProcessAddConnShape(ConnectionPort StartPort, ConnectionPort EndPort);
コード例 #20
0
        protected internal override void OnAddConnection(ConnectionPort port, ConnectionPort connection)
        {
            base.OnAddConnection(port, connection);
            if (port.direction == Direction.In)
            {
                if (connection.body.isChildOf(this))
                {
                    return;
                }

                if (connection.body is RPGTalkNode)
                {
                    startOfCutscene = false;
                    if (attachedTo == null)
                    {
                        attachedTo    = connection.body as RPGTalkNode;
                        CutsceneTitle = attachedTo.CutsceneTitle;
                    }
                }
                else if (connection.body is RPGTalkChoiceNode)
                {
                    if (attachedToChoice == null)
                    {
                        attachedToChoice = connection.body as RPGTalkChoiceNode;
                    }
                    //I am the result of a choice
                    if (attachedToChoice.attachedTo != null)
                    {
                        CutsceneTitle = "FollowUp_" + attachedToChoice.attachedTo.CutsceneTitle + "_" + attachedToChoice.Title;
                    }
                    else
                    {
                        CutsceneTitle = "FollowUp_" + attachedToChoice.Title;
                    }
                }
                else
                {
                    if (attachedToSave == null)
                    {
                        attachedToSave = connection.body as RPGTalkSaveNode;
                    }
                    //I am the result of a choice
                    if (attachedToSave.attachedTo != null)
                    {
                        CutsceneTitle = "FollowUp_" + attachedToSave.attachedTo.CutsceneTitle + "_" + attachedToSave.Title;
                    }
                    else
                    {
                        CutsceneTitle = "FollowUp_" + attachedToSave.Title;
                    }
                }
            }
            else
            {
                //make sure that will be only one connection to RPGTalkNode
                List <ConnectionPort> toDelete = new List <ConnectionPort>();
                foreach (ConnectionPort connected in outputPorts[0].connections)
                {
                    if (connection.body is RPGTalkNode)
                    {
                        if (connected != connection)
                        {
                            toDelete.Add(connected);
                        }
                    }
                    else if (connection.body is RPGTalkChoiceNode)
                    {
                        if (connected != connection && (connected.body is RPGTalkNode || connected.body is RPGTalkSaveNode))
                        {
                            toDelete.Add(connected);
                        }
                    }
                    else
                    {
                        if (connected != connection && (connected.body is RPGTalkNode || connected.body is RPGTalkChoiceNode))
                        {
                            toDelete.Add(connected);
                        }
                    }
                }

                foreach (ConnectionPort deleteMe in toDelete)
                {
                    outputPorts[0].RemoveConnection(deleteMe);
                }

                //Add choice
                if (connection.body is RPGTalkChoiceNode)
                {
                    choices.Add(connection.body as RPGTalkChoiceNode);
                }

                //Add save
                if (connection.body is RPGTalkSaveNode)
                {
                    saves.Add(connection.body as RPGTalkSaveNode);
                }
            }

            (NodeEditor.curNodeCanvas as RPGTalkNodeCanvas).GetNextLineInTxt();
        }
コード例 #21
0
 public void SetNode(ConnectionPort node)
 {
     setNode(node);
 }
コード例 #22
0
 internal override EdgePoint GetEdgePointForPort(ConnectionPort port)
 {
     return(new EdgePoint(port.rect.center, Vector2.up, colors.primaryColor2, colors.primaryColor1));
 }
コード例 #23
0
 /// <summary>
 /// Returns the edge point for the given port.
 /// </summary>
 internal abstract EdgePoint GetEdgePointForPort(ConnectionPort port);
コード例 #24
0
        /// <summary>
        /// Draws a connection port and updates the position.
        /// </summary>
        /// <param name="port">The port that should be drawn.</param>
        /// <param name="newPortPosition">The new position of the port.</param>
        /// <param name="portPositionAlignment">The alignment of the draw position.</param>
        /// <param name="labelPosition">The label position.</param>
        /// <param name="updateOnlyPosition">If this is true, only the position of the given port will be updated.</param>
        protected internal void DrawConnectionPort(ConnectionPort port, Vector2 newPortPosition, Alignment portPositionAlignment, LabelPosition labelPosition, bool updateOnlyPosition = false)
        {
            Vector2 boundsPosition = Vector2.zero;

            switch (portPositionAlignment)
            {
            case Alignment.TopLeft:
                boundsPosition = newPortPosition + Styles.visualPortSize / 2 - Styles.connectionPortBoundsSize / 2;
                break;

            case Alignment.TopRight:
                boundsPosition = new Vector2(newPortPosition.x - Styles.visualPortSize.x / 2 - Styles.connectionPortBoundsSize.x / 2, newPortPosition.y + Styles.visualPortSize.y / 2 - Styles.connectionPortBoundsSize.y / 2);
                break;

            case Alignment.BottomLeft:
                boundsPosition = new Vector2(newPortPosition.x + Styles.visualPortSize.x / 2 - Styles.connectionPortBoundsSize.x / 2, newPortPosition.y - Styles.visualPortSize.y / 2 - Styles.connectionPortBoundsSize.y / 2);
                break;

            case Alignment.BottomRight:
                boundsPosition = newPortPosition - Styles.visualPortSize / 2 - Styles.connectionPortBoundsSize / 2;
                break;

            case Alignment.Center:
                boundsPosition = newPortPosition - Styles.connectionPortBoundsSize / 2;
                break;

            case Alignment.MiddleLeft:
                boundsPosition = new Vector2(newPortPosition.x + Styles.visualPortSize.x / 2 - Styles.connectionPortBoundsSize.x / 2, newPortPosition.y - Styles.connectionPortBoundsSize.y / 2);
                break;

            case Alignment.MiddleRight:
                boundsPosition = new Vector2(newPortPosition.x - Styles.visualPortSize.x / 2 - Styles.connectionPortBoundsSize.x / 2, newPortPosition.y - Styles.connectionPortBoundsSize.y / 2);
                break;

            case Alignment.MiddleTop:
                boundsPosition = new Vector2(newPortPosition.x - Styles.connectionPortBoundsSize.x / 2, newPortPosition.y + Styles.visualPortSize.y / 2 - Styles.connectionPortBoundsSize.y / 2);
                break;

            case Alignment.MiddleBottom:
                boundsPosition = new Vector2(newPortPosition.x - Styles.connectionPortBoundsSize.x / 2, newPortPosition.y - Styles.visualPortSize.y / 2 - Styles.connectionPortBoundsSize.y / 2);
                break;
            }

            port.position = boundsPosition;
            port.size     = Styles.connectionPortBoundsSize;


            if (!updateOnlyPosition)
            {
                Vector2 visualPosition     = boundsPosition - node.position + Styles.connectionPortBoundsSize / 2 - Styles.visualPortSize / 2;
                Rect    connectionPortRect = new Rect(visualPosition, Styles.visualPortSize);

                Color portColor = colors.primaryColor1;

                EditorGUI.DrawSolidTexture(connectionPortRect, portColor, new BorderWidth(Styles.connectionPortStroke), new BorderRadius(90));

                if (port.hasConnections || canvas.IsPortSelected(port) || port.rect.Contains(mousePositionOnNode))
                {
                    EditorGUI.DrawTexture(connectionPortRect, Styles.portHoverIcon, ScaleMode.ScaleToFit, 0, portColor, true, BorderWidth.zero, BorderRadius.zero);
                }

                switch (labelPosition)
                {
                case LabelPosition.Left:
                    EditorGUI.Label(
                        visualPosition.x - Styles.connectionPortLabelPadding - Styles.portLabelWidth, visualPosition.y,
                        Styles.portLabelWidth, Styles.visualPortSize.y, port.name, Styles.portLabelStyleLeft
                        );
                    break;

                case LabelPosition.Right:
                    EditorGUI.Label(
                        visualPosition.x + Styles.visualPortSize.x + Styles.connectionPortLabelPadding, visualPosition.y,
                        Styles.portLabelWidth, Styles.visualPortSize.y, port.name, Styles.portLabelStyleRight
                        );
                    break;

                case LabelPosition.Top:
                    EditorGUI.Label(
                        visualPosition.x + Styles.visualPortSize.x / 2 - Styles.portLabelWidth / 2, visualPosition.y - Styles.connectionPortLabelPadding - Styles.visualPortSize.y,
                        Styles.portLabelWidth, Styles.visualPortSize.y, port.name, Styles.portLabelStyleTop);
                    break;

                case LabelPosition.Bottom:
                    EditorGUI.Label(
                        visualPosition.x + Styles.visualPortSize.x / 2 - Styles.portLabelWidth / 2, visualPosition.y + Styles.connectionPortLabelPadding + Styles.visualPortSize.y,
                        Styles.portLabelWidth, Styles.visualPortSize.y, port.name, Styles.portLabelStyleBottom);
                    break;
                }
            }
        }
コード例 #25
0
 /// <summary>
 /// Disconnect nanoFramework device
 /// </summary>
 public override void Disconnect(bool force = false)
 {
     ConnectionPort.DisconnectDevice(force);
 }
        public override void OnProcess(Event e)
        {
            // select port
            if (e.IsMouseDown(MouseButton.Left) && m_selectedPort == null && e.IsMouseInsideRect(canvas.unscaledRect))
            {
                for (int i = 0; i < canvas.nodes.Length; i++)
                {
                    Node currentNode = canvas.nodes[i];

                    if (currentNode.isHidden)
                    {
                        continue;
                    }

                    ConnectionPort[] currentNodePorts = currentNode.ports;

                    for (int j = 0; j < currentNodePorts.Length; j++)
                    {
                        ConnectionPort currentNodePort = currentNodePorts[j];

                        if (!currentNodePort.isHidden && currentNodePort.rect.Contains(canvas.mousePosition))
                        {
                            m_selectedPort      = currentNodePort;
                            canvas.selectedPort = currentNodePort;

                            break;
                        }
                    }

                    if (m_selectedPort != null)
                    {
                        e.Use();
                        break;
                    }
                }
            }


            // drag port
            if (e.IsMouseDrag(MouseButton.Left) && m_selectedPort != null)
            {
                graph.Repaint();
                e.Use();
            }

            // connect
            if (e.IsMouseUp(MouseButton.Left) && m_selectedPort != null)
            {
                bool connectionExecuted = false;

                for (int i = 0; i < canvas.nodes.Length; i++)
                {
                    Node currentNode = canvas.nodes[i];

                    if (currentNode.isHidden)
                    {
                        continue;
                    }

                    ConnectionPort[] currentNodePorts = currentNode.ports;

                    for (int j = 0; j < currentNodePorts.Length; j++)
                    {
                        ConnectionPort currentNodePort = currentNodePorts[j];

                        if (!currentNodePort.isHidden && currentNodePort.rect.Contains(canvas.mousePosition))
                        {
                            ConnectionPort fromPort = m_selectedPort;
                            ConnectionPort toPort   = currentNodePort;

                            bool connectionSuccess = Serializer.ConnectPorts(fromPort, toPort);

                            if (connectionSuccess)
                            {
                                GraphUndo.Record(fromPort.node.name + " connected to " + toPort.node.name,
                                                 () => { Serializer.DisconnectPorts(fromPort, toPort); },
                                                 () => { Serializer.ConnectPorts(fromPort, toPort); });
                            }

                            connectionExecuted = true;
                            break;
                        }
                    }

                    if (connectionExecuted)
                    {
                        break;
                    }
                }

                m_selectedPort      = null;
                canvas.selectedPort = null;
                e.Use();
            }
        }
コード例 #27
0
ファイル: Server.cs プロジェクト: maranarasauce/boneworks-mp
 public override int GetHashCode()
 {
     return(Address.GetHashCode() + SteamId.GetHashCode() + ConnectionPort.GetHashCode() + QueryPort.GetHashCode());
 }
コード例 #28
0
ファイル: XMLImportExport.cs プロジェクト: FoeFear/shellcore
        public override CanvasData ImportData(params object[] args)
        {
            if (args == null || args.Length != 1 || args[0].GetType() != typeof(string))
            {
                throw new ArgumentException("Location Arguments");
            }
            string path = (string)args[0];

            using (FileStream fs = new FileStream(path, FileMode.Open))
            {
                XmlDocument data = new XmlDocument();
                data.Load(fs);

                // CANVAS

                string     canvasName = Path.GetFileNameWithoutExtension(path);
                XmlElement xmlCanvas  = (XmlElement)data.SelectSingleNode("//NodeCanvas");
                Type       canvasType = NodeCanvasManager.GetCanvasTypeData(xmlCanvas.GetAttribute("type")).CanvasType;
                if (canvasType == null)
                {
                    throw new XmlException("Could not find NodeCanvas of type '" + xmlCanvas.GetAttribute("type") + "'!");
                }
                CanvasData canvasData            = new CanvasData(canvasType, canvasName);
                Dictionary <int, PortData> ports = new Dictionary <int, PortData>();

                // OBJECTS

                IEnumerable <XmlElement> xmlObjects = xmlCanvas.SelectNodes("Objects/Object").OfType <XmlElement>();
                foreach (XmlElement xmlObject in xmlObjects)
                {
                    int        refID    = GetIntegerAttribute(xmlObject, "refID");
                    string     typeName = xmlObject.GetAttribute("type");
                    Type       type     = Type.GetType(typeName, true);
                    object     obj      = DeserializeObjectFromXML(xmlObject, type);
                    ObjectData objData  = new ObjectData(refID, obj);
                    canvasData.objects.Add(refID, objData);
                }

                // NODES

                IEnumerable <XmlElement> xmlNodes = xmlCanvas.SelectNodes("Nodes/Node").OfType <XmlElement>();
                foreach (XmlElement xmlNode in xmlNodes)
                {
                    string  name    = xmlNode.GetAttribute("name");
                    int     nodeID  = GetIntegerAttribute(xmlNode, "ID");
                    string  typeID  = xmlNode.GetAttribute("type");
                    Vector2 nodePos = GetVectorAttribute(xmlNode, "pos");
                    // Record
                    NodeData node = new NodeData(name, typeID, nodeID, nodePos);
                    canvasData.nodes.Add(nodeID, node);

                    // NODE PORTS

                    IEnumerable <XmlElement> xmlConnectionPorts = xmlNode.SelectNodes("Port").OfType <XmlElement>();
                    foreach (XmlElement xmlPort in xmlConnectionPorts)
                    {
                        int    portID   = GetIntegerAttribute(xmlPort, "ID");
                        string portName = xmlPort.GetAttribute("name");
                        if (string.IsNullOrEmpty(portName))                         // Fallback to old save
                        {
                            portName = xmlPort.GetAttribute("varName");
                        }
                        bool     dynamic = GetBooleanAttribute(xmlPort, "dynamic", false);
                        PortData portData;
                        if (!dynamic)                         // Record static port
                        {
                            portData = new PortData(node, portName, portID);
                        }
                        else
                        {                         // Deserialize dynamic port
                            string typeName = xmlPort.GetAttribute("type");
                            Type   portType = Type.GetType(typeName, true);
                            if (portType != typeof(ConnectionPort) && !portType.IsSubclassOf(typeof(ConnectionPort)))
                            {
                                continue;                                 // Invalid type stored
                            }
                            ConnectionPort port = (ConnectionPort)ScriptableObject.CreateInstance(portType);
                            port.name = portName;
                            foreach (XmlElement portVar in xmlPort.ChildNodes.OfType <XmlElement>())
                            {
                                DeserializeFieldFromXML(portVar, port);
                            }
                            portData = new PortData(node, port, portID);
                        }
                        node.connectionPorts.Add(portData);
                        ports.Add(portID, portData);
                    }

                    // NODE VARIABLES

                    foreach (XmlElement variable in xmlNode.ChildNodes.OfType <XmlElement>())
                    {                     // Deserialize all value-type variables
                        if (variable.Name != "Variable" && variable.Name != "Port")
                        {
                            string       varName  = variable.GetAttribute("name");
                            object       varValue = DeserializeFieldFromXML(variable, node.type, null);
                            VariableData varData  = new VariableData(varName);
                            varData.value = varValue;
                            node.variables.Add(varData);
                        }
                    }

                    IEnumerable <XmlElement> xmlVariables = xmlNode.SelectNodes("Variable").OfType <XmlElement>();
                    foreach (XmlElement xmlVariable in xmlVariables)
                    {                     // Deserialize all reference-type variables (and also value type variables in old save files)
                        string       varName = xmlVariable.GetAttribute("name");
                        VariableData varData = new VariableData(varName);
                        if (xmlVariable.HasAttribute("refID"))
                        {                         // Read reference-type variables from objects
                            int        refID = GetIntegerAttribute(xmlVariable, "refID");
                            ObjectData objData;
                            if (canvasData.objects.TryGetValue(refID, out objData))
                            {
                                varData.refObject = objData;
                            }
                        }
                        else
                        {                         // Read value-type variable (old save file only) TODO: Remove
                            string typeName = xmlVariable.GetAttribute("type");
                            Type   type     = Type.GetType(typeName, true);
                            varData.value = DeserializeObjectFromXML(xmlVariable, type);
                        }
                        node.variables.Add(varData);
                    }
                }

                // CONNECTIONS

                IEnumerable <XmlElement> xmlConnections = xmlCanvas.SelectNodes("Connections/Connection").OfType <XmlElement>();
                foreach (XmlElement xmlConnection in xmlConnections)
                {
                    int      port1ID = GetIntegerAttribute(xmlConnection, "port1ID");
                    int      port2ID = GetIntegerAttribute(xmlConnection, "port2ID");
                    PortData port1, port2;
                    if (ports.TryGetValue(port1ID, out port1) && ports.TryGetValue(port2ID, out port2))
                    {
                        canvasData.RecordConnection(port1, port2);
                    }
                }

                // GROUPS

                IEnumerable <XmlElement> xmlGroups = xmlCanvas.SelectNodes("Groups/Group").OfType <XmlElement>();
                foreach (XmlElement xmlGroup in xmlGroups)
                {
                    string name  = xmlGroup.GetAttribute("name");
                    Rect   rect  = GetRectAttribute(xmlGroup, "rect");
                    Color  color = GetColorAttribute(xmlGroup, "color");
                    canvasData.groups.Add(new GroupData(name, rect, color));
                }

                // EDITOR STATES

                IEnumerable <XmlElement> xmlEditorStates = xmlCanvas.SelectNodes("EditorStates/EditorState").OfType <XmlElement>();
                List <EditorStateData>   editorStates    = new List <EditorStateData>();
                foreach (XmlElement xmlEditorState in xmlEditorStates)
                {
                    Vector2 pan = GetVectorAttribute(xmlEditorState, "pan");
                    float   zoom;
                    if (!float.TryParse(xmlEditorState.GetAttribute("zoom"), out zoom))
                    {
                        zoom = 1;
                    }
                    // Selected Node
                    NodeData selectedNode = null;
                    int      selectedNodeID;
                    if (int.TryParse(xmlEditorState.GetAttribute("selected"), out selectedNodeID))
                    {
                        selectedNode = canvasData.FindNode(selectedNodeID);
                    }
                    // Create state
                    editorStates.Add(new EditorStateData(selectedNode, pan, zoom));
                }
                canvasData.editorStates = editorStates.ToArray();

                return(canvasData);
            }
        }
コード例 #29
0
        /// <summary>
        /// Converts the NodeCanvas to a simplified CanvasData
        /// </summary>
        internal static CanvasData ConvertToCanvasData(NodeCanvas canvas)
        {
            if (canvas == null)
            {
                return(null);
            }

            // Validate canvas and create canvas data for it
            canvas.Validate();
            CanvasData canvasData = new CanvasData(canvas);

            // Store Lookup-Table for all ports
            Dictionary <ConnectionPort, PortData> portDatas = new Dictionary <ConnectionPort, PortData>();

            foreach (Node node in canvas.nodes)
            {
                // Create node data
                NodeData nodeData = new NodeData(node);
                canvasData.nodes.Add(nodeData.nodeID, nodeData);

                foreach (ConnectionPortDeclaration portDecl in ConnectionPortManager.GetPortDeclarationEnumerator(node))
                {                 // Fetch all static connection port declarations and record them
                    ConnectionPort port     = (ConnectionPort)portDecl.portField.GetValue(node);
                    PortData       portData = new PortData(nodeData, port, portDecl.portField.Name);
                    nodeData.connectionPorts.Add(portData);
                    portDatas.Add(port, portData);
                }

                foreach (ConnectionPort port in node.dynamicConnectionPorts)
                {                 // Fetch all dynamic connection ports and record them
                    PortData portData = new PortData(nodeData, port);
                    nodeData.connectionPorts.Add(portData);
                    portDatas.Add(port, portData);
                }

                // Fetch all serialized node variables specific to each node's implementation
                FieldInfo[] serializedFields = ReflectionUtility.getSerializedFields(node.GetType(), typeof(Node));
                foreach (FieldInfo field in serializedFields)
                {                 // Create variable data and enter the
                    if (field.FieldType.IsSubclassOf(typeof(ConnectionPort)))
                    {
                        continue;
                    }
                    VariableData varData = new VariableData(field);
                    nodeData.variables.Add(varData);
                    object varValue = field.GetValue(node);
                    if (field.FieldType.IsValueType)                     // Store value of the object
                    {
                        varData.value = varValue;
                    }
                    else                     // Store reference to the object
                    {
                        varData.refObject = canvasData.ReferenceObject(varValue);
                    }
                }
            }

            foreach (PortData portData in portDatas.Values)
            {             // Record the connections of this port
                foreach (ConnectionPort conPort in portData.port.connections)
                {
                    PortData conPortData;                     // Get portData associated with the connection port
                    if (portDatas.TryGetValue(conPort, out conPortData))
                    {
                        canvasData.RecordConnection(portData, conPortData);
                    }
                }
            }

            foreach (NodeGroup group in canvas.groups)
            {             // Record all groups
                canvasData.groups.Add(new GroupData(group));
            }

            canvasData.editorStates = new EditorStateData[canvas.editorStates.Length];
            for (int i = 0; i < canvas.editorStates.Length; i++)
            {             // Record all editorStates
                NodeEditorState state    = canvas.editorStates[i];
                NodeData        selected = state.selectedNode == null ? null : canvasData.FindNode(state.selectedNode);
                canvasData.editorStates[i] = new EditorStateData(selected, state.panOffset, state.zoom);
            }

            return(canvasData);
        }
コード例 #30
0
 public void SetNode(ConnectionPort node)
 {
     TaskManager.Instance.setNode(node);
 }