How to add own messages to subtitle panel

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Maltakreuz
Posts: 40
Joined: Sat Jul 25, 2015 2:36 pm

How to add own messages to subtitle panel

Post by Maltakreuz »

I am making an rpg game and want to add some alert-like messages direct in dialogue subtitle. For example like this:

Code: Select all

Npc: Hello
Player: Quest is done!
Npc: Very well
*party gained 1147 gold*
*party recieved 358753 exp*
Player: Farewell
I just referenced my text-component (textmeshpro) and tryed to add text just with subtitle_comp.text += "my msg\n"; but this does not work. How can i achieve this?
Maltakreuz
Posts: 40
Joined: Sat Jul 25, 2015 2:36 pm

Re: How to add own messages to subtitle panel

Post by Maltakreuz »

upd: it works if i just adjust text in inspector, but after i click some response, the subtitle seems to be completly rewritten and my message get lost.

I use wrpg/runic style subtitles, that consume all previous text.
User avatar
Tony Li
Posts: 22050
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to add own messages to subtitle panel

Post by Tony Li »

Hi,

Here are three ways you can do it:

1. Add the message to your conversation as a dialogue entry node. Then it will be added to the UI like any other node. You can use [var=variable] tags if the values are variable, such as:

Code: Select all

// C# code to set gold amount:
DialogueLua.SetVariable("gold", 1147);
  • Dialogue Text: "*party gained [var=gold] gold*"
2. Or make a Subtitle object at runtime and add it to the UI. Example:

Code: Select all

var speakerInfo = DialogueManager.conversationModel.conversantInfo; // May want to use different CharacterInfo objects.
var listenerInfo = DialogueManager.conversationModel.actorInfo;
var subtitle = new Subtitle(speakerInfo, listenerInfo, FormattedText.Parse("*party gained 1147 gold*"), null, null, null);
var ui = DialogueManager.dialogueUI as StandardDialogueUI;
ui.conversationUIElements.defaultNPCSubtitlePanel.ShowSubtitle(subtitle);
3. Or manually add text to the subtitle panel's accumulatedText property. Example:

Code: Select all

var ui = DialogueManager.dialogueUI as StandardDialogueUI;
var panel = ui.conversationUIElements.defaultNPCSubtitlePanel;
panel.accumulatedText += "*party gained 1147 gold*\n";
panel.subtitleText.text = panel.accumulatedText;
(Edit: Moved \n to end of line.)
Maltakreuz
Posts: 40
Joined: Sat Jul 25, 2015 2:36 pm

Re: How to add own messages to subtitle panel

Post by Maltakreuz »

Tony Li wrote: Wed Dec 09, 2020 8:17 am
Great! All three ways are pretty good. I probably use solution 3, it is somehow simplier then 2.

The first is OK too, but I do not really want to add standard messages to every side quest npc dialogue again and again. Thank you very much!

in case someone will find this topic in google: in last solution "\n" should stay after msg, not before.
User avatar
Tony Li
Posts: 22050
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to add own messages to subtitle panel

Post by Tony Li »

Glad to help! (I'll also update my example code to move the \n.)
Post Reply