Page 1 of 1
How to make player to speak in another color then NPCs
Posted: Sat Dec 11, 2021 12:15 pm
by Maltakreuz
I am using UI with accumulate text, so i want to make NPC subtitles and Player subtitles to be in slightly different colors. One possibility i found is to use DialogueActor-Component on NPC with custom color. But this have two downsides. It is tedious and error prone to add such component for every NPC. And I have
Code: Select all
AddSpeakerNameFormat = <color=#ECBE30>{0}:</color> {1}
, so applyColorToPrependedName does not work for me.
One straightforward option is just hardcode what i want into StandardUISubtitleControls. Of course if i update DialogueSys, i need to "repatch" it again. Is any better solutions to make dialogues player/npc in two colors? (with colored names too).
Can i add DialogueActor to the Player itself? Or is any other option to adjust colors available?
upd: Somehow i can not add Hook from my own namespace in StandardUISubtitleControls - probably it is a different Assembly.
Re: How to make player to speak in another color then NPCs
Posted: Sat Dec 11, 2021 1:14 pm
by Maltakreuz
I ened up with following solution:
Code: Select all
public class StandardUISubtitleControls : AbstractUISubtitleControls
{
#region patched
const string PLAYER_TEXT_CLR = "#E5BD8C"; // #a69076 // #E5BD8C // #C8975B
const string PLAYER_NAME_CLR = "#f5cd5f"; // #f29924
/// <summary>
/// To make Player and NPC in different colors
/// </summary>
public static void ColorizeSubtitleHook(Subtitle subtitle) {
if (!subtitle.speakerInfo.IsPlayer) {
return;
}
Color clr = Color.white;
ColorUtility.TryParseHtmlString(PLAYER_TEXT_CLR, out clr);
string txt = UITools.WrapTextInColor(subtitle.formattedText.text, clr);
subtitle.formattedText.text = txt;
}
#endregion
...
public override void ShowSubtitle(Subtitle subtitle)
{
...
#region patched
string format = panel.addSpeakerNameFormat;
if (subtitle.speakerInfo.isPlayer) {
format = "<color=" + PLAYER_NAME_CLR + ">{0}:</color> {1}";
}
subtitle.formattedText.text = string.Format(format, new object[] { subtitle.speakerInfo.Name, subtitle.formattedText.text });
#endregion
...
#region patched
ColorizeSubtitleHook(subtitle);
#endregion
...
Hopefully this is not overcomplicated way to make pretty simple task. But if no-coding simple solution exists i would like to know.
Re: How to make player to speak in another color then NPCs
Posted: Sat Dec 11, 2021 1:48 pm
by Tony Li
Hi,
There's no need to directly modify StandardUISubtitleControls. Add a new script to the Dialogue Manager that has an
OnConversationLine(Subtitle) method. Example:
Code: Select all
public class ColorizeSubtitles : MonoBehaviour
{
const string PLAYER_TEXT_CLR = "#E5BD8C"; // #a69076 // #E5BD8C // #C8975B
const string PLAYER_NAME_CLR = "#f5cd5f"; // #f29924
void OnConversationLine(Subtitle subtitle)
{
string format = panel.addSpeakerNameFormat;
if (subtitle.speakerInfo.isPlayer)
{
format = "<color=" + PLAYER_NAME_CLR + ">{0}:</color> {1}";
}
subtitle.formattedText.text = string.Format(format, new object[] { subtitle.speakerInfo.Name, subtitle.formattedText.text });
if (subtitle.speakerInfo.isPlayer)
{
Color clr = Color.white;
ColorUtility.TryParseHtmlString(PLAYER_TEXT_CLR, out clr);
string txt = UITools.WrapTextInColor(subtitle.formattedText.text, clr);
subtitle.formattedText.text = txt;
}
}
}
Re: How to make player to speak in another color then NPCs
Posted: Sun Dec 12, 2021 11:09 am
by Maltakreuz
Thank you, with broadcast-hook it would be cleaner and less problematic in case of Dialogue-Sys-Update.
But unfortunately i want to colorize Name too, and color-choose-if still done in StandardUISubtitleControls. Of course i could colorize names somehow different then with format-string. So i will keep this quick and dirty solution for now

Re: How to make player to speak in another color then NPCs
Posted: Sun Dec 12, 2021 11:25 am
by Tony Li
Okay. If you don't want to do that in the future, you can untick the panel's addSpeakerNameFormat and do it yourself in an OnConversationLine method instead. Or untick it and make a subclass of StandardUISubtitlePanel that does it.