Пример #1
0
 public TransitionNoduleUIInfo UIInfo(Output connection, bool canFail)
 {
     if (!m_cachedNodeUI.ContainsKey(connection))
     {
         var node = m_nodes.Where(n => n.Data.Connectors.Any(c => c.Id == connection.Id && n.Data.NodeId == connection.Parent.NodeId)).SingleOrDefault();
         if (node == null && canFail)
         {
             return(null);
         }
         var comparable = node.Data.Connectors.Where(c => c.Definition.Position == connection.Definition.Position);
         m_cachedNodeUI[connection] = CreateTransitionUIInfo(node, connection.Definition.Position, comparable.IndexOf(connection), comparable.Count());
     }
     return(m_cachedNodeUI[connection]);
 }
Пример #2
0
        private SimpleUndoPair InnerAddNodes(IEnumerable <ConversationNode> nodes, IEnumerable <NodeGroup> groups, ILocalizationEngine localization)
        {
            List <Action> undoActions = new List <Action>();
            List <Action> redoActions = new List <Action>();

            //Set up actions for adding/removing the nodes
            foreach (var node in nodes)
            {
                var            n       = node;
                SimpleUndoPair actions = n.GetNodeRemoveActions();

                //Ensure that the localization engine is up to date in terms of usage of localized data
                foreach (var parameter in n.Data.Parameters.OfType <ILocalizedStringParameter>())
                {
                    if (parameter.Value != null)
                    {
                        SimpleUndoPair clearLocalization = localization.ClearLocalizationAction(Id <LocalizedStringType> .ConvertFrom(parameter.TypeId), parameter.Value);
                        undoActions.Add(clearLocalization.Redo);
                        redoActions.Add(clearLocalization.Undo);
                    }
                }

                var containingGroups = m_groups.Where(g => g.Contents.Contains(n.Data.NodeId)).Evaluate();
                redoActions.Add(() =>
                {
                    m_nodes.Add(n);
                    m_audioProvider.UpdateUsage(n);
                    foreach (var group in containingGroups)
                    {
                        group.Contents.Add(n.Data.NodeId);
                    }
                    actions.Undo(); //Undo the node removal
                });
                undoActions.Add(() =>
                {
                    if (CanRemoveFromData(n, PromptNodeDeletion))
                    {
                        m_nodes.Remove(n);
                    }
                    foreach (var group in containingGroups)
                    {
                        group.Contents.Remove(n.Data.NodeId);
                    }
                    actions.Redo(); //Redo the node removal
                    NodesDeleted.Execute();
                });
            }

            //Set up actions for adding/removing nodes from other groups that are gaining/losing their grouping due to removing/adding new groups
            foreach (var group in groups)
            {
                foreach (var node in group.Contents)
                {
                    var n   = node;
                    var old = m_groups.SingleOrDefault(g => g.Contents.Contains(n));
                    if (old != null)
                    {
                        undoActions.Add(() => old.Contents.Add(n));
                        redoActions.Add(() => old.Contents.Remove(n));
                    }
                }
            }

            //Set up actions for adding/removing the groups
            undoActions.Add(() =>
            {
                foreach (var group in groups.Reverse())
                {
                    m_groups.Remove(group);
                }
            });
            redoActions.Add(() =>
            {
                m_groups.AddRange(groups);
            });

            return(new SimpleUndoPair
            {
                Undo = () => { using (m_audioProvider.SuppressUpdates()) foreach (Action action in undoActions)
                                   {
                                       action();
                                   }
                },
                Redo = () => { using (m_audioProvider.SuppressUpdates()) foreach (Action action in redoActions)
                                   {
                                       action();
                                   }
                },
            });
        }