private void addNodeTrade(TreeNode textNode, String id)
        {
            TalkNode talkNode = new TalkNode(textNode, TalkNodeTypes.Trade, id, "");

            textNode.Nodes.Insert(0, new TreeNode(talkNode.ToString())); // Always shown first
            textNode.Nodes[0].Tag = talkNode;
        }
        private void addNodeFlag(TreeNode textNode, String id, String text)
        {
            TalkNode talkNode  = new TalkNode(textNode, TalkNodeTypes.Flags, id, text);
            int      childNode = textNode.Nodes.Add(new TreeNode(talkNode.ToString()));

            textNode.Nodes[childNode].Tag = talkNode;
        }
        private void saveConversation(StringWriter stringWriter, TreeNode treeNode)
        {
            TalkNode talkNode = (TalkNode)treeNode.Tag;

            if (!talkNode.type.Equals(TalkNodeTypes.None))
            {
                stringWriter.Write(Xml.tagStart() + talkNode.type.ToString());
                if (talkNode.type.Equals(TalkNodeTypes.Branch))
                {
                    stringWriter.Write(Xml.attribute(XmlAttributes.TREENODEID, talkNode.id));
                }
                else if (talkNode.type.Equals(TalkNodeTypes.Flags) &&
                         talkNode.id.Length != 0)
                {
                    stringWriter.Write(Xml.attribute(XmlAttributes.DATA, talkNode.id));
                }
                stringWriter.WriteLine(Xml.tagEnd() + talkNode.text + Xml.tagEnd(talkNode.type.ToString()));
            }

            // Recurse the nodes
            foreach (TreeNode childTreeNode in treeNode.Nodes)
            {
                saveConversation(stringWriter, childTreeNode);
            }
        }
        private void saveConversation(StringWriter stringWriter, TreeNode treeNode)
        {
            TalkNode talkNode = (TalkNode)treeNode.Tag;

            if (!talkNode.type.Equals(TalkNodeTypes.None))
            {
                stringWriter.Write("\t<" + talkNode.type.ToString());
                if (talkNode.type.Equals(TalkNodeTypes.Branch))
                {
                    stringWriter.Write(" Node=\"" + talkNode.id + "\"");
                }
                if (talkNode.type.Equals(TalkNodeTypes.Trade))
                {
                    stringWriter.WriteLine(">" + talkNode.id + "</" + talkNode.type.ToString() + ">");
                }
                else
                {
                    stringWriter.WriteLine(">" + talkNode.text + "</" + talkNode.type.ToString() + ">");
                }
            }

            // Recurse the nodes
            foreach (TreeNode childTreeNode in treeNode.Nodes)
            {
                saveConversation(stringWriter, childTreeNode);
            }
        }
        private TreeNode addNodeText(String id, String text)
        {
            TalkNode talkNode = new TalkNode(null, TalkNodeTypes.None, id, text);
            TreeNode textNode = guiTalkTree.Nodes.Add(talkNode.ToString());

            textNode.Tag = talkNode;
            return(textNode);
        }
 private void onNpcTextChanged(object sender, EventArgs e)
 {
     if (!m_muteFieldEvents)
     {
         TextBox  textField = (TextBox)sender;
         TalkNode talkNode  = (TalkNode)m_currentTreeNode.Tag;
         talkNode.text          = textField.Text;
         m_currentTreeNode.Text = m_currentTreeNode.Tag.ToString();
     }
 }
        private void addNodeBranch(TreeNode textNode, String id, String text)
        {
            if (text.Length > m_MaxText)
            {
                text = text.Substring(0, m_MaxText);
            }
            TalkNode talkNode  = new TalkNode(textNode, TalkNodeTypes.Branch, id, text);
            int      childNode = textNode.Nodes.Add(new TreeNode(talkNode.ToString()));

            textNode.Nodes[childNode].Tag = talkNode;
        }
        /// <summary>
        /// Convert the information from the TreeView into an XML representation.
        /// This XML data is saved to a String rather than written to a file.
        /// </summary>
        private void saveConversation()
        {
            // TODO: Check that each text field is non-empty
            // TODO: Verify that each branch leads to a valid <Tree> node
            // TODO: Prune unused <Tree> nodes
            StringWriter stringWriter = new StringWriter();
            TalkNode     talkNode;

            int [] TreeID = new int[64];

            // 0 out all data
            for (int x = 0; x < 64; x++)
            {
                TreeID[x] = 0;
            }

            foreach (TreeNode node in talkTree.Nodes)
            {
                talkNode = (TalkNode)node.Tag;

                // See if our ID's are unique
                if (TreeID[Int32.Parse(talkNode.id)] == 1)
                {
                    MessageBox.Show("Error: Duplocate TreeID! Adding 1 to this!");
                    int TID = Int32.Parse(talkNode.id) + 1;
                    talkNode.id = TID.ToString();
                }
                TreeID[Int32.Parse(talkNode.id)] = 1;

                // Give warning about node 1 and trade
                if (talkNode.id == "1")
                {
                    // Recurse the nodes
                    foreach (TreeNode childTreeNode in node.Nodes)
                    {
                        TalkNode tcNode = (TalkNode)childTreeNode.Tag;
                        if (tcNode.type.Equals(TalkNodeTypes.Trade))
                        {
                            MessageBox.Show("Warning! Trade should not be in Node 1!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }

                stringWriter.WriteLine("<Tree Node=\"" + talkNode.id + "\">");
                stringWriter.WriteLine("\t<Text>" + talkNode.text + "</Text>");
                saveConversation(stringWriter, node);
                stringWriter.WriteLine("</Tree>");
            }

            if (stringWriter.ToString().Length > 0)
            {
                m_conversation = stringWriter.ToString();
            }
        }
        private void onNodeAdd(object sender, EventArgs e)
        {
            int id = guiTalkTree.Nodes.Count + 1;

            TalkNode talkNode = new TalkNode(null, TalkNodeTypes.None, id.ToString(), "");
            TreeNode newNode  = guiTalkTree.Nodes.Add(talkNode.ToString());

            newNode.Tag = talkNode;
            guiTalkTree.SelectedNode = newNode;
            guiTalkTree.Focus();
        }
        private void onAddNode(object sender, EventArgs e)
        {
            int id = talkTree.Nodes.Count + 1;

            TalkNode talkNode = new TalkNode(null, TalkNodeTypes.None, id.ToString(), "");
            TreeNode newNode  = talkTree.Nodes.Add(talkNode.ToString());

            newNode.Tag           = talkNode;
            talkTree.SelectedNode = newNode;
            talkTree.Focus();
            setFields(null);
            refreshTree();
        }
 /// <summary>
 /// A node in the tree has been selected. Move the highlight to the parent, the text
 /// and display the contents in the right-hand side fields.
 /// </summary>
 private void onTreeSelection(object sender, TreeViewEventArgs e)
 {
     m_muteFieldEvents = true;
     if (e.Node.Tag != null)
     {
         TalkNode talkNode = (TalkNode)e.Node.Tag;
         if (talkNode.parentNode != null)
         {
             // A child of the text node was selected by the user.
             // Change the selection to that of the text node.
             talkTree.SelectedNode = talkNode.parentNode;
         }
         else
         {
             // A text node is selected, display the contents of these nodes
             m_displayField    = true;
             m_currentTreeNode = e.Node;
             npcText.Text      = talkNode.text;
             TreeNode      children = e.Node.FirstNode;
             TreeNode      currentNode;
             String        id;
             TalkNodeTypes type;
             String        text;
             for (int childIndex = 0; childIndex < m_replies.Count; ++childIndex)
             {
                 currentNode = children;
                 if (children == null)
                 {
                     id   = "";
                     type = TalkNodeTypes.None;
                     text = "";
                 }
                 else
                 {
                     talkNode = (TalkNode)children.Tag;
                     id       = talkNode.id;
                     type     = talkNode.type;
                     text     = talkNode.text;
                     children = children.NextNode;
                 }
                 m_replies[childIndex].treeNode = currentNode;
                 m_replies[childIndex].typeField.SelectedItem = type.ToString();
                 m_replies[childIndex].idField.Text           = id;
                 m_replies[childIndex].textField.Text         = text;
             }
             m_displayField = false;
         }
     }
     m_muteFieldEvents = false;
 }
 private void onNodeRemove(object sender, EventArgs e)
 {
     if (guiTalkTree.SelectedNode != null)
     {
         TalkNode talkNode = (TalkNode)guiTalkTree.SelectedNode.Tag;
         if (!talkNode.id.Equals("1"))
         {
             // Cannot delete node 1
             guiTalkTree.Nodes.Remove(guiTalkTree.SelectedNode);
             if (guiTalkTree.Nodes.Count != 0)
             {
                 guiTalkTree.SelectedNode = guiTalkTree.Nodes[0];
                 guiTalkTree.Focus();
             }
         }
     }
 }
 private void onTextChanged(object sender, EventArgs e)
 {
     if (!m_muteFieldEvents)
     {
         TextBox textField = (TextBox)sender;
         foreach (Replies replyGroup in m_replies)
         {
             if (replyGroup.textField == textField && replyGroup.treeNode != null)
             {
                 TalkNode talkNode = (TalkNode)replyGroup.treeNode.Tag;
                 talkNode.text            = textField.Text;
                 replyGroup.treeNode.Text = talkNode.ToString();
                 break;
             }
         }
     }
 }
예제 #14
0
 private void addNodeTrade(TreeNode textNode, String id)
 {
     TalkNode talkNode = new TalkNode(textNode, TalkNodeTypes.Trade, id, "");
     textNode.Nodes.Insert(0, new TreeNode(talkNode.ToString())); // Always shown first
     textNode.Nodes[0].Tag = talkNode;
 }
        /// <summary>
        /// The type has been changed.  Find the appropriate reply and enable/disable its fields.
        /// </summary>
        private void onReplyType(object sender, EventArgs e)
        {
            if (m_displayField)
            {
                setFields(null);
            }
            else
            {
                // User is manually changing the field
                for (int childIndex = 0; childIndex < m_replies.Count; ++childIndex)
                {
                    if (sender == m_replies[childIndex].typeField)
                    {
                        TalkNodeTypes newType = (TalkNodeTypes)Enum.Parse(typeof(TalkNodeTypes), (String)m_replies[childIndex].typeField.SelectedItem);

                        TalkNodeTypes currentType = m_replies[childIndex].treeNode == null
                                                  ? TalkNodeTypes.None
                                                  : ((TalkNode)m_replies[childIndex].treeNode.Tag).type;
                        if (!currentType.Equals(newType))
                        {
                            // The type has been changed
                            if (newType.Equals(TalkNodeTypes.None))
                            {
                                // Delete this sub-node
                                TreeNode deletedNode = m_replies[childIndex].treeNode;
                                talkTree.SelectedNode.Nodes.Remove(deletedNode);
                                refreshTree();
                                setFields(null);
                            }
                            else
                            {
                                if (newType.Equals(TalkNodeTypes.Trade) &&
                                    !canSetNodeToTrade(talkTree.SelectedNode))
                                {
                                    // Already contains a Trade sub-node so reset to previous type
                                    m_replies[childIndex].typeField.SelectedItem = currentType.ToString();
                                    setFields(sender);
                                    return;
                                }

                                if (currentType.Equals(TalkNodeTypes.None))
                                {
                                    // Create a sub-node
                                    if (newType.Equals(TalkNodeTypes.Trade))
                                    {
                                        addNodeTrade(talkTree.SelectedNode, "1");
                                    }
                                    else
                                    {
                                        addNodeBranch(talkTree.SelectedNode, "", "");
                                    }
                                    setFields(sender);
                                    refreshTree();
                                }
                                else
                                {
                                    TreeNode modifiedNode = m_replies[childIndex].treeNode;
                                    TalkNode talkNode     = (TalkNode)modifiedNode.Tag;
                                    talkNode.type = newType;
                                    if (newType.Equals(TalkNodeTypes.Trade))
                                    {
                                        talkTree.SelectedNode.Nodes.Remove(modifiedNode);
                                        addNodeTrade(talkTree.SelectedNode, "");
                                    }
                                    refreshTree();
                                    setFields(sender);
                                    modifiedNode.Text = talkNode.ToString();
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #16
0
        private void onNodeAdd(object sender, EventArgs e)
        {
            int id = guiTalkTree.Nodes.Count + 1;

            TalkNode talkNode = new TalkNode(null, TalkNodeTypes.None, id.ToString(), "");
            TreeNode newNode = guiTalkTree.Nodes.Add(talkNode.ToString());
            newNode.Tag = talkNode;
            guiTalkTree.SelectedNode = newNode;
            guiTalkTree.Focus();
        }
예제 #17
0
 private TreeNode addNodeText(String id, String text)
 {
     TalkNode talkNode = new TalkNode(null, TalkNodeTypes.None, id, text);
     TreeNode textNode = guiTalkTree.Nodes.Add(talkNode.ToString());
     textNode.Tag = talkNode;
     return textNode;
 }
예제 #18
0
 private void addNodeFlag(TreeNode textNode, String id, String text)
 {
     TalkNode talkNode = new TalkNode(textNode, TalkNodeTypes.Flags, id, text);
     int childNode = textNode.Nodes.Add(new TreeNode(talkNode.ToString()));
     textNode.Nodes[childNode].Tag = talkNode;
 }