public void Talk(ConversationLine line, string talkerName = null) { var resources = line.getResources().Checked().FirstOrDefault(); if (resources != null) { var image = resources.existAsset("image") ? Game.Instance.ResourceManager.getImage(resources.getAssetPath("image")) : null; var audio = resources.existAsset("audio") ? Game.Instance.ResourceManager.getAudio(resources.getAssetPath("audio")) : null; var tts = resources.existAsset("tts") ? resources.getAssetPath("tts") == "yes" : false; Talk(line.getText(), image, audio, tts, talkerName); } else { Talk(line.getText(), null, null, false, talkerName); } }
protected void Update() { if (get_talker && GameObject.Find(talkerToFind) != null) { get_talker = false; Talk(line.getText(), talkerToFind); } }
void OnGUI() { float guiscale = Screen.width / 800f; style.box.fontSize = Mathf.RoundToInt(guiscale * 20); style.button.fontSize = Mathf.RoundToInt(guiscale * 20); style.label.fontSize = Mathf.RoundToInt(guiscale * 20); optionlabel.fontSize = Mathf.RoundToInt(guiscale * 36); style.GetStyle("talk_player").fontSize = Mathf.RoundToInt(guiscale * 20); float rectwith = guiscale * 330; switch (guistate) { case guiState.ANSWERS_MENU: GUILayout.BeginArea(new Rect(Screen.width * 0.1f, Screen.height * 0.1f, Screen.width * 0.8f, Screen.height * 0.8f)); GUILayout.BeginVertical(); OptionConversationNode options = (OptionConversationNode)guioptions.getNode(); GUILayout.Label(GUIManager.Instance.Last, optionlabel); for (int i = 0; i < options.getLineCount(); i++) { ConversationLine ono = options.getLine(i); if (ConditionChecker.check(options.getLineConditions(i))) { if (GUILayout.Button((string)ono.getText(), style.button)) { GameObject.Destroy(blur); guioptions.clicked(i); Tracker.T().Choice(GUIManager.Instance.Last, ono.getText()); Tracker.T().RequestFlush(); Interacted(); } } ; } GUILayout.EndVertical(); GUILayout.EndArea(); break; default: break; } }
protected void OnGUI() { if (loadingScreen != null) { loadingScreen.OnGUI(); } switch (guistate) { case GUIState.BOOK: if (ShowingBook) { bookDrawer.Draw(new Rect(Vector2.zero, new Vector2(Screen.width, Screen.height))); } break; case GUIState.ANSWERS_MENU: using (new GUIUtil.SkinScope(skin)) { float guiscale = Screen.width / 800f; var buttonImageWidth = (200f / 600f) * Screen.height; skin.box.fontSize = Mathf.RoundToInt(guiscale * 20); skin.button.fontSize = Mathf.RoundToInt(guiscale * 20); skin.button.alignment = TextAnchor.MiddleCenter; skin.button.imagePosition = ImagePosition.ImageAbove; skin.button.stretchHeight = false; skin.button.stretchWidth = true; skin.label.fontSize = Mathf.RoundToInt(guiscale * 20); skin.GetStyle("optionLabel").fontSize = Mathf.RoundToInt(guiscale * 36); skin.GetStyle("talk_player").fontSize = Mathf.RoundToInt(guiscale * 20); skin.GetStyle("emptyProgressBar").fontSize = Mathf.RoundToInt(guiscale * 20); OptionConversationNode options = (OptionConversationNode)guioptions.getNode(); var areawidth = Screen.width * 0.8f; using (new GUILayout.AreaScope(new Rect(Screen.width * 0.1f, Screen.height * 0.1f, areawidth, Screen.height * 0.8f))) { using (new GUILayout.VerticalScope(GUILayout.ExpandWidth(true))) { var restWidth = 1f; var initedHorizontal = false; if (options.isKeepShowing() && GUIManager.Instance.Line != null) { var text = GUIManager.Instance.Line.getText(); if (text[0] == '#') { text = text.Remove(0, Mathf.Max(0, text.IndexOf(' ') + 1)); } var textContent = new GUIContent(text); var textRect = GUILayoutUtility.GetRect(textContent, "optionLabel"); GUIUtil.DrawTextBorder(textRect, textContent, Color.black, "optionLabel"); GUIUtil.DrawText(textRect, textContent, ((GUIStyle)"optionLabel").normal.textColor, "optionLabel"); var resources = GUIManager.Instance.Line.getResources().Checked().FirstOrDefault(); if (resources != null) { var image = resources.existAsset("image") ? Game.Instance.ResourceManager.getImage(resources.getAssetPath("image")) : null; if (image) { GUILayout.BeginHorizontal(); initedHorizontal = true; restWidth = 0.7f; var imageRatio = image.width / (float)image.height; var imageWidth = areawidth * 0.28f; var imageHeight = Mathf.Min(imageWidth / imageRatio, Screen.height * 0.45f); using (new GUILayout.VerticalScope(GUILayout.Width(areawidth * 0.3f))) { GUILayout.FlexibleSpace(); GUILayout.Box(image, GUILayout.Width(imageWidth), GUILayout.Height(imageHeight)); GUILayout.FlexibleSpace(); } } } } using (new GUILayout.VerticalScope(GUILayout.Width(areawidth * restWidth))) { if (options.Horizontal) { GUILayout.FlexibleSpace(); } var elementsLeft = options.getLineCount(); while (elementsLeft > 0) { if (options.Horizontal) { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); } else { GUILayout.BeginVertical(); } var start = options.getLineCount() - elementsLeft; var amount = options.MaxElemsPerRow > 0 ? options.MaxElemsPerRow : options.getLineCount(); var end = Mathf.Clamp(start + amount, 0, options.getLineCount()); var eachWidth = (areawidth * restWidth / (end - start)) - 20; for (int i = start; i < end; i++) { ConversationLine ono = options.getLine(order[i]); var content = new GUIContent(ono.getText()); var resources = ono.getResources().Checked().FirstOrDefault(); auxLimitList.Clear(); if (end - start > 1 && options.Horizontal) { auxLimitList.Add(GUILayout.Width(eachWidth)); } if (resources != null && resources.existAsset("image") && !string.IsNullOrEmpty(resources.getAssetPath("image"))) { var imagePath = resources.getAssetPath("image"); var image = ResourceManager.getImage(imagePath); if (image) { content.image = image; /*if (image.height > buttonImageWidth) * {*/ auxLimitList.Add(GUILayout.Height(buttonImageWidth - 20)); //} } } if (ConditionChecker.check(options.getLineConditions(order[i])) && GUILayout.Button(content, auxLimitList.ToArray())) { OptionSelected(order[i]); } } elementsLeft = options.getLineCount() - end; if (options.Horizontal) { GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } else { GUILayout.EndVertical(); } if (doTimeOut) { if (Event.current.type == EventType.Repaint && elapsedTime > options.Timeout) { OptionSelected(options.getChildCount() - 1); } var timeLeft = Mathf.Max(0, options.Timeout - elapsedTime); var timeLeftText = Mathf.Round(timeLeft * 10) / 10 + " s"; GUILayout.FlexibleSpace(); DrawProgressBar(GUILayoutUtility.GetRect(0, 0, "emptyProgressBar", GUILayout.ExpandWidth(true), GUILayout.Height(50)), timeLeftText, 1 - (elapsedTime / options.Timeout)); } } if (initedHorizontal) { GUILayout.EndHorizontal(); } if (options.Horizontal) { GUILayout.FlexibleSpace(); } } } } } break; default: break; } }
protected void OnGUI() { switch (guistate) { case GUIState.BOOK: if (ShowingBook) { bookDrawer.Draw(new Rect(Vector2.zero, new Vector2(Screen.width, Screen.height))); } break; case GUIState.ANSWERS_MENU: using (new GUIUtil.SkinScope(skin)) { float guiscale = Screen.width / 800f; skin.box.fontSize = Mathf.RoundToInt(guiscale * 20); skin.button.fontSize = Mathf.RoundToInt(guiscale * 20); skin.label.fontSize = Mathf.RoundToInt(guiscale * 20); skin.GetStyle("optionLabel").fontSize = Mathf.RoundToInt(guiscale * 36); skin.GetStyle("talk_player").fontSize = Mathf.RoundToInt(guiscale * 20); skin.GetStyle("emptyProgressBar").fontSize = Mathf.RoundToInt(guiscale * 20); using (new GUILayout.AreaScope(new Rect(Screen.width * 0.1f, Screen.height * 0.1f, Screen.width * 0.8f, Screen.height * 0.8f))) { using (new GUILayout.VerticalScope()) { OptionConversationNode options = (OptionConversationNode)guioptions.getNode(); if (options.isKeepShowing()) { var text = GUIManager.Instance.Last; if (text[0] == '#') { text = text.Remove(0, Mathf.Max(0, text.IndexOf(' ') + 1)); } var textContent = new GUIContent(text); var textRect = GUILayoutUtility.GetRect(textContent, "optionLabel"); GUIUtil.DrawTextBorder(textRect, textContent, Color.black, "optionLabel"); GUIUtil.DrawText(textRect, textContent, ((GUIStyle)"optionLabel").normal.textColor, "optionLabel"); } foreach (var i in order) { ConversationLine ono = options.getLine(i); if (ConditionChecker.check(options.getLineConditions(i)) && GUILayout.Button(ono.getText())) { OptionSelected(i); } } if (doTimeOut) { if (Event.current.type == EventType.Repaint && elapsedTime > options.Timeout) { OptionSelected(options.getChildCount() - 1); } var timeLeft = Mathf.Max(0, options.Timeout - elapsedTime); var timeLeftText = Mathf.Round(timeLeft * 10) / 10 + " s"; GUILayout.FlexibleSpace(); DrawProgressBar(GUILayoutUtility.GetRect(0, 0, "emptyProgressBar", GUILayout.ExpandWidth(true), GUILayout.Height(50)), timeLeftText, 1 - (elapsedTime / options.Timeout)); } } } } break; default: break; } }
protected void OnGUI() { switch (guistate) { case GUIState.BOOK: if (ShowingBook) { bookDrawer.Draw(new Rect(Vector2.zero, new Vector2(Screen.width, Screen.height))); } break; case GUIState.ANSWERS_MENU: using (new GUIUtil.SkinScope(skin)) { float guiscale = Screen.width / 800f; skin.box.fontSize = Mathf.RoundToInt(guiscale * 20); skin.button.fontSize = Mathf.RoundToInt(guiscale * 20); skin.button.alignment = TextAnchor.MiddleCenter; skin.button.imagePosition = ImagePosition.ImageAbove; skin.button.stretchHeight = false; skin.button.stretchWidth = true; skin.label.fontSize = Mathf.RoundToInt(guiscale * 20); skin.GetStyle("optionLabel").fontSize = Mathf.RoundToInt(guiscale * 36); skin.GetStyle("talk_player").fontSize = Mathf.RoundToInt(guiscale * 20); skin.GetStyle("emptyProgressBar").fontSize = Mathf.RoundToInt(guiscale * 20); using (new GUILayout.AreaScope(new Rect(Screen.width * 0.1f, Screen.height * 0.1f, Screen.width * 0.8f, Screen.height * 0.8f))) { using (new GUILayout.VerticalScope()) { OptionConversationNode options = (OptionConversationNode)guioptions.getNode(); if (options.isKeepShowing()) { var text = GUIManager.Instance.Last; if (text[0] == '#') { text = text.Remove(0, Mathf.Max(0, text.IndexOf(' ') + 1)); } var textContent = new GUIContent(text); var textRect = GUILayoutUtility.GetRect(textContent, "optionLabel"); GUIUtil.DrawTextBorder(textRect, textContent, Color.black, "optionLabel"); GUIUtil.DrawText(textRect, textContent, ((GUIStyle)"optionLabel").normal.textColor, "optionLabel"); } foreach (var i in order) { ConversationLine ono = options.getLine(i); var content = new GUIContent(ono.getText()); var resources = ono.getResources().Checked().FirstOrDefault(); auxLimitList.Clear(); if (resources != null && resources.existAsset("image") && !string.IsNullOrEmpty(resources.getAssetPath("image"))) { var imagePath = resources.getAssetPath("image"); var image = ResourceManager.getImage(imagePath); if (image) { content.image = image; if (image.height > 240) { auxLimitList.Add(GUILayout.Height(240)); } } } if (ConditionChecker.check(options.getLineConditions(i)) && GUILayout.Button(content, auxLimitList.ToArray())) { OptionSelected(i); } } if (doTimeOut) { if (Event.current.type == EventType.Repaint && elapsedTime > options.Timeout) { OptionSelected(options.getChildCount() - 1); } var timeLeft = Mathf.Max(0, options.Timeout - elapsedTime); var timeLeftText = Mathf.Round(timeLeft * 10) / 10 + " s"; GUILayout.FlexibleSpace(); DrawProgressBar(GUILayoutUtility.GetRect(0, 0, "emptyProgressBar", GUILayout.ExpandWidth(true), GUILayout.Height(50)), timeLeftText, 1 - (elapsedTime / options.Timeout)); } } } } break; default: break; } }
/** * 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 var text = document.CreateElement("text"); text.InnerText = line.getText(); phrase.AppendChild(text); // Append the resources foreach (ResourcesUni resources in line.getResources()) { XmlNode resourcesNode = ResourcesDOMWriter.buildDOM(resources, ResourcesDOMWriter.RESOURCES_CONVERSATION_LINE); document.ImportNode(resourcesNode, true); phrase.AppendChild(resourcesNode); } // 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"); var text = document.CreateElement("text"); text.InnerText = currentNode.getLine(i).getText(); lineElement.AppendChild(text); // Append the resources foreach (ResourcesUni resources in line.getResources()) { XmlNode resourcesNode = ResourcesDOMWriter.buildDOM(resources, ResourcesDOMWriter.RESOURCES_CONVERSATION_LINE); document.ImportNode(resourcesNode, true); lineElement.AppendChild(resourcesNode); } // 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); } }
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()); } } // Append the resources foreach (ResourcesUni resources in line.getResources()) { XmlNode resourcesNode = ResourcesDOMWriter.buildDOM(resources, ResourcesDOMWriter.RESOURCES_CONVERSATION_LINE); doc.ImportNode(resourcesNode, true); phrase.AppendChild(resourcesNode); } // Add the line text into the element var text = doc.CreateElement("text"); text.InnerText = line.getText(); phrase.AppendChild(text); // 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"); var text = doc.CreateElement("text"); text.InnerText = node.getLine(j).getText(); lineElement.AppendChild(text); // Append the resources foreach (ResourcesUni resources in line.getResources()) { XmlNode resourcesNode = ResourcesDOMWriter.buildDOM(resources, ResourcesDOMWriter.RESOURCES_CONVERSATION_LINE); doc.ImportNode(resourcesNode, true); lineElement.AppendChild(resourcesNode); } 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); } }
public override void recursiveSearch() { check(conversationLine.getName(), TC.get("Search.LineName")); check(conversationLine.getText(), TC.get("Search.LineText")); }
/** * 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) { // 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.getType() == ConversationNodeViewEnum.DIALOGUE) { // 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; XmlNode conditionsNode = null; 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()); } // 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()); } } 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.getType() == ConversationNodeViewEnum.OPTION) { // 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()); } // Add the element rootDOMNode.AppendChild(response); } }
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; XmlNode conditionsNode = null; // If the node is a dialogue node if (node is DialogueConversationNode) { // 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 (((DialogueConversationNode)node).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()); } // 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()); } // 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()); } // 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); // TODO MODIFIED // If the terminal node has an effect, include it into the DOM if (node.hasEffects()) { DOMWriterUtility.DOMWrite(nodeElement, node.getEffects()); } } } // If the node is a option node if (node is OptionConversationNode) { // Create the node element and set the nodeindex nodeElement = doc.CreateElement("option-node"); nodeElement.SetAttribute("nodeindex", i.ToString()); // Adds a random attribute if "random" is activate in conversation node data if (((OptionConversationNode)node).isRandom()) { nodeElement.SetAttribute("random", "yes"); } // Adds a random attribute if "keepShowing" is activate in conversation node data if (((OptionConversationNode)node).isKeepShowing()) { nodeElement.SetAttribute("keepShowing", "yes"); } // Adds a random attribute if "showUserOption" is activate in conversation node data if (((OptionConversationNode)node).isShowUserOption()) { nodeElement.SetAttribute("showUserOption", "yes"); } // Adds a random attribute if "preListening" is activate in conversation node data if (((OptionConversationNode)node).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()); } // Adds the x position of the options conversations node nodeElement.SetAttribute("x", ((OptionConversationNode)node).getX().ToString()); // Adds a random attribute if "preListening" is activate in conversation node data nodeElement.SetAttribute("y", ((OptionConversationNode)node).getY().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"); } // 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()); // Insert child tag nodeElement.AppendChild(childElement); } // If node has an effect, include it into the DOM if (node.hasEffects()) { DOMWriterUtility.DOMWrite(nodeElement, node.getEffects()); } } // Add the node to the conversation conversationElement.AppendChild(nodeElement); } }
void OnGUI() { float guiscale = Screen.width / 800f; style.box.fontSize = Mathf.RoundToInt(guiscale * 20); style.button.fontSize = Mathf.RoundToInt(guiscale * 20); style.label.fontSize = Mathf.RoundToInt(guiscale * 20); optionlabel.fontSize = Mathf.RoundToInt(guiscale * 36); //style.label.fontSize = Mathf.RoundToInt(guiscale * 20); style.GetStyle("talk_player").fontSize = Mathf.RoundToInt(guiscale * 20); float rectwith = guiscale * 330; switch (guistate) { case guiState.TALK_PLAYER: /*GUILayout.BeginArea (new Rect ((Screen.width/2)-rectwith/2, 50, rectwith, 400)); * GUILayout.BeginHorizontal (); * GUILayout.Box (guitext,style.GetStyle("talk_player")); * GUILayout.EndHorizontal (); * GUILayout.EndArea ();*/ break; case guiState.TALK_CHARACTER: /*GUIStyle current = new GUIStyle(style.box); * if (this.guitalkerObject != null) { * position = Camera.current.WorldToScreenPoint (this.guitalkerObject.transform.position); * Color tmp = Color.black; * NPC cha = data.getChapters () [current_chapter].getCharacter (guitalker); * * * ColorUtility.TryParseHtmlString( * cha.getTextFrontColor() * ,out tmp); * * current.normal.textColor = tmp; * current.normal.background = BorderGenerator.generateFor (cha); * }else * position = new Vector2(Screen.width/2,100); * * if(position.x <= rectwith/2) * position.x = rectwith/2; * else if(position.x >= (Screen.width - rectwith/2) ) * position.x = (Screen.width - rectwith/2); * * GUILayout.BeginArea ( * new Rect (position.x-rectwith/2, * Screen.height * - position.y * - (this.guitalkerObject.GetComponent<CharacterMB>().getHeight())*guiscale/2 * - current.CalcHeight(new GUIContent(guitext),rectwith), rectwith, 400) * ); * GUILayout.BeginHorizontal (); * GUILayout.Box (guitext,current); * GUILayout.EndHorizontal (); * GUILayout.EndArea ();*/ break; case guiState.ANSWERS_MENU: GUILayout.BeginArea(new Rect(Screen.width * 0.1f, Screen.height * 0.1f, Screen.width * 0.8f, Screen.height * 0.8f)); GUILayout.BeginVertical(); OptionConversationNode options = (OptionConversationNode)guioptions.getNode(); GUILayout.Label(guitext, optionlabel); for (int i = 0; i < options.getLineCount(); i++) { ConversationLine ono = options.getLine(i); if (ConditionChecker.check(options.getLineConditions(i))) { if (GUILayout.Button((string)ono.getText(), style.button)) { GameObject.Destroy(blur); guioptions.clicked(i); Interacted(); } } ; } GUILayout.EndVertical(); GUILayout.EndArea(); break; case guiState.LOADING_GAME: break; case guiState.NOTHING: /*if(loader_state == loaderState.LOADING){ * GUILayout.BeginArea (new Rect (Screen.width*0.1f, Screen.height*0.1f, Screen.width*0.8f, Screen.height*0.8f)); * GUILayout.BeginVertical (); * GUILayout.Label ("Cargando",style.label); * * if(totals != null){ * GUILayout.Box ("Personajes: " + this.characters.Count + " de " + totals["Characters"],style.box); * GUILayout.Box ("Objetos: " + this.objects.Count + " de " + totals["Objects"],style.box); * GUILayout.Box ("Objetos de Atrezzo: " + this.atrezzos.Count + " de " + totals["Atrezzos"],style.box); * GUILayout.Box ("Estados Globales: " + this.global_states.Count + " de " + totals["Global-States"],style.box); * GUILayout.Box ("Grafos de Conversacion: " + this.graph_conversations.Count + " de " + totals["Graph-conversations"],style.box); * GUILayout.Box ("Macros: " + this.macros.Count + " de " + totals["Macros"],style.box); * * GUILayout.Box ("Escenas: " + this.scenes.Count + " de " + totals["Scene"],style.box); * } * * * GUILayout.EndVertical (); * GUILayout.EndArea (); * }*/ break; case guiState.GAME_SELECTION: /*GUILayout.BeginArea (new Rect (Screen.width*0.1f, Screen.height*0.1f, Screen.width*0.8f, Screen.height*0.8f)); * GUILayout.BeginVertical (); * string[] games = Directory.GetDirectories("Games/"); * * GUILayout.Label("eAdventure Loader v0.1",style.label); * foreach(string game in games){ * if(GUILayout.Button (game.Split('/')[1],style.button)){ * this.selected_game = game + "/"; * //this.startLoad(); * }; * } * GUILayout.EndVertical (); * GUILayout.EndArea (); * break;*/ default: break; } }