Make dialogue add onto paragraph, rather than adding another line.

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
s_cargo
Posts: 2
Joined: Thu Jan 12, 2023 8:55 am

Make dialogue add onto paragraph, rather than adding another line.

Post by s_cargo »

I'm creating visual novel right now and have been troubleshooting trying to find a way to make the dialogue display in a way that it adds to a paragraph with each advancement of dialogue, rather than displaying as a new line.

Here is what it looks like now with my conversation's dialogue displaying as a new line, one at a time:
Image

Here is what I am trying to get it to look like with each advancement of dialogue:
Image

I was only able to do this manually changing the dialogue printed in the Subtitle Text, but I'm wondering if there's a way to automate it so it displays like this. Any help is appreciated, and thanks in advanced.
User avatar
Tony Li
Posts: 21962
Joined: Thu Jul 18, 2013 1:27 pm

Re: Make dialogue add onto paragraph, rather than adding another line.

Post by Tony Li »

Hi,

Make a subclass of StandardUISubtitlePanel and use the subclass in place of your dialogue UI's regular StandardUISubtitlePanel component. Override SetSubtitleTextContent to add a space between the old text and new text instead of a newline. Here's a script that does that:

ParagraphSubtitlePanel .cs

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace PixelCrushers.DialogueSystem
{
    public class ParagraphSubtitlePanel : StandardUISubtitlePanel
    {
        protected override void SetSubtitleTextContent(Subtitle subtitle)
        {
            TypewriterUtility.StopTyping(subtitleText);
            var previousText = accumulateText ? accumulatedText : string.Empty;
            if (accumulateText && !string.IsNullOrEmpty(subtitle.formattedText.text))
            {
                if (numAccumulatedLines < maxLines)
                {
                    numAccumulatedLines++;
                }
                else
                {
                    // If we're at the max number of lines, remove the first line from the accumulated text:
                    previousText = previousText.Substring(previousText.IndexOf("\n") + 1);
                }
            }
            var previousChars = accumulateText ? UITools.StripRPGMakerCodes(Tools.StripTextMeshProTags(Tools.StripRichTextCodes(previousText))).Length : 0;
            SetFormattedText(subtitleText, previousText, subtitle.formattedText);
            if (accumulateText) accumulatedText = subtitleText.text + " "; // <<< CHANGED THIS LINE
            if (scrollbarEnabler != null && !HasTypewriter())
            {
                scrollbarEnabler.CheckScrollbarWithResetValue(0);
            }
            else if (delayTypewriterUntilOpen && !hasFocus)
            {
                DialogueManager.instance.StartCoroutine(StartTypingWhenFocused(subtitleText, subtitleText.text, previousChars));
            }
            else
            {
                TypewriterUtility.StartTyping(subtitleText, subtitleText.text, previousChars);
            }
        }
    }
}
I just copied the original SetSubtitleTextContent method's code and changed the line that adds the newline into one that adds a space.
s_cargo
Posts: 2
Joined: Thu Jan 12, 2023 8:55 am

Re: Make dialogue add onto paragraph, rather than adding another line.

Post by s_cargo »

Hey, thanks for the quick response. The code you gave me works, but curiously I cannot set the max limit for accumlated text anymore, despite it being enabled. I want to make it so that when the paragraph hits the max number of lines, the text clears, and begins printing from the next line of dialogue.
User avatar
Tony Li
Posts: 21962
Joined: Thu Jul 18, 2013 1:27 pm

Re: Make dialogue add onto paragraph, rather than adding another line.

Post by Tony Li »

Hi,

You'll need to modify the script to do that. Currently the "max lines" logic works by newlines, but the script above adds spaces instead of newlines.

For example, in addition to maintaining numAccumulatedLines, you could keep a List<string> of the lines that you've added to the paragraph. When you reach numAccumulatedLines, you could delete the first list element's text from the beginning of the subtitle panel's accumulatedText and delete the element from the list.
Post Reply