private void DoConversationLine(ConversationLine conversationLine) { WaitConversationLock = false; ShowConversationPanel(); if (conversationLine != null) { if (conversationLine.GetType() == typeof(DialogueLine)) { DisplayDialogueLine((DialogueLine)conversationLine); } else if (conversationLine.GetType() == typeof(GamePauseLine)) { if (Cutscene) { IntroBehaviour.PlayPaused = ((GamePauseLine)conversationLine).Pause; } else { GameController.PlayPaused = ((GamePauseLine)conversationLine).Pause; } MoveOnConversation(); } else if (conversationLine.GetType() == typeof(DelegateLine)) { ((DelegateLine)conversationLine).OnReachLine(); MoveOnConversation(); } } else { StopConversation(); } }
public ConversationLineDataControl(ConversationLine conversationLine) : base() { this.conversationLine = conversationLine; this.conversationLineConditionsController = new ConditionsController(conversationLine.getConditions()); this.resourcesList = conversationLine.getResources(); this.resourcesDataControlList = conversationLine.getResources().ConvertAll(r => new ResourcesDataControl(r, Controller.CONVERSATION_DIALOGUE_LINE)); }
public override ConversationLine removeLine(int index) { ConversationLine item = options[index]; options.RemoveAt(index); return(item); }
public override bool doTool() { lineAdded = new ConversationLine(name, TC.get("ConversationLine.DefaultText")); parent.addLine(lineIndex, lineAdded); node.Insert(lineIndex, new ConditionsController(lineAdded.getConditions(), Controller.CONVERSATION_OPTION_LINE, lineIndex.ToString())); return(true); }
public override ConversationLine removeLine(int index) { // WORKAROUND ConversationLine tmp = dialogue[index]; dialogue.RemoveAt(index); return(tmp); }
public override bool doTool() { lineDeleted = parent.getLine(lineIndex); parent.removeLine(lineIndex); conditionDeleted = node[lineIndex]; node.RemoveAt(lineIndex); return(true); }
public AddRemoveLineTool(ConversationNodeDataControl node, string name, string text) { this.isAdd = true; this.node = node; var newLine = new ConversationLine(name, text); newLine.addResources(new ResourcesUni()); this.line = new ConversationLineDataControl(newLine); }
protected static ResourcesUni createResources(ConversationLine line) { ResourcesUni resources = new ResourcesUni(); if (line.getAudioPath() != null) { resources.addAsset(AUDIO_STR, line.getAudioPath()); } return(resources); }
public override bool doTool() { bool done = base.doTool(); if (done) { deletedLine = parent.getLine(linkIndex); parent.removeLine(linkIndex); } return(done); }
public void Talk(string text, Texture2D image, AudioClip audio, bool synthetizeVoice, string talkerName = null) { line = new ConversationLine("", text); GameObject talkerObject = null; BubbleData bubbleData; if (talkerName == null || talkerName == Player.IDENTIFIER) { text = text.Replace("[]", "[" + Player.IDENTIFIER + "]"); NPC player = Game.Instance.GameState.Player; if (Game.Instance.GameState.IsFirstPerson || PlayerMB.Instance == null) { bubbleData = GenerateBubble(player, text); } else { talkerObject = GetTalker(talkerName); if (talkerObject == null) { return; } bubbleData = GenerateBubble(player, text, talkerObject); } bubbleData.Image = image; bubbleData.TTS = synthetizeVoice; bubbleData.Audio = audio; ShowBubble(bubbleData); } else { talkerObject = GetTalker(talkerName); if (talkerObject == null) { return; } NPC cha = Game.Instance.GameState.GetCharacter(talkerName); bubbleData = GenerateBubble(cha, text, talkerObject); bubbleData.Image = image; bubbleData.TTS = synthetizeVoice; bubbleData.Audio = audio; ShowBubble(bubbleData); } if (talkerObject) { var bubbleTalker = talkerObject.GetComponent <Representable>(); if (bubbleTalker) { bubbleTalker.Play("speak"); } } }
public object Clone() { ConversationLine cl = (ConversationLine)this.MemberwiseClone(); cl.audioPath = (audioPath != null ? audioPath : null); cl.name = (name != null ? name : null); cl.synthesizerVoice = synthesizerVoice; cl.text = (text != null ? text : null); cl.conditions = (conditions != null ? (Conditions)conditions.Clone() : null); cl.keepShowing = keepShowing; return(cl); }
public void OneOffConversationLine(ConversationLine conversationLine) { if (ShowTextCoroutine != null) { StopCoroutine(ShowTextCoroutine); ShowTextCoroutine = null; } SpeechEventsSinceTextChange = 0; WaitingForPlayer(false); DoConversationLine(conversationLine); }
protected override bool addChild(int index, ConversationNodeDataControl child, ref object data) { var line = data as ConversationLineDataControl; // If i receive a line its because I removed a line before, so I have to put the line making a new slot for the child if (line != null) { optionConversationNode.addLine(index, line.getContent() as ConversationLine); conversationLines.Insert(index, line); optionConversationNode.addChild(index, child.getContent() as ConversationNode); } // Otherwise push the current child to grandchild preserving the current line, except when adding in the end else { var timeout = data != null ? (float)data : 0f; if (timeout > 0) { // Reinsert the timeout child optionConversationNode.Timeout = timeout; optionConversationNode.addChild(child.getContent() as ConversationNode); } else { if (optionConversationNode.getChildCount() == index) { // We have to add brand new content var newLine = new ConversationLine(ConversationLine.PLAYER, ""); optionConversationNode.addLine(newLine); conversationLines.Add(new ConversationLineDataControl(newLine)); optionConversationNode.addChild(child.getContent() as ConversationNode); } else { // I have to push the current child to a grandchild position var grandChild = optionConversationNode.getChild(index); var newChild = child.getContent() as ConversationNode; // Set the child optionConversationNode.replaceChild(index, newChild); // Set the grandchild (if the node contains other childs, these will be preserved) if (newChild.getChildCount() == 0) { newChild.addChild(grandChild); } else { newChild.replaceChild(0, grandChild); } } } } return(true); }
///<summary> /// Shows the dialogue box for a character, types out the line, and eventually hides the box. ///</summary> private IEnumerator launchLine(ConversationLine line) { yield return(new WaitForSeconds(line.delay)); if (line.isChoice) { GameObject playerBox = dialogueBoxes[(int)CHARACTER.PLAYER]; // Hide the player's box until they make a choice. playerBox.SetActive(false); promptBox.SetActive(true); isUpSelected = true; isMakingChoice = true; selectorPanel1.SetActive(true); selectorPanel2.SetActive(false); StartCoroutine(typeSentence(choiceText1, line.text, line.keepPreviousText)); StartCoroutine(typeSentence(choiceText2, line.text2, line.keepPreviousText)); yield return(new WaitForSeconds(line.duration)); isMakingChoice = false; playerBox.SetActive(true); promptBox.SetActive(false); StartCoroutine(launchLine(isUpSelected ? line.response1 : line.response2)); StartCoroutine(typeSentence(dialogueTexts[(int)line.character], isUpSelected ? line.text : line.text2)); attitudes[(int)line.affectedCharacter] += isUpSelected ? 0 : -1; print($"Attitude of {line.affectedCharacter} = {attitudes[(int)line.affectedCharacter]}"); if (attitudes[(int)line.affectedCharacter] <= LEAVE_THRESHOLD) { dismissCharacter(line.affectedCharacter); } yield return(new WaitForSeconds(CHOICE_DISPLAY_DURATION)); playerBox.SetActive(false); yield break; } GameObject panel = dialogueBoxes[(int)line.character]; panel.SetActive(true); // Since typing takes its own time, we'll start it as a separate coroutine. StartCoroutine(typeSentence(dialogueTexts[(int)line.character], line.text, line.keepPreviousText)); if (line.hideOnExpire) { // Once the line's duration is finished, hide the box. yield return(new WaitForSeconds(line.duration)); panel.SetActive(false); } }
public void PlayLine(int lineNumber) { if (lineNumber >= storedData.conversationLines.Count) { FadeIn.Instance.FadeOut(); return; } ConversationLine lineToShow = storedData.conversationLines[lineNumber]; //Destroy the old line if (currentLine != null) { currentLine.SetActive(false); } //Spawn a new line // GameObject obj = Resources.Load<GameObject>("DialogueBox"); // if(obj != null) // { // obj = Instantiate(obj, Vector3.zero, Quaternion.identity); //Find the speaker locator if (speakerLocationDictionary.ContainsKey(lineToShow.speakerID)) { //Place it at the speaker location SpeakerLocator speakerLocator = speakerLocationDictionary[lineToShow.speakerID]; // obj.transform.parent = speakerLocator.sceneLocator.transform; // obj.transform.localPosition = Vector3.zero; speakerLocator.sceneLocator.SetActive(true); speakerLocator.sceneLocator.GetComponent <DialogueController>().SetText(lineToShow.dialogue); if (DonAnimatorController.Instance != null) { DonAnimatorController.Instance.PlayAnimation(lineToShow.speakerAnimation); } //text.text = lineToShow.dialogue; //Store the reference for later currentLine = speakerLocator.sceneLocator; } //Fill in the text //} //Play audio //Run animation countdownToNextLine = lineToShow.timeToDisplay; }
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); } }
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; } }
public override int countIdentifierReferences(string id) { int count = 0; // Check every node on the conversation List <ConversationNode> conversationNodes = graphConversation.getAllNodes(); foreach (ConversationNode conversationNode in conversationNodes) { // Check only dialogue nodes if (conversationNode.getType() == ConversationNodeViewEnum.DIALOGUE) { // Check all the lines in the node for (int i = 0; i < conversationNode.getLineCount(); i++) { ConversationLine conversationLine = conversationNode.getLine(i); if (conversationLine.getName().Equals(id)) { count++; } } // Add the references from the effects if (conversationNode.hasEffects()) { count += EffectsController.countIdentifierReferences(id, conversationNode.getEffects()); } } } // add conditions references foreach (List <ConditionsController> conditions in allConditions.Values) { foreach (ConditionsController condition in conditions) { count += condition.countIdentifierReferences(id); } } return(count); }
public override void replaceIdentifierReferences(string oldId, string newId) { // Check every node on the conversation List <ConversationNode> conversationNodes = graphConversation.getAllNodes(); foreach (ConversationNode conversationNode in conversationNodes) { // Check only dialogue nodes if (conversationNode.getType() == ConversationNodeViewEnum.DIALOGUE) { // Check all the lines in the node, and replace the identifier if necessary for (int i = 0; i < conversationNode.getLineCount(); i++) { ConversationLine conversationLine = conversationNode.getLine(i); if (conversationLine.getName().Equals(oldId)) { conversationLine.setName(newId); } } // Replace the references from the effects if (conversationNode.hasEffects()) { EffectsController.replaceIdentifierReferences(oldId, newId, conversationNode.getEffects()); } } // add conditions references foreach (List <ConditionsController> conditions in allConditions.Values) { foreach (ConditionsController condition in conditions) { condition.replaceIdentifierReferences(oldId, newId); } } } }
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; } }
public void Talk(string text, int x, int y, Color textColor, Color textBorderColor, Color backgroundColor, Color borderColor) { line = new ConversationLine("", text); ShowBubble(GenerateBubble(text, x, y, textColor, textBorderColor, backgroundColor, borderColor)); }
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; } }
public void Talk(ConversationLine line, string character) { GUIManager.Instance.Talk(line, character); }
public override void addLine(ConversationLine line) { options.Add(line); }
public override void addLine(int index, ConversationLine line) { options.Insert(index, line); }
/** * Adds a new line to the node, in the specified position * * @param index * Index for insertion * @param line * Line for insertion */ public abstract void addLine(int index, ConversationLine line);
/* * (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 override void addLine(int index, ConversationLine line) { dialogue.Insert(index, line); }
/* * (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 tag ending is the conversation, create the graph conversation, with the first node of the list if (qName.Equals("graph-conversation")) { setNodeLinks(); chapter.addConversation(new GraphConversation(conversationName, graphNodes[0])); } // If a node is closed else if (qName.Equals("dialogue-node") || qName.Equals("option-node")) { // Add the current node to the node list, and the set of children references into the node links graphNodes.Add(currentNode); nodeLinks.Add(currentLinks); } // 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 = new ConversationLine(ConversationLine.PLAYER, currentstring.Trim()); if (audioPath != null && !this.audioPath.Equals("")) { conversationLine.setAudioPath(audioPath); } if (synthesizerVoice != null) { conversationLine.setSynthesizerVoice(synthesizerVoice); } conversationLine.setKeepShowing(keepShowingLine); currentNode.addLine(conversationLine); } // 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 = new ConversationLine(characterName, currentstring.Trim()); if (audioPath != null && !this.audioPath.Equals("")) { conversationLine.setAudioPath(audioPath); } if (synthesizerVoice != null) { conversationLine.setSynthesizerVoice(synthesizerVoice); } conversationLine.setKeepShowing(keepShowingLine); currentNode.addLine(conversationLine); } // Reset the current string currentstring = string.Empty; } // If we are subparsing an effect else if (subParsing == SUBPARSING_EFFECT || subParsing == SUBPARSING_CONDITION) { // Spread the call subParser.endElement(namespaceURI, sName, qName); // If the effect is being closed, insert the effect into the current node if (qName.Equals("effect") && subParsing == SUBPARSING_EFFECT) { currentNode.setEffects(currentEffects); subParsing = SUBPARSING_NONE; } // If the effect is being closed, insert the effect into the current node else if (qName.Equals("condition") && subParsing == SUBPARSING_CONDITION) { conversationLine.setConditions(currentConditions); subParsing = SUBPARSING_NONE; } } }
public void Talk(ConversationLine line) { GUIManager.Instance.Talk(line); }
public override void OnImportAsset(AssetImportContext ctx) { var dlogObject = DlogUtility.LoadGraphAtPath(ctx.assetPath); var icon = Resources.Load <Texture2D>(ResourcesUtility.IconBig); var runtimeIcon = Resources.Load <Texture2D>(ResourcesUtility.RuntimeIconBig); if (string.IsNullOrEmpty(dlogObject.AssetGuid) || dlogObject.AssetGuid != AssetDatabase.AssetPathToGUID(ctx.assetPath)) { dlogObject.RecalculateAssetGuid(ctx.assetPath); DlogUtility.SaveGraph(dlogObject, false); } ctx.AddObjectToAsset("MainAsset", dlogObject, icon); ctx.SetMainObject(dlogObject); var runtimeObject = ScriptableObject.CreateInstance <DlogObject>(); var filePath = ctx.assetPath; var assetNameSubStartIndex = filePath.LastIndexOf('/') + 1; var assetNameSubEndIndex = filePath.LastIndexOf('.'); var assetName = filePath.Substring(assetNameSubStartIndex, assetNameSubEndIndex - assetNameSubStartIndex); runtimeObject.name = assetName + " (Runtime)"; // Add properties runtimeObject.Properties = new List <Runtime.Property>(); runtimeObject.Properties.AddRange(dlogObject.DlogGraph.Properties.Select( property => new Runtime.Property { Type = property.Type, DisplayName = property.DisplayName, ReferenceName = property.ReferenceName, Guid = property.GUID } )); // Add nodes runtimeObject.Nodes = new List <Runtime.Node>(); foreach (var node in dlogObject.DlogGraph.Nodes) { var nodeData = JObject.Parse(node.NodeData); var runtimeNode = new Runtime.Node(); runtimeNode.Guid = node.GUID; switch (node.Type) { case "Dlog.SelfNode": runtimeNode.Type = NodeType.SELF; break; case "Dlog.NpcNode": runtimeNode.Type = NodeType.NPC; break; case "Dlog.PropertyNode": runtimeNode.Type = NodeType.PROP; runtimeNode.Temp_PropertyNodeGuid = nodeData.Value <string>("propertyGuid"); break; case "Dlog.CheckCombinerNode": runtimeNode.Type = NodeType.COMBINER; break; default: throw new NotSupportedException($"Invalid node type {node.Type}."); } // Get lines if (runtimeNode.Type == NodeType.SELF) { runtimeNode.Lines = new List <ConversationLine>(); var lines = JsonConvert.DeserializeObject <List <LineDataSelf> >(nodeData.Value <string>("lines")); foreach (var line in lines) { var runtimeLine = new ConversationLine { Message = line.Line, Next = line.PortGuidA, TriggerPort = line.PortGuidB, CheckPort = Guid.Empty.ToString() }; runtimeNode.Lines.Add(runtimeLine); } } else if (runtimeNode.Type == NodeType.NPC) { runtimeNode.Lines = new List <ConversationLine>(); var lines = JsonConvert.DeserializeObject <List <LineDataNpc> >(nodeData.Value <string>("lines")); foreach (var line in lines) { var runtimeLine = new ConversationLine { Message = line.Line, Next = line.PortGuidA, TriggerPort = line.PortGuidB, CheckPort = line.PortGuidC }; runtimeNode.Lines.Add(runtimeLine); } } runtimeObject.Nodes.Add(runtimeNode); } // Add edges runtimeObject.Edges = new List <Runtime.Edge>(); runtimeObject.Edges.AddRange(dlogObject.DlogGraph.Edges.Select( edge => new Runtime.Edge { FromNode = edge.Output, FromPort = edge.OutputPort, ToNode = edge.Input, ToPort = edge.InputPort } )); runtimeObject.BuildGraph(); ctx.AddObjectToAsset("RuntimeAsset", runtimeObject, runtimeIcon); AssetDatabase.Refresh(); EditorUtility.SetDirty(runtimeObject); }
public override void addLine(ConversationLine line) { dialogue.Add(line); }
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); } }
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)); }
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; } }
/** * Adds a new line to the node, in the last position * * @param line * Line for insertion */ public abstract void addLine(ConversationLine line);
bool Create(ulong lowGuid, uint conversationEntry, Map map, Unit creator, Position pos, List <ObjectGuid> participants, SpellInfo spellInfo = null) { ConversationTemplate conversationTemplate = Global.ConversationDataStorage.GetConversationTemplate(conversationEntry); //ASSERT(conversationTemplate); _creatorGuid = creator.GetGUID(); _participants = participants; SetMap(map); Relocate(pos); _Create(ObjectGuid.Create(HighGuid.Conversation, GetMapId(), conversationEntry, lowGuid)); PhasingHandler.InheritPhaseShift(this, creator); SetEntry(conversationEntry); SetObjectScale(1.0f); SetUpdateFieldValue(m_values.ModifyValue(m_conversationData).ModifyValue(m_conversationData.LastLineEndTime), conversationTemplate.LastLineEndTime); _duration = conversationTemplate.LastLineEndTime; _textureKitId = conversationTemplate.TextureKitId; for (ushort actorIndex = 0; actorIndex < conversationTemplate.Actors.Count; ++actorIndex) { ConversationActorTemplate actor = conversationTemplate.Actors[actorIndex]; if (actor != null) { ConversationActor actorField = new ConversationActor(); actorField.CreatureID = actor.CreatureId; actorField.CreatureDisplayInfoID = actor.CreatureModelId; actorField.Type = ConversationActorType.CreatureActor; AddDynamicUpdateFieldValue(m_values.ModifyValue(m_conversationData).ModifyValue(m_conversationData.Actors), actorField); } } for (ushort actorIndex = 0; actorIndex < conversationTemplate.ActorGuids.Count; ++actorIndex) { ulong actorGuid = conversationTemplate.ActorGuids[actorIndex]; if (actorGuid == 0) { continue; } foreach (var creature in map.GetCreatureBySpawnIdStore().LookupByKey(actorGuid)) { // we just need the last one, overriding is legit AddActor(creature.GetGUID(), actorIndex); } } Global.ScriptMgr.OnConversationCreate(this, creator); List <ushort> actorIndices = new List <ushort>(); List <ConversationLine> lines = new List <ConversationLine>(); foreach (ConversationLineTemplate line in conversationTemplate.Lines) { actorIndices.Add(line.ActorIdx); ConversationLine lineField = new ConversationLine(); lineField.ConversationLineID = line.Id; lineField.StartTime = line.StartTime; lineField.UiCameraID = line.UiCameraID; lineField.ActorIndex = line.ActorIdx; lineField.Flags = line.Flags; lines.Add(lineField); } SetUpdateFieldValue(m_values.ModifyValue(m_conversationData).ModifyValue(m_conversationData.Lines), lines); Global.ScriptMgr.OnConversationCreate(this, creator); // All actors need to be set foreach (ushort actorIndex in actorIndices) { ConversationActor actor = actorIndex < m_conversationData.Actors.Size() ? m_conversationData.Actors[actorIndex] : null; if (actor == null || (actor.CreatureID == 0 && actor.ActorGUID.IsEmpty())) { Log.outError(LogFilter.Conversation, $"Failed to create conversation (Id: {conversationEntry}) due to missing actor (Idx: {actorIndex})."); return(false); } } if (!GetMap().AddToMap(this)) { return(false); } return(true); }
/* * (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 tag ending is the conversation, create the graph conversation, with the first node of the list if (qName.Equals("graph-conversation")) { setNodeLinks(); chapter.addConversation(new GraphConversation(conversationName, graphNodes[0])); } // If a node is closed else if (qName.Equals("dialogue-node") || qName.Equals("option-node")) { // Add the current node to the node list, and the set of children references into the node links graphNodes.Add(currentNode); nodeLinks.Add(currentLinks); } // 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 = new ConversationLine(ConversationLine.PLAYER, currentstring.Trim()); if (audioPath != null && !this.audioPath.Equals("")) { conversationLine.setAudioPath(audioPath); } if (synthesizerVoice != null) conversationLine.setSynthesizerVoice(synthesizerVoice); conversationLine.setKeepShowing(keepShowingLine); currentNode.addLine(conversationLine); } // 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 = new ConversationLine(characterName, currentstring.Trim()); if (audioPath != null && !this.audioPath.Equals("")) { conversationLine.setAudioPath(audioPath); } if (synthesizerVoice != null) conversationLine.setSynthesizerVoice(synthesizerVoice); conversationLine.setKeepShowing(keepShowingLine); currentNode.addLine(conversationLine); } // Reset the current string currentstring = string.Empty; } // If we are subparsing an effect else if (subParsing == SUBPARSING_EFFECT || subParsing == SUBPARSING_CONDITION) { // Spread the call subParser.endElement(namespaceURI, sName, qName); // If the effect is being closed, insert the effect into the current node if (qName.Equals("effect") && subParsing == SUBPARSING_EFFECT) { currentNode.setEffects(currentEffects); subParsing = SUBPARSING_NONE; } // If the effect is being closed, insert the effect into the current node else if (qName.Equals("condition") && subParsing == SUBPARSING_CONDITION) { conversationLine.setConditions(currentConditions); subParsing = SUBPARSING_NONE; } } }