private void DrawConversationTree(DialogHolder dh) { if (!handledNodes.Contains(dh.ID)) { handledNodes.Add(dh.ID); int parentNode = -1; DialogEntry de = projie.Assets.Conversations[loadedConversation].DialogEntries.First(d => d.ID == dh.ID); NodeControl ndctl = new NodeControl(); BrushConverter bc = new BrushConverter(); switch(de.NodeColor) { case "Red": ndctl.grid.Background = (Brush)bc.ConvertFrom("#CC4452"); ndctl.border.BorderBrush = (Brush)bc.ConvertFrom("#723147"); break; case "Green": ndctl.grid.Background = (Brush)bc.ConvertFrom("#FFA5C77F"); ndctl.border.BorderBrush = (Brush)bc.ConvertFrom("#002F32"); break; } ndctl.lblID.Content = de.ID; ndctl.lblNodeColor.Content = de.NodeColor; ndctl.Name = "_node_" + de.ID; ndctl.lblUserScript.Content = de.UserScript; ndctl.lblConditionsString.Content = de.ConditionsString; ndctl.lblConversationID.Content = loadedConversation; ndctl.lblFalseCondition.Content = de.FalseCondtionAction; Console.WriteLine("Setting Bindings..."); foreach(Link lanks in de.OutgoingLinks) { if (lanks.IsConnector == true) { ndctl.lblLinkTo.Content = lanks.DestinationDialogID; ndctl.btnAdd.Visibility = Visibility.Hidden; ndctl.faLink.Visibility = Visibility.Visible; } } foreach (Field field in de.Fields) { switch (field.Title) { case "Title": ndctl.lblDialogueName.Text = field.Value; break; case "Actor": ndctl.lblActorID.Content = field.Value; CharacterItem chara = lstCharacters.Items[Convert.ToInt16(field.Value) - 1] as CharacterItem; ndctl.imgActor.Source = chara.imgActorImage.Source; ndctl.lblActor.Text = chara.lblActorName.Text; break; case "Conversant": ndctl.lblConversantID.Content = field.Value; chara = lstCharacters.Items[Convert.ToInt16(field.Value) - 1] as CharacterItem; ndctl.lblConversant.Text = chara.lblActorName.Text; break; case "Menu Text": ndctl.lblMenuText.Text = field.Value; break; case "Dialogue Text": ndctl.txtDialogue.Text = field.Value; break; case "Sequence": ndctl.lblSequence.Content = field.Value; break; } } foreach(DialogHolder dhParent in IDs) { if (dhParent.ChildNodes.Contains(dh.ID)) parentNode = dhParent.ID; } if (parentNode == -1) { ConversationItem convo = lstConversations.Items[loadedConversation] as ConversationItem; ndctl.grdNodeImage.Height = new GridLength(0); ndctl.grdNodeText.Height = new GridLength(0); ndctl.lblDialogueName.Text = convo.lblConvTitle.Text; tcMain.AddRoot(ndctl, "node_" + dh.ID); Console.WriteLine("Writing root: " + dh.ID); } else { tcMain.AddNode(ndctl, "node_" + dh.ID, "node_" + parentNode); Console.WriteLine("Writing node: " + dh.ID); } } }
public void AddNode(string parentNode) { if (loadedConversation != -1) { TreeNode nodeTree = tcMain.FindName(parentNode.Remove(0, 1)) as TreeNode; NodeControl ndctl = nodeTree.Content as NodeControl; DialogEntry newDialogue = new DialogEntry(); Link newDialogueLink = new Link(); NodeControl newDialogueNode = new NodeControl(); ConversationItem convoInfo = lstConversations.Items[loadedConversation] as ConversationItem; int parentID = (int)ndctl.lblID.Content; int newNodeID = projie.Assets.Conversations[loadedConversation].DialogEntries.OrderByDescending(p => p.ID).First().ID + 1; //Create Dialogue Item in Project newDialogue.ID = newNodeID; newDialogue.ConditionsString = ""; newDialogue.FalseCondtionAction = "Block"; newDialogue.NodeColor = "White"; newDialogue.UserScript = ""; newDialogue.Fields.Add(new Field { Title = "Title", Value = "New Dialogue", Type = "Text" }); newDialogue.Fields.Add(new Field { Title = "Actor", Value = ndctl.lblConversantID.Content.ToString(), Type = "Actor" }); newDialogue.Fields.Add(new Field { Title = "Conversant", Value = ndctl.lblActorID.Content.ToString(), Type = "Actor" }); newDialogue.Fields.Add(new Field { Title = "Menu Text", Value = "", Type = "Text" }); newDialogue.Fields.Add(new Field { Title = "Dialogue Text", Value = "", Type = "Text" }); //Add to conversation projie.Assets.Conversations[loadedConversation].DialogEntries.Add(newDialogue); //Set link to parent. newDialogueLink.DestinationConvoID = loadedConversation; newDialogueLink.OriginConvoID = loadedConversation; newDialogueLink.OriginDialogID = parentID; newDialogueLink.DestinationDialogID = newNodeID; projie.Assets.Conversations[loadedConversation].DialogEntries.Where(p => p.ID == parentID).First().OutgoingLinks.Add(newDialogueLink); //Setup for Physical Node newDialogueNode.Name = "_node_" + newNodeID; newDialogueNode.lblID.Content = newNodeID; newDialogueNode.lblDialogueName.Text = "New Dialogue"; newDialogueNode.lblActorID.Content = ndctl.lblConversantID.Content.ToString(); newDialogueNode.lblActor.Text = ndctl.lblConversant.Text; newDialogueNode.lblConversantID.Content = ndctl.lblActorID.Content.ToString(); newDialogueNode.lblConversant.Text = ndctl.lblActor.Text; newDialogueNode.lblConversationID.Content = loadedConversation; newDialogueNode.lblLinkTo.Content = "0"; //Add to tree. rowLinkRow.Height = new GridLength(0); tcMain.AddNode(newDialogueNode, "node_" + newNodeID, "node_" + parentID).BringIntoView(); history.Do("add", new List<TreeNode> { tcMain.Children.OfType<TreeNode>().First(p => p.Name == "node_" + newNodeID) }, new List<DialogEntry> { newDialogue }); needsSave = true; } }