public PortraitOptions(bool useDefaultSettings = true) { character = null; replacedCharacter = null; portrait = null; display = DisplayType.None; offset = PositionOffset.None; fromPosition = null; toPosition = null; facing = FacingDirection.None; shiftOffset = new Vector2(0, 0); move = false; shiftIntoPlace = false; waitUntilFinished = true; onComplete = null; // Special values that can be overridden fadeDuration = 0.5f; moveDuration = 1f; this.useDefaultSettings = useDefaultSettings; }
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> /// Sets the character image to display on the Say Dialog. /// </summary> public virtual void SetCharacterImage(Character.PortraitData portrait) { //this is handled by the Stage now primarily, but if we ever wanted to do something in the say dialog itself we could here, I guess. }
/// <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); }
public abstract void SetPortrait(Character.PortraitData portrait);