Select conversation in UI like messages

Announcements, support questions, and discussion for the Dialogue System.
schmoey
Posts: 6
Joined: Thu Nov 12, 2020 11:52 am

Select conversation in UI like messages

Post by schmoey »

Hi!

Apologies if this has been covered already, I tried looking around the forum / docs for quite a while first!

I'm trying to basically emulate a message system, like any messaging app, social media DMs etc... where I can retrieve and display all the conversations at once. I'll show each with a shorter version in one panel, probably the name of the conversation or something to represent it, then as I select each one I want to show the full history of the conversation in another panel.

For the full history display I'll probably use something like the SMS dialogue UI panel!

Anything you can do to point me in the right direction would be very much appreciated.

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

Re: Select conversation in UI like messages

Post by Tony Li »

Hi,

You can code up something to handle the panel that shows all the conversations, and use the SMS Dialogue UI to play whichever conversation the player selects.

Alternatively, look into the Textline project available on the Dialogue System Extras page. It works similarly to the SMS Dialogue UI (the SMS Dialogue UI's script is actually based on Textline's) but it also has a start screen and a "lobby" page that lists the available conversations.
schmoey
Posts: 6
Joined: Thu Nov 12, 2020 11:52 am

Re: Select conversation in UI like messages

Post by schmoey »

Ok cool cheers!

I should be able to pull apart the textline demo and get something working! I'll holler if I can't figure something out, but I guess as lord of the forum you already knew that :roll: :lol:

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

Re: Select conversation in UI like messages

Post by Tony Li »

Glad to help! BTW, check the Textline PDF for instructions on the Lobby scene. The basic example doesn't use it, but there's a sub-example that does.
Alex95
Posts: 6
Joined: Tue Mar 23, 2021 8:13 pm

Re: Select conversation in UI like messages

Post by Alex95 »

Hello! I realize this is an older thread, but I have a similar query.
I would like to create a menu where the player can click a contact's name, which transitions to either the scrolling or SMS dialogue UI, where the player can converse with the chosen NPC contact. I looked at the Textline demo, but the documentation states that the contact list/lobby should be in a separate scene.
The solution that was given by Tony seems promising:
"You can code up something to handle the panel that shows all the conversations, and use the SMS Dialogue UI to play whichever conversation the player selects."
I assume this means that the panels have buttons that trigger SMS dialogue UI to appear? Could I get more info on how to do that? (just a brief blurb, no need to go into detail)
Alternately, I was wondering if it was possible to use a response menu option of one of the Dialogue System panels such as the Computer UI panel to trigger the SMS dialogue UI. Not sure if there are LUA commands that you can employ here in the "Script" field of the conversation entry. I want to be able to add more contacts easily.
Let me know if I am completely off-base! I am new to the system, and am still trying to figure things out.
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Select conversation in UI like messages

Post by Tony Li »

Hi,

Yes, you could use a conversation to select another conversation.

As a first step, I recommend doing it all with the same dialogue UI, such as the Basic Standard Dialogue UI.

Let's say the first conversation is titled "Contacts" and each NPC contact has a conversation titled "NPC A", "NPC B", "NPC C", etc.

In the Contacts conversation, show a menu of conversation titles (one title per response node: NPC A, NPC B, etc.). In each response node, set a variable "ChosenContact" to the NPC's conversation title. Example:
  • Dialogue Text: "Chat with NPC A"
  • Script: Variable["ChosenContact"] = "NPC A"
Add a script to the Dialogue Manager that has OnConversationStart and OnConversationEnd methods. In OnConversationStart, set the ChosenContact variable to a blank string. In OnConversationEnd, check if the variable has been set to a conversation title; if so, start that conversation. Example:
Spoiler

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class ContactSelectionHandler : MonoBehaviour
{
    // When a conversation starts, reset the ChosenContact variable:
    void OnConversationStart(Transform actor)
    {
        DialogueLua.SetVariable("ChosenContact", string.Empty);
    }
    
    // When a conversation ends, check if ChosenContact was set. If so, start the NPC conversation:
    void OnConversationEnd(Transform actor)
    {
        string chosenContact = DialogueLua.GetVariable("ChosenContact").asString;
        if (!string.IsNullOrEmpty(chosenContact))
        {
            DialogueManager.StartConversation(chosenContact);
        }
    }
}
---

The second part is to use different dialogue UIs. One way to do this is to assign a different dialogue UI to the Dialogue Manager. You can build on the script above:
Spoiler

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class ContactSelectionHandler : MonoBehaviour
{
    // Assign these in the inspector:
    public StandardDialogueUI computerUI;
    public StandardDialogueUI smsUI; 
    
    // When a conversation starts, reset the ChosenContact variable:
    void OnConversationStart(Transform actor)
    {
        DialogueLua.SetVariable("ChosenContact", string.Empty);
    }
    
    // When a conversation ends, check if ChosenContact was set. If so, start the NPC conversation:
    void OnConversationEnd(Transform actor)
    {
        string chosenContact = DialogueLua.GetVariable("ChosenContact").asString;
        if (!string.IsNullOrEmpty(chosenContact))
        {
            // When starting an NPC conversation, use the smsUI:
            DialogueManager.UseDialogueUI(smsUI.gameObject);
            DialogueManager.StartConversation(chosenContact);
        }
        else        
        {
            // Otherwise reset back to the computer UI as the default UI:
            DialogueManager.UseDialogueUI(computerUI.gameObject);
        }
    }
}
Alex95
Posts: 6
Joined: Tue Mar 23, 2021 8:13 pm

Re: Select conversation in UI like messages

Post by Alex95 »

Thank you so much for the comprehensive reply, Tony!
I am back to working on the project today and I will implement your solution. Thank you for making it very easy to understand. I am still getting used to things. :)
I appreciate the generous help!
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Select conversation in UI like messages

Post by Tony Li »

Glad to help! If any questions come up, just let me know.
Alex95
Posts: 6
Joined: Tue Mar 23, 2021 8:13 pm

Re: Select conversation in UI like messages

Post by Alex95 »

Hello again, Tony. I do have a couple of follow up questions if you don't mind.

I set up the scripts and conversations as you suggested, and it is working well for the most part. The UI switches to SMS when I start a conversation by clicking the reply button for the desired contact. However, I didn't mention in my first post that my contact list and SMS UIs are in a worldspace canvas triggered by "using" a terminal (like in the demo scene), and for that reason I am using the "Override Dialogue UI" component on the terminal to switch from the in-game UI to the terminal-triggered worldspace UI. I apologize for not giving all relevant details in my first post.

Results:
Because of the way my particular scene is set up, after I click the contact that I want to talk to in the message response buttons, the camera switches angles back to the player's POV. I can see that the conversation does play out in the SMS UI, however.

Questions:
How can I avoid having the camera switch back to the player POV when starting the SMS conversation? I didn't see any way to switch between more than one UI by using or building on the "Override Dialogue UI" script.

Because the default UI (set in Dialogue Manager) is not the UI I want to transition back to after the SMS conversation is finished. How can I instead transition back to the contact list UI canvas set in worldspace?

I hope this makes sense. Thanks again for the help!
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Select conversation in UI like messages

Post by Tony Li »

Hi,

When a conversation ends, and that conversation has moved the camera using the Camera() or Zoom2D() sequencer commands, it always put the camera back in its original position.

In this instance, move the camera using the MoveTo() sequencer command instead, such as:

Code: Select all

MoveTo(Terminal Screen, My Main Camera, 1)
where My Main Camera is the name of your main camera. The "1" at the end moves the camera smoothly over 1 second.
Post Reply