public DialogEditor(DialogTemplate template) { InitializeComponent(); SetContentTemplate(template); // Set reference if it's available if (string.IsNullOrEmpty(template.JsonPayload)) _rootDialogNode = new DialogNode("Default"); else _rootDialogNode = GetFromJson(template.JsonPayload); GenerateTree(); textName.DataBindings.Add("Text", ContentTemplate, "Name"); // Make sure nodes can be updated txtText.LostFocus += TxtTextOnTextChanged; txtComment.LostFocus += TxtTextOnTextChanged; txtText.GotFocus += TxtTextOnTextChanged; txtComment.GotFocus += TxtTextOnTextChanged; }
// Use this for sending notifications to client private void DialogProviderOnDialogNodeChanged(Player player, DialogNode newNode) { Logger.Instance.Info("{0} is advancing dialog.", player); string message = "The conversation ends."; ICollection<ExpandoObject> links = new Collection<ExpandoObject>(); if (newNode != null) { message = newNode.Text; for (int i = 0; i < newNode.Links.Count; i++) { var link = newNode.Links[i]; if (link.IsAvailable(player)) { dynamic entry = new ExpandoObject(); entry.link = link.Text; entry.index = i; links.Add(entry); } } } var packet = new ServerDialogPresentPacket(message, links); player.Client.Send(packet); }
public DialogProvider(DialogTemplate dialogTemplate) { // Deflate our root dialog node _rootDialogNode = JsonConvert.DeserializeObject<DialogNode>(dialogTemplate.JsonPayload, jsonSerializerSettings); }
protected virtual void OnDialogNodeChanged(Player player, DialogNode newnode) { DialogProviderEvent handler = DialogNodeChanged; if (handler != null) handler(player, newnode); }
public DialogLink(string text, DialogNode nextNode) { Text = text; NextNode = nextNode; Name = "New Link"; }
/// <summary> /// Using a recursive approach, generates the hierachy of links and dialog to be navigated /// via a tree. /// </summary> /// <param name="treeNode"></param> /// <param name="node"></param> private void RecurisveAdd(TreeNode treeNode, DialogNode node) { foreach (var childLink in node.Links) { // Create a link node from the child var linkNode = CreateTreeNodeFromDialogLink(childLink); treeNode.Nodes.Add(linkNode); // If it has a parent, we should go down that rabbit hole, too var linkChildNode = childLink.NextNode; if (linkChildNode != null) { var childTreeNode = CreateTreeNodeFromDialogNode(linkChildNode); linkNode.Nodes.Add(childTreeNode); RecurisveAdd(childTreeNode, linkChildNode); } } }
private DialogNode FindParentDialogNode(DialogNode nodeToFindParent, DialogNode currentNode, DialogNode previousNode) { if (currentNode == nodeToFindParent) return previousNode; foreach (var link in currentNode.Links) { if (link.NextNode != null) { DialogNode result = null; result = FindParentDialogNode(nodeToFindParent, link.NextNode, currentNode); if (result != null) return result; } } return null; }
private DialogLink FindOwningLink(DialogNode searchFor, DialogNode currentNode) { foreach (var link in currentNode.Links) { if (link.NextNode == searchFor) return link; DialogLink result = null; if (link.NextNode != null) result = FindOwningLink(searchFor, link.NextNode); if (result != null) return result; } return null; }
//private DialogNode private TreeNode CreateTreeNodeFromDialogNode(DialogNode node) { var treeNode = new TreeNode(node.Name + ": " + TruncateLongString(node.Text, 40)); treeNode.ImageKey = "script.png"; treeNode.SelectedImageKey = treeNode.ImageKey; treeNode.Tag = node; return treeNode; }