Skip dialogue choices outside of dialogue

Announcements, support questions, and discussion for the Dialogue System.
boz
Posts: 76
Joined: Mon Oct 19, 2020 8:59 pm

Skip dialogue choices outside of dialogue

Post by boz »

How might one accomplish the following:

In the dialogue you are given various options, but outside of the dialogue you can take an action that will move the dialogue to a result that is only selected if you take action outside of the dialogue.

Another way of asking this is imagine a made up situation where there are 2 dialogue choices:
Yes
No

And then there's a button outside the dialogue that says "Maybe".

Each of these three buttons have their own dialogue result.

How might this 'Maybe' button notify the dialogue system to go to that third result?
User avatar
Tony Li
Posts: 22034
Joined: Thu Jul 18, 2013 1:27 pm

Re: Skip dialogue choices outside of dialogue

Post by Tony Li »

Hi,

I'll assume that you want to define the Maybe button in the conversation editor, so the question node actually links to 3 response nodes (Yes, No, Maybe).

On the Dialogue Editor window's Templates page, you could add a custom field to the dialogue entry template to indicate that the entry's button should appear outside the regular menu.

Then use a subclass of StandardUIMenuPanel that overrides the SetResponseButtons method. For each response, if the custom field indicates the button should appear outside the regular menu, add it there. Rough example:

Code: Select all

public class MyMenuPanel : StandardUIMenuPanel
{
    protected override void SetResponseButtons(Response[] responses, Transform target)
    {
        var regularResponses = new List<Response>();
        foreach (var response in responses)
        {
            if (Field.LookupBool(response.destinationEntry.fields, "Show Outside UI"))
            {
                // Show special response button somewhere else
            }
            else
            {
                regularResponses.Add(response);
            }
        }
        
        base.SetResponseButtons(regularResponses.ToArray(), target);
    }
}
boz
Posts: 76
Joined: Mon Oct 19, 2020 8:59 pm

Re: Skip dialogue choices outside of dialogue

Post by boz »

Oooh I like this.

So let me expand into a specific use-case.
You are given a selection of cards - you can respond "No I don't want any of these" in the dialogue, or you can select a card - each one has a different reaction. (Examples attached)

In the example

Code: Select all

// Show special response button somewhere else
, would there be a way for it to attach itself to those card selection buttons, so that when you click on any one of them, it triggers the <Card Selected> node and drops into the "Our Contract is complete." node?

Thanks :)
Attachments
2021-05-26 17_14_43-Twilight Tower - Playing - PC, Mac & Linux Standalone - Unity 2020.3.8f1 Persona.png
2021-05-26 17_14_43-Twilight Tower - Playing - PC, Mac & Linux Standalone - Unity 2020.3.8f1 Persona.png (59.63 KiB) Viewed 1486 times
2021-05-26 17_17_22-Game.png
2021-05-26 17_17_22-Game.png (891.39 KiB) Viewed 1486 times
User avatar
Tony Li
Posts: 22034
Joined: Thu Jul 18, 2013 1:27 pm

Re: Skip dialogue choices outside of dialogue

Post by Tony Li »

It's easiest if you set up the <Card Selected> node to always be in a specific position in the response list, such as the first response. Then you can configure your card buttons to click the first response. Example:

Code: Select all

private Response cardSelectedResponse;

public void OnConversationResponseMenu(Response[] responses)
{
    cardSelectedResponse = responses[0];
}

public void SelectCard(int cardNumber)
{
    // Record the selected card number for the Dialogue System:
    DialogueLua.SetVariable("SelectedCardNumber", cardNumber);
    
    // Tell the StandardDialogueUI to use the card selected response:
    (DialogueManager.dialogueUI as StandardDialogueUI).OnClick(cardSelectedResponse);
}
boz
Posts: 76
Joined: Mon Oct 19, 2020 8:59 pm

Re: Skip dialogue choices outside of dialogue

Post by boz »

Great! I'll give this a try, thank you!
User avatar
Tony Li
Posts: 22034
Joined: Thu Jul 18, 2013 1:27 pm

Re: Skip dialogue choices outside of dialogue

Post by Tony Li »

Happy to help!
boz
Posts: 76
Joined: Mon Oct 19, 2020 8:59 pm

Re: Skip dialogue choices outside of dialogue

Post by boz »

Worked like a charm. Here's what I ended up using:

Code: Select all

    protected override void SetResponseButtons(Response[] responses, Transform target)
    {
        var regularResponses = new List<Response>();
        foreach (var response in responses)
        {
            if (Field.LookupBool(response.destinationEntry.fields, "CardButton"))
            {
                // Show special response button somewhere else
                cardSelectedResponse = response;
            }
            else
            {
                regularResponses.Add(response);
            }
        }

        base.SetResponseButtons(regularResponses.ToArray(), target);
    }

    public void SelectCard()
    {
        if (Field.LookupBool(cardSelectedResponse.destinationEntry.fields, "CardButton"))
        {
            (DialogueManager.dialogueUI as StandardDialogueUI).OnClick(cardSelectedResponse);
            ResponseMenuController.I.cardSelectedResponse = null;
        }
    }
Thanks again :)
User avatar
Tony Li
Posts: 22034
Joined: Thu Jul 18, 2013 1:27 pm

Re: Skip dialogue choices outside of dialogue

Post by Tony Li »

Awesome! Glad to help.
boz
Posts: 76
Joined: Mon Oct 19, 2020 8:59 pm

Re: Skip dialogue choices outside of dialogue

Post by boz »

Is there a way I could show potential responses in the dialogue, but you can't select one there - instead, you do things in the game and it makes a selection for you?

Sort of like making dialogue selections via your behavior.
User avatar
Tony Li
Posts: 22034
Joined: Thu Jul 18, 2013 1:27 pm

Re: Skip dialogue choices outside of dialogue

Post by Tony Li »

Yes. Here are two ways to do that:

1. Make a subclass of StandardUIMenuPanel that overrides the behavior. For example, it could set all of the buttons non-interactable, and instead let actions in the game call the buttons' StandardUIResponseButton.OnClick() methods.

2. Or assign anything to the response buttons' Button component > OnClick() UnityEvent. If anything is assigned to OnClick(), the StandardUIResponseButton component will not automatically add its own OnClick() method to the UnityEvent. This means clicking the button will not select the response. When the player performs a game action, loop through the responses to identify the button that corresponds to the game action. Then call its StandardUIResponseButton.OnClick() method.
Post Reply