Exemplo n.º 1
0
    /// <summary>
    /// Shows a line of dialogue, gradually.
    /// </summary>
    /// <param name="dialogueLine">The line to deliver.</param>
    /// <param name="onDialogueLineFinished">A callback to invoke when
    /// the text has finished appearing.</param>
    /// <returns></returns>
    protected IEnumerator DoRunLine(LocalizedLine dialogueLine, System.Action onDialogueLineFinished)
    {
        finishCurrentLine = false;

        // First, potentially change DialogueGroups
        Yarn.Markup.MarkupParseResult markupResult = TryParseCharacter(dialogueLine);

        // Then, prepare dialogue group for tweening, markup, etc
        onLineParse?.Invoke();

        // The final text we'll be showing for this line.
        string text = TryParseMarkup(markupResult);

        Sequence showAnimation = onLineStart.Invoke(text, textSpeed);
        var      frame         = new WaitForEndOfFrame();

        while (showAnimation != null && showAnimation.IsActive() && !showAnimation.IsComplete())
        {
            if (finishCurrentLine)
            {
                break;
            }
            yield return(frame);
        }

        // Indicate to the rest of the game that the text has finished
        // being delivered
        onTextFinishDisplaying?.Invoke();

        // Indicate to the dialogue runner that we're done delivering
        // the line here
        onDialogueLineFinished();
    }
Exemplo n.º 2
0
    public override void OnLineStatusChanged(LocalizedLine dialogueLine)
    {
        switch (dialogueLine.Status)
        {
        case LineStatus.Running:
            // No-op; this line is running
            break;

        case LineStatus.Interrupted:
            // The line is now interrupted, and we need to hurry up
            // in our delivery
            finishCurrentLine = true;
            break;

        case LineStatus.Delivered:
            // The line has now finished its delivery across all
            // views, so we can signal call our UnityEvent for it
            onLineFinishDisplaying?.Invoke();
            break;

        case LineStatus.Ended:
            // The line has now Ended. DismissLine will be called
            // shortly.
            onLineEnd?.Invoke();
            break;
        }
    }
Exemplo n.º 3
0
 public override void RunLine(LocalizedLine dialogueLine, Action onLineDeliveryComplete)
 {
     // Store the localised text in our CurrentLine property and
     // capture the completion handler so it can be called at
     // the correct moment later by the test system
     CurrentLine   = dialogueLine.Text.Text;
     lineDelivered = onLineDeliveryComplete;
 }
Exemplo n.º 4
0
 private Yarn.Markup.MarkupParseResult TryParseCharacter(LocalizedLine dialogueLine)
 {
     Yarn.Markup.MarkupParseResult markupResult = dialogueLine.Text;
     if (markupResult.TryGetAttributeWithName("character", out var attribute))
     {
         TextAttributeHandler.HandleAttribute(attribute, this);
         return(markupResult.DeleteRange(attribute));
     }
     return(markupResult);
 }
Exemplo n.º 5
0
        public override void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished)
        {
            // Try and get the character name from the line
            string characterName = dialogueLine.CharacterName;

            // if null, Update() will use the playerCharacter instead
            speakerCharacter = !string.IsNullOrEmpty(characterName) ? FindCharacter(characterName) : null;

            // IMPORTANT: we must mark this view as having finished its work, or else the DialogueRunner gets stuck forever
            onDialogueLineFinished();
        }
Exemplo n.º 6
0
        public override void OnLineStatusChanged(LocalizedLine dialogueLine)
        {
            switch (dialogueLine.Status)
            {
            case LineStatus.Interrupted:
                isLineInterrupted = true;
                break;

            default:
                // no-op; we don't care about other states in this mock
                // view
                break;
            }
        }
        public override void RunLine(LocalizedLine dialogueLine, System.Action onDialogueLineFinished)
        {
            var actorName = dialogueLine.CharacterName;

            if (string.IsNullOrEmpty(actorName) == false && actors.ContainsKey(actorName))
            {
                HighlightSprite(actors[actorName].actorImage);
                nameplateBG.color = actors[actorName].actorColor;
                nameplateBG.gameObject.SetActive(true);
            }
            else
            {
                nameplateBG.gameObject.SetActive(false);
            }

            onDialogueLineFinished();
        }
Exemplo n.º 8
0
        public override void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished)
        {
            // Try and get the character name from the line
            var hasCharacterName = dialogueLine.Text.TryGetAttributeWithName("character", out var characterAttribute);

            if (hasCharacterName)
            {
                speakerCharacter = FindCharacter(characterAttribute.Properties["name"].StringValue);
            }
            else
            {
                speakerCharacter = null; // if null, Update() will use the playerCharacter instead
            }

            // IMPORTANT: we must mark this view as having finished its work, or else the DialogueRunner gets stuck forever
            onDialogueLineFinished();
        }
Exemplo n.º 9
0
        public override void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished)
        {
            if (currentTypewriterEffect != null)
            {
                StopCoroutine(currentTypewriterEffect);
            }

            CloneMessageBoxToHistory();

            text.text = dialogueLine.TextWithoutCharacterName.Text;;

            currentTypewriterEffect = StartCoroutine(Effects.Typewriter(text, 10f, null, null, () =>
            {
                currentTypewriterEffect = null;
                onDialogueLineFinished();
            }));
        }
Exemplo n.º 10
0
        public override void OnLineStatusChanged(LocalizedLine dialogueLine)
        {
            switch (dialogueLine.Status)
            {
            case LineStatus.Running:
                break;

            case LineStatus.Interrupted:
                interrupt = true;
                break;

            case LineStatus.Delivered:
                break;

            case LineStatus.Ended:
                break;
            }
        }
Exemplo n.º 11
0
        public override void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished)
        {
            lineText.gameObject.SetActive(true);
            contentContainer.gameObject.SetActive(true);

            interrupt = false;

            lineText.text = dialogueLine.TextWithoutCharacterName.Text;

            string characterName = dialogueLine.CharacterName;

            if (characterName != null)
            {
                lineText.color = GetColorForCharacter(characterName);
            }

            StartCoroutine(FadeContent(0, 1, onDialogueLineFinished));
        }
Exemplo n.º 12
0
        public override void RunLine(LocalizedLine dialogueLine, Action onLineDeliveryComplete)
        {
            // Store the localised text in our CurrentLine property and
            // signal that we're done "delivering" the line after the
            // correct amount of time
            CurrentLine = dialogueLine.RawText;

            isLineInterrupted = false;

            if (simulatedLineDeliveryTime > 0)
            {
                StartCoroutine(SimulateLineDelivery(onLineDeliveryComplete));
            }
            else
            {
                onLineDeliveryComplete();
            }
        }
Exemplo n.º 13
0
    public override void OnLineStatusChanged(LocalizedLine dialogueLine)
    {
        switch (dialogueLine.Status)
        {
        case LineStatus.Presenting:
            break;

        case LineStatus.Interrupted:
            // We have been interrupted. Set our interruption flag,
            // so that any animations get skipped.
            interruptionFlag.Set();
            break;

        case LineStatus.FinishedPresenting:
            // The line has finished being delivered by all views.
            StartCoroutine(WaitForSeconds(2f, ReadyForNextLine));
            break;

        case LineStatus.Dismissed:
            break;
        }
    }
Exemplo n.º 14
0
 public override void OnLineStatusChanged(LocalizedLine dialogueLine)
 {
     // for YarnCharacterView, we don't care about this, so do nothing
 }
Exemplo n.º 15
0
 /// <inheritdoc/>
 public override void RunLine(LocalizedLine dialogueLine, System.Action onDialogueLineFinished)
 {
     StartCoroutine(DoRunLine(dialogueLine, onDialogueLineFinished));
 }
Exemplo n.º 16
0
 public override void InterruptLine(LocalizedLine dialogueLine, Action onDialogueLineFinished)
 {
     onDialogueLineFinished();
 }
Exemplo n.º 17
0
    public override void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished)
    {
        if (textBoxPrefab)
        {
            Transform textboxTransform = Instantiate(textBoxPrefab, transform).transform;
            if (dialogueLine.CharacterName == "Skelly")
            {
                textboxTransform.localScale             = new Vector3(-1, 1, 1);
                textboxTransform.GetChild(0).localScale = new Vector3(-1, 1, 1);
            }
            lineText = textboxTransform.GetComponentInChildren <TextMeshProUGUI>();
            currentLineCanvasGroup = textboxTransform.GetComponent <CanvasGroup>();
        }

        canvasGroup.gameObject.SetActive(true);

        interruptionFlag.Clear();

        if (characterNameText == null)
        {
            if (showCharacterNameInLineView)
            {
                lineText.text = dialogueLine.Text.Text;
            }
            else
            {
                lineText.text = dialogueLine.TextWithoutCharacterName.Text;
            }
        }
        else
        {
            characterNameText.text = dialogueLine.CharacterName;
            lineText.text          = dialogueLine.TextWithoutCharacterName.Text;
        }

        if (useFadeEffect)
        {
            if (useTypewriterEffect)
            {
                // If we're also using a typewriter effect, ensure that
                // there are no visible characters so that we don't
                // fade in on the text fully visible
                lineText.maxVisibleCharacters = 0;
            }
            else
            {
                // Ensure that the max visible characters is effectively unlimited.
                lineText.maxVisibleCharacters = int.MaxValue;
            }

            // Fade up and then call FadeComplete when done
            StartCoroutine(Effects.FadeAlpha(currentLineCanvasGroup, 0, 1, fadeInTime, () => FadeComplete(onDialogueLineFinished), interruptionFlag));
        }
        else
        {
            // Immediately appear
            canvasGroup.interactable   = true;
            canvasGroup.alpha          = 1;
            canvasGroup.blocksRaycasts = true;

            if (useTypewriterEffect)
            {
                // Start the typewriter
                StartCoroutine(Typewriter(lineText, typewriterEffectSpeed, onDialogueLineFinished, interruptionFlag));
            }
            else
            {
                onDialogueLineFinished();
            }
        }
    }