Esempio n. 1
0
        private void convTree_AfterSelect(object sender, TreeViewEventArgs e)
        {
            //after we change focus in our convTree we need to clean up a bit
            propTextBox.Clear();
            dialogTreeNode dNode = (dialogTreeNode)convTree.SelectedNode;

            //based on what kind of node we have, change our display accordingly
            switch (dNode.sType)
            {
            case dNodeType.displayText:
                dNodeDisplayText dispText = (dNodeDisplayText)convTree.SelectedNode;
                propTextBox.Text = dispText.dispText;
                nodePropBox.Text = "NPC Text";
                propTextBox.Show();
                break;

            case dNodeType.userResponse:
                dNodeUserResponse userResponse = (dNodeUserResponse)convTree.SelectedNode;
                propTextBox.Text = userResponse.responseText;
                nodePropBox.Text = "Player Response Text";
                propTextBox.Show();
                break;

            case dNodeType.root:
                propTextBox.Hide();
                nodePropBox.Text = "";
                break;
            }
        }
Esempio n. 2
0
        private void SaveNode(ref XmlWriter writer, TreeNode node)
        {
            //we will loop through the tree using Depth First Search
            dialogTreeNode dNode = (dialogTreeNode)node;

            //print the start element e.g. <text>
            switch (dNode.sType)
            {
            case dNodeType.root:
                writer.WriteStartElement("conversation");
                break;

            case dNodeType.displayText:
                writer.WriteStartElement("text");
                break;

            case dNodeType.responseContainer:
                writer.WriteStartElement("option_container");
                break;

            case dNodeType.userResponse:
                string responseText = ((dNodeUserResponse)dNode).responseText;
                writer.WriteStartElement("option");
                writer.WriteAttributeString("text", responseText);
                break;
            }

            //go deeper if we need to
            if (node.Nodes != null)
            {
                foreach (TreeNode childNode in node.Nodes)
                {
                    SaveNode(ref writer, childNode);
                }
            }

            //print the content and end the element e.g. "foobar"<\text>
            switch (dNode.sType)
            {
            case dNodeType.root:
                writer.WriteEndElement();
                break;

            case dNodeType.displayText:
                string text = ((dNodeDisplayText)dNode).dispText;
                writer.WriteRaw("\"" + text + "\"");
                writer.WriteEndElement();
                break;

            case dNodeType.responseContainer:
                writer.WriteEndElement();
                break;

            case dNodeType.userResponse:
                //don't need to do anything else
                writer.WriteEndElement();
                break;
            }
        }
Esempio n. 3
0
        private bool addUserResponseNode(TreeNode selectedNode = null, dNodeUserResponse newNode = null)
        {
            if (selectedNode == null)
            {
                selectedNode = convTree.SelectedNode;
            }
            if (newNode == null)
            {
                newNode = new dNodeUserResponse();
            }

            dialogTreeNode dNode        = (dialogTreeNode)selectedNode;
            int            newNodeIndex = 0;

            //add a container for our responses if we don't already have one
            switch (dNode.sType)
            {
            case dNodeType.responseContainer:
                //we don't need to do anything extra
                newNodeIndex = selectedNode.Nodes.Add(newNode);
                break;

            case dNodeType.userResponse:
                //we need to select the parent (the response container node) first
                newNodeIndex = addNodeAfter(selectedNode, newNode);
                selectedNode = selectedNode.Parent;
                break;


            default:
                //if we had a display text node, we need to select the parent before
                //making the response container
                //if (dNode.sType == dNodeType.displayText) selectedNode = selectedNode.Parent;

                //we need to make a response container first
                dialogTreeNode container = new dialogTreeNode(dNodeType.responseContainer);
                container.Text = "[Display Options]";
                selectedNode.Nodes.Add(container);
                //addNodeAfter(selectedNode, container);
                selectedNode.Expand();
                selectedNode = container;

                newNodeIndex = selectedNode.Nodes.Add(newNode);
                break;
            }

            //add a dialog option now



            selectedNode.Expand();
            convTree.SelectedNode = selectedNode.Nodes[newNodeIndex];

            return(true);
        }
Esempio n. 4
0
        public override object Clone()
        {
            dialogTreeNode clone = new dialogTreeNode(this.sType);
            clone.sType = this.sType;
            clone.Text = this.Text;

            foreach (TreeNode node in this.Nodes)
            {
                clone.Nodes.Add((TreeNode)node.Clone());
            }
            return clone;
        }
Esempio n. 5
0
        }                                    //sType will allow us to typecast to get all our info back

        public override object Clone()
        {
            dialogTreeNode clone = new dialogTreeNode(this.sType);

            clone.sType = this.sType;
            clone.Text  = this.Text;

            foreach (TreeNode node in this.Nodes)
            {
                clone.Nodes.Add((TreeNode)node.Clone());
            }
            return(clone);
        }
Esempio n. 6
0
        private bool addDisplayTextNode(TreeNode selectedNode = null, dNodeDisplayText newNode = null)
        {
            //if we don't have a target node just go where we're currently selected
            if (selectedNode == null)
            {
                selectedNode = convTree.SelectedNode;
            }
            dialogTreeNode dNode = (dialogTreeNode)selectedNode;

            if (newNode == null)
            {
                newNode = new dNodeDisplayText();
            }


            switch (dNode.sType)
            {
            case dNodeType.displayText:
                //if we're currently selecting a Display Text node then just place this node after
                //the current node, instead of as a child.
                //selectedNode.Parent.Nodes.Add(newNode);
                addNodeAfter(selectedNode, newNode);
                break;

            case dNodeType.responseContainer:
                //we shouldn't be adding anything to this node
                statusStripLabel.Text = "Can't add items other than options to an option container.";
                return(false);

                break;

            default:
                try
                {
                    selectedNode.Nodes.Add(newNode);
                }
                catch (SystemException e)
                {
                    return(false);
                }
                break;
            }

            selectedNode.Expand();
            convTree.SelectedNode = newNode;

            return(true);
        }
Esempio n. 7
0
        private void convTree_BeforeSelect(object sender, TreeViewCancelEventArgs e)
        {
            //if we didn't have anything selected (form just loaded) don't bother doing anything
            if (convTree.SelectedNode == null)
            {
                return;
            }

            //save what the user typed in the textbox, associate with the selected node
            dialogTreeNode dNode = (dialogTreeNode)convTree.SelectedNode;


            //based on what kind of node we have we'll save accordingly
            switch (dNode.sType)
            {
            case dNodeType.displayText:
                dNodeDisplayText dispTextNode = (dNodeDisplayText)dNode;
                dispTextNode.dispText = propTextBox.Text;

                //if the text box is empty, we'll set the treeview text to default
                //otherwise we'll set it to what the response is
                if (propTextBox.Text.Trim() != "")
                {
                    dispTextNode.Text = propTextBox.Text;
                }
                else
                {
                    dispTextNode.Text = "[Display Text]";
                }
                break;

            case dNodeType.userResponse:
                dNodeUserResponse responseNode = (dNodeUserResponse)dNode;
                responseNode.responseText = propTextBox.Text;
                if (propTextBox.Text.Trim() != "")
                {
                    responseNode.Text = propTextBox.Text;
                }
                else
                {
                    responseNode.Text = "[User Response]";
                }
                break;
            }
        }
Esempio n. 8
0
        //drag drop complete
        private void convTree_DragDrop(object sender, DragEventArgs e)
        {
            // Retrieve the client coordinates of the drop location.
            Point targetPoint = convTree.PointToClient(new Point(e.X, e.Y));

            // Retrieve the node at the drop location.
            TreeNode  targetNode = convTree.GetNodeAt(targetPoint);
            TreeNode  draggedNode;
            dNodeType draggedNodeType;

            // Retrieve the node that was dragged.
            if (e.Data.GetDataPresent(typeof(dNodeDisplayText)))
            {
                dNodeDisplayText dispTextNode = (dNodeDisplayText)e.Data.GetData(typeof(dNodeDisplayText));
                draggedNode     = dispTextNode;
                draggedNodeType = dNodeType.displayText;
            }
            else if (e.Data.GetDataPresent(typeof(dNodeUserResponse)))
            {
                dNodeUserResponse userRespNode = (dNodeUserResponse)e.Data.GetData(typeof(dNodeUserResponse));
                draggedNode     = userRespNode;
                draggedNodeType = dNodeType.userResponse;
            }
            else if (e.Data.GetDataPresent(typeof(dialogTreeNode)))
            {
                dialogTreeNode dTreeNode = (dialogTreeNode)e.Data.GetData(typeof(dialogTreeNode));

                if (dTreeNode.sType == dNodeType.responseContainer)
                {
                    draggedNode     = dTreeNode;
                    draggedNodeType = dNodeType.responseContainer;
                }

                else if (dTreeNode.sType == dNodeType.root)
                {
                    System.Media.SystemSounds.Exclamation.Play();;
                    statusStripLabel.Text = "Can't move the root node!";
                    return;
                }
                else
                {
                    //undefined dialog Tree Node object being dragged!
                    return;
                }
            }
            else
            {
                MessageBox.Show("Can't Drag that object!");
                return;
            }

            // Confirm that the node at the drop location is not
            // the dragged node and that target node isn't null
            // (for example if you drag outside the control)
            if (!draggedNode.Equals(targetNode) && targetNode != null)
            {
                bool nodeAdded;

                //targetNode.Nodes.Add(draggedNode);
                //depending on the node we were dragging, let's make a copy of it
                switch (draggedNodeType)
                {
                case dNodeType.displayText:
                    dNodeDisplayText dispTextNode = (dNodeDisplayText)draggedNode;
                    nodeAdded = addDisplayTextNode(targetNode, (dNodeDisplayText)dispTextNode.Clone());
                    break;

                case dNodeType.userResponse:
                    dNodeUserResponse userRespNode = (dNodeUserResponse)draggedNode;
                    nodeAdded = addUserResponseNode(targetNode, (dNodeUserResponse)userRespNode.Clone());
                    break;

                default:
                    throw new Exception("draggedNodeType doesn't match any known types.");
                }

                // Remove the node from its current location if we successfully added
                if (nodeAdded)
                {
                    draggedNode.Remove();
                }

                // Expand the node at the location
                // to show the dropped node.
                targetNode.Expand();
            }
        }
Esempio n. 9
0
        private bool addUserResponseNode(TreeNode selectedNode = null, dNodeUserResponse newNode = null)
        {
            if (selectedNode == null)
            {
                selectedNode = convTree.SelectedNode;
            }
            if (newNode == null)
            {
                newNode = new dNodeUserResponse();
            }

            dialogTreeNode dNode = (dialogTreeNode)selectedNode;
            int newNodeIndex = 0;

            //add a container for our responses if we don't already have one
            switch (dNode.sType)
            {
                case dNodeType.responseContainer:
                    //we don't need to do anything extra
                    newNodeIndex = selectedNode.Nodes.Add(newNode);
                    break;
                case dNodeType.userResponse:
                    //we need to select the parent (the response container node) first
                    newNodeIndex = addNodeAfter(selectedNode, newNode);
                    selectedNode = selectedNode.Parent;
                    break;

                default:
                    //if we had a display text node, we need to select the parent before
                    //making the response container
                    //if (dNode.sType == dNodeType.displayText) selectedNode = selectedNode.Parent;

                    //we need to make a response container first
                    dialogTreeNode container = new dialogTreeNode(dNodeType.responseContainer);
                    container.Text = "[Display Options]";
                    selectedNode.Nodes.Add(container);
                    //addNodeAfter(selectedNode, container);
                    selectedNode.Expand();
                    selectedNode = container;

                    newNodeIndex = selectedNode.Nodes.Add(newNode);
                    break;
            }

            //add a dialog option now

            selectedNode.Expand();
            convTree.SelectedNode = selectedNode.Nodes[newNodeIndex];

            return true;
        }