Exemple #1
0
 public void AddNode(INodeDataGenerator node, Point p)
 {
     if (CurrentFile.File.Exists)
     {
         TNode  g       = CurrentFile.MakeNode(node.Generate(Id <NodeTemp> .New(), new List <NodeDataGeneratorParameterData>(), CurrentFile), new NodeUIData(p));
         Action addNode = () => { CurrentFile.Add(g.Only(), Enumerable.Empty <NodeGroup>(), m_localization); };
         g.Configure(MyEdit).Do
         (
             //Configure the node and then add it. We need to configure the node before adding so that it is in a valid state
             //when added. Failure to do so results in localized string parameters having a null value meaning their undo
             //behavior can't be set up correctly.
             simpleUndoPair => { simpleUndoPair.Redo(); addNode(); },
             resultNotOk =>
         {
             if (resultNotOk == ConfigureResult.Cancel)
             {
                 //Merge the parameter into a junk source so it doesn't count towards the real source
                 foreach (var parameter in g.Data.Parameters.OfType <IDynamicEnumParameter>())
                 {
                     parameter.MergeInto(new DynamicEnumParameter.Source());
                 }
             }
             else
             {
                 addNode();      //Add the node if the user didn't cancel (i.e. no editing was required)
             }
         }
         );
     }
 }
Exemple #2
0
            private Either <GraphAndUI <TUIRawData>, LoadError> ReadEditable(XElement node, IDataSource datasource, object documentID)
            {
                Id <NodeTemp> id = Id <NodeTemp> .Parse(node.Attribute("Id").Value);

                Id <NodeTypeTemp> guid = ReadType(node);

                INodeDataGenerator editableGenerator = datasource.GetNode(guid);

                Either <GraphAndUI <TUIRawData>, LoadError> result;

                var parameterNodes = node.Elements("Parameter");
                var parameterData  = parameterNodes.Select(p => new NodeDataGeneratorParameterData(Id <Parameter> .Parse(p.Attribute("guid").Value), p.Attribute("value").Value)).ToList();

                if (editableGenerator != null)
                {
                    IConversationNodeData editable = editableGenerator.Generate(id, parameterData, documentID);
                    result = new GraphAndUI <TUIRawData>(editable, m_nodeUIDeserializer.Read(node));
                }
                else
                {
                    var             parameters = parameterData.Select(p => new UnknownParameter(p.Guid, p.Value));
                    UnknownEditable editable   = new UnknownEditable(id, guid, parameters);
                    result = new GraphAndUI <TUIRawData>(editable, m_nodeUIDeserializer.Read(node));
                }

                return(result);
            }
        public ConversationNodeData(INodeDataGenerator generator, Id <NodeTemp> id, IEnumerable <Func <IConversationNodeData, Output> > connectors, IEnumerable <IParameter> parameters)
        {
            m_id         = id;
            m_parameters = parameters.ToList();
            m_connectors = connectors.Select(i => i(this)).OrderBy(o => o.GetName()).Evaluate(); //TODO: Ordering by name is a little awkward what with many connectors not having one
            foreach (var connector in Connectors)
            {
                connector.Connected    += OnOutputLinked;
                connector.Disconnected += OnOutputLinked;
            }

            m_generator = generator;
        }
Exemple #4
0
        void AddNode(INodeDataGenerator node, int indent)
        {
            //TODO: It would be a lot better if node renderer customization used a traditional combobox rather than a suggestion box

            ComboBox c     = new ComboBox();
            Panel    panel = new Panel();

            try
            {
                panel.Height = 30;
                panel.Dock   = DockStyle.Top;

                const int BUFFER_WIDTH = 30;
                c.Dock  = DockStyle.Right;
                c.Width = 200;

                foreach (TChoice renderChoice in GetItemsFor(node.Guid))
                {
                    c.Items.Add(ToStringWrapper.Make(renderChoice, renderChoice.DisplayName));
                }
                var item = ToStringWrapper.Make(m_config[node.Guid], m_config[node.Guid].DisplayName);
                c.SelectedItem = item;
                if (c.Items.Count < 2)
                {
                    c.ForeColor = SystemColors.GrayText;
                }

                panel.Controls.Add(c);
                Label label = new Label();
                try
                {
                    label.Text = node.Name;
                    label.Dock = DockStyle.Left;
                }
                catch
                {
                    label.Dispose();
                    throw;
                }
                panel.Controls.Add(label);

                Panel p = new Panel();
                try
                {
                    p.Width = BUFFER_WIDTH * indent;
                    p.Dock  = DockStyle.Left;
                }
                catch
                {
                    p.Dispose();
                    throw;
                }
                panel.Controls.Add(p);

                panel1.Controls.Add(panel);
            }
            catch
            {
                panel.Dispose();
                throw;
            }

            panel1.ScrollControlIntoView(panel);

            m_save.Add(() => { m_config[node.Guid] = (c.SelectedItem as ToStringWrapper <TChoice>).Value; });
        }
Exemple #5
0
 public void AddNode(INodeDataGenerator node)
 {
     m_nodes.Add(node);
 }