Some questions regarding WRPG UI functionality

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
karterAKA
Posts: 5
Joined: Tue Aug 09, 2022 7:21 pm

Some questions regarding WRPG UI functionality

Post by karterAKA »

First of all, thanks so much for putting this wonderful package together! It has helped my workflow so much already, so much great functionality and the support here seems great.

I am working on a fairly simple text-adventure game. Most of my scenes are just Narrator/Player dialogue with some decorations. I love the Disco Elysium esque look of the WRPG UI, but I'm having a couple issues with it which I haven't been able to figure out on my own.

1. First and foremost, I seem to be running into problems with mesh rendering. I'm working on one scene which isn't terribly long, conversation looks like this:


It's not terribly long, but I run into errors when I get towards the end. When continuing through the second-to-last node in the longest branch, the typewriter effect cuts off, skips the final node entirely, and I get this error:


Interestingly, this didn't happen until I added a continue button.

I've searched around and as best I can tell the issue is it's trying to render more characters than Unity can handle within that one scrolling Subtitle mesh. I've tried a couple workarounds, including the ones suggested here: https://www.pixelcrushers.com/phpbb/vie ... ces#p18345, but neither seem to be working for me. The script to trim the existing text once it reaches some character limit works, but it chops off the bottom of the existing text rather than the top, so it ends up looking confusing. Maybe modifying that script would work, or maybe there's some way to instantiate the existing text past a certain point so it isn't rendering all that text as one GameObject? I love the ability to scroll back up through the previous text, it's a great feature, so I'd hate to have to break things into smaller subtitle panels.


2. My second question is also I think related to the fact that the WRPG UI prints all subtitles into one panel. I'd really like a way to customize the Player responses in a consistent format in all nodes and conversations, but still printing them in the scroll panel. I was able to use the DialogueActor component in a Player prefab to customize the color like so:


Which is great! But I'd love a way to also adjust bold/italics, alignment, font size, etc. without manually putting emphasis tags in every single node. Is there a smooth way to go about this, or would I need to script a custom DialogueActor subclass? I was thinking of giving it a shot but figured I should ask if this functionality already exists first.

Thanks so much for reading, and in advance for any help I can get with these.
User avatar
Tony Li
Posts: 21973
Joined: Thu Jul 18, 2013 1:27 pm

Re: Some questions regarding WRPG UI functionality

Post by Tony Li »

Hi,

Thanks for using the Dialogue System!

Since you mentioned the Disco Elysium-esque look, you might also be interested in the Scrolling Dialogue UI prefab located in the Pro folder. It has the same character limitation, though, so you'll want to read below.

As an alternative to this post in the thread you cited, you can also limit it by lines: How To: Limit Text Length With Accumulate Text Option

To apply different styling to player subtitle text, you can expand the method in that How To article. You can apply rich text codes or [em#] emphasis settings. Here's an example of modifying the How to article's script to also apply an emphasis setting to player text. You can customize how emphasis settings look in the Dialogue Editor's Database section.

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class LimitSubtitleTextLengthAndFormatPlayer : MonoBehaviour
{
    public EmTag emTagForPlayerText;
    
    public int maxLines = 50;

    private int numLines;

    void OnConversationStart(Transform actor)
    {
        // When we start a conversation, reset the line count.
        numLines = 0;
    }

    void OnConversationLine(Subtitle subtitle)
    {
        if (string.IsNullOrEmpty(subtitle.formattedText.text)) return;
        
        // If it's a player line, apply emphasis setting:
        if (subtitle.speakerInfo.isPlayer && emTagForPlayerText != EmTag.None)
        {
            int emNum = (int)emTagForPlayerText;
            subtitle.formattedText = FormattedText.Parse($"[em{emNum}]{subtitle.formattedText.text}[/em{emNum}]");
        }
        
        if (numLines < maxLines)
        {
            numLines++;
        }
        else
        {
            // If we're at the max number of lines, remove the first line from the accumulated text:
            var subtitlePanel = DialogueManager.standardDialogueUI.conversationUIElements.defaultNPCSubtitlePanel;
            subtitlePanel.accumulatedText = subtitlePanel.accumulatedText.Substring(subtitlePanel.accumulatedText.IndexOf("\n") + 1);
        }
    }
}
karterAKA
Posts: 5
Joined: Tue Aug 09, 2022 7:21 pm

Re: Some questions regarding WRPG UI functionality

Post by karterAKA »

Thanks for the speedy reply!

So, for whatever reason, the script you linked to trim lines off the top of the subtitle didn't work for me. I tried attaching it to the DialogueManager, the Subtitle Panel Info child object, and the Subtitle Text child too, and it didn't seem to have any effect at all when playtesting. Not sure why. I'm using Adventure Creator with the DE bridge on my Dialogue Manager, for what it's worth.

Switching to TextMeshPro seems to have fixed the "too many vertices" problem, but now I have a ton of other problems, because TMP seems very, uh, user-hostile and I can't even get text color to show up properly in playtesting. I guess I can try to figure out TMP for now, since it does at least seem to allow for a larger/more complex mesh.

Let me know if you have any other ideas or tips for either getting the Line-limit script working or getting going with TMP. Are there any resources for using TMP with DE aside from the setup instructions in the manual here? https://www.pixelcrushers.com/dialogue_ ... ProSupport

Thanks so much again!
User avatar
Tony Li
Posts: 21973
Joined: Thu Jul 18, 2013 1:27 pm

Re: Some questions regarding WRPG UI functionality

Post by Tony Li »

Here's an example scene:

DS_LineLimitedScrollingExample_2022-08-10.unitypackage

In this example, I named the script differently so it won't conflict with the script in your project. If you play the scene, you should see that it limits the text to 8 lines. The scene uses TMPro, but the script works fine with UI Text, too.
karterAKA
Posts: 5
Joined: Tue Aug 09, 2022 7:21 pm

Re: Some questions regarding WRPG UI functionality

Post by karterAKA »

Awesome, thanks so much for the help.

I've had a little more success figuring out the TMP Text UI so I think everything is pretty close to doing what I want.

I have one follow up on my second question - Can you point me to some syntax or anywhere to help me get started scripting some more customization to Player subtitles? I'd really like to be able to control text size, alignment, etc.; things that aren't available in emphasis tags. I've tried extending the DialogueActor's "Subtitle Color" script but not finding this functionality in the Subtitle class, and struggling to marry the script with e.g. TMPro formatting scripts. Pretty new to both plugins and scripting in general, so any help is greatly appreciated.

Thanks again!
User avatar
Tony Li
Posts: 21973
Joined: Thu Jul 18, 2013 1:27 pm

Re: Some questions regarding WRPG UI functionality

Post by Tony Li »

You could extend the script in that example scene above. The OnConversationLine() method already manipulates the text (subtitle.formattedText.text). The Dialogue System also has a UITools class with handy methods such as UITools.WrapTextInColor().

Since you're using TextMesh Pro, you can add any TextMesh Pro rich text tags such as <indent> and <size>. In addition, you might be interested in using Text Animator for Unity (DS integration). It works on top of TextMesh Pro to provide some really fancy animation and text effects.
karterAKA
Posts: 5
Joined: Tue Aug 09, 2022 7:21 pm

Re: Some questions regarding WRPG UI functionality

Post by karterAKA »

So, how can I call/customize TMPro settings within the Subtitle class (sorry if this is a basic coding question and not DE specific). I tried extending the script you provided to include a toggle for alignment options like so:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;
using TMPro;

public class CustomizePlayerLines : MonoBehaviour
{
    public EmTag emTagForPlayerText;
    public TextAlignmentOptions PlayerTextAlignment; // adds TMPro alignment options to customize for Player lines

    void OnConversationLine(Subtitle subtitle)
    {
        if (string.IsNullOrEmpty(subtitle.formattedText.text)) return;

        // If it's a player line, apply emphasis setting:
        if (subtitle.speakerInfo.isPlayer && emTagForPlayerText != EmTag.None)
        {
            int emNum = (int)emTagForPlayerText;
            subtitle.formattedText = FormattedText.Parse($"[em{emNum}]{subtitle.formattedText.text}[/em{emNum}]");
        }
        if (subtitle.speakerInfo.isPlayer)
        {
        // here i am trying to set the alignment options for Player subtitles, but can't figure out the syntax
            GetComponent<TextMeshPro>().alignment = PlayerTextAlignment;
        }
    }
}
But I can't seem to get the interface right. Been looking through the documentation but I can't find a clear method. Should I just use rich text? And if so how do I work that into the subtitle.formattedText lines? (Tried a few ways but getting stuck in syntax errors).

Thanks again!
User avatar
Tony Li
Posts: 21973
Joined: Thu Jul 18, 2013 1:27 pm

Re: Some questions regarding WRPG UI functionality

Post by Tony Li »

Hi,

Since the NPC and player text is in the same TextMeshProUGUI component, you won't want to change the alignment for the whole component. Instead, use and <align> rich text tag to change the alignment only for the player text part.

Try changing these lines:

Code: Select all

public TextAlignmentOptions PlayerTextAlignment; // adds TMPro alignment options to customize for Player lines
and

Code: Select all

if (subtitle.speakerInfo.isPlayer)
{
    // here i am trying to set the alignment options for Player subtitles, but can't figure out the syntax
    GetComponent<TextMeshPro>().alignment = PlayerTextAlignment;
}
to:

Code: Select all

public string alignment = "right"; // Set to left, center, or right.
and

Code: Select all

if (subtitle.speakerInfo.Player)
{
    subtitle.formattedText.text = $"<align=\"{alignment}\">{subtitle.formattedText.text}</align>";
}
karterAKA
Posts: 5
Joined: Tue Aug 09, 2022 7:21 pm

Re: Some questions regarding WRPG UI functionality

Post by karterAKA »

Brilliant, this did the trick. I was close! Just didn't quite have the right syntax in mind....still much to learn!

Thanks so much for the help, really appreciate it.
User avatar
Tony Li
Posts: 21973
Joined: Thu Jul 18, 2013 1:27 pm

Re: Some questions regarding WRPG UI functionality

Post by Tony Li »

Happy to help!
Post Reply