public override void OnEnter() { // Selected "use default Portrait Stage" if (stage == null) { // If no default specified, try to get any portrait stage in the scene stage = Stage.GetActiveStage(); // If portrait stage does not exist, do nothing if (stage == null) { Continue(); return; } } // If no display specified, do nothing if (IsDisplayNone(display)) { Continue(); return; } PortraitOptions options = new PortraitOptions(); options.character = character; options.replacedCharacter = replacedCharacter; options.portrait = portrait; options.display = display; options.offset = offset; options.fromPosition = fromPosition; options.toPosition = toPosition; options.facing = facing; options.useDefaultSettings = useDefaultSettings; options.fadeDuration = fadeDuration; options.moveDuration = moveDuration; options.shiftOffset = shiftOffset; options.move = move; options.shiftIntoPlace = shiftIntoPlace; options.waitUntilFinished = waitUntilFinished; stage.RunPortraitCommand(options, Continue); }
/// <summary> /// Parse and execute a conversation string. /// </summary> public virtual IEnumerator DoConversation(string conv) { if (string.IsNullOrEmpty(conv)) { yield break; } var conversationItems = Parse(conv); if (conversationItems.Count == 0) { yield break; } // Track the current and previous parameter values Character currentCharacter = null; Sprite currentPortrait = null; RectTransform currentPosition = null; Character previousCharacter = null; // Play the conversation for (int i = 0; i < conversationItems.Count; ++i) { ConversationItem item = conversationItems[i]; if (item.Character != null) { currentCharacter = item.Character; } currentPortrait = item.Portrait; currentPosition = item.Position; var sayDialog = GetSayDialog(currentCharacter); if (sayDialog == null) { // Should never happen yield break; } sayDialog.SetActive(true); if (currentCharacter != null && currentCharacter != previousCharacter) { sayDialog.SetCharacter(currentCharacter); } //Handle stage changes var stage = Stage.GetActiveStage(); if (currentCharacter != null && !currentCharacter.State.onScreen && currentPortrait == null) { // No call to show portrait of hidden character // so keep hidden item.Hide = true; } if (stage != null && currentCharacter != null && (currentPortrait != currentCharacter.State.portrait || currentPosition != currentCharacter.State.position)) { var portraitOptions = new PortraitOptions(true); portraitOptions.display = item.Hide ? DisplayType.Hide : DisplayType.Show; portraitOptions.character = currentCharacter; portraitOptions.fromPosition = currentCharacter.State.position; portraitOptions.toPosition = currentPosition; portraitOptions.portrait = currentPortrait; //Flip option - Flip the opposite direction the character is currently facing if (item.Flip) { portraitOptions.facing = item.FacingDirection; } // Do a move tween if the character is already on screen and not yet at the specified position if (currentCharacter.State.onScreen && currentPosition != currentCharacter.State.position) { portraitOptions.move = true; } if (item.Hide) { stage.Hide(portraitOptions); } else { stage.Show(portraitOptions); } } if (stage == null && currentPortrait != null) { sayDialog.SetCharacterImage(currentPortrait); } previousCharacter = currentCharacter; if (!string.IsNullOrEmpty(item.Text)) { exitSayWait = false; sayDialog.Say(item.Text, true, true, true, true, false, null, () => { exitSayWait = true; }); while (!exitSayWait) { yield return(null); } exitSayWait = false; } } }
/// <summary> /// Using the string of say parameters before the ':', /// set the current character, position and portrait if provided. /// </summary> /// <returns>The conversation item.</returns> /// <param name="sayParams">The list of say parameters.</param> /// <param name="text">The text for the character to say.</param> /// <param name="currentCharacter">The currently speaking character.</param> protected virtual ConversationItem CreateConversationItem(string[] sayParams, string text, Character currentCharacter) { var item = new ConversationItem(); // Populate the story text to be written item.Text = text; if (sayParams == null || sayParams.Length == 0) { // Text only, no params - early out. return(item); } // try to find the character param first, since we need to get its portrait int characterIndex = -1; if (characters == null) { PopulateCharacterCache(); } for (int i = 0; item.Character == null && i < sayParams.Length; i++) { for (int j = 0; j < characters.Length; j++) { if (characters[j].NameStartsWith(sayParams[i])) { characterIndex = i; item.Character = characters[j]; break; } } } // Assume last used character if none is specified now if (item.Character == null) { item.Character = currentCharacter; } // Check if there's a Hide parameter int hideIndex = -1; if (item.Character != null) { for (int i = 0; i < sayParams.Length; i++) { if (i != characterIndex && string.Compare(sayParams[i], "hide", true) == 0) { hideIndex = i; item.Hide = true; break; } } } int flipIndex = -1; if (item.Character != null) { for (int i = 0; i < sayParams.Length; i++) { if (i != characterIndex && i != hideIndex && (string.Compare(sayParams[i], ">>>", true) == 0 || string.Compare(sayParams[i], "<<<", true) == 0)) { if (string.Compare(sayParams[i], ">>>", true) == 0) { item.FacingDirection = FacingDirection.Right; } if (string.Compare(sayParams[i], "<<<", true) == 0) { item.FacingDirection = FacingDirection.Left; } flipIndex = i; item.Flip = true; break; } } } // Next see if we can find a portrait for this character int portraitIndex = -1; if (item.Character != null) { for (int i = 0; i < sayParams.Length; i++) { if (item.Portrait == null && item.Character != null && i != characterIndex && i != hideIndex && i != flipIndex) { Sprite s = item.Character.GetPortrait(sayParams[i]); if (s != null) { portraitIndex = i; item.Portrait = s; break; } } } } // Next check if there's a position parameter Stage stage = Stage.GetActiveStage(); if (stage != null) { for (int i = 0; i < sayParams.Length; i++) { if (i != characterIndex && i != portraitIndex && i != hideIndex) { RectTransform r = stage.GetPosition(sayParams[i]); if (r != null) { item.Position = r; break; } } } } return(item); }
/// <summary> /// Using the string of say parameters before the ':', /// set the current character, position and portrait if provided. /// </summary> /// <returns>The conversation item.</returns> /// <param name="sayParams">The list of say parameters.</param> /// <param name="text">The text for the character to say.</param> /// <param name="currentCharacter">The currently speaking character.</param> protected virtual ConversationItem CreateConversationItem(string[] sayParams, string text, Character currentCharacter) { var item = new ConversationItem(); item.ClearPrev = ClearPrev; item.FadeDone = FadeDone; item.WaitForInput = WaitForInput; // Populate the story text to be written item.Text = text; if (WaitForSeconds > 0) { item.Text += "{w=" + WaitForSeconds.ToString() + "}"; } if (sayParams == null || sayParams.Length == 0) { // Text only, no params - early out. return(item); } //TODO this needs a refactor for (int i = 0; i < sayParams.Length; i++) { if (string.Compare(sayParams[i], "clear", true) == 0) { item.ClearPrev = true; } else if (string.Compare(sayParams[i], "noclear", true) == 0) { item.ClearPrev = false; } else if (string.Compare(sayParams[i], "fade", true) == 0) { item.FadeDone = true; } else if (string.Compare(sayParams[i], "nofade", true) == 0) { item.FadeDone = false; } else if (string.Compare(sayParams[i], "wait", true) == 0) { item.WaitForInput = true; } else if (string.Compare(sayParams[i], "nowait", true) == 0) { item.WaitForInput = false; } } // try to find the character param first, since we need to get its portrait int characterIndex = -1; int characterParamIndexPartial = characterIndex; Character partialCharacter = null; if (characters == null) { PopulateCharacterCache(); } for (int i = 0; item.Character == null && i < sayParams.Length; i++) { for (int j = 0; j < characters.Length; j++) { if (characters[j].NameMatch(sayParams[i])) { characterIndex = i; item.Character = characters[j]; break; } else if (characters[j].NameStartsWith(sayParams[i])) { characterParamIndexPartial = i; partialCharacter = characters[j]; } } } //if still no charcter was found but we found a partial we use it for backcompat but warn user if (item.Character == null && partialCharacter != null) { Debug.LogWarning("Conversation Manager Character Partial Match; found '" + sayParams[characterParamIndexPartial] + "' and will use " + partialCharacter.NameText + "\n Recommend modifying conversation and characters so they match exactly."); characterIndex = characterParamIndexPartial; item.Character = partialCharacter; } // Assume last used character if none is specified now if (item.Character == null) { item.Character = currentCharacter; } // Check if there's a Hide parameter int hideIndex = -1; if (item.Character != null) { for (int i = 0; i < sayParams.Length; i++) { if (i != characterIndex && string.Compare(sayParams[i], "hide", true) == 0) { hideIndex = i; item.Hide = true; break; } } } int flipIndex = -1; if (item.Character != null) { for (int i = 0; i < sayParams.Length; i++) { if (i != characterIndex && i != hideIndex && (string.Compare(sayParams[i], ">>>", true) == 0 || string.Compare(sayParams[i], "<<<", true) == 0)) { if (string.Compare(sayParams[i], ">>>", true) == 0) { item.FacingDirection = FacingDirection.Right; } if (string.Compare(sayParams[i], "<<<", true) == 0) { item.FacingDirection = FacingDirection.Left; } flipIndex = i; item.Flip = true; break; } } } // Next see if we can find a portrait for this character int portraitIndex = -1; if (item.Character != null) { for (int i = 0; i < sayParams.Length; i++) { if (item.Portrait == null && item.Character != null && i != characterIndex && i != hideIndex && i != flipIndex) { Sprite s = item.Character.GetPortrait(sayParams[i]); if (s != null) { portraitIndex = i; item.Portrait = s; break; } } } } // Next check if there's a position parameter Stage stage = Stage.GetActiveStage(); if (stage != null) { for (int i = 0; i < sayParams.Length; i++) { if (i != characterIndex && i != portraitIndex && i != hideIndex) { RectTransform r = stage.GetPosition(sayParams[i]); if (r != null) { item.Position = r; break; } } } } return(item); }
public virtual IEnumerator DoConversation(List <ConversationItem> conversationItems) { // Track the current and previous parameter values Character currentCharacter = null; Character.PortraitData currentPortrait = null; RectTransform currentPosition = null; RectTransform fromPosition = null; Character previousCharacter = null; // Play the conversation for (int i = 0; i < conversationItems.Count; ++i) { ConversationItem item = conversationItems[i]; string alt = CheckConditions(item.Condition); if (!string.IsNullOrEmpty(alt)) { CanvasManager.instance.Get <UILetterboxedDialogue>(UIPanelID.Dialogue).NextConvoID = alt; yield break; } if (item.Guest) { GameManager.Instance.AddGuest(); } if (item.Character != null) { currentCharacter = item.Character; if (item.Kill) { GameManager.Instance.SetDead(currentCharacter.gameObject.name, true); } if (item.Invite) { GameManager.Instance.SetInvited(currentCharacter.gameObject.name); } } if (item.PlayerKill) { GameManager.Instance.KillPlayer(); } currentPortrait = item.Portrait; currentPosition = item.ToPosition; fromPosition = item.FromPosition; var sayDialog = GetSayDialog(); if (sayDialog == null) { // Should never happen yield break; } sayDialog.SetActive(true); if (currentCharacter != null && currentCharacter != previousCharacter) { sayDialog.SetCharacter(currentCharacter); } //Handle stage changes var stage = Stage.GetActiveStage(); if (currentCharacter != null && !currentCharacter.State.onScreen && currentPortrait == null) { // No call to show portrait of hidden character // so keep hidden item.Hide = true; } if (stage != null && currentCharacter != null) { var portraitOptions = new PortraitOptions(true); portraitOptions.display = item.Hide ? DisplayType.Hide : DisplayType.Show; portraitOptions.character = currentCharacter; if (fromPosition == null) { portraitOptions.fromPosition = currentCharacter.State.position; } else { portraitOptions.fromPosition = fromPosition; } portraitOptions.toPosition = currentPosition; portraitOptions.portrait = currentPortrait; //Flip option - Flip the opposite direction the character is currently facing if (item.Flip) { portraitOptions.facing = item.FacingDirection; } // Do a move tween if the character is already on screen and not yet at the specified position if (currentPosition != currentCharacter.State.position) { portraitOptions.move = true; } if (item.Hide) { stage.Hide(portraitOptions); } else { stage.Show(portraitOptions); } } if (stage == null && currentPortrait != null) { sayDialog.SetCharacterImage(currentPortrait); } previousCharacter = currentCharacter; bool hasResponse = (item.ResponseLinks != null && item.ResponseLinks.Length > 0) || (item.ResponseTexts != null && item.ResponseTexts.Length > 0); if (!string.IsNullOrEmpty(item.Text)) { exitSayWait = false; sayDialog.Say(ReplaceVariableTokens(item.Text), item.ClearPreviousLine, !hasResponse, true, true, false, null, () => { exitSayWait = true; }); while (!exitSayWait) { yield return(null); } exitSayWait = false; } if (hasResponse) { bool exitChoice = false; string choice = ""; CanvasManager.instance.Get <UIDialogueOptions>(UIPanelID.DialogueOptions).Open(item.ResponseLinks, item.ResponseTexts, (string s) => { exitChoice = true; choice = s; }); while (!exitChoice) { yield return(null); } if (!string.IsNullOrEmpty(choice)) { CanvasManager.instance.Get <UILetterboxedDialogue>(UIPanelID.Dialogue).NextConvoID = choice; yield break; } } } }
/// <summary> /// Using the string of say parameters before the ':', /// set the current character, position and portrait if provided. /// </summary> /// <returns>The conversation item.</returns> /// <param name="sayParams">The list of say parameters.</param> /// <param name="text">The text for the character to say.</param> /// <param name="currentCharacter">The currently speaking character.</param> protected virtual ConversationItem CreateConversationItem(string[] sayParams, string text, Character currentCharacter, string[] links) { var item = new ConversationItem(); // Populate the story text to be written item.Text = text; item.ClearPreviousLine = true; if (links != null) { string[] linkSplit; List <string> responseList = new List <string>(); List <string> linkList = new List <string>(); for (int i = 0; i < links.Length; i++) { linkSplit = links[i].Split('='); if (!string.IsNullOrEmpty(linkSplit[0]) || !string.IsNullOrEmpty(linkSplit[1])) { linkList.Add(linkSplit[0]); responseList.Add(linkSplit[1]); } } if (linkList.Count > 0) { item.ResponseLinks = linkList.ToArray(); item.ResponseTexts = responseList.ToArray(); } } if (sayParams == null || sayParams.Length == 0) { // Text only, no params - early out. return(item); } // try to find the character param first, since we need to get its portrait int characterIndex = -1; for (int i = 0; item.Character == null && i < sayParams.Length; i++) { Character c = GetCharacter(sayParams[i]); if (c != null) { characterIndex = i; item.Character = c; break; } } // Assume last used character if none is specified now if (item.Character == null) { item.Character = currentCharacter; } for (int i = 0; i < sayParams.Length; i++) { if (sayParams[i].Contains("=")) { item.Condition = sayParams[i]; } if (sayParams[i] == "kill") { item.Kill = true; } if (sayParams[i] == "invite") { item.Invite = true; } if (sayParams[i] == "playerkill") { item.PlayerKill = true; } if (sayParams[i] == "guest") { item.Guest = true; } } // Check if there's a Hide parameter int hideIndex = -1; if (item.Character != null) { for (int i = 0; i < sayParams.Length; i++) { if (i != characterIndex && string.Compare(sayParams[i], "hide", true) == 0) { hideIndex = i; item.Hide = true; break; } } } int flipIndex = -1; if (item.Character != null) { for (int i = 0; i < sayParams.Length; i++) { if (i != characterIndex && i != hideIndex && (string.Compare(sayParams[i], ">>>", true) == 0 || string.Compare(sayParams[i], "<<<", true) == 0)) { if (string.Compare(sayParams[i], ">>>", true) == 0) { item.FacingDirection = FacingDirection.Right; } if (string.Compare(sayParams[i], "<<<", true) == 0) { item.FacingDirection = FacingDirection.Left; } flipIndex = i; item.Flip = true; break; } } } // Next see if we can find a portrait for this character int portraitIndex = -1; if (item.Character != null) { for (int i = 0; i < sayParams.Length; i++) { if (item.Portrait == null && item.Character != null && i != characterIndex && i != hideIndex && i != flipIndex) { Character.PortraitData p = item.Character.GetPortrait(sayParams[i]); if (p != null) { portraitIndex = i; item.Portrait = p; break; } } } } // Next check if there's a position parameter int pos1Index = -1; int pos2Index = -1; Stage stage = Stage.GetActiveStage(); if (stage != null) { for (int i = 0; i < sayParams.Length; i++) { if (i != characterIndex && i != portraitIndex && i != flipIndex && i != hideIndex) { RectTransform r = stage.GetPosition(sayParams[i]); if (r != null) { if (pos1Index == -1) { pos1Index = i; item.ToPosition = r; } else { pos2Index = i; item.FromPosition = item.ToPosition; item.ToPosition = r; break; } } } } } //check if we should clear or not for (int i = 0; i < sayParams.Length; i++) { if (i != characterIndex && i != portraitIndex && i != hideIndex && i != flipIndex && i != pos1Index && i != pos2Index) { if (string.Compare(sayParams[i], "noclear", true) == 0) { item.ClearPreviousLine = false; } } } return(item); }