public void Talk() { Talk(currentNode.gameObject.name, currentNode.dialogue, currentNode.gameObject.name == "Wyllow"); Color temp; foreach (GameObject g in GameObject.FindGameObjectsWithTag("Speaker")) { temp = g.renderer.material.color; temp.a = 0.5f; g.renderer.material.color = temp; } temp = currentNode.gameObject.renderer.material.color; temp.a = 1.0f; currentNode.gameObject.renderer.material.color = temp; if (currentNode.GetType() == typeof(QuestionScript)) { QuestionScript q = currentNode as QuestionScript; answers = q.getAnswers(); } else answers = null; if (currentNode.GetType() == typeof(EndNode)) { (currentNode as EndNode).End(); } else currentNode = currentNode.next; }
public string AdvanceDialogue() { if (Cursor.HasNext) { Cursor = Cursor.Next; } return GetCurrentDialogue(); }
public DialogueConversationNode(bool waitUserInteraction) { dialogue = new List<ConversationLine>(); nextNode = null; terminal = true; effects = new Effects(); this.keepShowing = waitUserInteraction; }
public override void addChild(int index, ConversationNode child) { if (index != 0 || nextNode != null) throw new System.Exception(); nextNode = child; terminal = false; //TODO MODIFIED //effects.clear( ); }
public ConversationNodeHolder(ConversationNode node) { this.node = node; if (node != null) { switch (node.getType ()) { case ConversationNodeViewEnum.DIALOGUE: DialogueConversationNode dialog = (DialogueConversationNode)node; this.additional_effects = new EffectHolder (((DialogueConversationNode)node).getEffects ()); this.child = 0; break; case ConversationNodeViewEnum.OPTION: this.additional_effects = new EffectHolder (((OptionConversationNode)node).getEffects ()); this.child = -2; break; } } }
internal static ConversationChoice AsConversationChoice(this ConversationChoiceJsonData source, ConversationNode parent) { ConversationChoice conversationChoice = null; if (source.ID == ReservedIdentifiers.DefaultContinueConversationChoiceID) { conversationChoice = new ConversationChoice(parent, source.ID, ReservedIdentifiers.DefaultContinueConversationStringID, null, null, null); } else { conversationChoice = new ConversationChoice(parent, source.ID, source.TextID, source.CanShowID, source.OnSelectedID, source.NavigateTo); } return(conversationChoice); }
public int RelativePosition(ConversationNode ofNode, ConversationNode relativeTo) => throw new NotImplementedException();
/* * (non-Javadoc) * * @see conversationaleditor.xmlparser.ConversationParser#endElement(java.lang.string, java.lang.string, * java.lang.string) */ public override void endElement(string namespaceURI, string sName, string qName) { // If no element is being subparsed if (subParsing == SUBPARSING_NONE) { // If the conversation ends, store it in the game data if (qName.Equals("tree-conversation")) { chapter.addConversation(new GraphConversation((TreeConversation)conversation)); } // If the tag is a line said by the player, add it to the current node else if (qName.Equals("speak-player")) { // Store the read string into the current node, and then delete the string. The trim is performed so we // don't // have to worry with indentations or leading/trailing spaces ConversationLine line = new ConversationLine(ConversationLine.PLAYER, currentstring.Trim()); if (audioPath != null && !this.audioPath.Equals("")) { line.setAudioPath(audioPath); } if (synthesizerVoice != null) line.setSynthesizerVoice(synthesizerVoice); currentNode.addLine(line); // If we were waiting an option, create a new DialogueNode if (state == STATE_WAITING_OPTION) { // Create a new DialogueNode, and link it to the current node (which will be a OptionNode) ConversationNode newDialogueNode = new DialogueConversationNode(); currentNode.addChild(newDialogueNode); // Add the current node (OptionNode) in the list of past option nodes, and change the current node pastOptionNodes.Add(currentNode); currentNode = newDialogueNode; // Go back to the normal state state = STATE_NORMAL; } } // If the tag is a line said by a non-player character, add it to the current node else if (qName.Equals("speak-char")) { // Store the read string into the current node, and then delete the string. The trim is performed so we // don't // have to worry with indentations or leading/trailing spaces ConversationLine line = new ConversationLine(characterName, currentstring.Trim()); if (audioPath != null && !this.audioPath.Equals("")) { line.setAudioPath(audioPath); } if (synthesizerVoice != null) line.setSynthesizerVoice(synthesizerVoice); currentNode.addLine(line); } // If an "option" tag ends, go back to keep working on the last OptionNode else if (qName.Equals("option")) { // Se the current node to the last OptionNode stored currentNode = pastOptionNodes[pastOptionNodes.Count - 1]; pastOptionNodes.RemoveAt(pastOptionNodes.Count - 1); } // Reset the current string currentstring = string.Empty; } // If an effect tag is being subparsed else if (subParsing == SUBPARSING_EFFECT) { // Spread the call effectSubParser.endElement(namespaceURI, sName, qName); // If the effect is being closed, insert the effect into the current node if (qName.Equals("effect")) { currentNode.setEffects(currentEffects); subParsing = SUBPARSING_NONE; } } }
/* * (non-Javadoc) * * @see conversationaleditor.xmlparser.ConversationParser#startElement(java.lang.string, java.lang.string, * java.lang.string, org.xml.sax.Attributes) */ public override void startElement(string namespaceURI, string sName, string qName, Dictionary<string, string> attrs) { // If no element is being subparsed if (subParsing == SUBPARSING_NONE) { // If it is a "graph-conversation" we pick the name, so we can build the conversation later if (qName.Equals("graph-conversation")) { // Store the name conversationName = ""; foreach (KeyValuePair<string, string> entry in attrs) if (entry.Key.Equals("id")) conversationName = entry.Value.ToString(); graphNodes = new List<ConversationNode>(); nodeLinks = new List<List<int>>(); } // If it is a node, create a new node else if (qName.Equals("dialogue-node") || qName.Equals("option-node")) { // Create the node depending of the tag editorX = editorY = int.MinValue; if (qName.Equals("dialogue-node")) { foreach (KeyValuePair<string, string> entry in attrs) { //If there is a "waitUserInteraction" attribute, store if the lines will wait until user interacts if (entry.Key.Equals("keepShowing")) { if (entry.Value.ToString().Equals("yes")) keepShowingDialogue = true; else keepShowingDialogue = false; } //If there is a "editor-x" and "editor-y" attributes if (entry.Key.Equals("editor-x")) { editorX = Mathf.Max(0, int.Parse(entry.Value.ToString())); } else if (entry.Key.Equals("editor-y")) { editorY = Mathf.Max(0, int.Parse(entry.Value.ToString())); } } currentNode = new DialogueConversationNode(keepShowingDialogue); if (editorX > int.MinValue) { currentNode.setEditorX(editorX); } if (editorY > int.MinValue) { currentNode.setEditorY(editorY); } } if (qName.Equals("option-node")) { foreach (KeyValuePair<string, string> entry in attrs) { //If there is a "random" attribute, store if the options will be random if (entry.Key.Equals("random")) { if (entry.Value.ToString().Equals("yes")) random = true; else random = false; } else //If there is a "keepShowing" attribute, keep the previous conversation line showing if (entry.Key.Equals("keepShowing")) { if (entry.Value.ToString().Equals("yes")) keepShowing = true; else keepShowing = false; } else //If there is a "showUserOption" attribute, identify if show the user response at option node if (entry.Key.Equals("showUserOption")) { if (entry.Value.ToString().Equals("yes")) showUserOption = true; else showUserOption = false; } else //If there is a "showUserOption" attribute, identify if show the user response at option node if (entry.Key.Equals("preListening")) { if (entry.Value.ToString().Equals("yes")) preListening = true; else preListening = false; } else //If there is a "x" and "y" attributes with the position where the option node has to be painted, if (entry.Key.Equals("x")) { x = int.Parse(entry.Value.ToString()); } else if (entry.Key.Equals("y")) { y = int.Parse(entry.Value.ToString()); } //If there is a "editor-x" and "editor-y" attributes if (entry.Key.Equals("editor-x")) { editorX = Mathf.Max(0, int.Parse(entry.Value.ToString())); } else if (entry.Key.Equals("editor-y")) { editorY = Mathf.Max(0, int.Parse(entry.Value.ToString())); } } currentNode = new OptionConversationNode(random, keepShowing, showUserOption, preListening, x, y); if (editorX > int.MinValue) { currentNode.setEditorX(editorX); } if (editorY > int.MinValue) { currentNode.setEditorY(editorY); } } // Create a new vector for the links of the current node currentLinks = new List<int>(); } // If it is a non-player character line, store the character name and audio path (if present) else if (qName.Equals("speak-char")) { // Set default name to "NPC" characterName = "NPC"; audioPath = ""; foreach (KeyValuePair<string, string> entry in attrs) { // If there is a "idTarget" attribute, store it if (entry.Key.Equals("idTarget")) characterName = entry.Value.ToString(); // If there is a "uri" attribute, store it as audio path if (entry.Key.Equals("uri")) audioPath = entry.Value.ToString(); // If there is a "synthesize" attribute, store its value if (entry.Key.Equals("synthesize")) { string response = entry.Value.ToString(); if (response.Equals("yes")) synthesizerVoice = true; else synthesizerVoice = false; } // If there is a "keepShowing" attribute, store its value if (entry.Key.Equals("keepShowing")) { string response = entry.Value.ToString(); if (response.Equals("yes")) keepShowingLine = true; else keepShowingLine = false; } } } // If it is a player character line, store the audio path (if present) else if (qName.Equals("speak-player")) { audioPath = ""; foreach (KeyValuePair<string, string> entry in attrs) { // If there is a "uri" attribute, store it as audio path if (entry.Key.Equals("uri")) audioPath = entry.Value.ToString(); // If there is a "synthesize" attribute, store its value if (entry.Key.Equals("synthesize")) { string response = entry.Value.ToString(); if (response.Equals("yes")) synthesizerVoice = true; else synthesizerVoice = false; } // If there is a "keepShowing" attribute, store its value if (entry.Key.Equals("keepShowing")) { string response = entry.Value.ToString(); if (response.Equals("yes")) keepShowingLine = true; else keepShowingLine = false; } } } // If it is a node to a child, store the number of the child node else if (qName.Equals("child")) { // Look for the index of the link, and add it foreach (KeyValuePair<string, string> entry in attrs) { if (entry.Key.Equals("nodeindex")) { // Get the child node index, and store it int childIndex = int.Parse(entry.Value.ToString()); currentLinks.Add(childIndex); } } } // If it is an effect tag else if (qName.Equals("effect")) { // Create the new effects, and the subparser currentEffects = new Effects(); subParser = new EffectSubParser(currentEffects, chapter); subParsing = SUBPARSING_EFFECT; }// If it is a condition tag, create new conditions and switch the state else if (qName.Equals("condition")) { currentConditions = new Conditions(); subParser = new ConditionSubParser(currentConditions, chapter); subParsing = SUBPARSING_CONDITION; } } // If we are subparsing an effect, spread the call if (subParsing == SUBPARSING_EFFECT || subParsing == SUBPARSING_CONDITION) { subParser.startElement(namespaceURI, sName, qName, attrs); endElement(namespaceURI, sName, qName); } }
void initFromHeadNode (ConversationNode head) { this.Head = head; this.Cursor = head; }
/** * Graph conversation constructor. * * @param conversationName * Name of the conversation * @param root * Root of the conversation */ public GraphConversation(string conversationName, ConversationNode root) : base(Conversation.GRAPH, conversationName, root) { }
private void FillNode(XmlNode toFill, GraphConversation graphConversation, params IDOMWriterParam[] options) { XmlElement conversationElement = toFill as XmlElement; // Get the complete node list List <ConversationNode> nodes = graphConversation.getAllNodes(); // Create the necessary elements to create the DOM XmlDocument doc = Writer.GetDoc(); // Create the root node conversationElement.SetAttribute("id", graphConversation.getId()); // For each node for (int i = 0; i < nodes.Count; i++) { ConversationNode node = nodes[i]; XmlElement nodeElement = null; var dialogConversationNode = node as DialogueConversationNode; // If the node is a dialogue node if (dialogConversationNode != null) { // Create the node element and set the nodeindex nodeElement = doc.CreateElement("dialogue-node"); nodeElement.SetAttribute("nodeindex", i.ToString()); // Adds a random attribute if "keepShowing" is activate in conversation node data if (dialogConversationNode.isKeepShowing()) { nodeElement.SetAttribute("keepShowing", "yes"); } if (node.getEditorX() != -1) { nodeElement.SetAttribute("editor-x", node.getEditorX().ToString()); } if (node.getEditorY() != -1) { nodeElement.SetAttribute("editor-y", node.getEditorY().ToString()); } if (node.getEditorCollapsed()) { nodeElement.SetAttribute("editor-collapsed", "yes"); } // For each line of the node for (int j = 0; j < node.getLineCount(); j++) { // Create a phrase element, and extract the actual text line XmlElement phrase; ConversationLine line = node.getLine(j); // If the line belongs to the player, create a "speak-player" element. Otherwise, if it belongs // to a NPC, // create a "speak-char" element, which will have an attribute "idTarget" with the name of the // non-playable character, // if there is no name the attribute won't be written if (line.isPlayerLine()) { phrase = doc.CreateElement("speak-player"); } else { phrase = doc.CreateElement("speak-char"); if (!line.getName().Equals("NPC")) { phrase.SetAttribute("idTarget", line.getName()); } } //If there is audio track, store it as attribute if (line.isValidAudio()) { phrase.SetAttribute("uri", line.getAudioPath()); } //If there is a synthesizer valid voice, store it as attribute if (line.getSynthesizerVoice()) { phrase.SetAttribute("synthesize", "yes"); } // Add the line text into the element phrase.InnerText = (line.getText()); // Add the element to the node nodeElement.AppendChild(phrase); // Create conditions for current effect DOMWriterUtility.DOMWrite(nodeElement, line.getConditions(), options); } // Check if the node is terminal if (node.isTerminal()) { // If it is terminal add a "end-conversation" element XmlElement endConversation = doc.CreateElement("end-conversation"); // If the terminal node has an effect, include it into the DOM if (node.hasEffects()) { DOMWriterUtility.DOMWrite(endConversation, node.getEffects(), options); } // Add the "end-conversation" tag into the node nodeElement.AppendChild(endConversation); } else { // Otherwise, if the node has a child, add the element XmlElement childElement = doc.CreateElement("child"); // Add the number of the child node (index of the node in the structure) childElement.SetAttribute("nodeindex", nodes.IndexOf(node.getChild(0)).ToString()); // Insert the tag into the node nodeElement.AppendChild(childElement); // If the terminal node has an effect, include it into the DOM if (node.hasEffects()) { DOMWriterUtility.DOMWrite(nodeElement, node.getEffects(), options); } } } var optionConversationNode = node as OptionConversationNode; // If the node is a option node if (optionConversationNode != null) { // Create the node element and set the nodeindex nodeElement = doc.CreateElement("option-node"); nodeElement.SetAttribute("nodeindex", i.ToString()); if (!string.IsNullOrEmpty(optionConversationNode.getXApiQuestion())) { nodeElement.SetAttribute("question", optionConversationNode.getXApiQuestion()); } // Adds a random attribute if "random" is activate in conversation node data if (optionConversationNode.isRandom()) { nodeElement.SetAttribute("random", "yes"); } // Adds a random attribute if "keepShowing" is activate in conversation node data if (optionConversationNode.isKeepShowing()) { nodeElement.SetAttribute("keepShowing", "yes"); } // Adds a random attribute if "showUserOption" is activate in conversation node data if (optionConversationNode.isShowUserOption()) { nodeElement.SetAttribute("showUserOption", "yes"); } // Adds a random attribute if "preListening" is activate in conversation node data if (optionConversationNode.isPreListening()) { nodeElement.SetAttribute("preListening", "yes"); } if (node.getEditorX() != -1) { nodeElement.SetAttribute("editor-x", node.getEditorX().ToString()); } if (node.getEditorY() != -1) { nodeElement.SetAttribute("editor-y", node.getEditorY().ToString()); } if (node.getEditorCollapsed()) { nodeElement.SetAttribute("editor-collapsed", "yes"); } // Adds the x position of the options conversations node nodeElement.SetAttribute("x", optionConversationNode.getEditorX().ToString()); // Adds a random attribute if "preListening" is activate in conversation node data nodeElement.SetAttribute("y", optionConversationNode.getEditorY().ToString()); // For each line of the node for (int j = 0; j < node.getLineCount(); j++) { // Take the current conversation line ConversationLine line = node.getLine(j); // Create the actual option (a "speak-player" element) and add its respective text XmlElement lineElement = doc.CreateElement("speak-player"); lineElement.InnerText = (node.getLine(j).getText()); //If there is audio track, store it as attribute if (line.isValidAudio()) { lineElement.SetAttribute("uri", line.getAudioPath()); } //If there is a synthesizer valid voice, store it as attribute if (line.getSynthesizerVoice()) { lineElement.SetAttribute("synthesize", "yes"); } if (line.getXApiCorrect()) { lineElement.SetAttribute("correct", line.getXApiCorrect().ToString().ToLower()); } // Create a child tag, and set it the index of the child XmlElement childElement = doc.CreateElement("child"); childElement.SetAttribute("nodeindex", nodes.IndexOf(node.getChild(j)).ToString()); // Insert the text line in the option node nodeElement.AppendChild(lineElement); // Add conditions associated to that effect DOMWriterUtility.DOMWrite(nodeElement, line.getConditions(), options); // Insert child tag nodeElement.AppendChild(childElement); } if (optionConversationNode.Timeout >= 0) { // Timeout XmlElement timeoutElement = doc.CreateElement("timeout"); timeoutElement.InnerText = optionConversationNode.Timeout.ToString(); nodeElement.AppendChild(timeoutElement); // Timeout conditions DOMWriterUtility.DOMWrite(nodeElement, optionConversationNode.TimeoutConditions); // Create a child tag, and set it the index of the child XmlElement timeoutchildElement = doc.CreateElement("child"); timeoutchildElement.SetAttribute("nodeindex", nodes.IndexOf(node.getChild(node.getChildCount() - 1)).ToString()); nodeElement.AppendChild(timeoutchildElement); } // If node has an effect, include it into the DOM if (node.hasEffects()) { DOMWriterUtility.DOMWrite(nodeElement, node.getEffects(), options); } } // Add the node to the conversation conversationElement.AppendChild(nodeElement); } }
/** * Tree conversation constructor. * * @param conversationName * Name of the conversation * @param root * Root of the conversation */ public TreeConversation(string conversationName, ConversationNode root) : base(Conversation.TREE, conversationName, root) { }
/* * (non-Javadoc) * * @see conversationaleditor.xmlparser.ConversationParser#startElement(java.lang.string, java.lang.string, * java.lang.string, org.xml.sax.Attributes) */ public override void startElement(string namespaceURI, string sName, string qName, Dictionary <string, string> attrs) { // If no element is being subparsed if (subParsing == SUBPARSING_NONE) { // If it is a "conversation" we pick the name, so we can build the tree later if (qName.Equals("tree-conversation")) { // Store the name string conversationName = ""; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("id")) { conversationName = entry.Value.ToString(); } } // Create a dialogue node (which will be the root node) and add it to a new tree // The content of the tree will be built adding nodes directly to the root currentNode = new DialogueConversationNode(); conversation = new TreeConversation(conversationName, currentNode); pastOptionNodes = new List <ConversationNode>(); } // If it is a non-player character line, store the character name and audio path (if present) else if (qName.Equals("speak-char")) { // Set default name to "NPC" characterName = "NPC"; audioPath = ""; foreach (KeyValuePair <string, string> entry in attrs) { // If there is a "idTarget" attribute, store it if (entry.Key.Equals("idTarget")) { characterName = entry.Value.ToString(); } // If there is a "uri" attribute, store it as audio path if (entry.Key.Equals("uri")) { audioPath = entry.Value.ToString(); } // If there is a "synthesize" attribute, store its value if (entry.Key.Equals("synthesize")) { string response = entry.Value.ToString(); if (response.Equals("yes")) { synthesizerVoice = true; } else { synthesizerVoice = false; } } } } // If it is a player character line, store the audio path (if present) else if (qName.Equals("speak-player")) { audioPath = ""; foreach (KeyValuePair <string, string> entry in attrs) { // If there is a "uri" attribute, store it as audio path if (entry.Key.Equals("uri")) { audioPath = entry.Value.ToString(); } // If there is a "synthesize" attribute, store its value if (entry.Key.Equals("synthesize")) { string response = entry.Value.ToString(); if (response.Equals("yes")) { synthesizerVoice = true; } else { synthesizerVoice = false; } } } } // If it is a point with a set of possible responses, create a new OptionNode else if (qName.Equals("response")) { foreach (KeyValuePair <string, string> entry in attrs) { //If there is a "random" attribute, store is the options will be random if (entry.Key.Equals("random")) { if (entry.Value.ToString().Equals("yes")) { random = true; } else { random = false; } } //If there is a "keepShowing" attribute, keep the previous conversation line showing if (entry.Key.Equals("keepShowing")) { if (entry.Value.ToString().Equals("yes")) { keepShowing = true; } else { keepShowing = false; } } //If there is a "showUserOption" attribute, identify if show the user response at option node if (entry.Key.Equals("showUserOption")) { if (entry.Value.ToString().Equals("yes")) { showUserOption = true; } else { showUserOption = false; } } //If there is a "showUserOption" attribute, identify if show the user response at option node if (entry.Key.Equals("preListening")) { if (entry.Value.ToString().Equals("yes")) { preListening = true; } else { preListening = false; } } //If there is a "x" and "y" attributes with the position where the option node has to be painted, if (entry.Key.Equals("x")) { x = int.Parse(entry.Value.ToString()); } if (entry.Key.Equals("y")) { y = int.Parse(entry.Value.ToString()); } } // Create a new OptionNode, and link it to the current node ConversationNode nuevoNodoOpcion = new OptionConversationNode(random, keepShowing, showUserOption, preListening, x, y); currentNode.addChild(nuevoNodoOpcion); // Change the actual node for the option node recently created currentNode = nuevoNodoOpcion; } // If we are about to read an option, change the state of the recognizer, so we can read the line of the // option else if (qName.Equals("option")) { state = STATE_WAITING_OPTION; } // If it is an effect tag, create new effect, new subparser and switch state else if (qName.Equals("effect")) { currentEffects = new Effects(); effectSubParser = new EffectSubParser(currentEffects, chapter); subParsing = SUBPARSING_EFFECT; } // If there is a go back, link the current node (which will be a DialogueNode) with the last OptionNode // stored else if (qName.Equals("go-back")) { currentNode.addChild(pastOptionNodes[pastOptionNodes.Count - 1]); } } // If an effect element is being subparsed, spread the call if (subParsing == SUBPARSING_EFFECT) { effectSubParser.startElement(namespaceURI, sName, qName, attrs); } }
/* * (non-Javadoc) * * @see conversationaleditor.xmlparser.ConversationParser#endElement(java.lang.string, java.lang.string, * java.lang.string) */ public override void endElement(string namespaceURI, string sName, string qName) { // If no element is being subparsed if (subParsing == SUBPARSING_NONE) { // If the conversation ends, store it in the game data if (qName.Equals("tree-conversation")) { chapter.addConversation(new GraphConversation((TreeConversation)conversation)); } // If the tag is a line said by the player, add it to the current node else if (qName.Equals("speak-player")) { // Store the read string into the current node, and then delete the string. The trim is performed so we // don't // have to worry with indentations or leading/trailing spaces ConversationLine line = new ConversationLine(ConversationLine.PLAYER, currentstring.Trim()); if (audioPath != null && !this.audioPath.Equals("")) { line.setAudioPath(audioPath); } if (synthesizerVoice != null) { line.setSynthesizerVoice(synthesizerVoice); } currentNode.addLine(line); // If we were waiting an option, create a new DialogueNode if (state == STATE_WAITING_OPTION) { // Create a new DialogueNode, and link it to the current node (which will be a OptionNode) ConversationNode newDialogueNode = new DialogueConversationNode(); currentNode.addChild(newDialogueNode); // Add the current node (OptionNode) in the list of past option nodes, and change the current node pastOptionNodes.Add(currentNode); currentNode = newDialogueNode; // Go back to the normal state state = STATE_NORMAL; } } // If the tag is a line said by a non-player character, add it to the current node else if (qName.Equals("speak-char")) { // Store the read string into the current node, and then delete the string. The trim is performed so we // don't // have to worry with indentations or leading/trailing spaces ConversationLine line = new ConversationLine(characterName, currentstring.Trim()); if (audioPath != null && !this.audioPath.Equals("")) { line.setAudioPath(audioPath); } if (synthesizerVoice != null) { line.setSynthesizerVoice(synthesizerVoice); } currentNode.addLine(line); } // If an "option" tag ends, go back to keep working on the last OptionNode else if (qName.Equals("option")) { // Se the current node to the last OptionNode stored currentNode = pastOptionNodes[pastOptionNodes.Count - 1]; pastOptionNodes.RemoveAt(pastOptionNodes.Count - 1); } // Reset the current string currentstring = string.Empty; } // If an effect tag is being subparsed else if (subParsing == SUBPARSING_EFFECT) { // Spread the call effectSubParser.endElement(namespaceURI, sName, qName); // If the effect is being closed, insert the effect into the current node if (qName.Equals("effect")) { currentNode.setEffects(currentEffects); subParsing = SUBPARSING_NONE; } } }
public abstract int ConversationNodeEditorIndex(ConversationNode node);
/* * (non-Javadoc) * * @see conversationaleditor.xmlparser.ConversationParser#startElement(java.lang.string, java.lang.string, * java.lang.string, org.xml.sax.Attributes) */ public override void startElement(string namespaceURI, string sName, string qName, Dictionary<string, string> attrs) { // If no element is being subparsed if (subParsing == SUBPARSING_NONE) { // If it is a "conversation" we pick the name, so we can build the tree later if (qName.Equals("tree-conversation")) { // Store the name string conversationName = ""; foreach (KeyValuePair<string, string> entry in attrs) if (entry.Key.Equals("id")) conversationName = entry.Value.ToString(); // Create a dialogue node (which will be the root node) and add it to a new tree // The content of the tree will be built adding nodes directly to the root currentNode = new DialogueConversationNode(); conversation = new TreeConversation(conversationName, currentNode); pastOptionNodes = new List<ConversationNode>(); } // If it is a non-player character line, store the character name and audio path (if present) else if (qName.Equals("speak-char")) { // Set default name to "NPC" characterName = "NPC"; audioPath = ""; foreach (KeyValuePair<string, string> entry in attrs) { // If there is a "idTarget" attribute, store it if (entry.Key.Equals("idTarget")) characterName = entry.Value.ToString(); // If there is a "uri" attribute, store it as audio path if (entry.Key.Equals("uri")) audioPath = entry.Value.ToString(); // If there is a "synthesize" attribute, store its value if (entry.Key.Equals("synthesize")) { string response = entry.Value.ToString(); if (response.Equals("yes")) synthesizerVoice = true; else synthesizerVoice = false; } } } // If it is a player character line, store the audio path (if present) else if (qName.Equals("speak-player")) { audioPath = ""; foreach (KeyValuePair<string, string> entry in attrs) { // If there is a "uri" attribute, store it as audio path if (entry.Key.Equals("uri")) audioPath = entry.Value.ToString(); // If there is a "synthesize" attribute, store its value if (entry.Key.Equals("synthesize")) { string response = entry.Value.ToString(); if (response.Equals("yes")) synthesizerVoice = true; else synthesizerVoice = false; } } } // If it is a point with a set of possible responses, create a new OptionNode else if (qName.Equals("response")) { foreach (KeyValuePair<string, string> entry in attrs) { //If there is a "random" attribute, store is the options will be random if (entry.Key.Equals("random")) { if (entry.Value.ToString().Equals("yes")) random = true; else random = false; } //If there is a "keepShowing" attribute, keep the previous conversation line showing if (entry.Key.Equals("keepShowing")) { if (entry.Value.ToString().Equals("yes")) keepShowing = true; else keepShowing = false; } //If there is a "showUserOption" attribute, identify if show the user response at option node if (entry.Key.Equals("showUserOption")) { if (entry.Value.ToString().Equals("yes")) showUserOption = true; else showUserOption = false; } //If there is a "showUserOption" attribute, identify if show the user response at option node if (entry.Key.Equals("preListening")) { if (entry.Value.ToString().Equals("yes")) preListening = true; else preListening = false; } //If there is a "x" and "y" attributes with the position where the option node has to be painted, if (entry.Key.Equals("x")) { x = int.Parse(entry.Value.ToString()); } if (entry.Key.Equals("y")) { y = int.Parse(entry.Value.ToString()); } } // Create a new OptionNode, and link it to the current node ConversationNode nuevoNodoOpcion = new OptionConversationNode(random, keepShowing, showUserOption, preListening, x, y); currentNode.addChild(nuevoNodoOpcion); // Change the actual node for the option node recently created currentNode = nuevoNodoOpcion; } // If we are about to read an option, change the state of the recognizer, so we can read the line of the // option else if (qName.Equals("option")) { state = STATE_WAITING_OPTION; } // If it is an effect tag, create new effect, new subparser and switch state else if (qName.Equals("effect")) { currentEffects = new Effects(); effectSubParser = new EffectSubParser(currentEffects, chapter); subParsing = SUBPARSING_EFFECT; } // If there is a go back, link the current node (which will be a DialogueNode) with the last OptionNode // stored else if (qName.Equals("go-back")) { currentNode.addChild(pastOptionNodes[pastOptionNodes.Count - 1]); } } // If an effect element is being subparsed, spread the call if (subParsing == SUBPARSING_EFFECT) { effectSubParser.startElement(namespaceURI, sName, qName, attrs); } }
public override void addChild(ConversationNode child) { optionNodes.Add(child); }
public MoveNodeLineTool(ConversationNode parent, int lineIndex, int mode) { this.parent = parent; this.lineIndex = lineIndex; this.mode = mode; }
/** * Recursive function responsible for transforming a node (and its children) * into a DOM structure * * @param currentNode * Node to be transformed * @param rootDOMNode * DOM node in which the elements must be attached */ private static void WriteNodeInDom(ConversationNode currentNode, XmlNode rootDOMNode, params IDOMWriterParam[] options) { // Extract the document XmlDocument document = rootDOMNode.OwnerDocument; // If the node is a DialogueNode write the lines one after another, and then the child (or the mark if it is no // child) if (currentNode is DialogueConversationNode) { // For each line of the node for (int i = 0; i < currentNode.getLineCount(); i++) { // Create a phrase element, and extract the actual text line XmlElement phrase; ConversationLine line = currentNode.getLine(i); // If the line belongs to the player, create a "speak-player" element. Otherwise, if it belongs to a // NPC, // create a "speak-char" element, which will have an attribute "idTarget" with the name of the // non-playable character, // if there is no name the attribute won't be written if (line.isPlayerLine()) { phrase = document.CreateElement("speak-player"); } else { phrase = document.CreateElement("speak-char"); if (!line.getName().Equals("NPC")) { phrase.SetAttribute("idTarget", line.getName()); } } // Add the line text into the element phrase.InnerText = (line.getText()); //If there is audio track, store it as attribute if (line.isValidAudio()) { phrase.SetAttribute("uri", line.getAudioPath()); } //If there is a synthesizer valid voice, store it as attribute if (line.getSynthesizerVoice()) { phrase.SetAttribute("synthesize", "yes"); } // Add the element to the DOM root rootDOMNode.AppendChild(phrase); // Create conditions for current effect DOMWriterUtility.DOMWrite(rootDOMNode, line.getConditions(), options); } // Check if the node is terminal if (currentNode.isTerminal()) { // If it is terminal add a "end-conversation" element XmlElement endConversation = document.CreateElement("end-conversation"); // Add the "end-conversation" tag into the root rootDOMNode.AppendChild(endConversation); // If the terminal node has an effect, include it into the DOM if (currentNode.hasEffects()) { DOMWriterUtility.DOMWrite(endConversation, currentNode.getEffects(), options); } } else { // If the node isn't terminal, check if it performing a "go-back" (going back to the inmediatly upper // OptionNode) if (TreeConversation.thereIsGoBackTag(currentNode)) { // If it is the case, add a "go-back" element rootDOMNode.AppendChild(document.CreateElement("go-back")); } else { // Otherwise, if the node has a child, call the recursive function with the child node, and the same // DOM root node WriteNodeInDom(currentNode.getChild(0), rootDOMNode); } } } // If the node is a OptionNode write a "response" element, and inside it a "option" element with its content else if (currentNode is OptionConversationNode) { // Create the "response" element XmlElement response = document.CreateElement("response"); // Adds a random attribute if "random" is activate in conversation node data if (((OptionConversationNode)currentNode).isRandom()) { response.SetAttribute("random", "yes"); } // For each line of the node (we suppose the number of line equals the number of links, or children nodes) for (int i = 0; i < currentNode.getLineCount(); i++) { // Create the "option" element XmlElement optionElement = document.CreateElement("option"); ConversationLine line = currentNode.getLine(i); // Create the actual option (a "speak-player" element) and add its respective text XmlElement lineElement = document.CreateElement("speak-player"); lineElement.InnerText = currentNode.getLine(i).getText(); //If there is audio track, store it as attribute if (line.isValidAudio()) { lineElement.SetAttribute("uri", line.getAudioPath()); } //If there is a synthesizer valid voice, store it as attribute if (line.getSynthesizerVoice()) { lineElement.SetAttribute("synthesize", "yes"); } // Insert the text line in the option node optionElement.AppendChild(lineElement); // Call the recursive function, to write in the "option" node the appropiate elements // Note that the root DOM node is the "option" element WriteNodeInDom(currentNode.getChild(i), optionElement); // Add the "option" element response.AppendChild(optionElement); } // If the terminal node has an effect, include it into the DOM if (currentNode.hasEffects()) { DOMWriterUtility.DOMWrite(response, currentNode.getEffects(), options); } // Add the element rootDOMNode.AppendChild(response); } }
/** * Adds a new child to the node, in the last position * * @param child * Node for insertion */ public abstract void addChild(ConversationNode child);
public OptionNodeDataControl(ConversationDataControl conversation, ConversationNode conversationNode) : base(conversation, conversationNode) { this.optionConversationNode = conversationNode as OptionConversationNode; this.timeoutConditions = new ConditionsController(optionConversationNode.TimeoutConditions); }
public override void ParseElement(XmlElement element) { XmlNodeList speakschar = element.SelectNodes("speak-char"), speaksplayer = element.SelectNodes("speak-player"), responses = element.SelectNodes("response"), options = element.SelectNodes("option"), effects = element.SelectNodes("effect"), gosback = element.SelectNodes("go-back"); string tmpArgVal; // Store the name string conversationName = ""; tmpArgVal = element.GetAttribute("id"); if (!string.IsNullOrEmpty(tmpArgVal)) { conversationName = tmpArgVal; } // Create a dialogue node (which will be the root node) and add it to a new tree // The content of the tree will be built adding nodes directly to the root currentNode = new DialogueConversationNode(); conversation = new TreeConversation(conversationName, currentNode); pastOptionNodes = new List<ConversationNode>(); foreach (XmlElement el in speakschar) { // Set default name to "NPC" characterName = "NPC"; audioPath = ""; // If there is a "idTarget" attribute, store it tmpArgVal = el.GetAttribute("idTarget"); if (!string.IsNullOrEmpty(tmpArgVal)) { characterName = tmpArgVal; } // If there is a "uri" attribute, store it as audio path tmpArgVal = el.GetAttribute("uri"); if (!string.IsNullOrEmpty(tmpArgVal)) { audioPath = tmpArgVal; } // If there is a "uri" attribute, store it as audio path tmpArgVal = el.GetAttribute("synthesize"); if (!string.IsNullOrEmpty(tmpArgVal)) { string response = tmpArgVal; if (response.Equals("yes")) synthesizerVoice = true; else synthesizerVoice = false; } // Store the read string into the current node, and then delete the string. The trim is performed so we // don't // have to worry with indentations or leading/trailing spaces ConversationLine line = new ConversationLine(characterName, el.InnerText); if (audioPath != null && !this.audioPath.Equals("")) { line.setAudioPath(audioPath); } if (synthesizerVoice != null) line.setSynthesizerVoice(synthesizerVoice); currentNode.addLine(line); } foreach (XmlElement el in speaksplayer) { audioPath = ""; // If there is a "uri" attribute, store it as audio path tmpArgVal = el.GetAttribute("uri"); if (!string.IsNullOrEmpty(tmpArgVal)) { audioPath = tmpArgVal; } // If there is a "uri" attribute, store it as audio path tmpArgVal = el.GetAttribute("synthesize"); if (!string.IsNullOrEmpty(tmpArgVal)) { string response = tmpArgVal; if (response.Equals("yes")) synthesizerVoice = true; else synthesizerVoice = false; } // Store the read string into the current node, and then delete the string. The trim is performed so we // don't have to worry with indentations or leading/trailing spaces ConversationLine line = new ConversationLine(ConversationLine.PLAYER, el.InnerText); if (audioPath != null && !this.audioPath.Equals("")) { line.setAudioPath(audioPath); } if (synthesizerVoice != null) line.setSynthesizerVoice(synthesizerVoice); currentNode.addLine(line); } foreach (XmlElement el in responses) { //If there is a "random" attribute, store is the options will be random tmpArgVal = el.GetAttribute("random"); if (!string.IsNullOrEmpty(tmpArgVal)) { if (tmpArgVal.Equals("yes")) random = true; else random = false; } //If there is a "keepShowing" attribute, keep the previous conversation line showing tmpArgVal = el.GetAttribute("keepShowing"); if (!string.IsNullOrEmpty(tmpArgVal)) { if (tmpArgVal.Equals("yes")) keepShowing = true; else keepShowing = false; } //If there is a "showUserOption" attribute, identify if show the user response at option node tmpArgVal = el.GetAttribute("showUserOption"); if (!string.IsNullOrEmpty(tmpArgVal)) { if (tmpArgVal.Equals("yes")) showUserOption = true; else showUserOption = false; } //If there is a "showUserOption" attribute, identify if show the user response at option node tmpArgVal = el.GetAttribute("preListening"); if (!string.IsNullOrEmpty(tmpArgVal)) { if (tmpArgVal.Equals("yes")) preListening = true; else preListening = false; } //If there is a "x" and "y" attributes with the position where the option node has to be painted, tmpArgVal = el.GetAttribute("preListening"); if (!string.IsNullOrEmpty(tmpArgVal)) { if (tmpArgVal.Equals("yes")) preListening = true; else preListening = false; } //If there is a "x" and "y" attributes with the position where the option node has to be painted tmpArgVal = el.GetAttribute("x"); if (!string.IsNullOrEmpty(tmpArgVal)) { x = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("y"); if (!string.IsNullOrEmpty(tmpArgVal)) { y = int.Parse(tmpArgVal); } // Create a new OptionNode, and link it to the current node ConversationNode nuevoNodoOpcion = new OptionConversationNode(random, keepShowing, showUserOption, preListening, x, y); currentNode.addChild(nuevoNodoOpcion); // Change the actual node for the option node recently created currentNode = nuevoNodoOpcion; } foreach (XmlElement el in options) { currentNode = pastOptionNodes[pastOptionNodes.Count - 1]; pastOptionNodes.RemoveAt(pastOptionNodes.Count - 1); } foreach (XmlElement el in effects) { currentEffects = new Effects(); new EffectSubParser_(currentEffects, chapter).ParseElement(el); currentNode.setEffects(currentEffects); } foreach (XmlElement el in gosback) { currentNode.addChild(pastOptionNodes[pastOptionNodes.Count - 1]); } chapter.addConversation(new GraphConversation((TreeConversation)conversation)); }
public IconRenderer(ConversationNode <ConversationEditor.INodeGui> node, PointF p, Func <Id <LocalizedStringType>, Id <LocalizedText>, string> localizer) : base(node, p) { m_localizer = localizer; SetIcon(); }
public override ConversationNode removeChild(int index) { if (index != 0 || nextNode == null) throw new System.Exception(); ConversationNode deletedChild = nextNode; nextNode = null; terminal = true; return deletedChild; }
/** * Select the position of the options node (top or bottom) * * @param selectedNode * @param bottomPosition * if true, the option will appear at the bottom, if false, the options will appear at the top */ public void setOptionPositions(ConversationNodeView selectedNode, bool bottomPosition) { ConversationNode node = (ConversationNode)selectedNode; controller.addTool(new OptionsPositionTool(((OptionConversationNode)node), bottomPosition)); }
private void parseLines(ConversationNode node, XmlElement lines) { string tmpArgVal = ""; currentLinks = new List<int> (); bool addline = true; foreach (XmlElement ell in lines.ChildNodes) { addline = true; if (ell.Name == "speak-player") { audioPath = ""; tmpArgVal = ell.GetAttribute ("uri"); if (!string.IsNullOrEmpty (tmpArgVal)) { audioPath = tmpArgVal; } // If there is a "synthesize" attribute, store its value tmpArgVal = ell.GetAttribute ("synthesize"); if (!string.IsNullOrEmpty (tmpArgVal)) { string response = tmpArgVal; if (response.Equals ("yes")) synthesizerVoice = true; else synthesizerVoice = false; } // If there is a "keepShowing" attribute, store its value tmpArgVal = ell.GetAttribute ("keepShowing"); if (!string.IsNullOrEmpty (tmpArgVal)) { string response = tmpArgVal; if (response.Equals ("yes")) keepShowingLine = true; else keepShowingLine = false; } // Store the read string into the current node, and then delete the string. The trim is performed so we // don't have to worry with indentations or leading/trailing spaces conversationLine = new ConversationLine (ConversationLine.PLAYER, ell.InnerText); if (audioPath != null && !this.audioPath.Equals ("")) { conversationLine.setAudioPath (audioPath); } if (synthesizerVoice != null) conversationLine.setSynthesizerVoice (synthesizerVoice); conversationLine.setKeepShowing (keepShowingLine); } else if (ell.Name == "speak-char") { // If it is a non-player character line, store the character name and audio path (if present) // Set default name to "NPC" characterName = "NPC"; audioPath = ""; // If there is a "idTarget" attribute, store it tmpArgVal = ell.GetAttribute ("idTarget"); if (!string.IsNullOrEmpty (tmpArgVal)) { characterName = tmpArgVal; } tmpArgVal = ell.GetAttribute ("uri"); if (!string.IsNullOrEmpty (tmpArgVal)) { audioPath = tmpArgVal; } // If there is a "synthesize" attribute, store its value tmpArgVal = ell.GetAttribute ("synthesize"); if (!string.IsNullOrEmpty (tmpArgVal)) { string response = tmpArgVal; if (response.Equals ("yes")) synthesizerVoice = true; else synthesizerVoice = false; } // If there is a "keepShowing" attribute, store its value tmpArgVal = ell.GetAttribute ("keepShowing"); if (!string.IsNullOrEmpty (tmpArgVal)) { string response = tmpArgVal; if (response.Equals ("yes")) keepShowingLine = true; else keepShowingLine = false; } // Store the read string into the current node, and then delete the string. The trim is performed so we // don't have to worry with indentations or leading/trailing spaces conversationLine = new ConversationLine (characterName, ell.InnerText); if (audioPath != null && !this.audioPath.Equals ("")) { conversationLine.setAudioPath (audioPath); } if (synthesizerVoice != null) conversationLine.setSynthesizerVoice (synthesizerVoice); conversationLine.setKeepShowing (keepShowingLine); } else if (ell.Name == "condition") { addline = false; currentConditions = new Conditions (); new ConditionSubParser_ (currentConditions, chapter).ParseElement (ell); currentNode.getLine (currentNode.getLineCount () - 1).setConditions (currentConditions); }else if (ell.Name == "child"){ addline = false; tmpArgVal = ell.GetAttribute("nodeindex"); if (!string.IsNullOrEmpty(tmpArgVal)) { // Get the child node index, and store it int childIndex = int.Parse(tmpArgVal); currentLinks.Add(childIndex); } }else addline = false; if(addline) node.addLine (conversationLine); } }
/** * Change the show user option in the selected node. * * @param selectedNode * The node in which will be the actions * */ public void setShowUserOptionOptions(ConversationNodeView selectedNode) { ConversationNode node = (ConversationNode)selectedNode; controller.addTool(new ChangeBooleanValueTool(node, !((OptionConversationNode)node).isShowUserOption(), "isShowUserOption", "setShowUserOption")); }
private void getAllNodes(ConversationNode firstNode, List<ConversationNode> nodes) { for (int i = -1; i < firstNode.getChildCount(); i++) { ConversationNode child = null; if (i == -1) child = firstNode; else child = firstNode.getChild(i); // Check the child is not in the list yet bool isInList = false; foreach (ConversationNode aNode in nodes) { if (aNode == child) { isInList = true; break; } } if (!isInList) { nodes.Add(child); getAllNodes(child, nodes); } } }
/** * Change the wait user interaction option in the selected node, for dialogue node * * @param selectedNode * The node in which will be the actions * */ public void setKeepShowingDialogueOptions(ConversationNodeView selectedNode) { ConversationNode node = (ConversationNode)selectedNode; controller.addTool(new ChangeBooleanValueTool(node, !((DialogueConversationNode)node).isKeepShowing(), "isKeepShowing", "setKeepShowing")); }
public PartialRenderer(ConversationNode <ConversationEditor.INodeGui> node, PointF p, Func <Id <LocalizedStringType>, Id <LocalizedText>, string> localizer, Func <IDataSource> datasource) : base(node, p, localizer) { m_datasource = datasource; }
/** * Change the pre-hearing option in the selected option node * * @param selectedNode * The node in which will be the actions * */ public void setPreListeningOptions(ConversationNodeView selectedNode) { ConversationNode node = (ConversationNode)selectedNode; controller.addTool(new ChangeBooleanValueTool(node, !((OptionConversationNode)node).isPreListening(), "isPreListening", "setPreListening")); }
public DeleteNodeLineTool(ConversationNode parent, int lineIndex, List <ConditionsController> node) { this.parent = parent; this.lineIndex = lineIndex; this.node = node; }
/** * Check if in selectedNode is active the random option * * @param selectedNode * The node in which will it ask * @return */ public bool isRandomActivate(ConversationNodeView selectedNode) { ConversationNode node = (ConversationNode)selectedNode; return(((OptionConversationNode)node).isRandom()); }
public void StartConversation() { // First, load conversation resource // Modifies the path to use the path seperator for the current system _conversationPath = _conversationPath.Replace(@"/", Path.DirectorySeparatorChar.ToString()); _conversationPath = _conversationPath.Replace(@"\", Path.DirectorySeparatorChar.ToString()); TextAsset txt = (TextAsset)Resources.Load(_conversationPath, typeof(TextAsset)); // Read in the conversation from the JSON file and initialise the node collection JSONNode node = JSONNode.Parse(txt.text); allNodes = new ConversationNode[ node["AllNodes"].Count ]; // Build all ConversationNodes and add to allNodes foreach(JSONNode n in node["AllNodes"].Childs) { // If answeringDelay is undefined, it will default to 0.0 ConversationNode cNode = new ConversationNode(n["dialogue"], n["responses"].Count, n["answeringDelay"].AsFloat); // Set up responses int i = 0; // .Childs doesn't have Count/Size field foreach(JSONNode response in n["responses"].Childs) { cNode.Responses[i] = response["response"]; cNode.NodeLinks[i] = response["gotoNode"].AsInt; i++; } var silResp = n["silentResponse"]; if (silResp != null) { cNode.SilentResponse = silResp["timer"].AsFloat; cNode.SilentGoto = silResp["gotoNode"].AsInt; } JSONNode answerAppearanceDelay = n["answeringAppearanceDelay"]; cNode.AnswerAppearanceDelay = answerAppearanceDelay.AsFloat; JSONNode nextNodeDelay = n["nextNodeDelay"]; cNode.NextNodeDelay = nextNodeDelay.AsFloat; // Add to allNodes allNodes[ n["index"].AsInt ] = cNode; } // Then set the conversation as running _conversationIsRunning = true; lastDialogueTick = Time.time; textBubble.gameObject.SetActive(true); //SimplePlayer.PLAYER.SwitchState(PlayerState.IN_CONVERSATION); }
/** * Check if in selectedNode is active the keep showing the previous conversation line, for option node * * @param selectedNode * The node in which will it ask * @return */ public bool isKeepShowingOptionsNodeActivate(ConversationNodeView selectedNode) { ConversationNode node = (ConversationNode)selectedNode; return(((OptionConversationNode)node).isKeepShowing()); }
public virtual object Clone() { ConversationNode cn = (ConversationNode)this.MemberwiseClone(); return(cn); }
/** * Check if in selectedNode is active the show user response option * * @param selectedNode * The node in which will it ask * @return */ public bool isShowUserOptionActivate(ConversationNodeView selectedNode) { ConversationNode node = (ConversationNode)selectedNode; return(((OptionConversationNode)node).isShowUserOption()); }
/** * Adds a new child to the node, in the specified position * * @param index * Index for insertion * @param child * Node for insertion */ public abstract void addChild(int index, ConversationNode child);
Conversation ParseConversationFile(TextAsset file) { Conversation conv = new Conversation(); string t = file.text.Replace("\r", ""); string[] lines = t.Split('\n'); ConversationNode node = null; bool vars = false; for(int i = 0; i < lines.Length; i++){ if(DEBUG){ Debug.Log (lines[i]); } if(lines[i] == ""){ continue; } if(lines[i] == "START_VARS"){ vars = true; continue; } if(lines[i] == "END_VARS"){ vars = false; continue; } if(lines[i] == "START_NODE"){ node = new ConversationNode(); continue; } if(lines[i] == "END_NODE"){ conv.AddNode(node); continue; } string[] text = lines[i].Split ('='); text[0] = text[0].Replace (" ", ""); for(int j = 1; j < text.Length; j++){ if(text[j][0] == ' '){ text[j] = text[j].Substring (1); } } if(vars){ conv.speakers[text[0]] = (Texture2D)Resources.Load ("Portraits/" + text[1]); } if(text[0] == "conversation_name"){ conv.name = text[1]; } if(text[0] == "node"){ node.name = text[1]; } if(text[0] == "type"){ node.type = text[1]; } if(text[0] == "text_count"){ node.InitializeTextCount(int.Parse (text[1])); } if(text[0] == "text"){ node.AddText (text[1]); } if(text[0] == "target"){ node.AddTarget (text[1]); } if(text[0] == "left"){ node.left = text[1]; } if(text[0] == "right"){ node.right = text[1]; } if(text[0] == "speaker"){ node.AddSpeaker (text[1]); } } return conv; }
public void AddNode(ConversationNode n) { convNodes.Add(n.name, n); }
public Conversation (ConversationNode head) { initFromHeadNode(head); }
public void SwapToNewNode(int i) { currentNode.ResetNode (); currentNode = convNodes[currentNode.targets[i]]; SetUpNewNode (); }
/** * Check if in selectedNode is active the pre-hearing option * * @param selectedNode * The node in which will it ask * @return */ public bool isPreListeningActivate(ConversationNodeView selectedNode) { ConversationNode node = (ConversationNode)selectedNode; return(((OptionConversationNode)node).isPreListening()); }
public override void addChild(int index, ConversationNode child) { optionNodes.Insert(index, child); }
/** * Check if in selectedNode is active the show user response option, for dialogue node * * @param selectedNode * The node in which will it ask * @return */ public bool isKeepShowingDialogueActivate(ConversationNodeView selectedNode) { ConversationNode node = (ConversationNode)selectedNode; return(((DialogueConversationNode)node).isKeepShowing()); }
public void Initialize() { currentNode = convNodes["START"]; SetUpNewNode (); speakers["null"] = null; }
public int getEditorY(ConversationNodeView selectedNode) { ConversationNode node = (ConversationNode)selectedNode; return(node.getEditorY()); }
public Line(string line, ConversationNode then) { _line = line.Replace("\\n", Environment.NewLine); FollowingNode = then; }
String GetCollectionItemXmlElementName(ConversationNode complexProperty) { return(complexProperty.GetXmlElementName()); }
public override void ParseElement(XmlElement element) { XmlNodeList speakschar, speaksplayer, childs, effects, conditions; XmlNode end_conversation; string tmpArgVal; // Store the name conversationName = ""; tmpArgVal = element.GetAttribute("id"); if (!string.IsNullOrEmpty(tmpArgVal)) { conversationName = tmpArgVal; } graphNodes = new List<ConversationNode>(); nodeLinks = new List<List<int>>(); foreach (XmlElement el in element) { if (el.Name == "dialogue-node") { // Create the node depending of the tag editorX = editorY = int.MinValue; //If there is a "waitUserInteraction" attribute, store if the lines will wait until user interacts tmpArgVal = element.GetAttribute ("keepShowing"); if (!string.IsNullOrEmpty (tmpArgVal)) { if (tmpArgVal.Equals ("yes")) keepShowingDialogue = true; else keepShowingDialogue = false; } //If there is a "editor-x" and "editor-y" attributes tmpArgVal = element.GetAttribute ("editor-x"); if (!string.IsNullOrEmpty (tmpArgVal)) { editorX = Mathf.Max (0, int.Parse (tmpArgVal)); } tmpArgVal = element.GetAttribute ("editor-y"); if (!string.IsNullOrEmpty (tmpArgVal)) { editorY = Mathf.Max (0, int.Parse (tmpArgVal)); } currentNode = new DialogueConversationNode (keepShowingDialogue); if (editorX > int.MinValue) { currentNode.setEditorX (editorX); } if (editorY > int.MinValue) { currentNode.setEditorY (editorY); } // Create a new vector for the links of the current node currentLinks = new List<int> (); parseLines (currentNode, el); end_conversation = el.SelectSingleNode ("end-conversation"); if (end_conversation != null) effects = end_conversation.SelectNodes ("effect"); else effects = el.SelectNodes ("effect"); foreach (XmlElement ell in effects) { currentEffects = new Effects (); new EffectSubParser_ (currentEffects, chapter).ParseElement (ell); currentNode.setEffects (currentEffects); } // Add the current node to the node list, and the set of children references into the node links graphNodes.Add (currentNode); nodeLinks.Add (currentLinks); } else if (el.Name == "option-node") { editorX = editorY = int.MinValue; //If there is a "waitUserInteraction" attribute, store if the lines will wait until user interacts tmpArgVal = element.GetAttribute ("keepShowing"); if (!string.IsNullOrEmpty (tmpArgVal)) { if (tmpArgVal.Equals ("yes")) keepShowingDialogue = true; else keepShowingDialogue = false; } //If there is a "editor-x" and "editor-y" attributes tmpArgVal = element.GetAttribute ("editor-x"); if (!string.IsNullOrEmpty (tmpArgVal)) { editorX = Mathf.Max (0, int.Parse (tmpArgVal)); } tmpArgVal = element.GetAttribute ("editor-y"); if (!string.IsNullOrEmpty (tmpArgVal)) { editorY = Mathf.Max (0, int.Parse (tmpArgVal)); } tmpArgVal = element.GetAttribute ("random"); if (!string.IsNullOrEmpty (tmpArgVal)) { if (tmpArgVal.Equals ("yes")) random = true; else random = false; } tmpArgVal = element.GetAttribute ("showUserOption"); if (!string.IsNullOrEmpty (tmpArgVal)) { if (tmpArgVal.Equals ("yes")) showUserOption = true; else showUserOption = false; } tmpArgVal = element.GetAttribute ("preListening"); if (!string.IsNullOrEmpty (tmpArgVal)) { if (tmpArgVal.Equals ("yes")) preListening = true; else preListening = false; } //If there is a "x" and "y" attributes with the position where the option node has to be painted tmpArgVal = element.GetAttribute ("x"); if (!string.IsNullOrEmpty (tmpArgVal)) { if (tmpArgVal.Equals ("yes")) preListening = true; else preListening = false; } tmpArgVal = element.GetAttribute ("y"); if (!string.IsNullOrEmpty (tmpArgVal)) { if (tmpArgVal.Equals ("yes")) preListening = true; else preListening = false; } currentNode = new OptionConversationNode (random, keepShowing, showUserOption, preListening, x, y); if (editorX > int.MinValue) { x = int.Parse (tmpArgVal); } if (editorY > int.MinValue) { y = int.Parse (tmpArgVal); } // Create a new vector for the links of the current node currentLinks = new List<int> (); parseLines (currentNode, el); end_conversation = el.SelectSingleNode ("end-conversation"); if (end_conversation != null) effects = end_conversation.SelectNodes ("effect"); else effects = el.SelectNodes ("effect"); foreach (XmlElement ell in effects) { currentEffects = new Effects (); new EffectSubParser_ (currentEffects, chapter).ParseElement (ell); currentNode.setEffects (currentEffects); } // Add the current node to the node list, and the set of children references into the node links graphNodes.Add (currentNode); nodeLinks.Add (currentLinks); } } setNodeLinks(); chapter.addConversation(new GraphConversation(conversationName, graphNodes[0])); }
public override bool doTool() { bool nodeDeleted = false; // Ask for confirmation if (!showConfirmation || controller.showStrictConfirmDialog(TC.get("Conversation.OperationDeleteNode"), TC.get("Conversation.ConfirmDeleteNode"))) { // Take the complete node ConversationNode node = (ConversationNode)nodeView; // If the node was deleted if (mode == MODE_TREE) { if (recursiveDeleteNode(rootNode /*treeConversation.getRootNode( )*/, node)) { // Set the data as modified nodeDeleted = true; } } else if (mode == MODE_GRAPH) { // Get the complete node list List <ConversationNodeView> nodes = getAllNodes(conversation); // For each node foreach (ConversationNodeView currentNodeView in nodes) { int j = 0; // Search for the node which is being deleted among each node's children while (j < currentNodeView.getChildCount()) { // If the current child is the node we want to delete if (currentNodeView.getChildView(j) == nodeView) { // Take the complete current node parentNode = (ConversationNode)currentNodeView; // Delete the child deletedNode = parentNode.removeChild(j); index = j; // remove the conditions associated to removed node deletedConditions = allConditions[deletedNode]; allConditions.Remove((ConversationNode)deletedNode); // If the current node is an option node, delete the line too if (parentNode.getType() == ConversationNodeViewEnum.OPTION) { deletedLine = parentNode.removeLine(j); // delete the associated condition data control deletedCondition = allConditions[parentNode][j]; allConditions[parentNode].RemoveAt(j); } // The node has been deleted nodeDeleted = true; } // If it's not, go for the next child else { j++; } } } } } return(nodeDeleted); }
void OnGUI() { if (!isShowingDialogue) return; // NAMEPLATE LABEL GUI.Label( new Rect( (isPlayerTalking)? transform.position.x + indentFromLeft : Screen.width - (nameplateWidth + indentFromLeft + 6), Screen.height - (nameplateHeight + dialogueHeight), // + dialogueHeight), nameplateWidth, nameplateHeight ), nameplateContent, nameplateStyle ); // DIALOGUE BOX LABEL GUI.Label( new Rect( transform.position.x + indentFromLeft, Screen.height - (dialogueHeight), dialogueWidth, dialogueHeight ), dialogueContent, dialogueStyle ); if (answers != null) { int x = 0; foreach(KeyValuePair<string, ConversationNode> kvp in answers) { if (GUI.Button( new Rect( Screen.width / 2 - nameplateWidth / 2, (nameplateHeight + dialogueHeight) + (x++ * nameplateHeight), nameplateWidth, nameplateHeight ), kvp.Key) ) { currentNode = kvp.Value; } } } if (currentNode != null && currentNode.GetType() == typeof(EndNode) && (currentNode as EndNode).isConversationEnding()) { if (GUI.Button( new Rect( Screen.width / 2 - nameplateWidth / 2, nameplateHeight + dialogueHeight, nameplateWidth, nameplateHeight ), "Let's go home!") ) { Application.LoadLevel(0); } } }
public bool manages(ConversationNode c) { return(c.GetType() == myNode.GetType()); }
//private Sprite talkingSprite; void Awake() { if(Instance != null) { Debug.Log("ERROR: Multiple instances of DialogueScript created."); } Instance = this; nameplateContent = "Nameplate"; dialogueContent = "Dialogue"; answers = null; currentNode = startNode; Talk(); //talkingSprite = null; }
public INodeGui GetRenderer(ConversationNode <INodeGui> n, PointF p, Func <Id <LocalizedStringType>, Id <LocalizedText>, string> localizer, Func <IDataSource> datasource) { return(new PartialRenderer(n, p, localizer, datasource)); }
/* Methods */ /** * Constructor * * @param conversationType * Type of the conversation * @param conversationId * Identifier of the conversation * @param root * Root node (start) of the conversation */ protected Conversation(int conversationType, string conversationId, ConversationNode root) { this.conversationType = conversationType; this.conversationId = conversationId; this.root = root; }
public void SetNext (ConversationNode node) { this.Next = node; }