/// <summary>
        /// Creates a NPCChatDialogViewNode as a child of this NPCChatDialogViewNode.
        /// </summary>
        /// <param name="dialogItem">The NPCChatDialogItemBase the child node will handle.</param>
        /// <returns>A NPCChatDialogViewNode as a child of this NPCChatDialogViewNode.</returns>
        NPCChatDialogViewNode CreateNode(NPCChatDialogItemBase dialogItem)
        {
            // Check if the node already exists
            var children = Nodes.OfType <NPCChatDialogViewNode>();
            var retNode  =
                children.FirstOrDefault(
                    x =>
                    (x.ChatItemType == NPCChatDialogViewNodeItemType.DialogItem ||
                     x.ChatItemType == NPCChatDialogViewNodeItemType.Redirect) && x.ChatItemAsDialogItem == dialogItem);

            // Create the new node if needed
            if (retNode == null)
            {
                // Check if it has to be a redirect node
                var existingDialogNode = TreeViewCasted.GetNodeForDialogItem(dialogItem);
                if (existingDialogNode != null)
                {
                    retNode = new NPCChatDialogViewNode(this, existingDialogNode);
                }
                else
                {
                    retNode = new NPCChatDialogViewNode(this, dialogItem);
                }
            }

            return(retNode);
        }
Example #2
0
        /// <summary>
        /// Notifies the NPCChatDialogView when a NPCChatDialogViewNode was destroyed.
        /// </summary>
        /// <param name="node">The NPCChatDialogViewNode that was destroyed.</param>
        internal void NotifyNodeDestroyed(NPCChatDialogViewNode node)
        {
            List <NPCChatDialogViewNode> l;

            if (!_objToTreeNode.TryGetValue(node.ChatItem, out l))
            {
                return;
            }

            l.Remove(node);
        }
        /// <summary>
        /// Creates a NPCChatDialogViewNode as a child of this NPCChatDialogViewNode.
        /// </summary>
        /// <param name="response">The NPCChatResponseBase the child node will handle.</param>
        /// <returns>A NPCChatDialogViewNode as a child of this NPCChatDialogViewNode.</returns>
        NPCChatDialogViewNode CreateNode(NPCChatResponseBase response)
        {
            // Check if the node already exists
            var children = Nodes.OfType <NPCChatDialogViewNode>();
            var retNode  =
                children.FirstOrDefault(
                    x => x.ChatItemType == NPCChatDialogViewNodeItemType.Response && x.ChatItemAsResponse == response);

            if (retNode == null)
            {
                retNode = new NPCChatDialogViewNode(this, response);
            }

            return(retNode);
        }
        /// <summary>
        /// Notifies the NPCChatDialogView when a NPCChatDialogViewNode was created.
        /// </summary>
        /// <param name="node">The NPCChatDialogViewNode that was created.</param>
        internal void NotifyNodeCreated(NPCChatDialogViewNode node)
        {
            List <NPCChatDialogViewNode> l;

            if (!_objToTreeNode.TryGetValue(node.ChatItem, out l))
            {
                l = new List <NPCChatDialogViewNode>(1);
                _objToTreeNode.Add(node.ChatItem, l);
            }

            if (node.ChatItemType == NPCChatDialogViewNodeItemType.Response)
            {
                node.ChatItemAsResponse.Changed += EditorNPCChatResponse_Changed;
            }
            else
            {
                node.ChatItemAsDialogItem.Changed += EditorNPCChatDialogItem_Changed;
            }

            l.Add(node);
        }
Example #5
0
        /// <summary>
        /// Notifies the NPCChatDialogView when a NPCChatDialogViewNode was destroyed.
        /// </summary>
        /// <param name="node">The NPCChatDialogViewNode that was destroyed.</param>
        internal void NotifyNodeDestroyed(NPCChatDialogViewNode node)
        {
            List<NPCChatDialogViewNode> l;
            if (!_objToTreeNode.TryGetValue(node.ChatItem, out l))
                return;

            l.Remove(node);
        }
Example #6
0
        /// <summary>
        /// Notifies the NPCChatDialogView when a NPCChatDialogViewNode was created.
        /// </summary>
        /// <param name="node">The NPCChatDialogViewNode that was created.</param>
        internal void NotifyNodeCreated(NPCChatDialogViewNode node)
        {
            List<NPCChatDialogViewNode> l;
            if (!_objToTreeNode.TryGetValue(node.ChatItem, out l))
            {
                l = new List<NPCChatDialogViewNode>(1);
                _objToTreeNode.Add(node.ChatItem, l);
            }

            if (node.ChatItemType == NPCChatDialogViewNodeItemType.Response)
            {
                node.ChatItemAsResponse.Changed -= EditorNPCChatResponse_Changed;
                node.ChatItemAsResponse.Changed += EditorNPCChatResponse_Changed;
            }
            else
            {
                node.ChatItemAsDialogItem.Changed -= EditorNPCChatDialogItem_Changed;
                node.ChatItemAsDialogItem.Changed += EditorNPCChatDialogItem_Changed;
            }

            l.Add(node);
        }
Example #7
0
        /// <summary>
        /// Creates a NPCChatDialogViewNode as a child of this NPCChatDialogViewNode.
        /// </summary>
        /// <param name="response">The NPCChatResponseBase the child node will handle.</param>
        /// <returns>A NPCChatDialogViewNode as a child of this NPCChatDialogViewNode.</returns>
        NPCChatDialogViewNode CreateNode(NPCChatResponseBase response)
        {
            // Check if the node already exists
            var children = Nodes.OfType<NPCChatDialogViewNode>();
            var retNode =
                children.FirstOrDefault(
                    x => x.ChatItemType == NPCChatDialogViewNodeItemType.Response && x.ChatItemAsResponse == response);

            if (retNode == null)
                retNode = new NPCChatDialogViewNode(this, response);

            return retNode;
        }
Example #8
0
        /// <summary>
        /// Creates a NPCChatDialogViewNode as a child of this NPCChatDialogViewNode.
        /// </summary>
        /// <param name="dialogItem">The NPCChatDialogItemBase the child node will handle.</param>
        /// <returns>A NPCChatDialogViewNode as a child of this NPCChatDialogViewNode.</returns>
        NPCChatDialogViewNode CreateNode(NPCChatDialogItemBase dialogItem)
        {
            // Check if the node already exists
            var children = Nodes.OfType<NPCChatDialogViewNode>();
            var retNode =
                children.FirstOrDefault(
                    x =>
                    (x.ChatItemType == NPCChatDialogViewNodeItemType.DialogItem ||
                     x.ChatItemType == NPCChatDialogViewNodeItemType.Redirect) && x.ChatItemAsDialogItem == dialogItem);

            // Create the new node if needed
            if (retNode == null)
            {
                // Check if it has to be a redirect node
                var existingDialogNode = TreeViewCasted.GetNodeForDialogItem(dialogItem);
                if (existingDialogNode != null)
                    retNode = new NPCChatDialogViewNode(this, existingDialogNode);
                else
                    retNode = new NPCChatDialogViewNode(this, dialogItem);
            }

            return retNode;
        }
        /// <summary>
        /// Updates this <see cref="NPCChatDialogViewNode"/>.
        /// </summary>
        /// <param name="recursive">If true, all nodes under this <see cref="NPCChatDialogViewNode"/> are updated, too.</param>
        /// <exception cref="ArgumentException">The <see cref="ChatItemType"/> is not a valid
        /// <see cref="NPCChatDialogViewNodeItemType"/>.</exception>
        public void Update(bool recursive)
        {
            var checkToSwapRedirectNodes = false;
            var childNodes = Nodes.OfType <NPCChatDialogViewNode>();
            IEnumerable <NPCChatDialogViewNode> nodesToRemove = null;

            switch (ChatItemType)
            {
            case NPCChatDialogViewNodeItemType.DialogItem:
                // For a dialog item, add the responses
                var asDialogItem = ChatItemAsDialogItem;
                var validNodes   = new List <NPCChatDialogViewNode>(asDialogItem.Responses.Count());
                foreach (var response in asDialogItem.Responses)
                {
                    validNodes.Add(CreateNode(response));
                }

                // Mark dead nodes
                if (validNodes.Count != Nodes.Count)
                {
                    nodesToRemove = childNodes.Except(validNodes);
                }

                break;

            case NPCChatDialogViewNodeItemType.Redirect:
                // For a redirect, there are no child nodes

                // Mark dead nodes
                if (Nodes.Count > 0)
                {
                    nodesToRemove = childNodes;
                }

                break;

            case NPCChatDialogViewNodeItemType.Response:
                // For a response, add the dialog item, using a redirect if needed
                var dialogItem = TreeViewCasted.NPCChatDialog.GetDialogItem(ChatItemAsResponse.Page);
                NPCChatDialogViewNode validNode = null;
                if (dialogItem != null)
                {
                    validNode = CreateNode(dialogItem);
                    if (validNode.ChatItemType == NPCChatDialogViewNodeItemType.Redirect)
                    {
                        checkToSwapRedirectNodes = true;
                    }
                }

                // Mark dead nodes
                if (Nodes.Count > (dialogItem != null ? 1 : 0))
                {
                    nodesToRemove = childNodes.Where(x => x != validNode);
                }

                break;

            default:
                const string errmsg = "Invalid ChatItemType `{0}`.";
                throw new ArgumentException(string.Format(errmsg, ChatItemType));
            }

            // Remove the marked nodes to be removed
            if (nodesToRemove != null)
            {
                foreach (var node in nodesToRemove)
                {
                    node.Remove();
                }
            }

            // Update the text of this node
            UpdateText();

            // Check to recursively update all the children nodes
            if (recursive)
            {
                foreach (var child in childNodes)
                {
                    child.Update(true);
                }
            }

            // Check if to swap nodes so the redirect is as deep in the tree as possible
            // This must be done here at the end, otherwise we will disrupt the recursive update process
            // and some nodes will end up not appearing in the tree
            if (checkToSwapRedirectNodes)
            {
                foreach (var child in childNodes.Where(x => x.ChatItemType == NPCChatDialogViewNodeItemType.Redirect))
                {
                    var existing      = TreeViewCasted.GetNodeForDialogItem(child.ChatItemAsDialogItem);
                    var existingDepth = existing.GetDepth();
                    var childDepth    = child.GetDepth();

                    if (existingDepth > childDepth)
                    {
                        existing.SwapNode(child, existing.Nodes.Count <= 0);
                    }
                }
            }
        }