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; } }
public override object Clone() { dNodeDisplayText clone = new dNodeDisplayText(); clone.dispText = this.dispText; clone.Text = this.Text; clone.sType = this.sType; foreach (TreeNode node in this.Nodes) { clone.Nodes.Add((TreeNode)node.Clone()); } return clone; }
public override object Clone() { dNodeDisplayText clone = new dNodeDisplayText(); clone.dispText = this.dispText; clone.Text = this.Text; clone.sType = this.sType; foreach (TreeNode node in this.Nodes) { clone.Nodes.Add((TreeNode)node.Clone()); } return(clone); }
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); }
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; } }
//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(); } }
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; }