Page 1 of 1

Custom Markup Tags?

Posted: Fri Oct 25, 2024 5:56 am
by DarkProphet
Is it possible to create custom Lua markup tags like [auto] and [f]?
Essentially I'm currently using Rich Text Tags to insert sprites into my Response buttons, such as <sprite name="prayer">.
It's working fine, but I would love a less verbose solution, something like [prayer].

If not possible, is there another solution that would suit the following needs:
- Need custom response buttons or button icons that can easily be assigned to dialogue response entries.
- If custom buttons, need to be able to use same button look for multiple possible entries (so I believe static [position] references would not work)
- Ideally, if the response entries could also have a custom color assigned in the Conversation node editor, that would make troubleshooting at a glance much easier!

Re: Custom Markup Tags?

Posted: Fri Oct 25, 2024 7:08 am
by Tony Li
Hi,

You can add a script with OnConversationLine and OnConversationResponseMenu special methods to the Dialogue Manager. Example:

Code: Select all

void OnConversationLine(Subtitle subtitle)
{
    subtitle.formattedText.text = ReplaceSpecialMarkupTags(subtitle.formattedText.text);
}
void OnConversationResponseMenu(Response[] responses)
{
    foreach (var response in responses)
    {
        response.formattedText.text = ReplaceSpecialMarkupTags(response.formattedText.text);
    }
}
string ReplaceSpecialMarkupTags(string text)
{
    return text.Replace("[prayer]", "<sprite name=\"prayer\">");
}

Re: Custom Markup Tags?

Posted: Fri Oct 25, 2024 9:29 am
by DarkProphet
Nice one.
I implemented this, however, the text.Replace function seems to not be working.
The events fire (Debug.Log outputs the text from ReplaceSpecialMarkupTags(), but Replace never does any actual replacing.
I've tried it with multiple different words, even single letters. Replace() seems to just return the initial string, unchanged. :?:

Re: Custom Markup Tags?

Posted: Fri Oct 25, 2024 10:10 am
by Tony Li
Hi,

Here's an example scene:

DS_TestReplaceTags_2024-10-25.unitypackage

It replaces "[friend]" with the string "good old buddy old pal".

Re: Custom Markup Tags?

Posted: Fri Oct 25, 2024 10:35 am
by DarkProphet
Thanks,
I figured out what was wrong.
I had multiple lines of replace and forgot to assign the text back to itself like this:

Code: Select all

text = text.Replace("[key]", "replaced key");
text = text.Replace("[other]", "replaced other");
return text;
I was just going:

Code: Select all

text.Replace("[code]", "replaced text")
return text;
which just returned the original text with no replacement.

Re: Custom Markup Tags?

Posted: Fri Oct 25, 2024 12:03 pm
by Tony Li
I can vouch from personal experience that you're not the first to do that. ;)